2021-04-16 12:50:22 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2021 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;
|
|
|
|
|
|
2021-05-05 14:04:11 -07:00
|
|
|
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_BACK;
|
|
|
|
|
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_HOME;
|
|
|
|
|
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_IME_SWITCH;
|
|
|
|
|
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_RECENTS;
|
|
|
|
|
|
2021-04-16 12:50:22 -07:00
|
|
|
import android.annotation.DrawableRes;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.R;
|
2021-05-05 14:04:11 -07:00
|
|
|
import com.android.launcher3.taskbar.TaskbarNavButtonController.TaskbarButton;
|
2021-04-16 12:50:22 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates Buttons for Taskbar for 3 button nav.
|
|
|
|
|
* Can add animations and state management for buttons in this class as things progress.
|
|
|
|
|
*/
|
|
|
|
|
public class ButtonProvider {
|
|
|
|
|
|
2021-05-05 14:04:11 -07:00
|
|
|
private final int mMarginLeftRight;
|
|
|
|
|
private final TaskbarActivityContext mContext;
|
2021-04-16 12:50:22 -07:00
|
|
|
|
2021-05-05 14:04:11 -07:00
|
|
|
public ButtonProvider(TaskbarActivityContext context) {
|
2021-04-16 12:50:22 -07:00
|
|
|
mContext = context;
|
2021-05-05 14:04:11 -07:00
|
|
|
mMarginLeftRight = context.getResources()
|
|
|
|
|
.getDimensionPixelSize(R.dimen.taskbar_icon_spacing);
|
2021-04-16 12:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public View getBack() {
|
|
|
|
|
// Back button
|
2021-05-05 14:04:11 -07:00
|
|
|
return getButtonForDrawable(R.drawable.ic_sysbar_back, BUTTON_BACK);
|
2021-04-16 12:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public View getDown() {
|
|
|
|
|
// Ime down button
|
2021-05-05 14:04:11 -07:00
|
|
|
return getButtonForDrawable(R.drawable.ic_sysbar_back, BUTTON_BACK);
|
2021-04-16 12:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public View getHome() {
|
|
|
|
|
// Home button
|
2021-05-05 14:04:11 -07:00
|
|
|
return getButtonForDrawable(R.drawable.ic_sysbar_home, BUTTON_HOME);
|
2021-04-16 12:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public View getRecents() {
|
|
|
|
|
// Recents button
|
2021-05-05 14:04:11 -07:00
|
|
|
return getButtonForDrawable(R.drawable.ic_sysbar_recent, BUTTON_RECENTS);
|
2021-04-16 12:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public View getImeSwitcher() {
|
|
|
|
|
// IME Switcher Button
|
2021-05-05 14:04:11 -07:00
|
|
|
return getButtonForDrawable(R.drawable.ic_ime_switcher, BUTTON_IME_SWITCH);
|
2021-04-16 12:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-05 14:04:11 -07:00
|
|
|
private View getButtonForDrawable(@DrawableRes int drawableId, @TaskbarButton int buttonType) {
|
2021-04-16 12:50:22 -07:00
|
|
|
ImageView buttonView = new ImageView(mContext);
|
|
|
|
|
buttonView.setImageResource(drawableId);
|
|
|
|
|
buttonView.setBackgroundResource(R.drawable.taskbar_icon_click_feedback_roundrect);
|
|
|
|
|
buttonView.setPadding(mMarginLeftRight, 0, mMarginLeftRight, 0);
|
2021-05-05 14:04:11 -07:00
|
|
|
buttonView.setOnClickListener(view -> mContext.onNavigationButtonClick(buttonType));
|
2021-04-16 12:50:22 -07:00
|
|
|
return buttonView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|