Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 307b1ef7 authored by Matt Pietal's avatar Matt Pietal
Browse files

Controls UI - Update drag behavior for ranges

Consolidate toggle() fns. Update range handling. It was previously
acting like a slider but now detects the diff between how far you
swiped and updates the current value appropriately.

Bug: 148207527
Test: manual testing of drag behavior
Change-Id: I85896527bd3ff225cd08d11fbe2e4b34190a6b5a
parent 20024529
Loading
Loading
Loading
Loading
+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")
            }
        }
    }
}
+15 −17
Original line number Diff line number Diff line
@@ -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
@@ -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(
@@ -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
            })
        }
@@ -100,6 +94,11 @@ class ControlViewHolder(
        }

        if (!text.isEmpty()) {
            setTransientStatus(text)
        }
    }

    fun setTransientStatus(tempStatus: String) {
        val previousText = status.getText()
        val previousTextExtra = statusExtra.getText()

@@ -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)
+4 −0
Original line number Diff line number Diff line
@@ -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>)
+9 −11
Original line number Diff line number Diff line
@@ -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
@@ -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()
@@ -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
        }

@@ -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
        }
    }
@@ -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

@@ -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)
            }
@@ -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
@@ -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)
+2 −0
Original line number Diff line number Diff line
@@ -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