OSDN Git Service

Disable left pane of "Input languages" conditionally.
authorDaisuke Miyakawa <dmiyakawa@google.com>
Mon, 31 Jan 2011 03:43:08 +0000 (19:43 -0800)
committerDaisuke Miyakawa <dmiyakawa@google.com>
Tue, 1 Feb 2011 06:12:01 +0000 (22:12 -0800)
The screen is available from LatinIME's setting button, in which
we don't want the left pane, while we want the left pane when
launched as part of Settings app.

Bug: 3383738
Change-Id: I62e901e7cc14053742ae35829d82c20e432a358f

AndroidManifest.xml
src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java
src/com/android/settings/inputmethod/InputMethodAndSubtypeEnablerActivity.java [new file with mode: 0644]
src/com/android/settings/inputmethod/InputMethodConfig.java

index e94dfcb..e559325 100644 (file)
                 android:resource="@id/language_settings" />
         </activity>
 
-        <activity android:name="Settings$InputMethodAndSubtypeEnablerActivity"
+        <activity android:name=".inputmethod.InputMethodAndSubtypeEnablerActivity"
                 android:theme="@android:style/Theme.Holo"
                 android:label="@string/input_methods_and_subtype_enabler_title"
                 android:clearTaskOnLaunch="true">
                 <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="com.android.settings.SHORTCUT" />
             </intent-filter>
-            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                android:value="com.android.settings.inputmethod.InputMethodAndSubtypeEnabler" />
-            <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
-                android:resource="@id/language_settings" />
-            <meta-data android:name="com.android.settings.PARENT_FRAGMENT_TITLE"
-                android:resource="@string/language_keyboard_settings_title" />
-            <meta-data android:name="com.android.settings.PARENT_FRAGMENT_CLASS"
-                android:value="com.android.settings.Settings$InputMethodAndLanguageSettingsActivity" />
         </activity>
 
         <activity android:name="Settings$InputMethodConfigActivity"
index 0e5be20..6e1d4d1 100644 (file)
@@ -55,8 +55,21 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
         mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
         Configuration config = getResources().getConfiguration();
         mHaveHardKeyboard = (config.keyboard == Configuration.KEYBOARD_QWERTY);
+
+        // Input method id should be available from an Intent when this preference is launched as a
+        // single Activity (see InputMethodAndSubtypeEnablerActivity). It should be available
+        // from a preference argument when the preference is launched as a part of the other
+        // Activity (like a right pane of 2-pane Settings app)
         mInputMethodId = getActivity().getIntent().getStringExtra(
                 android.provider.Settings.EXTRA_INPUT_METHOD_ID);
+        if (mInputMethodId == null && (getArguments() != null)) {
+            final String inputMethodId =
+                    getArguments().getString(android.provider.Settings.EXTRA_INPUT_METHOD_ID);
+            if (inputMethodId != null) {
+                mInputMethodId = inputMethodId;
+            }
+        }
+
         onCreateIMM();
         setPreferenceScreen(createPreferenceHierarchy());
     }
diff --git a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnablerActivity.java b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnablerActivity.java
new file mode 100644 (file)
index 0000000..d70d5e4
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2011 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.settings.inputmethod;
+
+import android.content.Intent;
+import android.preference.PreferenceActivity;
+
+public class InputMethodAndSubtypeEnablerActivity extends PreferenceActivity {
+    @Override
+    public Intent getIntent() {
+        final Intent modIntent = new Intent(super.getIntent());
+        if (!modIntent.hasExtra(EXTRA_SHOW_FRAGMENT)) {
+            modIntent.putExtra(EXTRA_SHOW_FRAGMENT, InputMethodAndSubtypeEnabler.class.getName());
+            modIntent.putExtra(EXTRA_NO_HEADERS, true);
+        }
+        return modIntent;
+    }
+}
index 3e77ba1..f2bdafd 100644 (file)
@@ -29,6 +29,7 @@ import android.content.res.Configuration;
 import android.os.Bundle;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceCategory;
 import android.preference.PreferenceScreen;
 import android.provider.Settings;
@@ -219,12 +220,17 @@ public class InputMethodConfig extends SettingsPreferenceFragment {
         PreferenceScreen prefScreen = new PreferenceScreen(getActivity(), null);
         prefScreen.setTitle(R.string.active_input_method_subtypes);
         if (imi.getSubtypeCount() > 1) {
-            intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
-            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
-                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
-                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
-            intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, imiId);
-            prefScreen.setIntent(intent);
+            prefScreen.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+                @Override 
+                public boolean onPreferenceClick(Preference preference){
+                    final Bundle bundle = new Bundle();
+                    bundle.putString(Settings.EXTRA_INPUT_METHOD_ID, imiId);
+                    startFragment(InputMethodConfig.this,
+                            InputMethodAndSubtypeEnabler.class.getName(),
+                            0, bundle);
+                    return true;
+                }
+            });
             keyboardSettingsCategory.addPreference(prefScreen);
             mActiveInputMethodsPrefMap.put(imi, prefScreen);
             mInputMethodPrefsMap.get(imiId).add(prefScreen);