Editor/display changes
This commit is contained in:
parent
726ef0795c
commit
631ea40c15
@ -7,7 +7,6 @@
|
|||||||
-->
|
-->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
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_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:id="@+id/main_layout"
|
a:id="@+id/main_layout"
|
||||||
@ -24,64 +23,40 @@
|
|||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp">
|
a:layout_height="0dp">
|
||||||
|
|
||||||
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
<include layout="@layout/calc_left_button"
|
||||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
a:layout_margin="@dimen/button_margin"
|
||||||
a:id="@+id/leftButton"
|
a:layout_width="0dp"
|
||||||
c:textUp="◀◀"
|
a:layout_height="match_parent"
|
||||||
a:text="◀"
|
a:layout_weight="1"/>
|
||||||
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_erase_button"
|
||||||
<org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
a:layout_margin="@dimen/button_margin"
|
||||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
a:layout_width="0dp"
|
||||||
a:id="@+id/eraseButton"
|
a:layout_height="match_parent"
|
||||||
a:drawableTop="@drawable/sym_keyboard_delete"
|
a:layout_weight="1"/>
|
||||||
style="?controlImageButtonStyle"
|
|
||||||
a:onClick="eraseButtonClickHandler"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/displayContainer"
|
<LinearLayout a:id="@+id/displayContainer"
|
||||||
|
a:layout_margin="@dimen/display_margin"
|
||||||
a:layout_weight="4"
|
a:layout_weight="4"
|
||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_height="match_parent"/>
|
a:layout_height="match_parent"/>
|
||||||
|
|
||||||
<org.solovyev.android.calculator.view.NumeralBasesButton xmlns:a="http://schemas.android.com/apk/res/android"
|
<include layout="@layout/calc_clear_button"
|
||||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
a:layout_margin="@dimen/button_margin"
|
||||||
a:id="@+id/clearButton"
|
a:layout_width="0dp"
|
||||||
c:textUp="dec"
|
a:layout_height="match_parent"
|
||||||
a:text="@string/c_clear"
|
a:layout_weight="1"/>
|
||||||
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"/>
|
|
||||||
|
|
||||||
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
<include layout="@layout/calc_right_button"
|
||||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
a:layout_margin="@dimen/button_margin"
|
||||||
a:id="@+id/rightButton"
|
a:layout_width="0dp"
|
||||||
c:textUp="▶▶"
|
a:layout_height="match_parent"
|
||||||
a:text="▶"
|
a:layout_weight="1"/>
|
||||||
c:directionTextScale="0.5"
|
|
||||||
style="?controlButtonStyle"
|
|
||||||
a:onClick="moveRightButtonClickHandler"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/keyboardContainer"
|
<LinearLayout a:id="@+id/keyboardContainer"
|
||||||
a:layout_weight="4"
|
a:layout_weight="3"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp"/>
|
a:layout_height="0dp"/>
|
||||||
|
|
||||||
|
@ -25,11 +25,13 @@
|
|||||||
a:layout_height="0dp">
|
a:layout_height="0dp">
|
||||||
|
|
||||||
<include layout="@layout/calc_equals_button"
|
<include layout="@layout/calc_equals_button"
|
||||||
|
a:layout_margin="@dimen/button_margin"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_height="match_parent"/>
|
a:layout_height="match_parent"/>
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/displayContainer"
|
<LinearLayout a:id="@+id/displayContainer"
|
||||||
|
a:layout_margin="@dimen/display_margin"
|
||||||
a:layout_weight="4"
|
a:layout_weight="4"
|
||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_height="match_parent"/>
|
a:layout_height="match_parent"/>
|
||||||
|
@ -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>
|
|
4
calculatorpp/res/values/dimensions.xml
Normal file
4
calculatorpp/res/values/dimensions.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<resources>
|
||||||
|
<dimen name="button_margin">0.5dp</dimen>
|
||||||
|
<dimen name="display_margin">@dimen/button_margin</dimen>
|
||||||
|
</resources>
|
@ -13,7 +13,7 @@
|
|||||||
<item name="android:layout_weight">1</item>
|
<item name="android:layout_weight">1</item>
|
||||||
<item name="android:focusable">true</item>
|
<item name="android:focusable">true</item>
|
||||||
<item name="android:background">@drawable/default_button_dark</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>
|
||||||
|
|
||||||
<style name="editor_style" parent="editor_style_parent">
|
<style name="editor_style" parent="editor_style_parent">
|
||||||
@ -26,7 +26,7 @@
|
|||||||
<item name="android:gravity">top|right</item>
|
<item name="android:gravity">top|right</item>
|
||||||
<item name="android:layout_width">match_parent</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="android:layout_height">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>
|
||||||
|
|
||||||
<style name="about_style" parent="about_style_parent">
|
<style name="about_style" parent="about_style_parent">
|
||||||
|
@ -5,12 +5,14 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.*;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -24,17 +26,18 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.FontSizeAdjuster;
|
import org.solovyev.android.FontSizeAdjuster;
|
||||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
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.calculator.view.CalculatorAdditionalTitle;
|
||||||
|
import org.solovyev.android.fragments.FragmentUtils;
|
||||||
import org.solovyev.android.menu.ActivityMenu;
|
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.prefs.Preference;
|
||||||
import org.solovyev.android.view.ColorButton;
|
import org.solovyev.android.view.ColorButton;
|
||||||
import org.solovyev.common.equals.EqualsTool;
|
import org.solovyev.common.equals.EqualsTool;
|
||||||
import org.solovyev.common.history.HistoryAction;
|
import org.solovyev.common.history.HistoryAction;
|
||||||
import org.solovyev.common.text.StringUtils;
|
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
|
@NotNull
|
||||||
public static final String TAG = "Calculator++";
|
public static final String TAG = "Calculator++";
|
||||||
@ -53,7 +56,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
private boolean useBackAsPrev;
|
private boolean useBackAsPrev;
|
||||||
|
|
||||||
@NotNull
|
@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.
|
* 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);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
setTheme(preferences);
|
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
|
||||||
|
setTheme(this.theme.getThemeId());
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setLayout(preferences);
|
setLayout(preferences);
|
||||||
|
|
||||||
CalculatorKeyboardFragment.fixThemeParameters(true, theme, this.getWindow().getDecorView());
|
CalculatorKeyboardFragment.fixThemeParameters(true, theme, this.getWindow().getDecorView());
|
||||||
|
|
||||||
createFragment(CalculatorEditorFragment.class, R.id.editorContainer, "tag");
|
FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
|
||||||
createFragment(CalculatorDisplayFragment.class, R.id.displayContainer, "display");
|
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
|
||||||
createFragment(CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
|
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
|
||||||
|
|
||||||
if (customTitleSupported) {
|
if (customTitleSupported) {
|
||||||
try {
|
try {
|
||||||
@ -105,31 +110,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
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
|
@NotNull
|
||||||
private AndroidCalculator getCalculator() {
|
private AndroidCalculator getCalculator() {
|
||||||
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
|
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
|
||||||
@ -141,11 +121,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
setContentView(layout.getLayoutId());
|
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) {
|
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
|
||||||
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
|
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
|
||||||
if (appOpenedCounter != null) {
|
if (appOpenedCounter != null) {
|
||||||
@ -233,6 +208,20 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
getCalculator().evaluate();
|
getCalculator().evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* MENU
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
|
return this.menu.onPrepareOptionsMenu(this, menu);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
return this.menu.onCreateOptionsMenu(this, menu);
|
return this.menu.onCreateOptionsMenu(this, menu);
|
||||||
@ -375,7 +364,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
CalculatorActivityLauncher.showOperators(this);
|
CalculatorActivityLauncher.showOperators(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void operatorsButtonClickHandler(@NotNull Activity activity, @NotNull View view) {
|
public static void operatorsButtonClickHandler(@NotNull Activity activity) {
|
||||||
CalculatorActivityLauncher.showOperators(activity);
|
CalculatorActivityLauncher.showOperators(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,10 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
setTheme(preferences);
|
||||||
|
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
final AndroidCalculator calculator = new AndroidCalculator();
|
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);
|
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) {
|
public static void showDonationDialog(@NotNull final Context context) {
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||||
final View view = layoutInflater.inflate(R.layout.donate, null);
|
final View view = layoutInflater.inflate(R.layout.donate, null);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Fragment;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Fragment;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -101,7 +101,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
|
|||||||
@Override
|
@Override
|
||||||
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
||||||
if (dragDirection == DragDirection.down) {
|
if (dragDirection == DragDirection.down) {
|
||||||
CalculatorActivity.operatorsButtonClickHandler(getActivity(), dragButton);
|
CalculatorActivity.operatorsButtonClickHandler(getActivity());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -6,51 +6,51 @@ import android.util.Log;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
||||||
import org.solovyev.android.menu.IdentifiableMenuItem;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 4/23/12
|
* Date: 4/23/12
|
||||||
* Time: 2:25 PM
|
* 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
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
CalculatorActivityLauncher.showSettings(context);
|
CalculatorActivityLauncher.showSettings(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
history(R.id.main_menu_item_history) {
|
history(R.string.c_history) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
CalculatorActivityLauncher.showHistory(context);
|
CalculatorActivityLauncher.showHistory(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
about(R.id.main_menu_item_about) {
|
about(R.string.c_about) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
CalculatorActivityLauncher.showAbout(context);
|
CalculatorActivityLauncher.showAbout(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
help(R.id.main_menu_item_help) {
|
help(R.string.c_help) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
CalculatorActivityLauncher.showHelp(context);
|
CalculatorActivityLauncher.showHelp(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
conversion_tool( R.id.main_menu_conversion_tool) {
|
conversion_tool(R.string.c_conversion_tool) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
new NumeralBaseConverterDialog(null).show(context);
|
new NumeralBaseConverterDialog(null).show(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
exit(R.id.main_menu_item_exit) {
|
exit(R.string.c_exit) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
if (context instanceof Activity) {
|
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) {
|
private CalculatorMenu(int captionResId) {
|
||||||
this.menuItemId = menuItemId;
|
this.captionResId = captionResId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Integer getItemId() {
|
public String getCaption(@NotNull Context context) {
|
||||||
return menuItemId;
|
return context.getString(captionResId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,11 @@ public final class CalculatorPreferences {
|
|||||||
public static final Preference<Boolean> autoOrientation = new BooleanPreference("autoOrientation", true);
|
public static final Preference<Boolean> autoOrientation = new BooleanPreference("autoOrientation", true);
|
||||||
public static final Preference<Boolean> hideNumeralBaseDigits = new BooleanPreference("hideNumeralBaseDigits", 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 {
|
public static enum Theme {
|
||||||
|
|
||||||
default_theme(ThemeType.other, R.style.default_theme),
|
default_theme(ThemeType.other, R.style.default_theme),
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user