From a68e08201f15fb346659c7e091e02c187a4c1e85 Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 22 Feb 2016 15:12:48 +0100 Subject: [PATCH] Tablet support --- app/src/main/AndroidManifest.xml | 31 +++++++++ .../android/calculator/ActivityLauncher.java | 18 ++--- .../android/calculator/ActivityUi.java | 33 ++-------- .../android/calculator/Preferences.java | 25 ++++++- .../calculator/about/AboutActivity.java | 14 ++++ .../functions/EditFunctionFragment.java | 41 +++++++++--- .../functions/FunctionsActivity.java | 12 ++++ .../calculator/history/HistoryActivity.java | 23 ++++++- .../operators/OperatorsActivity.java | 13 ++++ .../preferences/PreferencesActivity.java | 11 +++- .../preferences/PreferencesFragment.java | 20 ++++-- .../variables/EditVariableFragment.java | 28 +++++--- .../variables/VariablesActivity.java | 11 ++++ .../main/res/layout-sw600dp/activity_tabs.xml | 66 +++++++++++++++++++ .../main/res/layout/fragment_preferences.xml | 4 +- app/src/main/res/values/styles.xml | 2 +- app/src/main/res/values/theme.xml | 19 +++--- 17 files changed, 292 insertions(+), 79 deletions(-) create mode 100644 app/src/main/res/layout-sw600dp/activity_tabs.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c7bf696b..3cc19714 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -60,10 +60,20 @@ android:name=".preferences.PreferencesActivity" android:label="@string/c_app_settings" /> + + + + + + + + + + + + + fragmentClass, - @Nullable Bundle fragmentArgs, - int title) { - addTab(fragmentClass, fragmentArgs, activity.getString(title)); - } - - public void addTab(@Nonnull Class fragmentClass, - @Nullable Bundle fragmentArgs, - @Nonnull CharSequence title) { - tabs.addTab(fragmentClass, fragmentArgs, title); - } - - public void addTab(@Nonnull FragmentTab tab, @Nullable Bundle fragmentArgs) { - addTab(tab.type, fragmentArgs, tab.title); - } - @Nonnull public Language getLanguage() { return language; diff --git a/app/src/main/java/org/solovyev/android/calculator/Preferences.java b/app/src/main/java/org/solovyev/android/calculator/Preferences.java index 73bbf8ff..66240de3 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Preferences.java +++ b/app/src/main/java/org/solovyev/android/calculator/Preferences.java @@ -41,8 +41,14 @@ import android.util.SparseArray; import android.view.ContextThemeWrapper; import org.solovyev.android.Check; +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.PreferencesActivity; +import org.solovyev.android.calculator.variables.VariablesActivity; import org.solovyev.android.calculator.wizard.WizardActivity; import org.solovyev.android.prefs.BooleanPreference; import org.solovyev.android.prefs.IntegerPreference; @@ -334,7 +340,24 @@ public final class Preferences { if (context instanceof WizardActivity) { return wizardTheme; } - final boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); + if (context instanceof FunctionsActivity.Dialog) { + return dialogTheme; + } + if (context instanceof PreferencesActivity.Dialog) { + return dialogTheme; + } + if (context instanceof VariablesActivity.Dialog) { + return dialogTheme; + } + if (context instanceof OperatorsActivity.Dialog) { + return dialogTheme; + } + if (context instanceof HistoryActivity.Dialog) { + return dialogTheme; + } + if (context instanceof AboutActivity.Dialog) { + return dialogTheme; + } return theme; } diff --git a/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java index 26eabb3b..be2f0f4d 100644 --- a/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java @@ -22,14 +22,28 @@ package org.solovyev.android.calculator.about; +import android.content.Context; +import android.support.annotation.NonNull; + import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.FragmentTab; +import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.view.Tabs; import javax.annotation.Nonnull; public class AboutActivity extends BaseActivity { + public static class Dialog extends AboutActivity { + } + + @Nonnull + public static Class getClass(@NonNull Context context) { + boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); + return tablet ? Dialog.class : AboutActivity.class; + } + + @Override protected void populateTabs(@Nonnull Tabs tabs) { super.populateTabs(tabs); diff --git a/app/src/main/java/org/solovyev/android/calculator/functions/EditFunctionFragment.java b/app/src/main/java/org/solovyev/android/calculator/functions/EditFunctionFragment.java index ee0602b5..4fcc5033 100644 --- a/app/src/main/java/org/solovyev/android/calculator/functions/EditFunctionFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/functions/EditFunctionFragment.java @@ -22,6 +22,8 @@ package org.solovyev.android.calculator.functions; +import static org.solovyev.android.calculator.functions.CppFunction.NO_ID; + import android.annotation.SuppressLint; import android.content.Context; import android.content.DialogInterface; @@ -35,26 +37,47 @@ import android.support.v4.app.FragmentManager; import android.support.v7.app.AlertDialog; import android.text.Editable; import android.text.TextUtils; -import android.view.*; +import android.view.ContextMenu; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; -import butterknife.Bind; -import butterknife.ButterKnife; -import jscl.math.function.Function; + import org.solovyev.android.Activities; import org.solovyev.android.Check; -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.AppComponent; +import org.solovyev.android.calculator.BaseDialogFragment; +import org.solovyev.android.calculator.Calculator; +import org.solovyev.android.calculator.Engine; +import org.solovyev.android.calculator.FloatingCalculatorKeyboard; +import org.solovyev.android.calculator.Keyboard; +import org.solovyev.android.calculator.ParseException; +import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.VariablesRegistry; import org.solovyev.android.calculator.entities.EntityRemovalDialog; import org.solovyev.android.calculator.keyboard.FloatingKeyboardWindow; import org.solovyev.android.calculator.view.EditTextCompat; import org.solovyev.common.math.MathRegistry; +import butterknife.Bind; +import butterknife.ButterKnife; +import jscl.math.function.Function; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; -import java.util.*; - -import static org.solovyev.android.calculator.functions.CppFunction.NO_ID; public class EditFunctionFragment extends BaseDialogFragment implements View.OnClickListener, View.OnFocusChangeListener, View.OnKeyListener { @@ -107,7 +130,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC public static void show(@Nullable CppFunction function, @Nonnull Context context) { if (!(context instanceof FunctionsActivity)) { - final Intent intent = new Intent(context, FunctionsActivity.class); + final Intent intent = new Intent(context, FunctionsActivity.getClass(context)); Activities.addIntentFlags(intent, false, context); intent.putExtra(FunctionsActivity.EXTRA_FUNCTION, function); context.startActivity(intent); diff --git a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java index bb4bf6f4..acc8ed30 100644 --- a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java @@ -22,8 +22,11 @@ package org.solovyev.android.calculator.functions; +import android.content.Context; import android.os.Bundle; +import android.support.annotation.NonNull; import android.view.View; + import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.FragmentTab; import org.solovyev.android.calculator.R; @@ -36,6 +39,12 @@ public class FunctionsActivity extends BaseActivity { public static final String EXTRA_FUNCTION = "function"; + @Nonnull + public static Class getClass(@NonNull Context context) { + boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); + return tablet ? Dialog.class : FunctionsActivity.class; + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -74,4 +83,7 @@ public class FunctionsActivity extends BaseActivity { tabs.addTab(category, FragmentTab.operators, title); } } + + public static final class Dialog extends FunctionsActivity { + } } \ No newline at end of file diff --git a/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java b/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java index 63109b87..3993d5dc 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java @@ -22,21 +22,38 @@ package org.solovyev.android.calculator.history; +import static org.solovyev.android.calculator.FragmentTab.saved_history; + +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; import android.view.View; -import org.solovyev.android.calculator.*; + +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.AppComponent; +import org.solovyev.android.calculator.BaseActivity; +import org.solovyev.android.calculator.FragmentTab; +import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.view.Tabs; import javax.annotation.Nonnull; import javax.inject.Inject; -import static org.solovyev.android.calculator.FragmentTab.saved_history; - public class HistoryActivity extends BaseActivity { + public static class Dialog extends HistoryActivity { + } + + @Nonnull + public static Class getClass(@NonNull Context context) { + boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); + return tablet ? Dialog.class : HistoryActivity.class; + } + + @Inject History history; diff --git a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java index ec93b733..5a0a9a5d 100644 --- a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java @@ -22,14 +22,27 @@ package org.solovyev.android.calculator.operators; +import android.content.Context; +import android.support.annotation.NonNull; + import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.FragmentTab; +import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.view.Tabs; import javax.annotation.Nonnull; public class OperatorsActivity extends BaseActivity { + public static class Dialog extends OperatorsActivity { + } + + @Nonnull + public static Class getClass(@NonNull Context context) { + boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); + return tablet ? Dialog.class : OperatorsActivity.class; + } + @Override protected void populateTabs(@Nonnull Tabs tabs) { super.populateTabs(tabs); diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java index a24c3480..f2ca9248 100644 --- a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.StringRes; import android.support.annotation.XmlRes; import android.util.SparseArray; @@ -30,6 +31,11 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc @Nonnull private static final SparseArray preferences = new SparseArray<>(); + public static Class getClass(@NonNull Context context) { + final boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); + return tablet ? Dialog.class : PreferencesActivity.class; + } + static { preferences.append(R.xml.preferences, new PrefDef("screen-main", R.string.c_app_settings)); preferences.append(R.xml.preferences_calculations, new PrefDef("screen-calculations", R.string.c_prefs_calculations_category)); @@ -68,7 +74,7 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc @Nonnull public static Intent makeIntent(@Nonnull Context context, @XmlRes int preference, @StringRes int title) { - final Intent intent = new Intent(context, PreferencesActivity.class); + final Intent intent = new Intent(context, getClass(context)); intent.putExtra(EXTRA_PREFERENCE, preference); if (title != 0) { intent.putExtra(EXTRA_PREFERENCE_TITLE, title); @@ -150,4 +156,7 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc this.title = title; } } + + public static final class Dialog extends PreferencesActivity { + } } diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java index 45ea65d3..b793dd8e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java @@ -1,15 +1,24 @@ package org.solovyev.android.calculator.preferences; +import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW; +import static org.solovyev.android.wizard.WizardUi.startWizard; + import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; +import android.support.v4.app.FragmentActivity; import android.util.SparseArray; import android.view.View; import android.widget.ListView; -import org.solovyev.android.calculator.*; + +import org.solovyev.android.calculator.AdView; +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.Engine; +import org.solovyev.android.calculator.Preferences; +import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.checkout.BillingRequests; @@ -17,12 +26,10 @@ import org.solovyev.android.checkout.Checkout; import org.solovyev.android.checkout.ProductTypes; import org.solovyev.android.checkout.RequestListener; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.List; -import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW; -import static org.solovyev.android.wizard.WizardUi.startWizard; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; public class PreferencesFragment extends org.solovyev.android.material.preferences.PreferencesFragment implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -49,7 +56,8 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc private void setPreferenceIntent(int xml, @Nonnull PreferencesActivity.PrefDef def) { final Preference preference = findPreference(def.id); if (preference != null) { - final Intent intent = new Intent(getActivity(), PreferencesActivity.class); + final FragmentActivity context = getActivity(); + final Intent intent = new Intent(context, PreferencesActivity.getClass(context)); intent.putExtra(PreferencesActivity.EXTRA_PREFERENCE, xml); intent.putExtra(PreferencesActivity.EXTRA_PREFERENCE_TITLE, def.title); preference.setIntent(intent); diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/EditVariableFragment.java b/app/src/main/java/org/solovyev/android/calculator/variables/EditVariableFragment.java index 14014b2e..846f41fa 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/EditVariableFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/EditVariableFragment.java @@ -22,6 +22,8 @@ package org.solovyev.android.calculator.variables; +import static org.solovyev.android.calculator.variables.CppVariable.NO_ID; + import android.annotation.SuppressLint; import android.content.Context; import android.content.DialogInterface; @@ -41,12 +43,17 @@ import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.PopupWindow; -import butterknife.Bind; -import butterknife.ButterKnife; -import jscl.math.function.IConstant; + import org.solovyev.android.Activities; import org.solovyev.android.Check; -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.AppComponent; +import org.solovyev.android.calculator.BaseDialogFragment; +import org.solovyev.android.calculator.Calculator; +import org.solovyev.android.calculator.Engine; +import org.solovyev.android.calculator.Keyboard; +import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.VariablesRegistry; import org.solovyev.android.calculator.entities.EntityRemovalDialog; import org.solovyev.android.calculator.functions.FunctionsRegistry; import org.solovyev.android.calculator.keyboard.FloatingKeyboard; @@ -55,13 +62,16 @@ import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.view.EditTextCompat; import org.solovyev.common.text.Strings; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.inject.Inject; +import butterknife.Bind; +import butterknife.ButterKnife; +import jscl.math.function.IConstant; + import java.util.Arrays; import java.util.List; -import static org.solovyev.android.calculator.variables.CppVariable.NO_ID; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.inject.Inject; public class EditVariableFragment extends BaseDialogFragment implements View.OnFocusChangeListener, View.OnKeyListener, View.OnClickListener { @@ -119,7 +129,7 @@ public class EditVariableFragment extends BaseDialogFragment implements View.OnF public static void showDialog(@Nullable CppVariable variable, @Nonnull Context context) { if (!(context instanceof VariablesActivity)) { - final Intent intent = new Intent(context, VariablesActivity.class); + final Intent intent = new Intent(context, VariablesActivity.getClass(context)); Activities.addIntentFlags(intent, false, context); intent.putExtra(VariablesActivity.EXTRA_VARIABLE, variable); context.startActivity(intent); diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java index ca5949f4..b55866dc 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java @@ -22,7 +22,9 @@ package org.solovyev.android.calculator.variables; +import android.content.Context; import android.os.Bundle; +import android.support.annotation.NonNull; import android.view.View; import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.FragmentTab; @@ -36,6 +38,12 @@ public class VariablesActivity extends BaseActivity { public static final String EXTRA_VARIABLE = "variable"; + @Nonnull + public static Class getClass(@NonNull Context context) { + boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); + return tablet ? Dialog.class : VariablesActivity.class; + } + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -63,4 +71,7 @@ public class VariablesActivity extends BaseActivity { tabs.addTab(category, FragmentTab.variables); } } + + public static final class Dialog extends VariablesActivity { + } } diff --git a/app/src/main/res/layout-sw600dp/activity_tabs.xml b/app/src/main/res/layout-sw600dp/activity_tabs.xml new file mode 100644 index 00000000..a6861469 --- /dev/null +++ b/app/src/main/res/layout-sw600dp/activity_tabs.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_preferences.xml b/app/src/main/res/layout/fragment_preferences.xml index 1ebddba6..5d273ddc 100644 --- a/app/src/main/res/layout/fragment_preferences.xml +++ b/app/src/main/res/layout/fragment_preferences.xml @@ -3,6 +3,4 @@ \ No newline at end of file + style="@style/CppListView"/> \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ed2144be..ab71723b 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -322,7 +322,7 @@ 1px @drawable/divider @android:color/transparent - match_parent + wrap_content match_parent 1 none diff --git a/app/src/main/res/values/theme.xml b/app/src/main/res/values/theme.xml index 3c854695..aad98ea8 100644 --- a/app/src/main/res/values/theme.xml +++ b/app/src/main/res/values/theme.xml @@ -40,22 +40,19 @@ @drawable/divider_dark - + -