Add entry point to launch media output slice
Add media output panel type to launch media output slice. Bug: 121083246 Test: make -j RunSettingsRoboTests Change-Id: Ibf706146430e309fef6cbf0e1e86c2d5b78b50d5
This commit is contained in:
74
src/com/android/settings/panel/MediaOutputPanel.java
Normal file
74
src/com/android/settings/panel/MediaOutputPanel.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settings.media.MediaOutputSlice.MEDIA_PACKAGE_NAME;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the Media output Panel.
|
||||
*
|
||||
* <p>
|
||||
* Displays Media output item
|
||||
* </p>
|
||||
*/
|
||||
public class MediaOutputPanel implements PanelContent {
|
||||
|
||||
private final Context mContext;
|
||||
private final String mPackageName;
|
||||
|
||||
public static MediaOutputPanel create(Context context, String packageName) {
|
||||
return new MediaOutputPanel(context, packageName);
|
||||
}
|
||||
|
||||
private MediaOutputPanel(Context context, String packageName) {
|
||||
mContext = context.getApplicationContext();
|
||||
mPackageName = packageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mContext.getText(R.string.media_output_panel_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Uri> getSlices() {
|
||||
final List<Uri> uris = new ArrayList<>();
|
||||
MEDIA_OUTPUT_SLICE_URI =
|
||||
MEDIA_OUTPUT_SLICE_URI
|
||||
.buildUpon()
|
||||
.clearQuery()
|
||||
.appendQueryParameter(MEDIA_PACKAGE_NAME, mPackageName)
|
||||
.build();
|
||||
uris.add(MEDIA_OUTPUT_SLICE_URI);
|
||||
return uris;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent getSeeMoreIntent() {
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -21,7 +21,7 @@ import android.content.Context;
|
||||
public interface PanelFeatureProvider {
|
||||
|
||||
/**
|
||||
* Returns {@link PanelContent} as specified by the {@param panelType}.
|
||||
* Returns {@link PanelContent} as specified by the {@code panelType} and {@code packageName}.
|
||||
*/
|
||||
PanelContent getPanel(Context context, String panelType);
|
||||
PanelContent getPanel(Context context, String panelType, String packageName);
|
||||
}
|
||||
|
@@ -16,13 +16,15 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
public class PanelFeatureProviderImpl implements PanelFeatureProvider {
|
||||
|
||||
@Override
|
||||
public PanelContent getPanel(Context context, String panelType) {
|
||||
public PanelContent getPanel(Context context, String panelType, String packageName) {
|
||||
switch (panelType) {
|
||||
case Settings.Panel.ACTION_INTERNET_CONNECTIVITY:
|
||||
return InternetConnectivityPanel.create(context);
|
||||
@@ -30,6 +32,8 @@ public class PanelFeatureProviderImpl implements PanelFeatureProvider {
|
||||
return VolumePanel.create(context);
|
||||
case Settings.Panel.ACTION_NFC:
|
||||
return NfcPanel.create(context);
|
||||
case ACTION_MEDIA_OUTPUT:
|
||||
return MediaOutputPanel.create(context, packageName);
|
||||
}
|
||||
|
||||
throw new IllegalStateException("No matching panel for: " + panelType);
|
||||
|
@@ -70,10 +70,12 @@ public class PanelFragment extends Fragment {
|
||||
|
||||
final Bundle arguments = getArguments();
|
||||
final String panelType = arguments.getString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT);
|
||||
final String packageName =
|
||||
arguments.getString(SettingsPanelActivity.KEY_PANEL_PACKAGE_NAME);
|
||||
|
||||
final PanelContent panel = FeatureFactory.getFactory(activity)
|
||||
.getPanelFeatureProvider()
|
||||
.getPanel(activity, panelType);
|
||||
.getPanel(activity, panelType, packageName);
|
||||
|
||||
mAdapter = new PanelSlicesAdapter(this, panel.getSlices());
|
||||
|
||||
@@ -86,6 +88,11 @@ public class PanelFragment extends Fragment {
|
||||
mSeeMoreButton.setOnClickListener(getSeeMoreListener(panel.getSeeMoreIntent()));
|
||||
mDoneButton.setOnClickListener(mDoneButtonListener);
|
||||
|
||||
//If getSeeMoreIntent() is null, hide the mSeeMoreButton.
|
||||
if (panel.getSeeMoreIntent() == null) {
|
||||
mSeeMoreButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@@ -16,8 +16,12 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
|
||||
import static com.android.settingslib.media.MediaOutputSliceConstants.EXTRA_PACKAGE_NAME;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.Window;
|
||||
@@ -28,6 +32,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
@@ -37,10 +42,14 @@ public class SettingsPanelActivity extends FragmentActivity {
|
||||
|
||||
private final String TAG = "panel_activity";
|
||||
|
||||
@VisibleForTesting
|
||||
final Bundle mBundle = new Bundle();
|
||||
|
||||
/**
|
||||
* Key specifying which Panel the app is requesting.
|
||||
*/
|
||||
public static final String KEY_PANEL_TYPE_ARGUMENT = "PANEL_TYPE_ARGUMENT";
|
||||
public static final String KEY_PANEL_PACKAGE_NAME = "PANEL_PACKAGE_NAME";
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -53,6 +62,16 @@ public class SettingsPanelActivity extends FragmentActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
final String packageName =
|
||||
callingIntent.getStringExtra(EXTRA_PACKAGE_NAME);
|
||||
|
||||
if (TextUtils.equals(ACTION_MEDIA_OUTPUT, callingIntent.getAction())
|
||||
&& TextUtils.isEmpty(packageName)) {
|
||||
Log.e(TAG, "Null package name, closing Panel Activity");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
setContentView(R.layout.settings_panel);
|
||||
|
||||
// Move the window to the bottom of screen, and make it take up the entire screen width.
|
||||
@@ -61,11 +80,11 @@ public class SettingsPanelActivity extends FragmentActivity {
|
||||
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(KEY_PANEL_TYPE_ARGUMENT, callingIntent.getAction());
|
||||
mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, callingIntent.getAction());
|
||||
mBundle.putString(KEY_PANEL_PACKAGE_NAME, packageName);
|
||||
|
||||
final PanelFragment panelFragment = new PanelFragment();
|
||||
panelFragment.setArguments(bundle);
|
||||
panelFragment.setArguments(mBundle);
|
||||
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
final Fragment fragment = fragmentManager.findFragmentById(R.id.main_content);
|
||||
|
Reference in New Issue
Block a user