1、给Launcher添加DockBar
2、修改Launcher长安AllApps的预览图
(1、2两点请参考何明桂何兄的博客,地址分别为:http://blog.csdn.net/hmg25/article/details/6289438 http://blog.csdn.net/hmg25/article/details/6289725)DockBar的实现,何兄只提供了竖屏,我在其博客的评论中看到不少人说是要实现横屏,下面我将我的实现帖出来。主要是修改layout-land/launcher.xml文件,以下是这个文件的全部代码:
- <spanstyle="font-size:18px;"><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">
- <includelayout="@layout/all_apps"/>
- <!--Theworkspacecontains3screensofcells-->
- <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">
- <includeandroid:id="@+id/cell1"layout="@layout/workspace_screen"/>
- <includeandroid:id="@+id/cell2"layout="@layout/workspace_screen"/>
- <includeandroid:id="@+id/cell3"layout="@layout/workspace_screen"/>
- <includeandroid:id="@+id/cell4"layout="@layout/workspace_screen"/>
- <includeandroid: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
- style="@style/HotseatButton"
- 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"
- style="@style/HotseatButton.Left"
- android:src="@drawable/hotseat_phone"
- android:visibility="gone"
- android:onClick="launchHotSeat"
- />
- <ImageView
- android:id="@+id/hotseat_right"
- style="@style/HotseatButton.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>
- </span>
3、启用3D效果
3D效果启动很简单,只需要将all_apps.xml文件下的
<include layout="@layout/all_apps_2d" />改为:
<include layout="@layout/all_apps_3d" />
即可。当然你可能还需要对图标做一些调整。我主要是调整了一下几个参数:
- <spanstyle="font-size:18px;">publicstaticfinalintICON_WIDTH_PX=64;
- publicstaticfinalintICON_TEXTURE_WIDTH_PX=74;
- publicstaticfinalintSELECTION_TEXTURE_WIDTH_PX=74+20;
- publicstaticfinalintICON_HEIGHT_PX=64;
- publicstaticfinalintICON_TEXTURE_HEIGHT_PX=74;
- publicstaticfinalintSELECTION_TEXTURE_HEIGHT_PX=74+20;</span>
4、替换应用程序图标
主要是在IconCache中做了以下修改。修改的只是Launcher上显示的图标,长按Home键显示最近开启的应用时,图标还是原先默认的图标,这些就自己去改吧。- <spanstyle="font-size:18px;">privateCacheEntrycacheLocked(ComponentNamecomponentName,ResolveInfoinfo){
- CacheEntryentry=mCache.get(componentName);
- if(entry==null){
- entry=newCacheEntry();
- 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);
- }
- returnentry;
- }
- /**
- *ReplacethedefaultLaunchericon
- *@paraminfo
- *@return
- */
- privateBitmapsuBIcon(ResolveInfoinfo){
- Drawabledrawable=null;
- Stringpname=info.activityInfo.packageName;
- if(pname.equals(Constant.PACKAGE_VIDEOPLAYER)){
- drawable=mResources.getDrawable(R.drawable.lu_videoplayer);
- }elseif(pname.equals(Constant.PACKAGENAME_BROWSER)){
- drawable=mResources.getDrawable(R.drawable.lu_browser);
- }elseif(pname.equals(Constant.PACKAGE_CALCULATOR)){
- drawable=mResources.getDrawable(R.drawable.lu_calculator2);
- }elseif(pname.equals(Constant.PACKAGE_CALENDAR)){
- drawable=mResources.getDrawable(R.drawable.lu_calendar);
- }elseif(pname.equals(Constant.PACKAGE_CAMERA)){
- drawable=mResources.getDrawable(R.drawable.lu_camera);
- }elseif(pname.equals(Constant.PACKAGE_CLOCK)){
- drawable=mResources.getDrawable(R.drawable.lu_alarmclock);
- }elseif(pname.equals(Constant.PACKAGE_EMAIL)){
- drawable=mResources.getDrawable(R.drawable.lu_email);
- }elseif(pname.equals(Constant.PACKAGE_GALLERY)){
- drawable=mResources.getDrawable(R.drawable.lu_gallery);
- }elseif(pname.equals(Constant.PACKAGE_MUSIC)){
- drawable=mResources.getDrawable(R.drawable.lu_music);
- }elseif(pname.equals(Constant.PACKAGE_SETTINGS)){
- drawable=mResources.getDrawable(R.drawable.lu_settings);
- }
- if(drawable!=null){
- returnUtilities.createIconBitmap(drawable,mContext);
- }else{
- returnUtilities.createIconBitmap(info.activityInfo.loadIcon(mPackageManager),mContext);
- }
- }</span>
5、批量添加快捷方式
操作:长按桌面 -- Add to Home Screen点击Applications即显示所有安装应用程序列表。可任意选择多个应用程序的快捷方式添加到Launcher上。1、Activity类:AddShortcutsActivity 主要用于显示安装应用程序信息和添加操作界面
2、列表适配: AddShortcutsAdapter 继承BaseAdapter。
3、快捷方式实体类:ShortcutsEntity
4、add_shortcuts_adapter.xml
5、add_shortcuts.xml
直接上代码:
- <spanstyle="font-size:18px;">packagecom.android.launcherex;
- importjava.util.ArrayList;
- importjava.util.List;
- importandroid.app.Activity;
- importandroid.content.Intent;
- importandroid.content.pm.ActivityInfo;
- importandroid.content.pm.PackageManager;
- importandroid.content.pm.ResolveInfo;
- importandroid.os.Bundle;
- importandroid.os.Parcelable;
- importandroid.util.Log;
- importandroid.view.View;
- importandroid.view.View.OnClickListener;
- importandroid.widget.AdapterView;
- importandroid.widget.AdapterView.OnItemClickListener;
- importandroid.widget.Button;
- importandroid.widget.ListView;
- importcom.android.launcher.R;
- publicclassAddShortcutsActivityextendsActivityimplementsOnClickListener,OnItemClickListener{
- privateAddShortcutsAdaptermShortcutsAdapter;
- privatefinalstaticStringTAG="AddShortcutsActivity";
- privateListViewlstShortcuts;
- privateButtonbtnAddShortcuts;
- privateButtonbtnCancelShortcuts;
- privateArrayList<ShortcutsEntity>mShortcutsEntity=newArrayList<ShortcutsEntity>();
- @Override
- protectedvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.add_shortcuts);
- setupViews();
- }
- privatevoidsetupViews(){
- 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=newAddShortcutsAdapter(mShortcutsEntity,this);
- lstShortcuts.setAdapter(mShortcutsAdapter);
- }
- publicvoidonClick(Viewarg0){
- switch(arg0.getId()){
- caseR.id.shortcuts_add:
- ArrayList<Intent>intents=getSelectedShortcuts();
- Intentintent=getIntent();
- //Readbaseintentfromextras,otherwiseassumedefault
- Parcelableparcel=intent.getParcelableExtra(Intent.EXTRA_INTENT);
- if(parcelinstanceofIntent){
- intent=(Intent)parcel;
- }else{
- intent=newIntent(Intent.ACTION_MAIN,null);
- intent.addCategory(Intent.CATEGORY_DEFAULT);
- }
- Bundlebundle=newBundle();
- bundle.putSerializable("intents",intents);
- intent.putExtras(bundle);
- setResult(Activity.RESULT_OK,intent);
- finish();
- break;
- caseR.id.shortcuts_cancel:
- finish();
- break;
- }
- }
- /**
- *Getalltheapplications
- *@return
- */
- privateArrayList<ShortcutsEntity>getAllShortcuts(){
- ArrayList<ShortcutsEntity>entitys=newArrayList<ShortcutsEntity>();
- Intentintent=newIntent(Intent.ACTION_MAIN);
- intent.addCategory(Intent.CATEGORY_LAUNCHER);
- PackageManagermPackageManager=this.getPackageManager();
- List<ResolveInfo>mAllApps=mPackageManager.queryIntentActivities(intent,0);
- intsize=mAllApps.size();
- for(inti=0;i<size;i++){
- ShortcutsEntityentity=newShortcutsEntity();
- ResolveInforesolveInfo=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
- returnentitys;
- }
- publicvoidonItemClick(AdapterView<?>arg0,Viewarg1,intarg2,longarg3){
- mShortcutsAdapter.setSelectItem(arg2);
- mShortcutsAdapter.notifyDataSetChanged();
- }
- /**
- *Beenselectedshortcuts
- *@return
- */
- privateArrayList<Intent>getSelectedShortcuts(){
- ArrayList<Intent>selecteds=newArrayList<Intent>();
- ArrayList<Boolean>isCheck=AddShortcutsAdapter.isChecked;
- intcheckSize=isCheck.size();
- for(inti=0;i<checkSize;i++){
- if(isCheck.get(i)){
- ShortcutsEntityentity=mShortcutsEntity.get(i);
- ActivityInfoactivityInfo=entity.Info.activityInfo;
- Intentintent=newIntent();
- intent.setClassName(activityInfo.applicationInfo.packageName,activityInfo.name);
- selecteds.add(intent);
- Log.i(TAG,"selecteditem.name="+mShortcutsEntity.get(i).Title);
- }
- }
- returnselecteds;
- }
- }
- </span>
- <spanstyle="font-size:18px;">packagecom.android.launcherex;
- importjava.util.ArrayList;
- importcom.android.launcher.R;
- importandroid.content.Context;
- importandroid.view.LayoutInflater;
- importandroid.view.View;
- importandroid.view.ViewGroup;
- importandroid.widget.BaseAdapter;
- importandroid.widget.CheckBox;
- importandroid.widget.ImageView;
- importandroid.widget.TextView;
- publicclassAddShortcutsAdapterextendsBaseAdapter{
- privateArrayList<ShortcutsEntity>mShortcuts;
- privatefinalLayoutInflatermInflater;
- privateContextmContext;
- publicstaticArrayList<Boolean>isChecked;
- publicAddShortcutsAdapter(ArrayList<ShortcutsEntity>shortcuts,Contextcontext)
- {
- mShortcuts=shortcuts;
- mContext=context;
- mInflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- isChecked=newArrayList<Boolean>();
- intsize=mShortcuts.size();
- for(inti=0;i<size;i++){
- isChecked.add(false);
- }
- }
- publicintgetCount(){
- if(mShortcuts!=null){
- returnmShortcuts.size();
- }
- return0;
- }
- publicObjectgetItem(intarg0){
- if(mShortcuts!=null){
- returnmShortcuts.get(arg0);
- }
- returnnull;
- }
- publiclonggetItemId(intarg0){
- return0;
- }
- publicViewgetView(intposition,ViewconvertView,ViewGroupparent){
- ViewHolderholder=null;
- ShortcutsEntityentity=mShortcuts.get(position);
- if(convertView==null){
- holder=newViewHolder();
- 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:Modifythepicturesize.
- holder.imageView.setBackgroundDrawable(Utilities.getDrawable(entity.Icon));
- }
- if(isChecked!=null&&!isChecked.isEmpty()){
- holder.checkBox.setChecked(isChecked.get(position));
- }
- returnconvertView;
- }
- publicvoidsetSelectItem(intitem){
- if(isChecked.get(item)){
- isChecked.set(item,false);
- }else{
- isChecked.set(item,true);
- }
- }
- privateclassViewHolder{
- ImageViewimageView;
- TextViewtextView;
- CheckBoxcheckBox;
- }
- }
- </span>
- <spanstyle="font-size:18px;">packagecom.android.launcherex;
- importandroid.content.pm.ResolveInfo;
- importandroid.graphics.drawable.Drawable;
- publicclassShortcutsEntity{
- publicCharSequenceTitle;
- publicDrawableIcon;
- publicResolveInfoInfo;
- }
- </span>
- <spanstyle="font-size:18px;"><?xmlversion="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>
- </span>
- <spanstyle="font-size:18px;"><?xmlversion="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>
- </span>
最后在Launcher.java的onActivityResult方法中添加如下代码,即大功告成
- <spanstyle="font-size:18px;">Bundlebundle=data.getExtras();
- ArrayList<Intent>intents=(ArrayList<Intent>)bundle.getSerializable("intents");
- if(intents!=null&&!intents.isEmpty()){
- intsize=intents.size();
- for(inti=0;i<size;i++){
- mAddItemCellInfo=newCellLayout.CellInfo();//Shortcuttosolvetheproblemofoverlapping
- completeAddApplication(this,intents.get(i),mAddItemCellInfo);
- }
- }
- break;</span>