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

Commit 337e17bc authored by Ben Lin's avatar Ben Lin Committed by Android (Google) Code Review
Browse files

Merge "Block further onClick / onDoubleTap calls after a single tap on buttons." into main

parents c8b33cc1 11dd1894
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.wm.shell.windowdecor.extension

import android.view.View

/**
 * Throttles clicking on the view - if a view gets a click/tap within the delay given, then the
 * click is dropped.
 */
fun View.throttleFirstClicks(delay: Long, onClick: (View) -> Unit) {
    setOnClickListener {
        onClick(this)
        isClickable = false
        postDelayed({ isClickable = true }, delay)
    }
}
+11 −3
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import com.android.wm.shell.windowdecor.common.createBackgroundDrawable
import com.android.wm.shell.windowdecor.extension.identityHashCode
import com.android.wm.shell.windowdecor.extension.isLightCaptionBarAppearance
import com.android.wm.shell.windowdecor.extension.isTransparentCaptionBarAppearance
import com.android.wm.shell.windowdecor.extension.throttleFirstClicks
import com.android.wm.shell.windowdecor.viewholder.util.AppHeaderDimensions
import com.android.wm.shell.windowdecor.viewholder.util.DefaultAppHeaderDimensions
import com.android.wm.shell.windowdecor.viewholder.util.LargeAppHeaderDimensions
@@ -166,13 +167,19 @@ class AppHeaderViewHolder(
        captionHandle.setOnTouchListener(onCaptionTouchListener)
        openMenuButton.setOnClickListener(onCaptionButtonClickListener)
        openMenuButton.setOnTouchListener(onCaptionTouchListener)
        closeWindowButton.setOnClickListener(onCaptionButtonClickListener)
        maximizeWindowButton.setOnClickListener(onCaptionButtonClickListener)
        closeWindowButton.throttleFirstClicks(CLICK_DELAY) { v ->
            onCaptionButtonClickListener.onClick(v)
        }
        maximizeWindowButton.throttleFirstClicks(CLICK_DELAY) { v ->
            onCaptionButtonClickListener.onClick(v)
        }
        maximizeWindowButton.setOnTouchListener(onCaptionTouchListener)
        maximizeWindowButton.setOnGenericMotionListener(onCaptionGenericMotionListener)
        maximizeWindowButton.onLongClickListener = onLongClickListener
        closeWindowButton.setOnTouchListener(onCaptionTouchListener)
        minimizeWindowButton.setOnClickListener(onCaptionButtonClickListener)
        minimizeWindowButton.throttleFirstClicks(CLICK_DELAY) { v ->
            onCaptionButtonClickListener.onClick(v)
        }
        minimizeWindowButton.setOnTouchListener(onCaptionTouchListener)
        maximizeButtonView.onHoverAnimationFinishedListener =
            onMaximizeHoverAnimationFinishedListener
@@ -982,6 +989,7 @@ class AppHeaderViewHolder(
        private const val DARK_THEME_UNFOCUSED_OPACITY = 140 // 55%
        private const val LIGHT_THEME_UNFOCUSED_OPACITY = 166 // 65%
        private const val FOCUSED_OPACITY = 255
        private const val CLICK_DELAY: Long = 500
    }

    class Factory {