blob: 110147a4a687ffc1f8a6eda31b1be37b79201049 [file] [log] [blame]
danielwbhuang16397822022-10-04 20:14:59 +08001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings.inputmethod;
18
19import android.app.settings.SettingsEnums;
20import android.content.Context;
21import android.hardware.input.InputDeviceIdentifier;
danielwbhuang1f326142023-02-24 18:16:30 +080022import android.hardware.input.InputManager;
danielwbhuang16397822022-10-04 20:14:59 +080023import android.os.Bundle;
danielwbhuangf43c3582022-12-29 20:28:44 +080024import android.view.inputmethod.InputMethodInfo;
25import android.view.inputmethod.InputMethodSubtype;
danielwbhuang16397822022-10-04 20:14:59 +080026
27import com.android.settings.R;
28import com.android.settings.dashboard.DashboardFragment;
29
30public class NewKeyboardLayoutPickerContent extends DashboardFragment {
31
32 private static final String TAG = "KeyboardLayoutPicker";
33
danielwbhuang16397822022-10-04 20:14:59 +080034 @Override
35 public void onAttach(Context context) {
36 super.onAttach(context);
danielwbhuang1f326142023-02-24 18:16:30 +080037 InputManager inputManager = getContext().getSystemService(InputManager.class);
danielwbhuang16397822022-10-04 20:14:59 +080038 Bundle arguments = getArguments();
danielwbhuanga6b78f62023-03-07 21:43:33 +080039 final CharSequence title = arguments.getCharSequence(NewKeyboardSettingsUtils.EXTRA_TITLE);
danielwbhuangf43c3582022-12-29 20:28:44 +080040 final String layout = arguments.getString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT);
41 final int userId = arguments.getInt(NewKeyboardSettingsUtils.EXTRA_USER_ID);
danielwbhuang1f326142023-02-24 18:16:30 +080042 final InputDeviceIdentifier identifier =
danielwbhuangf43c3582022-12-29 20:28:44 +080043 arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER);
44 final InputMethodInfo inputMethodInfo =
45 arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_INFO);
46 final InputMethodSubtype inputMethodSubtype =
47 arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_SUBTYPE);
danielwbhuang1f326142023-02-24 18:16:30 +080048 if (identifier == null
49 || NewKeyboardSettingsUtils.getInputDevice(inputManager, identifier) == null) {
danielwbhuangcc749152023-03-24 19:11:53 +080050 getActivity().finish();
danielwbhuang1f326142023-02-24 18:16:30 +080051 return;
danielwbhuang16397822022-10-04 20:14:59 +080052 }
53 getActivity().setTitle(title);
danielwbhuangf43c3582022-12-29 20:28:44 +080054 use(NewKeyboardLayoutPickerController.class).initialize(this /*parent*/, userId,
danielwbhuang1f326142023-02-24 18:16:30 +080055 identifier, inputMethodInfo, inputMethodSubtype, layout);
danielwbhuang16397822022-10-04 20:14:59 +080056 }
57
58 @Override
59 public int getMetricsCategory() {
60 // TODO: add new SettingsEnums SETTINGS_KEYBOARDS_LAYOUT_PICKER_CONTENT
61 return SettingsEnums.SETTINGS_KEYBOARDS_LAYOUT_PICKER;
62 }
63
64 @Override
65 protected String getLogTag() {
66 return TAG;
67 }
68
69 protected int getPreferenceScreenResId() {
70 return R.xml.new_keyboard_layout_picker_fragment;
71 }
72}