Loading src/com/android/settings/inputmethod/SpellCheckerPreference.java +25 −8 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.textservice.SpellCheckerInfo; import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.AlertDialog.Builder; import androidx.preference.PreferenceViewHolder; Loading @@ -41,11 +42,15 @@ import com.android.settings.R; class SpellCheckerPreference extends CustomListPreference { private final SpellCheckerInfo[] mScis; private Intent mIntent; @VisibleForTesting Intent mIntent; public SpellCheckerPreference(final Context context, final SpellCheckerInfo[] scis) { super(context, null); mScis = scis; setLayoutResource( com.android.settingslib.widget.preference.twotarget.R.layout.preference_two_target); setWidgetLayoutResource(R.layout.preference_widget_gear); if (scis == null) { return; Loading Loading @@ -108,7 +113,18 @@ class SpellCheckerPreference extends CustomListPreference { @Override public void onBindViewHolder(PreferenceViewHolder view) { super.onBindViewHolder(view); final View divider = view.findViewById( com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider); final View widgetFrame = view.findViewById(android.R.id.widget_frame); if (divider != null) { divider.setVisibility(mIntent != null ? View.VISIBLE : View.GONE); } if (widgetFrame != null) { widgetFrame.setVisibility(mIntent != null ? View.VISIBLE : View.GONE); } View settingsButton = view.findViewById(R.id.settings_button); if (settingsButton != null) { settingsButton.setVisibility(mIntent != null ? View.VISIBLE : View.INVISIBLE); settingsButton.setOnClickListener(new OnClickListener() { @Override Loading @@ -117,6 +133,7 @@ class SpellCheckerPreference extends CustomListPreference { } }); } } private void onSettingsButtonClicked() { final Context context = getContext(); Loading tests/robotests/src/com/android/settings/inputmethod/SpellCheckerPreferenceTest.java 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.settings.inputmethod; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.spy; import android.content.Context; import android.content.Intent; import android.view.View; import android.view.textservice.SpellCheckerInfo; import androidx.preference.PreferenceViewHolder; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class SpellCheckerPreferenceTest { private Context mContext; private PreferenceViewHolder mViewHolder; private View mDivider; private SpellCheckerPreference mPreference; private final SpellCheckerInfo[] mScis = new SpellCheckerInfo[]{}; @Before public void setUp() { mContext = RuntimeEnvironment.application; mPreference = new SpellCheckerPreference(mContext, mScis); } @Test public void onBindViewHolder_withIntent_DividerIsVisible() { final View view = spy(View.inflate(mContext, mPreference.getLayoutResource(), null)); mViewHolder = PreferenceViewHolder.createInstanceForTests(view); mDivider = view.findViewById( com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider); mPreference.mIntent = new Intent(Intent.ACTION_MAIN); mPreference.onBindViewHolder(mViewHolder); assertThat(mDivider.getVisibility()).isEqualTo(View.VISIBLE); } @Test public void onBindViewHolder_withoutIntent_DividerIsNotExist() { final View view = spy(View.inflate(mContext, mPreference.getLayoutResource(), null)); mViewHolder = PreferenceViewHolder.createInstanceForTests(view); mDivider = view.findViewById( com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider); mPreference.onBindViewHolder(mViewHolder); assertThat(mDivider.getVisibility()).isEqualTo(View.GONE); } } Loading
src/com/android/settings/inputmethod/SpellCheckerPreference.java +25 −8 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.textservice.SpellCheckerInfo; import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.AlertDialog.Builder; import androidx.preference.PreferenceViewHolder; Loading @@ -41,11 +42,15 @@ import com.android.settings.R; class SpellCheckerPreference extends CustomListPreference { private final SpellCheckerInfo[] mScis; private Intent mIntent; @VisibleForTesting Intent mIntent; public SpellCheckerPreference(final Context context, final SpellCheckerInfo[] scis) { super(context, null); mScis = scis; setLayoutResource( com.android.settingslib.widget.preference.twotarget.R.layout.preference_two_target); setWidgetLayoutResource(R.layout.preference_widget_gear); if (scis == null) { return; Loading Loading @@ -108,7 +113,18 @@ class SpellCheckerPreference extends CustomListPreference { @Override public void onBindViewHolder(PreferenceViewHolder view) { super.onBindViewHolder(view); final View divider = view.findViewById( com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider); final View widgetFrame = view.findViewById(android.R.id.widget_frame); if (divider != null) { divider.setVisibility(mIntent != null ? View.VISIBLE : View.GONE); } if (widgetFrame != null) { widgetFrame.setVisibility(mIntent != null ? View.VISIBLE : View.GONE); } View settingsButton = view.findViewById(R.id.settings_button); if (settingsButton != null) { settingsButton.setVisibility(mIntent != null ? View.VISIBLE : View.INVISIBLE); settingsButton.setOnClickListener(new OnClickListener() { @Override Loading @@ -117,6 +133,7 @@ class SpellCheckerPreference extends CustomListPreference { } }); } } private void onSettingsButtonClicked() { final Context context = getContext(); Loading
tests/robotests/src/com/android/settings/inputmethod/SpellCheckerPreferenceTest.java 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.settings.inputmethod; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.spy; import android.content.Context; import android.content.Intent; import android.view.View; import android.view.textservice.SpellCheckerInfo; import androidx.preference.PreferenceViewHolder; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class SpellCheckerPreferenceTest { private Context mContext; private PreferenceViewHolder mViewHolder; private View mDivider; private SpellCheckerPreference mPreference; private final SpellCheckerInfo[] mScis = new SpellCheckerInfo[]{}; @Before public void setUp() { mContext = RuntimeEnvironment.application; mPreference = new SpellCheckerPreference(mContext, mScis); } @Test public void onBindViewHolder_withIntent_DividerIsVisible() { final View view = spy(View.inflate(mContext, mPreference.getLayoutResource(), null)); mViewHolder = PreferenceViewHolder.createInstanceForTests(view); mDivider = view.findViewById( com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider); mPreference.mIntent = new Intent(Intent.ACTION_MAIN); mPreference.onBindViewHolder(mViewHolder); assertThat(mDivider.getVisibility()).isEqualTo(View.VISIBLE); } @Test public void onBindViewHolder_withoutIntent_DividerIsNotExist() { final View view = spy(View.inflate(mContext, mPreference.getLayoutResource(), null)); mViewHolder = PreferenceViewHolder.createInstanceForTests(view); mDivider = view.findViewById( com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider); mPreference.onBindViewHolder(mViewHolder); assertThat(mDivider.getVisibility()).isEqualTo(View.GONE); } }