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; 22 import android.hardware.input.InputManager; 23 24 import com.android.settings.R; 25 import com.android.settings.dashboard.DashboardFragment; 26 27 public class NewKeyboardLayoutPickerContent extends DashboardFragment { 28 29 private static final String TAG = "KeyboardLayoutPicker"; 30 private NewKeyboardLayoutPickerController mNewKeyboardLayoutPickerController; 31 private ControllerUpdateCallback mControllerUpdateCallback; 32 33 public interface ControllerUpdateCallback { 34 /** 35 * Called when mNewKeyBoardLayoutPickerController been initialized. 36 */ onControllerUpdated(NewKeyboardLayoutPickerController newKeyboardLayoutPickerController)37 void onControllerUpdated(NewKeyboardLayoutPickerController 38 newKeyboardLayoutPickerController); 39 } 40 setControllerUpdateCallback(ControllerUpdateCallback controllerUpdateCallback)41 public void setControllerUpdateCallback(ControllerUpdateCallback controllerUpdateCallback) { 42 this.mControllerUpdateCallback = controllerUpdateCallback; 43 } 44 45 @Override onAttach(Context context)46 public void onAttach(Context context) { 47 super.onAttach(context); 48 InputManager im = getContext().getSystemService(InputManager.class); 49 InputDeviceIdentifier identifier = 50 getArguments().getParcelable( 51 NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER); 52 if (identifier == null 53 || NewKeyboardSettingsUtils.getInputDevice(im, identifier) == null) { 54 getActivity().finish(); 55 return; 56 } 57 mNewKeyboardLayoutPickerController = use(NewKeyboardLayoutPickerController.class); 58 mNewKeyboardLayoutPickerController.initialize(this); 59 if (mControllerUpdateCallback != null) { 60 mControllerUpdateCallback.onControllerUpdated(mNewKeyboardLayoutPickerController); 61 } 62 } 63 64 @Override getMetricsCategory()65 public int getMetricsCategory() { 66 return SettingsEnums.SETTINGS_KEYBOARDS_LAYOUT_PICKER; 67 } 68 69 @Override getLogTag()70 protected String getLogTag() { 71 return TAG; 72 } 73 getPreferenceScreenResId()74 protected int getPreferenceScreenResId() { 75 return R.xml.new_keyboard_layout_picker_fragment; 76 } 77 getController()78 public NewKeyboardLayoutPickerController getController() { 79 return mNewKeyboardLayoutPickerController; 80 } 81 } 82