diff --git a/README.md b/README.md index a9e52fe78..a46056a2a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A gallery for viewing photos and videos. -A simple tool usable for viewing photos and videos. Items can be sorted by date, size, name both ascending or descending, photos can be zoomed in. Media files are shown in multiple columns, depending on the size of the display. They can be renamed, shared or deleted. +A simple tool usable for viewing photos and videos. Items can be sorted by date, size, name both ascending or descending, photos can be zoomed in. Media files are shown in multiple columns, depending on the size of the display. They can be renamed, shared or deleted. Images can also be cropped, rotated or set as Wallpaper directly from the app. The Gallery is also offered for third party usage for previewing images / videos, adding attachments at email clients etc. It's perfect for everyday usage. diff --git a/app/src/main/java/com/simplemobiletools/gallery/ViewServer.java b/app/src/main/java/com/simplemobiletools/gallery/ViewServer.java new file mode 100644 index 000000000..3e6fb8f8e --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/gallery/ViewServer.java @@ -0,0 +1,136 @@ +package com.simplemobiletools.gallery; + +import android.Manifest; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.res.Resources; +import android.net.Uri; +import android.os.Build; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.ActionBar; +import android.util.DisplayMetrics; +import android.util.TypedValue; +import android.view.Display; +import android.view.KeyCharacterMap; +import android.view.KeyEvent; +import android.view.View; +import android.view.ViewConfiguration; +import android.view.Window; +import android.webkit.MimeTypeMap; +import android.widget.Toast; + +import com.simplemobiletools.gallery.models.Medium; + +import java.io.File; + +public class ViewServer { + public static String getFilename(final String path) { + return path.substring(path.lastIndexOf("/") + 1); + } + + public static void showToast(Context context, int resId) { + Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show(); + } + + public static int getActionBarHeight(Context context, Resources res) { + final TypedValue tv = new TypedValue(); + int height = 0; + if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { + height = TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); + } + return height; + } + + public static int getStatusBarHeight(Resources res) { + int id = res.getIdentifier("status_bar_height", "dimen", "android"); + if (id > 0) { + return res.getDimensionPixelSize(id); + } + return 0; + } + + public static int getNavBarHeight(Resources res) { + int id = res.getIdentifier("navigation_bar_height", "dimen", "android"); + if (id > 0) { + return res.getDimensionPixelSize(id); + } + return 0; + } + + public static boolean hasNavBar(Activity act) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + Display display = act.getWindowManager().getDefaultDisplay(); + + DisplayMetrics realDisplayMetrics = new DisplayMetrics(); + display.getRealMetrics(realDisplayMetrics); + + int realHeight = realDisplayMetrics.heightPixels; + int realWidth = realDisplayMetrics.widthPixels; + + DisplayMetrics displayMetrics = new DisplayMetrics(); + display.getMetrics(displayMetrics); + + int displayHeight = displayMetrics.heightPixels; + int displayWidth = displayMetrics.widthPixels; + + return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; + } else { + boolean hasMenuKey = ViewConfiguration.get(act).hasPermanentMenuKey(); + boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); + return !hasMenuKey && !hasBackKey; + } + } + + public static boolean hasStoragePermission(Context cxt) { + return ContextCompat.checkSelfPermission(cxt, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; + } + + public static String getMimeType(String url) { + final String extension = MimeTypeMap.getFileExtensionFromUrl(url); + if (extension != null) { + return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + } + return ""; + } + + public static void shareMedium(Medium medium, Activity activity) { + final String shareTitle = activity.getResources().getString(R.string.share_via); + final Intent intent = new Intent(); + final File file = new File(medium.getPath()); + final Uri uri = Uri.fromFile(file); + intent.setAction(Intent.ACTION_SEND); + intent.putExtra(Intent.EXTRA_STREAM, uri); + intent.setType(getMimeType(medium)); + activity.startActivity(Intent.createChooser(intent, shareTitle)); + } + + public static String getMimeType(Medium medium) { + if (medium.getIsVideo()) + return "video/*"; + else + return "image/*"; + } + + public static void showSystemUI(ActionBar actionbar, Window window) { + if (actionbar != null) + actionbar.show(); + + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } + + public static void hideSystemUI(ActionBar actionbar, Window window) { + if (actionbar != null) + actionbar.hide(); + + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | + View.SYSTEM_UI_FLAG_LOW_PROFILE | + View.SYSTEM_UI_FLAG_FULLSCREEN | + View.SYSTEM_UI_FLAG_IMMERSIVE); + } +} diff --git a/screenshots/app.jpg b/screenshots/app.jpg index 1eadb077a..77cdb24fa 100644 Binary files a/screenshots/app.jpg and b/screenshots/app.jpg differ diff --git a/screenshots/app_2.jpg b/screenshots/app_2.jpg index c94388821..1d420aab9 100644 Binary files a/screenshots/app_2.jpg and b/screenshots/app_2.jpg differ diff --git a/screenshots/app_3.jpg b/screenshots/app_3.jpg index f31db0dd5..a9d2172be 100644 Binary files a/screenshots/app_3.jpg and b/screenshots/app_3.jpg differ diff --git a/screenshots/app_4.jpg b/screenshots/app_4.jpg index a9d2172be..c6f9e99bf 100644 Binary files a/screenshots/app_4.jpg and b/screenshots/app_4.jpg differ diff --git a/screenshots/tablet-10.jpg b/screenshots/tablet-10.jpg index 1436e5edc..2ad593ae0 100644 Binary files a/screenshots/tablet-10.jpg and b/screenshots/tablet-10.jpg differ diff --git a/screenshots/tablet-7.jpg b/screenshots/tablet-7.jpg index 276cc59c2..ffa5183b7 100644 Binary files a/screenshots/tablet-7.jpg and b/screenshots/tablet-7.jpg differ