InputMethodAndSubtypeEnabler use DashboardFragment

- Move preference log to InputMethodAndSubtypePreferenceController
- Add input_methods_subtype.xml

Test: manual
Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.inputmethod
Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.core
Test: atest UniquePreferenceTest

Change-Id: I45b6e8303d94ef07d17016eeed1d728432a70d98
This commit is contained in:
rafftsai
2018-04-12 11:56:32 +08:00
committed by Fan Zhang
parent 8efbe6e255
commit 9bd1ac38c5
8 changed files with 316 additions and 25 deletions

View File

@@ -16,17 +16,18 @@
package com.android.settings.inputmethod;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.preference.PreferenceScreen;
import android.text.TextUtils;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.inputmethod.InputMethodAndSubtypeEnablerManager;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
private InputMethodAndSubtypeEnablerManager mManager;
public class InputMethodAndSubtypeEnabler extends DashboardFragment {
private static final String TAG = "InputMethodAndSubtypeEnabler";
@Override
public int getMetricsCategory() {
@@ -34,8 +35,18 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
}
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
protected int getPreferenceScreenResId() {
return R.xml.input_methods_subtype;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
// Input method id should be available from an Intent when this preference is launched as a
// single Activity (see InputMethodAndSubtypeEnablerActivity). It should be available
@@ -44,11 +55,8 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
final String targetImi = getStringExtraFromIntentOrArguments(
android.provider.Settings.EXTRA_INPUT_METHOD_ID);
final PreferenceScreen root =
getPreferenceManager().createPreferenceScreen(getPrefContext());
mManager = new InputMethodAndSubtypeEnablerManager(this);
mManager.init(this, targetImi, root);
setPreferenceScreen(root);
use(InputMethodAndSubtypePreferenceController.class).initialize(this /* fragment */,
targetImi);
}
private String getStringExtraFromIntentOrArguments(final String name) {
@@ -69,16 +77,4 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
getActivity().setTitle(title);
}
}
@Override
public void onResume() {
super.onResume();
mManager.refresh(getContext(), this);
}
@Override
public void onPause() {
super.onPause();
mManager.save(getContext(), this);
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2018 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.Context;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.inputmethod.InputMethodAndSubtypeEnablerManager;
import androidx.preference.PreferenceFragment;
import androidx.preference.PreferenceScreen;
public class InputMethodAndSubtypePreferenceController extends BasePreferenceController implements
LifecycleObserver, OnStart, OnStop {
private PreferenceFragment mFragment;
private InputMethodAndSubtypeEnablerManager mManager;
private String mTargetImi;
public InputMethodAndSubtypePreferenceController(Context context, String key) {
super(context, key);
}
public void initialize(PreferenceFragment fragment, String imi) {
mFragment = fragment;
mTargetImi = imi;
mManager = new InputMethodAndSubtypeEnablerManager(mFragment);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mManager.init(mFragment, mTargetImi, screen);
}
@Override
public void onStart() {
mManager.refresh(mContext, mFragment);
}
@Override
public void onStop() {
mManager.save(mContext, mFragment);
}
}