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

Commit b0e0e006 authored by Jagrut Desai's avatar Jagrut Desai Committed by Android (Google) Code Review
Browse files

Merge "Adding Skeleton Code for Customizable Taksbar" into main

parents c9174e17 dafd7f55
Loading
Loading
Loading
Loading
+121 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2024 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.
-->
<com.android.launcher3.taskbar.TaskbarDragLayer
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/taskbar_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clipChildren="false">

    <!-- TODO(b/349885828) : to be removed in future cl. -->
    <com.android.launcher3.taskbar.TaskbarView
        android:id="@+id/taskbar_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:focusable="true"
        android:importantForAccessibility="yes"
        android:forceHasOverlappingRendering="false"
        android:layout_gravity="bottom"
        android:layout_marginBottom="@dimen/transient_taskbar_bottom_margin"
        android:clipChildren="false" />

    <com.android.launcher3.taskbar.customization.CustomizableTaskbarView
        android:id="@+id/customizable_taskbar_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:focusable="true"
        android:importantForAccessibility="yes"
        android:forceHasOverlappingRendering="false"
        android:layout_gravity="bottom"
        android:layout_marginBottom="@dimen/transient_taskbar_bottom_margin"
        android:clipChildren="false" />

    <com.android.launcher3.taskbar.TaskbarScrimView
        android:id="@+id/taskbar_scrim"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <com.android.launcher3.taskbar.bubbles.BubbleBarView
        android:id="@+id/taskbar_bubbles"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/bubblebar_size_with_pointer"
        android:layout_gravity="bottom|end"
        android:layout_marginHorizontal="@dimen/transient_taskbar_bottom_margin"
        android:paddingTop="@dimen/bubblebar_pointer_visible_size"
        android:paddingEnd="@dimen/taskbar_icon_spacing"
        android:paddingStart="@dimen/taskbar_icon_spacing"
        android:visibility="gone"
        android:gravity="center"
        android:clipChildren="false"
        android:elevation="@dimen/bubblebar_elevation"
        />

    <com.android.launcher3.taskbar.navbutton.NearestTouchFrame
        android:id="@+id/navbuttons_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom" >

        <FrameLayout
            android:id="@+id/start_contextual_buttons"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingStart="@dimen/taskbar_contextual_button_padding"
            android:paddingEnd="@dimen/taskbar_contextual_button_padding"
            android:paddingTop="@dimen/taskbar_contextual_padding_top"
            android:gravity="center_vertical"
            android:layout_gravity="start"/>

        <LinearLayout
            android:id="@+id/end_nav_buttons"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:layout_gravity="end"/>

        <FrameLayout
            android:id="@+id/end_contextual_buttons"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingTop="@dimen/taskbar_contextual_padding_top"
            android:gravity="center_vertical"
            android:layout_gravity="end"/>
    </com.android.launcher3.taskbar.navbutton.NearestTouchFrame>

    <com.android.launcher3.taskbar.StashedHandleView
        android:id="@+id/stashed_handle"
        tools:comment1="The actual size and shape will be set as a ViewOutlineProvider at runtime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/taskbar_stashed_handle_dark_color"
        android:clipToOutline="true"
        android:layout_gravity="bottom"/>

    <com.android.launcher3.taskbar.StashedHandleView
        android:id="@+id/stashed_bubble_handle"
        tools:comment1="The actual size and shape will be set as a ViewOutlineProvider at runtime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:background="@color/taskbar_stashed_handle_dark_color"
        android:clipToOutline="true"
        android:layout_gravity="bottom"/>

</com.android.launcher3.taskbar.TaskbarDragLayer>
 No newline at end of file
+56 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2024 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.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.android.launcher3.taskbar.customization.TaskbarAllAppsButtonContainer
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@id/guideline1"/>

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.1" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.5" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.7" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.9" />

</androidx.constraintlayout.widget.ConstraintLayout>
 No newline at end of file
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.launcher3.taskbar.customization

import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import androidx.constraintlayout.widget.ConstraintLayout
import com.android.launcher3.Insettable
import com.android.launcher3.R
import com.android.launcher3.taskbar.TaskbarActivityContext
import com.android.launcher3.views.ActivityContext

/** TaskbarView that is customizeable via Taskbar containers. */
class CustomizableTaskbarView(context: Context, attrs: AttributeSet? = null) :
    ConstraintLayout(context, attrs), Insettable {
    private val activityContext: TaskbarActivityContext = ActivityContext.lookupContext(context)

    init {
        inflate(context, R.layout.customizable_taskbar_view, this)
    }

    override fun setInsets(insets: Rect?) {
        // Ignore, we just implement Insettable to draw behind system insets.
    }
}
+97 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.launcher3.taskbar.customization

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.annotation.DimenRes
import androidx.annotation.DrawableRes
import androidx.core.view.setPadding
import com.android.launcher3.R
import com.android.launcher3.Utilities.dpToPx
import com.android.launcher3.config.FeatureFlags
import com.android.launcher3.taskbar.TaskbarActivityContext
import com.android.launcher3.views.ActivityContext
import com.android.launcher3.views.IconButtonView

/** Taskbar all apps button container for customizable taskbar. */
class TaskbarAllAppsButtonContainer
@JvmOverloads
constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
) : LinearLayout(context, attrs), TaskbarContainer {

    private val allAppsButton: IconButtonView =
        LayoutInflater.from(context).inflate(R.layout.taskbar_all_apps_button, this, false)
            as IconButtonView
    private val activityContext: TaskbarActivityContext = ActivityContext.lookupContext(context)

    override val spaceNeeded: Int
        get() {
            return dpToPx(activityContext.taskbarSpecsEvaluator.taskbarIconSize.size.toFloat())
        }

    init {
        setUpIcon()
    }

    @SuppressLint("UseCompatLoadingForDrawables", "ResourceAsColor")
    private fun setUpIcon() {
        val drawable =
            resources.getDrawable(
                getAllAppsButton(activityContext.taskbarFeatureEvaluator.isTransient)
            )
        val padding = activityContext.taskbarSpecsEvaluator.taskbarIconPadding

        allAppsButton.setIconDrawable(drawable)
        allAppsButton.setPadding(/* left= */ padding)
        allAppsButton.setForegroundTint(activityContext.getColor(R.color.all_apps_button_color))

        // TODO(jagrutdesai) : add click listeners in future cl
        addView(allAppsButton)
    }

    @DrawableRes
    private fun getAllAppsButton(isTransientTaskbar: Boolean): Int {
        val shouldSelectTransientIcon =
            isTransientTaskbar ||
                (FeatureFlags.enableTaskbarPinning() && !activityContext.isThreeButtonNav)
        return if (FeatureFlags.ENABLE_ALL_APPS_SEARCH_IN_TASKBAR.get()) {
            if (shouldSelectTransientIcon) R.drawable.ic_transient_taskbar_all_apps_search_button
            else R.drawable.ic_taskbar_all_apps_search_button
        } else {
            if (shouldSelectTransientIcon) R.drawable.ic_transient_taskbar_all_apps_button
            else R.drawable.ic_taskbar_all_apps_button
        }
    }

    @DimenRes
    fun getAllAppsButtonTranslationXOffset(isTransientTaskbar: Boolean): Int {
        return if (isTransientTaskbar) {
            R.dimen.transient_taskbar_all_apps_button_translation_x_offset
        } else if (FeatureFlags.ENABLE_ALL_APPS_SEARCH_IN_TASKBAR.get()) {
            R.dimen.taskbar_all_apps_search_button_translation_x_offset
        } else {
            R.dimen.taskbar_all_apps_button_translation_x_offset
        }
    }
}