back button behaviour

This commit is contained in:
Sergey Solovyev 2011-12-25 13:17:08 +04:00
parent 039298af7e
commit 422fd8f693
5 changed files with 29 additions and 2 deletions

View File

@ -159,4 +159,7 @@
<string name="c_calc_show_release_notes_title">Показывать замечания к выпуску</string> <string name="c_calc_show_release_notes_title">Показывать замечания к выпуску</string>
<string name="c_calc_show_release_notes_summary">Определяет показывать или нет всплывающее окно с замечаниями к выпуску после обновления новой версии</string> <string name="c_calc_show_release_notes_summary">Определяет показывать или нет всплывающее окно с замечаниями к выпуску после обновления новой версии</string>
<string name="c_calc_use_back_button_as_prev_summary">Устанавливает поведение по нажатию на кнопку Назад</string>
<string name="c_calc_use_back_button_as_prev_title">Использовать кнопку назад как назад по истории</string>
</resources> </resources>

View File

@ -24,6 +24,9 @@
<string name="p_calc_haptic_feedback_key">org.solovyev.android.calculator.CalculatorModel_haptic_feedback</string> <string name="p_calc_haptic_feedback_key">org.solovyev.android.calculator.CalculatorModel_haptic_feedback</string>
<string name="p_calc_haptic_feedback">false</string> <string name="p_calc_haptic_feedback">false</string>
<string name="p_calc_use_back_button_as_prev_key">org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev</string>
<string name="p_calc_use_back_button_as_prev">false</string>
<string name="p_calc_show_release_notes_key">org.solovyev.android.calculator.CalculatorActivity_show_release_notes</string> <string name="p_calc_show_release_notes_key">org.solovyev.android.calculator.CalculatorActivity_show_release_notes</string>
<string name="p_calc_show_release_notes">true</string> <string name="p_calc_show_release_notes">true</string>

View File

@ -159,4 +159,7 @@
<string name="c_calc_show_release_notes_title">Show release notes</string> <string name="c_calc_show_release_notes_title">Show release notes</string>
<string name="c_calc_show_release_notes_summary">Defines if release notes popup window should appear after update to the new version</string> <string name="c_calc_show_release_notes_summary">Defines if release notes popup window should appear after update to the new version</string>
<string name="c_calc_use_back_button_as_prev_summary">Defines the behaviour of the Back button</string>
<string name="c_calc_use_back_button_as_prev_title">Use Back button as history prev</string>
</resources> </resources>

View File

@ -92,6 +92,12 @@
a:title="@string/c_calc_show_release_notes_title" a:title="@string/c_calc_show_release_notes_title"
a:defaultValue="true"/> a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_use_back_button_as_prev_key"
a:summary="@string/c_calc_use_back_button_as_prev_summary"
a:title="@string/c_calc_use_back_button_as_prev_title"
a:defaultValue="false"/>
<!-- <org.solovyev.android.view.prefs.FloatRangeSeekBarPreference <!-- <org.solovyev.android.view.prefs.FloatRangeSeekBarPreference
a:key="@string/p_drag_duration_key" a:key="@string/p_drag_duration_key"
a:title="Duration of drag event" a:title="Duration of drag event"

View File

@ -56,6 +56,10 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
public static final String SHOW_RELEASE_NOTES_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_show_release_notes"; public static final String SHOW_RELEASE_NOTES_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_show_release_notes";
public static final boolean SHOW_RELEASE_NOTES_P_DEFAULT = true; public static final boolean SHOW_RELEASE_NOTES_P_DEFAULT = true;
@NotNull
public static final String USE_BACK_AS_PREV_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev";
public static final boolean USE_BACK_AS_PREV_DEFAULT = false;
@NotNull @NotNull
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class); private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
@ -73,6 +77,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@Nullable @Nullable
private Vibrator vibrator; private Vibrator vibrator;
private boolean useBackAsPrev = USE_BACK_AS_PREV_DEFAULT;
/** /**
* Called when the activity is first created. * Called when the activity is first created.
*/ */
@ -510,9 +516,11 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
if (useBackAsPrev) {
calculatorModel.doHistoryAction(HistoryAction.undo); calculatorModel.doHistoryAction(HistoryAction.undo);
return true; return true;
} }
}
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
@ -625,6 +633,10 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
this.calculatorModel.evaluate(); this.calculatorModel.evaluate();
} }
if ( USE_BACK_AS_PREV_P_KEY.equals(key) ) {
useBackAsPrev = preferences.getBoolean(USE_BACK_AS_PREV_P_KEY, USE_BACK_AS_PREV_DEFAULT);
}
if ( CalculatorEngine.MULTIPLICATION_SIGN_P_KEY.equals(key) ) { if ( CalculatorEngine.MULTIPLICATION_SIGN_P_KEY.equals(key) ) {
initMultiplicationButton(); initMultiplicationButton();
} }