在Launcher的主菜单中隐藏某个应用removePackage

在package/apps/Launcher3/src/com/android/launcher3/LauncherModel.java中的private void loadAllApps() {}函数中的mBgAllAppsList.reorderApplist();之前添加如下:

     // ZJ Add START
               mBgAllAppsList.removePackage("com.mediatek.filemanager");
               mBgAllAppsList.removePackage("com.android.chrome");
               mBgAllAppsList.removePackage("com.android.providers.downloads.ui");
               mBgAllAppsList.removePackage("com.android.deskclock");
               mBgAllAppsList.removePackage("com.android.email");
               mBgAllAppsList.removePackage("com.google.android.apps.maps");
               mBgAllAppsList.removePackage("com.google.android.gm");
               mBgAllAppsList.removePackage("com.android.soundrecorder");
               mBgAllAppsList.removePackage("com.mediatek.FMRadio");
               mBgAllAppsList.removePackage("com.google.android.inputmethod.korean");
               //  ZJ Add END

            mBgAllAppsList.reorderApplist();

mBgAllAppList是类AllAppList的对象,可以看下AllAppList这个类的内容:

/*
* Copyright (C) 2008 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;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Xml;

import com.android.internal.util.XmlUtils;
import com.android.launcher3.R;

import com.mediatek.launcher3.ext.LauncherLog;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/**
* Stores the list of all applications for the all apps view.
*/
class AllAppsList {
    private static final String TAG = "AllAppsList";

    /// M: add for top packages.
    private static final String TAG_TOPPACKAGES = "toppackages";
    private static final String WIFI_SETTINGPKGNAME = "com.android.settings";
    private static final String WIFI_SETTINGCLASSNAME = "com.android.settings.Settings$WifiSettingsActivity";

    private static final boolean DEBUG_LOADERS_REORDER = false;
    public static final int DEFAULT_APPLICATIONS_NUMBER = 42;

    /** The list off all apps. */
    public ArrayList<AppInfo> data =
            new ArrayList<AppInfo>(DEFAULT_APPLICATIONS_NUMBER);
    /** The list of apps that have been added since the last notify() call. */
    public ArrayList<AppInfo> added =
            new ArrayList<AppInfo>(DEFAULT_APPLICATIONS_NUMBER);
    /** The list of apps that have been removed since the last notify() call. */
    public ArrayList<AppInfo> removed = new ArrayList<AppInfo>();
    /** The list of apps that have been modified since the last notify() call. */
    public ArrayList<AppInfo> modified = new ArrayList<AppInfo>();

    private IconCache mIconCache;

    private AppFilter mAppFilter;

    /// M: add for top packages.
    static ArrayList<TopPackage> sTopPackages = null;

    static class TopPackage {
        public TopPackage(String pkgName, String clsName, int index) {
            packageName = pkgName;
            className = clsName;
            order = index;
        }

        String packageName;
        String className;
        int order;
    }

    /**
     * Boring constructor.
     */
    public AllAppsList(IconCache iconCache, AppFilter appFilter) {
        mIconCache = iconCache;
        mAppFilter = appFilter;
    }

    /**
     * Add the supplied ApplicationInfo objects to the list, and enqueue it into the
     * list to broadcast when notify() is called.
     *
     * If the app is already in the list, doesn't add it.
     */
    public void add(AppInfo info) {
        if (LauncherLog.DEBUG) {
            LauncherLog.d(TAG, "Add application in app list: app = " + info.componentName
                    + ", title = " + info.title);
        }

        if (mAppFilter != null && !mAppFilter.shouldShowApp(info.componentName)) {
            return;
        }
        if (findActivity(data, info.componentName)) {
            LauncherLog.i(TAG, "Application " + info + " already exists in app list, app = " + info);
            return;
        }
        data.add(info);
        added.add(info);
    }

    public void clear() {
        if (LauncherLog.DEBUG) {
            LauncherLog.d(TAG, "clear all data in app list: app size = " + data.size());
        }

        data.clear();
        // TODO: do we clear these too?
        added.clear();
        removed.clear();
        modified.clear();
    }

    public int size() {
        return data.size();
    }

    public AppInfo get(int index) {
        return data.get(index);
    }

    /**
     * Add the icons for the supplied apk called packageName.
     */
    public void addPackage(Context context, String packageName) {
        final List<ResolveInfo> matches = findActivitiesForPackage(context, packageName);

        if (LauncherLog.DEBUG) {
            LauncherLog.d(TAG, "addPackage: packageName = " + packageName + ", matches = " + matches.size());
        }

        if (matches.size() > 0) {
            for (ResolveInfo info : matches) {
                add(new AppInfo(context.getPackageManager(), info, mIconCache, null));
            }
        }
    }

    /**
     * Remove the apps for the given apk identified by packageName.
     */
    public void removePackage(String packageName) {
        final List<AppInfo> data = this.data;
        if (LauncherLog.DEBUG) {
            LauncherLog.d(TAG, "removePackage: packageName = " + packageName + ", data size = " + data.size());
        }

        for (int i = data.size() - 1; i >= 0; i--) {
            AppInfo info = data.get(i);
            final ComponentName component = info.intent.getComponent();
            if (packageName.equals(component.getPackageName())) {
                removed.add(info);
                data.remove(i);
            }
        }
        // This is more aggressive than it needs to be.
        mIconCache.flush();
    }

    /**
     * Add and remove icons for this package which has been updated.
     */
    public void updatePackage(Context context, String packageName) {
        final List<ResolveInfo> matches = findActivitiesForPackage(context, packageName);
        if (LauncherLog.DEBUG) {
            LauncherLog.d(TAG, "updatePackage: packageName = " + packageName + ", matches = " + matches.size());
        }

        if (matches.size() > 0) {
            // Find disabled/removed activities and remove them from data and add them
            // to the removed list.
            for (int i = data.size() - 1; i >= 0; i--) {
                final AppInfo applicationInfo = data.get(i);
                final ComponentName component = applicationInfo.intent.getComponent();
                if (packageName.equals(component.getPackageName())) {
                    if (!findActivity(matches, component)) {
                        removed.add(applicationInfo);
                        mIconCache.remove(component);
                        data.remove(i);
                    }
                }
            }

            // Find enabled activities and add them to the adapter
            // Also updates existing activities with new labels/icons
            int count = matches.size();
            for (int i = 0; i < count; i++) {
                final ResolveInfo info = matches.get(i);
                final String pkgName = info.activityInfo.applicationInfo.packageName;
                final String className = info.activityInfo.name;

                AppInfo applicationInfo = findApplicationInfoLocked(
                        info.activityInfo.applicationInfo.packageName,
                        info.activityInfo.name);
                if (applicationInfo == null) {
                    add(new AppInfo(context.getPackageManager(), info, mIconCache, null));
                } else {
                    mIconCache.remove(applicationInfo.componentName);
                    mIconCache.getTitleAndIcon(applicationInfo, info, null);
                    modified.add(applicationInfo);
                }
            }
        } else {
            // Remove all data for this package.
            for (int i = data.size() - 1; i >= 0; i--) {
                final AppInfo applicationInfo = data.get(i);
                final ComponentName component = applicationInfo.intent.getComponent();
                if (packageName.equals(component.getPackageName())) {
                    if (LauncherLog.DEBUG) {
                        LauncherLog.d(TAG, "Remove application from launcher: component = " + component);
                    }
                    removed.add(applicationInfo);
                    mIconCache.remove(component);
                    data.remove(i);
                }
            }
        }
    }

    /**
     * Query the package manager for MAIN/LAUNCHER activities in the supplied package.
     */
    // mtk modify to default
    static List<ResolveInfo> findActivitiesForPackage(Context context, String packageName) {
        final PackageManager packageManager = context.getPackageManager();

        final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        mainIntent.setPackage(packageName);

        final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0);
        return apps != null ? apps : new ArrayList<ResolveInfo>();
    }

    /**
     * Returns whether <em>apps</em> contains <em>component</em>.
     */
    // mtk modify to default
    static boolean findActivity(List<ResolveInfo> apps, ComponentName component) {
        final String className = component.getClassName();
        for (ResolveInfo info : apps) {
            final ActivityInfo activityInfo = info.activityInfo;
            if (activityInfo.name.equals(className)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Returns whether <em>apps</em> contains <em>component</em>.
     */
    private static boolean findActivity(ArrayList<AppInfo> apps, ComponentName component) {
        final int N = apps.size();
        for (int i=0; i<N; i++) {
            final AppInfo info = apps.get(i);
            if (info.componentName.equals(component)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Find an ApplicationInfo object for the given packageName and className.
     */
    private AppInfo findApplicationInfoLocked(String packageName, String className) {
        for (AppInfo info: data) {
            final ComponentName component = info.intent.getComponent();
            if (packageName.equals(component.getPackageName())
                    && className.equals(component.getClassName())) {
                return info;
            }
        }
        return null;
    }

    /**
     * M: Load the default set of default top packages from an xml file.
     *
     * @param context
     * @return true if load successful.
     */
    static boolean loadTopPackage(final Context context) {
        boolean bRet = false;
        if (sTopPackages != null) {
            return bRet;
        }

        sTopPackages = new ArrayList<TopPackage>();

        try {
            XmlResourceParser parser = context.getResources().getXml(R.xml.default_toppackage);
            AttributeSet attrs = Xml.asAttributeSet(parser);
            XmlUtils.beginDocument(parser, TAG_TOPPACKAGES);

            final int depth = parser.getDepth();

            int type = -1;
            while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
                    && type != XmlPullParser.END_DOCUMENT) {

                if (type != XmlPullParser.START_TAG) {
                    continue;
                }

                TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TopPackage);

                sTopPackages.add(new TopPackage(a.getString(R.styleable.TopPackage_topPackageName),
                        a.getString(R.styleable.TopPackage_topClassName), a.getInt(
                                R.styleable.TopPackage_topOrder, 0)));

                LauncherLog.d(TAG, "loadTopPackage: packageName = "
                        + a.getString(R.styleable.TopPackage_topPackageName)
                        + ", className = "
                        + a.getString(R.styleable.TopPackage_topClassName));

                a.recycle();
            }
        } catch (XmlPullParserException e) {
            LauncherLog.w(TAG, "Got XmlPullParserException while parsing toppackage.", e);
        } catch (IOException e) {
            LauncherLog.w(TAG, "Got IOException while parsing toppackage.", e);
        }

        return bRet;
    }

    /**
     * M: Get the index for the given appInfo in the top packages.
     *
     * @param appInfo
     * @return the index of the given appInfo.
     */
    static int getTopPackageIndex(final AppInfo appInfo) {
        int retIndex = -1;
        if (sTopPackages == null || sTopPackages.isEmpty() || appInfo == null) {
            return retIndex;
        }

        for (TopPackage tp : sTopPackages) {
            if (appInfo.componentName.getPackageName().equals(tp.packageName)
                    && appInfo.componentName.getClassName().equals(tp.className)) {
                retIndex = tp.order;
                break;
            }
        }

        return retIndex;
    }

    /**
     * M: Reorder all apps index according to TopPackages.
     */
    void reorderApplist() {
        final long sortTime = DEBUG_LOADERS_REORDER ? SystemClock.uptimeMillis() : 0;

        if (sTopPackages == null || sTopPackages.isEmpty()) {
            return;
        }
        ensureTopPackageOrdered();

        final ArrayList<AppInfo> dataReorder = new ArrayList<AppInfo>(
                DEFAULT_APPLICATIONS_NUMBER);

        for (TopPackage tp : sTopPackages) {
            int loop = 0;
            for (AppInfo ai : added) {
                if (DEBUG_LOADERS_REORDER) {
                    LauncherLog.d(TAG, "reorderApplist: remove loop = " + loop);
                }

                if (ai.componentName.getPackageName().equals(tp.packageName)
                        && ai.componentName.getClassName().equals(tp.className)) {
                    if (DEBUG_LOADERS_REORDER) {
                        LauncherLog.d(TAG, "reorderApplist: remove packageName = "
                                + ai.componentName.getPackageName());
                    }
                    data.remove(ai);
                    dataReorder.add(ai);
                    dumpData();
                    break;
                }
                loop++;
            }
        }

        for (TopPackage tp : sTopPackages) {
            int loop = 0;
            int newIndex = 0;
            for (AppInfo ai : dataReorder) {
                if (DEBUG_LOADERS_REORDER) {
                    LauncherLog.d(TAG, "reorderApplist: added loop = " + loop + ", packageName = "
                            + ai.componentName.getPackageName());
                }

                if (ai.componentName.getPackageName().equals(tp.packageName)
                        && ai.componentName.getClassName().equals(tp.className)) {
                    newIndex = Math.min(Math.max(tp.order, 0), added.size());
                    if (DEBUG_LOADERS_REORDER) {
                        LauncherLog.d(TAG, "reorderApplist: added newIndex = " + newIndex);
                    }
                    /// M: make sure the array list not out of bound
                    if (newIndex < data.size()) {
                        data.add(newIndex, ai);
                    } else {
                        data.add(ai);
                    }
                    dumpData();
                    break;
                }
                loop++;
            }
        }

        if (added.size() == data.size()) {
            added = (ArrayList<AppInfo>) data.clone();
            LauncherLog.d(TAG, "reorderApplist added.size() == data.size()");
        }

        if (DEBUG_LOADERS_REORDER) {
            LauncherLog.d(TAG, "sort and reorder took " + (SystemClock.uptimeMillis() - sortTime) + "ms");
        }
    }

    /**
     * Dump application informations in data.
     */
    void dumpData() {
        int loop2 = 0;
        for (AppInfo ai : data) {
            if (DEBUG_LOADERS_REORDER) {
                LauncherLog.d(TAG, "reorderApplist data loop2 = " + loop2);
                LauncherLog.d(TAG, "reorderApplist data packageName = "
                        + ai.componentName.getPackageName());
            }
            loop2++;
        }
    }

    /*
     * M: ensure the items from top_package.xml is in order,
     * for some special case of top_package.xml will make the arraylist out of bound.
     */

    static void ensureTopPackageOrdered() {
        ArrayList<TopPackage> tpOrderList = new ArrayList<TopPackage>(DEFAULT_APPLICATIONS_NUMBER);
        boolean bFirst = true;
        for (TopPackage tp : sTopPackages) {
            if (bFirst) {
                tpOrderList.add(tp);
                bFirst = false;
            } else {
                for (int i = tpOrderList.size() - 1; i >= 0; i--) {
                    TopPackage tpItor = tpOrderList.get(i);
                    if (0 == i) {
                        if (tp.order < tpOrderList.get(0).order) {
                            tpOrderList.add(0, tp);
                        } else {
                            tpOrderList.add(1, tp);
                        }
                        break;
                    }

                    if ((tp.order < tpOrderList.get(i).order)
                        && (tp.order >= tpOrderList.get(i - 1).order)) {
                        tpOrderList.add(i, tp);
                        break;
                    } else if (tp.order > tpOrderList.get(i).order) {
                        tpOrderList.add(i + 1, tp);
                        break;
                    }
                }
            }
        }

        if (sTopPackages.size() == tpOrderList.size()) {
            sTopPackages = (ArrayList<TopPackage>) tpOrderList.clone();
            tpOrderList = null;
            LauncherLog.d(TAG, "ensureTopPackageOrdered done");
        } else {
            LauncherLog.d(TAG, "some mistake may occur when ensureTopPackageOrdered");
        }
    }

    /**
     * M: add an application, only add to data list, not for added list.
     *
     * @param info
     */
    public void addApp(final AppInfo info) {
        if (LauncherLog.DEBUG_EDIT) {
            LauncherLog.d(TAG, "Add application to data list: app = " + info.componentName);
        }

        if (findActivity(data, info.componentName)) {
            LauncherLog.i(TAG, "The app " + info + " is already exist in data list.");
            return;
        }
        data.add(info);
    }

    /**
     * M: whether the all apps list is empty.
     *
     * @return
     */
    public boolean isEmpty() {
        return data.isEmpty();
    }
}
时间: 2024-11-07 21:11:50

在Launcher的主菜单中隐藏某个应用removePackage的相关文章

form表单中隐藏类型input的使用

<form action="PersonSave.ashx" method="post"> <input type="hidden" name="action" value="{action}"/> <input type="hidden" name="id" value="{id}"/> 姓名:<inpu

Android Launcher浅析(二)

1,如何修改主菜单图标的位置? [DESCRIPTION] 默认主菜单图标在中间,如何修改它的位置? Launcher3: DynamicGrid.java文件 hotseatAllAppsRank = (int) (numColumns/2); //默认是列数除以2取整,可以设置为需要的值 Launcher2: 1. 请修改packages/apps/Laucher2/res/values/config.xml 中hotseat_all_apps_index的值,例如修改为1 2. 默认在ho

索尼 LT26I刷机包 X.I.D 增加官方风格 GF A3.9.4 各方面完美

ROM介 FX_GF_A系列是具有官方风格的.稳定的.流畅的.省电的.新功能体验的.最悦耳音效体验的ROM. FX_GF_A更新日志 ☆ GF_3.9.4 更新信息 ☆ 更新播放器 ☆ 更新adsp数据 ☆ 更新部分Z2音频数据 ☆ 改动脚本 ☆ 修正可换锁屏壁纸 ☆ GF_3.9.3 更新信息 ☆ 更新播放器桌面插件2.0.A.0.54 ☆ 调整录音文字显示 ☆ 增加新版日历带农历12.0.A.0.23 ☆ 更新播放器8.3.A.0.7 ☆ 更新相冊6.1.A.1.14 ☆ 调整均衡器 ☆ 改

索尼 LT26I刷机包 X.I.D 加入官方风格 GF A3.9.4 各方面完美

ROM介 FX_GF_A系列是具有官方风格的.稳定的.流畅的.省电的.新功能体验的.最悦耳音效体验的ROM. FX_GF_A更新日志 ☆ GF_3.9.4 更新信息 ☆ 更新播放器 ☆ 更新adsp数据 ☆ 更新部分Z2音频数据 ☆ 修改脚本 ☆ 修正可换锁屏壁纸 ☆ GF_3.9.3 更新信息 ☆ 更新播放器桌面插件2.0.A.0.54 ☆ 调整录音文字显示 ☆ 加入新版日历带农历12.0.A.0.23 ☆ 更新播放器8.3.A.0.7 ☆ 更新相册6.1.A.1.14 ☆ 调整均衡器 ☆ 修

284.软件体系结构集成开发环境的作用

软件体系结构集成开发环境基于体系结构形式化描述从系统框架的角度关注软件开发.体系结构开发工具是体系结构研究和分析的工具,给软件系统提供了形式化和可视化的描述.它不但提供了图形用户界面.文本编辑器.图形编辑器等可视化工具,还集成了编译器.解析器.校验器.仿真器等工具:不但可以针对每个系统元素,还支持从较高的构件层次分析和设计系统,这样可以有效地支持构件重用.具体来说,软件体系结构集成开发环境的功能可以分为以下5类. 1.辅助体系结构建模 建立体系结构模型是体系结构集成开发环境最重要的功能之一.集成

DOS命令大全

http://www.cnblogs.com/yuanweiming84/archive/2006/05/24/408269.html DOS基本命令MD——建立子目录1.功能:创建新的子目录2.类型:内部命令3.格式:MD[盘符:][路径名]〈子目录名〉4.使用说明:(1)“盘符”:指定要建立子目录的磁盘驱动器字母,若省略,则为当前驱动器:(2)“路径名”:要建立的子目录的上级目录名,若缺省则建在当前目录下.例:(1)在C盘的根目录下创建名为FOX的子目录:(2)在FOX子目录下再创建USER

Orchard官方文档翻译(六) 建立你的第一个Orchartd站点

让我们开始 该主题内容已在Orchard1.8Release版本下测试通过. 这里通过向导式的教程来告诉大家Orchard的功能如何使用.如果你是第一次使用Orchard,该文档就是为你而准备的! Orchard使用从零开始 对于初次接触Orchard的你来说,这里就是你的圣地,因为你能在这里找到最新的Orchard资源. Orchard 初学者 Orchard CodePlex - Orchard代码库 Orchard 讨论区 - 关于Orchard讨论区 Orchard 文档 - 与Orch

3ds max 2010版本的石墨建模工具使用方法

此教程源自AboutCG 作者:freeyy , 学习之前,尊重尤为重要.向作者致敬,学习快乐! 教程分类:MAX建模适用读者:中高级用户作者:freeyy 这篇教程主要适用于原来使用过3ds MAX多边形建模插件Polyboost的老用户,文章内容主要是讨论相对于之前版本的变化,以及参数的更新.小技巧等等,主要是方便老用户快速适应新生事物而准备的,在MAX help文档中涉及的内容我基本不会重复浪费太多表情和口水~~,所以要完全学习max 2010的石墨建模请参看3ds max 2010的用户

安卓创建快捷方式相关问题 Intent Intent-filter

Intent 在安卓中,Activity启动时通常需要Intent参数.Intent参数中包含以下几个常用的属性: Component,指定了要启动的Activity,以及启动的context,使用Intent.setClass或Intent.setComponent方法可以设置: Action属性,可用Intent.setAction方法设置: Category属性,可用Intent.addCategory方法添加,Action和Category属性一般用于做过滤: Extra属性,用于传入一