package com.simplemobiletools.gallery; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; import android.util.TypedValue; import android.view.View; import android.view.Window; import android.webkit.MimeTypeMap; import android.widget.Toast; public class Utils { 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(Resources res) { int id = res.getIdentifier("config_showNavigationBar", "bool", "android"); return id > 0 && res.getBoolean(id); } 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 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); } }