cellphone/calculator layouts
This commit is contained in:
parent
cd546ecc47
commit
d58f0356f6
120
res/layout-land/main_calculator.xml
Normal file
120
res/layout-land/main_calculator.xml
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
|
~ or visit http://se.solovyev.org
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||||
|
a:orientation="vertical"
|
||||||
|
a:layout_width="fill_parent"
|
||||||
|
a:layout_height="fill_parent"
|
||||||
|
a:background="#ff000000">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
a:layout_width="fill_parent"
|
||||||
|
a:layout_height="fill_parent"
|
||||||
|
a:orientation="vertical"
|
||||||
|
a:layout_gravity="center">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_editor"/>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||||
|
a:id="@+id/leftButton"
|
||||||
|
calc:textUp="◀◀"
|
||||||
|
a:text="◀"
|
||||||
|
calc:directionTextScale="0.5"
|
||||||
|
style="?controlButtonStyle"
|
||||||
|
a:onClick="moveLeftButtonClickHandler"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="fill_parent"
|
||||||
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
|
|
||||||
|
<org.solovyev.android.view.widgets.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:calc="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="fill_parent"
|
||||||
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
|
|
||||||
|
<include layout="@layout/calc_display"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="fill_parent"
|
||||||
|
a:layout_weight="4"/>
|
||||||
|
|
||||||
|
<org.solovyev.android.view.widgets.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||||
|
a:id="@+id/clearButton"
|
||||||
|
a:text="@string/c_clear"
|
||||||
|
a:textStyle="bold"
|
||||||
|
style="?controlImageButtonStyle"
|
||||||
|
a:onClick="clearButtonClickHandler"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="fill_parent"
|
||||||
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
|
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||||
|
a:id="@+id/rightButton"
|
||||||
|
calc:textUp="▶▶"
|
||||||
|
a:text="▶"
|
||||||
|
calc:directionTextScale="0.5"
|
||||||
|
style="?controlButtonStyle"
|
||||||
|
a:onClick="moveRightButtonClickHandler"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="fill_parent"
|
||||||
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_history_button"/>
|
||||||
|
<include layout="@layout/calc_copy_button"/>
|
||||||
|
<include layout="@layout/calc_seven_digit_button"/>
|
||||||
|
<include layout="@layout/calc_eight_digit_button"/>
|
||||||
|
<include layout="@layout/calc_nine_digit_button"/>
|
||||||
|
<include layout="@layout/calc_multiplication_button"/>
|
||||||
|
<include layout="@layout/calc_division_button"/>
|
||||||
|
<include layout="@layout/calc_equals_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_vars_button"/>
|
||||||
|
<include layout="@layout/calc_paste_button"/>
|
||||||
|
<include layout="@layout/calc_four_digit_button"/>
|
||||||
|
<include layout="@layout/calc_five_digit_button"/>
|
||||||
|
<include layout="@layout/calc_six_digit_button"/>
|
||||||
|
<include layout="@layout/calc_plus_button"/>
|
||||||
|
<include layout="@layout/calc_subtraction_button"/>
|
||||||
|
<include layout="@layout/calc_empty_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_donate_button"/>
|
||||||
|
<include layout="@layout/calc_empty_button"/>
|
||||||
|
<include layout="@layout/calc_one_digit_button"/>
|
||||||
|
<include layout="@layout/calc_two_digit_button"/>
|
||||||
|
<include layout="@layout/calc_three_digit_button"/>
|
||||||
|
<include layout="@layout/calc_zero_digit_button"/>
|
||||||
|
<include layout="@layout/calc_round_brackets_button"/>
|
||||||
|
<include layout="@layout/calc_square_brackets_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
88
res/layout-port/main_calculator.xml
Normal file
88
res/layout-port/main_calculator.xml
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
|
~ or visit http://se.solovyev.org
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
a:orientation="vertical"
|
||||||
|
a:layout_width="fill_parent"
|
||||||
|
a:layout_height="fill_parent"
|
||||||
|
a:background="#ff000000">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
a:layout_width="fill_parent"
|
||||||
|
a:layout_height="fill_parent"
|
||||||
|
a:orientation="vertical"
|
||||||
|
a:layout_gravity="center">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_editor"/>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_equals_button"
|
||||||
|
a:layout_weight="4"
|
||||||
|
a:layout_width="fill_parent"
|
||||||
|
a:layout_height="fill_parent"/>
|
||||||
|
|
||||||
|
<include layout="@layout/calc_display"
|
||||||
|
a:layout_weight="1"
|
||||||
|
a:layout_width="fill_parent"
|
||||||
|
a:layout_height="fill_parent"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_seven_digit_button"/>
|
||||||
|
<include layout="@layout/calc_eight_digit_button"/>
|
||||||
|
<include layout="@layout/calc_nine_digit_button"/>
|
||||||
|
<include layout="@layout/calc_multiplication_button"/>
|
||||||
|
<include layout="@layout/calc_clear_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_four_digit_button"/>
|
||||||
|
<include layout="@layout/calc_five_digit_button"/>
|
||||||
|
<include layout="@layout/calc_six_digit_button"/>
|
||||||
|
<include layout="@layout/calc_division_button"/>
|
||||||
|
<include layout="@layout/calc_erase_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_one_digit_button"/>
|
||||||
|
<include layout="@layout/calc_two_digit_button"/>
|
||||||
|
<include layout="@layout/calc_three_digit_button"/>
|
||||||
|
<include layout="@layout/calc_plus_button"/>
|
||||||
|
<include layout="@layout/calc_copy_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_round_brackets_button"/>
|
||||||
|
<include layout="@layout/calc_zero_digit_button"/>
|
||||||
|
<include layout="@layout/calc_square_brackets_button"/>
|
||||||
|
<include layout="@layout/calc_subtraction_button"/>
|
||||||
|
<include layout="@layout/calc_paste_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_left_button"/>
|
||||||
|
<include layout="@layout/calc_right_button"/>
|
||||||
|
<include layout="@layout/calc_vars_button"/>
|
||||||
|
<include layout="@layout/calc_history_button"/>
|
||||||
|
<include layout="@layout/calc_donate_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
@ -92,4 +92,9 @@
|
|||||||
<string name="c_calc_grouping_separator">Разделитель разрядов</string>
|
<string name="c_calc_grouping_separator">Разделитель разрядов</string>
|
||||||
<string name="c_calc_grouping_separator_summary">Устанавливает разделитель разрядов числа</string>
|
<string name="c_calc_grouping_separator_summary">Устанавливает разделитель разрядов числа</string>
|
||||||
|
|
||||||
|
<string name="c_calc_layout">Раскладка</string>
|
||||||
|
<string name="p_layout_cellphone">Телефон</string>
|
||||||
|
<string name="p_layout_calculator">Калькулятор</string>
|
||||||
|
<string name="c_calc_layout_summary">Устанавливает раскладку кнопок</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -27,4 +27,13 @@
|
|||||||
<item>" "</item>
|
<item>" "</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="p_layout_names">
|
||||||
|
<item>@string/p_layout_cellphone</item>
|
||||||
|
<item>@string/p_layout_calculator</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="p_layout_values">
|
||||||
|
<item>main_cellphone</item>
|
||||||
|
<item>main_calculator</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -24,6 +24,9 @@
|
|||||||
<string name="p_calc_theme_key">org.solovyev.android.calculator.CalculatorActivity_calc_theme</string>
|
<string name="p_calc_theme_key">org.solovyev.android.calculator.CalculatorActivity_calc_theme</string>
|
||||||
<string name="p_calc_theme">default_theme</string>
|
<string name="p_calc_theme">default_theme</string>
|
||||||
|
|
||||||
|
<string name="p_calc_layout_key">org.solovyev.android.calculator.CalculatorActivity_calc_layout</string>
|
||||||
|
<string name="p_calc_layout">main_cellphone</string>
|
||||||
|
|
||||||
<string name="p_calc_grouping_separator_key">org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator</string>
|
<string name="p_calc_grouping_separator_key">org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator</string>
|
||||||
<string name="p_calc_grouping_separator"> </string>
|
<string name="p_calc_grouping_separator"> </string>
|
||||||
|
|
||||||
|
@ -91,4 +91,10 @@
|
|||||||
<string name="p_grouping_separator_space">Space ( )</string>
|
<string name="p_grouping_separator_space">Space ( )</string>
|
||||||
<string name="c_calc_grouping_separator">Grouping separator</string>
|
<string name="c_calc_grouping_separator">Grouping separator</string>
|
||||||
<string name="c_calc_grouping_separator_summary">Sets grouping separator</string>
|
<string name="c_calc_grouping_separator_summary">Sets grouping separator</string>
|
||||||
|
|
||||||
|
<string name="c_calc_layout">Layout</string>
|
||||||
|
<string name="p_layout_cellphone">Cellphone</string>
|
||||||
|
<string name="p_layout_calculator">Calculator</string>
|
||||||
|
<string name="c_calc_layout_summary">Sets layout of buttons</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -29,6 +29,12 @@
|
|||||||
a:summary="@string/c_calc_theme_summary"
|
a:summary="@string/c_calc_theme_summary"
|
||||||
a:entryValues="@array/p_theme_values"/>
|
a:entryValues="@array/p_theme_values"/>
|
||||||
|
|
||||||
|
<ListPreference a:key="@string/p_calc_layout_key"
|
||||||
|
a:title="@string/c_calc_layout"
|
||||||
|
a:entries="@array/p_layout_names"
|
||||||
|
a:summary="@string/c_calc_layout_summary"
|
||||||
|
a:entryValues="@array/p_layout_values"/>
|
||||||
|
|
||||||
|
|
||||||
<!-- <org.solovyev.android.view.prefs.FloatRangeSeekBarPreference
|
<!-- <org.solovyev.android.view.prefs.FloatRangeSeekBarPreference
|
||||||
a:key="@string/p_drag_distance_key"
|
a:key="@string/p_drag_distance_key"
|
||||||
|
@ -44,6 +44,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
|
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final static Map<Class<?>, Map<String, Integer>> caches = new HashMap<Class<?>, Map<String, Integer>>(3);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorModel calculatorModel;
|
private CalculatorModel calculatorModel;
|
||||||
|
|
||||||
@ -52,8 +55,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
@NotNull
|
@NotNull
|
||||||
private String themeName;
|
private String themeName;
|
||||||
|
|
||||||
// key: style name, value: id of style in R.class
|
@NotNull
|
||||||
private Map<String, Integer> styles = null;
|
private String layoutName;
|
||||||
|
|
||||||
// ids of drag buttons in R.class
|
// ids of drag buttons in R.class
|
||||||
private List<Integer> dragButtonIds = null;
|
private List<Integer> dragButtonIds = null;
|
||||||
@ -71,7 +74,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
|
|
||||||
setTheme(preferences);
|
setTheme(preferences);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
setLayout(preferences);
|
||||||
|
|
||||||
firstTimeInit(preferences);
|
firstTimeInit(preferences);
|
||||||
|
|
||||||
@ -151,24 +154,26 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void setTheme(@NotNull SharedPreferences preferences) {
|
|
||||||
if (styles == null) {
|
private synchronized void setLayout(@NotNull SharedPreferences preferences) {
|
||||||
styles = new HashMap<String, Integer>();
|
final Map<String, Integer> layouts = getCache(R.layout.class);
|
||||||
for (Field themeField : R.style.class.getDeclaredFields()) {
|
|
||||||
int modifiers = themeField.getModifiers();
|
layoutName = preferences.getString(getString(R.string.p_calc_layout_key), getString(R.string.p_calc_layout));
|
||||||
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
|
|
||||||
try {
|
Integer layoutId = layouts.get(layoutName);
|
||||||
Log.d(this.getClass().getName(), "Style found: " + themeField.getName());
|
if (layoutId == null) {
|
||||||
int styleId = themeField.getInt(R.style.class);
|
Log.d(this.getClass().getName(), "No saved layout found => applying default layout: " + R.layout.main_cellphone);
|
||||||
Log.d(this.getClass().getName(), "Style id: " + styleId);
|
layoutId = R.layout.main_cellphone;
|
||||||
styles.put(themeField.getName(), styleId);
|
} else {
|
||||||
} catch (IllegalAccessException e) {
|
Log.d(this.getClass().getName(), "Saved layout found: " + layoutId);
|
||||||
Log.e(CalculatorActivity.class.getName(), e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setContentView(layoutId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void setTheme(@NotNull SharedPreferences preferences) {
|
||||||
|
final Map<String, Integer> styles = getCache(R.style.class);
|
||||||
|
|
||||||
themeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme));
|
themeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme));
|
||||||
|
|
||||||
Integer styleId = styles.get(themeName);
|
Integer styleId = styles.get(themeName);
|
||||||
@ -176,12 +181,36 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
Log.d(this.getClass().getName(), "No saved theme found => applying default theme: " + R.style.default_theme);
|
Log.d(this.getClass().getName(), "No saved theme found => applying default theme: " + R.style.default_theme);
|
||||||
styleId = R.style.default_theme;
|
styleId = R.style.default_theme;
|
||||||
} else {
|
} else {
|
||||||
Log.d(this.getClass().getName(), "Saved them found: " + styleId);
|
Log.d(this.getClass().getName(), "Saved theme found: " + styleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTheme(styleId);
|
setTheme(styleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static Map<String, Integer> getCache(@NotNull Class<?> clazz) {
|
||||||
|
Map<String, Integer> result = caches.get(clazz);
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
result = new HashMap<String, Integer>();
|
||||||
|
|
||||||
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
|
int modifiers = field.getModifiers();
|
||||||
|
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
|
||||||
|
try {
|
||||||
|
result.put(field.getName(), field.getInt(R.style.class));
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
Log.e(CalculatorActivity.class.getName(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
caches.put(clazz, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized void firstTimeInit(@NotNull SharedPreferences preferences) {
|
private synchronized void firstTimeInit(@NotNull SharedPreferences preferences) {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
try {
|
try {
|
||||||
@ -390,8 +419,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
final String newLayoutName = preferences.getString(getString(R.string.p_calc_layout_key), getString(R.string.p_calc_layout));
|
||||||
final String newThemeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme));
|
final String newThemeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme));
|
||||||
if (!newThemeName.equals(themeName)) {
|
if (!themeName.equals(newThemeName) || !layoutName.equals(newLayoutName)) {
|
||||||
restart();
|
restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user