Merge "Remove inifinite recursion from PagedView" into ub-launcher3-burnaby
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5f9d7f4..03e9bbf 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -45,10 +45,6 @@
android:protectionLevel="signature"
/>
<permission
- android:name="com.android.launcher3.permission.RECEIVE_UPDATE_ORIENTATION_BROADCASTS"
- android:protectionLevel="signature"
- />
- <permission
android:name="com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST"
android:protectionLevel="signatureOrSystem" />
@@ -66,7 +62,6 @@
<uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS" />
<uses-permission android:name="com.android.launcher3.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.android.launcher3.permission.RECEIVE_LAUNCH_BROADCASTS" />
- <uses-permission android:name="com.android.launcher3.permission.RECEIVE_UPDATE_ORIENTATION_BROADCASTS" />
<uses-permission android:name="com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST" />
<application
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
index 9415941..d9bfc30 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -1147,6 +1147,6 @@
return true;
// Check if the user has specifically enabled rotation via preferences.
- return Utilities.isAllowRotationPrefEnabled(getApplicationContext());
+ return Utilities.isAllowRotationPrefEnabled(getApplicationContext(), true);
}
}
diff --git a/proguard.flags b/proguard.flags
index 5e2c384..7ec488b 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -44,7 +44,7 @@
public void setBrightness(int);
}
--keep class com.android.launcher3.AppsContainerRecyclerView {
+-keep class com.android.launcher3.BaseRecyclerView {
public void setFastScrollerAlpha(float);
public float getFastScrollerAlpha();
}
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 305c310..440a537 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -27,9 +27,6 @@
<!-- Permission to receive the com.android.launcher3.action.LAUNCH intent -->
<string name="receive_launch_broadcasts_permission" translatable="false">com.android.launcher3.permission.RECEIVE_LAUNCH_BROADCASTS</string>
- <!-- Permission to receive the com.android.launcher3.SCREEN_ORIENTATION_PREF_CHANGED intent -->
- <string name="receive_update_orientation_broadcasts_permission" translatable="false">com.android.launcher3.permission.RECEIVE_UPDATE_ORIENTATION_BROADCASTS</string>
-
<!-- Permission to receive the com.android.launcher3.action.FIRST_LOAD_COMPLETE intent -->
<string name="receive_first_load_broadcast_permission" translatable="false">com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST</string>
diff --git a/src/com/android/launcher3/BaseRecyclerView.java b/src/com/android/launcher3/BaseRecyclerView.java
index a207d9a..3a741f2 100644
--- a/src/com/android/launcher3/BaseRecyclerView.java
+++ b/src/com/android/launcher3/BaseRecyclerView.java
@@ -290,6 +290,13 @@
}
/**
+ * Returns the fast scroller alpha.
+ */
+ public float getFastScrollerAlpha() {
+ return mFastScrollAlpha;
+ }
+
+ /**
* Maps the touch (from 0..1) to the adapter position that should be visible.
* <p>Override in each subclass of this base class.
*/
diff --git a/src/com/android/launcher3/ClickShadowView.java b/src/com/android/launcher3/ClickShadowView.java
index 42fafe2..e31d7f7 100644
--- a/src/com/android/launcher3/ClickShadowView.java
+++ b/src/com/android/launcher3/ClickShadowView.java
@@ -96,12 +96,14 @@
float drawableWidth = view.getIcon().getBounds().width();
setTranslationX(leftShift
+ + viewParent.getTranslationX()
+ view.getCompoundPaddingLeft() * view.getScaleX()
+ (iconHSpace - drawableWidth) * view.getScaleX() / 2 /* drawable gap */
+ iconWidth * (1 - view.getScaleX()) / 2 /* gap due to scale */
- mShadowPadding /* extra shadow size */
);
setTranslationY(topShift
+ + viewParent.getTranslationY()
+ view.getPaddingTop() * view.getScaleY() /* drawable gap */
+ view.getHeight() * (1 - view.getScaleY()) / 2 /* gap due to scale */
- mShadowPadding /* extra shadow size */
diff --git a/src/com/android/launcher3/InfoDropTarget.java b/src/com/android/launcher3/InfoDropTarget.java
index 0ede2fc..d93cdcc 100644
--- a/src/com/android/launcher3/InfoDropTarget.java
+++ b/src/com/android/launcher3/InfoDropTarget.java
@@ -16,11 +16,8 @@
package com.android.launcher3;
-import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
-import android.os.Build;
-import android.provider.Settings;
import android.util.AttributeSet;
import com.android.launcher3.compat.UserHandleCompat;
@@ -70,18 +67,8 @@
return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info);
}
- @SuppressWarnings("deprecation")
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean supportsDrop(Context context, Object info) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- return (Settings.Global.getInt(context.getContentResolver(),
- Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) &&
- (info instanceof AppInfo || info instanceof PendingAddItemInfo);
- } else {
- return (Settings.Secure.getInt(context.getContentResolver(),
- Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) &&
- (info instanceof AppInfo || info instanceof PendingAddItemInfo);
- }
+ return info instanceof AppInfo || info instanceof PendingAddItemInfo;
}
@Override
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 796de3f..191fdf4 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -398,29 +398,8 @@
}
private Stats mStats;
-
FocusIndicatorView mFocusHandler;
-
- @Thunk boolean mRotationEnabled = false;
- private boolean mScreenOrientationSettingReceiverRegistered = false;
-
- final private BroadcastReceiver mScreenOrientationSettingReceiver =
- new BroadcastReceiver() {
- @Thunk Runnable mUpdateOrientationRunnable = new Runnable() {
- public void run() {
- setOrientation();
- }
- };
-
- @Override
- public void onReceive(Context context, Intent intent) {
- mRotationEnabled = intent.getBooleanExtra(
- Utilities.SCREEN_ROTATION_SETTING_EXTRA, false);
- if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
- setOrientation();
- }
- }
- };
+ private boolean mRotationEnabled = false;
@Thunk void setOrientation() {
if (mRotationEnabled) {
@@ -431,6 +410,12 @@
}
}
+ private Runnable mUpdateOrientationRunnable = new Runnable() {
+ public void run() {
+ setOrientation();
+ }
+ };
+
@Override
protected void onCreate(Bundle savedInstanceState) {
if (DEBUG_STRICT_MODE) {
@@ -530,13 +515,7 @@
// In case we are on a device with locked rotation, we should look at preferences to check
// if the user has specifically allowed rotation.
if (!mRotationEnabled) {
- String updateOrientationBroadcastPermission = getResources().getString(
- R.string.receive_update_orientation_broadcasts_permission);
- registerReceiver(mScreenOrientationSettingReceiver,
- new IntentFilter(Utilities.SCREEN_ROTATION_SETTING_INTENT),
- updateOrientationBroadcastPermission, null);
- mScreenOrientationSettingReceiverRegistered = true;
- mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
+ mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext(), false);
}
// On large interfaces, or on devices that a user has specifically enabled screen rotation,
@@ -562,6 +541,16 @@
}
}
+ @Override
+ public void onSettingsChanged(String settings, boolean value) {
+ if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
+ mRotationEnabled = value;
+ if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
+ mUpdateOrientationRunnable.run();
+ }
+ }
+ }
+
private LauncherCallbacks mLauncherCallbacks;
public void onPostCreate(Bundle savedInstanceState) {
@@ -2030,11 +2019,6 @@
public void onDestroy() {
super.onDestroy();
- if (mScreenOrientationSettingReceiverRegistered) {
- unregisterReceiver(mScreenOrientationSettingReceiver);
- mScreenOrientationSettingReceiverRegistered = false;
- }
-
// Remove all pending runnables
mHandler.removeMessages(ADVANCE_MSG);
mHandler.removeMessages(0);
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 76ad8c1..540bdf8 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -21,10 +21,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.res.Resources;
import android.util.Log;
-import android.view.ViewConfiguration;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
@@ -48,6 +46,7 @@
private static LauncherAppState INSTANCE;
private InvariantDeviceProfile mInvariantDeviceProfile;
+
private LauncherAccessibilityDelegate mAccessibilityDelegate;
public static LauncherAppState getInstance() {
diff --git a/src/com/android/launcher3/LauncherFiles.java b/src/com/android/launcher3/LauncherFiles.java
index ec4e4f9..c08cd0b 100644
--- a/src/com/android/launcher3/LauncherFiles.java
+++ b/src/com/android/launcher3/LauncherFiles.java
@@ -26,8 +26,6 @@
public static final String WIDGET_PREVIEWS_DB = "widgetpreviews.db";
public static final String APP_ICONS_DB = "app_icons.db";
- public static final String ROTATION_PREF_FILE = "com.android.launcher3.rotation.prefs";
-
public static final List<String> ALL_FILES = Collections.unmodifiableList(Arrays.asList(
DEFAULT_WALLPAPER_THUMBNAIL,
DEFAULT_WALLPAPER_THUMBNAIL_OLD,
@@ -37,8 +35,7 @@
WALLPAPER_IMAGES_DB,
WIDGET_PREVIEWS_DB,
MANAGED_USER_PREFERENCES_KEY,
- APP_ICONS_DB,
- ROTATION_PREF_FILE));
+ APP_ICONS_DB));
// TODO: Delete these files on upgrade
public static final List<String> OBSOLETE_FILES = Collections.unmodifiableList(Arrays.asList(
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index b590126..cb808c2 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -39,8 +39,10 @@
import android.database.sqlite.SQLiteQueryBuilder;
import android.database.sqlite.SQLiteStatement;
import android.net.Uri;
+import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
+import android.os.Process;
import android.os.StrictMode;
import android.os.UserManager;
import android.text.TextUtils;
@@ -237,6 +239,38 @@
return count;
}
+ @Override
+ public Bundle call(String method, String arg, Bundle extras) {
+ if (Binder.getCallingUid() != Process.myUid()) {
+ return null;
+ }
+
+ switch (method) {
+ case LauncherSettings.Settings.METHOD_GET_BOOLEAN: {
+ Bundle result = new Bundle();
+ result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
+ getContext().getSharedPreferences(
+ LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE)
+ .getBoolean(arg, extras.getBoolean(
+ LauncherSettings.Settings.EXTRA_DEFAULT_VALUE)));
+ return result;
+ }
+ case LauncherSettings.Settings.METHOD_SET_BOOLEAN: {
+ boolean value = extras.getBoolean(LauncherSettings.Settings.EXTRA_VALUE);
+ getContext().getSharedPreferences(
+ LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE)
+ .edit().putBoolean(arg, value).apply();
+ if (mListener != null) {
+ mListener.onSettingsChanged(arg, value);
+ }
+ Bundle result = new Bundle();
+ result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, value);
+ return result;
+ }
+ }
+ return null;
+ }
+
private void notifyListeners() {
// always notify the backup agent
LauncherBackupAgentHelper.dataChanged(getContext());
diff --git a/src/com/android/launcher3/LauncherProviderChangeListener.java b/src/com/android/launcher3/LauncherProviderChangeListener.java
index 0de96fb..5b5c6c5 100644
--- a/src/com/android/launcher3/LauncherProviderChangeListener.java
+++ b/src/com/android/launcher3/LauncherProviderChangeListener.java
@@ -8,4 +8,6 @@
public interface LauncherProviderChangeListener {
public void onLauncherProviderChange();
+
+ public void onSettingsChanged(String settings, boolean value);
}
diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java
index 90e60e4..afdb3dd 100644
--- a/src/com/android/launcher3/LauncherSettings.java
+++ b/src/com/android/launcher3/LauncherSettings.java
@@ -305,4 +305,19 @@
*/
static final String OPTIONS = "options";
}
+
+ /**
+ * Launcher settings
+ */
+ public static final class Settings {
+
+ public static final Uri CONTENT_URI = Uri.parse("content://" +
+ ProviderConfig.AUTHORITY + "/settings");
+
+ public static final String METHOD_GET_BOOLEAN = "get_boolean_setting";
+ public static final String METHOD_SET_BOOLEAN = "set_boolean_setting";
+
+ public static final String EXTRA_VALUE = "value";
+ public static final String EXTRA_DEFAULT_VALUE = "default_value";
+ }
}
diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java
index 27763f5..dab71c8 100644
--- a/src/com/android/launcher3/SettingsActivity.java
+++ b/src/com/android/launcher3/SettingsActivity.java
@@ -17,12 +17,11 @@
package com.android.launcher3;
import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
-import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
/**
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
@@ -41,26 +40,36 @@
/**
* This fragment shows the launcher preferences.
*/
- @SuppressWarnings("WeakerAccess")
- public static class LauncherSettingsFragment extends PreferenceFragment {
+ public static class LauncherSettingsFragment extends PreferenceFragment
+ implements OnPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
- getPreferenceManager().setSharedPreferencesName(LauncherFiles.ROTATION_PREF_FILE);
addPreferencesFromResource(R.xml.launcher_preferences);
+
+ SwitchPreference pref = (SwitchPreference) findPreference(
+ Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
+ pref.setPersistent(false);
+
+ Bundle extras = new Bundle();
+ extras.putBoolean(LauncherSettings.Settings.EXTRA_DEFAULT_VALUE, false);
+ Bundle value = getActivity().getContentResolver().call(
+ LauncherSettings.Settings.CONTENT_URI,
+ LauncherSettings.Settings.METHOD_GET_BOOLEAN,
+ Utilities.ALLOW_ROTATION_PREFERENCE_KEY, extras);
+ pref.setChecked(value.getBoolean(LauncherSettings.Settings.EXTRA_VALUE));
+
+ pref.setOnPreferenceChangeListener(this);
}
@Override
- public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
- Preference preference) {
- boolean allowRotation = getPreferenceManager().getSharedPreferences().getBoolean(
- Utilities.ALLOW_ROTATION_PREFERENCE_KEY, false);
- Intent rotationSetting = new Intent(Utilities.SCREEN_ROTATION_SETTING_INTENT);
- String launchBroadcastPermission = getResources().getString(
- R.string.receive_update_orientation_broadcasts_permission);
- rotationSetting.putExtra(Utilities.SCREEN_ROTATION_SETTING_EXTRA, allowRotation);
- getActivity().sendBroadcast(rotationSetting, launchBroadcastPermission);
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Bundle extras = new Bundle();
+ extras.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, (Boolean) newValue);
+ getActivity().getContentResolver().call(
+ LauncherSettings.Settings.CONTENT_URI,
+ LauncherSettings.Settings.METHOD_SET_BOOLEAN,
+ preference.getKey(), extras);
return true;
}
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 0cd980c..2d8a1b1 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -92,17 +92,15 @@
private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
- public static final String SCREEN_ROTATION_SETTING_INTENT =
- "come.android.launcher3.SCREEN_ORIENTATION_PREF_CHANGED";
- public static final String SCREEN_ROTATION_SETTING_EXTRA = "screenRotationPref";
public static boolean isPropertyEnabled(String propertyName) {
return Log.isLoggable(propertyName, Log.VERBOSE);
}
- public static boolean isAllowRotationPrefEnabled(Context context) {
- SharedPreferences sharedPrefs = context.getSharedPreferences(LauncherFiles.ROTATION_PREF_FILE,
- Context.MODE_MULTI_PROCESS);
+ public static boolean isAllowRotationPrefEnabled(Context context, boolean multiProcess) {
+ SharedPreferences sharedPrefs = context.getSharedPreferences(
+ LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE | (multiProcess ?
+ Context.MODE_MULTI_PROCESS : 0));
boolean allowRotationPref = sharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, false);
return sForceEnableRotation || allowRotationPref;
}