Switch to SDK 23, support for Android 6 permissions model

This commit is contained in:
Adrian Ulrich 2015-10-25 13:09:06 +01:00
parent eb7b5dd4de
commit a1552370c6
10 changed files with 171 additions and 49 deletions

View File

@ -26,8 +26,9 @@ THE SOFTWARE.
android:versionName="1.0.33"
android:versionCode="1033"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="21" />
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- This is needed for isWiredHeadsetOn() to work in some cases. (bug?) -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
@ -149,6 +150,8 @@ THE SOFTWARE.
android:name="TabOrderActivity" />
<activity
android:name="FilebrowserStartActivity" />
<activity
android:name="PermissionRequestActivity" />
<activity android:name="AudioPickerActivity" android:theme="@style/DialogMinWidth"
android:excludeFromRecents="true" android:exported="true" >

View File

@ -10,7 +10,7 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-21
target=android-23
## do not enable: breaks settings in SDK15
##proguard.config=proguard.config

30
res/values-v21/colors.xml Normal file
View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- framework colors -->
<color name="material_grey_300">#ffeeeeee</color>
<color name="material_grey_400">#bdbdbd</color>
<color name="material_grey_500">#ffa3a3a3</color>
<color name="material_grey_600">#ff757575</color>
<color name="material_grey_900">#ff212121</color>
<color name="button_material_light">#ffd6d7d7</color>
<color name="button_material_dark">#ff5a595b</color>
<!-- Material design primary colors -->
<color name="vanillaPrimary">#ff37474f</color>
<color name="vanillaPrimaryDark">#ff263238</color>
<color name="vanillaAccent">#ff3e677a</color>
<!-- now-playing screen buttons tint -->
<color name="controls_active">@color/vanillaAccent</color>
<color name="controls_normal">@color/material_grey_600</color>
<!-- showqueue info -->
<color name="now_playing_marker">@color/vanillaAccent</color>
<!-- themed overlay colors for full playback activity -->
<color name="overlay_background_light">#ffeeeeee</color>
<color name="overlay_foreground_light">#f000</color>
<color name="overlay_background_dark">#ff303030</color>
<color name="overlay_foreground_dark">#ffffffff</color>
</resources>

View File

@ -17,34 +17,13 @@ Copyright (C) 2015 Adrian Ulrich <adrian@blinkenlights.ch>
-->
<resources>
<!-- framework colors -->
<color name="material_grey_300">#ffeeeeee</color>
<color name="material_grey_400">#bdbdbd</color>
<color name="material_grey_500">#ffa3a3a3</color>
<color name="material_grey_600">#ff757575</color>
<color name="material_grey_900">#ff212121</color>
<color name="button_material_light">#ffd6d7d7</color>
<color name="button_material_dark">#ff5a595b</color>
<!-- Material design primary colors -->
<color name="vanillaPrimary">#ff37474f</color>
<color name="vanillaPrimaryDark">#ff263238</color>
<color name="vanillaAccent">#ff3e677a</color>
<!-- now-playing screen buttons tint -->
<color name="controls_active">@color/vanillaAccent</color>
<color name="controls_normal">@color/material_grey_600</color>
<!-- showqueue info -->
<color name="now_playing_marker">@color/vanillaAccent</color>
<!-- styles -->
<style name="Dialog" parent="android:Theme.Material.Light.Dialog" />
<style name="DialogMinWidth" parent="android:Theme.Material.Light.Dialog.MinWidth" />
<style name="VanillaBase" parent="android:Theme.Material.Light.DarkActionBar">
<item name="overlay_background_color">#ffeeeeee</item>
<item name="overlay_foreground_color">#f000</item>
<item name="overlay_background_color">@color/overlay_background_light</item>
<item name="overlay_foreground_color">@color/overlay_foreground_light</item>
<item name="divider_color">@color/button_material_light</item>
<item name="float_color">@color/button_material_light</item>
<item name="android:colorAccent">@color/vanillaAccent</item>
@ -85,8 +64,8 @@ Copyright (C) 2015 Adrian Ulrich <adrian@blinkenlights.ch>
<!-- dark theme -->
<style name="Dark.VanillaBase" parent="android:Theme.Material">
<item name="overlay_background_color">#ff303030</item>
<item name="overlay_foreground_color">#ffffffff</item>
<item name="overlay_background_color">@color/overlay_background_dark</item>
<item name="overlay_foreground_color">@color/overlay_foreground_dark</item>
<item name="divider_color">@color/button_material_dark</item>
<item name="float_color">@color/material_grey_900</item>
<item name="android:colorAccent">@color/vanillaAccent</item>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="overlay_background_light">#fffafafa</color>
</resources>

View File

@ -27,7 +27,6 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.util.Log;
import android.view.FocusFinder;
import android.view.Gravity;
@ -555,7 +554,7 @@ public class ViewPager extends ViewGroup {
static float distanceInfluenceForSnapDuration(float f) {
f -= 0.5f; // center the values about 0.
f *= 0.3f * Math.PI / 2.0f;
return FloatMath.sin(f);
return (float)Math.sin((double)f);
}
/**

View File

@ -0,0 +1,110 @@
/*
* Copyright (C) 2015 Adrian Ulrich <adrian@blinkenlights.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package ch.blinkenlights.android.vanilla;
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
public class PermissionRequestActivity extends Activity {
// 'dangerous' permissions not granted by the manifest on versions >= M
private static final String[] NEEDED_PERMISSIONS = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE };
@Override
public void onCreate(Bundle savedInstanceState) {
ThemeHelper.setTheme(this, R.style.VanillaBase);
super.onCreate(savedInstanceState);
setTitle(R.string.app_name);
// Fixme: This should probably be some welcome dialog with a button to launch askForPermissions
// setContentView(R.layout.showqueue_listview);
requestPermissions(NEEDED_PERMISSIONS, 0);
}
/**
* Called by Activity after the user interacted with the permission request
* Will launch the main activity if all permissions were granted, exits otherwise
*
* @param requestCode The code set by requestPermissions
* @param permissions Names of the permissions we got granted or denied
* @param grantResults Results of the permission requests
*/
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
int grantedPermissions = 0;
for (int result : grantResults) {
if (result == PackageManager.PERMISSION_GRANTED)
grantedPermissions++;
}
if (grantedPermissions == grantResults.length) {
Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
// Hack: We *kill* ourselfs (while launching the main activity) to get startet
// in a new process: This works around a bug/feature in 6.0 that would cause us
// to get 'partial read' permissions (eg: reading from the content provider works
// but reading from /sdcard doesn't)
android.os.Process.killProcess(android.os.Process.myPid());
}
finish();
}
/**
* Launches a permission request dialog if needed
*
* @param activity The activitys context to use for the permission check
* @return boolean true if we showed a permission request dialog
*/
public static boolean requestPermissions(Activity activity) {
boolean havePermissions = havePermissions(activity);
if (havePermissions == false)
activity.startActivity(new Intent(activity, PermissionRequestActivity.class));
return !havePermissions;
}
/**
* Checks if all required permissions have been granted
*
* @param context The context to use
* @return boolean true if all permissions have been granded
*/
private static boolean havePermissions(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (String permission : NEEDED_PERMISSIONS) {
if (context.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
} // else: granted during installation
return true;
}
}

View File

@ -97,6 +97,9 @@ public abstract class PlaybackActivity extends Activity
mLooper = thread.getLooper();
mHandler = new Handler(mLooper, this);
if (PermissionRequestActivity.requestPermissions(this))
finish();
}
@Override

View File

@ -169,7 +169,7 @@ public class PreferencesActivity extends PreferenceActivity {
// does not support multiple themes
PreferenceScreen screen = getPreferenceScreen();
CheckBoxPreference dark_theme_pref = (CheckBoxPreference)findPreference("use_dark_theme");
if (ThemeHelper.couldUseDarkTheme() == false)
if (ThemeHelper.usesHoloTheme()) // not available on 4.x devices
screen.removePreference(dark_theme_pref);
}

View File

@ -66,13 +66,6 @@ public class ThemeHelper {
return playButton;
}
/**
* Configures (or unconfigures) the use of the black theme
*/
final public static void setDarkTheme(boolean enable)
{
}
/**
* Returns TRUE if we should use the dark material theme,
* Returns FALSE otherwise - always returns FALSE on pre-5.x devices
@ -80,7 +73,7 @@ public class ThemeHelper {
final private static boolean usesDarkTheme(Context context)
{
boolean useDark = false;
if(couldUseDarkTheme()) {
if(usesHoloTheme() == false) {
SharedPreferences settings = PlaybackService.getSettings(context);
useDark = settings.getBoolean(PrefKeys.USE_DARK_THEME, PrefDefaults.USE_DARK_THEME);
}
@ -88,11 +81,10 @@ public class ThemeHelper {
}
/**
* Returns TRUE if this device may use the dark theme
* (eg: running api v21 or later)
* Returns TRUE if this device uses the HOLO (android 4) theme
*/
final public static boolean couldUseDarkTheme() {
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
final public static boolean usesHoloTheme() {
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP);
}
/**
@ -101,15 +93,17 @@ public class ThemeHelper {
* is a big mess
*/
final public static int[] getDefaultCoverColors(Context context) {
int[] colors_holo_yolo = { 0xff000000, 0xff606060, 0xff404040, 0x88000000 };
int[] colors_material_light = { 0xffeeeeee, 0xffd6d7d7, 0xffd6d7d7, 0x55ffffff };
int[] colors_material_dark = { 0xff303030, 0xff606060, 0xff404040, 0x33ffffff };
if (couldUseDarkTheme() == false)
int[] colors_holo_yolo = { 0xff000000, 0xff606060, 0xff404040, 0x88000000 };
int[] colors_material_light = { 0xffeeeeee, 0xffd6d7d7, 0xffd6d7d7, 0x55ffffff };
int[] colors_material_dark = { 0xff303030, 0xff606060, 0xff404040, 0x33ffffff };
int[] colors_marshmallow_light = { 0xfffafafa, 0xffd6d7d7, 0xffd6d7d7, 0x55ffffff };
int[] colors_marshmallow_dark = colors_material_dark;
if (usesHoloTheme()) // pre material device
return colors_holo_yolo;
if (usesDarkTheme(context))
return colors_material_dark;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
return usesDarkTheme(context) ? colors_marshmallow_dark : colors_marshmallow_light;
// else
return colors_material_light;
return usesDarkTheme(context) ? colors_material_dark : colors_material_light;
}
}