Editor/display changes

This commit is contained in:
Sergey Solovyev 2012-09-25 22:25:08 +04:00
parent 726ef0795c
commit 631ea40c15
13 changed files with 1264 additions and 1266 deletions

View File

@ -7,7 +7,6 @@
-->
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:id="@+id/main_layout"
@ -24,64 +23,40 @@
a:layout_width="match_parent"
a:layout_height="0dp">
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/leftButton"
c:textUp="◀◀"
a:text="◀"
c:directionTextScale="0.5"
style="?controlButtonStyle"
a:onClick="moveLeftButtonClickHandler"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1"/>
<include layout="@layout/calc_left_button"
a:layout_margin="@dimen/button_margin"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1"/>
<org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/eraseButton"
a:drawableTop="@drawable/sym_keyboard_delete"
style="?controlImageButtonStyle"
a:onClick="eraseButtonClickHandler"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1"/>
<include layout="@layout/calc_erase_button"
a:layout_margin="@dimen/button_margin"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1"/>
<LinearLayout a:id="@+id/displayContainer"
a:layout_margin="@dimen/display_margin"
a:layout_weight="4"
a:layout_width="0dp"
a:layout_height="match_parent"/>
<org.solovyev.android.calculator.view.NumeralBasesButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/clearButton"
c:textUp="dec"
a:text="@string/c_clear"
c:textDown="bin"
c:textLeft="hex"
a:textStyle="bold"
style="?controlImageButtonStyle"
a:onClick="clearButtonClickHandler"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1"/>
<include layout="@layout/calc_clear_button"
a:layout_margin="@dimen/button_margin"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1"/>
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/rightButton"
c:textUp="▶▶"
a:text="▶"
c:directionTextScale="0.5"
style="?controlButtonStyle"
a:onClick="moveRightButtonClickHandler"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1"/>
<include layout="@layout/calc_right_button"
a:layout_margin="@dimen/button_margin"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1"/>
</LinearLayout>
<LinearLayout a:id="@+id/keyboardContainer"
a:layout_weight="4"
a:layout_weight="3"
a:layout_width="match_parent"
a:layout_height="0dp"/>

View File

@ -25,11 +25,13 @@
a:layout_height="0dp">
<include layout="@layout/calc_equals_button"
a:layout_margin="@dimen/button_margin"
a:layout_weight="1"
a:layout_width="0dp"
a:layout_height="match_parent"/>
<LinearLayout a:id="@+id/displayContainer"
a:layout_margin="@dimen/display_margin"
a:layout_weight="4"
a:layout_width="0dp"
a:layout_height="match_parent"/>

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:a="http://schemas.android.com/apk/res/android">
<item a:id="@+id/main_menu_item_settings"
a:title="@string/c_settings"/>
<item a:id="@+id/main_menu_item_history"
a:title="@string/c_history"/>
<item a:id="@+id/main_menu_conversion_tool"
a:title="@string/c_conversion_tool"/>
<item a:id="@+id/main_menu_item_help"
a:title="@string/c_help"/>
<item a:id="@+id/main_menu_item_about"
a:title="@string/c_about"/>
<item a:id="@+id/main_menu_item_exit"
a:title="@string/c_exit"/>
</menu>

View File

@ -0,0 +1,4 @@
<resources>
<dimen name="button_margin">0.5dp</dimen>
<dimen name="display_margin">@dimen/button_margin</dimen>
</resources>

View File

@ -13,7 +13,7 @@
<item name="android:layout_weight">1</item>
<item name="android:focusable">true</item>
<item name="android:background">@drawable/default_button_dark</item>
<item name="android:layout_margin">0.5dp</item>
<item name="android:layout_margin">@dimen/button_margin</item>
</style>
<style name="editor_style" parent="editor_style_parent">
@ -26,7 +26,7 @@
<item name="android:gravity">top|right</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">0.5dp</item>
<item name="android:layout_margin">@dimen/display_margin</item>
</style>
<style name="about_style" parent="about_style_parent">

View File

@ -5,12 +5,14 @@
package org.solovyev.android.calculator;
import android.app.*;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
@ -24,17 +26,18 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.android.AndroidUtils;
import org.solovyev.android.FontSizeAdjuster;
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.view.CalculatorAdditionalTitle;
import org.solovyev.android.fragments.FragmentUtils;
import org.solovyev.android.menu.ActivityMenu;
import org.solovyev.android.menu.LayoutActivityMenu;
import org.solovyev.android.menu.AndroidMenuHelper;
import org.solovyev.android.menu.ListActivityMenu;
import org.solovyev.android.prefs.Preference;
import org.solovyev.android.view.ColorButton;
import org.solovyev.common.equals.EqualsTool;
import org.solovyev.common.history.HistoryAction;
import org.solovyev.common.text.StringUtils;
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
public class CalculatorActivity extends FragmentActivity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
@NotNull
public static final String TAG = "Calculator++";
@ -53,7 +56,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
private boolean useBackAsPrev;
@NotNull
private ActivityMenu<Menu, MenuItem> menu = LayoutActivityMenu.newInstance(R.menu.main_menu, CalculatorMenu.class);
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromList(CalculatorMenu.class, AndroidMenuHelper.getInstance());
/**
* Called when the activity is first created.
@ -67,15 +70,17 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
setTheme(preferences);
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
setTheme(this.theme.getThemeId());
super.onCreate(savedInstanceState);
setLayout(preferences);
CalculatorKeyboardFragment.fixThemeParameters(true, theme, this.getWindow().getDecorView());
createFragment(CalculatorEditorFragment.class, R.id.editorContainer, "tag");
createFragment(CalculatorDisplayFragment.class, R.id.displayContainer, "display");
createFragment(CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
if (customTitleSupported) {
try {
@ -105,31 +110,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
preferences.registerOnSharedPreferenceChangeListener(this);
}
private void createFragment(@NotNull Class<? extends Fragment> fragmentClass, int parentViewId, @NotNull String tag) {
final FragmentManager fm = getFragmentManager();
Fragment messagesFragment = fm.findFragmentByTag(tag);
final FragmentTransaction ft = fm.beginTransaction();
try {
if (messagesFragment == null) {
messagesFragment = Fragment.instantiate(this, fragmentClass.getName(), null);
ft.add(parentViewId, messagesFragment, tag);
} else {
if (messagesFragment.isDetached()) {
ft.attach(messagesFragment);
}
}
} finally {
ft.commit();
}
}
@NotNull
private AndroidCalculatorEngine getEngine() {
return ((AndroidCalculatorEngine) CalculatorLocatorImpl.getInstance().getEngine());
}
@NotNull
private AndroidCalculator getCalculator() {
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
@ -141,11 +121,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
setContentView(layout.getLayoutId());
}
private synchronized void setTheme(@NotNull SharedPreferences preferences) {
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
setTheme(theme.getThemeId());
}
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
if (appOpenedCounter != null) {
@ -233,6 +208,20 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
getCalculator().evaluate();
}
/*
**********************************************************************
*
* MENU
*
**********************************************************************
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return this.menu.onPrepareOptionsMenu(this, menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return this.menu.onCreateOptionsMenu(this, menu);
@ -375,7 +364,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
CalculatorActivityLauncher.showOperators(this);
}
public static void operatorsButtonClickHandler(@NotNull Activity activity, @NotNull View view) {
public static void operatorsButtonClickHandler(@NotNull Activity activity) {
CalculatorActivityLauncher.showOperators(activity);
}

View File

@ -46,6 +46,10 @@ public class CalculatorApplication extends android.app.Application {
@Override
public void onCreate() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
setTheme(preferences);
super.onCreate();
final AndroidCalculator calculator = new AndroidCalculator();
@ -71,11 +75,14 @@ public class CalculatorApplication extends android.app.Application {
}
});
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
CalculatorPreferences.setDefaultValues(preferences);
}
private void setTheme(@NotNull SharedPreferences preferences) {
final CalculatorPreferences.Gui.Theme theme = CalculatorPreferences.Gui.getTheme(preferences);
setTheme(theme.getThemeId());
}
public static void showDonationDialog(@NotNull final Context context) {
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
final View view = layoutInflater.inflate(R.layout.donate, null);

View File

@ -1,7 +1,7 @@
package org.solovyev.android.calculator;
import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

View File

@ -1,7 +1,7 @@
package org.solovyev.android.calculator;
import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

View File

@ -1,13 +1,13 @@
package org.solovyev.android.calculator;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.*;
import android.widget.Button;
@ -101,7 +101,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
@Override
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
if (dragDirection == DragDirection.down) {
CalculatorActivity.operatorsButtonClickHandler(getActivity(), dragButton);
CalculatorActivity.operatorsButtonClickHandler(getActivity());
return true;
}
return false;

View File

@ -6,51 +6,51 @@ import android.util.Log;
import android.view.MenuItem;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
import org.solovyev.android.menu.IdentifiableMenuItem;
import org.solovyev.android.menu.LabeledMenuItem;
/**
* User: serso
* Date: 4/23/12
* Time: 2:25 PM
*/
enum CalculatorMenu implements IdentifiableMenuItem<MenuItem> {
enum CalculatorMenu implements LabeledMenuItem<MenuItem> {
settings(R.id.main_menu_item_settings){
settings(R.string.c_settings) {
@Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
CalculatorActivityLauncher.showSettings(context);
}
},
history(R.id.main_menu_item_history) {
history(R.string.c_history) {
@Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
CalculatorActivityLauncher.showHistory(context);
}
},
about(R.id.main_menu_item_about) {
about(R.string.c_about) {
@Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
CalculatorActivityLauncher.showAbout(context);
}
},
help(R.id.main_menu_item_help) {
help(R.string.c_help) {
@Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
CalculatorActivityLauncher.showHelp(context);
}
},
conversion_tool( R.id.main_menu_conversion_tool) {
conversion_tool(R.string.c_conversion_tool) {
@Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
new NumeralBaseConverterDialog(null).show(context);
}
},
exit(R.id.main_menu_item_exit) {
exit(R.string.c_exit) {
@Override
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
if (context instanceof Activity) {
@ -61,15 +61,15 @@ enum CalculatorMenu implements IdentifiableMenuItem<MenuItem> {
}
};
private final int menuItemId;
private final int captionResId;
private CalculatorMenu (int menuItemId) {
this.menuItemId = menuItemId;
private CalculatorMenu(int captionResId) {
this.captionResId = captionResId;
}
@NotNull
@Override
public Integer getItemId() {
return menuItemId;
public String getCaption(@NotNull Context context) {
return context.getString(captionResId);
}
}

View File

@ -39,6 +39,11 @@ public final class CalculatorPreferences {
public static final Preference<Boolean> autoOrientation = new BooleanPreference("autoOrientation", true);
public static final Preference<Boolean> hideNumeralBaseDigits = new BooleanPreference("hideNumeralBaseDigits", true);
@NotNull
public static Theme getTheme(@NotNull SharedPreferences preferences) {
return theme.getPreferenceNoError(preferences);
}
public static enum Theme {
default_theme(ThemeType.other, R.style.default_theme),

View File

@ -0,0 +1,38 @@
package org.solovyev.android.fragments;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 9/25/12
* Time: 9:29 PM
*/
public class FragmentUtils {
public static void createFragment(@NotNull FragmentActivity activity,
@NotNull Class<? extends Fragment> fragmentClass,
int parentViewId,
@NotNull String tag) {
final FragmentManager fm = activity.getSupportFragmentManager();
Fragment messagesFragment = fm.findFragmentByTag(tag);
final FragmentTransaction ft = fm.beginTransaction();
try {
if (messagesFragment == null) {
messagesFragment = Fragment.instantiate(activity, fragmentClass.getName(), null);
ft.add(parentViewId, messagesFragment, tag);
} else {
if (messagesFragment.isDetached()) {
ft.attach(messagesFragment);
}
}
} finally {
ft.commit();
}
}
}