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; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.preference.PreferenceManager; 23 import android.support.v7.preference.PreferenceScreen; 24 import android.text.TextUtils; 25 import android.util.Log; 26 27 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 28 import com.android.internal.widget.LockPatternUtils; 29 import com.android.settings.R; 30 import com.android.settings.applications.AppInfoBase; 31 import com.android.settingslib.core.AbstractPreferenceController; 32 33 import java.util.ArrayList; 34 import java.util.List; 35 36 public class ChannelNotificationSettings extends NotificationSettingsBase { 37 private static final String TAG = "ChannelSettings"; 38 39 @Override getMetricsCategory()40 public int getMetricsCategory() { 41 return MetricsEvent.NOTIFICATION_TOPIC_NOTIFICATION; 42 } 43 44 @Override onCreate(Bundle savedInstanceState)45 public void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 final PreferenceScreen screen = getPreferenceScreen(); 48 Bundle args = getArguments(); 49 // If linking to this screen from an external app, expand settings 50 if (screen != null && args != null) { 51 if (!args.getBoolean(ARG_FROM_SETTINGS, false)) { 52 screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE); 53 } 54 } 55 } 56 57 @Override onResume()58 public void onResume() { 59 super.onResume(); 60 if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) { 61 Log.w(TAG, "Missing package or uid or packageinfo or channel"); 62 finish(); 63 return; 64 } 65 66 for (NotificationPreferenceController controller : mControllers) { 67 controller.onResume(mAppRow, mChannel, mChannelGroup, mSuspendedAppsAdmin); 68 controller.displayPreference(getPreferenceScreen()); 69 } 70 updatePreferenceStates(); 71 } 72 73 @Override onActivityResult(int requestCode, int resultCode, Intent data)74 public void onActivityResult(int requestCode, int resultCode, Intent data) { 75 for (NotificationPreferenceController controller : mControllers) { 76 if (controller instanceof PreferenceManager.OnActivityResultListener) { 77 ((PreferenceManager.OnActivityResultListener) controller) 78 .onActivityResult(requestCode, resultCode, data); 79 } 80 } 81 } 82 83 @Override getLogTag()84 protected String getLogTag() { 85 return TAG; 86 } 87 88 @Override getPreferenceScreenResId()89 protected int getPreferenceScreenResId() { 90 return R.xml.channel_notification_settings; 91 } 92 93 @Override createPreferenceControllers(Context context)94 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 95 mControllers = new ArrayList<>(); 96 mControllers.add(new HeaderPreferenceController(context, this)); 97 mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend)); 98 mControllers.add(new ImportancePreferenceController( 99 context, mImportanceListener, mBackend)); 100 mControllers.add(new AllowSoundPreferenceController( 101 context, mImportanceListener, mBackend)); 102 mControllers.add(new SoundPreferenceController(context, this, 103 mImportanceListener, mBackend)); 104 mControllers.add(new VibrationPreferenceController(context, mBackend)); 105 mControllers.add(new AppLinkPreferenceController(context)); 106 mControllers.add(new DescriptionPreferenceController(context)); 107 mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context), 108 mBackend)); 109 mControllers.add(new LightsPreferenceController(context, mBackend)); 110 mControllers.add(new BadgePreferenceController(context, mBackend)); 111 mControllers.add(new DndPreferenceController(context, mBackend)); 112 mControllers.add(new NotificationsOffPreferenceController(context)); 113 return new ArrayList<>(mControllers); 114 } 115 } 116