Loading res/layout/modes_activation_button.xml 0 → 100644 +30 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2024 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. --> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/activate_mode" style="@style/ActionPrimaryButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"/> </FrameLayout> No newline at end of file res/xml/modes_rule_settings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,11 @@ android:key="header" android:layout="@layout/settings_entity_header" /> <com.android.settingslib.widget.LayoutPreference android:key="activate" android:selectable="false" android:layout="@layout/modes_activation_button"/> <PreferenceCategory android:title="@string/mode_interruption_filter_title" android:key="modes_filters"> Loading src/com/android/settings/notification/modes/AbstractZenModePreferenceController.java +17 −2 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ abstract class AbstractZenModePreferenceController extends AbstractPreferenceCon @Nullable protected ZenModesBackend mBackend; @Nullable // only until updateZenMode() is called @Nullable // only until setZenMode() is called private ZenMode mZenMode; @NonNull Loading @@ -65,8 +65,23 @@ abstract class AbstractZenModePreferenceController extends AbstractPreferenceCon @Override public boolean isAvailable() { if (mZenMode != null) { return Flags.modesUi() && isAvailable(mZenMode); } else { return Flags.modesUi(); } } public boolean isAvailable(@NonNull ZenMode zenMode) { return true; } // Called by parent Fragment onAttach, for any methods (such as isAvailable()) that need // zen mode info before onStart. Most callers should use updateZenMode instead, which will // do any further necessary propagation. protected final void setZenMode(@NonNull ZenMode zenMode) { mZenMode = zenMode; } // Called by the parent Fragment onStart, which means it will happen before resume. public void updateZenMode(@NonNull Preference preference, @NonNull ZenMode zenMode) { Loading src/com/android/settings/notification/modes/ZenModeButtonPreferenceController.java 0 → 100644 +59 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.notification.modes; import android.annotation.NonNull; import android.content.Context; import android.widget.Button; import androidx.preference.Preference; import com.android.settings.R; import com.android.settingslib.widget.LayoutPreference; public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController { private Button mZenButton; public ZenModeButtonPreferenceController(Context context, String key, ZenModesBackend backend) { super(context, key, backend); } @Override public boolean isAvailable(ZenMode zenMode) { return zenMode.getRule().isManualInvocationAllowed() && zenMode.getRule().isEnabled(); } @Override public void updateState(Preference preference, @NonNull ZenMode zenMode) { if (mZenButton == null) { mZenButton = ((LayoutPreference) preference).findViewById(R.id.activate_mode); } mZenButton.setOnClickListener(v -> { if (zenMode.isActive()) { mBackend.deactivateMode(zenMode); } else { mBackend.activateMode(zenMode, null); } }); if (zenMode.isActive()) { mZenButton.setText(R.string.zen_mode_button_turn_off); } else { mZenButton.setText(R.string.zen_mode_button_turn_on); } } } src/com/android/settings/notification/modes/ZenModeFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ public class ZenModeFragment extends ZenModeFragmentBase { protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { List<AbstractPreferenceController> prefControllers = new ArrayList<>(); prefControllers.add(new ZenModeHeaderController(context, "header", this, mBackend)); prefControllers.add(new ZenModeButtonPreferenceController(context, "activate", mBackend)); prefControllers.add(new ZenModePeopleLinkPreferenceController( context, "zen_mode_people", mBackend)); prefControllers.add(new ZenModeOtherLinkPreferenceController( Loading Loading
res/layout/modes_activation_button.xml 0 → 100644 +30 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2024 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. --> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/activate_mode" style="@style/ActionPrimaryButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"/> </FrameLayout> No newline at end of file
res/xml/modes_rule_settings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,11 @@ android:key="header" android:layout="@layout/settings_entity_header" /> <com.android.settingslib.widget.LayoutPreference android:key="activate" android:selectable="false" android:layout="@layout/modes_activation_button"/> <PreferenceCategory android:title="@string/mode_interruption_filter_title" android:key="modes_filters"> Loading
src/com/android/settings/notification/modes/AbstractZenModePreferenceController.java +17 −2 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ abstract class AbstractZenModePreferenceController extends AbstractPreferenceCon @Nullable protected ZenModesBackend mBackend; @Nullable // only until updateZenMode() is called @Nullable // only until setZenMode() is called private ZenMode mZenMode; @NonNull Loading @@ -65,8 +65,23 @@ abstract class AbstractZenModePreferenceController extends AbstractPreferenceCon @Override public boolean isAvailable() { if (mZenMode != null) { return Flags.modesUi() && isAvailable(mZenMode); } else { return Flags.modesUi(); } } public boolean isAvailable(@NonNull ZenMode zenMode) { return true; } // Called by parent Fragment onAttach, for any methods (such as isAvailable()) that need // zen mode info before onStart. Most callers should use updateZenMode instead, which will // do any further necessary propagation. protected final void setZenMode(@NonNull ZenMode zenMode) { mZenMode = zenMode; } // Called by the parent Fragment onStart, which means it will happen before resume. public void updateZenMode(@NonNull Preference preference, @NonNull ZenMode zenMode) { Loading
src/com/android/settings/notification/modes/ZenModeButtonPreferenceController.java 0 → 100644 +59 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.notification.modes; import android.annotation.NonNull; import android.content.Context; import android.widget.Button; import androidx.preference.Preference; import com.android.settings.R; import com.android.settingslib.widget.LayoutPreference; public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController { private Button mZenButton; public ZenModeButtonPreferenceController(Context context, String key, ZenModesBackend backend) { super(context, key, backend); } @Override public boolean isAvailable(ZenMode zenMode) { return zenMode.getRule().isManualInvocationAllowed() && zenMode.getRule().isEnabled(); } @Override public void updateState(Preference preference, @NonNull ZenMode zenMode) { if (mZenButton == null) { mZenButton = ((LayoutPreference) preference).findViewById(R.id.activate_mode); } mZenButton.setOnClickListener(v -> { if (zenMode.isActive()) { mBackend.deactivateMode(zenMode); } else { mBackend.activateMode(zenMode, null); } }); if (zenMode.isActive()) { mZenButton.setText(R.string.zen_mode_button_turn_off); } else { mZenButton.setText(R.string.zen_mode_button_turn_on); } } }
src/com/android/settings/notification/modes/ZenModeFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ public class ZenModeFragment extends ZenModeFragmentBase { protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { List<AbstractPreferenceController> prefControllers = new ArrayList<>(); prefControllers.add(new ZenModeHeaderController(context, "header", this, mBackend)); prefControllers.add(new ZenModeButtonPreferenceController(context, "activate", mBackend)); prefControllers.add(new ZenModePeopleLinkPreferenceController( context, "zen_mode_people", mBackend)); prefControllers.add(new ZenModeOtherLinkPreferenceController( Loading