Settings refactor + Feedback reporter + Translations

This commit is contained in:
serso
2016-05-11 21:47:07 +02:00
parent ed194941c1
commit 2609cede5b
116 changed files with 1186 additions and 622 deletions

View File

@@ -29,7 +29,10 @@ import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import dagger.Lazy;
import jscl.math.Generic;
import jscl.math.function.Constant;
import jscl.math.function.CustomFunction;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.about.AboutActivity;
import org.solovyev.android.calculator.functions.CppFunction;
@@ -47,18 +50,12 @@ import org.solovyev.android.plotter.PlotFunction;
import org.solovyev.android.plotter.Plotter;
import org.solovyev.common.msg.MessageType;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.Lazy;
import jscl.math.Generic;
import jscl.math.function.Constant;
import jscl.math.function.CustomFunction;
import java.util.ArrayList;
import java.util.List;
@Singleton
public final class ActivityLauncher {
@@ -111,8 +108,7 @@ public final class ActivityLauncher {
public void showWidgetSettings() {
final Context context = getContext();
show(context, PreferencesActivity.makeIntent(context, R.xml.preferences_widget,
R.string.prefs_widget_title));
show(context, PreferencesActivity.makeIntent(context, R.xml.preferences_widget, R.string.cpp_widget));
}
public void showOperators() {

View File

@@ -38,7 +38,9 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import butterknife.Bind;
import jscl.AngleUnit;
import jscl.NumeralBase;
import org.solovyev.android.calculator.converter.ConverterFragment;
import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.keyboard.PartialKeyboardUi;
@@ -48,10 +50,6 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import butterknife.Bind;
import jscl.AngleUnit;
import jscl.NumeralBase;
public class CalculatorActivity extends BaseActivity implements View.OnClickListener {
@Nonnull
@@ -76,7 +74,7 @@ public class CalculatorActivity extends BaseActivity implements View.OnClickList
private boolean useBackAsPrevious;
public CalculatorActivity() {
super(R.layout.activity_main, R.string.c_app_name);
super(R.layout.activity_main, R.string.cpp_app_name);
}
@Override

View File

@@ -27,9 +27,15 @@ import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.text.TextUtils;
import com.squareup.otto.Bus;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.MathEngine;
import jscl.NumeralBase;
import jscl.math.operator.Operator;
import jscl.text.Identifier;
import jscl.text.Parser;
import midpcalc.Real;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.functions.FunctionsRegistry;
import org.solovyev.android.calculator.math.MathType;
@@ -44,6 +50,10 @@ import org.solovyev.common.text.CharacterMapper;
import org.solovyev.common.text.EnumMapper;
import org.solovyev.common.text.NumberMapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Collections;
@@ -51,20 +61,6 @@ import java.util.List;
import java.util.Locale;
import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.MathEngine;
import jscl.NumeralBase;
import jscl.math.operator.Operator;
import jscl.text.Identifier;
import jscl.text.Parser;
import midpcalc.Real;
@Singleton
public class Engine implements SharedPreferences.OnSharedPreferenceChangeListener {
@@ -339,13 +335,13 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
public static int angleUnitName(AngleUnit angleUnit) {
switch (angleUnit) {
case deg:
return R.string.p_deg;
return R.string.cpp_deg;
case rad:
return R.string.p_rad;
return R.string.cpp_rad;
case grad:
return R.string.p_grad;
return R.string.cpp_grad;
case turns:
return R.string.p_turns;
return R.string.cpp_turns;
}
return 0;
}
@@ -354,13 +350,13 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
public static int numeralBaseName(NumeralBase numeralBase) {
switch (numeralBase) {
case bin:
return R.string.p_bin;
return R.string.cpp_bin;
case oct:
return R.string.p_oct;
return R.string.cpp_oct;
case dec:
return R.string.p_dec;
return R.string.cpp_dec;
case hex:
return R.string.p_hex;
return R.string.cpp_hex;
}
return 0;
}

View File

@@ -38,7 +38,6 @@ import org.solovyev.android.calculator.about.AboutActivity;
import org.solovyev.android.calculator.functions.FunctionsActivity;
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;
@@ -48,13 +47,9 @@ import org.solovyev.android.prefs.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.text.DecimalFormatSymbols;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;
import jscl.JsclMathEngine;
import static org.solovyev.android.prefs.IntegerPreference.DEF_VALUE;
public final class Preferences {
@@ -272,7 +267,7 @@ public final class Preferences {
default_theme(R.style.Cpp_Theme_Gray),
violet_theme(R.style.Cpp_Theme_Violet),
light_blue_theme(R.style.Cpp_Theme_Blue),
metro_blue_theme(R.string.p_metro_blue_theme, R.style.Cpp_Theme_Metro_Blue, R.style.Cpp_Theme_Metro_Blue_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Blue_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
metro_blue_theme(R.string.cpp_theme_metro_blue, R.style.Cpp_Theme_Metro_Blue, R.style.Cpp_Theme_Metro_Blue_Calculator, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Metro_Blue_Dialog, R.style.Cpp_Theme_Material_Dialog_Alert),
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),
@@ -377,8 +372,8 @@ public final class Preferences {
}
public enum Mode {
engineer(R.string.cpp_wizard_mode_engineer),
simple(R.string.cpp_wizard_mode_simple);
engineer(R.string.cpp_mode_engineer),
simple(R.string.cpp_mode_simple);
@StringRes
public final int name;

View File

@@ -82,8 +82,8 @@ public class StartupHelper {
}
});
builder.setNegativeButton(R.string.cpp_rateus_cancel, null);
builder.setMessage(activity.getString(R.string.cpp_rateus_message, activity.getString(R.string.c_app_name)));
builder.setTitle(activity.getString(R.string.cpp_rateus_title, activity.getString(R.string.c_app_name)));
builder.setMessage(activity.getString(R.string.cpp_rateus_message, activity.getString(R.string.cpp_app_name)));
builder.setTitle(activity.getString(R.string.cpp_rateus_title, activity.getString(R.string.cpp_app_name)));
builder.create().show();
UiPreferences.rateUsShown.putPreference(editor, true);
}

View File

@@ -0,0 +1,45 @@
package org.solovyev.android.calculator.feedback;
import android.app.Application;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import org.solovyev.android.calculator.R;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class FeedbackReporter {
private final Application context;
@Inject
public FeedbackReporter(Application context) {
this.context = context;
}
public void report() {
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"se.solovyev@gmail.com"});
final String version = getVersion();
intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.cpp_app_name) + " " + version + " // " + Build.MANUFACTURER + " " + Build.MODEL + " (" + Build.DEVICE + ") " + Build.VERSION.SDK_INT);
intent.setType("plain/html");
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.e("FeedbackReporter", e.getMessage(), e);
}
}
private String getVersion() {
try {
return context.getPackageManager().getPackageInfo(context.getApplicationInfo().packageName, 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
return "x.x.x";
}
}
}

View File

@@ -172,7 +172,7 @@ public class FloatingCalculatorService extends Service implements FloatingViewLi
private void showNotification() {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.kb_logo);
builder.setContentTitle(getText(R.string.c_app_name));
builder.setContentTitle(getText(R.string.cpp_app_name));
builder.setContentText(getString(R.string.open_onscreen_calculator));
builder.setOngoing(true);

View File

@@ -35,12 +35,11 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
static {
preferenceDefs.append(R.xml.preferences, new PrefDef("screen-main", R.string.cpp_settings));
preferenceDefs.append(R.xml.preferences_number_format, new PrefDef("screen-number-format", R.string.c_prefs_calculations_category));
preferenceDefs.append(R.xml.preferences_calculations, new PrefDef("screen-calculations", R.string.c_prefs_calculations_category));
preferenceDefs.append(R.xml.preferences_appearance, new PrefDef("screen-appearance", R.string.c_prefs_appearance_category));
preferenceDefs.append(R.xml.preferences_other, new PrefDef("screen-other", R.string.c_prefs_other_category));
preferenceDefs.append(R.xml.preferences_onscreen, new PrefDef("screen-onscreen", R.string.prefs_onscreen_title));
preferenceDefs.append(R.xml.preferences_widget, new PrefDef("screen-widget", R.string.prefs_widget_title));
preferenceDefs.append(R.xml.preferences_number_format, new PrefDef("screen-number-format", R.string.cpp_number_format));
preferenceDefs.append(R.xml.preferences_appearance, new PrefDef("screen-appearance", R.string.cpp_appearance));
preferenceDefs.append(R.xml.preferences_other, new PrefDef("screen-other", R.string.cpp_other));
preferenceDefs.append(R.xml.preferences_onscreen, new PrefDef("screen-onscreen", R.string.cpp_floating_calculator));
preferenceDefs.append(R.xml.preferences_widget, new PrefDef("screen-widget", R.string.cpp_widget));
}
ActivityCheckout checkout;

View File

@@ -11,15 +11,14 @@ import android.support.v4.app.FragmentActivity;
import android.util.SparseArray;
import android.view.View;
import android.widget.ListView;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import org.solovyev.android.calculator.AdView;
import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.Preferences;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.NumeralBase;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.Preferences.Gui.Theme;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.feedback.FeedbackReporter;
import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.checkout.BillingRequests;
@@ -30,16 +29,11 @@ import org.solovyev.android.prefs.StringPreference;
import org.solovyev.android.wizard.Wizards;
import org.solovyev.common.text.CharacterMapper;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.NumeralBase;
import java.util.Arrays;
import java.util.List;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.Engine.Preferences.angleUnitName;
@@ -51,8 +45,6 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
private static boolean SUPPORT_HEADERS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
@Nullable
private Preference buyPremiumPreference;
@Nullable
private AdView adView;
@Inject
SharedPreferences preferences;
@@ -63,6 +55,10 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
@Inject
JsclMathEngine engine;
@Inject
FeedbackReporter feedbackReporter;
@Inject
ActivityLauncher launcher;
@Inject
Bus bus;
@Nonnull
@@ -98,41 +94,21 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
final int preference = getPreferencesResId();
if (preference == R.xml.preferences) {
final SparseArray<PreferencesActivity.PrefDef> preferences = PreferencesActivity.getPreferenceDefs();
for (int i = 0; i < preferences.size(); i++) {
final int xml = preferences.keyAt(i);
final PreferencesActivity.PrefDef def = preferences.valueAt(i);
setPreferenceIntent(xml, def);
}
final Preference restartWizardPreference = findPreference("restart_wizard");
restartWizardPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startWizard(wizards, DEFAULT_WIZARD_FLOW, getActivity());
return true;
}
});
buyPremiumPreference = findPreference("buy_premium");
if (buyPremiumPreference != null) {
buyPremiumPreference.setEnabled(false);
buyPremiumPreference.setSelectable(false);
buyPremiumPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(getActivity(), PurchaseDialogActivity.class));
return true;
}
});
}
prepareModePreference();
prepareAnglesPreference();
prepareRadixPreference();
prepareScreens();
prepareIntroduction();
prepareReportBug();
prepareAbout();
prepareSupportProject();
prepareMode();
prepareAngles();
prepareRadix();
} else if (preference == R.xml.preferences_number_format) {
prepareListPreference(Engine.Preferences.Output.notation, Engine.Notation.class);
preparePrecisionPreference();
prepareSeparatorPreference();
prepareNumberFormatExamplesPreference();
} else if (preference == R.xml.preferences_onscreen) {
updateFloatingCalculatorPreferences();
}
prepareLanguagePreference(preference);
@@ -144,9 +120,10 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
requests.isPurchased(ProductTypes.IN_APP, "ad_free", new RequestListener<Boolean>() {
@Override
public void onSuccess(@Nonnull Boolean purchased) {
if (buyPremiumPreference != null) {
buyPremiumPreference.setEnabled(!purchased);
buyPremiumPreference.setSelectable(!purchased);
final Preference supportProject = findPreference("prefs.supportProject");
if (supportProject != null) {
supportProject.setEnabled(!purchased);
supportProject.setSelectable(!purchased);
}
onShowAd(!purchased);
}
@@ -160,6 +137,63 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
});
}
private void prepareFloatingCalculatorPreferences() {
}
private void prepareReportBug() {
final Preference reportBug = findPreference("prefs.reportBug");
reportBug.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
feedbackReporter.report();
return true;
}
});
}
private void prepareSupportProject() {
final Preference supportProject = findPreference("prefs.supportProject");
supportProject.setEnabled(false);
supportProject.setSelectable(false);
supportProject.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(getActivity(), PurchaseDialogActivity.class));
return true;
}
});
}
private void prepareScreens() {
final SparseArray<PreferencesActivity.PrefDef> preferences = PreferencesActivity.getPreferenceDefs();
for (int i = 0; i < preferences.size(); i++) {
setPreferenceIntent(preferences.keyAt(i), preferences.valueAt(i));
}
}
private void prepareIntroduction() {
final Preference introduction = findPreference("prefs.introduction");
introduction.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startWizard(wizards, DEFAULT_WIZARD_FLOW, getActivity());
return true;
}
});
}
private void prepareAbout() {
final Preference about = findPreference("prefs.about");
about.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
launcher.showAbout();
return true;
}
});
}
private void prepareNumberFormatExamplesPreference() {
final NumberFormatExamplesPreference preference = (NumberFormatExamplesPreference) preferenceManager.findPreference("numberFormat.examples");
if (preference == null) {
@@ -183,13 +217,13 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
private int separatorName(char separator) {
switch (separator) {
case '\'':
return R.string.p_grouping_separator_apostrophe;
return R.string.cpp_thousands_separator_apostrophe;
case ' ':
return R.string.p_grouping_separator_space;
return R.string.cpp_thousands_separator_space;
case 0:
return R.string.p_grouping_separator_no;
return R.string.cpp_thousands_separator_no;
}
return R.string.p_grouping_separator_no;
return R.string.cpp_thousands_separator_no;
}
private void preparePrecisionPreference() {
@@ -227,7 +261,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
});
}
private void prepareModePreference() {
private void prepareMode() {
final ListPreference mode = (ListPreference) preferenceManager.findPreference(Preferences.Gui.mode.getKey());
mode.setSummary(Preferences.Gui.getMode(preferences).name);
mode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -239,7 +273,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
});
}
private void prepareAnglesPreference() {
private void prepareAngles() {
final ListPreference angles = (ListPreference) preferenceManager.findPreference(Engine.Preferences.angleUnit.getKey());
angles.setSummary(angleUnitName(Engine.Preferences.angleUnit.getPreference(preferences)));
angles.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -251,7 +285,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
});
}
private void prepareRadixPreference() {
private void prepareRadix() {
final ListPreference radix = (ListPreference) preferenceManager.findPreference(Engine.Preferences.numeralBase.getKey());
radix.setSummary(numeralBaseName(Engine.Preferences.numeralBase.getPreference(preferences)));
radix.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -330,6 +364,16 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (Preferences.Onscreen.showAppIcon.isSameKey(key)) {
updateFloatingCalculatorPreferences();
}
}
private void updateFloatingCalculatorPreferences() {
final Preference theme = findPreference(Preferences.Onscreen.theme.getKey());
if (theme != null) {
theme.setEnabled(Preferences.Onscreen.showAppIcon.getPreference(preferences));
}
}
@Subscribe