当前位置: 首页 > article >正文

MTK Android12 最近历史任务 最左侧的清除历史任务改到页面底部

Android最近历史任务页面 -清除所有- 功能按钮放到底部

文章目录

  • 需求
    • 需求原因
  • 修改的核心文件
  • 实现方案
    • 最近历史任务基本UI结构了解
    • 代码实现
      • 思路
      • 实现方案
        • RecentsView
        • TaskOverlayFactory
        • 在overview_actions_container
        • OverviewActionsView
      • 实际效果
  • 总结


需求

最近历史任务重,全部清除按钮迁移到页面底部,常显。

需求原因

  • 其实很多客户都有反馈过,或者我们自己在使用自己手机时候,最近历史任务界面比较多的时候,右滑到最左边才会出现全部清除按钮,使用不方便,
    需要放到下边常显。

如下界面所示,修改之前:

在这里插入图片描述

修改的核心文件

\vendor\mediatek\proprietary\packages\apps\Launcher3\quickstep\src\com\android\quickstep\TaskOverlayFactory.java
\vendor\mediatek\proprietary\packages\apps\Launcher3\quickstep\src\com\android\quickstep\views\OverviewActionsView.java
\vendor\mediatek\proprietary\packages\apps\Launcher3\quickstep\src\com\android\quickstep\views\RecentsView.java
\vendor\mediatek\proprietary\packages\apps\Launcher3\quickstep\res\layout\overview_actions_container.xml

#参考资料

  • 网上很多参考资料参考,思路永远一致,但是不同芯片平台,相同平台不同安卓版本 还是有一些区别的,根据自己实际环境,调试。

比如:在Android11之前最近历史任务在SystemUI中,在Android11 版本及之后,最近历史任务已经转移到了Launcher 里面了。

  • 这里只是给一个思路,我自己在RKAndroid11 和 Rk Android12 上面都实践过,思路一致,修改点少许改动,即可实现。

SystemUI 调整Recents中全部清除按钮位置

Android 11.0 最近任务的全部清除由左边移到下边显示

Android 13.0 Launcher3定制化之最近任务的全部清除由左边移到下边显示

实现方案

最近历史任务基本UI结构了解

源文件说明
TaskOverlayFactoryFactory class to create and add an overlays on the TaskView 创建和添加UI 覆盖在TaskView
OverviewActionsViewView for showing action buttons in Overview 在UI上展示覆盖的按钮
RecentsViewA list of recent tasks. 最近历史任务列表
overview_actions_containerOverviewActionsView 的布局

下面以RK 产品最近历史任务作为基本说明,上面的机器显示的最近历史任务界面中 下方的OverView 层 实际开发需求影藏起来了,不利于说明UI结构。
在这里插入图片描述

代码实现

思路

  • 上面的UI结构图和列举的UI关联类说明,这里给一下 实现思路
  • 将最近历史任务列表里面的清除所有按钮 永久影藏
  • 在TaskOverlayFactory 和 OverviewActionsView 中添加UI和功能实现
  • 在布局overview_actions_container 中 添加删除功能按钮

实现方案

RecentsView
  1. 一直影藏 全部清除按钮
    在RecentsView 构造方法中,设置清除所有按钮mClearAllButton INVISIBLE
	mClearAllButton.setVisibility(View.INVISIBLE);   //隐藏左侧的“全部清除”按钮
 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr,
            BaseActivityInterface sizeStrategy) {
        super(context, attrs, defStyleAttr);
    。。。。。。。。。。。。。。。
        mClearAllButton.setOnClickListener(this::dismissAllTasks);
		mClearAllButton.setVisibility(View.INVISIBLE);   //隐藏左侧的“全部清除”按钮
    。。。。。。。。。。
    }
  1. isClearAllHidden 是否隐藏的判断,直接设置为true
  /**
     * Whether the Clear All button is hidden or fully visible. Used to determine if center
     * displayed page is a task or the Clear All button.
     *
     * @return True = Clear All button not fully visible, center page is a task. False = Clear All
     * button fully visible, center page is Clear All button.
     */
    public boolean isClearAllHidden() {
        //return mClearAllButton.getAlpha() != 1f;
		Log.d(TAG, " isClearAllHidden.. return true");

		return true;
    }
TaskOverlayFactory

1) OverlayUICallbacks 内部接口中添加清除所有的接口方法 clearAllRecentTask()

这里本身定义的有 分享onShare 、 截屏 onScreenshot 的功能按钮

 /**
     * Callbacks the Ui can generate. This is the only way for a Ui to call methods on the
     * controller.
     */
    public interface OverlayUICallbacks {
        /** User has indicated they want to share the current task. */
        void onShare();

        /** User has indicated they want to screenshot the current task. */
        void onScreenshot();
		void clearAllRecentTask();
    }

2) OverlayUICallbacksImpl 实现上述接口OverlayUICallbacks中的clearAllRecentTask 方法 clearAllRecentTask,定义清除所有的功能

protected class OverlayUICallbacksImpl implements OverlayUICallbacks {
            protected final boolean mIsAllowedByPolicy;
            protected final Task mTask;

            public OverlayUICallbacksImpl(boolean isAllowedByPolicy, Task task) {
                mIsAllowedByPolicy = isAllowedByPolicy;
                mTask = task;
            }

            public void onShare() {
                if (mIsAllowedByPolicy) {
                    endLiveTileMode(() -> mImageApi.startShareActivity(null));
                } else {
                    showBlockedByPolicyMessage();
                }
            }

            @SuppressLint("NewApi")
            public void onScreenshot() {
                endLiveTileMode(() -> saveScreenshot(mTask));
            }
			 @Override
             public void clearAllRecentTask() {
			   Log.d(TAG, " clearAllRecentTask...");
               mThumbnailView.getTaskView().getRecentsView().dismissAllTasks(mThumbnailView.getTaskView().getRecentsView());
            }
        }
在overview_actions_container

布局文件中添加 UI布局 的UI按钮

        <Button
            android:id="@+id/recents_clear_all_btn"
            style="@style/OverviewActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/ic_screenshot"
            android:text="@string/recents_clear_all"
            android:theme="@style/ThemeControlHighlightWorkspaceColor"
            />

OverviewActionsView

加载布局,给布局设置接口回调和点击功能
1) onFinishInflate 方法周公加载 布局文件的UI按钮 并设置监按钮点击监听事件

findViewById(R.id.recents_clear_all_btn).setOnClickListener(this);
 @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        View share = findViewById(R.id.action_share);
        share.setOnClickListener(this);
        findViewById(R.id.action_screenshot).setOnClickListener(this);
		findViewById(R.id.recents_clear_all_btn).setOnClickListener(this);
         if (ENABLE_OVERVIEW_SHARE.get()) {
            share.setVisibility(VISIBLE);
            findViewById(R.id.oav_three_button_space).setVisibility(VISIBLE);
        }
    }

2) onClick 中回调 view 点击事件,然后回调接口事件 mCallbacks.clearAllRecentTask();


    @Override
    public void onClick(View view) {
        if (mCallbacks == null) {
			Log.d(TAG, " mCallbacks == null...");
            return;
        }
        int id = view.getId();
        if (id == R.id.action_share) {
            mCallbacks.onShare();
        } else if (id == R.id.action_screenshot) {
            mCallbacks.onScreenshot();
        } else if (id == R.id.recents_clear_all_btn) {
			  Log.d(TAG, "onClick recents_clear_all_btn...");
              mCallbacks.clearAllRecentTask();
        }
    }

3) updateDisabledFlags 更新,永为true

LayoutUtils.setViewEnabled(this, true);
  /**
     * Updates the proper disabled flag to indicate whether OverviewActionsView should be enabled.
     * Ignores DISABLED_ROTATED flag for determining enabled. Flag is used to enable/disable
     * buttons individually, currently done for select button in subclass.
     *
     * @param disabledFlags The flag to update.
     * @param enable        Whether to enable the disable flag: True will cause view to be disabled.
     */
    public void updateDisabledFlags(@ActionsDisabledFlags int disabledFlags, boolean enable) {
        if (enable) {
            mDisabledFlags |= disabledFlags;
        } else {
            mDisabledFlags &= ~disabledFlags;
        }
        //
        boolean isEnabled = (mDisabledFlags & ~DISABLED_ROTATED) == 0;
        //LayoutUtils.setViewEnabled(this, isEnabled);
		Log.d(TAG, " updateDisabledFlags...");
		LayoutUtils.setViewEnabled(this, true);
    }

实际效果

在这里插入图片描述

总结

  • 简单实现了全部清除功能 放到页面下方
  • 熟悉最近历史任务的基本功能,基本结构,基本框架
  • 其它最近历史任务功能 待 研究

http://www.kler.cn/a/585263.html

相关文章:

  • SAP IBP for Supply Chain Certification Guide (Parag Bakde, Rishabh Gupta)
  • Go语言入门基础详解
  • 深入浅出消息队列 (MQ)
  • 提升开发效率的FPGA/IC小工具
  • CSS3学习教程,从入门到精通,CSS3 选择器语法知识点及案例代码(3)
  • 区块链技术与 DICT(数字化信息与通信技术)的结合
  • 江苏无锡一家汽车零部件企业终止,拓展氢燃料电池存不确定性
  • 网易爆米花 1.8.2| 免费无广告,智能刮削,聚合6大网盘,全端无缝看片
  • ArcGIS助力水文分析:数据处理、地图制作与流域特征提取
  • uni-app打包h5并部署到nginx,路由模式history
  • QKV矩阵:优维大模型自注意力机制的数学之美
  • TCP 采用三次握手建立连接的原因
  • 30天学习Java第六天——Object类
  • C++ const 使用
  • Android源码学习之Overlay
  • 实现手机手势签字功能
  • 在线教育网站项目第四步 :学习Vue3 + Nuxt3+springcloud,服务器为ubuntu24.04
  • 日志Python安全之SSTI——Flask/Jinja2
  • go中实现子模块调用main包中函数的方法
  • 外星人入侵-Python-二