AMOLED-friendly theme added
This commit is contained in:
@@ -33,8 +33,6 @@ import android.support.annotation.*;
|
||||
import android.support.v7.view.ContextThemeWrapper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseArray;
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.calculator.about.AboutActivity;
|
||||
import org.solovyev.android.calculator.functions.FunctionsActivity;
|
||||
@@ -42,6 +40,7 @@ import org.solovyev.android.calculator.history.HistoryActivity;
|
||||
import org.solovyev.android.calculator.language.Languages;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.operators.OperatorsActivity;
|
||||
import org.solovyev.android.calculator.preferences.PreferenceEntry;
|
||||
import org.solovyev.android.calculator.preferences.PreferencesActivity;
|
||||
import org.solovyev.android.calculator.variables.VariablesActivity;
|
||||
import org.solovyev.android.calculator.wizard.WizardActivity;
|
||||
@@ -285,7 +284,7 @@ public final class Preferences {
|
||||
return mode.getPreferenceNoError(preferences);
|
||||
}
|
||||
|
||||
public enum Theme {
|
||||
public enum Theme implements PreferenceEntry {
|
||||
|
||||
default_theme(R.style.Cpp_Theme_Gray),
|
||||
violet_theme(R.style.Cpp_Theme_Violet),
|
||||
@@ -294,12 +293,19 @@ public final class Preferences {
|
||||
metro_purple_theme(R.string.p_metro_purple_theme, R.style.Cpp_Theme_Metro_Purple, R.style.Cpp_Theme_Metro_Purple_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Purple_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
|
||||
metro_green_theme(R.string.p_metro_green_theme, R.style.Cpp_Theme_Metro_Green, R.style.Cpp_Theme_Metro_Green_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Green_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
|
||||
material_theme(R.string.cpp_theme_dark, R.style.Cpp_Theme_Material, R.style.Cpp_Theme_Material_Calculator),
|
||||
material_black_theme(R.string.cpp_theme_black, R.style.Cpp_Theme_Material_Black, R.style.Cpp_Theme_Material_Black_Calculator) {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getName(@NonNull Context context) {
|
||||
return context.getString(name, material_theme.getName(context));
|
||||
}
|
||||
},
|
||||
material_light_theme(R.string.cpp_theme_light, R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Material_Light_Calculator, R.style.Cpp_Theme_Wizard_Light, R.style.Cpp_Theme_Material_Light_Dialog, R.style.Cpp_Theme_Material_Light_Dialog_Alert);
|
||||
|
||||
private static final SparseArray<TextColor> textColors = new SparseArray<>();
|
||||
|
||||
@StringRes
|
||||
public final int name;
|
||||
protected final int name;
|
||||
@StyleRes
|
||||
public final int theme;
|
||||
@StyleRes
|
||||
@@ -373,6 +379,18 @@ public final class Preferences {
|
||||
}
|
||||
return textColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getName(@NonNull Context context) {
|
||||
return context.getString(name);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CharSequence getId() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
|
@@ -1,15 +1,15 @@
|
||||
package org.solovyev.android.calculator.language;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.solovyev.android.calculator.preferences.PreferenceEntry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class Language {
|
||||
public final class Language implements PreferenceEntry{
|
||||
@Nonnull
|
||||
public final String code;
|
||||
|
||||
@@ -39,6 +39,7 @@ public final class Language {
|
||||
return locale.getDisplayName(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public String getName(@Nonnull Context context) {
|
||||
if (!isSystem()) {
|
||||
@@ -48,6 +49,12 @@ public final class Language {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CharSequence getId() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public boolean isSystem() {
|
||||
return code.equals(Languages.SYSTEM_LANGUAGE_CODE);
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
package org.solovyev.android.calculator.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public interface PreferenceEntry {
|
||||
@NonNull
|
||||
CharSequence getName(@NonNull Context context);
|
||||
|
||||
@NonNull
|
||||
CharSequence getId();
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package org.solovyev.android.calculator.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
@@ -13,6 +14,7 @@ import android.widget.ListView;
|
||||
import org.solovyev.android.calculator.AdView;
|
||||
import org.solovyev.android.calculator.Engine;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.Preferences.Gui.Theme;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.language.Language;
|
||||
import org.solovyev.android.calculator.language.Languages;
|
||||
@@ -25,6 +27,7 @@ import org.solovyev.android.wizard.Wizards;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.solovyev.android.calculator.App.cast;
|
||||
@@ -154,32 +157,50 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
|
||||
return;
|
||||
}
|
||||
final ListPreference theme = (ListPreference) preferenceManager.findPreference(Preferences.Gui.theme.getKey());
|
||||
theme.setSummary(Preferences.Gui.getTheme(preferences).name);
|
||||
final FragmentActivity context = getActivity();
|
||||
populate(theme,
|
||||
Theme.material_theme,
|
||||
Theme.material_black_theme,
|
||||
Theme.material_light_theme,
|
||||
Theme.metro_blue_theme,
|
||||
Theme.metro_green_theme,
|
||||
Theme.metro_purple_theme);
|
||||
theme.setSummary(Preferences.Gui.getTheme(preferences).getName(context));
|
||||
theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
theme.setSummary(Preferences.Gui.Theme.valueOf((String) newValue).name);
|
||||
final Theme newTheme = Theme.valueOf((String) newValue);
|
||||
theme.setSummary(newTheme.getName(context));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void populate(@Nonnull ListPreference preference, @Nonnull PreferenceEntry... entries) {
|
||||
populate(preference, Arrays.asList(entries));
|
||||
}
|
||||
|
||||
private static void populate(@Nonnull ListPreference preference, @Nonnull List<? extends PreferenceEntry> entries) {
|
||||
final int size = entries.size();
|
||||
final CharSequence[] e = new CharSequence[size];
|
||||
final CharSequence[] v = new CharSequence[size];
|
||||
final Context context = preference.getContext();
|
||||
for (int i = 0; i < size; i++) {
|
||||
final PreferenceEntry entry = entries.get(i);
|
||||
e[i] = entry.getName(context);
|
||||
v[i] = entry.getId();
|
||||
}
|
||||
preference.setEntries(e);
|
||||
preference.setEntryValues(v);
|
||||
}
|
||||
|
||||
private void prepareLanguagePreference(int preference) {
|
||||
if (preference != R.xml.preferences_appearance) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ListPreference language = (ListPreference) preferenceManager.findPreference(Preferences.Gui.language.getKey());
|
||||
final List<Language> languagesList = languages.getList();
|
||||
final CharSequence[] entries = new CharSequence[languagesList.size()];
|
||||
final CharSequence[] entryValues = new CharSequence[languagesList.size()];
|
||||
for (int i = 0; i < languagesList.size(); i++) {
|
||||
final Language l = languagesList.get(i);
|
||||
entries[i] = l.getName(getActivity());
|
||||
entryValues[i] = l.code;
|
||||
}
|
||||
language.setEntries(entries);
|
||||
language.setEntryValues(entryValues);
|
||||
populate(language, languages.getList());
|
||||
language.setSummary(languages.getCurrent().getName(getActivity()));
|
||||
language.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
|
@@ -23,7 +23,6 @@
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -58,11 +57,12 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
|
||||
final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(preferences);
|
||||
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_theme_spinner);
|
||||
themes.clear();
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.material_theme, R.string.cpp_theme_dark));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.material_light_theme, R.string.cpp_theme_light));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.metro_blue_theme, R.string.p_metro_blue_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.metro_green_theme, R.string.p_metro_green_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.metro_purple_theme, R.string.p_metro_purple_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.material_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.material_black_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.material_light_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.metro_blue_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.metro_green_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.metro_purple_theme));
|
||||
adapter = new WizardArrayAdapter<>(getActivity(), themes);
|
||||
spinner.setAdapter(adapter);
|
||||
spinner.setSelection(findPosition(theme));
|
||||
@@ -111,9 +111,9 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
|
||||
@Nonnull
|
||||
final String name;
|
||||
|
||||
public ThemeUi(@Nonnull Preferences.Gui.Theme theme, @StringRes int name) {
|
||||
public ThemeUi(@Nonnull Preferences.Gui.Theme theme) {
|
||||
this.theme = theme;
|
||||
this.name = getString(name);
|
||||
this.name = theme.getName(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user