require write_external_storage so we can modify things too

This commit is contained in:
tibbi 2016-11-06 15:42:56 +01:00
parent 3f756369f2
commit f0e8746bce
3 changed files with 2 additions and 138 deletions

View File

@ -86,7 +86,7 @@ public class Utils {
} }
public static boolean hasStoragePermission(Context cxt) { public static boolean hasStoragePermission(Context cxt) {
return ContextCompat.checkSelfPermission(cxt, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; return ContextCompat.checkSelfPermission(cxt, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
} }
public static String getMimeType(String url) { public static String getMimeType(String url) {

View File

@ -1,136 +0,0 @@
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);
}
}

View File

@ -151,7 +151,7 @@ public class MainActivity extends SimpleActivity
if (Utils.hasStoragePermission(getApplicationContext())) { if (Utils.hasStoragePermission(getApplicationContext())) {
getDirectories(); getDirectories();
} else { } else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION); ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION);
} }
} }