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 大小一些参数的自适。
  1. <div>
  2. </div><div>private LauncherAppState() {
  3.     if (sContext == null) {
  4.         throw new IllegalStateException("LauncherAppState inited before app context set");
  5.     }

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

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

  10.     mInvariantDeviceProfile = new InvariantDeviceProfile(sContext);
  11.     mIconCache = new IconCache(sContext, mInvariantDeviceProfile);
  12.     mWidgetCache = new WidgetPreviewLoader(sContext, mIconCache);

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

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

  17.     // Register intent receivers
  18.     IntentFilter filter = new IntentFilter();
  19.     filter.addAction(Intent.ACTION_LOCALE_CHANGED);
  20.     filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
  21.     filter.addAction(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED);
  22.     // For handling managed profiles
  23.     filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
  24.     filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);

  25.     sContext.registerReceiver(mModel, filter);

  26.     mUnreadInfoManager = new SprdUnreadInfoManager(this);
  27.     SprdUnreadInfoManager.getInstance().init(this);

  28. }</div>
复制代码



       修改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 @}*/
复制代码

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值