• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.app;
18 
19 import static com.android.settings.notification.app.ChannelListPreferenceController.ARG_FROM_SETTINGS;
20 
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.os.Bundle;
25 import android.preference.PreferenceManager;
26 import android.text.TextUtils;
27 import android.util.Log;
28 
29 import androidx.preference.PreferenceScreen;
30 
31 import com.android.internal.widget.LockPatternUtils;
32 import com.android.settings.R;
33 import com.android.settings.core.SubSettingLauncher;
34 import com.android.settingslib.core.AbstractPreferenceController;
35 
36 import java.util.ArrayList;
37 import java.util.List;
38 
39 public class ChannelNotificationSettings extends NotificationSettings {
40     private static final String TAG = "ChannelSettings";
41 
42     @Override
getMetricsCategory()43     public int getMetricsCategory() {
44         return SettingsEnums.NOTIFICATION_TOPIC_NOTIFICATION;
45     }
46 
47     @Override
onCreate(Bundle savedInstanceState)48     public void onCreate(Bundle savedInstanceState) {
49         super.onCreate(savedInstanceState);
50         final PreferenceScreen screen = getPreferenceScreen();
51         Bundle args = getArguments();
52         // If linking to this screen from an external app, expand settings
53         if (screen != null && args != null) {
54             if (!args.getBoolean(ARG_FROM_SETTINGS, false)) {
55                 screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
56             }
57         }
58     }
59 
60     @Override
onResume()61     public void onResume() {
62         super.onResume();
63         if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) {
64             Log.w(TAG, "Missing package or uid or packageinfo or channel");
65             finish();
66             return;
67         }
68 
69         getActivity().setTitle(mChannel.getName());
70 
71         if (!TextUtils.isEmpty(mChannel.getConversationId()) && !mChannel.isDemoted()) {
72             Intent intent = new SubSettingLauncher(mContext)
73                     .setDestination(ConversationNotificationSettings.class.getName())
74                     .setArguments(getArguments())
75                     .setExtras(getIntent() != null ? getIntent().getExtras(): null)
76                     .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_TOPIC_NOTIFICATION)
77                     .toIntent();
78             if (mPreferenceFilter != null) {
79                 intent.setClass(mContext, ChannelPanelActivity.class);
80             }
81             startActivity(intent);
82             finish();
83             return;
84         }
85 
86         for (NotificationPreferenceController controller : mControllers) {
87             controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin,
88                     mPreferenceFilter);
89             controller.displayPreference(getPreferenceScreen());
90         }
91         updatePreferenceStates();
92         animatePanel();
93     }
94 
95     @Override
onActivityResult(int requestCode, int resultCode, Intent data)96     public void onActivityResult(int requestCode, int resultCode, Intent data) {
97         for (NotificationPreferenceController controller : mControllers) {
98             if (controller instanceof PreferenceManager.OnActivityResultListener) {
99                 ((PreferenceManager.OnActivityResultListener) controller)
100                         .onActivityResult(requestCode, resultCode, data);
101             }
102         }
103     }
104 
105     @Override
getLogTag()106     protected String getLogTag() {
107         return TAG;
108     }
109 
110     @Override
getPreferenceScreenResId()111     protected int getPreferenceScreenResId() {
112         return  R.xml.channel_notification_settings;
113     }
114 
115     @Override
createPreferenceControllers(Context context)116     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
117         mControllers = new ArrayList<>();
118         mControllers.add(new HeaderPreferenceController(context, this));
119         mControllers.add(new BlockPreferenceController(context, mDependentFieldListener, mBackend));
120         mControllers.add(new ImportancePreferenceController(
121                 context, mDependentFieldListener, mBackend));
122         mControllers.add(new MinImportancePreferenceController(
123                 context, mDependentFieldListener, mBackend));
124         mControllers.add(new HighImportancePreferenceController(
125                 context, mDependentFieldListener, mBackend));
126         mControllers.add(new AllowSoundPreferenceController(
127                 context, mDependentFieldListener, mBackend));
128         mControllers.add(new SoundPreferenceController(context, this,
129                 mDependentFieldListener, mBackend));
130         mControllers.add(new VibrationPreferenceController(context, mBackend));
131         mControllers.add(new AppLinkPreferenceController(context));
132         mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
133                 mBackend));
134         mControllers.add(new LightsPreferenceController(context, mBackend));
135         mControllers.add(new BadgePreferenceController(context, mBackend));
136         mControllers.add(new DndPreferenceController(context, mBackend));
137         mControllers.add(new NotificationsOffPreferenceController(context));
138         mControllers.add(new ConversationPromotePreferenceController(context, this, mBackend));
139         return new ArrayList<>(mControllers);
140     }
141 }
142