Merge changes from topic 'badge-color' into ub-launcher3-master
* changes:
Fix merge conflicts
Use a single color for all icon badges.
diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml
index 565728c..1e82f22 100644
--- a/res/layout-land/launcher.xml
+++ b/res/layout-land/launcher.xml
@@ -32,8 +32,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <include layout="@layout/gradient_scrim" />
-
<!-- The workspace contains 5 screens of cells -->
<!-- DO NOT CHANGE THE ID -->
<com.android.launcher3.Workspace
@@ -44,6 +42,8 @@
android:layout_gravity="center"
launcher:pageIndicator="@id/page_indicator" />
+ <include layout="@layout/gradient_scrim" />
+
<!-- DO NOT CHANGE THE ID -->
<include layout="@layout/hotseat"
android:id="@+id/hotseat"
diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml
index eccb824..c15e53d 100644
--- a/res/layout-port/launcher.xml
+++ b/res/layout-port/launcher.xml
@@ -33,8 +33,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <include layout="@layout/gradient_scrim" />
-
<!-- The workspace contains 5 screens of cells -->
<!-- DO NOT CHANGE THE ID -->
<com.android.launcher3.Workspace
@@ -46,6 +44,8 @@
launcher:pageIndicator="@+id/page_indicator">
</com.android.launcher3.Workspace>
+ <include layout="@layout/gradient_scrim" />
+
<!-- DO NOT CHANGE THE ID -->
<include layout="@layout/hotseat"
android:id="@+id/hotseat"
diff --git a/res/layout-sw720dp/launcher.xml b/res/layout-sw720dp/launcher.xml
index 7fad517..c516c46 100644
--- a/res/layout-sw720dp/launcher.xml
+++ b/res/layout-sw720dp/launcher.xml
@@ -32,8 +32,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <include layout="@layout/gradient_scrim" />
-
<!-- The workspace contains 5 screens of cells -->
<!-- DO NOT CHANGE THE ID -->
<com.android.launcher3.Workspace
@@ -45,6 +43,8 @@
launcher:pageIndicator="@id/page_indicator">
</com.android.launcher3.Workspace>
+ <include layout="@layout/gradient_scrim" />
+
<!-- DO NOT CHANGE THE ID -->
<include layout="@layout/hotseat"
android:id="@+id/hotseat"
diff --git a/res/layout/gradient_scrim.xml b/res/layout/gradient_scrim.xml
index 02c39eb..c40c5fc 100644
--- a/res/layout/gradient_scrim.xml
+++ b/res/layout/gradient_scrim.xml
@@ -15,7 +15,7 @@
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
- <com.android.launcher3.graphics.RadialGradientView
+ <com.android.launcher3.graphics.GradientView
android:id="@+id/gradient_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e840328..f7c4825 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -172,6 +172,12 @@
<string name="allow_rotation_desc">When phone is rotated</string>
<!-- Text explaining that rotation is disabled in Display settings. 'Display' refers to the Display section in system settings [CHAR LIMIT=100] -->
<string name="allow_rotation_blocked_desc">Current Display setting doesn\'t permit rotation</string>
+ <!-- Title for Icon Badging setting. Tapping this will link to the system Notifications Settings screen where the user can turn off badging globally. [CHAR LIMIT=50] -->
+ <string name="icon_badging_title">Icon badging</string>
+ <!-- Text to indicate that the system icon badging setting is on [CHAR LIMIT=100] -->
+ <string name="icon_badging_desc_on">On for all apps</string>
+ <!-- Text to indicate that the system icon badging setting is off [CHAR LIMIT=100] -->
+ <string name="icon_badging_desc_off">Off for all apps</string>
<!-- Label for the setting that allows the automatic placement of launcher shortcuts for applications and games installed on the device [CHAR LIMIT=40] -->
<string name="auto_add_shortcuts_label">Add icon to Home screen</string>
diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml
index 301bef1..8763883 100644
--- a/res/xml/launcher_preferences.xml
+++ b/res/xml/launcher_preferences.xml
@@ -17,13 +17,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
- android:key="pref_allowRotation"
- android:title="@string/allow_rotation_title"
- android:defaultValue="@bool/allow_rotation"
- android:persistent="true"
- />
-
- <SwitchPreference
android:key="pref_add_icon_to_home"
android:title="@string/auto_add_shortcuts_label"
android:summary="@string/auto_add_shortcuts_description"
@@ -40,4 +33,23 @@
android:defaultValue=""
android:persistent="false" />
+ <Preference
+ android:key="pref_icon_badging"
+ android:title="@string/icon_badging_title"
+ android:persistent="false">
+ <intent android:action="android.settings.NOTIFICATION_SETTINGS">
+ <!-- This extra highlights the "Allow icon badges" field in Notification settings -->
+ <extra
+ android:name=":settings:fragment_args_key"
+ android:value="notification_badging" />
+ </intent>
+ </Preference>/>
+
+ <SwitchPreference
+ android:key="pref_allowRotation"
+ android:title="@string/allow_rotation_title"
+ android:defaultValue="@bool/allow_rotation"
+ android:persistent="true"
+ />
+
</PreferenceScreen>
diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java
index 7ae6b26..0902b20 100644
--- a/src/com/android/launcher3/SettingsActivity.java
+++ b/src/com/android/launcher3/SettingsActivity.java
@@ -34,6 +34,11 @@
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
*/
public class SettingsActivity extends Activity {
+
+ private static final String ICON_BADGING_PREFERENCE_KEY = "pref_icon_badging";
+ // TODO: use Settings.Secure.NOTIFICATION_BADGING
+ private static final String NOTIFICATION_BADGING = "notification_badging";
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -50,6 +55,7 @@
public static class LauncherSettingsFragment extends PreferenceFragment {
private SystemDisplayRotationLockObserver mRotationLockObserver;
+ private IconBadgingObserver mIconBadgingObserver;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -57,13 +63,14 @@
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
addPreferencesFromResource(R.xml.launcher_preferences);
+ ContentResolver resolver = getActivity().getContentResolver();
+
// Setup allow rotation preference
Preference rotationPref = findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
if (getResources().getBoolean(R.bool.allow_rotation)) {
// Launcher supports rotation by default. No need to show this setting.
getPreferenceScreen().removePreference(rotationPref);
} else {
- ContentResolver resolver = getActivity().getContentResolver();
mRotationLockObserver = new SystemDisplayRotationLockObserver(rotationPref, resolver);
// Register a content observer to listen for system setting changes while
@@ -77,9 +84,18 @@
rotationPref.setDefaultValue(Utilities.getAllowRotationDefaultValue(getActivity()));
}
+ Preference iconBadgingPref = findPreference(ICON_BADGING_PREFERENCE_KEY);
if (!BuildCompat.isAtLeastO()) {
getPreferenceScreen().removePreference(
findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY));
+ getPreferenceScreen().removePreference(iconBadgingPref);
+ } else {
+ // Listen to system notification badge settings while this UI is active.
+ mIconBadgingObserver = new IconBadgingObserver(iconBadgingPref, resolver);
+ resolver.registerContentObserver(
+ Settings.Secure.getUriFor(NOTIFICATION_BADGING),
+ false, mIconBadgingObserver);
+ mIconBadgingObserver.onChange(true);
}
Preference iconShapeOverride = findPreference(IconShapeOverride.KEY_PREFERENCE);
@@ -98,6 +114,10 @@
getActivity().getContentResolver().unregisterContentObserver(mRotationLockObserver);
mRotationLockObserver = null;
}
+ if (mIconBadgingObserver != null) {
+ getActivity().getContentResolver().unregisterContentObserver(mIconBadgingObserver);
+ mIconBadgingObserver = null;
+ }
super.onDestroy();
}
}
@@ -127,4 +147,29 @@
? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc);
}
}
+
+ /**
+ * Content observer which listens for system badging setting changes,
+ * and updates the launcher badging setting subtext accordingly.
+ */
+ private static class IconBadgingObserver extends ContentObserver {
+
+ private final Preference mBadgingPref;
+ private final ContentResolver mResolver;
+
+ public IconBadgingObserver(Preference badgingPref, ContentResolver resolver) {
+ super(new Handler());
+ mBadgingPref = badgingPref;
+ mResolver = resolver;
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ boolean enabled = Settings.Secure.getInt(mResolver, NOTIFICATION_BADGING, 1) == 1;
+ mBadgingPref.setSummary(enabled
+ ? R.string.icon_badging_desc_on
+ : R.string.icon_badging_desc_off);
+ }
+ }
+
}
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 97aa54a..7c6ff51 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -24,7 +24,7 @@
import com.android.launcher3.Workspace;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dynamicui.ExtractedColors;
-import com.android.launcher3.graphics.RadialGradientView;
+import com.android.launcher3.graphics.GradientView;
import com.android.launcher3.graphics.ScrimView;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@@ -47,7 +47,8 @@
private static final String TAG = "AllAppsTrans";
private static final boolean DBG = false;
- private final Interpolator mAccelInterpolator = new AccelerateInterpolator(2f);
+ private final Interpolator mWorkspaceAccelnterpolator = new AccelerateInterpolator(2f);
+ private final Interpolator mHotseatAccelInterpolator = new AccelerateInterpolator(.5f);
private final Interpolator mDecelInterpolator = new DecelerateInterpolator(3f);
private final Interpolator mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
private final VerticalPullDetector.ScrollInterpolator mScrollInterpolator
@@ -95,7 +96,7 @@
// Used in discovery bounce animation to provide the transition without workspace changing.
private boolean mIsTranslateWithoutWorkspace = false;
private AnimatorSet mDiscoBounceAnimation;
- private RadialGradientView mGradientView;
+ private GradientView mGradientView;
private ScrimView mScrimView;
public AllAppsTransitionController(Launcher l) {
@@ -275,7 +276,7 @@
private void updateAllAppsBg(float progress) {
// gradient
if (mGradientView == null) {
- mGradientView = (RadialGradientView) mLauncher.findViewById(R.id.gradient_bg);
+ mGradientView = (GradientView) mLauncher.findViewById(R.id.gradient_bg);
mGradientView.setVisibility(View.VISIBLE);
onExtractedColorsChanged();
}
@@ -313,7 +314,8 @@
float workspaceHotseatAlpha = Utilities.boundToRange(progress, 0f, 1f);
float alpha = 1 - workspaceHotseatAlpha;
- float interpolation = mAccelInterpolator.getInterpolation(workspaceHotseatAlpha);
+ float workspaceAlpha = mWorkspaceAccelnterpolator.getInterpolation(workspaceHotseatAlpha);
+ float hotseatAlpha = mHotseatAccelInterpolator.getInterpolation(workspaceHotseatAlpha);
int color = (Integer) mEvaluator.evaluate(mDecelInterpolator.getInterpolation(alpha),
mHotseatBackgroundColor, mAllAppsBackgroundColor);
@@ -331,18 +333,18 @@
if (!mLauncher.getDeviceProfile().isVerticalBarLayout()) {
mWorkspace.setHotseatTranslationAndAlpha(Workspace.Direction.Y, -mShiftRange + shiftCurrent,
- interpolation);
+ hotseatAlpha);
} else {
mWorkspace.setHotseatTranslationAndAlpha(Workspace.Direction.Y,
PARALLAX_COEFFICIENT * (-mShiftRange + shiftCurrent),
- interpolation);
+ hotseatAlpha);
}
if (mIsTranslateWithoutWorkspace) {
return;
}
mWorkspace.setWorkspaceYTranslationAndAlpha(
- PARALLAX_COEFFICIENT * (-mShiftRange + shiftCurrent), interpolation);
+ PARALLAX_COEFFICIENT * (-mShiftRange + shiftCurrent), workspaceAlpha);
if (!mDetector.isDraggingState()) {
mContainerVelocity = mDetector.computeVelocity(shiftCurrent - shiftPrevious,
diff --git a/src/com/android/launcher3/graphics/RadialGradientView.java b/src/com/android/launcher3/graphics/GradientView.java
similarity index 65%
rename from src/com/android/launcher3/graphics/RadialGradientView.java
rename to src/com/android/launcher3/graphics/GradientView.java
index cf6851c..c5b7693 100644
--- a/src/com/android/launcher3/graphics/RadialGradientView.java
+++ b/src/com/android/launcher3/graphics/GradientView.java
@@ -27,7 +27,8 @@
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
-import android.view.animation.DecelerateInterpolator;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.Interpolator;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
@@ -36,63 +37,50 @@
* Draws a translucent radial gradient background from an initial state with progress 0.0 to a
* final state with progress 1.0;
*/
-public class RadialGradientView extends View {
+public class GradientView extends View {
- public static final int DEFAULT_COLOR_1 = Color.WHITE;
- public static final int DEFAULT_COLOR_2 = Color.BLACK;
+ private static final int DEFAULT_COLOR = Color.WHITE;
+ private static final float GRADIENT_ALPHA_MASK_LENGTH_DP = 300;
+ private static final float FINAL_GRADIENT_ALPHA = 0.75f;
+ private static final boolean DEBUG = false;
private static Bitmap sFinalGradientMask;
private static Bitmap sAlphaGradientMask;
- // TODO needs to be cleaned up once design finalizes
- static class Config {
- // dimens
- final float gradientCenterX = 0.5f;
- final float gradientCenterY = 1.05f;
- final float gradientHeadStartFactor = 0.35f;
- final float gradientAlphaMaskLengthDp = 700;
- // interpolation
- final boolean useGradientAlphaDecel = false;
- final float decelFactorForGradientAlpha = 2f;
- // colors
- final float finalGradientAlpha = 0.75f;
- int color1 = DEFAULT_COLOR_1;
- int color2 = DEFAULT_COLOR_2;
- }
-
+ private int mColor1 = DEFAULT_COLOR;
+ private int mColor2 = DEFAULT_COLOR;
+ private int mWidth;
+ private int mHeight;
private final RectF mAlphaMaskRect = new RectF();
private final RectF mFinalMaskRect = new RectF();
private final Paint mPaint = new Paint();
- private final Config mConfig = new Config();
- private final DecelerateInterpolator mDecelInterpolator;
private float mProgress;
- private int mWidth;
- private int mHeight;
private final int mMaskHeight;
private final Context mAppContext;
+ private final Paint mDebugPaint = DEBUG ? new Paint() : null;
+ private final Interpolator mAccelerator = new AccelerateInterpolator();
- public RadialGradientView(Context context, AttributeSet attrs) {
+ public GradientView(Context context, AttributeSet attrs) {
super(context, attrs);
this.mAppContext = context.getApplicationContext();
- this.mDecelInterpolator = new DecelerateInterpolator(mConfig.decelFactorForGradientAlpha);
- this.mMaskHeight = Utilities.pxFromDp(mConfig.gradientAlphaMaskLengthDp,
+ this.mMaskHeight = Utilities.pxFromDp(GRADIENT_ALPHA_MASK_LENGTH_DP,
mAppContext.getResources().getDisplayMetrics());
if (sFinalGradientMask == null) {
sFinalGradientMask = Utilities.convertToAlphaMask(
- Utilities.createOnePixBitmap(), mConfig.finalGradientAlpha);
+ Utilities.createOnePixBitmap(), FINAL_GRADIENT_ALPHA);
}
if (sAlphaGradientMask == null) {
Bitmap alphaMaskFromResource = BitmapFactory.decodeResource(context.getResources(),
R.drawable.all_apps_alpha_mask);
sAlphaGradientMask = Utilities.convertToAlphaMask(
- alphaMaskFromResource, mConfig.finalGradientAlpha);
+ alphaMaskFromResource, FINAL_GRADIENT_ALPHA);
}
}
public void onExtractedColorsChanged(int color1, int color2) {
- mConfig.color1 = color1;
- mConfig.color2 = color2;
+ this.mColor1 = color1;
+ this.mColor2 = color2;
if (mWidth + mHeight > 0) {
createRadialShader();
}
@@ -110,14 +98,15 @@
// only being called when colors change
private void createRadialShader() {
- float radius = Math.max(mHeight, mWidth) * mConfig.gradientCenterY;
+ final float gradientCenterY = 1.05f;
+ float radius = Math.max(mHeight, mWidth) * gradientCenterY;
float posScreenBottom = (radius - mHeight) / radius; // center lives below screen
RadialGradient shader = new RadialGradient(
- mWidth * mConfig.gradientCenterX,
- mHeight * mConfig.gradientCenterY,
+ mWidth * 0.5f,
+ mHeight * gradientCenterY,
radius,
- new int[] {mConfig.color1, mConfig.color1, mConfig.color2},
+ new int[] {mColor1, mColor1, mColor2},
new float[] {0f, posScreenBottom, 1f},
Shader.TileMode.CLAMP);
mPaint.setShader(shader);
@@ -130,17 +119,22 @@
@Override
protected void onDraw(Canvas canvas) {
- float head = mConfig.gradientHeadStartFactor;
+ float head = 0.29f;
float linearProgress = head + (mProgress * (1f - head));
- float adjustProgress = mConfig.useGradientAlphaDecel
- ? mDecelInterpolator.getInterpolation(linearProgress)
- : linearProgress;
- float startMaskY = (1f - adjustProgress) * mHeight - mMaskHeight * adjustProgress;
-
+ float startMaskY = (1f - linearProgress) * mHeight - mMaskHeight * linearProgress;
+ float startAlpha = 100;
+ float interpolatedAlpha = (255 - startAlpha) * mAccelerator.getInterpolation(mProgress);
+ mPaint.setAlpha((int) (startAlpha + interpolatedAlpha));
mAlphaMaskRect.set(0, startMaskY, mWidth, startMaskY + mMaskHeight);
mFinalMaskRect.set(0, startMaskY + mMaskHeight, mWidth, mHeight);
canvas.drawBitmap(sAlphaGradientMask, null, mAlphaMaskRect, mPaint);
canvas.drawBitmap(sFinalGradientMask, null, mFinalMaskRect, mPaint);
+
+ if (DEBUG) {
+ mDebugPaint.setColor(0xFF00FF00);
+ canvas.drawLine(0, startMaskY, mWidth, startMaskY, mDebugPaint);
+ canvas.drawLine(0, startMaskY + mMaskHeight, mWidth, startMaskY + mMaskHeight, mDebugPaint);
+ }
}
}
\ No newline at end of file
diff --git a/src/com/android/launcher3/graphics/ScrimView.java b/src/com/android/launcher3/graphics/ScrimView.java
index 521fbed..feb3f03 100644
--- a/src/com/android/launcher3/graphics/ScrimView.java
+++ b/src/com/android/launcher3/graphics/ScrimView.java
@@ -26,18 +26,22 @@
import android.support.v4.graphics.ColorUtils;
import android.util.AttributeSet;
import android.view.View;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.Interpolator;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
public class ScrimView extends View {
- // Config
- private static final int MASK_HEIGHT_DP = 600;
- private static final float MASK_START_LENGTH_FACTOR = 0.4f;
+ private static final boolean DEBUG = false;
+
+ private static final int MASK_HEIGHT_DP = 300;
+ private static final float MASK_START_LENGTH_FACTOR = 1f;
private static final float FINAL_ALPHA = 0.87f;
private static final int SCRIM_COLOR = ColorUtils.setAlphaComponent(
Color.WHITE, (int) (FINAL_ALPHA * 255));
+ private static final boolean APPLY_ALPHA = true;
private static Bitmap sFinalScrimMask;
private static Bitmap sAlphaScrimMask;
@@ -50,6 +54,8 @@
private final RectF mFinalMaskRect = new RectF();
private final Paint mPaint = new Paint();
private float mProgress;
+ private final Interpolator mAccelerator = new AccelerateInterpolator();
+ private final Paint mDebugPaint = DEBUG ? new Paint() : null;
public ScrimView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -73,17 +79,22 @@
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
mVisibleHeight = MeasureSpec.getSize(heightMeasureSpec);
- int fullHeight = mVisibleHeight * 2 + mMaskHeight;
- setMeasuredDimension(width, fullHeight);
+ setMeasuredDimension(width, mVisibleHeight * 2);
setProgress(mProgress);
}
public void setProgress(float progress) {
mProgress = progress;
float initialY = mVisibleHeight - mHeadStart;
- float fullTranslationY = mMaskHeight + initialY + mVisibleHeight;
- float translationY = initialY - progress * fullTranslationY;
- setTranslationY(translationY);
+ float fullTranslationY = mVisibleHeight;
+ float linTranslationY = initialY - progress * fullTranslationY;
+ setTranslationY(linTranslationY);
+
+ if (APPLY_ALPHA) {
+ int alpha = 55 + (int) (200f * mAccelerator.getInterpolation(progress));
+ mPaint.setAlpha(alpha);
+ invalidate();
+ }
}
@Override
@@ -92,6 +103,12 @@
mFinalMaskRect.set(0, mMaskHeight, getWidth(), getHeight());
canvas.drawBitmap(sAlphaScrimMask, null, mAlphaMaskRect, mPaint);
canvas.drawBitmap(sFinalScrimMask, null, mFinalMaskRect, mPaint);
+
+ if (DEBUG) {
+ mDebugPaint.setColor(0xFF0000FF);
+ canvas.drawLine(0, mAlphaMaskRect.top, getWidth(), mAlphaMaskRect.top, mDebugPaint);
+ canvas.drawLine(0, mAlphaMaskRect.bottom, getWidth(), mAlphaMaskRect.bottom, mDebugPaint);
+ }
}
}