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