Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd7ea706 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use StringJoiner in InputMethodDebug"

parents cd5b6cfe 5e46a66c
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.internal.inputmethod;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;

import java.util.StringJoiner;

/**
 * Provides useful methods for debugging.
 */
@@ -96,7 +98,7 @@ public final class InputMethodDebug {
     * @return {@link String} message corresponds for the given {@code softInputMode}.
     */
    public static String softInputModeToString(@SoftInputModeFlags int softInputMode) {
        final StringBuilder sb = new StringBuilder();
        final StringJoiner joiner = new StringJoiner("|");
        final int state = softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE;
        final int adjust = softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
        final boolean isForwardNav =
@@ -104,55 +106,51 @@ public final class InputMethodDebug {

        switch (state) {
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
                sb.append("STATE_UNSPECIFIED");
                joiner.add("STATE_UNSPECIFIED");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
                sb.append("STATE_UNCHANGED");
                joiner.add("STATE_UNCHANGED");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
                sb.append("STATE_HIDDEN");
                joiner.add("STATE_HIDDEN");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
                sb.append("STATE_ALWAYS_HIDDEN");
                joiner.add("STATE_ALWAYS_HIDDEN");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
                sb.append("STATE_VISIBLE");
                joiner.add("STATE_VISIBLE");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
                sb.append("STATE_ALWAYS_VISIBLE");
                joiner.add("STATE_ALWAYS_VISIBLE");
                break;
            default:
                sb.append("STATE_UNKNOWN(");
                sb.append(state);
                sb.append(")");
                joiner.add("STATE_UNKNOWN(" + state + ")");
                break;
        }

        switch (adjust) {
            case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED:
                sb.append("|ADJUST_UNSPECIFIED");
                joiner.add("ADJUST_UNSPECIFIED");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE:
                sb.append("|ADJUST_RESIZE");
                joiner.add("ADJUST_RESIZE");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN:
                sb.append("|ADJUST_PAN");
                joiner.add("ADJUST_PAN");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING:
                sb.append("|ADJUST_NOTHING");
                joiner.add("ADJUST_NOTHING");
                break;
            default:
                sb.append("|ADJUST_UNKNOWN(");
                sb.append(adjust);
                sb.append(")");
                joiner.add("ADJUST_UNKNOWN(" + adjust + ")");
                break;
        }

        if (isForwardNav) {
            // This is a special bit that is set by the system only during the window navigation.
            sb.append("|IS_FORWARD_NAVIGATION");
            joiner.add("IS_FORWARD_NAVIGATION");
        }

        return sb.toString();
        return joiner.setEmptyValue("(none)").toString();
    }
}
+56 −0
Original line number Diff line number Diff line
/*
 * 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.internal.inputmethod;

import static org.junit.Assert.assertEquals;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.WindowManager.LayoutParams;

import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class InputMethodDebugTest {
    @Test
    public void testStartInputReasonToString() {
        // TODO: Use reflection to make sure that all the constants defined in StartInputReason are
        // covered.
        assertEquals("UNSPECIFIED",
                InputMethodDebug.startInputReasonToString(StartInputReason.UNSPECIFIED));
    }

    @Test
    public void testUnbindReasonToString() {
        // TODO: Use reflection to make sure that all the constants defined in UnbindReason are
        // covered.
        assertEquals("UNSPECIFIED",
                InputMethodDebug.startInputReasonToString(UnbindReason.UNSPECIFIED));
    }

    @Test
    public void testSoftInputModeToString() {
        // TODO: add more tests
        assertEquals("STATE_UNCHANGED|ADJUST_RESIZE|IS_FORWARD_NAVIGATION",
                InputMethodDebug.softInputModeToString(
                        LayoutParams.SOFT_INPUT_STATE_UNCHANGED
                                | LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                                | LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION));
    }
}