集成android源码中的 packages/apps 到eclipse 比如launcher2

1,自己编译android生成sdk,我选择的是gingerbread-2.3.3_r1。把eclipse指向自己编译的sdk--android2.3.3r1-sdk_eng.root_linux-x86

 

2, 首先把packages/apps下的程序拉出来。比如:Calculator,DeskClock,Launcher2,Music,Protips。

其他的改动太多,不推荐。

 

3,在eclipse新建android工程,源码选择有AndroidManifest.xml的文件夹,得到一个android工程比如Launcher2。为了和模拟器上自带的launcher2有所区别,更改launcher2的包名。把“com.android.launcher”,“com.android.launcher2” 改成“com.zyl.launcher, com.zyl.launcher2”。(zyl就是自己名字的缩写)

 

4,当然,现在会看到几百个错误。为什么会有很多的类和方法看不到,在sdk里被屏蔽掉了,launcher2 命令行编译就可以过。生成sdk时会扫描所有的类和方法,有public和protected就会公开,生成framewroks/api/current.xml文件,命令“make update-api”可以更新current.xml.

 

5,但是,在类和方法前的注释有@hide字样的,这个类或方法就会被屏蔽,不会输出到current.xml。这样sdk就没有这个类或方法了。

实际在out/target/common/obj/JAVA_LIBRARIES 有你需要的类和方法。有人把“framework_intermediates/classes.jar” 导入到工程中当成一个外部库(注意库的顺序,android.jar应该放在最后),其实就是覆盖了android.jar内同包同名的.class。但是因为“framework_intermediates/classes.jar”很大,eclipse很容易死机啊。

 

6,只有用最笨的方法,把“framework_intermediates/classes.jar”解压,只是把需要的.class导入工程。android-common_intermediates和别文件夹能也可能用到。

 

7,重启emulator可以看到两个“启动器”了。想要直接启动,

AndroidManifest.xml 内加上 <category android:name="android.intent.category.LAUNCHER" />

 

8,eclipse集成的Graphical Layout 对<include />支持的不好,应该直接显示出来的。不知道Google如何编译调试xml文件的,eclipse很不方便啊。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是 IconShapeOverride.java 的源代码: ```java package com.android.launcher3.graphics; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.Path; import android.graphics.Rect; import android.os.Build; import android.util.Log; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.android.launcher3.Utilities; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.icons.IconProvider; import com.android.launcher3.icons.ShapeData; import com.android.launcher3.util.MainThreadInitializedObject; import com.android.launcher3.util.ResourceBasedOverride; /** * Provides custom icon shapes based on user preferences. */ public class IconShapeOverride extends ResourceBasedOverride { public static final String KEY_PREFERENCE = "pref_override_icon_shape"; private static final String TAG = "IconShapeOverride"; private final IconProvider mIconProvider; public IconShapeOverride(Context context) { this(context, IconProvider.INSTANCE); } @VisibleForTesting public IconShapeOverride(Context context, IconProvider iconProvider) { super(context, KEY_PREFERENCE); mIconProvider = iconProvider; } /** * @return the current shape path, or null if not defined. */ @Nullable public ShapeData getShape() { String pathString = getStringValue(); if (pathString == null) { return null; } try { return ShapeData.parse(pathString); } catch (IllegalArgumentException e) { Log.e(TAG, "Unable to parse shape", e); return null; } } /** * @return the current shape path as a {@link Path} instance, or null if not defined. */ @Nullable public Path getShapePath() { ShapeData data = getShape(); return data != null ? data.getPath() : null; } /** * @return the current shape path bounds, or null if not defined. */ @Nullable public Rect getShapeBounds() { ShapeData data = getShape(); return data != null ? data.getBounds() : null; } /** * Returns the shape path for the given context, or null if none is specified. */ public static Path getShapePath(Resources res, SharedPreferences prefs) { IconShapeOverride override = new IconShapeOverride(res); override.setSharedPreferences(prefs); return override.getShapePath(); } /** * Tests whether the current shape is a circle, by checking if all corners of the shape are at * the same distance from the center. */ public boolean isShapeCircle() { Path shape = getShapePath(); if (shape == null) { return false; } Rect bounds = getShapeBounds(); if (bounds == null) { return false; } Rect outBounds = new Rect(); shape.computeBounds(outBounds, true); float centerX = bounds.exactCenterX(); float centerY = bounds.exactCenterY(); float radius = Math.max(centerX - bounds.left, centerY - bounds.top); float maxDeviation = 0; float[] radii = new float[9]; shape.approximate(1f, radii); for (int i = 0; i < radii.length; i += 2) { float deviation = Math.abs(radii[i] - radius); if (deviation > maxDeviation) { maxDeviation = deviation; } } return maxDeviation < GraphicsUtils.EPSILON; } /** * Updates the default icon shape, if the user has not overridden it. */ public static void updateDefaultShape(Context context) { SharedPreferences prefs = Utilities.getPrefs(context); if (prefs.contains(KEY_PREFERENCE)) { return; } IconShapeOverride override = new IconShapeOverride(context); Path path = override.getDefaultShape(); if (path != null) { prefs.edit().putString(KEY_PREFERENCE, ShapeData.toString(path)).apply(); } } /** * @return the default shape path for the current device. */ @Nullable public Path getDefaultShape() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return IconShape.applyMaskIfNeeded(mIconProvider.getDeviceProfile(), mIconProvider.getIconMask()); } return null; } @Override protected void onValueChanged() { super.onValueChanged(); mIconProvider.clearCaches(); } } ``` 该类提供了自定义应用图标的形状的功能,它会根据用户的偏好设置提供自定义图标形状。其包含了获取、设置、更新默认图标形状等方法。此外,还包含一些辅助方法,如测试当前形状是否为圆形。在 Android Oreo 及以上版本,会调用 IconShape 类提供的方法来获取默认图标形状。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值