android launcher開發之表徵圖背景以及預設配置

來源:互聯網
上載者:User

android launcher開發之表徵圖背景以及預設配置
1:然後我自己看了一下案頭表徵圖的載入過程:
案頭第一次載入時是預設讀取一個xml設定檔,完成配置工作。這個設定檔在Launcher目錄下,
路徑是:\Launcher\res\xml\default_workspace.xml 。這個XML檔案就是剛升級,Launcher第
一次顯示的時候,會讀取的設定檔。default_workspace。xml裡面可以配置APP捷徑、Widget、Search搜尋欄等




launcher裡面負責解析default_workspace.xml檔案的方法是 LauncherProvider.java裡面的loadFavorites方法
LauncherProvider.java裡面有loadFavorites()這個方法:
private int loadFavorites(SQLiteDatabase db, int workspaceResourceId) {
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ContentValues values = new ContentValues();


if (LOGD) Log.v(TAG, String.format("Loading favorites from resid=0x%08x", workspaceResourceId));


PackageManager packageManager = mContext.getPackageManager();
int i = 0;
try {
XmlResourceParser parser = mContext.getResources().getXml(workspaceResourceId);
AttributeSet attrs = Xml.asAttributeSet(parser);
beginDocument(parser, TAG_FAVORITES);


final int depth = parser.getDepth();


final HashMap occupied = new HashMap();
LauncherModel model = LauncherAppState.getInstance().getModel();






return i;
}


其實就是一個分析XML和寫入資料庫的過程,LauncherProvider.java是整個Launcher的資料來源,
知道這些表徵圖如何載入出來之後對做螢幕是壞 修改背景大小 行列等都有好處。










2:Launcher 表徵圖加入預設背景。是主題功能的一個小部分也是不可缺少的一部分,下面是我今天整理的一些邏輯和代碼,Launcher表徵圖的擷取處理是在Utilities.java類裡面,
我們可以從裡面找到Bitmap createIconBitmap(Drawable icon, Context context) 方法。這個方法就是返回應用表徵圖的。
static Bitmap createIconBitmap(Bitmap icon, Context context) {
int textureWidth = sIconTextureWidth;
int textureHeight = sIconTextureHeight;
int sourceWidth = icon.getWidth();
int sourceHeight = icon.getHeight();
if (sourceWidth > textureWidth && sourceHeight > textureHeight) {
// Icon is bigger than it should be; clip it (solves the GB->ICS migration case)
return Bitmap.createBitmap(icon,
(sourceWidth - textureWidth) / 2,
(sourceHeight - textureHeight) / 2,
textureWidth, textureHeight);
} else if (sourceWidth == textureWidth && sourceHeight == textureHeight) {
// Icon is the right size, no need to change it
return icon;
} else {
// Icon is too small, render to a larger bitmap
final Resources resources = context.getResources();
return createIconBitmap(new BitmapDrawable(resources, icon), context);
}
}
可以在這裡修改表徵圖的背景 可以加入
if (tru{
Bitmap backBitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.apical_icon_bg);
int backWidth = backBitmap.getWidth();
int backHeight = backBitmap.getHeight();
if(backWidth != sIconWidth || backHeight != sIconHeight)
{
Matrix matrix = new Matrix();
matrix.postScale((float)sIconWidth/backWidth, (float)sIconHeight/backHeight);
canvas.drawBitmap(Bitmap.createBitmap(backBitmap, 0, 0, backWidth, backHeight, matrix, true),
.0f, 0.0f, null);
}else
{
canvas.drawBitmap(backBitmap, 0.0f, 0.0f, null);
}
}


直接指定一個圖片為表徵圖背景 R.drawable.apical_icon_bg;












聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.