diff options
Diffstat (limited to 'core/java/android/content/res')
| -rw-r--r-- | core/java/android/content/res/IThemeChangeListener.aidl | 22 | ||||
| -rw-r--r-- | core/java/android/content/res/IThemeProcessingListener.aidl | 21 | ||||
| -rw-r--r-- | core/java/android/content/res/IThemeService.aidl | 43 | ||||
| -rw-r--r-- | core/java/android/content/res/ThemeChangeRequest.aidl | 19 | ||||
| -rw-r--r-- | core/java/android/content/res/ThemeChangeRequest.java | 307 | ||||
| -rw-r--r-- | core/java/android/content/res/ThemeConfig.java | 52 | ||||
| -rw-r--r-- | core/java/android/content/res/ThemeManager.java | 316 |
7 files changed, 16 insertions, 764 deletions
diff --git a/core/java/android/content/res/IThemeChangeListener.aidl b/core/java/android/content/res/IThemeChangeListener.aidl deleted file mode 100644 index a2e2abd..0000000 --- a/core/java/android/content/res/IThemeChangeListener.aidl +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2014 The CyanogenMod 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 android.content.res; - -/** {@hide} */ -oneway interface IThemeChangeListener { - void onProgress(int progress); - void onFinish(boolean isSuccess); -} diff --git a/core/java/android/content/res/IThemeProcessingListener.aidl b/core/java/android/content/res/IThemeProcessingListener.aidl deleted file mode 100644 index 2e1c16e..0000000 --- a/core/java/android/content/res/IThemeProcessingListener.aidl +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2014 The CyanogenMod 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 android.content.res; - -/** {@hide} */ -oneway interface IThemeProcessingListener { - void onFinishedProcessing(String pkgName); -} diff --git a/core/java/android/content/res/IThemeService.aidl b/core/java/android/content/res/IThemeService.aidl deleted file mode 100644 index 90cb9fb..0000000 --- a/core/java/android/content/res/IThemeService.aidl +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2014 The CyanogenMod 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 android.content.res; - -import android.content.res.IThemeChangeListener; -import android.content.res.IThemeProcessingListener; -import android.content.res.ThemeChangeRequest; -import android.graphics.Bitmap; - -import java.util.Map; - -/** {@hide} */ -interface IThemeService { - void requestThemeChangeUpdates(in IThemeChangeListener listener); - void removeUpdates(in IThemeChangeListener listener); - - void requestThemeChange(in ThemeChangeRequest request, boolean removePerAppThemes); - void applyDefaultTheme(); - boolean isThemeApplying(); - int getProgress(); - - boolean cacheComposedIcon(in Bitmap icon, String path); - - boolean processThemeResources(String themePkgName); - boolean isThemeBeingProcessed(String themePkgName); - void registerThemeProcessingListener(in IThemeProcessingListener listener); - void unregisterThemeProcessingListener(in IThemeProcessingListener listener); - - void rebuildResourceCache(); -} diff --git a/core/java/android/content/res/ThemeChangeRequest.aidl b/core/java/android/content/res/ThemeChangeRequest.aidl deleted file mode 100644 index e6cf115..0000000 --- a/core/java/android/content/res/ThemeChangeRequest.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2015 The CyanogenMod 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 android.content.res; - -/** @hide */ -parcelable ThemeChangeRequest; diff --git a/core/java/android/content/res/ThemeChangeRequest.java b/core/java/android/content/res/ThemeChangeRequest.java deleted file mode 100644 index 1d13bb0..0000000 --- a/core/java/android/content/res/ThemeChangeRequest.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (C) 2015 The CyanogenMod 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 android.content.res; - -import android.content.pm.ThemeUtils; -import android.os.Parcel; -import android.os.Parcelable; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - - -import static android.provider.ThemesContract.ThemesColumns.*; - -/** @hide */ -public final class ThemeChangeRequest implements Parcelable { - public static final int DEFAULT_WALLPAPER_ID = -1; - - private final Map<String, String> mThemeComponents = new HashMap<String, String>(); - private final Map<String, String> mPerAppOverlays = new HashMap<String, String>(); - private RequestType mRequestType; - private long mWallpaperId = -1; - - public String getOverlayThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_OVERLAYS); - } - - public String getStatusBarThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_STATUS_BAR); - } - - public String getNavBarThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_NAVIGATION_BAR); - } - - public String getFontThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_FONTS); - } - - public String getIconsThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_ICONS); - } - - public String getBootanimationThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_BOOT_ANIM); - } - - public String getWallpaperThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_LAUNCHER); - } - - public String getLockWallpaperThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_LOCKSCREEN); - } - - public String getAlarmThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_ALARMS); - } - - public String getNotificationThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_NOTIFICATIONS); - } - - public String getRingtoneThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_RINGTONES); - } - - public String getLiveLockScreenThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_LIVE_LOCK_SCREEN); - } - - public final Map<String, String> getThemeComponentsMap() { - return Collections.unmodifiableMap(mThemeComponents); - } - - public long getWallpaperId() { - return mWallpaperId; - } - - /** - * Get the mapping for per app themes - * @return A mapping of apps and the theme to apply for each one. or null if none set. - */ - public final Map<String, String> getPerAppOverlays() { - return Collections.unmodifiableMap(mPerAppOverlays); - } - - public int getNumChangesRequested() { - return mThemeComponents.size() + mPerAppOverlays.size(); - } - - public RequestType getReqeustType() { - return mRequestType; - } - - private String getThemePackageNameForComponent(String componentName) { - return mThemeComponents.get(componentName); - } - - private ThemeChangeRequest(Map<String, String> components, Map<String, String> perAppThemes, - RequestType requestType, long wallpaperId) { - if (components != null) { - mThemeComponents.putAll(components); - } - if (perAppThemes != null) { - mPerAppOverlays.putAll(perAppThemes); - } - mRequestType = requestType; - mWallpaperId = wallpaperId; - } - - private ThemeChangeRequest(Parcel source) { - int numComponents = source.readInt(); - for (int i = 0; i < numComponents; i++) { - mThemeComponents.put(source.readString(), source.readString()); - } - - numComponents = source.readInt(); - for (int i = 0 ; i < numComponents; i++) { - mPerAppOverlays.put(source.readString(), source.readString()); - } - mRequestType = RequestType.values()[source.readInt()]; - mWallpaperId = source.readLong(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mThemeComponents.size()); - for (String component : mThemeComponents.keySet()) { - dest.writeString(component); - dest.writeString(mThemeComponents.get(component)); - } - dest.writeInt((mPerAppOverlays.size())); - for (String appPkgName : mPerAppOverlays.keySet()) { - dest.writeString(appPkgName); - dest.writeString(mPerAppOverlays.get(appPkgName)); - } - dest.writeInt(mRequestType.ordinal()); - dest.writeLong(mWallpaperId); - } - - public static final Parcelable.Creator<ThemeChangeRequest> CREATOR = - new Parcelable.Creator<ThemeChangeRequest>() { - @Override - public ThemeChangeRequest createFromParcel(Parcel source) { - return new ThemeChangeRequest(source); - } - - @Override - public ThemeChangeRequest[] newArray(int size) { - return new ThemeChangeRequest[size]; - } - }; - - public enum RequestType { - USER_REQUEST, - USER_REQUEST_MIXNMATCH, - THEME_UPDATED, - THEME_REMOVED, - THEME_RESET; - } - - public static class Builder { - Map<String, String> mThemeComponents = new HashMap<String, String>(); - Map<String, String> mPerAppOverlays = new HashMap<String, String>(); - RequestType mRequestType = RequestType.USER_REQUEST; - long mWallpaperId; - - public Builder() {} - - public Builder(ThemeConfig themeConfig) { - if (themeConfig != null) { - buildChangeRequestFromThemeConfig(themeConfig); - } - } - - public Builder setOverlay(String pkgName) { - return setComponent(MODIFIES_OVERLAYS, pkgName); - } - - public Builder setStatusBar(String pkgName) { - return setComponent(MODIFIES_STATUS_BAR, pkgName); - } - - public Builder setNavBar(String pkgName) { - return setComponent(MODIFIES_NAVIGATION_BAR, pkgName); - } - - public Builder setFont(String pkgName) { - return setComponent(MODIFIES_FONTS, pkgName); - } - - public Builder setIcons(String pkgName) { - return setComponent(MODIFIES_ICONS, pkgName); - } - - public Builder setBootanimation(String pkgName) { - return setComponent(MODIFIES_BOOT_ANIM, pkgName); - } - - public Builder setWallpaper(String pkgName) { - return setComponent(MODIFIES_LAUNCHER, pkgName); - } - - // Used in the case that more than one wallpaper exists for a given pkg name - public Builder setWallpaperId(long id) { - mWallpaperId = id; - return this; - } - - public Builder setLockWallpaper(String pkgName) { - return setComponent(MODIFIES_LOCKSCREEN, pkgName); - } - - public Builder setAlarm(String pkgName) { - return setComponent(MODIFIES_ALARMS, pkgName); - } - - public Builder setNotification(String pkgName) { - return setComponent(MODIFIES_NOTIFICATIONS, pkgName); - } - - public Builder setRingtone(String pkgName) { - return setComponent(MODIFIES_RINGTONES, pkgName); - } - - public Builder setLiveLockScreen(String pkgName) { - return setComponent(MODIFIES_LIVE_LOCK_SCREEN, pkgName); - } - - public Builder setComponent(String component, String pkgName) { - if (pkgName != null) { - mThemeComponents.put(component, pkgName); - } else { - mThemeComponents.remove(component); - } - return this; - } - - public Builder setAppOverlay(String appPkgName, String themePkgName) { - if (appPkgName != null) { - if (themePkgName != null) { - mPerAppOverlays.put(appPkgName, themePkgName); - } else { - mPerAppOverlays.remove(appPkgName); - } - } - - return this; - } - - public Builder setRequestType(RequestType requestType) { - mRequestType = requestType != null ? requestType : RequestType.USER_REQUEST; - return this; - } - - public ThemeChangeRequest build() { - return new ThemeChangeRequest(mThemeComponents, mPerAppOverlays, - mRequestType, mWallpaperId); - } - - private void buildChangeRequestFromThemeConfig(ThemeConfig themeConfig) { - if (themeConfig.getFontPkgName() != null) { - this.setFont(themeConfig.getFontPkgName()); - } - if (themeConfig.getIconPackPkgName() != null) { - this.setIcons(themeConfig.getIconPackPkgName()); - } - if (themeConfig.getOverlayPkgName() != null) { - this.setOverlay(themeConfig.getOverlayPkgName()); - } - if (themeConfig.getOverlayForStatusBar() != null) { - this.setStatusBar(themeConfig.getOverlayForStatusBar()); - } - if (themeConfig.getOverlayForNavBar() != null) { - this.setNavBar(themeConfig.getOverlayForNavBar()); - } - - // Check if there are any per-app overlays using this theme - final Map<String, ThemeConfig.AppTheme> themes = themeConfig.getAppThemes(); - for (String appPkgName : themes.keySet()) { - if (ThemeUtils.isPerAppThemeComponent(appPkgName)) { - this.setAppOverlay(appPkgName, themes.get(appPkgName).getOverlayPkgName()); - } - } - } - } -} diff --git a/core/java/android/content/res/ThemeConfig.java b/core/java/android/content/res/ThemeConfig.java index ac95d6b..f304801 100644 --- a/core/java/android/content/res/ThemeConfig.java +++ b/core/java/android/content/res/ThemeConfig.java @@ -1,12 +1,12 @@ /* - * Copyright (C) 2014 The CyanogenMod Project + * Copyright (C) 2016 The CyanogenMod Project * Portions copyright (C) 2014, T-Mobile USA, Inc. * * 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 + * 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, @@ -17,12 +17,13 @@ package android.content.res; import android.content.ContentResolver; -import android.content.res.ThemeChangeRequest.RequestType; import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; import android.provider.Settings; import android.text.TextUtils; +import android.util.ArrayMap; +import android.util.ArraySet; import android.util.JsonReader; import android.util.JsonToken; import android.util.JsonWriter; @@ -34,8 +35,6 @@ import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; import java.util.Map; /** @@ -61,9 +60,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi private static final SystemAppTheme mSystemAppTheme = new SystemAppTheme(); // Maps pkgname to theme (ex com.angry.birds -> red theme) - protected final Map<String, AppTheme> mThemes = new HashMap<String, AppTheme>(); - - private RequestType mLastThemeChangeRequestType = RequestType.USER_REQUEST; + protected final Map<String, AppTheme> mThemes = new ArrayMap<>(); public ThemeConfig(Map<String, AppTheme> appThemes) { mThemes.putAll(appThemes); @@ -111,10 +108,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi return Collections.unmodifiableMap(mThemes); } - public RequestType getLastThemeChangeRequestType() { - return mLastThemeChangeRequestType; - } - private AppTheme getThemeFor(String pkgName) { AppTheme theme = mThemes.get(pkgName); if (theme == null) theme = getDefaultTheme(); @@ -136,12 +129,11 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi ThemeConfig o = (ThemeConfig) object; Map<String, AppTheme> currThemes = (mThemes == null) ? - new HashMap<String, AppTheme>() : mThemes; + new ArrayMap<String, AppTheme>() : mThemes; Map<String, AppTheme> newThemes = (o.mThemes == null) ? - new HashMap<String, AppTheme>() : o.mThemes; + new ArrayMap<String, AppTheme>() : o.mThemes; - return (currThemes.equals(newThemes) && - mLastThemeChangeRequestType == o.mLastThemeChangeRequestType); + return currThemes.equals(newThemes); } return false; } @@ -160,8 +152,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public int hashCode() { int hash = 17; hash = 31 * hash + mThemes.hashCode(); - hash = 31 * hash + (mLastThemeChangeRequestType == null ? 0 : - mLastThemeChangeRequestType.ordinal()); return hash; } @@ -227,7 +217,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public void writeToParcel(Parcel dest, int flags) { String json = JsonSerializer.toJson(this); dest.writeString(json); - dest.writeInt(mLastThemeChangeRequestType.ordinal()); } public static final Parcelable.Creator<ThemeConfig> CREATOR = @@ -235,7 +224,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public ThemeConfig createFromParcel(Parcel source) { String json = source.readString(); ThemeConfig themeConfig = JsonSerializer.fromJson(json); - themeConfig.mLastThemeChangeRequestType = RequestType.values()[source.readInt()]; return themeConfig; } @@ -351,10 +339,9 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public static class Builder { - private HashMap<String, String> mOverlays = new HashMap<String, String>(); - private HashMap<String, String> mIcons = new HashMap<String, String>(); - private HashMap<String, String> mFonts = new HashMap<String, String>(); - private RequestType mLastThemeChangeRequestType = RequestType.USER_REQUEST; + private Map<String, String> mOverlays = new ArrayMap<>(); + private Map<String, String> mIcons = new ArrayMap<>(); + private Map<String, String> mFonts = new ArrayMap<>(); public Builder() {} @@ -366,7 +353,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi mIcons.put(key, appTheme.getIconPackPkgName()); mOverlays.put(key, appTheme.getOverlayPkgName()); } - mLastThemeChangeRequestType = theme.mLastThemeChangeRequestType; } /** @@ -427,18 +413,13 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi return this; } - public Builder setLastThemeChangeRequestType(RequestType requestType) { - mLastThemeChangeRequestType = requestType; - return this; - } - public ThemeConfig build() { - HashSet<String> appPkgSet = new HashSet<String>(); + ArraySet<String> appPkgSet = new ArraySet<>(); appPkgSet.addAll(mOverlays.keySet()); appPkgSet.addAll(mIcons.keySet()); appPkgSet.addAll(mFonts.keySet()); - HashMap<String, AppTheme> appThemes = new HashMap<String, AppTheme>(); + Map<String, AppTheme> appThemes = new ArrayMap<>(); for(String appPkgName : appPkgSet) { String icon = mIcons.get(appPkgName); String overlay = mOverlays.get(appPkgName); @@ -455,7 +436,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi } } ThemeConfig themeConfig = new ThemeConfig(appThemes); - themeConfig.mLastThemeChangeRequestType = mLastThemeChangeRequestType; return themeConfig; } } @@ -506,7 +486,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public static ThemeConfig fromJson(String json) { if (json == null) return null; - HashMap<String, AppTheme> map = new HashMap<String, AppTheme>(); + Map<String, AppTheme> map = new ArrayMap<>(); StringReader reader = null; JsonReader jsonReader = null; try { @@ -582,7 +562,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public static class SystemConfig extends ThemeConfig { public SystemConfig() { - super(new HashMap<String, AppTheme>()); + super(new ArrayMap<String, AppTheme>()); } } @@ -593,7 +573,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi @Override public String toString() { - return "No Theme Applied (Holo)"; + return "No Theme Applied (System)"; } } } diff --git a/core/java/android/content/res/ThemeManager.java b/core/java/android/content/res/ThemeManager.java deleted file mode 100644 index fd05f1e..0000000 --- a/core/java/android/content/res/ThemeManager.java +++ /dev/null @@ -1,316 +0,0 @@ -/* - * Copyright (C) 2014 The CyanogenMod 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 android.content.res; - -import android.content.Context; -import android.content.pm.ThemeUtils; -import android.os.Handler; -import android.os.Looper; -import android.os.RemoteException; -import android.util.Log; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * {@hide} - */ -public class ThemeManager { - private static final String TAG = ThemeManager.class.getName(); - private Context mContext; - private IThemeService mService; - private Handler mHandler; - - private Set<ThemeChangeListener> mChangeListeners = - new HashSet<ThemeChangeListener>(); - - private Set<ThemeProcessingListener> mProcessingListeners = - new HashSet<ThemeProcessingListener>(); - - public ThemeManager(Context context, IThemeService service) { - mContext = context; - mService = service; - mHandler = new Handler(Looper.getMainLooper()); - } - - private final IThemeChangeListener mThemeChangeListener = new IThemeChangeListener.Stub() { - @Override - public void onProgress(final int progress) throws RemoteException { - mHandler.post(new Runnable() { - @Override - public void run() { - synchronized (mChangeListeners) { - List<ThemeChangeListener> listenersToRemove = new ArrayList - <ThemeChangeListener>(); - for (ThemeChangeListener listener : mChangeListeners) { - try { - listener.onProgress(progress); - } catch (Throwable e) { - Log.w(TAG, "Unable to update theme change progress", e); - listenersToRemove.add(listener); - } - } - if (listenersToRemove.size() > 0) { - for (ThemeChangeListener listener : listenersToRemove) { - mChangeListeners.remove(listener); - } - } - } - } - }); - } - - @Override - public void onFinish(final boolean isSuccess) throws RemoteException { - mHandler.post(new Runnable() { - @Override - public void run() { - synchronized (mChangeListeners) { - List<ThemeChangeListener> listenersToRemove = new ArrayList - <ThemeChangeListener>(); - for (ThemeChangeListener listener : mChangeListeners) { - try { - listener.onFinish(isSuccess); - } catch (Throwable e) { - Log.w(TAG, "Unable to update theme change listener", e); - listenersToRemove.add(listener); - } - } - if (listenersToRemove.size() > 0) { - for (ThemeChangeListener listener : listenersToRemove) { - mChangeListeners.remove(listener); - } - } - } - } - }); - } - }; - - private final IThemeProcessingListener mThemeProcessingListener = - new IThemeProcessingListener.Stub() { - @Override - public void onFinishedProcessing(final String pkgName) throws RemoteException { - mHandler.post(new Runnable() { - @Override - public void run() { - synchronized (mProcessingListeners) { - List<ThemeProcessingListener> listenersToRemove = new ArrayList - <ThemeProcessingListener>(); - for (ThemeProcessingListener listener : mProcessingListeners) { - try { - listener.onFinishedProcessing(pkgName); - } catch (Throwable e) { - Log.w(TAG, "Unable to update theme change progress", e); - listenersToRemove.add(listener); - } - } - if (listenersToRemove.size() > 0) { - for (ThemeProcessingListener listener : listenersToRemove) { - mProcessingListeners.remove(listener); - } - } - } - } - }); - } - }; - - - public void addClient(ThemeChangeListener listener) { - synchronized (mChangeListeners) { - if (mChangeListeners.contains(listener)) { - throw new IllegalArgumentException("Client was already added "); - } - if (mChangeListeners.size() == 0) { - try { - mService.requestThemeChangeUpdates(mThemeChangeListener); - } catch (RemoteException e) { - Log.w(TAG, "Unable to register listener", e); - } - } - mChangeListeners.add(listener); - } - } - - public void removeClient(ThemeChangeListener listener) { - synchronized (mChangeListeners) { - mChangeListeners.remove(listener); - if (mChangeListeners.size() == 0) { - try { - mService.removeUpdates(mThemeChangeListener); - } catch (RemoteException e) { - Log.w(TAG, "Unable to remove listener", e); - } - } - } - } - - public void onClientPaused(ThemeChangeListener listener) { - removeClient(listener); - } - - public void onClientResumed(ThemeChangeListener listener) { - addClient(listener); - } - - public void onClientDestroyed(ThemeChangeListener listener) { - removeClient(listener); - } - - /** - * Register a ThemeProcessingListener to be notified when a theme is done being processed. - * @param listener ThemeChangeListener to register - */ - public void registerProcessingListener(ThemeProcessingListener listener) { - synchronized (mProcessingListeners) { - if (mProcessingListeners.contains(listener)) { - throw new IllegalArgumentException("Listener was already added "); - } - if (mProcessingListeners.size() == 0) { - try { - mService.registerThemeProcessingListener(mThemeProcessingListener); - } catch (RemoteException e) { - Log.w(TAG, "Unable to register listener", e); - } - } - mProcessingListeners.add(listener); - } - } - - /** - * Unregister a ThemeChangeListener. - * @param listener ThemeChangeListener to unregister - */ - public void unregisterProcessingListener(ThemeChangeListener listener) { - synchronized (mProcessingListeners) { - mProcessingListeners.remove(listener); - if (mProcessingListeners.size() == 0) { - try { - mService.unregisterThemeProcessingListener(mThemeProcessingListener); - } catch (RemoteException e) { - Log.w(TAG, "Unable to remove listener", e); - } - } - } - } - - /** - * Convenience method. Applies the entire theme. - */ - public void requestThemeChange(String pkgName) { - //List<String> components = ThemeUtils.getSupportedComponents(mContext, pkgName); - //requestThemeChange(pkgName, components); - } - - public void requestThemeChange(String pkgName, List<String> components) { - requestThemeChange(pkgName, components, true); - } - - public void requestThemeChange(String pkgName, List<String> components, - boolean removePerAppThemes) { - Map<String, String> componentMap = new HashMap<String, String>(components.size()); - for (String component : components) { - componentMap.put(component, pkgName); - } - requestThemeChange(componentMap, removePerAppThemes); - } - - public void requestThemeChange(Map<String, String> componentMap) { - requestThemeChange(componentMap, true); - } - - public void requestThemeChange(Map<String, String> componentMap, boolean removePerAppThemes) { - ThemeChangeRequest.Builder builder = new ThemeChangeRequest.Builder(); - for (String component : componentMap.keySet()) { - builder.setComponent(component, componentMap.get(component)); - } - - requestThemeChange(builder.build(), removePerAppThemes); - } - - public void requestThemeChange(ThemeChangeRequest request, boolean removePerAppThemes) { - try { - mService.requestThemeChange(request, removePerAppThemes); - } catch (RemoteException e) { - logThemeServiceException(e); - } - } - - public void applyDefaultTheme() { - try { - mService.applyDefaultTheme(); - } catch (RemoteException e) { - logThemeServiceException(e); - } - } - - public boolean isThemeApplying() { - try { - return mService.isThemeApplying(); - } catch (RemoteException e) { - logThemeServiceException(e); - } - - return false; - } - - public boolean isThemeBeingProcessed(String themePkgName) { - try { - return mService.isThemeBeingProcessed(themePkgName); - } catch (RemoteException e) { - logThemeServiceException(e); - } - return false; - } - - public int getProgress() { - try { - return mService.getProgress(); - } catch (RemoteException e) { - logThemeServiceException(e); - } - return -1; - } - - public boolean processThemeResources(String themePkgName) { - try { - return mService.processThemeResources(themePkgName); - } catch (RemoteException e) { - logThemeServiceException(e); - } - return false; - } - - private void logThemeServiceException(Exception e) { - Log.w(TAG, "Unable to access ThemeService", e); - } - - public interface ThemeChangeListener { - void onProgress(int progress); - void onFinish(boolean isSuccess); - } - - public interface ThemeProcessingListener { - void onFinishedProcessing(String pkgName); - } -} - |
