Re-add theming, much better this time

This commit is contained in:
Daniel Martí 2013-11-03 16:12:22 +01:00
parent 5d57711fcb
commit a76a465cf1
15 changed files with 136 additions and 11 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ build.properties
bin/* bin/*
gen/* gen/*
proguard.cfg proguard.cfg
build.xml
*~ *~
.idea .idea
*.iml *.iml

View File

@ -31,6 +31,7 @@
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:allowBackup="true" android:allowBackup="true"
android:theme="@style/AppThemeDark"
android:supportsRtl="false" > android:supportsRtl="false" >
<activity <activity
android:name=".FDroid" android:name=".FDroid"

View File

@ -1,5 +1,6 @@
### Future release ### Future release
* Add theming with Light and Dark themes
* New launcher and notification icons * New launcher and notification icons
* New default/loading app icon * New default/loading app icon
* List anti-features on the App Details screen * List anti-features on the App Details screen

View File

@ -1,2 +1 @@
-dontobfuscate -dontobfuscate

11
res/values-v11/styles.xml Normal file
View File

@ -0,0 +1,11 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseThemeDark" parent="android:Theme.Holo">
<!-- API 11 theme customizations go here -->
</style>
<style name="AppBaseThemeLight" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations go here -->
</style>
</resources>

View File

@ -15,6 +15,15 @@
<item>24</item> <item>24</item>
</string-array> </string-array>
<string-array name="themeNames">
<item>Dark</item>
<item>Light</item>
</string-array>
<string-array name="themeValues">
<item>dark</item>
<item>light</item>
</string-array>
<string-array name="dbSyncModeNames"> <string-array name="dbSyncModeNames">
<item>Off (unsafe)</item> <item>Off (unsafe)</item>
<item>Normal</item> <item>Normal</item>

View File

@ -146,5 +146,7 @@
<string name="no_handler_app">You don\'t have any available app that can handle %s</string> <string name="no_handler_app">You don\'t have any available app that can handle %s</string>
<string name="compactlayout">Compact Layout</string> <string name="compactlayout">Compact Layout</string>
<string name="compactlayout_long">Only show app names and summaries in list</string> <string name="compactlayout_long">Only show app names and summaries in list</string>
<string name="theme">Theme</string>
<string name="theme_long">Choose a theme to use</string>
</resources> </resources>

27
res/values/styles.xml Normal file
View File

@ -0,0 +1,27 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseThemeDark" parent="android:Theme.Black">
<!-- backward-compatibility theme options go here -->
</style>
<style name="AppBaseThemeLight" parent="android:Theme.Light">
<!-- backward-compatibility theme options go here -->
</style>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<style name="AboutDialogLight" parent="@android:style/Theme.Dialog">
<item name="@android:windowBackground">@color/black</item>
<item name="@android:textColor">@color/white</item>
</style>
<style name="AppThemeDark" parent="AppBaseThemeDark">
<!-- customizations that are not API-level specific go here. -->
</style>
<style name="AppThemeLight" parent="AppBaseThemeLight">
<!-- customizations that are not API-level specific go here. -->
</style>
</resources>

View File

@ -26,6 +26,11 @@
<CheckBoxPreference android:title="@string/compactlayout" <CheckBoxPreference android:title="@string/compactlayout"
android:defaultValue="false" android:summary="@string/compactlayout_long" android:defaultValue="false" android:summary="@string/compactlayout_long"
android:key="compactlayout"/> android:key="compactlayout"/>
<ListPreference android:title="@string/theme"
android:summary="@string/theme_long" android:key="theme"
android:defaultValue="dark"
android:entries="@array/themeNames"
android:entryValues="@array/themeValues" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/appcompatibility"> <PreferenceCategory android:title="@string/appcompatibility">
<CheckBoxPreference android:title="@string/show_incompat_versions" <CheckBoxPreference android:title="@string/show_incompat_versions"

View File

@ -202,6 +202,8 @@ public class AppDetails extends ListActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
((FDroidApp) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActionBarCompat abCompat = ActionBarCompat.create(this); ActionBarCompat abCompat = ActionBarCompat.create(this);
abCompat.setDisplayHomeAsUpEnabled(true); abCompat.setDisplayHomeAsUpEnabled(true);

View File

@ -30,12 +30,14 @@ import android.app.ProgressDialog;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.ResultReceiver; import android.os.ResultReceiver;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.util.Log; import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -61,6 +63,7 @@ public class FDroid extends FragmentActivity {
private ProgressDialog pd; private ProgressDialog pd;
private ViewPager viewPager; private ViewPager viewPager;
private AppListFragmentPageAdapter viewPageAdapter;
private AppListManager manager = null; private AppListManager manager = null;
@ -73,6 +76,8 @@ public class FDroid extends FragmentActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
((FDroidApp) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
manager = new AppListManager(this); manager = new AppListManager(this);
setContentView(R.layout.fdroid); setContentView(R.layout.fdroid);
@ -165,20 +170,35 @@ public class FDroid extends FragmentActivity {
return true; return true;
case ABOUT: case ABOUT:
LayoutInflater li = LayoutInflater.from(this); View view = null;
View view = li.inflate(R.layout.about, null); if (Build.VERSION.SDK_INT >= 11) {
LayoutInflater li = LayoutInflater.from(this);
view = li.inflate(R.layout.about, null);
} else {
view = View.inflate(
new ContextThemeWrapper(this, R.style.AboutDialogLight),
R.layout.about, null);
}
// Fill in the version... // Fill in the version...
TextView tv = (TextView) view.findViewById(R.id.version);
PackageManager pm = getPackageManager();
try { try {
PackageInfo pi = pm.getPackageInfo(getApplicationContext() PackageInfo pi = getPackageManager()
.getPackageName(), 0); .getPackageInfo(getApplicationContext()
tv.setText(pi.versionName); .getPackageName(), 0);
((TextView) view.findViewById(R.id.version))
.setText(pi.versionName);
} catch (Exception e) { } catch (Exception e) {
} }
Builder p = new AlertDialog.Builder(this).setView(view); Builder p = null;
if (Build.VERSION.SDK_INT >= 11) {
p = new AlertDialog.Builder(this).setView(view);
} else {
p = new AlertDialog.Builder(
new ContextThemeWrapper(
this, R.style.AboutDialogLight)
).setView(view);
}
final AlertDialog alrt = p.create(); final AlertDialog alrt = p.create();
alrt.setIcon(R.drawable.ic_launcher); alrt.setIcon(R.drawable.ic_launcher);
alrt.setTitle(getString(R.string.about_title)); alrt.setTitle(getString(R.string.about_title));
@ -244,6 +264,16 @@ public class FDroid extends FragmentActivity {
} else if ((resultCode & PreferencesActivity.RESULT_REFILTER) != 0) { } else if ((resultCode & PreferencesActivity.RESULT_REFILTER) != 0) {
((FDroidApp) getApplication()).filterApps(); ((FDroidApp) getApplication()).filterApps();
} }
if ((resultCode & PreferencesActivity.RESULT_RESTART) != 0) {
((FDroidApp) getApplication()).reloadTheme();
final Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
}
break; break;
} }
@ -251,7 +281,7 @@ public class FDroid extends FragmentActivity {
private void createViews() { private void createViews() {
viewPager = (ViewPager)findViewById(R.id.main_pager); viewPager = (ViewPager)findViewById(R.id.main_pager);
AppListFragmentPageAdapter viewPageAdapter = new AppListFragmentPageAdapter(this); viewPageAdapter = new AppListFragmentPageAdapter(this);
viewPager.setAdapter(viewPageAdapter); viewPager.setAdapter(viewPageAdapter);
viewPager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { viewPager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() {
public void onPageSelected(int position) { public void onPageSelected(int position) {

View File

@ -26,6 +26,7 @@ import java.util.concurrent.Semaphore;
import android.os.Build; import android.os.Build;
import android.app.Application; import android.app.Application;
import android.app.Activity;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.content.Context; import android.content.Context;
@ -43,6 +44,27 @@ import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
public class FDroidApp extends Application { public class FDroidApp extends Application {
private static enum Theme {
dark, light
}
private static Theme curTheme = Theme.dark;
public void reloadTheme() {
curTheme = Theme.valueOf(PreferenceManager
.getDefaultSharedPreferences(getBaseContext())
.getString("theme", "dark"));
}
public void applyTheme(Activity activity) {
switch (curTheme) {
case dark:
//activity.setTheme(R.style.AppThemeDark);
return;
case light:
activity.setTheme(R.style.AppThemeLight);
return;
}
}
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
@ -58,6 +80,7 @@ public class FDroidApp extends Application {
// because the install intent says it's finished when it hasn't. // because the install intent says it's finished when it hasn't.
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
curTheme = Theme.valueOf(prefs.getString("theme", "dark"));
if (!prefs.getBoolean("cacheDownloaded", false)) { if (!prefs.getBoolean("cacheDownloaded", false)) {
File local_path = DB.getDataPath(this); File local_path = DB.getDataPath(this);

View File

@ -81,6 +81,8 @@ public class ManageRepo extends ListActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
((FDroidApp) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActionBarCompat abCompat = ActionBarCompat.create(this); ActionBarCompat abCompat = ActionBarCompat.create(this);
abCompat.setDisplayHomeAsUpEnabled(true); abCompat.setDisplayHomeAsUpEnabled(true);

View File

@ -35,15 +35,20 @@ public class PreferencesActivity extends PreferenceActivity implements
public static final int RESULT_RELOAD = 1; public static final int RESULT_RELOAD = 1;
public static final int RESULT_REFILTER = 2; public static final int RESULT_REFILTER = 2;
public static final int RESULT_RESTART = 4;
private int result = 0; private int result = 0;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
((FDroidApp) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true); ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
for (String prefkey : new String[] { for (String prefkey : new String[] {
"updateInterval", "rooted", "incompatibleVersions" }) { "updateInterval", "rooted", "incompatibleVersions",
"theme" }) {
findPreference(prefkey).setOnPreferenceChangeListener(this); findPreference(prefkey).setOnPreferenceChangeListener(this);
} }
CheckBoxPreference onlyOnWifi = (CheckBoxPreference) CheckBoxPreference onlyOnWifi = (CheckBoxPreference)
@ -83,6 +88,11 @@ public class PreferencesActivity extends PreferenceActivity implements
setResult(result); setResult(result);
return true; return true;
} }
if (key.equals("theme")) {
result |= RESULT_RESTART;
setResult(result);
return true;
}
return false; return false;
} }

View File

@ -70,6 +70,8 @@ public class SearchResults extends ListActivity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
((FDroidApp) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true); ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true);
applist = new AvailableAppListAdapter(this); applist = new AvailableAppListAdapter(this);