diff --git a/quickstep/res/layout/customizable_taskbar.xml b/quickstep/res/layout/customizable_taskbar.xml new file mode 100644 index 0000000000..e1a80aee30 --- /dev/null +++ b/quickstep/res/layout/customizable_taskbar.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/quickstep/res/layout/customizable_taskbar_view.xml b/quickstep/res/layout/customizable_taskbar_view.xml new file mode 100644 index 0000000000..f55e1d050d --- /dev/null +++ b/quickstep/res/layout/customizable_taskbar_view.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/quickstep/src/com/android/launcher3/taskbar/customization/CustomizableTaskbarView.kt b/quickstep/src/com/android/launcher3/taskbar/customization/CustomizableTaskbarView.kt new file mode 100644 index 0000000000..e384586b45 --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/customization/CustomizableTaskbarView.kt @@ -0,0 +1,40 @@ +/* + * 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. + } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/customization/TaskbarAllAppsButtonContainer.kt b/quickstep/src/com/android/launcher3/taskbar/customization/TaskbarAllAppsButtonContainer.kt new file mode 100644 index 0000000000..415a05156e --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/customization/TaskbarAllAppsButtonContainer.kt @@ -0,0 +1,97 @@ +/* + * 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 + } + } +}