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.core.view.ViewCompat; 32 import androidx.core.view.WindowInsetsControllerCompat; 33 import androidx.fragment.app.FragmentActivity; 34 import androidx.fragment.app.FragmentManager; 35 36 import com.android.settings.R; 37 import com.android.settings.Utils; 38 import com.android.settings.core.SubSettingLauncher; 39 import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin; 40 41 /** 42 * Dialog Activity to host channel settings 43 */ 44 public class ChannelPanelActivity extends FragmentActivity { 45 46 private static final String TAG = "ChannelPanelActivity"; 47 48 final Bundle mBundle = new Bundle(); 49 NotificationSettings mPanelFragment; 50 51 @Override onCreate(@ullable Bundle savedInstanceState)52 protected void onCreate(@Nullable Bundle savedInstanceState) { 53 super.onCreate(savedInstanceState); 54 if (!getIntent().hasExtra(Settings.EXTRA_CHANNEL_FILTER_LIST)) { 55 launchFullSettings(); 56 } 57 58 getApplicationContext().getTheme().rebase(); 59 createOrUpdatePanel(); 60 getLifecycle().addObserver(new HideNonSystemOverlayMixin(this)); 61 } 62 63 @Override onNewIntent(Intent intent)64 protected void onNewIntent(Intent intent) { 65 super.onNewIntent(intent); 66 setIntent(intent); 67 createOrUpdatePanel(); 68 } 69 70 @Override onConfigurationChanged(@onNull Configuration newConfig)71 public void onConfigurationChanged(@NonNull Configuration newConfig) { 72 super.onConfigurationChanged(newConfig); 73 } 74 launchFullSettings()75 private void launchFullSettings() { 76 Bundle extras = getIntent().getExtras(); 77 extras.remove(Settings.EXTRA_CHANNEL_FILTER_LIST); 78 startActivity(new SubSettingLauncher(this) 79 .setDestination(ChannelNotificationSettings.class.getName()) 80 .setExtras(extras) 81 .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_TOPIC_NOTIFICATION) 82 .toIntent()); 83 finish(); 84 } 85 createOrUpdatePanel()86 private void createOrUpdatePanel() { 87 final Intent callingIntent = getIntent(); 88 if (callingIntent == null) { 89 Log.e(TAG, "Null intent, closing Panel Activity"); 90 finish(); 91 return; 92 } 93 94 final FragmentManager fragmentManager = getSupportFragmentManager(); 95 setContentView(R.layout.notification_channel_panel); 96 97 // Move the window to the bottom of screen, and make it take up the entire screen width. 98 final Window window = getWindow(); 99 window.setGravity(Gravity.BOTTOM); 100 window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, 101 WindowManager.LayoutParams.WRAP_CONTENT); 102 103 findViewById(R.id.done).setOnClickListener(v -> finish()); 104 findViewById(R.id.see_more).setOnClickListener(v -> launchFullSettings()); 105 setupNavigationBar(); 106 mPanelFragment = callingIntent.hasExtra(Settings.EXTRA_CONVERSATION_ID) 107 ? new ConversationNotificationSettings() 108 : new ChannelNotificationSettings(); 109 mPanelFragment.setArguments(new Bundle(mBundle)); 110 fragmentManager.beginTransaction().replace( 111 android.R.id.list_container, mPanelFragment).commit(); 112 } 113 114 /** 115 * Adjust bottom edge and color. 116 */ setupNavigationBar()117 private void setupNavigationBar() { 118 // Extend the panel all the way to the bottom of the screen, as opposed to sitting on top of 119 // the navigation bar. 120 ViewCompat.setOnApplyWindowInsetsListener(getWindow().getDecorView(), 121 (v, windowInsets) -> { 122 v.setPadding(v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(), 0); 123 return windowInsets; // propagate down to panel layout root element 124 }); 125 126 // When using 3-button navigation in light mode, the system picks white navigation buttons 127 // which are not sufficiently contrasted from the panel background. 128 WindowInsetsControllerCompat windowInsetsController = 129 ViewCompat.getWindowInsetsController(getWindow().getDecorView()); 130 131 if (windowInsetsController != null) { 132 boolean forceNavigationButtonsDark = !Utils.isNightMode(this); 133 windowInsetsController.setAppearanceLightNavigationBars(forceNavigationButtonsDark); 134 } 135 } 136 } 137