From 9bcc4d4d9fe60d6917440674d10f8c89651392fa Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 1 Mar 2016 17:43:11 +0100 Subject: [PATCH] UI changes --- .../org/solovyev/android/calculator/App.java | 36 ++++++++----------- .../calculator/CalculatorActivity.java | 2 +- .../android/calculator/EditorView.java | 9 ++--- .../android/calculator/Preferences.java | 2 +- .../floating/FloatingCalculatorView.java | 33 +++++++++++++---- .../calculator/keyboard/BaseKeyboardUi.java | 25 +++++++++---- .../keyboard/PartialKeyboardUi.java | 14 ++++---- .../wizard/ChooseThemeWizardStep.java | 6 ++-- app/src/main/res/layout/cpp_app_editor.xml | 4 +-- app/src/main/res/layout/widget_editor.xml | 20 +++-------- .../main/res/layout/widget_editor_light.xml | 20 +++-------- .../widget_layout_lockscreen_collapsed.xml | 5 --- .../res/values-land/text_non_translatable.xml | 2 +- app/src/main/res/values/styles.xml | 5 ++- .../main/res/values/text_non_translatable.xml | 2 +- 15 files changed, 91 insertions(+), 94 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/App.java b/app/src/main/java/org/solovyev/android/calculator/App.java index 8a9142a8..8c644cf9 100644 --- a/app/src/main/java/org/solovyev/android/calculator/App.java +++ b/app/src/main/java/org/solovyev/android/calculator/App.java @@ -26,6 +26,7 @@ import android.app.Activity; import android.app.Application; import android.content.ActivityNotFoundException; import android.content.Context; +import android.content.ContextWrapper; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -40,6 +41,7 @@ import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; +import android.support.v7.view.ContextThemeWrapper; import android.text.Spannable; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; @@ -64,7 +66,6 @@ import org.solovyev.common.JPredicate; import java.util.Collection; import java.util.List; -import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; @@ -85,13 +86,9 @@ public final class App { @Nonnull private static volatile Application application; @Nonnull - private static Executor uiThreadExecutor; - @Nonnull private static SharedPreferences preferences; @Nonnull private static volatile Ga ga; - @Nullable - private static Boolean lg = null; @Nonnull private static volatile ScreenMetrics screenMetrics; @Nonnull @@ -111,7 +108,6 @@ public final class App { @Nonnull Languages languages) { App.application = application; App.preferences = PreferenceManager.getDefaultSharedPreferences(application); - App.uiThreadExecutor = application.uiThread; App.ga = new Ga(application, preferences); App.screenMetrics = new ScreenMetrics(application); App.languages = languages; @@ -132,16 +128,6 @@ public final class App { return (A) application; } - /** - * Method returns executor which runs on Main Application's thread. It's safe to do all UI work on this executor - * - * @return UI thread executor - */ - @Nonnull - public static Executor getUiThreadExecutor() { - return uiThreadExecutor; - } - @Nonnull public static Wizards getWizards() { return wizards; @@ -152,10 +138,6 @@ public final class App { return ga; } - public static boolean isLargeScreen() { - return Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, App.getApplication().getResources().getConfiguration()); - } - @Nonnull public static SharedPreferences getPreferences() { return preferences; @@ -173,7 +155,7 @@ public final class App { @Nonnull public static Preferences.Gui.Theme getThemeFor(@Nonnull Context context) { - if (context instanceof FloatingCalculatorService) { + if (isFloatingCalculator(context)) { final SharedPreferences p = getPreferences(); final Preferences.SimpleTheme onscreenTheme = Preferences.Onscreen.getTheme(p); final Preferences.Gui.Theme appTheme = Preferences.Gui.getTheme(p); @@ -183,6 +165,14 @@ public final class App { } } + @NonNull + private static Context unwrap(@NonNull Context context) { + if (context instanceof ContextThemeWrapper) { + return unwrap(((ContextThemeWrapper) context).getBaseContext()); + } + return context; + } + @Nonnull public static Languages getLanguages() { return languages; @@ -399,4 +389,8 @@ public final class App { ((ViewGroup) root).addView(helperTextView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } + + static boolean isFloatingCalculator(@NonNull Context context) { + return unwrap(context) instanceof FloatingCalculatorService; + } } \ No newline at end of file diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index d28956ae..3eb8ba6f 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -143,10 +143,10 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference @Override protected void onResume() { super.onResume(); + launcher.setActivity(this); if (restartIfLayoutChanged()) { return; } - launcher.setActivity(this); final Window window = getWindow(); if (keepScreenOn.getPreference(preferences)) { diff --git a/app/src/main/java/org/solovyev/android/calculator/EditorView.java b/app/src/main/java/org/solovyev/android/calculator/EditorView.java index 21398fa5..c92fcacb 100644 --- a/app/src/main/java/org/solovyev/android/calculator/EditorView.java +++ b/app/src/main/java/org/solovyev/android/calculator/EditorView.java @@ -31,7 +31,6 @@ import android.util.AttributeSet; import android.view.ContextMenu; import org.solovyev.android.Check; -import org.solovyev.android.calculator.floating.FloatingCalculatorService; import org.solovyev.android.calculator.view.EditTextCompat; import org.solovyev.android.views.Adjuster; @@ -66,7 +65,7 @@ public class EditorView extends EditTextCompat { } private void init() { - if (!isFloatingCalculator()) { + if (!App.isFloatingCalculator(getContext())) { Adjuster.adjustText(this, 0.22f, getResources().getDimensionPixelSize(R.dimen.cpp_min_editor_text_size)); } @@ -96,7 +95,7 @@ public class EditorView extends EditTextCompat { Check.isMainThread(); // we don't want to be notified about changes we make ourselves editorChange = true; - if (App.getTheme().light && isFloatingCalculator()) { + if (App.getTheme().light && App.isFloatingCalculator(getContext())) { // don't need formatting setText(state.getTextString()); } else { @@ -106,10 +105,6 @@ public class EditorView extends EditTextCompat { setSelection(Editor.clamp(state.selection, length())); } - private boolean isFloatingCalculator() { - return getContext() instanceof FloatingCalculatorService; - } - @Override protected void onSelectionChanged(int start, int end) { Check.isMainThread(); 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 bdd9fff0..2227c7b9 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Preferences.java +++ b/app/src/main/java/org/solovyev/android/calculator/Preferences.java @@ -33,8 +33,8 @@ import android.support.annotation.ColorRes; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.StyleRes; +import android.support.v7.view.ContextThemeWrapper; import android.util.SparseArray; -import android.view.ContextThemeWrapper; import org.solovyev.android.Check; import org.solovyev.android.calculator.about.AboutActivity; diff --git a/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java index 6245ffcc..8d0be61f 100644 --- a/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java +++ b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java @@ -31,12 +31,26 @@ import android.graphics.drawable.Drawable; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; +import android.support.v7.view.ContextThemeWrapper; import android.util.DisplayMetrics; import android.view.Display; -import android.view.*; +import android.view.Gravity; +import android.view.MotionEvent; +import android.view.View; +import android.view.WindowManager; import android.widget.ImageView; import android.widget.TextView; -import org.solovyev.android.calculator.*; + +import org.solovyev.android.calculator.AppModule; +import org.solovyev.android.calculator.BaseActivity; +import org.solovyev.android.calculator.DisplayState; +import org.solovyev.android.calculator.DisplayView; +import org.solovyev.android.calculator.Editor; +import org.solovyev.android.calculator.EditorState; +import org.solovyev.android.calculator.EditorView; +import org.solovyev.android.calculator.Keyboard; +import org.solovyev.android.calculator.Preferences; +import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.buttons.CppButton; import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; import org.solovyev.android.views.Adjuster; @@ -45,8 +59,14 @@ import javax.annotation.Nonnull; import javax.inject.Inject; import javax.inject.Named; -import static android.view.HapticFeedbackConstants.*; -import static android.view.WindowManager.LayoutParams.*; +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING; +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING; +import static android.view.HapticFeedbackConstants.KEYBOARD_TAP; +import static android.view.HapticFeedbackConstants.LONG_PRESS; +import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; +import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; +import static android.view.WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; +import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; import static org.solovyev.android.calculator.App.cast; public class FloatingCalculatorView { @@ -258,13 +278,14 @@ public class FloatingCalculatorView { @Nonnull State state, @NonNull FloatingViewListener listener) { cast(context).getComponent().inject(this); - this.context = context; this.listener = listener; final Preferences.SimpleTheme theme = Preferences.Onscreen.theme.getPreferenceNoError(preferences); final Preferences.Gui.Theme appTheme = Preferences.Gui.theme.getPreferenceNoError(preferences); - this.root = View.inflate(context, theme.getOnscreenLayout(appTheme), null); + final Preferences.SimpleTheme resolvedTheme = theme.resolveThemeFor(appTheme); + this.context = new ContextThemeWrapper(context, resolvedTheme.light ? R.style.Cpp_Theme_Light : R.style.Cpp_Theme); + this.root = View.inflate(this.context, theme.getOnscreenLayout(appTheme), null); final State persistedState = State.fromPrefs(myPreferences); if (persistedState != null) { this.state = persistedState; diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java index e52ecd7f..d85f3136 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java @@ -12,8 +12,16 @@ import android.util.TypedValue; import android.view.View; import android.widget.ImageView; import android.widget.TextView; + import org.solovyev.android.Views; -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.ActivityLauncher; +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.BaseActivity; +import org.solovyev.android.calculator.Calculator; +import org.solovyev.android.calculator.Editor; +import org.solovyev.android.calculator.Keyboard; +import org.solovyev.android.calculator.Preferences; +import org.solovyev.android.calculator.PreferredPreferences; import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.view.ScreenMetrics; import org.solovyev.android.views.Adjuster; @@ -22,12 +30,15 @@ import org.solovyev.android.views.dragbutton.DragButton; import org.solovyev.android.views.dragbutton.DragDirection; import org.solovyev.android.views.dragbutton.SimpleDragListener; -import javax.annotation.Nonnull; -import javax.inject.Inject; import java.util.ArrayList; import java.util.List; -import static android.view.HapticFeedbackConstants.*; +import javax.annotation.Nonnull; +import javax.inject.Inject; + +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING; +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING; +import static android.view.HapticFeedbackConstants.KEYBOARD_TAP; import static org.solovyev.android.calculator.App.cast; import static org.solovyev.android.calculator.App.getScreenMetrics; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple; @@ -36,11 +47,11 @@ import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobi public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPreferenceChangeListener, SimpleDragListener.DragProcessor, View.OnClickListener { public static float getTextScale(@NonNull Context context) { - return App.isTablet(context) ? 0.5f : 0.6f; + return App.isTablet(context) ? 0.4f : 0.5f; } - public static final float IMAGE_SCALE = 0.6f; - public static final float IMAGE_SCALE_ERASE = 0.5f; + public static final float IMAGE_SCALE = 0.5f; + public static final float IMAGE_SCALE_ERASE = 0.4f; @NonNull private final List dragButtons = new ArrayList<>(); diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java index fd1014f2..e0ad0d64 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java @@ -13,10 +13,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.Button; import android.widget.ImageButton; -import butterknife.Bind; -import butterknife.ButterKnife; -import jscl.NumeralBase; -import org.solovyev.android.Check; + import org.solovyev.android.calculator.Engine; import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.R; @@ -30,10 +27,16 @@ import org.solovyev.android.views.dragbutton.DragDirection; import javax.annotation.Nonnull; import javax.inject.Inject; +import butterknife.Bind; +import butterknife.ButterKnife; +import jscl.NumeralBase; + import static org.solovyev.android.calculator.Engine.Preferences.numeralBase; import static org.solovyev.android.calculator.Preferences.Gui.showEqualsButton; import static org.solovyev.android.calculator.Preferences.Gui.vibrateOnKeypress; -import static org.solovyev.android.views.dragbutton.DragDirection.*; +import static org.solovyev.android.views.dragbutton.DragDirection.down; +import static org.solovyev.android.views.dragbutton.DragDirection.left; +import static org.solovyev.android.views.dragbutton.DragDirection.up; public class PartialKeyboardUi extends BaseKeyboardUi { @@ -72,7 +75,6 @@ public class PartialKeyboardUi extends BaseKeyboardUi { clearButton.setNumeralBase(numeralBase.getPreference(preferences)); } if (eraseButton != null) { - Check.isTrue(IMAGE_SCALE == 0.6f); // backspace button is too big, scale it more prepareButton(eraseButton, IMAGE_SCALE_ERASE); longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator); diff --git a/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java b/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java index 7f62ca3a..85229f8e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java +++ b/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java @@ -24,22 +24,24 @@ package org.solovyev.android.calculator.wizard; import android.os.Bundle; import android.support.annotation.StringRes; -import android.view.ContextThemeWrapper; +import android.support.v7.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.FrameLayout; import android.widget.Spinner; + import org.solovyev.android.Views; import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; -import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; +import javax.annotation.Nonnull; + public class ChooseThemeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener { @Nonnull diff --git a/app/src/main/res/layout/cpp_app_editor.xml b/app/src/main/res/layout/cpp_app_editor.xml index 9e8fb289..dfc900a2 100644 --- a/app/src/main/res/layout/cpp_app_editor.xml +++ b/app/src/main/res/layout/cpp_app_editor.xml @@ -24,6 +24,4 @@ \ No newline at end of file + xmlns:a="http://schemas.android.com/apk/res/android"/> \ No newline at end of file diff --git a/app/src/main/res/layout/widget_editor.xml b/app/src/main/res/layout/widget_editor.xml index f96b9eb3..e84d5f57 100644 --- a/app/src/main/res/layout/widget_editor.xml +++ b/app/src/main/res/layout/widget_editor.xml @@ -6,19 +6,7 @@ ~ or visit http://se.solovyev.org --> - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/widget_editor_light.xml b/app/src/main/res/layout/widget_editor_light.xml index cb0c4abe..459b6f71 100644 --- a/app/src/main/res/layout/widget_editor_light.xml +++ b/app/src/main/res/layout/widget_editor_light.xml @@ -6,19 +6,7 @@ ~ or visit http://se.solovyev.org --> - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/widget_layout_lockscreen_collapsed.xml b/app/src/main/res/layout/widget_layout_lockscreen_collapsed.xml index 7f870349..2e0567f2 100644 --- a/app/src/main/res/layout/widget_layout_lockscreen_collapsed.xml +++ b/app/src/main/res/layout/widget_layout_lockscreen_collapsed.xml @@ -22,11 +22,6 @@ a:layout_width="0dp" a:layout_weight="3" a:gravity="center_vertical|left" - a:hint="@string/c_calc_editor_hint" - a:padding="@dimen/cpp_editor_padding" - a:scrollbars="vertical" - a:singleLine="false" - a:textIsSelectable="true" a:textSize="@dimen/cpp_widget_editor_text_size_collapsed" /> - 0.4;0.4;0.4;0.35 + 0.4;0.4;0.4;0.4 \ 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 a28a80c2..e72d20b0 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -55,7 +55,6 @@ text|textNoSuggestions center_vertical|left horizontal - @dimen/cpp_editor_padding @color/cpp_text @@ -68,6 +67,7 @@ ?attr/cpp_text_color textMultiLine|textNoSuggestions vertical + @dimen/cpp_editor_padding