• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.notification.modes;
18 
19 import android.app.settings.SettingsEnums;
20 
21 import androidx.annotation.Nullable;
22 
23 import com.android.settings.R;
24 import com.android.settingslib.notification.modes.ZenMode;
25 
26 import com.google.common.base.Strings;
27 
28 public class ZenModeNewCustomFragment extends ZenModeEditNameIconFragmentBase {
29 
30     @Nullable
31     @Override
onCreateInstantiateZenMode()32     protected ZenMode onCreateInstantiateZenMode() {
33         return ZenMode.newCustomManual(
34                 requireContext().getString(R.string.zen_mode_new_custom_default_name),
35                 /* iconResId= */ 0);
36     }
37 
38     @Override
onStart()39     public void onStart() {
40         super.onStart();
41         requireActivity().setTitle(R.string.zen_mode_new_custom_title);
42     }
43 
44     @Override
saveMode(ZenMode mode)45     void saveMode(ZenMode mode) {
46         String modeName = Strings.isNullOrEmpty(mode.getName())
47                 ? requireContext().getString(R.string.zen_mode_new_custom_default_name)
48                 : mode.getName();
49 
50         ZenMode created = requireBackend().addCustomManualMode(modeName, mode.getIconResId());
51         if (created != null) {
52             // Open the mode view fragment and close the "add mode" fragment, so exiting the mode
53             // view goes back to previous screen (which should be the modes list).
54             ZenSubSettingLauncher.forModeFragment(requireContext(), ZenModeFragment.class,
55                     created.getId(), getMetricsCategory()).launch();
56             finish();
57         }
58     }
59 
60     @Override
getMetricsCategory()61     public int getMetricsCategory() {
62         return SettingsEnums.ZEN_MODE_ADD_NEW;
63     }
64 
65     @Override
getLogTag()66     protected String getLogTag() {
67         return "ZenModeNewCustomFragment";
68     }
69 }
70