Add "Light Theme" setting

Default theme is dark (Holo dark on >=11), addition is light on <11, Holo.Ligt
on >=11 and Holo.Light.DarkActionbar on >=14
This commit is contained in:
Daniel Martí 2013-08-23 14:29:50 +02:00
parent d6a66017e9
commit 50f0856f67
10 changed files with 97 additions and 8 deletions

View File

@ -29,6 +29,7 @@
android:name="FDroidApp"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:supportsRtl="false" >
<activity
android:name="FDroid"

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="AppBaseTheme" 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>

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

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

View File

@ -186,5 +186,7 @@
<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_long">Only show app names and summaries in list</string>
<string name="lightTheme">Light Theme</string>
<string name="lightTheme_long">Use a light theme</string>
</resources>

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

@ -0,0 +1,19 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" 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>
<style name="AppTheme" parent="AppBaseTheme">
<!-- 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

@ -33,6 +33,9 @@
<CheckBoxPreference android:title="@string/compactlayout"
android:defaultValue="false" android:summary="@string/compactlayout_long"
android:key="compactlayout"/>
<CheckBoxPreference android:title="@string/lightTheme"
android:defaultValue="false" android:summary="@string/lightTheme_long"
android:key="lightTheme"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/antifeatures">
<CheckBoxPreference android:title="@string/antiads"

View File

@ -184,6 +184,10 @@ public class AppDetails extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if (PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean("lightTheme", false))
setTheme(R.style.AppThemeLight);
super.onCreate(savedInstanceState);
ActionBarCompat abCompat = ActionBarCompat.create(this);
abCompat.setDisplayHomeAsUpEnabled(true);

View File

@ -33,6 +33,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
@ -61,6 +62,7 @@ public class FDroid extends FragmentActivity {
private ProgressDialog pd;
private ViewPager viewPager;
private AppListFragmentPageAdapter viewPageAdapter;
private AppListManager manager = null;
@ -73,6 +75,10 @@ public class FDroid extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if (PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean("lightTheme", false))
setTheme(R.style.AppThemeLight);
super.onCreate(savedInstanceState);
manager = new AppListManager(this);
setContentView(R.layout.fdroid);
@ -242,6 +248,13 @@ public class FDroid extends FragmentActivity {
UpdateService.schedule(getBaseContext());
if (data != null && data.hasExtra("update")) {
updateRepos();
} else if (data != null && data.hasExtra("restart")) {
final Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
} else {
repopulateViews();
}
@ -252,7 +265,7 @@ public class FDroid extends FragmentActivity {
private void createViews() {
viewPager = (ViewPager)findViewById(R.id.main_pager);
AppListFragmentPageAdapter viewPageAdapter = new AppListFragmentPageAdapter(this);
viewPageAdapter = new AppListFragmentPageAdapter(this);
viewPager.setAdapter(viewPageAdapter);
viewPager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() {
public void onPageSelected(int position) {

View File

@ -77,6 +77,10 @@ public class ManageRepo extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if (PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean("lightTheme", false))
setTheme(R.style.AppThemeLight);
super.onCreate(savedInstanceState);
setContentView(R.layout.repolist);

View File

@ -24,6 +24,7 @@ import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Toast;
@ -32,28 +33,48 @@ import org.fdroid.fdroid.compat.ActionBarCompat;
public class PreferencesActivity extends PreferenceActivity implements
OnPreferenceClickListener {
private boolean ignoreTouchscreenChanged = false;
private boolean showIncompatibleChanged = false;
private boolean lightThemeChanged = false;
Intent ret;
@Override
protected void onCreate(Bundle savedInstanceState) {
if (PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean("lightTheme", false))
setTheme(R.style.AppThemeLight);
super.onCreate(savedInstanceState);
ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preferences);
for (String prefkey : new String[] { "ignoreTouchscreen",
"showIncompatible" }) {
"showIncompatible", "lightTheme" }) {
Preference pref = findPreference(prefkey);
pref.setOnPreferenceClickListener(this);
}
ret = new Intent();
}
@Override
public boolean onPreferenceClick(Preference preference) {
// Currently only one action is returned.
//String key = preference.getKey();
//if (key.equals("ignoreTouchscreen") || key.equals("showIncompatible")) {
Intent ret = new Intent();
String key = preference.getKey();
if (key.equals("ignoreTouchscreen"))
ignoreTouchscreenChanged ^= true;
else if (key.equals("showIncompatible"))
showIncompatibleChanged ^= true;
else
lightThemeChanged ^= true;
if (lightThemeChanged)
ret.putExtra("restart", true);
else if (ignoreTouchscreenChanged || showIncompatibleChanged)
ret.putExtra("update", true);
setResult(RESULT_OK, ret);
return true;
//}
}
}