1 /* 2 * Copyright (C) 2018 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.panel; 18 19 import static com.android.settingslib.media.MediaOutputSliceConstants.EXTRA_PACKAGE_NAME; 20 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.util.Log; 24 import android.view.Gravity; 25 import android.view.Window; 26 import android.view.WindowManager; 27 28 import androidx.annotation.Nullable; 29 import androidx.fragment.app.Fragment; 30 import androidx.fragment.app.FragmentActivity; 31 import androidx.fragment.app.FragmentManager; 32 33 import com.android.internal.annotations.VisibleForTesting; 34 import com.android.settings.R; 35 import com.android.settings.core.HideNonSystemOverlayMixin; 36 37 /** 38 * Dialog Activity to host Settings Slices. 39 */ 40 public class SettingsPanelActivity extends FragmentActivity { 41 42 private final String TAG = "panel_activity"; 43 44 @VisibleForTesting 45 final Bundle mBundle = new Bundle(); 46 47 /** 48 * Key specifying which Panel the app is requesting. 49 */ 50 public static final String KEY_PANEL_TYPE_ARGUMENT = "PANEL_TYPE_ARGUMENT"; 51 52 /** 53 * Key specifying the package which requested the Panel. 54 */ 55 public static final String KEY_CALLING_PACKAGE_NAME = "PANEL_CALLING_PACKAGE_NAME"; 56 57 /** 58 * Key specifying the package name for which the 59 */ 60 public static final String KEY_MEDIA_PACKAGE_NAME = "PANEL_MEDIA_PACKAGE_NAME"; 61 62 @Override onCreate(@ullable Bundle savedInstanceState)63 protected void onCreate(@Nullable Bundle savedInstanceState) { 64 super.onCreate(savedInstanceState); 65 createOrUpdatePanel(true /* shouldForceCreation */); 66 getLifecycle().addObserver(new HideNonSystemOverlayMixin(this)); 67 } 68 69 @Override onNewIntent(Intent intent)70 protected void onNewIntent(Intent intent) { 71 super.onNewIntent(intent); 72 setIntent(intent); 73 createOrUpdatePanel(false /* shouldForceCreation */); 74 } 75 createOrUpdatePanel(boolean shouldForceCreation)76 private void createOrUpdatePanel(boolean shouldForceCreation) { 77 final Intent callingIntent = getIntent(); 78 if (callingIntent == null) { 79 Log.e(TAG, "Null intent, closing Panel Activity"); 80 finish(); 81 return; 82 } 83 84 // We will use it once media output switch panel support remote device. 85 final String mediaPackageName = callingIntent.getStringExtra(EXTRA_PACKAGE_NAME); 86 87 mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, callingIntent.getAction()); 88 mBundle.putString(KEY_CALLING_PACKAGE_NAME, getCallingPackage()); 89 mBundle.putString(KEY_MEDIA_PACKAGE_NAME, mediaPackageName); 90 91 final FragmentManager fragmentManager = getSupportFragmentManager(); 92 final Fragment fragment = fragmentManager.findFragmentById(R.id.main_content); 93 94 // If fragment already exists, we will need to update panel with animation. 95 if (!shouldForceCreation && fragment != null && fragment instanceof PanelFragment) { 96 final PanelFragment panelFragment = (PanelFragment) fragment; 97 panelFragment.setArguments(mBundle); 98 ((PanelFragment) fragment).updatePanelWithAnimation(); 99 } else { 100 setContentView(R.layout.settings_panel); 101 102 // Move the window to the bottom of screen, and make it take up the entire screen width. 103 final Window window = getWindow(); 104 window.setGravity(Gravity.BOTTOM); 105 window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, 106 WindowManager.LayoutParams.WRAP_CONTENT); 107 final PanelFragment panelFragment = new PanelFragment(); 108 panelFragment.setArguments(mBundle); 109 fragmentManager.beginTransaction().add(R.id.main_content, panelFragment).commit(); 110 } 111 } 112 } 113