• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 android.app.settings.SettingsEnums;
20 import android.content.Intent;
21 import android.content.res.Configuration;
22 import android.os.Bundle;
23 import android.provider.Settings;
24 import android.util.Log;
25 import android.view.Gravity;
26 import android.view.Window;
27 import android.view.WindowManager;
28 
29 import androidx.annotation.NonNull;
30 import androidx.annotation.Nullable;
31 import androidx.fragment.app.FragmentActivity;
32 import androidx.fragment.app.FragmentManager;
33 
34 import com.android.settings.R;
35 import com.android.settings.core.SubSettingLauncher;
36 import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
37 
38 /**
39  * Dialog Activity to host channel settings
40  */
41 public class ChannelPanelActivity extends FragmentActivity {
42 
43     private static final String TAG = "ChannelPanelActivity";
44 
45     final Bundle mBundle = new Bundle();
46     NotificationSettings mPanelFragment;
47 
48     @Override
onCreate(@ullable Bundle savedInstanceState)49     protected void onCreate(@Nullable Bundle savedInstanceState) {
50         super.onCreate(savedInstanceState);
51         if (!getIntent().hasExtra(Settings.EXTRA_CHANNEL_FILTER_LIST)) {
52             launchFullSettings();
53         }
54 
55         getApplicationContext().getTheme().rebase();
56         createOrUpdatePanel();
57         getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
58     }
59 
60     @Override
onNewIntent(Intent intent)61     protected void onNewIntent(Intent intent) {
62         super.onNewIntent(intent);
63         setIntent(intent);
64         createOrUpdatePanel();
65     }
66 
67     @Override
onConfigurationChanged(@onNull Configuration newConfig)68     public void onConfigurationChanged(@NonNull Configuration newConfig) {
69         super.onConfigurationChanged(newConfig);
70     }
71 
launchFullSettings()72     private void launchFullSettings() {
73         Bundle extras = getIntent().getExtras();
74         extras.remove(Settings.EXTRA_CHANNEL_FILTER_LIST);
75         startActivity(new SubSettingLauncher(this)
76                 .setDestination(ChannelNotificationSettings.class.getName())
77                 .setExtras(extras)
78                 .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_TOPIC_NOTIFICATION)
79                 .toIntent());
80         finish();
81     }
82 
createOrUpdatePanel()83     private void createOrUpdatePanel() {
84         final Intent callingIntent = getIntent();
85         if (callingIntent == null) {
86             Log.e(TAG, "Null intent, closing Panel Activity");
87             finish();
88             return;
89         }
90 
91         final FragmentManager fragmentManager = getSupportFragmentManager();
92         setContentView(R.layout.notification_channel_panel);
93 
94         // Move the window to the bottom of screen, and make it take up the entire screen width.
95         final Window window = getWindow();
96         window.setGravity(Gravity.BOTTOM);
97         window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
98                 WindowManager.LayoutParams.WRAP_CONTENT);
99 
100         findViewById(R.id.done).setOnClickListener(v -> finish());
101         findViewById(R.id.see_more).setOnClickListener(v -> launchFullSettings());
102 
103         mPanelFragment = callingIntent.hasExtra(Settings.EXTRA_CONVERSATION_ID)
104                 ? new ConversationNotificationSettings()
105                 : new ChannelNotificationSettings();
106         mPanelFragment.setArguments(new Bundle(mBundle));
107         fragmentManager.beginTransaction().replace(
108                 android.R.id.list_container, mPanelFragment).commit();
109     }
110 }
111