首页 > 其他分享 >Android 10.0 Launcher3拖拽图标进入hotseat自适应布局功能实现四

Android 10.0 Launcher3拖拽图标进入hotseat自适应布局功能实现四

时间:2024-07-23 11:25:28浏览次数:12  
标签:10.0 int void import hotseat Android public 图标

1.前言

在10.0的系统rom定制化开发中,在对于launcher3的一些开发定制中,在对hotseat的一些开发中,需要实现动态hotseat居中
的功能,就是在拖拽图标进入和拖出hotseat,都可以保持hotseat居中的功能,接下来分析下相关功能实现
具体如图:

<iframe allowfullscreen="true" data-mediaembed="csdn" frameborder="0" id="OB7uMsFv-1721646344747" src="https://live.csdn.net/v/embed/410420"></iframe>

hotseat


2.Launcher3拖拽图标进入hotseat自适应布局功能实现四的核心类

packages\apps\Launcher3\src\com\android\launcher3\CellLayout.java
packages/apps/Launcher3/src/com/android/launcher3/BaseActivity.java

3.Launcher3拖拽图标进入hotseat自适应布局功能实现四的核心功能分析和实现

Launcher顾名思义,就是桌面的意思,也是android系统启动后第一个启动的应用程序,
:Launcher3负责管理和展示用户手机桌面上的各个应用程序图标。它通过GridView或者LinearLayout等布局管理器将
图标进行排列,并支持滑动、放大缩小等手势操作
Hotseat也是属于在导航栏底部的BubbleTextView的布局,只是不显示app图标
CellLayout:主屏幕中的每一页,其父布局就是Workspace,左右滑动屏幕,就是每一个CellLayout的变化过程,这个类中有很多处理拖拽相关方法

3.1 新增一部分关于处理拖拽图标重叠的工具类

在实现Launcher3拖拽图标进入hotseat自适应布局功能实现四中,通过分析得知,在进行
一些拖拽的过程中,在只有两个三个hotseat的时候,这时候会出现hotseat重叠的问题,这时候就需要先清除掉hotseat的所有view,然后添加hotseat,

package com.android.launcher3.util;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.database.sqlite.SQLiteDatabase;
import android.os.UserHandle;

import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.model.data.AppInfo;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class LauncherAppMonitorCallback {
    //Launcher activity Callbacks
    public void onLauncherPreCreate(Launcher launcher) { }

    public void onLauncherCreated() { }

    public void onLauncherPreResume() { }

    public void onLauncherResumed() { }

    public void onLauncherStart() { }

    public void onLauncherStop() { }

    public void onLauncherPrePaused() { }

    public void onLauncherPaused() { }

    public void onLauncherDestroy() { }

    public void onLauncherRequestPermissionsResult(int requestCode, String[] permissions,
                                                   int[] grantResults) { }

    public void onSettingsActivityRequestPermissionsResult(int requestCode, String[] permissions,
                                                   int[] grantResults) { }

    public void onLauncherFocusChanged(boolean hasFocus) { }

    public void onQuickstepLauncherStart() { }

    public void onRecentsActivityCreate(BaseDraggingActivity activity) { }

    public void onRecentsActivityStart() { }

    public void onHomeIntent() { }

    public void onBindingWorkspaceFinish () { }

    public void onBindingAllAppFinish (AppInfo[] apps) { }

    //Launcher app Callbacks
    public void onAppCreated(Context context) { }

    public void onReceive(Intent intent) { }

    public void onUIConfigChanged() { }

    public void onThemeChanged() { }

    public void onGridChanged() { }
    public void onDbUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }

    public void onStateSetStart(LauncherState toState) { }

    public void onStateSetEnd(LauncherState toState) { }

    public void onTaskStackUpdated(boolean hasTask) { }

    public void onOrientationStateChanged() { }
    public void onAppSharedPreferenceChanged(String key) { }

    public void onPackageRemoved(String packageName, UserHandle user) { }

    public void onPackageAdded(String packageName, UserHandle user) { }

    public void onPackageChanged(String packageName, UserHandle user) { }

    public void onPackagesAvailable(String[] packageNames, UserHandle user, boolean replacing) { }

    public void onPackagesUnavailable(String[] packageNames, UserHandle user, boolean replacing) { }

    public void onPackagesSuspended(String[] packageNames, UserHandle user) { }

    public void onPackagesUnsuspended(String[] packageNames, UserHandle user) { }

    public void onPackagesUpdated(String[] packageNames, UserHandle user, int op) { }

    public void onShortcutsChanged(String packageName, List<ShortcutInfo> shortcuts, UserHandle user) { }

    public void onAllAppsListUpdated(List<AppInfo> apps) { }

    public void onLauncherLocaleChanged() { }

    public void onLauncherOrientationChanged () { }

    public void onLauncherScreensizeChanged() { }

    public void onl oadAllAppsEnd(ArrayList<AppInfo> apps) { }

    public void onHomeStyleChanged(String style) { }

    //Launcher database callbacks

    public void dump(String prefix, FileDescriptor fd, PrintWriter w, boolean dumpAll) { }
}

在实现Launcher3拖拽图标进入hotseat自适应布局功能实现四中,通过分析得知,
新增的uitl下的LauncherAppMonitorCallback.java中的相关源码中,这里主要就是处理
在Launcher3中关于绑定hotseat的一些事件回调,在这里主要就是Launcher3中关于hotseat的
一些回调事件,作为辅助类的存在

3.2 BaseActivity.java中关于初始化LauncherAppMonitor的一些相关操作

在实现Launcher3拖拽图标进入hotseat自适应布局功能实现四中,通过分析得知,
BaseActivity.java中的相关源码分析得知,在这里只是作为Activity的基类来实现某些功能的
所以这里来具体初始化相关功能实现

//add core start
import com.android.launcher3.util.LauncherAppMonitor;
//add core end

public abstract class BaseActivity extends Activity implements ActivityContext {
//add core start
    protected LauncherAppMonitor mAppMonitor;
    public LauncherAppMonitor getAppMonitor() {
        if (mAppMonitor == null) {
            mAppMonitor = LauncherAppMonitor.getInstance(this);
        }
        return mAppMonitor;
    }
//add core end

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
//add core start
        getAppMonitor().onLauncherFocusChanged(hasFocus);
//add core end
        if (hasFocus) {
            addActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
        } else {
            removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
        }
    }

在实现Launcher3拖拽图标进入hotseat自适应布局功能实现四中,通过分析得知,
BaseActivity.java中的相关源码分析得知,在这里初始化了 关于LauncherAppMonitor的
相关功能,主要是在onWindowFocusChanged(boolean hasFocus) 中添加了
getAppMonitor().onLauncherFocusChanged(hasFocus);来表示窗口焦点发生变化的
功能

3.3 CellLayout.java中关于hotseat布局的一些修改功能

在实现Launcher3拖拽图标进入hotseat自适应布局功能实现四中,通过分析得知,
CellLayout.java中主屏幕中的每一页关于每个app图标hotseat widget的布局绑定
布局,接下来看下具体的功能实现

      *
      * @param result Array of 2 ints to hold the x and y coordinate of the point
      */
-    void cellToCenterPoint(int cellX, int cellY, int[] result) {
+    public void cellToCenterPoint(int cellX, int cellY, int[] result) {
         regionToCenterPoint(cellX, cellY, 1, 1, result);
     }

     public static final class CellInfo extends CellAndSpan {
         public final View cell;
         final int screenId;
-        final int container;
+        public final int container;

在实现Launcher3拖拽图标进入hotseat自适应布局功能实现四中,通过分析得知,
CellLayout.java中的主要功能就是实现关于void cellToCenterPoint(int cellX, int cellY, int[] result)
公有化的调用这个设置CellLayout的中心点,和container参数的调用功能

标签:10.0,int,void,import,hotseat,Android,public,图标
From: https://blog.csdn.net/baidu_41666295/article/details/140617449

相关文章

  • 深入分析 Android ContentProvider (二)
    文章目录深入分析AndroidContentProvider(二)1.高级特性和常见使用场景1.1.使用ContentObserver监听数据变化示例:实现ContentObserver1.2.数据同步示例:实现SyncAdapter1.3.批量操作示例:批量操作1.4.权限控制示例:声明权限2.ContentProvider的设计总结......
  • Android开发 - LayoutParams解析
    LayoutParams翻译过来就是布局参数,子View通过LayoutParams告诉父容器(ViewGroup)应该如何放置自己。从这个定义中也可以看出来LayoutParams与ViewGroup是息息相关的,因此脱离ViewGroup谈LayoutParams是没有意义的。事实上,每个ViewGroup的子类都有自己对应的LayoutParams类,典型的如L......
  • android audio不同音频流,(六)settings内音频流音量调整
    (1)settings内,可设置音频流音量,如下图:(2)settings调整音量条进度,会触发SeekBarVolumizer对象:SeekBarVolumizer文件路径:frameworks/base/core/java/android/preference/SeekBarVolumizer.javaSeekBarVolumizer对象,handle会接到MSG_SET_STREAM_VOLUME事件:publicbooleanhandl......
  • android在一个TextView中设置不同字体大小、不同字体颜色封装
    一、概述在开发过程中遇到过这样一种业务,有很多单行文本字体。字符串中每一部分的字体样式、大小、颜色都不相同。传统的做法是放多个TextView以达到效果。但是当这个页面中的这样的元素非常多,且非常复杂的时候,就会出现页面加载缓慢的问题(view加载=深度(递归)+平铺),也就是......
  • Android开发 - Context解析
    Context是什么Context的中文翻译为:语境;上下文;背景;环境,在开发中我们经常说称之为“上下文”,那么这个“上下文”到底是指什么意思呢?在语文中,我们可以理解为语境,在程序中,我们可以理解为当前对象在程序中所处的一个环境,一个与系统交互的过程。比如微信聊天,此时的“环境”是指......
  • Android开发 - Bundle传值的理解与使用
    什么是BundleBundle经常出现在以下场合:Activity状态数据的保存与恢复涉及到的两个回调:voidonSaveInstanceState(BundleoutState)voidonCreate(BundlesavedInstanceState)Fragment的setArguments方法:voidsetArguments(Bundleargs)消息机制中的Message的setData......
  • Android 常见面试题(一)
    Android常见面试题(一)1、java中==和equals和hashCode的区别基本数据类型的==比较的值相等.类的==比较的内存的地址,即是否是同一个对象。在不重写equals方法的情况下,equals同比较内存地址,原实现也为==,如String等重写了equals方法,会判断字符串里的值是否相等......
  • Android4.4.4双声卡同时出声
    在调试RK3288Android4.4.4,该方案默认配置上SPDIF时HDMI就没声音,但客户需求是同时要有声音的,于是驱动配置上后,呈现两个声卡状态,此时需要通过修改HAL层来处理(RK3288Android4.4.4对应的HAL层源码为hardware/rk29/audio目录),修改如下:1.修改AudioHardware.cpp文件,在AudioHardware:......
  • Android或iOS 与 REST/SOAP测试 工具推荐
    移动测试工具- 有助于自动测试Android或iOS应用程序1)AppiumAppium是用于移动应用程序自动化的开源测试工具之一。它允许用户测试各种原生、移动、web和混合应用程序。它还支持模拟器和模拟器上的自动测试。功能特点:这是一个简单的应用程序,需要很少的内存用于测试过程......
  • Android笔试面试题AI答之控件Views(3)
    答案仅供参考,来自文心一言目录1.如何在ListView间添加分割线?方法1:在XML布局文件中设置方法2:在Java代码中设置注意事项2.如何实现ListView的逐行显示?1.使用`Handler`和`postDelayed()`方法2.监听滚动事件3.自定义Adapter4.使用`RecyclerView`代替`ListVie......