diff options
author | Hyunyoung Song <hyunyoungs@google.com> | 2018-12-17 23:38:43 -0800 |
---|---|---|
committer | Hyunyoung Song <hyunyoungs@google.com> | 2018-12-19 17:16:56 -0800 |
commit | a7a9583bb8ffbee7a760c7e6ab8c99f63dddd145 (patch) | |
tree | dd20ded871fbd2b43f373debd69d0a8f7e41cfb7 /src/com/android/launcher3 | |
parent | afe57dd0ef4c3f92e550f7e88c7139ed14670b28 (diff) | |
download | android_packages_apps_Trebuchet-a7a9583bb8ffbee7a760c7e6ab8c99f63dddd145.tar.gz android_packages_apps_Trebuchet-a7a9583bb8ffbee7a760c7e6ab8c99f63dddd145.tar.bz2 android_packages_apps_Trebuchet-a7a9583bb8ffbee7a760c7e6ab8c99f63dddd145.zip |
Remove IconShapeOverride
Bug: 120736782
Change-Id: Iee44f10ff2b9ec447ae74d9ad6a0aa3668c401d6
Diffstat (limited to 'src/com/android/launcher3')
3 files changed, 0 insertions, 225 deletions
diff --git a/src/com/android/launcher3/MainProcessInitializer.java b/src/com/android/launcher3/MainProcessInitializer.java index a2538930e..9692d73b2 100644 --- a/src/com/android/launcher3/MainProcessInitializer.java +++ b/src/com/android/launcher3/MainProcessInitializer.java @@ -20,7 +20,6 @@ import android.content.Context; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.folder.FolderShape; -import com.android.launcher3.graphics.IconShapeOverride; import com.android.launcher3.logging.FileLog; import com.android.launcher3.util.ResourceBasedOverride; @@ -38,7 +37,6 @@ public class MainProcessInitializer implements ResourceBasedOverride { protected void init(Context context) { FileLog.setDir(context.getApplicationContext().getFilesDir()); FeatureFlags.initialize(context); - IconShapeOverride.apply(context); SessionCommitReceiver.applyDefaultUserPrefs(context); FolderShape.init(); } diff --git a/src/com/android/launcher3/graphics/IconShapeOverride.java b/src/com/android/launcher3/graphics/IconShapeOverride.java deleted file mode 100644 index b636c6d47..000000000 --- a/src/com/android/launcher3/graphics/IconShapeOverride.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.launcher3.graphics; - -import static com.android.launcher3.Utilities.getDevicePrefs; - -import android.annotation.TargetApi; -import android.app.AlarmManager; -import android.app.PendingIntent; -import android.app.ProgressDialog; -import android.content.Context; -import android.content.Intent; -import android.content.res.Resources; -import android.os.Build; -import android.os.SystemClock; -import android.provider.Settings; -import android.text.TextUtils; -import android.util.Log; - -import com.android.launcher3.LauncherAppState; -import com.android.launcher3.LauncherModel; -import com.android.launcher3.R; -import com.android.launcher3.Utilities; -import com.android.launcher3.util.LooperExecutor; - -import java.lang.reflect.Field; - -import androidx.annotation.NonNull; -import androidx.preference.ListPreference; -import androidx.preference.Preference; -import androidx.preference.Preference.OnPreferenceChangeListener; - -/** - * Utility class to override shape of {@link android.graphics.drawable.AdaptiveIconDrawable}. - */ -@TargetApi(Build.VERSION_CODES.O) -public class IconShapeOverride { - - private static final String TAG = "IconShapeOverride"; - - public static final String KEY_PREFERENCE = "pref_override_icon_shape"; - - // Time to wait before killing the process this ensures that the progress bar is visible for - // sufficient time so that there is no flicker. - private static final long PROCESS_KILL_DELAY_MS = 1000; - - private static final int RESTART_REQUEST_CODE = 42; // the answer to everything - - public static boolean isSupported(Context context) { - if (!Utilities.ATLEAST_OREO) { - return false; - } - // Only supported when developer settings is enabled - if (Settings.Global.getInt(context.getContentResolver(), - Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 1) { - return false; - } - - try { - if (getSystemResField().get(null) != Resources.getSystem()) { - // Our assumption that mSystem is the system resource is not true. - return false; - } - } catch (Exception e) { - // Ignore, not supported - return false; - } - - return getConfigResId() != 0; - } - - public static void apply(Context context) { - if (!Utilities.ATLEAST_OREO) { - return; - } - String path = getAppliedValue(context); - if (TextUtils.isEmpty(path)) { - return; - } - if (!isSupported(context)) { - return; - } - - // magic - try { - Resources override = - new ResourcesOverride(Resources.getSystem(), getConfigResId(), path); - getSystemResField().set(null, override); - } catch (Exception e) { - Log.e(TAG, "Unable to override icon shape", e); - // revert value. - getDevicePrefs(context).edit().remove(KEY_PREFERENCE).apply(); - } - } - - private static Field getSystemResField() throws Exception { - Field staticField = Resources.class.getDeclaredField("mSystem"); - staticField.setAccessible(true); - return staticField; - } - - private static int getConfigResId() { - return Resources.getSystem().getIdentifier("config_icon_mask", "string", "android"); - } - - private static String getAppliedValue(Context context) { - return getDevicePrefs(context).getString(KEY_PREFERENCE, ""); - } - - public static void handlePreferenceUi(ListPreference preference) { - Context context = preference.getContext(); - preference.setValue(getAppliedValue(context)); - preference.setOnPreferenceChangeListener(new PreferenceChangeHandler(context)); - } - - private static class ResourcesOverride extends Resources { - - private final int mOverrideId; - private final String mOverrideValue; - - @SuppressWarnings("deprecation") - public ResourcesOverride(Resources parent, int overrideId, String overrideValue) { - super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration()); - mOverrideId = overrideId; - mOverrideValue = overrideValue; - } - - @NonNull - @Override - public String getString(int id) throws NotFoundException { - if (id == mOverrideId) { - return mOverrideValue; - } - return super.getString(id); - } - } - - private static class PreferenceChangeHandler implements OnPreferenceChangeListener { - - private final Context mContext; - - private PreferenceChangeHandler(Context context) { - mContext = context; - } - - @Override - public boolean onPreferenceChange(Preference preference, Object o) { - String newValue = (String) o; - if (!getAppliedValue(mContext).equals(newValue)) { - // Value has changed - ProgressDialog.show(mContext, - null /* title */, - mContext.getString(R.string.icon_shape_override_progress), - true /* indeterminate */, - false /* cancelable */); - new LooperExecutor(LauncherModel.getWorkerLooper()).execute( - new OverrideApplyHandler(mContext, newValue)); - } - return false; - } - } - - private static class OverrideApplyHandler implements Runnable { - - private final Context mContext; - private final String mValue; - - private OverrideApplyHandler(Context context, String value) { - mContext = context; - mValue = value; - } - - @Override - public void run() { - // Synchronously write the preference. - getDevicePrefs(mContext).edit().putString(KEY_PREFERENCE, mValue).commit(); - // Clear the icon cache. - LauncherAppState.getInstance(mContext).getIconCache().clear(); - - // Wait for it - try { - Thread.sleep(PROCESS_KILL_DELAY_MS); - } catch (Exception e) { - Log.e(TAG, "Error waiting", e); - } - - // Schedule an alarm before we kill ourself. - Intent homeIntent = new Intent(Intent.ACTION_MAIN) - .addCategory(Intent.CATEGORY_HOME) - .setPackage(mContext.getPackageName()) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - PendingIntent pi = PendingIntent.getActivity(mContext, RESTART_REQUEST_CODE, - homeIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); - mContext.getSystemService(AlarmManager.class).setExact( - AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 50, pi); - - // Kill process - android.os.Process.killProcess(android.os.Process.myPid()); - } - } -} diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index 77682e55e..6e7188f3c 100644 --- a/src/com/android/launcher3/settings/SettingsActivity.java +++ b/src/com/android/launcher3/settings/SettingsActivity.java @@ -32,11 +32,9 @@ import com.android.launcher3.LauncherFiles; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; -import com.android.launcher3.graphics.IconShapeOverride; import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; import com.android.launcher3.util.SecureSettingsObserver; -import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragment; import androidx.preference.PreferenceFragment.OnPreferenceStartFragmentCallback; @@ -185,13 +183,6 @@ public class SettingsActivity extends Activity case ADD_ICON_PREFERENCE_KEY: return Utilities.ATLEAST_OREO; - case IconShapeOverride.KEY_PREFERENCE: - if (!IconShapeOverride.isSupported(getActivity())) { - return false; - } - IconShapeOverride.handlePreferenceUi((ListPreference) preference); - return true; - case ALLOW_ROTATION_PREFERENCE_KEY: if (getResources().getBoolean(R.bool.allow_rotation)) { // Launcher supports rotation by default. No need to show this setting. |