Orientation change lock

This commit is contained in:
Sergey Solovyev 2012-04-21 12:33:51 +04:00
parent c42530f534
commit 2171d9dd2c
6 changed files with 36 additions and 4 deletions

View File

@ -10,7 +10,9 @@
<application android:debuggable="true" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication"> <application android:debuggable="true" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication">
<activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan"> <activity android:label="@string/c_app_name"
android:name=".CalculatorActivity"
android:windowSoftInputMode="adjustPan">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

View File

@ -0,0 +1,7 @@
<resources>
<string name="c_auto_orientation_title">Toggle screen orientation change</string>
<string name="c_auto_orientation_summary">If turned on calculator will change screen orientation automatically</string>
<string name="c_show_equals_button_title">Show equals button</string>
<string name="c_show_equals_button_summary">Preference hides or shows equals button</string>
</resources>

View File

@ -134,6 +134,13 @@
a:defaultValue="0;45" a:defaultValue="0;45"
range:steps="5" range:steps="5"
range:boundaries="0;45"/>--> range:boundaries="0;45"/>-->
<android.preference.CheckBoxPreference
a:key="autoOrientation"
a:title="@string/c_auto_orientation_title"
a:summary="@string/c_auto_orientation_summary"
a:defaultValue="false"/>
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen

View File

@ -8,6 +8,7 @@ package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.*; import android.content.*;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
@ -225,6 +226,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
numeralBaseButtons.addButtonId(R.id.sixDigitButton); numeralBaseButtons.addButtonId(R.id.sixDigitButton);
numeralBaseButtons.toggleNumericDigits(this, preferences); numeralBaseButtons.toggleNumericDigits(this, preferences);
toggleOrientationChange(preferences);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
} }
@ -670,6 +673,10 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences); useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
} }
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
toggleOrientationChange(preferences);
}
if (CalculatorEngine.Preferences.numeralBase.getKey().equals(key)) { if (CalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
numeralBaseButtons.toggleNumericDigits(this, preferences); numeralBaseButtons.toggleNumericDigits(this, preferences);
} }
@ -679,6 +686,15 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
} }
} }
private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
private void initMultiplicationButton() { private void initMultiplicationButton() {
final View multiplicationButton = findViewById(R.id.multiplicationButton); final View multiplicationButton = findViewById(R.id.multiplicationButton);
if ( multiplicationButton instanceof Button) { if ( multiplicationButton instanceof Button) {

View File

@ -35,6 +35,7 @@ public final class CalculatorPreferences {
public static final Preference<Boolean> showReleaseNotes = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true); public static final Preference<Boolean> showReleaseNotes = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
public static final Preference<Boolean> usePrevAsBack = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false); public static final Preference<Boolean> usePrevAsBack = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false);
public static final Preference<Boolean> showEqualsButton = new BooleanPreference("showEqualsButton", true); public static final Preference<Boolean> showEqualsButton = new BooleanPreference("showEqualsButton", true);
public static final Preference<Boolean> autoOrientation = new BooleanPreference("autoOrientation", true);
public static enum Theme { public static enum Theme {

View File

@ -18,7 +18,6 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<android.sdk.path>/home/ssolovyev/projects/org.solovyev/misc/lib/android-sdk-linux_x86</android.sdk.path>
</properties> </properties>
<dependencyManagement> <dependencyManagement>