Loading packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinator.kt 0 → 100644 +50 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 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.controls.ui import android.app.PendingIntent import android.content.Intent import android.service.controls.actions.BooleanAction import android.util.Log import android.view.HapticFeedbackConstants object ControlActionCoordinator { public const val MIN_LEVEL = 0 public const val MAX_LEVEL = 10000 fun toggle(cvh: ControlViewHolder, templateId: String, isChecked: Boolean) { cvh.action(BooleanAction(templateId, !isChecked)) val nextLevel = if (isChecked) MIN_LEVEL else MAX_LEVEL cvh.clipLayer.setLevel(nextLevel) } fun longPress(cvh: ControlViewHolder) { // Long press snould only be called when there is valid control state, otherwise ignore cvh.cws.control?.let { try { cvh.layout.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) it.getAppIntent().send() val closeDialog = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS) cvh.context.sendBroadcast(closeDialog) } catch (e: PendingIntent.CanceledException) { Log.e(ControlsUiController.TAG, "Error sending pending intent", e) cvh.setTransientStatus("Error opening application") } } } } packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +15 −17 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package com.android.systemui.controls.ui import android.content.Context import android.content.Intent import android.graphics.drawable.ClipDrawable import android.graphics.drawable.GradientDrawable import android.graphics.drawable.Icon Loading @@ -37,8 +36,6 @@ import com.android.systemui.controls.controller.ControlsController import com.android.systemui.util.concurrency.DelayableExecutor import com.android.systemui.R const val MIN_LEVEL = 0 const val MAX_LEVEL = 10000 private const val UPDATE_DELAY_IN_MILLIS = 3000L class ControlViewHolder( Loading Loading @@ -79,12 +76,9 @@ class ControlViewHolder( Pair(Control.STATUS_UNKNOWN, ControlTemplate.NO_TEMPLATE) } cws.control?.let { c -> cws.control?.let { layout.setOnLongClickListener(View.OnLongClickListener() { val closeDialog = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS) context.sendBroadcast(closeDialog) c.getAppIntent().send() ControlActionCoordinator.longPress(this@ControlViewHolder) true }) } Loading @@ -100,6 +94,11 @@ class ControlViewHolder( } if (!text.isEmpty()) { setTransientStatus(text) } } fun setTransientStatus(tempStatus: String) { val previousText = status.getText() val previousTextExtra = statusExtra.getText() Loading @@ -108,10 +107,9 @@ class ControlViewHolder( statusExtra.setText(previousTextExtra) }, UPDATE_DELAY_IN_MILLIS) status.setText(text) status.setText(tempStatus) statusExtra.setText("") } } fun action(action: ControlAction) { controlsController.action(cws.ci, action) Loading packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt +4 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,10 @@ import android.view.ViewGroup interface ControlsUiController { val available: Boolean companion object { public const val TAG = "ControlsUiController" } fun show(parent: ViewGroup) fun hide() fun onRefreshState(componentName: ComponentName, controls: List<Control>) Loading packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt +9 −11 Original line number Diff line number Diff line Loading @@ -51,8 +51,6 @@ import java.text.Collator import javax.inject.Inject import javax.inject.Singleton private const val TAG = "ControlsUi" // TEMP CODE for MOCK private const val TOKEN = "https://www.googleapis.com/auth/assistant" private const val SCOPE = "oauth2:" + TOKEN Loading @@ -63,13 +61,13 @@ class TokenProviderConnection(val cc: ControlsController, val context: Context) override fun onServiceConnected(cName: ComponentName, binder: IBinder) { Thread({ Log.i(TAG, "TokenProviderConnection connected") Log.i(ControlsUiController.TAG, "TokenProviderConnection connected") mTokenProvider = TokenProvider.Stub.asInterface(binder) val mLastAccountName = mTokenProvider?.getAccountName() if (mLastAccountName == null || mLastAccountName.isEmpty()) { Log.e(TAG, "NO ACCOUNT IS SET. Open HomeMock app") Log.e(ControlsUiController.TAG, "NO ACCOUNT IS SET. Open HomeMock app") } else { mTokenProvider?.setAuthToken(getAuthToken(mLastAccountName)) cc.subscribeToFavorites() Loading @@ -85,7 +83,7 @@ class TokenProviderConnection(val cc: ControlsController, val context: Context) val am = AccountManager.get(context) val accounts = am.getAccountsByType("com.google") if (accounts == null || accounts.size == 0) { Log.w(TAG, "No com.google accounts found") Log.w(ControlsUiController.TAG, "No com.google accounts found") return null } Loading @@ -104,7 +102,7 @@ class TokenProviderConnection(val cc: ControlsController, val context: Context) try { return am.blockingGetAuthToken(account!!, SCOPE, true) } catch (e: Throwable) { Log.e(TAG, "Error getting auth token", e) Log.e(ControlsUiController.TAG, "Error getting auth token", e) return null } } Loading Loading @@ -146,7 +144,7 @@ class ControlsUiControllerImpl @Inject constructor ( } override fun show(parent: ViewGroup) { Log.d(TAG, "show()") Log.d(ControlsUiController.TAG, "show()") this.parent = parent Loading Loading @@ -218,7 +216,7 @@ class ControlsUiControllerImpl @Inject constructor ( val listView = parent.requireViewById(R.id.global_actions_controls_list) as ViewGroup var lastRow: ViewGroup = createRow(inflater, listView) controlInfos.forEach { Log.d(TAG, "favorited control id: " + it.controlId) Log.d(ControlsUiController.TAG, "favorited control id: " + it.controlId) if (lastRow.getChildCount() == 2) { lastRow = createRow(inflater, listView) } Loading @@ -240,7 +238,7 @@ class ControlsUiControllerImpl @Inject constructor ( } override fun hide() { Log.d(TAG, "hide()") Log.d(ControlsUiController.TAG, "hide()") controlsController.get().unsubscribe() context.unbindService(tokenProviderConnection) tokenProviderConnection = null Loading @@ -252,10 +250,10 @@ class ControlsUiControllerImpl @Inject constructor ( } override fun onRefreshState(componentName: ComponentName, controls: List<Control>) { Log.d(TAG, "onRefreshState()") Log.d(ControlsUiController.TAG, "onRefreshState()") controls.forEach { c -> controlsById.get(ControlKey(componentName, c.getControlId()))?.let { Log.d(TAG, "onRefreshState() for id: " + c.getControlId()) Log.d(ControlsUiController.TAG, "onRefreshState() for id: " + c.getControlId()) val cws = ControlWithState(it.ci, c) val key = ControlKey(componentName, c.getControlId()) controlsById.put(key, cws) Loading packages/SystemUI/src/com/android/systemui/controls/ui/TemperatureControlBehavior.kt +2 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import android.service.controls.templates.TemperatureControlTemplate import android.widget.TextView import com.android.systemui.R import com.android.systemui.controls.ui.ControlActionCoordinator.MIN_LEVEL import com.android.systemui.controls.ui.ControlActionCoordinator.MAX_LEVEL class TemperatureControlBehavior : Behavior { lateinit var clipLayer: Drawable Loading Loading
packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinator.kt 0 → 100644 +50 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 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.controls.ui import android.app.PendingIntent import android.content.Intent import android.service.controls.actions.BooleanAction import android.util.Log import android.view.HapticFeedbackConstants object ControlActionCoordinator { public const val MIN_LEVEL = 0 public const val MAX_LEVEL = 10000 fun toggle(cvh: ControlViewHolder, templateId: String, isChecked: Boolean) { cvh.action(BooleanAction(templateId, !isChecked)) val nextLevel = if (isChecked) MIN_LEVEL else MAX_LEVEL cvh.clipLayer.setLevel(nextLevel) } fun longPress(cvh: ControlViewHolder) { // Long press snould only be called when there is valid control state, otherwise ignore cvh.cws.control?.let { try { cvh.layout.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) it.getAppIntent().send() val closeDialog = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS) cvh.context.sendBroadcast(closeDialog) } catch (e: PendingIntent.CanceledException) { Log.e(ControlsUiController.TAG, "Error sending pending intent", e) cvh.setTransientStatus("Error opening application") } } } }
packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +15 −17 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package com.android.systemui.controls.ui import android.content.Context import android.content.Intent import android.graphics.drawable.ClipDrawable import android.graphics.drawable.GradientDrawable import android.graphics.drawable.Icon Loading @@ -37,8 +36,6 @@ import com.android.systemui.controls.controller.ControlsController import com.android.systemui.util.concurrency.DelayableExecutor import com.android.systemui.R const val MIN_LEVEL = 0 const val MAX_LEVEL = 10000 private const val UPDATE_DELAY_IN_MILLIS = 3000L class ControlViewHolder( Loading Loading @@ -79,12 +76,9 @@ class ControlViewHolder( Pair(Control.STATUS_UNKNOWN, ControlTemplate.NO_TEMPLATE) } cws.control?.let { c -> cws.control?.let { layout.setOnLongClickListener(View.OnLongClickListener() { val closeDialog = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS) context.sendBroadcast(closeDialog) c.getAppIntent().send() ControlActionCoordinator.longPress(this@ControlViewHolder) true }) } Loading @@ -100,6 +94,11 @@ class ControlViewHolder( } if (!text.isEmpty()) { setTransientStatus(text) } } fun setTransientStatus(tempStatus: String) { val previousText = status.getText() val previousTextExtra = statusExtra.getText() Loading @@ -108,10 +107,9 @@ class ControlViewHolder( statusExtra.setText(previousTextExtra) }, UPDATE_DELAY_IN_MILLIS) status.setText(text) status.setText(tempStatus) statusExtra.setText("") } } fun action(action: ControlAction) { controlsController.action(cws.ci, action) Loading
packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt +4 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,10 @@ import android.view.ViewGroup interface ControlsUiController { val available: Boolean companion object { public const val TAG = "ControlsUiController" } fun show(parent: ViewGroup) fun hide() fun onRefreshState(componentName: ComponentName, controls: List<Control>) Loading
packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt +9 −11 Original line number Diff line number Diff line Loading @@ -51,8 +51,6 @@ import java.text.Collator import javax.inject.Inject import javax.inject.Singleton private const val TAG = "ControlsUi" // TEMP CODE for MOCK private const val TOKEN = "https://www.googleapis.com/auth/assistant" private const val SCOPE = "oauth2:" + TOKEN Loading @@ -63,13 +61,13 @@ class TokenProviderConnection(val cc: ControlsController, val context: Context) override fun onServiceConnected(cName: ComponentName, binder: IBinder) { Thread({ Log.i(TAG, "TokenProviderConnection connected") Log.i(ControlsUiController.TAG, "TokenProviderConnection connected") mTokenProvider = TokenProvider.Stub.asInterface(binder) val mLastAccountName = mTokenProvider?.getAccountName() if (mLastAccountName == null || mLastAccountName.isEmpty()) { Log.e(TAG, "NO ACCOUNT IS SET. Open HomeMock app") Log.e(ControlsUiController.TAG, "NO ACCOUNT IS SET. Open HomeMock app") } else { mTokenProvider?.setAuthToken(getAuthToken(mLastAccountName)) cc.subscribeToFavorites() Loading @@ -85,7 +83,7 @@ class TokenProviderConnection(val cc: ControlsController, val context: Context) val am = AccountManager.get(context) val accounts = am.getAccountsByType("com.google") if (accounts == null || accounts.size == 0) { Log.w(TAG, "No com.google accounts found") Log.w(ControlsUiController.TAG, "No com.google accounts found") return null } Loading @@ -104,7 +102,7 @@ class TokenProviderConnection(val cc: ControlsController, val context: Context) try { return am.blockingGetAuthToken(account!!, SCOPE, true) } catch (e: Throwable) { Log.e(TAG, "Error getting auth token", e) Log.e(ControlsUiController.TAG, "Error getting auth token", e) return null } } Loading Loading @@ -146,7 +144,7 @@ class ControlsUiControllerImpl @Inject constructor ( } override fun show(parent: ViewGroup) { Log.d(TAG, "show()") Log.d(ControlsUiController.TAG, "show()") this.parent = parent Loading Loading @@ -218,7 +216,7 @@ class ControlsUiControllerImpl @Inject constructor ( val listView = parent.requireViewById(R.id.global_actions_controls_list) as ViewGroup var lastRow: ViewGroup = createRow(inflater, listView) controlInfos.forEach { Log.d(TAG, "favorited control id: " + it.controlId) Log.d(ControlsUiController.TAG, "favorited control id: " + it.controlId) if (lastRow.getChildCount() == 2) { lastRow = createRow(inflater, listView) } Loading @@ -240,7 +238,7 @@ class ControlsUiControllerImpl @Inject constructor ( } override fun hide() { Log.d(TAG, "hide()") Log.d(ControlsUiController.TAG, "hide()") controlsController.get().unsubscribe() context.unbindService(tokenProviderConnection) tokenProviderConnection = null Loading @@ -252,10 +250,10 @@ class ControlsUiControllerImpl @Inject constructor ( } override fun onRefreshState(componentName: ComponentName, controls: List<Control>) { Log.d(TAG, "onRefreshState()") Log.d(ControlsUiController.TAG, "onRefreshState()") controls.forEach { c -> controlsById.get(ControlKey(componentName, c.getControlId()))?.let { Log.d(TAG, "onRefreshState() for id: " + c.getControlId()) Log.d(ControlsUiController.TAG, "onRefreshState() for id: " + c.getControlId()) val cws = ControlWithState(it.ci, c) val key = ControlKey(componentName, c.getControlId()) controlsById.put(key, cws) Loading
packages/SystemUI/src/com/android/systemui/controls/ui/TemperatureControlBehavior.kt +2 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import android.service.controls.templates.TemperatureControlTemplate import android.widget.TextView import com.android.systemui.R import com.android.systemui.controls.ui.ControlActionCoordinator.MIN_LEVEL import com.android.systemui.controls.ui.ControlActionCoordinator.MAX_LEVEL class TemperatureControlBehavior : Behavior { lateinit var clipLayer: Drawable Loading