Skip to content

Commit 6cb1a89

Browse files
committed
fix image shortcut
1 parent 78a5aae commit 6cb1a89

5 files changed

Lines changed: 76 additions & 46 deletions

File tree

PowerFileExplorer/src/main/AndroidManifest.xml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,23 +328,25 @@
328328
</activity>
329329
<activity
330330
android:name="net.gnu.mupdf.viewer.app.LibraryActivity"
331-
android:configChanges="orientation|screenSize|keyboardHidden">
331+
android:configChanges="orientation|screenSize|keyboardHidden"
332+
android:label="PDF Reader">
332333
<intent-filter>
333-
<action android:name="android.intent.action.MAIN" />
334-
<category android:name="android.intent.category.DEFAULT" />
335-
</intent-filter>
334+
<action android:name="android.intent.action.MAIN" />
335+
<category android:name="android.intent.category.LAUNCHER" />
336+
</intent-filter>
336337
</activity>
337338

338339
<activity android:name="com.tuarua.avane.android.libavaneexample.MainActivity"
339-
android:label="Ffmpeg utilities">
340+
android:label="FFMpeg Utilities">
340341
<intent-filter>
341342
<action android:name="android.intent.action.MAIN" />
342343
<category android:name="android.intent.category.LAUNCHER" />
343344
</intent-filter>
344345
</activity>
345346

346347
<activity android:name="videoeditor.bhuvnesh.com.ffmpegvideoeditor.activity.MainActivity"
347-
android:screenOrientation="portrait">
348+
android:screenOrientation="portrait"
349+
android:label="Media Editor">
348350
<intent-filter>
349351
<action android:name="android.intent.action.MAIN" />
350352
<category android:name="android.intent.category.LAUNCHER" />
@@ -437,7 +439,10 @@
437439
android:label="Text Editor"
438440
android:theme="@style/AppTheme"
439441
>
440-
442+
<intent-filter>
443+
<action android:name="android.intent.action.MAIN" />
444+
<category android:name="android.intent.category.LAUNCHER" />
445+
</intent-filter>
441446
<intent-filter>
442447
<action android:name="android.intent.action.VIEW" />
443448
<action android:name="android.intent.action.OPEN_DOCUMENT" />

PowerFileExplorer/src/main/java/net/gnu/androidutil/AndroidUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static void addShortcut(final Context context, final File f) {
101101
if (f.isFile()) {
102102
if (MimeTypes.getMimeType(f).startsWith("image")) {
103103
final int size = (int) context.getResources().getDimension(android.R.dimen.app_icon_size);
104-
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapUtil.scaleBmp(BitmapFactory.decodeFile(absolutePath), size));
104+
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapUtil.resizeKeepScale(BitmapFactory.decodeFile(absolutePath), size));
105105
shortcutIntent = new Intent(context.getApplicationContext(),
106106
PhotoActivity.class);
107107
} else {

PowerFileExplorer/src/main/java/net/gnu/androidutil/BitmapUtil.java

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void saveDrawable2Bitmap(Context ctx, int resId, String fName, int
4040
public static Bitmap createVideoThumbnail(String path) {
4141
return ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND);
4242
}
43-
43+
4444
public static void setImageDrawable(ImageView imgView, Context ctx, int resId) {
4545
imgView.setImageBitmap(BitmapFactory.decodeResource(ctx.getResources(), resId));
4646
}
@@ -68,7 +68,7 @@ public static Bitmap createResizedBitmap(byte[] img, int newHeight,
6868
}
6969

7070
public static int calculateSampleSize(BitmapFactory.Options options,
71-
int newHeight, int newWidth) {
71+
int newHeight, int newWidth) {
7272
int sampleSize = 1;
7373

7474
while (((options.outHeight / 2) / sampleSize) > newHeight
@@ -90,7 +90,7 @@ public static BitmapFactory.Options getBitmapDimesions(byte[] img) {
9090

9191
return options;
9292
}
93-
93+
9494
public static BitmapFactory.Options getBitmapDimesions(final String img) {
9595

9696
final BitmapFactory.Options options = new BitmapFactory.Options();
@@ -100,15 +100,15 @@ public static BitmapFactory.Options getBitmapDimesions(final String img) {
100100

101101
return options;
102102
}
103-
103+
104104
public static Bitmap getBitmapForVisibleRegion(WebView webview) {
105105
Bitmap returnedBitmap = null;
106106
webview.setDrawingCacheEnabled(true);
107107
returnedBitmap = Bitmap.createBitmap(webview.getDrawingCache());
108108
webview.setDrawingCacheEnabled(false);
109109
return returnedBitmap;
110110
}
111-
111+
112112
public static Bitmap getThumbnail(Context context, Uri uri, int size)
113113
throws FileNotFoundException, IOException {
114114
InputStream input = context.getContentResolver().openInputStream(uri);
@@ -136,15 +136,15 @@ public static Bitmap getThumbnail(Context context, Uri uri, int size)
136136
input.close();
137137
return bitmap;
138138
}
139-
139+
140140
private static int getPowerOfTwoForSampleRatio(double ratio) {
141141
int k = Integer.highestOneBit((int) Math.floor(ratio));
142142
if (k == 0)
143143
return 1;
144144
else
145145
return k;
146146
}
147-
147+
148148
public Bitmap scaleRelative2View(View view, Bitmap bitmap, float inScaleX, float inScaleY) {
149149
// create a matrix for the manipulation
150150
Matrix matrix = new Matrix();
@@ -170,31 +170,56 @@ public Bitmap scaleRelative2View(View view, Bitmap bitmap, float inScaleX, float
170170

171171
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
172172
}
173-
173+
174+
public static Bitmap resizeKeepScale(final Bitmap bitmap, final int max) {
175+
//Log.d(TAG, "resizeKeepScale " + max);
176+
int bmpWidth = bitmap.getWidth();
177+
int bmpHeight = bitmap.getHeight();
178+
if (bmpWidth < bmpHeight) {
179+
bmpWidth = Math.max(1, (bmpWidth * max / bmpHeight));
180+
bmpHeight = max;
181+
} else {
182+
bmpHeight = Math.max(1, (bmpHeight * max / bmpWidth));
183+
bmpWidth = max;
184+
}
185+
final Bitmap createScaledBitmap = Bitmap.createScaledBitmap(bitmap, bmpWidth, bmpHeight, true);
186+
final Rect rect = new Rect((max - bmpWidth)/2, (max - bmpHeight)/2, bmpWidth, bmpHeight);
187+
188+
final Bitmap output = Bitmap.createBitmap(max, max, Bitmap.Config.ARGB_8888);
189+
final Canvas canvas = new Canvas(output);
190+
canvas.drawARGB(0, 0, 0, 0);
191+
192+
final Paint paint = new Paint();
193+
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
194+
canvas.drawBitmap(createScaledBitmap, rect, rect, paint);
195+
createScaledBitmap.recycle();
196+
return output;
197+
}
198+
174199
/**
175200
* scale the bitmap to a long edge of max
176201
*
177202
* @param Bitmap
178203
* @param Integer
179204
* @return Bitmap
180205
*/
181-
public static Bitmap scaleBmp(Bitmap bmp, int max) {
182-
float bmpWidth = bmp.getWidth();
183-
float bmpHeight = bmp.getHeight();
206+
public static Bitmap scaleBmp(final Bitmap bmp, final int max) {
207+
int bmpWidth = bmp.getWidth();
208+
int bmpHeight = bmp.getHeight();
184209
if (bmpWidth < bmpHeight) {
185-
bmpWidth = (bmpWidth * max / bmpHeight);
210+
bmpWidth = Math.max(1, (bmpWidth * max / bmpHeight));
186211
bmpHeight = max;
187212
} else {
188-
bmpHeight = (bmpHeight * max / bmpWidth);
213+
bmpHeight = Math.max(1, (bmpHeight * max / bmpWidth));
189214
bmpWidth = max;
190215
}
191-
if (bmpWidth > 0 && bmpWidth > 0) {
192-
bmp = Bitmap.createScaledBitmap(bmp, (int) bmpWidth,
193-
(int) bmpHeight, true);
194-
}
195-
return bmp;
216+
//if (bmpWidth > 0 && bmpWidth > 0) {
217+
return Bitmap.createScaledBitmap(bmp, bmpWidth,
218+
bmpHeight, true);
219+
// }
220+
// return bmp;
196221
}
197-
222+
198223
public static File saveBitmap(final Bitmap bitmap,
199224
final String filename) {
200225
OutputStream outStream = null;
@@ -213,7 +238,7 @@ public static File saveBitmap(final Bitmap bitmap,
213238
}
214239
return out;
215240
}
216-
241+
217242
public static void recycleBitmap(ImageView iv) {
218243
Drawable d = iv.getDrawable();
219244
if (d instanceof BitmapDrawable) {
@@ -222,7 +247,7 @@ public static void recycleBitmap(ImageView iv) {
222247
}
223248
d.setCallback(null);
224249
}
225-
250+
226251
public static Bitmap rotate(Bitmap bitmap, int rotation) {
227252

228253
int targetWidth = bitmap.getWidth();
@@ -243,7 +268,7 @@ public static Bitmap rotate(Bitmap bitmap, int rotation) {
243268
bitmap.recycle();
244269
return targetBitmap;
245270
}
246-
271+
247272
public static Bitmap rotateImageView(int angle, Bitmap bitmap) {
248273

249274
if (bitmap == null)
@@ -260,17 +285,17 @@ public static Bitmap rotateImageView(int angle, Bitmap bitmap) {
260285
bitmap.recycle();
261286
return resizedBitmap;
262287
}
263-
288+
264289
public static Bitmap loadScaledBitmap(Context context, String bitmapFilePath, int widthDp, int heightDp) throws IOException {
265290
//create movie icon
266291
Bitmap bitmap;
267-
bitmap=BitmapFactory.decodeStream(context.openFileInput(bitmapFilePath));
268-
bitmap=Bitmap.createScaledBitmap(bitmap, widthDp, heightDp, true);
292+
bitmap = BitmapFactory.decodeStream(context.openFileInput(bitmapFilePath));
293+
bitmap = Bitmap.createScaledBitmap(bitmap, widthDp, heightDp, true);
269294
return bitmap;
270295
}
271-
296+
272297
public static Bitmap loadBitmapAndScale(final String filePath,
273-
final int width, final int height) {
298+
final int width, final int height) {
274299
final BitmapFactory.Options options = new BitmapFactory.Options();
275300
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
276301
options.inDither = false;
@@ -318,7 +343,7 @@ private static int calculateInSampleSize(
318343
}
319344
return inSampleSize;
320345
}
321-
346+
322347
public static Bitmap circularBitmap(Bitmap bitmap) {
323348
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
324349
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
@@ -340,7 +365,7 @@ public static Bitmap circularBitmap(Bitmap bitmap) {
340365
//return _bmp;
341366
return output;
342367
}
343-
368+
344369
public static Bitmap centerCrop(Bitmap srcBmp) {
345370
Bitmap dstBmp = null;
346371
if (srcBmp.getWidth() >= srcBmp.getHeight()) {
@@ -362,7 +387,7 @@ public static Bitmap centerCrop(Bitmap srcBmp) {
362387
}
363388
return dstBmp;
364389
}
365-
390+
366391
public static Bitmap cropCenter(Bitmap bitmap) {
367392

368393
int minSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
@@ -382,33 +407,33 @@ public static Bitmap cropCenter(Bitmap bitmap) {
382407
bitmap.recycle();
383408
return targetBitmap;
384409
}
385-
410+
386411
public static Bitmap drawableToBitmap(int res_id, Context context) {
387412
BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(res_id);
388413
Bitmap bitmap = drawable.getBitmap();
389414
return bitmap;
390415
}
391416

392417
public static Bitmap drawableToBitmap(Drawable drawable) {
393-
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),
418+
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
394419
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888: Bitmap.Config.RGB_565);
395420
Canvas canvas = new Canvas(bitmap);
396-
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
421+
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
397422
drawable.draw(canvas);
398423
return bitmap;
399424
}
400-
425+
401426
public static Drawable bitmapToDrawable(Bitmap bitmap) {
402427
return new BitmapDrawable(bitmap);
403428
}
404-
429+
405430
public static Bitmap bytes2Bimap(byte[] b) {
406431
if (b.length == 0) {
407432
return null;
408433
}
409434
return BitmapFactory.decodeByteArray(b, 0, b.length);
410435
}
411-
436+
412437
public static Bitmap getScaledScreenshot(final Activity activity, int scaleWidth, int scaleHeight, boolean relativeScaleIfTrue) {
413438
final View someView = activity.findViewById(android.R.id.content);
414439
final View rootView = someView.getRootView();

PowerFileExplorer/src/main/java/net/gnu/explorer/ContentFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2609,9 +2609,9 @@ public void publish(final Object... message) {
26092609

26102610
@Override
26112611
public void onProgressUpdate(final Object... message) {
2612-
Log.d(TAG, "onProgressUpdate " + message[0]);
26132612
if (message != null) {
26142613
if (message[0] instanceof String) {
2614+
Log.d(TAG, "onProgressUpdate " + message[0]);
26152615
showToast(message[0]);
26162616
} else {
26172617
busyNoti = true;

PowerFileExplorer/src/main/java/net/gnu/explorer/ExplorerApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void onCreate() {
123123
if (!installed_shortcut) {
124124
AndroidUtils.createShortCut(getApplicationContext(), TextEditorActivity.class, "Text Editor", R.drawable.textpng);
125125
// AndroidUtils.createShortCut(getApplicationContext(), MediaPlayerActivity.class, "Media Player", R.drawable.exo_banner);
126-
// AndroidUtils.createShortCut(getApplicationContext(), WebActivity.class, "WebView", R.drawable.html);
126+
AndroidUtils.createShortCut(getApplicationContext(), ExplorerActivity.class, "Power File Explorer", R.drawable.file_browser);
127127
AndroidUtils.createShortCut(getApplicationContext(), LibraryActivity.class, "PDF Viewer", R.drawable.pdf_icon);
128128
AndroidUtils.setSharedPreference(this, "install_shortcut", true);
129129
}

0 commit comments

Comments
 (0)