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

Commit 738b400e authored by Beverly's avatar Beverly
Browse files

Zen automatic rule page ui changes

- Can change rule name from header
- Text for turning on/off rule is now "Use rule" instead of on/off

Test: make ROBOTEST_FILTER=EntityHeaderControllerTest RunSettingsRoboTests -j40
Test: manual (Settings > Sound > Do Not Disturb > Turn On Automatically)
Bug: 63077372
Change-Id: Id55b02de0509f168c2470a4f875e84140eb840fa
parent 18a9d7ba
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -6870,6 +6870,9 @@
    <!--  Do not disturb: Summary for the zen mode automation option Suggestion. [CHAR LIMIT=NONE] -->
    <string name="zen_mode_automation_suggestion_summary">Limit sounds &amp; vibrations at certain times</string>
    <!--  Do not disturb: Switch toggle to toggle whether to use an automatic dnd rule or not [CHAR LIMIT=40] -->
    <string name="zen_mode_use_automatic_rule">Use rule</string>
    <!--  Do not disturb: Zen mode option: Important interruptions [CHAR LIMIT=60] -->
    <string name="zen_mode_option_important_interruptions">Priority only</string>
+0 −6
Original line number Diff line number Diff line
@@ -28,12 +28,6 @@
        android:key="zen_automatic_rule_switch"
        android:layout="@layout/styled_switch_bar" />

    <!-- Rule name -->
    <Preference
        android:key="rule_name"
        android:title="@string/zen_mode_rule_name"
        android:persistent="false" />

    <!-- During events for -->
    <DropDownPreference
        android:key="calendar"
+0 −6
Original line number Diff line number Diff line
@@ -28,12 +28,6 @@
        android:key="zen_automatic_rule_switch"
        android:layout="@layout/styled_switch_bar" />

    <!-- Rule name -->
    <Preference
        android:key="rule_name"
        android:title="@string/zen_mode_rule_name"
        android:persistent="false" />

    <!-- Days -->
    <Preference
        android:key="days"
+26 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.notification;
import static com.android.settings.widget.EntityHeaderController.PREF_KEY_APP_HEADER;

import android.app.AutomaticZenRule;
import android.app.Fragment;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -28,6 +29,7 @@ import android.support.v7.preference.Preference;
import android.util.Slog;
import android.view.View;

import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.PreferenceControllerMixin;
@@ -40,6 +42,7 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
    private final String KEY = PREF_KEY_APP_HEADER;
    private final PreferenceFragment mFragment;
    private AutomaticZenRule mRule;
    private String mId;
    private EntityHeaderController mController;

    public ZenAutomaticRuleHeaderPreferenceController(Context context, PreferenceFragment fragment,
@@ -70,6 +73,14 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
                mController = EntityHeaderController
                        .newInstance(mFragment.getActivity(), mFragment,
                                pref.findViewById(R.id.entity_header));

                mController.setEditZenRuleNameListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ZenRuleNameDialog.show(mFragment, mRule.getName(), null,
                                new RuleNameChangeListener());
                    }
                });
            }

            pref = mController.setIcon(getIcon())
@@ -77,7 +88,7 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
                    .setPackageName(mRule.getOwner().getPackageName())
                    .setUid(mContext.getUserId())
                    .setHasAppInfoLink(false)
                    .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
                    .setButtonActions(EntityHeaderController.ActionType.ACTION_DND_RULE_PREFERENCE,
                            EntityHeaderController.ActionType.ACTION_NONE)
                    .done(mFragment.getActivity(), mContext);

@@ -98,7 +109,20 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
        return null;
    }

    protected void onResume(AutomaticZenRule rule) {
    protected void onResume(AutomaticZenRule rule, String id) {
        mRule = rule;
        mId = id;
    }

    public class RuleNameChangeListener implements ZenRuleNameDialog.PositiveClickListener {
        public RuleNameChangeListener() {}

        @Override
        public void onOk(String ruleName, Fragment parent) {
            mMetricsFeatureProvider.action(mContext,
                    MetricsProto.MetricsEvent.ACTION_ZEN_MODE_RULE_NAME_CHANGE_OK);
            mRule.setName(ruleName);
            mBackend.setZenRule(mId, mRule);
        }
    }
}
+22 −12
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.AutomaticZenRule;
import android.app.Fragment;
import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.widget.Switch;
import android.widget.Toast;

@@ -37,6 +38,7 @@ public class ZenAutomaticRuleSwitchPreferenceController extends
    private String mId;
    private Toast mEnabledToast;
    private int mToastTextResource;
    private SwitchBar mSwitchBar;

    public ZenAutomaticRuleSwitchPreferenceController(Context context, Fragment parent,
            int toastTextResource, Lifecycle lifecycle) {
@@ -54,26 +56,34 @@ public class ZenAutomaticRuleSwitchPreferenceController extends
        return mRule != null && mId != null;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        LayoutPreference pref = (LayoutPreference) screen.findPreference(KEY);
        mSwitchBar = pref.findViewById(R.id.switch_bar);

        if (mSwitchBar != null) {
            mSwitchBar.setSwitchBarText(R.string.zen_mode_use_automatic_rule,
                    R.string.zen_mode_use_automatic_rule);
            try {
                mSwitchBar.addOnSwitchChangeListener(this);
            } catch (IllegalStateException e) {
                // an exception is thrown if you try to add the listener twice
            }
            mSwitchBar.show();
        }
    }


    public void onResume(AutomaticZenRule rule, String id) {
        mRule = rule;
        mId = id;
    }

    public void updateState(Preference preference) {
        LayoutPreference pref = (LayoutPreference) preference;
        SwitchBar bar = pref.findViewById(R.id.switch_bar);
        if (mRule != null) {
            bar.setChecked(mRule.isEnabled());
        }
        if (bar != null) {
            bar.show();
            try {
                bar.addOnSwitchChangeListener(this);
            } catch (IllegalStateException e) {
                // an exception is thrown if you try to add the listener twice
            }
            mSwitchBar.setChecked(mRule.isEnabled());
        }
        bar.show();
    }

    @Override
Loading