Merge "Fix title clipped for "Custom settings for schedule"" into tm-dev am: fbafdbdd8f
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17607148 Change-Id: I3c042e5201702cfc140a823e340ded7b96cc55f8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -38,10 +38,8 @@ import com.android.settingslib.widget.LayoutPreference;
|
||||
public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModePreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
private final String KEY = PREF_KEY_APP_HEADER;
|
||||
private final PreferenceFragmentCompat mFragment;
|
||||
private AutomaticZenRule mRule;
|
||||
private String mId;
|
||||
private EntityHeaderController mController;
|
||||
|
||||
public ZenAutomaticRuleHeaderPreferenceController(Context context,
|
||||
@@ -52,7 +50,11 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
return PREF_KEY_APP_HEADER;
|
||||
}
|
||||
|
||||
void setRule(AutomaticZenRule rule) {
|
||||
mRule = rule;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,9 +98,4 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onResume(AutomaticZenRule rule, String id) {
|
||||
mRule = rule;
|
||||
mId = id;
|
||||
}
|
||||
}
|
||||
|
@@ -48,6 +48,11 @@ public class ZenAutomaticRuleSwitchPreferenceController extends
|
||||
return KEY;
|
||||
}
|
||||
|
||||
void setIdAndRule(String id, AutomaticZenRule rule) {
|
||||
mId = id;
|
||||
mRule = rule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mRule != null && mId != null;
|
||||
@@ -74,11 +79,6 @@ public class ZenAutomaticRuleSwitchPreferenceController extends
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume(AutomaticZenRule rule, String id) {
|
||||
mRule = rule;
|
||||
mId = id;
|
||||
}
|
||||
|
||||
public void updateState(Preference preference) {
|
||||
if (mRule != null) {
|
||||
mSwitchBar.updateStatus(mRule.isEnabled());
|
||||
|
@@ -45,7 +45,6 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
|
||||
private final String CUSTOM_BEHAVIOR_KEY = "zen_custom_setting";
|
||||
|
||||
protected Context mContext;
|
||||
protected boolean mDisableListeners;
|
||||
protected AutomaticZenRule mRule;
|
||||
protected String mId;
|
||||
@@ -60,9 +59,8 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
abstract protected void updateControlsInternal();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
mContext = getActivity();
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
final Intent intent = getActivity().getIntent();
|
||||
if (DEBUG) Log.d(TAG, "onCreate getIntent()=" + intent);
|
||||
@@ -83,7 +81,14 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
}
|
||||
|
||||
if (DEBUG) Log.d(TAG, "mId=" + mId);
|
||||
if (refreshRuleOrFinish()) {
|
||||
refreshRuleOrFinish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
if (isFinishingOrDestroyed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -133,15 +138,12 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
protected void updateHeader() {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
|
||||
mSwitch.onResume(mRule, mId);
|
||||
mSwitch.displayPreference(screen);
|
||||
updatePreference(mSwitch);
|
||||
|
||||
mHeader.onResume(mRule, mId);
|
||||
mHeader.displayPreference(screen);
|
||||
updatePreference(mHeader);
|
||||
|
||||
mActionButtons.onResume(mRule, mId);
|
||||
mActionButtons.displayPreference(screen);
|
||||
updatePreference(mActionButtons);
|
||||
}
|
||||
@@ -162,6 +164,9 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
private boolean refreshRuleOrFinish() {
|
||||
mRule = getZenRule();
|
||||
if (DEBUG) Log.d(TAG, "mRule=" + mRule);
|
||||
mHeader.setRule(mRule);
|
||||
mSwitch.setIdAndRule(mId, mRule);
|
||||
mActionButtons.setIdAndRule(mId, mRule);
|
||||
if (!setRule(mRule)) {
|
||||
toastAndFinish();
|
||||
return true;
|
||||
|
@@ -39,11 +39,9 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
|
||||
implements PreferenceControllerMixin {
|
||||
public static final String KEY = "zen_action_buttons";
|
||||
|
||||
private AutomaticZenRule mRule;
|
||||
private final PreferenceFragmentCompat mFragment;
|
||||
private String mId;
|
||||
private PreferenceFragmentCompat mFragment;
|
||||
private ActionButtonsPreference mButtonsPref;
|
||||
|
||||
private AutomaticZenRule mRule;
|
||||
|
||||
public ZenRuleButtonsPreferenceController(Context context, PreferenceFragmentCompat fragment,
|
||||
Lifecycle lc) {
|
||||
@@ -51,6 +49,10 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
void setIdAndRule(String id, AutomaticZenRule rule) {
|
||||
mId = id;
|
||||
mRule = rule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
@@ -60,7 +62,7 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
if (isAvailable()) {
|
||||
mButtonsPref = ((ActionButtonsPreference) screen.findPreference(KEY))
|
||||
((ActionButtonsPreference) screen.findPreference(KEY))
|
||||
.setButton1Text(R.string.zen_mode_rule_name_edit)
|
||||
.setButton1Icon(com.android.internal.R.drawable.ic_mode_edit)
|
||||
.setButton1OnClickListener(new EditRuleNameClickListener())
|
||||
@@ -116,9 +118,4 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected void onResume(AutomaticZenRule rule, String id) {
|
||||
mRule = rule;
|
||||
mId = id;
|
||||
}
|
||||
}
|
||||
|
@@ -18,31 +18,27 @@ package com.android.settings.notification.zen;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.shadows.ShadowToast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -57,42 +53,32 @@ public class ZenModeEventRuleSettingsTest {
|
||||
@Mock
|
||||
private Intent mIntent;
|
||||
|
||||
@Mock
|
||||
private NotificationManager mNotificationManager;
|
||||
|
||||
private TestFragment mFragment;
|
||||
private ZenModeEventRuleSettings mFragment;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||
mContext = application;
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
mFragment = spy(new TestFragment());
|
||||
mFragment.onAttach(application);
|
||||
|
||||
doReturn(mActivity).when(mFragment).getActivity();
|
||||
|
||||
Resources res = application.getResources();
|
||||
|
||||
doReturn(res).when(mFragment).getResources();
|
||||
Resources res = mContext.getResources();
|
||||
when(mActivity.getTheme()).thenReturn(res.newTheme());
|
||||
when(mActivity.getIntent()).thenReturn(mIntent);
|
||||
when(mActivity.getResources()).thenReturn(res);
|
||||
when(mActivity.getMainLooper()).thenReturn(mock(Looper.class));
|
||||
|
||||
mFragment = spy(new ZenModeEventRuleSettings());
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.getResources()).thenReturn(res);
|
||||
mFragment.onAttach(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void onCreate_noRuleId_shouldToastAndFinishAndNoCrash() {
|
||||
public void onAttach_noRuleId_shouldToastAndFinishAndNoCrash() {
|
||||
final String expected = mContext.getString(R.string.zen_mode_rule_not_found_text);
|
||||
|
||||
mFragment.onCreate(null);
|
||||
|
||||
// verify the toast
|
||||
assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(expected);
|
||||
|
||||
@@ -110,12 +96,4 @@ public class ZenModeEventRuleSettingsTest {
|
||||
mFragment.addCalendar(1234, "calName", 3, calendarsList);
|
||||
assertThat(calendarsList.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
private static class TestFragment extends ZenModeEventRuleSettings {
|
||||
|
||||
@Override
|
||||
protected Object getSystemService(final String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user