1 /* 2 * Copyright (C) 2018 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.example.android.multiclientinputmethod; 18 19 import android.view.WindowManager; 20 21 import com.android.internal.inputmethod.StartInputFlags; 22 23 import java.util.StringJoiner; 24 25 /** 26 * Provides useful methods for debugging. 27 */ 28 final class InputMethodDebug { 29 30 /** 31 * Not intended to be instantiated. 32 */ InputMethodDebug()33 private InputMethodDebug() { 34 } 35 36 /** 37 * Converts soft input flags to {@link String} for debug logging. 38 * 39 * @param softInputMode integer constant for soft input flags. 40 * @return {@link String} message corresponds for the given {@code softInputMode}. 41 */ softInputModeToString(int softInputMode)42 public static String softInputModeToString(int softInputMode) { 43 final StringJoiner joiner = new StringJoiner("|"); 44 final int state = softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE; 45 final int adjust = softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; 46 final boolean isForwardNav = 47 (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0; 48 49 switch (state) { 50 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: 51 joiner.add("STATE_UNSPECIFIED"); 52 break; 53 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED: 54 joiner.add("STATE_UNCHANGED"); 55 break; 56 case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN: 57 joiner.add("STATE_HIDDEN"); 58 break; 59 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: 60 joiner.add("STATE_ALWAYS_HIDDEN"); 61 break; 62 case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE: 63 joiner.add("STATE_VISIBLE"); 64 break; 65 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: 66 joiner.add("STATE_ALWAYS_VISIBLE"); 67 break; 68 default: 69 joiner.add("STATE_UNKNOWN(" + state + ")"); 70 break; 71 } 72 73 switch (adjust) { 74 case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED: 75 joiner.add("ADJUST_UNSPECIFIED"); 76 break; 77 case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE: 78 joiner.add("ADJUST_RESIZE"); 79 break; 80 case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN: 81 joiner.add("ADJUST_PAN"); 82 break; 83 case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING: 84 joiner.add("ADJUST_NOTHING"); 85 break; 86 default: 87 joiner.add("ADJUST_UNKNOWN(" + adjust + ")"); 88 break; 89 } 90 91 if (isForwardNav) { 92 // This is a special bit that is set by the system only during the window navigation. 93 joiner.add("IS_FORWARD_NAVIGATION"); 94 } 95 96 return joiner.setEmptyValue("(none)").toString(); 97 } 98 99 /** 100 * Converts start input flags to {@link String} for debug logging. 101 * 102 * @param startInputFlags integer constant for start input flags. 103 * @return {@link String} message corresponds for the given {@code startInputFlags}. 104 */ startInputFlagsToString(int startInputFlags)105 public static String startInputFlagsToString(int startInputFlags) { 106 final StringJoiner joiner = new StringJoiner("|"); 107 if ((startInputFlags & StartInputFlags.VIEW_HAS_FOCUS) != 0) { 108 joiner.add("VIEW_HAS_FOCUS"); 109 } 110 if ((startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0) { 111 joiner.add("IS_TEXT_EDITOR"); 112 } 113 if ((startInputFlags & StartInputFlags.FIRST_WINDOW_FOCUS_GAIN) != 0) { 114 joiner.add("FIRST_WINDOW_FOCUS_GAIN"); 115 } 116 if ((startInputFlags & StartInputFlags.INITIAL_CONNECTION) != 0) { 117 joiner.add("INITIAL_CONNECTION"); 118 } 119 120 return joiner.setEmptyValue("(none)").toString(); 121 } 122 } 123