UI changes

This commit is contained in:
serso 2016-03-01 17:43:11 +01:00
parent ea21bbe811
commit 9bcc4d4d9f
15 changed files with 91 additions and 94 deletions

View File

@ -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;
}
}

View File

@ -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)) {

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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<DragButton> dragButtons = new ArrayList<>();

View File

@ -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);

View File

@ -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

View File

@ -24,6 +24,4 @@
<org.solovyev.android.calculator.EditorView
a:id="@+id/calculator_editor"
style="@style/CppText.Editor"
xmlns:a="http://schemas.android.com/apk/res/android"
a:hint="@string/c_calc_editor_hint"
a:padding="@dimen/cpp_editor_padding" />
xmlns:a="http://schemas.android.com/apk/res/android"/>

View File

@ -6,19 +6,7 @@
~ or visit http://se.solovyev.org
-->
<FrameLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:padding="@dimen/cpp_editor_padding">
<TextView
a:id="@+id/calculator_editor"
style="@style/CppText.Editor.Widget"
a:hint="@string/c_calc_editor_hint"
a:scrollbars="vertical"
a:singleLine="false"
a:textIsSelectable="true" />
</FrameLayout>
<TextView
a:id="@+id/calculator_editor"
style="@style/CppText.Editor.Widget"
xmlns:a="http://schemas.android.com/apk/res/android"/>

View File

@ -6,19 +6,7 @@
~ or visit http://se.solovyev.org
-->
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:padding="@dimen/cpp_editor_padding">
<TextView
a:id="@+id/calculator_editor"
style="@style/CppText.Editor.Widget.Light"
a:hint="@string/c_calc_editor_hint"
a:scrollbars="vertical"
a:singleLine="false"
a:textIsSelectable="true" />
</LinearLayout>
<TextView
a:id="@+id/calculator_editor"
style="@style/CppText.Editor.Widget.Light"
xmlns:a="http://schemas.android.com/apk/res/android"/>

View File

@ -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" />
<include

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="cpp_direction_text_size" translatable="false">0.4;0.4;0.4;0.35</string>
<string name="cpp_direction_text_size" translatable="false">0.4;0.4;0.4;0.4</string>
</resources>

View File

@ -55,7 +55,6 @@
<item name="android:inputType">text|textNoSuggestions</item>
<item name="android:gravity">center_vertical|left</item>
<item name="android:scrollbars">horizontal</item>
<item name="android:padding">@dimen/cpp_editor_padding</item>
<item name="android:textColor">@color/cpp_text</item>
</style>
@ -68,6 +67,7 @@
<item name="android:textColor">?attr/cpp_text_color</item>
<item name="android:inputType">textMultiLine|textNoSuggestions</item>
<item name="android:scrollbars">vertical</item>
<item name="android:padding">@dimen/cpp_editor_padding</item>
</style>
<style name="CppText.Display" parent="CppText">
@ -120,6 +120,9 @@
<style name="CppText.Editor.Widget" parent="CppText.Editor">
<item name="android:textSize">@dimen/cpp_widget_editor_text_size</item>
<item name="android:textColor">@color/cpp_text</item>
<item name="android:scrollbars">vertical</item>
<item name="android:singleLine">false</item>
<item name="android:textIsSelectable">true</item>
</style>
<style name="CppText.Editor.Widget.Light" parent="CppText.Editor.Widget">

View File

@ -5,7 +5,7 @@
<string name="cpp_kb_operators" translatable="false"></string>
<string name="cpp_kb_undo" translatable="false"></string>
<string name="cpp_kb_redo" translatable="false"></string>
<string name="cpp_direction_text_size" translatable="false">0.3;0.3;0.3;0.25</string>
<string name="cpp_direction_text_size" translatable="false">0.3;0.3;0.3;0.3</string>
<string name="cpp_plot_add_function" translatable="false">+</string>
<string name="cpp_plot_zoom_in" translatable="false">+</string>
<string name="cpp_plot_zoom_reset" translatable="false">0</string>