[Android] Ask system permission for brightness mode
Geoffrey Métais
git at videolan.org
Fri Mar 4 11:10:17 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar 4 10:53:01 2016 +0100| [366ddd8038c2e91b0941cdb05e1a787299fb2c2e] | committer: Geoffrey Métais
Ask system permission for brightness mode
> https://code.videolan.org/videolan/vlc-android/commit/366ddd8038c2e91b0941cdb05e1a787299fb2c2e
---
vlc-android/res/values/strings.xml | 6 +++--
.../org/videolan/vlc/gui/helpers/AudioUtil.java | 2 +-
.../vlc/gui/video/VideoPlayerActivity.java | 4 +++
.../src/org/videolan/vlc/util/Permissions.java | 29 ++++++++++++++++------
4 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 1680b63..fcdad6a 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -393,8 +393,10 @@
<string name="widget_name_b">VLC Dark Widget</string>
<string name="allow_storage_access_title">Allow VLC to access video and audio files</string>
<string name="allow_storage_access_description">VLC needs you to grant this permission to access the media files on this device.</string>
- <string name="allow_settings_access_title">Allow VLC to set the ringtone</string>
- <string name="allow_settings_access_description">VLC needs you to grant this permission to set up this song as your ringtone.</string>
+ <string name="allow_settings_access_ringtone_title">Allow VLC to set the ringtone</string>
+ <string name="allow_settings_access_ringtone_description">VLC needs you to grant this permission to set up this song as your ringtone.</string>
+ <string name="allow_settings_access_brightness_title">Allow VLC to change brightness mode</string>
+ <string name="allow_settings_access_brightness_description">VLC needs you to grant this permission to change your brightness mode.</string>
<string name="permission_ask_again">Grant permission</string>
<string name="exit_app">Close VLC</string>
<string name="hardware_acceleration_error">hardware acceleration error, switching to software decoding</string>
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
index f90f648..6dea655 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
@@ -86,7 +86,7 @@ public class AudioUtil {
@RequiresPermission(android.Manifest.permission.WRITE_SETTINGS)
public static void setRingtone(MediaWrapper song, Activity context){
if (!Permissions.canWriteSettings(context)) {
- Permissions.checkWriteSettingsPermission(context);
+ Permissions.checkWriteSettingsPermission(context, Permissions.PERMISSION_SYSTEM_RINGTONE);
return;
}
File newringtone = AndroidUtil.UriToFile(song.getUri());
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index f90df0b..f22f5e3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1965,6 +1965,10 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
// Initialize the layoutParams screen brightness
try {
if (Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
+ if (!Permissions.canWriteSettings(this)) {
+ Permissions.checkWriteSettingsPermission(this, Permissions.PERMISSION_SYSTEM_BRIGHTNESS);
+ return;
+ }
Settings.System.putInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
diff --git a/vlc-android/src/org/videolan/vlc/util/Permissions.java b/vlc-android/src/org/videolan/vlc/util/Permissions.java
index 6ffa989..ae0cbe3 100644
--- a/vlc-android/src/org/videolan/vlc/util/Permissions.java
+++ b/vlc-android/src/org/videolan/vlc/util/Permissions.java
@@ -50,6 +50,10 @@ public class Permissions {
public static final int PERMISSION_STORAGE_TAG = 255;
public static final int PERMISSION_SETTINGS_TAG = 254;
+
+ public static final int PERMISSION_SYSTEM_RINGTONE = 42;
+ public static final int PERMISSION_SYSTEM_BRIGHTNESS = 43;
+
/*
* Marshmallow permission system management
*/
@@ -78,18 +82,18 @@ public class Permissions {
}
}
- public static void checkWriteSettingsPermission(Activity activity) {
+ public static void checkWriteSettingsPermission(Activity activity, int mode) {
if (AndroidUtil.isMarshMallowOrLater() && !canWriteSettings(activity)) {
- showSettingsPermissionDialog(activity);
+ showSettingsPermissionDialog(activity, mode);
}
}
private static Dialog sAlertDialog;
- public static void showSettingsPermissionDialog(final Activity activity) {
+ public static void showSettingsPermissionDialog(final Activity activity, int mode) {
if (activity.isFinishing() || (sAlertDialog != null && sAlertDialog.isShowing()))
return;
- sAlertDialog = createSettingsDialogCompat(activity);
+ sAlertDialog = createSettingsDialogCompat(activity, mode);
}
public static void showStoragePermissionDialog(final Activity activity, boolean exit) {
@@ -177,10 +181,21 @@ public class Permissions {
return dialogBuilder.show();
}
- private static Dialog createSettingsDialogCompat(final Activity activity) {
+ private static Dialog createSettingsDialogCompat(final Activity activity, int mode) {
+ int titleId = 0, textId = 0;
+ switch (mode) {
+ case PERMISSION_SYSTEM_RINGTONE:
+ titleId = R.string.allow_settings_access_ringtone_title;
+ textId = R.string.allow_settings_access_ringtone_description;
+ break;
+ case PERMISSION_SYSTEM_BRIGHTNESS:
+ titleId = R.string.allow_settings_access_brightness_title;
+ textId = R.string.allow_settings_access_brightness_description;
+ break;
+ }
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity)
- .setTitle(activity.getString(R.string.allow_settings_access_title))
- .setMessage(activity.getString(R.string.allow_settings_access_description))
+ .setTitle(activity.getString(titleId))
+ .setMessage(activity.getString(textId))
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(activity.getString(R.string.permission_ask_again), new DialogInterface.OnClickListener() {
@Override
More information about the Android
mailing list