Launcher3--launcher3 icon以及hotseat size大小修改

本帖最后由 wangjicong 于 2017-3-9 17:12 编辑

1.首先看icon大小的修改。
       Launcher3在启动Launcher.java过程会先初始话一些列的参数配置。
      1). Laucher.java   

  1. @Override
  2.     protected void onCreate(Bundle savedInstanceState) {
  3.         if (DEBUG_STRICT_MODE) {
  4.             StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
  5.                     .detectDiskReads()
  6.                     .detectDiskWrites()
  7.                     .detectNetwork()   // or .detectAll() for all detectable problems
  8.                     .penaltyLog()
  9.                     .build());
  10.             StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
  11.                     .detectLeakedSqlLiteObjects()
  12.                     .detectLeakedClosableObjects()
  13.                     .penaltyLog()
  14.                     .penaltyDeath()
  15.                     .build());
  16.         }

  17.         if (mLauncherCallbacks != null) {
  18.             mLauncherCallbacks.preOnCreate();
  19.         }

  20.         super.onCreate(savedInstanceState);

  21.         LauncherAppState.setApplicationContext(getApplicationContext());
  22.         LauncherAppState app = LauncherAppState.getInstance();
复制代码
        Launcher.java  在oncreate的过程中,通过单例模式LauncherAppState.java来初始话。


       上面  mInvariantDeviceProfile = new InvariantDeviceProfile(sContext);就是对页面布局,icon大小,hotseat 大小一些参数的自适。

private LauncherAppState() {
  •     if (sContext == null) {
  •         throw new IllegalStateException("LauncherAppState inited before app context set");
  •     }

  •     Log.v(Launcher.TAG, "LauncherAppState inited");

  •     if (sContext.getResources().getBoolean(R.bool.debug_memory_enabled)) {
  •         MemoryTracker.startTrackingMe(sContext, "L");
  •     }

  •     mInvariantDeviceProfile = new InvariantDeviceProfile(sContext);
  •     mIconCache = new IconCache(sContext, mInvariantDeviceProfile);
  •     mWidgetCache = new WidgetPreviewLoader(sContext, mIconCache);

  •     mAppFilter = AppFilter.loadByName(sContext.getString(R.string.app_filter_class));
  •     mBuildInfo = BuildInfo.loadByName(sContext.getString(R.string.build_info_class));
  •     mModel = new LauncherModel(this, mIconCache, mAppFilter);

  •     LauncherAppsCompat.getInstance(sContext).addOnAppsChangedCallback(mModel);

  •     // Register intent receivers
  •     IntentFilter filter = new IntentFilter();
  •     filter.addAction(Intent.ACTION_LOCALE_CHANGED);
  •     filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
  •     filter.addAction(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED);
  •     // For handling managed profiles
  •     filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
  •     filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);

  •     sContext.registerReceiver(mModel, filter);

  •     mUnreadInfoManager = new SprdUnreadInfoManager(this);
  •     SprdUnreadInfoManager.getInstance().init(this);

  • }
  • 复制代码


           修改icon大小:
          在InvariantDeviceProfile 的构造函数中:

    1.       iconSize = interpolatedDeviceProfileOut.iconSize;
    2.         /*SUN:jicong.wang add for custom icon size start {@*/
    3.         String sunvov_custom_icon_size = context.getResources().getString(R.string.sunvov_icon_size);
    4.         if (!"ignore".equals(sunvov_custom_icon_size)){
    5.             iconSize = Float.parseFloat(sunvov_custom_icon_size);
    6.         }
    7.         /*SUN:jicong.wang add for custom icon size end @}*/
    复制代码



       2.修改hotseat icon的大小:
             在修改玩icon大小之后,发现shortcut icon的大小和主菜单中icon的大小同步变化了,但是hotseat icon的大小比icon的较大;
            通过源码发现:CellLayout.java


    1.     public boolean addViewToCellLayout(View child, int index, int childId, LayoutParams params,
    2.             boolean markCells) {
    3.         final LayoutParams lp = params;

    4.         // Hotseat icons - remove text
    5.         if (child instanceof BubbleTextView) {
    6.             BubbleTextView bubbleChild = (BubbleTextView) child;
    7.             bubbleChild.setTextVisibility(!mIsHotseat);
    8.         }

    9.         child.setScaleX(getChildrenScale());
    10.         child.setScaleY(getChildrenScale());

    11.         // Generate an id for each view, this assumes we have at most 256x256 cells
    12.         // per workspace screen
    13.         if (lp.cellX >= 0 && lp.cellX <= mCountX - 1 && lp.cellY >= 0 && lp.cellY <= mCountY - 1) {
    14.             // If the horizontal or vertical span is set to -1, it is taken to
    15.             // mean that it spans the extent of the CellLayout
    16.             if (lp.cellHSpan < 0) lp.cellHSpan = mCountX;
    17.             if (lp.cellVSpan < 0) lp.cellVSpan = mCountY;

    18.             child.setId(childId);
    19.             mShortcutsAndWidgets.addView(child, index, lp);

    20.             if (markCells) markCellsAsOccupiedForView(child);

    21.             return true;
    22.         }
    23.         return false;
    24.     }

    复制代码



               通过上面发现在addview的过程中居然需要child.setScaleX(getChildrenScale());
               mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx;
               修改:


    1.         final Resources res = getResources();
    2.         /*SUN:jicong.wang add for hotseat icon size same with shortcut icon start {@*/
    3.         if (!res.getBoolean(R.bool.sunvov_hotseat_shortcut_icon_size_same)){        
    4.             mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx;
    5.         }
    6.         /*SUN:jicong.wang add for hotseat icon size same with shortcut icon end @}*/
    复制代码

    你可能感兴趣的:(Android,android系统)