| danielwbhuang | 1639782 | 2022-10-04 20:14:59 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings.inputmethod; |
| 18 | |
| 19 | import android.app.settings.SettingsEnums; |
| 20 | import android.content.Context; |
| 21 | import android.hardware.input.InputDeviceIdentifier; |
| danielwbhuang | 1f32614 | 2023-02-24 18:16:30 +0800 | [diff] [blame] | 22 | import android.hardware.input.InputManager; |
| danielwbhuang | 1639782 | 2022-10-04 20:14:59 +0800 | [diff] [blame] | 23 | import android.os.Bundle; |
| danielwbhuang | f43c358 | 2022-12-29 20:28:44 +0800 | [diff] [blame] | 24 | import android.view.inputmethod.InputMethodInfo; |
| 25 | import android.view.inputmethod.InputMethodSubtype; |
| danielwbhuang | 1639782 | 2022-10-04 20:14:59 +0800 | [diff] [blame] | 26 | |
| 27 | import com.android.settings.R; |
| 28 | import com.android.settings.dashboard.DashboardFragment; |
| 29 | |
| 30 | public class NewKeyboardLayoutPickerContent extends DashboardFragment { |
| 31 | |
| 32 | private static final String TAG = "KeyboardLayoutPicker"; |
| 33 | |
| danielwbhuang | 1639782 | 2022-10-04 20:14:59 +0800 | [diff] [blame] | 34 | @Override |
| 35 | public void onAttach(Context context) { |
| 36 | super.onAttach(context); |
| danielwbhuang | 1f32614 | 2023-02-24 18:16:30 +0800 | [diff] [blame] | 37 | InputManager inputManager = getContext().getSystemService(InputManager.class); |
| danielwbhuang | 1639782 | 2022-10-04 20:14:59 +0800 | [diff] [blame] | 38 | Bundle arguments = getArguments(); |
| danielwbhuang | a6b78f6 | 2023-03-07 21:43:33 +0800 | [diff] [blame] | 39 | final CharSequence title = arguments.getCharSequence(NewKeyboardSettingsUtils.EXTRA_TITLE); |
| danielwbhuang | f43c358 | 2022-12-29 20:28:44 +0800 | [diff] [blame] | 40 | final String layout = arguments.getString(NewKeyboardSettingsUtils.EXTRA_KEYBOARD_LAYOUT); |
| 41 | final int userId = arguments.getInt(NewKeyboardSettingsUtils.EXTRA_USER_ID); |
| danielwbhuang | 1f32614 | 2023-02-24 18:16:30 +0800 | [diff] [blame] | 42 | final InputDeviceIdentifier identifier = |
| danielwbhuang | f43c358 | 2022-12-29 20:28:44 +0800 | [diff] [blame] | 43 | 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); |
| danielwbhuang | 1f32614 | 2023-02-24 18:16:30 +0800 | [diff] [blame] | 48 | if (identifier == null |
| 49 | || NewKeyboardSettingsUtils.getInputDevice(inputManager, identifier) == null) { |
| danielwbhuang | cc74915 | 2023-03-24 19:11:53 +0800 | [diff] [blame^] | 50 | getActivity().finish(); |
| danielwbhuang | 1f32614 | 2023-02-24 18:16:30 +0800 | [diff] [blame] | 51 | return; |
| danielwbhuang | 1639782 | 2022-10-04 20:14:59 +0800 | [diff] [blame] | 52 | } |
| 53 | getActivity().setTitle(title); |
| danielwbhuang | f43c358 | 2022-12-29 20:28:44 +0800 | [diff] [blame] | 54 | use(NewKeyboardLayoutPickerController.class).initialize(this /*parent*/, userId, |
| danielwbhuang | 1f32614 | 2023-02-24 18:16:30 +0800 | [diff] [blame] | 55 | identifier, inputMethodInfo, inputMethodSubtype, layout); |
| danielwbhuang | 1639782 | 2022-10-04 20:14:59 +0800 | [diff] [blame] | 56 | } |
| 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 | } |