Android2.2 Luncher2扩展(仿Ipad DockBar、HTC预览图、批量添加快捷方式、启用3D效果等)

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文件,以下是这个文件的全部代码:

  1. <span style="font-size:18px;"><com.android.launcherex.DragLayer  
  2.     xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"  
  4.   
  5.     android:id="@+id/drag_layer"  
  6.     android:layout_width="match_parent"  
  7.     android:layout_height="match_parent">  
  8.   
  9.     <include layout="@layout/all_apps" />  
  10.   
  11.     <!-- The workspace contains 3 screens of cells -->  
  12.     <com.android.launcherex.Workspace  
  13.         android:id="@+id/workspace"  
  14.         android:layout_width="match_parent"  
  15.         android:layout_height="match_parent"  
  16.         android:scrollbars="horizontal"  
  17.         android:fadeScrollbars="true"  
  18.         launcher:defaultScreen="2">  
  19.   
  20.         <include android:id="@+id/cell1" layout="@layout/workspace_screen" />  
  21.         <include android:id="@+id/cell2" layout="@layout/workspace_screen" />  
  22.         <include android:id="@+id/cell3" layout="@layout/workspace_screen" />  
  23.         <include android:id="@+id/cell4" layout="@layout/workspace_screen" />  
  24.         <include android:id="@+id/cell5" layout="@layout/workspace_screen" />  
  25.   
  26.     </com.android.launcherex.Workspace>  
  27.   
  28.   
  29.     <RelativeLayout   
  30.         android:id="@+id/dock_layout"  
  31.         android:layout_gravity="bottom|left"  
  32.         android:layout_width="match_parent"  
  33.         android:layout_height="95dip"  
  34.         >  
  35.         <com.android.launcherex.ClippedImageView  
  36.             android:id="@+id/previous_screen"  
  37.             android:layout_width="93dip"  
  38.             android:layout_height="@dimen/button_bar_height"  
  39.             android:layout_alignParentTop="true"  
  40.             android:layout_alignParentLeft="true"  
  41.             android:layout_marginLeft="6dip"  
  42.             android:scaleType="center"  
  43.             android:src="@drawable/home_arrows_left"  
  44.             android:onClick="previousScreen"  
  45.             launcher:ignoreZone="56dip"  
  46.             android:focusable="true"  
  47.             android:clickable="true" />  
  48.       
  49.         <com.android.launcherex.ClippedImageView  
  50.             android:id="@+id/next_screen"  
  51.             android:layout_width="93dip"  
  52.             android:layout_height="@dimen/button_bar_height"  
  53.             android:layout_alignParentTop="true"  
  54.             android:layout_alignParentRight="true"  
  55.             android:layout_marginRight="6dip"  
  56.             android:scaleType="center"  
  57.             android:src="@drawable/home_arrows_right"  
  58.             android:onClick="nextScreen"  
  59.             launcher:ignoreZone="-56dip"  
  60.             android:focusable="true"  
  61.             android:clickable="true" />  
  62.       
  63.         <com.android.launcherex.DeleteZone  
  64.             android:id="@+id/delete_zone"  
  65.             android:layout_width="@dimen/delete_zone_size"  
  66.             android:layout_height="@dimen/delete_zone_size"  
  67.             android:paddingLeft="@dimen/delete_zone_padding"  
  68.             android:layout_marginBottom="@dimen/dock_bar_height"  
  69.             android:layout_alignParentBottom="true"  
  70.             android:layout_centerHorizontal="true"  
  71.       
  72.             android:scaleType="center"  
  73.             android:src="@drawable/delete_zone_selector"  
  74.             android:visibility="invisible"  
  75.             launcher:direction="vertical"  
  76.             />  
  77.       
  78.         <RelativeLayout  
  79.             android:id="@+id/all_apps_button_cluster"  
  80.             android:layout_height="fill_parent"  
  81.             android:layout_width="@dimen/button_bar_height_portrait"  
  82.             android:layout_gravity="bottom|center_vertical"  
  83.             android:layout_marginBottom="@dimen/half_status_bar_height"  
  84.             >  
  85.       
  86.            <!-- <com.android.launcherex.HandleView  
  87.                 style="@style/HotseatButton"  
  88.                 android:id="@+id/all_apps_button"  
  89.                 android:layout_centerVertical="true"  
  90.                 android:layout_alignParentRight="true"  
  91.       
  92.                 android:src="@drawable/all_apps_button"  
  93.                 launcher:direction="vertical"  
  94.                 />-->  
  95.     <!-- android:layout_below="@id/all_apps_button" -->  
  96.     <!--  android:layout_above="@id/all_apps_button" -->  
  97.             <ImageView  
  98.                 android:id="@+id/hotseat_left"  
  99.                 style="@style/HotseatButton.Left"  
  100.       
  101.                 android:src="@drawable/hotseat_phone"  
  102.                 android:visibility="gone"  
  103.                 android:onClick="launchHotSeat"  
  104.                 />  
  105.       
  106.             <ImageView  
  107.                 android:id="@+id/hotseat_right"  
  108.                 style="@style/HotseatButton.Right"  
  109.                android:visibility="gone"  
  110.                 android:src="@drawable/hotseat_browser"  
  111.                 android:onClick="launchHotSeat"  
  112.                 />  
  113.         </RelativeLayout>  
  114.         <com.android.launcherex.DockBar  
  115.             android:id="@+id/dockbar"   
  116.             android:layout_width="fill_parent"  
  117.             android:layout_height="@dimen/button_bar_height"  
  118.             android:background="@drawable/dock_bg"  
  119.             android:layout_alignParentBottom="true"  
  120.             launcher:direction="horizontal">  
  121.               
  122.             <HorizontalScrollView   
  123.                 android:id="@+id/dock_scroll_view"  
  124.                 android:scrollbars="none"  
  125.                 android:fadingEdge="none"  
  126.                 android:saveEnabled="false"   
  127.                 android:layout_width="fill_parent"  
  128.                 android:layout_height="fill_parent">  
  129.                 <LinearLayout   
  130.                     android:orientation="horizontal"  
  131.                     android:id="@+id/dock_item_holder"   
  132.                     android:saveEnabled="false"  
  133.                     android:layout_width="fill_parent"   
  134.                     android:layout_height="fill_parent">  
  135.                     <com.android.launcherex.HandleView  
  136.                         android:id="@+id/all_apps_button"   
  137.                         android:layout_centerVertical="true"  
  138.                         android:src="@drawable/all_apps_button"   
  139.                         launcher:direction="horizontal"  
  140.                         android:layout_width="fill_parent"   
  141.                         android:layout_height="fill_parent"  
  142.                         android:focusable="true"   
  143.                         android:clickable="true" />  
  144.                 </LinearLayout>  
  145.             </HorizontalScrollView>  
  146.         </com.android.launcherex.DockBar>  
  147.     </RelativeLayout>  
  148. </com.android.launcherex.DragLayer>  
  149. </span>  

3、启用3D效果

3D效果启动很简单,只需要将all_apps.xml文件下的

<include layout="@layout/all_apps_2d" />改为:

<include layout="@layout/all_apps_3d" />

即可。当然你可能还需要对图标做一些调整。我主要是调整了一下几个参数:

  1. <span style="font-size:18px;">        public static final int ICON_WIDTH_PX = 64;  
  2.         public static final int ICON_TEXTURE_WIDTH_PX = 74;  
  3.         public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;  
  4.   
  5.         public static final int ICON_HEIGHT_PX = 64;  
  6.         public static final int ICON_TEXTURE_HEIGHT_PX = 74;  
  7.         public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;</span>  

4、替换应用程序图标

主要是在IconCache中做了以下修改。修改的只是Launcher上显示的图标,长按Home键显示最近开启的应用时,图标还是原先默认的图标,这些就自己去改吧。
  1. <span style="font-size:18px;">private CacheEntry cacheLocked(ComponentName componentName, ResolveInfo info) {  
  2.         CacheEntry entry = mCache.get(componentName);  
  3.         if (entry == null) {  
  4.             entry = new CacheEntry();  
  5.             mCache.put(componentName, entry);  
  6.             entry.title = info.loadLabel(mPackageManager).toString();  
  7.             if (entry.title == null) {  
  8.                 entry.title = info.activityInfo.name;  
  9.             }  
  10.            // entry.icon = Utilities.createIconBitmap(info.activityInfo.loadIcon(mPackageManager), mContext);  
  11.               
  12.             entry.icon = suBIcon(info);  
  13.         }  
  14.         return entry;  
  15.     }  
  16.       
  17.     /** 
  18.      * Replace the default Launcher icon 
  19.      * @param info 
  20.      * @return 
  21.      */  
  22.     private Bitmap suBIcon(ResolveInfo info){  
  23.         Drawable drawable = null;  
  24.         String pname = info.activityInfo.packageName;  
  25.           
  26.         if(pname.equals(Constant.PACKAGE_VIDEOPLAYER)){  
  27.             drawable = mResources.getDrawable(R.drawable.lu_videoplayer);  
  28.         }else if(pname.equals(Constant.PACKAGENAME_BROWSER)){  
  29.             drawable = mResources.getDrawable(R.drawable.lu_browser);  
  30.         }else if(pname.equals(Constant.PACKAGE_CALCULATOR)){  
  31.             drawable = mResources.getDrawable(R.drawable.lu_calculator2);  
  32.         }else if(pname.equals(Constant.PACKAGE_CALENDAR)){  
  33.             drawable = mResources.getDrawable(R.drawable.lu_calendar);  
  34.         }else if(pname.equals(Constant.PACKAGE_CAMERA)){  
  35.             drawable = mResources.getDrawable(R.drawable.lu_camera);  
  36.         }else if(pname.equals(Constant.PACKAGE_CLOCK)){  
  37.             drawable = mResources.getDrawable(R.drawable.lu_alarmclock);  
  38.         }else if(pname.equals(Constant.PACKAGE_EMAIL)){  
  39.             drawable = mResources.getDrawable(R.drawable.lu_email);  
  40.         }else if(pname.equals(Constant.PACKAGE_GALLERY)){  
  41.             drawable = mResources.getDrawable(R.drawable.lu_gallery);  
  42.         }else if(pname.equals(Constant.PACKAGE_MUSIC)){  
  43.             drawable = mResources.getDrawable(R.drawable.lu_music);  
  44.         }else if(pname.equals(Constant.PACKAGE_SETTINGS)){  
  45.             drawable = mResources.getDrawable(R.drawable.lu_settings);  
  46.         }  
  47.           
  48.         if(drawable!=null){  
  49.             return Utilities.createIconBitmap(drawable, mContext);  
  50.         }else{  
  51.             return Utilities.createIconBitmap(info.activityInfo.loadIcon(mPackageManager), mContext);  
  52.         }  
  53.     }</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

直接上代码:

  1. <span style="font-size:18px;">package com.android.launcherex;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import android.app.Activity;  
  7. import android.content.Intent;  
  8. import android.content.pm.ActivityInfo;  
  9. import android.content.pm.PackageManager;  
  10. import android.content.pm.ResolveInfo;  
  11. import android.os.Bundle;  
  12. import android.os.Parcelable;  
  13. import android.util.Log;  
  14. import android.view.View;  
  15. import android.view.View.OnClickListener;  
  16. import android.widget.AdapterView;  
  17. import android.widget.AdapterView.OnItemClickListener;  
  18. import android.widget.Button;  
  19. import android.widget.ListView;  
  20.   
  21. import com.android.launcher.R;  
  22.   
  23. public class AddShortcutsActivity extends Activity implements OnClickListener,OnItemClickListener{  
  24.   
  25.     private AddShortcutsAdapter mShortcutsAdapter;  
  26.       
  27.     private final static String TAG = "AddShortcutsActivity";  
  28.       
  29.     private ListView lstShortcuts;  
  30.     private Button btnAddShortcuts;  
  31.     private Button btnCancelShortcuts;  
  32.       
  33.     private ArrayList<ShortcutsEntity> mShortcutsEntity = new ArrayList<ShortcutsEntity>();  
  34.       
  35.     @Override  
  36.     protected void onCreate(Bundle savedInstanceState) {  
  37.         super.onCreate(savedInstanceState);  
  38.         setContentView(R.layout.add_shortcuts);  
  39.           
  40.         setupViews();  
  41.     }  
  42.       
  43.     private void setupViews(){  
  44.         lstShortcuts = (ListView) findViewById(R.id.shortcuts_list);  
  45. //      lstShortcuts.setItemsCanFocus(false);  
  46.         lstShortcuts.setChoiceMode(ListView.CHOICE_MODE_SINGLE);   
  47.           
  48.         btnAddShortcuts = (Button) findViewById(R.id.shortcuts_add);  
  49.         btnCancelShortcuts=(Button) findViewById(R.id.shortcuts_cancel);  
  50.           
  51.         btnAddShortcuts.setOnClickListener(this);  
  52.         btnCancelShortcuts.setOnClickListener(this);  
  53.         lstShortcuts.setOnItemClickListener(this);  
  54.           
  55.         mShortcutsEntity = getAllShortcuts();  
  56.           
  57.         mShortcutsAdapter = new AddShortcutsAdapter(mShortcutsEntity,this);  
  58.         lstShortcuts.setAdapter(mShortcutsAdapter);  
  59.           
  60.     }  
  61.   
  62.     public void onClick(View arg0) {  
  63.         switch(arg0.getId()){  
  64.         case R.id.shortcuts_add:  
  65.               
  66.             ArrayList<Intent> intents = getSelectedShortcuts();  
  67.             Intent intent = getIntent();  
  68.             // Read base intent from extras, otherwise assume default  
  69.             Parcelable parcel = intent.getParcelableExtra(Intent.EXTRA_INTENT);  
  70.               
  71.             if (parcel instanceof Intent) {  
  72.                 intent = (Intent) parcel;  
  73.             } else {  
  74.                 intent = new Intent(Intent.ACTION_MAIN, null);  
  75.                 intent.addCategory(Intent.CATEGORY_DEFAULT);  
  76.             }  
  77.               
  78.             Bundle bundle = new Bundle();  
  79.             bundle.putSerializable("intents", intents);  
  80.             intent.putExtras(bundle);  
  81.               
  82.             setResult(Activity.RESULT_OK,intent);  
  83.               
  84.               
  85.             finish();  
  86.               
  87.             break;  
  88.         case R.id.shortcuts_cancel:  
  89.             finish();  
  90.             break;  
  91.         }  
  92.     }  
  93.       
  94.     /** 
  95.      * Get all the applications 
  96.      * @return 
  97.      */  
  98.     private ArrayList<ShortcutsEntity> getAllShortcuts(){  
  99.           
  100.         ArrayList<ShortcutsEntity> entitys = new ArrayList<ShortcutsEntity>();  
  101.           
  102.         Intent intent = new Intent(Intent.ACTION_MAIN);  
  103.         intent.addCategory(Intent.CATEGORY_LAUNCHER);  
  104.           
  105.         PackageManager mPackageManager = this.getPackageManager();  
  106.         List<ResolveInfo> mAllApps = mPackageManager.queryIntentActivities(intent, 0);  
  107.           
  108.         int size = mAllApps.size();  
  109.           
  110.         for(int i=0;i<size;i++){  
  111.               
  112.             ShortcutsEntity entity = new ShortcutsEntity();  
  113.             ResolveInfo resolveInfo = mAllApps.get(i);  
  114.             entity.Title = resolveInfo.loadLabel(mPackageManager);  
  115.             entity.Icon = resolveInfo.loadIcon(mPackageManager);  
  116.             entity.Info = resolveInfo;  
  117.             entitys.add(entity);  
  118.               
  119.             Log.i(TAG, "entity.Title="+resolveInfo.loadLabel(mPackageManager));  
  120.         }  
  121.           
  122.         //TODO: sort  
  123.           
  124.         return entitys;  
  125.     }  
  126.   
  127.     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {  
  128.         mShortcutsAdapter.setSelectItem(arg2);  
  129.         mShortcutsAdapter.notifyDataSetChanged();  
  130.     }  
  131.       
  132.     /** 
  133.      * Been selected shortcuts 
  134.      * @return 
  135.      */  
  136.     private ArrayList<Intent> getSelectedShortcuts(){  
  137.           
  138.         ArrayList<Intent> selecteds = new ArrayList<Intent>();  
  139.           
  140.         ArrayList<Boolean> isCheck = AddShortcutsAdapter.isChecked;  
  141.         int checkSize =  isCheck.size();  
  142.         for(int i=0;i<checkSize;i++){  
  143.             if(isCheck.get(i)){  
  144.                 ShortcutsEntity entity = mShortcutsEntity.get(i);  
  145.                 ActivityInfo activityInfo = entity.Info.activityInfo;  
  146.                 Intent intent = new Intent();  
  147.                 intent.setClassName(activityInfo.applicationInfo.packageName,activityInfo.name);  
  148.                 selecteds.add(intent);  
  149.                 Log.i(TAG, "selected item.name="+mShortcutsEntity.get(i).Title);  
  150.             }  
  151.         }  
  152.           
  153.         return selecteds;  
  154.     }  
  155. }  
  156. </span>  

  1. <span style="font-size:18px;">package com.android.launcherex;  
  2.   
  3. import java.util.ArrayList;  
  4.   
  5. import com.android.launcher.R;  
  6.   
  7. import android.content.Context;  
  8. import android.view.LayoutInflater;  
  9. import android.view.View;  
  10. import android.view.ViewGroup;  
  11. import android.widget.BaseAdapter;  
  12. import android.widget.CheckBox;  
  13. import android.widget.ImageView;  
  14. import android.widget.TextView;  
  15.   
  16. public class AddShortcutsAdapter extends BaseAdapter {  
  17.   
  18.     private ArrayList<ShortcutsEntity> mShortcuts;  
  19.     private final LayoutInflater mInflater;  
  20.     private Context mContext;  
  21.     public static ArrayList<Boolean> isChecked;  
  22.       
  23.     public AddShortcutsAdapter(ArrayList<ShortcutsEntity> shortcuts,Context context)  
  24.     {  
  25.         mShortcuts = shortcuts;  
  26.         mContext = context;  
  27.         mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  28.           
  29.         isChecked = new ArrayList<Boolean>();  
  30.           
  31.         int size = mShortcuts.size();  
  32.         for(int i=0;i<size;i++){  
  33.             isChecked.add(false);  
  34.         }  
  35.     }  
  36.       
  37.     public int getCount() {  
  38.         if(mShortcuts!=null){  
  39.             return mShortcuts.size();  
  40.         }  
  41.         return 0;  
  42.     }  
  43.   
  44.     public Object getItem(int arg0) {  
  45.         if(mShortcuts!=null){  
  46.             return mShortcuts.get(arg0);  
  47.         }  
  48.         return null;  
  49.     }  
  50.   
  51.     public long getItemId(int arg0) {  
  52.         return 0;  
  53.     }  
  54.   
  55.     public View getView(int position, View convertView, ViewGroup parent) {  
  56.           
  57.         ViewHolder holder = null;  
  58.         ShortcutsEntity entity = mShortcuts.get(position);  
  59.           
  60.         if(convertView==null){  
  61.             holder = new ViewHolder();  
  62.             convertView = mInflater.inflate(R.layout.add_shortcuts_adapter, parent, false);  
  63.               
  64.             holder.imageView = (ImageView) convertView.findViewById(R.id.sc_icon);  
  65.             holder.textView = (TextView) convertView.findViewById(R.id.sc_title);  
  66.             holder.checkBox = (CheckBox) convertView.findViewById(R.id.sc_checkbox);  
  67.               
  68.             convertView.setTag(holder);  
  69.         }else{  
  70.             holder = (ViewHolder) convertView.getTag();  
  71.         }  
  72.           
  73.         if(entity!=null){  
  74.             holder.textView.setText(entity.Title);  
  75.             //TODO: Modify the picture size.  
  76.             holder.imageView.setBackgroundDrawable(Utilities.getDrawable(entity.Icon));  
  77.         }  
  78.           
  79.         if(isChecked!=null && !isChecked.isEmpty()){  
  80.             holder.checkBox.setChecked(isChecked.get(position));  
  81.         }  
  82.           
  83.         return convertView;  
  84.     }  
  85.       
  86.     public void setSelectItem(int item){  
  87.         if(isChecked.get(item)){  
  88.             isChecked.set(item, false);  
  89.         }else{  
  90.             isChecked.set(item,true);  
  91.         }  
  92.     }  
  93.       
  94.     private class ViewHolder{  
  95.         ImageView imageView;  
  96.         TextView textView;  
  97.         CheckBox checkBox;  
  98.     }  
  99. }  
  100. </span>  

  1. <span style="font-size:18px;">package com.android.launcherex;  
  2.   
  3. import android.content.pm.ResolveInfo;  
  4. import android.graphics.drawable.Drawable;  
  5.   
  6. public class ShortcutsEntity {  
  7.   
  8.     public CharSequence Title;  
  9.     public Drawable Icon;  
  10.     public ResolveInfo Info;  
  11. }  
  12. </span>  

  1. <span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout  
  3.   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.   android:orientation="vertical"  
  5.   android:layout_width="match_parent"  
  6.   android:layout_height="match_parent">  
  7.     <ImageView   
  8.         android:id="@+id/sc_icon"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:layout_alignParentTop="true"  
  12.         android:layout_alignParentLeft="true"  
  13.         android:layout_marginLeft="6dip"/>  
  14.     <TextView   
  15.         android:id="@+id/sc_title"  
  16.         android:layout_width="wrap_content"  
  17.         android:layout_height="wrap_content"  
  18.         android:layout_alignParentTop="true"  
  19.         android:layout_toRightOf="@+id/sc_icon"  
  20.         android:layout_marginLeft="4dip"/>  
  21.     <CheckBox  
  22.         android:id="@+id/sc_checkbox"  
  23.         android:layout_width="wrap_content"  
  24.         android:layout_height="wrap_content"  
  25.         android:layout_alignParentTop="true"  
  26.         android:layout_alignParentRight="true"  
  27.         android:focusable="false"  
  28.         android:layout_marginRight="6dip"/>  
  29. </RelativeLayout>  
  30. </span>  

  1. <span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout  
  3.   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.   android:orientation="vertical"  
  5.   android:layout_width="match_parent"  
  6.   android:layout_height="match_parent">  
  7.       
  8.     <ListView   
  9.         android:id="@+id/shortcuts_list"  
  10.         android:layout_width="match_parent"  
  11.         android:layout_height="wrap_content"  
  12.         android:layout_alignParentLeft="true"  
  13.         android:layout_alignParentTop="true"  
  14.         android:layout_above="@+id/shortcuts_layout"  
  15.         />  
  16.     <LinearLayout   
  17.         android:id="@+id/shortcuts_layout"  
  18.         android:layout_width="match_parent"  
  19.         android:layout_height="wrap_content"  
  20.         android:orientation="horizontal"  
  21.         android:layout_alignParentLeft="true"  
  22.         android:layout_alignParentBottom="true"  
  23.         >  
  24.         <Button   
  25.             android:id="@+id/shortcuts_add"  
  26.             android:layout_width="wrap_content"  
  27.             android:layout_height="wrap_content"  
  28.             android:layout_weight="1"  
  29.             android:text="@string/shortcuts_add_text"/>  
  30.               
  31.         <Button   
  32.             android:id="@+id/shortcuts_cancel"  
  33.             android:layout_width="wrap_content"  
  34.             android:layout_height="wrap_content"  
  35.             android:layout_weight="1"  
  36.             android:text="@string/shortcuts_cancel_text"  
  37.             />  
  38.     </LinearLayout>  
  39. </RelativeLayout>  
  40. </span>  

最后在Launcher.java的onActivityResult方法中添加如下代码,即大功告成
  1. <span style="font-size:18px;">Bundle bundle = data.getExtras();  
  2.                     ArrayList<Intent> intents = (ArrayList<Intent>) bundle.getSerializable("intents");  
  3.                       
  4.                     if (intents != null && !intents.isEmpty()) {  
  5.                         int size = intents.size();  
  6.                         for (int i = 0; i < size; i++) {  
  7.                             mAddItemCellInfo = new CellLayout.CellInfo(); // Shortcut to solve the problem of overlapping  
  8.                             completeAddApplication(this, intents.get(i),mAddItemCellInfo);  
  9.                         }  
  10.                     }  
  11.                     break;</span>  


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值