Use InputMethodSettingsFragment for IME settings

Change-Id: Id6d9cd0ddf99c0687b6d3ea4b2f868f6cf2a0eaf
main
Tadashi G. Takaoka 2012-04-13 19:53:44 +09:00
parent f6972561fc
commit c206d04623
7 changed files with 101 additions and 37 deletions

View File

@ -30,7 +30,7 @@
<meta-data android:name="android.view.textservice.scs" android:resource="@xml/spellchecker" /> <meta-data android:name="android.view.textservice.scs" android:resource="@xml/spellchecker" />
</service> </service>
<activity android:name="Settings" android:label="@string/english_ime_settings"> <activity android:name="SettingsActivity" android:label="@string/english_ime_settings">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
</intent-filter> </intent-filter>
@ -43,7 +43,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="DebugSettings" android:label="@string/english_ime_debug_settings"> <activity android:name="DebugSettingsActivity" android:label="@string/english_ime_debug_settings">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
</intent-filter> </intent-filter>

View File

@ -68,7 +68,7 @@
<!-- If IME doesn't have an applicable subtype, the first subtype will be used as a default <!-- If IME doesn't have an applicable subtype, the first subtype will be used as a default
subtype.--> subtype.-->
<input-method xmlns:android="http://schemas.android.com/apk/res/android" <input-method xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.android.inputmethod.latin.Settings" android:settingsActivity="com.android.inputmethod.latin.SettingsActivity"
android:isDefault="@bool/im_is_default"> android:isDefault="@bool/im_is_default">
<subtype android:icon="@drawable/ic_subtype_keyboard" <subtype android:icon="@drawable/ic_subtype_keyboard"
android:label="@string/subtype_en_US" android:label="@string/subtype_en_US"

View File

@ -16,18 +16,19 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle; import android.os.Bundle;
import android.os.Process; import android.os.Process;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.PreferenceActivity; import android.preference.PreferenceFragment;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
public class DebugSettings extends PreferenceActivity public class DebugSettings extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener { implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = DebugSettings.class.getSimpleName(); private static final String TAG = DebugSettings.class.getSimpleName();
@ -38,7 +39,7 @@ public class DebugSettings extends PreferenceActivity
private CheckBoxPreference mDebugMode; private CheckBoxPreference mDebugMode;
@Override @Override
protected void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_for_debug); addPreferencesFromResource(R.xml.prefs_for_debug);
SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
@ -50,7 +51,7 @@ public class DebugSettings extends PreferenceActivity
} }
@Override @Override
protected void onStop() { public void onStop() {
super.onStop(); super.onStop();
if (mServiceNeedsRestart) Process.killProcess(Process.myPid()); if (mServiceNeedsRestart) Process.killProcess(Process.myPid());
} }
@ -76,7 +77,9 @@ public class DebugSettings extends PreferenceActivity
boolean isDebugMode = mDebugMode.isChecked(); boolean isDebugMode = mDebugMode.isChecked();
String version = ""; String version = "";
try { try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0); final Context context = getActivity();
final String packageName = context.getPackageName();
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
version = "Version " + info.versionName; version = "Version " + info.versionName;
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
Log.e(TAG, "Could not find version info."); Log.e(TAG, "Could not find version info.");

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.android.inputmethod.latin;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class DebugSettingsActivity extends PreferenceActivity {
@Override
public Intent getIntent() {
final Intent modIntent = new Intent(super.getIntent());
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, DebugSettings.class.getName());
return modIntent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.english_ime_debug_settings);
}
}

View File

@ -2226,15 +2226,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
} }
protected void launchSettings() { private void launchSettings() {
launchSettingsClass(Settings.class); launchSettingsClass(SettingsActivity.class);
} }
public void launchDebugSettings() { public void launchDebugSettings() {
launchSettingsClass(DebugSettings.class); launchSettingsClass(DebugSettingsActivity.class);
} }
protected void launchSettingsClass(Class<? extends PreferenceActivity> settingsClass) { private void launchSettingsClass(Class<? extends PreferenceActivity> settingsClass) {
handleClose(); handleClose();
Intent intent = new Intent(); Intent intent = new Intent();
intent.setClass(LatinIME.this, settingsClass); intent.setClass(LatinIME.this, settingsClass);

View File

@ -16,9 +16,7 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Fragment;
import android.app.backup.BackupManager; import android.app.backup.BackupManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -33,15 +31,16 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceGroup; import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; import android.widget.TextView;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethodcommon.InputMethodSettingsActivity; import com.android.inputmethodcommon.InputMethodSettingsFragment;
public class Settings extends InputMethodSettingsActivity public class Settings extends InputMethodSettingsFragment
implements SharedPreferences.OnSharedPreferenceChangeListener { implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final boolean ENABLE_EXPERIMENTAL_SETTINGS = false; public static final boolean ENABLE_EXPERIMENTAL_SETTINGS = false;
@ -103,26 +102,16 @@ public class Settings extends InputMethodSettingsActivity
} }
} }
public Activity getActivityInternal() {
Object thisObject = (Object) this;
if (thisObject instanceof Activity) {
return (Activity) thisObject;
} else if (thisObject instanceof Fragment) {
return ((Fragment) thisObject).getActivity();
} else {
return null;
}
}
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
setInputMethodSettingsCategoryTitle(R.string.language_selection_title); setInputMethodSettingsCategoryTitle(R.string.language_selection_title);
setSubtypeEnablerTitle(R.string.select_language); setSubtypeEnablerTitle(R.string.select_language);
final Resources res = getResources();
final Context context = getActivityInternal();
addPreferencesFromResource(R.xml.prefs); addPreferencesFromResource(R.xml.prefs);
final Resources res = getResources();
final Context context = getActivity();
mVoicePreference = (ListPreference) findPreference(PREF_VOICE_MODE); mVoicePreference = (ListPreference) findPreference(PREF_VOICE_MODE);
mShowCorrectionSuggestionsPreference = mShowCorrectionSuggestionsPreference =
(ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING); (ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING);
@ -276,7 +265,7 @@ public class Settings extends InputMethodSettingsActivity
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
(new BackupManager(getActivityInternal())).dataChanged(); (new BackupManager(getActivity())).dataChanged();
if (key.equals(PREF_POPUP_ON)) { if (key.equals(PREF_POPUP_ON)) {
final ListPreference popupDismissDelay = final ListPreference popupDismissDelay =
(ListPreference)findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY); (ListPreference)findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
@ -318,7 +307,7 @@ public class Settings extends InputMethodSettingsActivity
private void refreshEnablingsOfKeypressSoundAndVibrationSettings( private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
SharedPreferences sp, Resources res) { SharedPreferences sp, Resources res) {
if (mKeypressVibrationDurationSettingsPref != null) { if (mKeypressVibrationDurationSettingsPref != null) {
final boolean hasVibrator = VibratorUtils.getInstance(this).hasVibrator(); final boolean hasVibrator = VibratorUtils.getInstance(getActivity()).hasVibrator();
final boolean vibrateOn = hasVibrator && sp.getBoolean(Settings.PREF_VIBRATE_ON, final boolean vibrateOn = hasVibrator && sp.getBoolean(Settings.PREF_VIBRATE_ON,
res.getBoolean(R.bool.config_default_vibration_enabled)); res.getBoolean(R.bool.config_default_vibration_enabled));
mKeypressVibrationDurationSettingsPref.setEnabled(vibrateOn); mKeypressVibrationDurationSettingsPref.setEnabled(vibrateOn);
@ -342,7 +331,7 @@ public class Settings extends InputMethodSettingsActivity
private void showKeypressVibrationDurationSettingsDialog() { private void showKeypressVibrationDurationSettingsDialog() {
final SharedPreferences sp = getPreferenceManager().getSharedPreferences(); final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
final Activity context = getActivityInternal(); final Context context = getActivity();
final Resources res = context.getResources(); final Resources res = context.getResources();
final AlertDialog.Builder builder = new AlertDialog.Builder(context); final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.prefs_keypress_vibration_duration_settings); builder.setTitle(R.string.prefs_keypress_vibration_duration_settings);
@ -361,7 +350,7 @@ public class Settings extends InputMethodSettingsActivity
dialog.dismiss(); dialog.dismiss();
} }
}); });
final View v = context.getLayoutInflater().inflate( final View v = LayoutInflater.from(context).inflate(
R.layout.vibration_settings_dialog, null); R.layout.vibration_settings_dialog, null);
final int currentMs = SettingsValues.getCurrentVibrationDuration( final int currentMs = SettingsValues.getCurrentVibrationDuration(
getPreferenceManager().getSharedPreferences(), getResources()); getPreferenceManager().getSharedPreferences(), getResources());
@ -398,9 +387,9 @@ public class Settings extends InputMethodSettingsActivity
} }
private void showKeypressSoundVolumeSettingDialog() { private void showKeypressSoundVolumeSettingDialog() {
final AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); final Context context = getActivity();
final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
final SharedPreferences sp = getPreferenceManager().getSharedPreferences(); final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
final Activity context = getActivityInternal();
final Resources res = context.getResources(); final Resources res = context.getResources();
final AlertDialog.Builder builder = new AlertDialog.Builder(context); final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.prefs_keypress_sound_volume_settings); builder.setTitle(R.string.prefs_keypress_sound_volume_settings);
@ -420,7 +409,7 @@ public class Settings extends InputMethodSettingsActivity
dialog.dismiss(); dialog.dismiss();
} }
}); });
final View v = context.getLayoutInflater().inflate( final View v = LayoutInflater.from(context).inflate(
R.layout.sound_effect_volume_dialog, null); R.layout.sound_effect_volume_dialog, null);
final int currentVolumeInt = final int currentVolumeInt =
(int)(SettingsValues.getCurrentKeypressSoundVolume(sp, res) * 100); (int)(SettingsValues.getCurrentKeypressSoundVolume(sp, res) * 100);

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.android.inputmethod.latin;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class SettingsActivity extends PreferenceActivity {
@Override
public Intent getIntent() {
final Intent modIntent = new Intent(super.getIntent());
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, Settings.class.getName());
return modIntent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.english_ime_settings);
}
}