(1、2两点请参考何明桂何兄的博客,地址分别为:http://blog.csdn.net/hmg25/article/details/6289438 http://blog.csdn.net/hmg25/article/details/6289725)Dockbar的实现,何兄只提供了竖屏,我在其博客的评论中看到不少人说是要实现横屏,下面我将我的实现帖出来。主要是修改layout-land/launcher.xml文件,以下是这个文件的全部代码:
<com.androID.launcherex.DragLayer xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:launcher="http://schemas.androID.com/apk/res/com.androID.launcher" androID:ID="@+ID/drag_layer" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <include layout="@layout/all_apps" /> <!-- The workspace contains 3 screens of cells --> <com.androID.launcherex.Workspace androID:ID="@+ID/workspace" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:scrollbars="horizontal" androID:fadeScrollbars="true" launcher:defaultScreen="2"> <include androID:ID="@+ID/cell1" layout="@layout/workspace_screen" /> <include androID:ID="@+ID/cell2" layout="@layout/workspace_screen" /> <include androID:ID="@+ID/cell3" layout="@layout/workspace_screen" /> <include androID:ID="@+ID/cell4" layout="@layout/workspace_screen" /> <include androID:ID="@+ID/cell5" layout="@layout/workspace_screen" /> </com.androID.launcherex.Workspace> <relativeLayout androID:ID="@+ID/dock_layout" androID:layout_gravity="bottom|left" androID:layout_wIDth="match_parent" androID:layout_height="95dip" > <com.androID.launcherex.ClippedImageVIEw androID:ID="@+ID/prevIoUs_screen" androID:layout_wIDth="93dip" androID:layout_height="@dimen/button_bar_height" androID:layout_alignParenttop="true" androID:layout_alignParentleft="true" androID:layout_marginleft="6dip" androID:scaleType="center" androID:src="@drawable/home_arrows_left" androID:onClick="prevIoUsScreen" launcher:ignoreZone="56dip" androID:focusable="true" androID:clickable="true" /> <com.androID.launcherex.ClippedImageVIEw androID:ID="@+ID/next_screen" androID:layout_wIDth="93dip" androID:layout_height="@dimen/button_bar_height" androID:layout_alignParenttop="true" androID:layout_alignParentRight="true" androID:layout_marginRight="6dip" androID:scaleType="center" androID:src="@drawable/home_arrows_right" androID:onClick="nextScreen" launcher:ignoreZone="-56dip" androID:focusable="true" androID:clickable="true" /> <com.androID.launcherex.DeleteZone androID:ID="@+ID/delete_zone" androID:layout_wIDth="@dimen/delete_zone_size" androID:layout_height="@dimen/delete_zone_size" androID:paddingleft="@dimen/delete_zone_padding" androID:layout_marginBottom="@dimen/dock_bar_height" androID:layout_alignParentBottom="true" androID:layout_centerHorizontal="true" androID:scaleType="center" androID:src="@drawable/delete_zone_selector" androID:visibility="invisible" launcher:direction="vertical" /> <relativeLayout androID:ID="@+ID/all_apps_button_cluster" androID:layout_height="fill_parent" androID:layout_wIDth="@dimen/button_bar_height_portrait" androID:layout_gravity="bottom|center_vertical" androID:layout_marginBottom="@dimen/half_status_bar_height" > <!-- <com.androID.launcherex.HandleVIEw androID:ID="@+ID/all_apps_button" androID:layout_centerVertical="true" androID:layout_alignParentRight="true" androID:src="@drawable/all_apps_button" launcher:direction="vertical" />--> <!-- androID:layout_below="@ID/all_apps_button" --> <!-- androID:layout_above="@ID/all_apps_button" --> <ImageVIEw androID:ID="@+ID/hotseat_left" androID:src="@drawable/hotseat_phone" androID:visibility="gone" androID:onClick="launchHotSeat" /> <ImageVIEw androID:ID="@+ID/hotseat_right" androID:visibility="gone" androID:src="@drawable/hotseat_browser" androID:onClick="launchHotSeat" /> </relativeLayout> <com.androID.launcherex.Dockbar androID:ID="@+ID/dockbar" androID:layout_wIDth="fill_parent" androID:layout_height="@dimen/button_bar_height" androID:background="@drawable/dock_bg" androID:layout_alignParentBottom="true" launcher:direction="horizontal"> <horizontalscrollview androID:ID="@+ID/dock_scroll_vIEw" androID:scrollbars="none" androID:fadingEdge="none" androID:saveEnabled="false" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent"> <linearLayout androID:orIEntation="horizontal" androID:ID="@+ID/dock_item_holder" androID:saveEnabled="false" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent"> <com.androID.launcherex.HandleVIEw androID:ID="@+ID/all_apps_button" androID:layout_centerVertical="true" androID:src="@drawable/all_apps_button" launcher:direction="horizontal" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:focusable="true" androID:clickable="true" /> </linearLayout> </horizontalscrollview> </com.androID.launcherex.Dockbar> </relativeLayout></com.androID.launcherex.DragLayer>
3、启用3D效果
3D效果启动很简单,只需要将all_apps.xml文件下的
<include layout="@layout/all_apps_2d" />改为:
<include layout="@layout/all_apps_3d" />
即可。当然你可能还需要对图标做一些调整。我主要是调整了一下几个参数:
public static final int ICON_WIDTH_PX = 64; public static final int ICON_TEXTURE_WIDTH_PX = 74; public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20; public static final int ICON_HEIGHT_PX = 64; public static final int ICON_TEXTURE_HEIGHT_PX = 74; public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
4、替换应用程序图标 主要是在IconCache中做了以下修改。修改的只是Launcher上显示的图标,长按Home键显示最近开启的应用时,图标还是原先默认的图标,这些就自己去改吧。
private CacheEntry cacheLocked(Componentname componentname,ResolveInfo info) { CacheEntry entry = mCache.get(componentname); if (entry == null) { entry = new CacheEntry(); mCache.put(componentname,entry); entry.Title = info.loadLabel(mPackageManager).toString(); if (entry.Title == null) { entry.Title = info.activityInfo.name; } // entry.icon = UtilitIEs.createIconBitmap(info.activityInfo.loadIcon(mPackageManager),mContext); entry.icon = suBIcon(info); } return entry; } /** * Replace the default Launcher icon * @param info * @return */ private Bitmap suBIcon(ResolveInfo info){ Drawable drawable = null; String pname = info.activityInfo.packagename; if(pname.equals(Constant.PACKAGE_VIDEOPLAYER)){ drawable = mResources.getDrawable(R.drawable.lu_vIDeoplayer); }else if(pname.equals(Constant.PACKAGEname_broWSER)){ drawable = mResources.getDrawable(R.drawable.lu_browser); }else if(pname.equals(Constant.PACKAGE_CALculaTOR)){ drawable = mResources.getDrawable(R.drawable.lu_calculator2); }else if(pname.equals(Constant.PACKAGE_CALENDAR)){ drawable = mResources.getDrawable(R.drawable.lu_calendar); }else if(pname.equals(Constant.PACKAGE_CAMERA)){ drawable = mResources.getDrawable(R.drawable.lu_camera); }else if(pname.equals(Constant.PACKAGE_CLOCK)){ drawable = mResources.getDrawable(R.drawable.lu_alarmclock); }else if(pname.equals(Constant.PACKAGE_EMAIL)){ drawable = mResources.getDrawable(R.drawable.lu_email); }else if(pname.equals(Constant.PACKAGE_galLERY)){ drawable = mResources.getDrawable(R.drawable.lu_gallery); }else if(pname.equals(Constant.PACKAGE_MUSIC)){ drawable = mResources.getDrawable(R.drawable.lu_music); }else if(pname.equals(Constant.PACKAGE_SETTINGS)){ drawable = mResources.getDrawable(R.drawable.lu_settings); } if(drawable!=null){ return UtilitIEs.createIconBitmap(drawable,mContext); }else{ return UtilitIEs.createIconBitmap(info.activityInfo.loadIcon(mPackageManager),mContext); } }
5、批量添加快捷方式 *** 作:长按桌面 -- Add to Home Screen点击Applications即显示所有安装应用程序列表。可任意选择多个应用程序的快捷方式添加到Launcher上。
1、Activity类:AddShortcutsActivity 主要用于显示安装应用程序信息和添加 *** 作界面
2、列表适配: AddShortcutsAdapter 继承BaseAdapter。
3、快捷方式实体类:ShortcutsEntity
4、add_shortcuts_adapter.xml
5、add_shortcuts.xml
直接上代码:
package com.androID.launcherex;import java.util.ArrayList;import java.util.List;import androID.app.Activity;import androID.content.Intent;import androID.content.pm.ActivityInfo;import androID.content.pm.PackageManager;import androID.content.pm.ResolveInfo;import androID.os.Bundle;import androID.os.Parcelable;import androID.util.Log;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.Widget.AdapterVIEw;import androID.Widget.AdapterVIEw.OnItemClickListener;import androID.Widget.button;import androID.Widget.ListVIEw;import com.androID.launcher.R;public class AddShortcutsActivity extends Activity implements OnClickListener,OnItemClickListener{ private AddShortcutsAdapter mShortcutsAdapter; private final static String TAG = "AddShortcutsActivity"; private ListVIEw lstShortcuts; private button btnAddShortcuts; private button btnCancelShortcuts; private ArrayList<ShortcutsEntity> mShortcutsEntity = new ArrayList<ShortcutsEntity>(); @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.add_shortcuts); setupVIEws(); } private voID setupVIEws(){ lstShortcuts = (ListVIEw) findVIEwByID(R.ID.shortcuts_List);// lstShortcuts.setItemsCanFocus(false); lstShortcuts.setChoiceMode(ListVIEw.CHOICE_MODE_SINGLE); btnAddShortcuts = (button) findVIEwByID(R.ID.shortcuts_add); btnCancelShortcuts=(button) findVIEwByID(R.ID.shortcuts_cancel); btnAddShortcuts.setonClickListener(this); btnCancelShortcuts.setonClickListener(this); lstShortcuts.setonItemClickListener(this); mShortcutsEntity = getAllShortcuts(); mShortcutsAdapter = new AddShortcutsAdapter(mShortcutsEntity,this); lstShortcuts.setAdapter(mShortcutsAdapter); } public voID onClick(VIEw arg0) { switch(arg0.getID()){ case R.ID.shortcuts_add: ArrayList<Intent> intents = getSelectedShortcuts(); Intent intent = getIntent(); // Read base intent from extras,otherwise assume default Parcelable parcel = intent.getParcelableExtra(Intent.EXTRA_INTENT); if (parcel instanceof Intent) { intent = (Intent) parcel; } else { intent = new Intent(Intent.ACTION_MAIN,null); intent.addcategory(Intent.category_DEFAulT); } Bundle bundle = new Bundle(); bundle.putSerializable("intents",intents); intent.putExtras(bundle); setResult(Activity.RESulT_OK,intent); finish(); break; case R.ID.shortcuts_cancel: finish(); break; } } /** * Get all the applications * @return */ private ArrayList<ShortcutsEntity> getAllShortcuts(){ ArrayList<ShortcutsEntity> entitys = new ArrayList<ShortcutsEntity>(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addcategory(Intent.category_LAUNCHER); PackageManager mPackageManager = this.getPackageManager(); List<ResolveInfo> mAllApps = mPackageManager.queryIntentActivitIEs(intent,0); int size = mAllApps.size(); for(int i=0;i<size;i++){ ShortcutsEntity entity = new ShortcutsEntity(); ResolveInfo resolveInfo = mAllApps.get(i); entity.Title = resolveInfo.loadLabel(mPackageManager); entity.Icon = resolveInfo.loadIcon(mPackageManager); entity.Info = resolveInfo; entitys.add(entity); Log.i(TAG,"entity.title="+resolveInfo.loadLabel(mPackageManager)); } //Todo: sort return entitys; } public voID onItemClick(AdapterVIEw<?> arg0,VIEw arg1,int arg2,long arg3) { mShortcutsAdapter.setSelectItem(arg2); mShortcutsAdapter.notifyDataSetChanged(); } /** * Been selected shortcuts * @return */ private ArrayList<Intent> getSelectedShortcuts(){ ArrayList<Intent> selecteds = new ArrayList<Intent>(); ArrayList<Boolean> isCheck = AddShortcutsAdapter.isChecked; int checkSize = isCheck.size(); for(int i=0;i<checkSize;i++){ if(isCheck.get(i)){ ShortcutsEntity entity = mShortcutsEntity.get(i); ActivityInfo activityInfo = entity.Info.activityInfo; Intent intent = new Intent(); intent.setClassname(activityInfo.applicationInfo.packagename,activityInfo.name); selecteds.add(intent); Log.i(TAG,"selected item.name="+mShortcutsEntity.get(i).Title); } } return selecteds; }}
package com.androID.launcherex;import java.util.ArrayList;import com.androID.launcher.R;import androID.content.Context;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.BaseAdapter;import androID.Widget.CheckBox;import androID.Widget.ImageVIEw;import androID.Widget.TextVIEw;public class AddShortcutsAdapter extends BaseAdapter { private ArrayList<ShortcutsEntity> mShortcuts; private final LayoutInflater mInflater; private Context mContext; public static ArrayList<Boolean> isChecked; public AddShortcutsAdapter(ArrayList<ShortcutsEntity> shortcuts,Context context) { mShortcuts = shortcuts; mContext = context; mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); isChecked = new ArrayList<Boolean>(); int size = mShortcuts.size(); for(int i=0;i<size;i++){ isChecked.add(false); } } public int getCount() { if(mShortcuts!=null){ return mShortcuts.size(); } return 0; } public Object getItem(int arg0) { if(mShortcuts!=null){ return mShortcuts.get(arg0); } return null; } public long getItemID(int arg0) { return 0; } public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) { VIEwHolder holder = null; ShortcutsEntity entity = mShortcuts.get(position); if(convertVIEw==null){ holder = new VIEwHolder(); convertVIEw = mInflater.inflate(R.layout.add_shortcuts_adapter,parent,false); holder.imageVIEw = (ImageVIEw) convertVIEw.findVIEwByID(R.ID.sc_icon); holder.textVIEw = (TextVIEw) convertVIEw.findVIEwByID(R.ID.sc_Title); holder.checkBox = (CheckBox) convertVIEw.findVIEwByID(R.ID.sc_checkBox); convertVIEw.setTag(holder); }else{ holder = (VIEwHolder) convertVIEw.getTag(); } if(entity!=null){ holder.textVIEw.setText(entity.Title); //Todo: Modify the picture size. holder.imageVIEw.setBackgroundDrawable(UtilitIEs.getDrawable(entity.Icon)); } if(isChecked!=null && !isChecked.isEmpty()){ holder.checkBox.setChecked(isChecked.get(position)); } return convertVIEw; } public voID setSelectItem(int item){ if(isChecked.get(item)){ isChecked.set(item,false); }else{ isChecked.set(item,true); } } private class VIEwHolder{ ImageVIEw imageVIEw; TextVIEw textVIEw; CheckBox checkBox; }}
package com.androID.launcherex;import androID.content.pm.ResolveInfo;import androID.graphics.drawable.Drawable;public class ShortcutsEntity { public CharSequence Title; public Drawable Icon; public ResolveInfo Info;}
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <ImageVIEw androID:ID="@+ID/sc_icon" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParenttop="true" androID:layout_alignParentleft="true" androID:layout_marginleft="6dip"/> <TextVIEw androID:ID="@+ID/sc_Title" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParenttop="true" androID:layout_toRightOf="@+ID/sc_icon" androID:layout_marginleft="4dip"/> <CheckBox androID:ID="@+ID/sc_checkBox" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParenttop="true" androID:layout_alignParentRight="true" androID:focusable="false" androID:layout_marginRight="6dip"/></relativeLayout>
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <ListVIEw androID:ID="@+ID/shortcuts_List" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_alignParentleft="true" androID:layout_alignParenttop="true" androID:layout_above="@+ID/shortcuts_layout" /> <linearLayout androID:ID="@+ID/shortcuts_layout" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal" androID:layout_alignParentleft="true" androID:layout_alignParentBottom="true" > <button androID:ID="@+ID/shortcuts_add" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="1" androID:text="@string/shortcuts_add_text"/> <button androID:ID="@+ID/shortcuts_cancel" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="1" androID:text="@string/shortcuts_cancel_text" /> </linearLayout></relativeLayout>
最后在Launcher.java的onActivityResult方法中添加如下代码,即大功告成
Bundle bundle = data.getExtras(); ArrayList<Intent> intents = (ArrayList<Intent>) bundle.getSerializable("intents"); if (intents != null && !intents.isEmpty()) { int size = intents.size(); for (int i = 0; i < size; i++) { mAddItemCellinfo = new CellLayout.Cellinfo(); // Shortcut to solve the problem of overlapPing completeAddApplication(this,intents.get(i),mAddItemCellinfo); } } break;
总结 以上是内存溢出为你收集整理的Android2.2 Luncher2扩展(仿Ipad DockBar、HTC预览图、批量添加快捷方式、启用3D效果等)全部内容,希望文章能够帮你解决Android2.2 Luncher2扩展(仿Ipad DockBar、HTC预览图、批量添加快捷方式、启用3D效果等)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)