Skip to content

Commit

Permalink
fix image shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerExplorer committed Jun 1, 2018
1 parent 78a5aae commit 6cb1a89
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 46 deletions.
19 changes: 12 additions & 7 deletions PowerFileExplorer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,23 +328,25 @@
</activity>
<activity
android:name="net.gnu.mupdf.viewer.app.LibraryActivity"
android:configChanges="orientation|screenSize|keyboardHidden">
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="PDF Reader">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name="com.tuarua.avane.android.libavaneexample.MainActivity"
android:label="Ffmpeg utilities">
android:label="FFMpeg Utilities">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name="videoeditor.bhuvnesh.com.ffmpegvideoeditor.activity.MainActivity"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:label="Media Editor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down Expand Up @@ -437,7 +439,10 @@
android:label="Text Editor"
android:theme="@style/AppTheme"
>

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.OPEN_DOCUMENT" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static void addShortcut(final Context context, final File f) {
if (f.isFile()) {
if (MimeTypes.getMimeType(f).startsWith("image")) {
final int size = (int) context.getResources().getDimension(android.R.dimen.app_icon_size);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapUtil.scaleBmp(BitmapFactory.decodeFile(absolutePath), size));
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapUtil.resizeKeepScale(BitmapFactory.decodeFile(absolutePath), size));
shortcutIntent = new Intent(context.getApplicationContext(),
PhotoActivity.class);
} else {
Expand Down
97 changes: 61 additions & 36 deletions PowerFileExplorer/src/main/java/net/gnu/androidutil/BitmapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void saveDrawable2Bitmap(Context ctx, int resId, String fName, int
public static Bitmap createVideoThumbnail(String path) {
return ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND);
}

public static void setImageDrawable(ImageView imgView, Context ctx, int resId) {
imgView.setImageBitmap(BitmapFactory.decodeResource(ctx.getResources(), resId));
}
Expand Down Expand Up @@ -68,7 +68,7 @@ public static Bitmap createResizedBitmap(byte[] img, int newHeight,
}

public static int calculateSampleSize(BitmapFactory.Options options,
int newHeight, int newWidth) {
int newHeight, int newWidth) {
int sampleSize = 1;

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

return options;
}

public static BitmapFactory.Options getBitmapDimesions(final String img) {

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

return options;
}

public static Bitmap getBitmapForVisibleRegion(WebView webview) {
Bitmap returnedBitmap = null;
webview.setDrawingCacheEnabled(true);
returnedBitmap = Bitmap.createBitmap(webview.getDrawingCache());
webview.setDrawingCacheEnabled(false);
return returnedBitmap;
}

public static Bitmap getThumbnail(Context context, Uri uri, int size)
throws FileNotFoundException, IOException {
InputStream input = context.getContentResolver().openInputStream(uri);
Expand Down Expand Up @@ -136,15 +136,15 @@ public static Bitmap getThumbnail(Context context, Uri uri, int size)
input.close();
return bitmap;
}

private static int getPowerOfTwoForSampleRatio(double ratio) {
int k = Integer.highestOneBit((int) Math.floor(ratio));
if (k == 0)
return 1;
else
return k;
}

public Bitmap scaleRelative2View(View view, Bitmap bitmap, float inScaleX, float inScaleY) {
// create a matrix for the manipulation
Matrix matrix = new Matrix();
Expand All @@ -170,31 +170,56 @@ public Bitmap scaleRelative2View(View view, Bitmap bitmap, float inScaleX, float

return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}


public static Bitmap resizeKeepScale(final Bitmap bitmap, final int max) {
//Log.d(TAG, "resizeKeepScale " + max);
int bmpWidth = bitmap.getWidth();
int bmpHeight = bitmap.getHeight();
if (bmpWidth < bmpHeight) {
bmpWidth = Math.max(1, (bmpWidth * max / bmpHeight));
bmpHeight = max;
} else {
bmpHeight = Math.max(1, (bmpHeight * max / bmpWidth));
bmpWidth = max;
}
final Bitmap createScaledBitmap = Bitmap.createScaledBitmap(bitmap, bmpWidth, bmpHeight, true);
final Rect rect = new Rect((max - bmpWidth)/2, (max - bmpHeight)/2, bmpWidth, bmpHeight);

final Bitmap output = Bitmap.createBitmap(max, max, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(output);
canvas.drawARGB(0, 0, 0, 0);

final Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
canvas.drawBitmap(createScaledBitmap, rect, rect, paint);
createScaledBitmap.recycle();
return output;
}

/**
* scale the bitmap to a long edge of max
*
* @param Bitmap
* @param Integer
* @return Bitmap
*/
public static Bitmap scaleBmp(Bitmap bmp, int max) {
float bmpWidth = bmp.getWidth();
float bmpHeight = bmp.getHeight();
public static Bitmap scaleBmp(final Bitmap bmp, final int max) {
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
if (bmpWidth < bmpHeight) {
bmpWidth = (bmpWidth * max / bmpHeight);
bmpWidth = Math.max(1, (bmpWidth * max / bmpHeight));
bmpHeight = max;
} else {
bmpHeight = (bmpHeight * max / bmpWidth);
bmpHeight = Math.max(1, (bmpHeight * max / bmpWidth));
bmpWidth = max;
}
if (bmpWidth > 0 && bmpWidth > 0) {
bmp = Bitmap.createScaledBitmap(bmp, (int) bmpWidth,
(int) bmpHeight, true);
}
return bmp;
//if (bmpWidth > 0 && bmpWidth > 0) {
return Bitmap.createScaledBitmap(bmp, bmpWidth,
bmpHeight, true);
// }
// return bmp;
}

public static File saveBitmap(final Bitmap bitmap,
final String filename) {
OutputStream outStream = null;
Expand All @@ -213,7 +238,7 @@ public static File saveBitmap(final Bitmap bitmap,
}
return out;
}

public static void recycleBitmap(ImageView iv) {
Drawable d = iv.getDrawable();
if (d instanceof BitmapDrawable) {
Expand All @@ -222,7 +247,7 @@ public static void recycleBitmap(ImageView iv) {
}
d.setCallback(null);
}

public static Bitmap rotate(Bitmap bitmap, int rotation) {

int targetWidth = bitmap.getWidth();
Expand All @@ -243,7 +268,7 @@ public static Bitmap rotate(Bitmap bitmap, int rotation) {
bitmap.recycle();
return targetBitmap;
}

public static Bitmap rotateImageView(int angle, Bitmap bitmap) {

if (bitmap == null)
Expand All @@ -260,17 +285,17 @@ public static Bitmap rotateImageView(int angle, Bitmap bitmap) {
bitmap.recycle();
return resizedBitmap;
}

public static Bitmap loadScaledBitmap(Context context, String bitmapFilePath, int widthDp, int heightDp) throws IOException {
//create movie icon
Bitmap bitmap;
bitmap=BitmapFactory.decodeStream(context.openFileInput(bitmapFilePath));
bitmap=Bitmap.createScaledBitmap(bitmap, widthDp, heightDp, true);
bitmap = BitmapFactory.decodeStream(context.openFileInput(bitmapFilePath));
bitmap = Bitmap.createScaledBitmap(bitmap, widthDp, heightDp, true);
return bitmap;
}

public static Bitmap loadBitmapAndScale(final String filePath,
final int width, final int height) {
final int width, final int height) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = false;
Expand Down Expand Up @@ -318,7 +343,7 @@ private static int calculateInSampleSize(
}
return inSampleSize;
}

public static Bitmap circularBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Expand All @@ -340,7 +365,7 @@ public static Bitmap circularBitmap(Bitmap bitmap) {
//return _bmp;
return output;
}

public static Bitmap centerCrop(Bitmap srcBmp) {
Bitmap dstBmp = null;
if (srcBmp.getWidth() >= srcBmp.getHeight()) {
Expand All @@ -362,7 +387,7 @@ public static Bitmap centerCrop(Bitmap srcBmp) {
}
return dstBmp;
}

public static Bitmap cropCenter(Bitmap bitmap) {

int minSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
Expand All @@ -382,33 +407,33 @@ public static Bitmap cropCenter(Bitmap bitmap) {
bitmap.recycle();
return targetBitmap;
}

public static Bitmap drawableToBitmap(int res_id, Context context) {
BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(res_id);
Bitmap bitmap = drawable.getBitmap();
return bitmap;
}

public static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}

public static Drawable bitmapToDrawable(Bitmap bitmap) {
return new BitmapDrawable(bitmap);
}

public static Bitmap bytes2Bimap(byte[] b) {
if (b.length == 0) {
return null;
}
return BitmapFactory.decodeByteArray(b, 0, b.length);
}

public static Bitmap getScaledScreenshot(final Activity activity, int scaleWidth, int scaleHeight, boolean relativeScaleIfTrue) {
final View someView = activity.findViewById(android.R.id.content);
final View rootView = someView.getRootView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2609,9 +2609,9 @@ public void publish(final Object... message) {

@Override
public void onProgressUpdate(final Object... message) {
Log.d(TAG, "onProgressUpdate " + message[0]);
if (message != null) {
if (message[0] instanceof String) {
Log.d(TAG, "onProgressUpdate " + message[0]);
showToast(message[0]);
} else {
busyNoti = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void onCreate() {
if (!installed_shortcut) {
AndroidUtils.createShortCut(getApplicationContext(), TextEditorActivity.class, "Text Editor", R.drawable.textpng);
// AndroidUtils.createShortCut(getApplicationContext(), MediaPlayerActivity.class, "Media Player", R.drawable.exo_banner);
// AndroidUtils.createShortCut(getApplicationContext(), WebActivity.class, "WebView", R.drawable.html);
AndroidUtils.createShortCut(getApplicationContext(), ExplorerActivity.class, "Power File Explorer", R.drawable.file_browser);
AndroidUtils.createShortCut(getApplicationContext(), LibraryActivity.class, "PDF Viewer", R.drawable.pdf_icon);
AndroidUtils.setSharedPreference(this, "install_shortcut", true);
}
Expand Down

0 comments on commit 6cb1a89

Please sign in to comment.