From b6da00e69a4c0c40a9f75a1909ad5f519b108e08 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Tue, 15 Oct 2019 09:44:12 -0400 Subject: [PATCH] Home Controls: Add a new Controls tile for prototyping Must edit the QS area to add the new Controls tile and have set: adb shell settings put system qs_controls_tile_enabled 1 Test: visual Change-Id: I7359d394d6d0a5eb408de7049bf0b3051c83e361 --- .../systemui/plugins/HomeControlsPlugin.java | 5 + .../ic_lightbulb_outline_gm2_24px.xml | 9 + .../SystemUI/res/layout/home_controls.xml | 13 ++ .../res/layout/status_bar_expanded.xml | 14 +- packages/SystemUI/res/values/config.xml | 2 +- .../systemui/qs/tileimpl/QSFactoryImpl.java | 10 + .../systemui/qs/tiles/ControlsTile.java | 197 ++++++++++++++++++ 7 files changed, 237 insertions(+), 13 deletions(-) create mode 100644 packages/SystemUI/res/drawable/ic_lightbulb_outline_gm2_24px.xml create mode 100644 packages/SystemUI/res/layout/home_controls.xml create mode 100644 packages/SystemUI/src/com/android/systemui/qs/tiles/ControlsTile.java diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/HomeControlsPlugin.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/HomeControlsPlugin.java index cac673fdbf0b1..c1d4b03b66206 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/HomeControlsPlugin.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/HomeControlsPlugin.java @@ -33,4 +33,9 @@ public interface HomeControlsPlugin extends Plugin { * will add home controls to this space. */ void sendParentGroup(ViewGroup group); + + /** + * When visible, will poll for updates. + */ + void setVisible(boolean visible); } diff --git a/packages/SystemUI/res/drawable/ic_lightbulb_outline_gm2_24px.xml b/packages/SystemUI/res/drawable/ic_lightbulb_outline_gm2_24px.xml new file mode 100644 index 0000000000000..87684a32e016b --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_lightbulb_outline_gm2_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/packages/SystemUI/res/layout/home_controls.xml b/packages/SystemUI/res/layout/home_controls.xml new file mode 100644 index 0000000000000..bb971c206e5ce --- /dev/null +++ b/packages/SystemUI/res/layout/home_controls.xml @@ -0,0 +1,13 @@ + + + diff --git a/packages/SystemUI/res/layout/status_bar_expanded.xml b/packages/SystemUI/res/layout/status_bar_expanded.xml index 0e59a41a8e2c8..4869be11a9062 100644 --- a/packages/SystemUI/res/layout/status_bar_expanded.xml +++ b/packages/SystemUI/res/layout/status_bar_expanded.xml @@ -51,17 +51,7 @@ systemui:viewType="com.android.systemui.plugins.qs.QS" /> - - + - \ No newline at end of file + diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 105b27eb7e1b1..efcc2c44ba942 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -117,7 +117,7 @@ - wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,location,hotspot,inversion,saver,dark,work,cast,night + wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,location,hotspot,inversion,saver,dark,work,cast,night,controls diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java index daaee4cd53362..1c8e451e52f7c 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java @@ -16,6 +16,7 @@ package com.android.systemui.qs.tileimpl; import android.content.Context; import android.os.Build; +import android.provider.Settings; import android.util.Log; import android.view.ContextThemeWrapper; @@ -32,6 +33,7 @@ import com.android.systemui.qs.tiles.BluetoothTile; import com.android.systemui.qs.tiles.CastTile; import com.android.systemui.qs.tiles.CellularTile; import com.android.systemui.qs.tiles.ColorInversionTile; +import com.android.systemui.qs.tiles.ControlsTile; import com.android.systemui.qs.tiles.DataSaverTile; import com.android.systemui.qs.tiles.DndTile; import com.android.systemui.qs.tiles.FlashlightTile; @@ -58,6 +60,7 @@ public class QSFactoryImpl implements QSFactory { private final Provider mWifiTileProvider; private final Provider mBluetoothTileProvider; + private final Provider mControlsTileProvider; private final Provider mCellularTileProvider; private final Provider mDndTileProvider; private final Provider mColorInversionTileProvider; @@ -81,6 +84,7 @@ public class QSFactoryImpl implements QSFactory { @Inject public QSFactoryImpl(Provider wifiTileProvider, Provider bluetoothTileProvider, + Provider controlsTileProvider, Provider cellularTileProvider, Provider dndTileProvider, Provider colorInversionTileProvider, @@ -100,6 +104,7 @@ public class QSFactoryImpl implements QSFactory { Provider uiModeNightTileProvider) { mWifiTileProvider = wifiTileProvider; mBluetoothTileProvider = bluetoothTileProvider; + mControlsTileProvider = controlsTileProvider; mCellularTileProvider = cellularTileProvider; mDndTileProvider = dndTileProvider; mColorInversionTileProvider = colorInversionTileProvider; @@ -138,6 +143,11 @@ public class QSFactoryImpl implements QSFactory { return mWifiTileProvider.get(); case "bt": return mBluetoothTileProvider.get(); + case "controls": + if (Settings.System.getInt(mHost.getContext().getContentResolver(), + "qs_controls_tile_enabled", 0) == 1) { + return mControlsTileProvider.get(); + } else return null; case "cell": return mCellularTileProvider.get(); case "dnd": diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/ControlsTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/ControlsTile.java new file mode 100644 index 0000000000000..0a59618b59a18 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/ControlsTile.java @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2014 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.systemui.qs.tiles; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import com.android.systemui.R; +import com.android.systemui.plugins.ActivityStarter; +import com.android.systemui.plugins.HomeControlsPlugin; +import com.android.systemui.plugins.PluginListener; +import com.android.systemui.plugins.qs.DetailAdapter; +import com.android.systemui.plugins.qs.QSTile.BooleanState; +import com.android.systemui.qs.QSHost; +import com.android.systemui.qs.tileimpl.QSTileImpl; +import com.android.systemui.shared.plugins.PluginManager; + +import javax.inject.Inject; + + +/** + * Temporary control test for prototyping + */ +public class ControlsTile extends QSTileImpl { + private ControlsDetailAdapter mDetailAdapter; + private final ActivityStarter mActivityStarter; + private PluginManager mPluginManager; + private HomeControlsPlugin mPlugin; + private Intent mHomeAppIntent; + + @Inject + public ControlsTile(QSHost host, + ActivityStarter activityStarter, + PluginManager pluginManager) { + super(host); + mActivityStarter = activityStarter; + mPluginManager = pluginManager; + mDetailAdapter = (ControlsDetailAdapter) createDetailAdapter(); + + mHomeAppIntent = new Intent(Intent.ACTION_VIEW); + mHomeAppIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mHomeAppIntent.setComponent(new ComponentName("com.google.android.apps.chromecast.app", + "com.google.android.apps.chromecast.app.DiscoveryActivity")); + } + + @Override + public DetailAdapter getDetailAdapter() { + return mDetailAdapter; + } + + @Override + public BooleanState newTileState() { + return new BooleanState(); + } + + @Override + public void handleSetListening(boolean listening) { + + } + + @Override + public void setDetailListening(boolean listening) { + if (mPlugin == null) return; + + mPlugin.setVisible(listening); + } + + @Override + protected void handleClick() { + showDetail(true); + } + + @Override + public Intent getLongClickIntent() { + return mHomeAppIntent; + } + + @Override + protected void handleSecondaryClick() { + showDetail(true); + } + + @Override + public CharSequence getTileLabel() { + return "Controls"; + } + + @Override + protected void handleUpdateState(BooleanState state, Object arg) { + state.icon = ResourceIcon.get(R.drawable.ic_lightbulb_outline_gm2_24px); + state.label = "Controls"; + } + + @Override + public boolean supportsDetailView() { + return getDetailAdapter() != null && mQSSettingsPanelOption == QSSettingsPanel.OPEN_CLICK; + } + + @Override + public int getMetricsCategory() { + return -1; + } + + @Override + protected String composeChangeAnnouncement() { + if (mState.value) { + return "On"; + } else { + return "Off"; + } + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + protected DetailAdapter createDetailAdapter() { + mDetailAdapter = new ControlsDetailAdapter(); + return mDetailAdapter; + } + + private class ControlsDetailAdapter implements DetailAdapter { + private View mDetailView; + protected LinearLayout mHomeControlsLayout; + + public CharSequence getTitle() { + return "Controls"; + } + + public Boolean getToggleState() { + return null; + } + + public boolean getToggleEnabled() { + return false; + } + + public View createDetailView(Context context, View convertView, final ViewGroup parent) { + mHomeControlsLayout = (LinearLayout) LayoutInflater.from(context).inflate( + R.layout.home_controls, parent, false); + mHomeControlsLayout.setVisibility(View.VISIBLE); + mPluginManager.addPluginListener( + new PluginListener() { + @Override + public void onPluginConnected(HomeControlsPlugin plugin, + Context pluginContext) { + mPlugin = plugin; + mPlugin.sendParentGroup(mHomeControlsLayout); + mPlugin.setVisible(true); + } + + @Override + public void onPluginDisconnected(HomeControlsPlugin plugin) { + + } + }, HomeControlsPlugin.class, false); + return mHomeControlsLayout; + } + + public Intent getSettingsIntent() { + return mHomeAppIntent; + } + + public void setToggleState(boolean state) { + + } + + public int getMetricsCategory() { + return -1; + } + + public boolean hasHeader() { + return false; + } + } +}