summaryrefslogtreecommitdiffstats
path: root/src/com/cyngn
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-03-18 17:33:31 -0700
committerd34d <clark@cyngn.com>2015-03-18 17:33:31 -0700
commita503d05a5e142b94676724b527fb1b9cce8a2980 (patch)
tree85625887882a2f0aa1d8ff9ef96493ccbbf01973 /src/com/cyngn
parent44c6c629812051d4d1561efdb07b569ea2c1abec (diff)
downloadpackages_apps_ThemeChooser-a503d05a5e142b94676724b527fb1b9cce8a2980.zip
packages_apps_ThemeChooser-a503d05a5e142b94676724b527fb1b9cce8a2980.tar.gz
packages_apps_ThemeChooser-a503d05a5e142b94676724b527fb1b9cce8a2980.tar.bz2
App Themer: Observe changes to themes database
Change-Id: Ib61eedfaa50e9e6cfbba1e51ad4e3cea2b856edc REF: CHOOSER-62
Diffstat (limited to 'src/com/cyngn')
-rw-r--r--src/com/cyngn/theme/perapptheming/PerAppThemingWindow.java38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/com/cyngn/theme/perapptheming/PerAppThemingWindow.java b/src/com/cyngn/theme/perapptheming/PerAppThemingWindow.java
index d33e7ed..84f43de 100644
--- a/src/com/cyngn/theme/perapptheming/PerAppThemingWindow.java
+++ b/src/com/cyngn/theme/perapptheming/PerAppThemingWindow.java
@@ -14,8 +14,10 @@ import android.content.res.Resources;
import android.content.res.ThemeChangeRequest;
import android.content.res.ThemeConfig;
import android.content.res.ThemeManager;
+import android.database.ContentObserver;
import android.database.Cursor;
import android.graphics.PixelFormat;
+import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.provider.ThemesContract.ThemesColumns;
@@ -168,6 +170,8 @@ public class PerAppThemingWindow extends Service implements OnTouchListener,
final Configuration config = getResources().getConfiguration();
mThemeConfig = config != null ? config.themeConfig : null;
loadThemes();
+ getContentResolver().registerContentObserver(ThemesColumns.CONTENT_URI, true,
+ mThemesObserver);
}
@Override
@@ -302,6 +306,10 @@ public class PerAppThemingWindow extends Service implements OnTouchListener,
unregisterReceiver(mBroadcastReceiver);
mBroadcastReceiver = null;
}
+ if (mThemesObserver != null) {
+ getContentResolver().unregisterContentObserver(mThemesObserver);
+ mThemesObserver = null;
+ }
}
@Override
@@ -551,18 +559,37 @@ public class PerAppThemingWindow extends Service implements OnTouchListener,
private void loadThemes() {
String[] columns = {ThemesColumns._ID, ThemesColumns.TITLE, ThemesColumns.PKG_NAME};
- String selection = ThemesColumns.MODIFIES_OVERLAYS + "=?";
- String[] selectionArgs = {"1"};
+ String selection = ThemesColumns.MODIFIES_OVERLAYS + "=? AND " +
+ ThemesColumns.INSTALL_STATE + "=?";
+ String[] selectionArgs = {"1", "" + ThemesColumns.InstallState.INSTALLED};
String sortOrder = ThemesColumns.TITLE + " ASC";
Cursor c = getContentResolver().query(ThemesColumns.CONTENT_URI, columns, selection,
selectionArgs, sortOrder);
if (c != null) {
- mAdapter = new ThemesAdapter(this, c);
- mThemeList.setAdapter(mAdapter);
- mThemeList.setOnItemClickListener(mThemeClickedListener);
+ if (mAdapter == null) {
+ mAdapter = new ThemesAdapter(this, c);
+ mThemeList.setAdapter(mAdapter);
+ mThemeList.setOnItemClickListener(mThemeClickedListener);
+ } else {
+ String pkgName = (String) mAdapter.getItem(0);
+ mAdapter.populateThemes(c);
+ mAdapter.setCurrentTheme(pkgName);
+ }
}
}
+ private ContentObserver mThemesObserver = new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ onChange(selfChange, null);
+ }
+
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ loadThemes();
+ }
+ };
+
private void showThemeList(final int listSide) {
if (mListLayoutParams == null) {
mListLayoutParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
@@ -955,6 +982,7 @@ public class PerAppThemingWindow extends Service implements OnTouchListener,
}
private void populateThemes(Cursor cursor) {
+ mThemes.clear();
while(cursor.moveToNext()) {
ThemeInfo info = new ThemeInfo(
cursor.getString(cursor.getColumnIndex(ThemesColumns.PKG_NAME)),