Android自定义简易luancherDemo(有图有真相哦)
来源:互联网 发布:网上淘宝贷款是真的吗 编辑:程序博客网 时间:2024/06/06 03:46
就两个界面,一个是所有程序,一个是开机动画设置,还有设置壁纸。
比较粗糙,因为项目停滞,所以就没有继续开发,在此分享一下,望高手莫喷。
有些代码是网上摘抄,找不到出处了,原作者莫怪咯!
效果图:
项目结构:
HomeActivity.java(所有程序界面)
1 package com.bvin.demo.launcher; 2 3 import java.util.List; 4 5 import android.app.Activity; 6 import android.content.ComponentName; 7 import android.content.Intent; 8 import android.content.pm.ResolveInfo; 9 import android.os.Bundle; 10 import android.util.Log; 11 import android.view.Menu; 12 import android.view.MenuItem; 13 import android.view.View; 14 import android.view.ViewGroup; 15 import android.widget.AdapterView; 16 import android.widget.BaseAdapter; 17 import android.widget.GridView; 18 import android.widget.ImageView; 19 20 public class HomeActivity extends Activity { 21 /** Called when the activity is first created. */ 22 23 List<ResolveInfo> mApp; 24 GridView mGrid; 25 26 @Override 27 public void onCreate(Bundle savedInstanceState) { 28 super.onCreate(savedInstanceState); 29 loadApps(); 30 setContentView(R.layout.main); 31 initsViews(); 32 } 33 34 35 36 @Override 37 public boolean onCreateOptionsMenu(Menu menu) { 38 // TODO Auto-generated method stub 39 menu.add(0, 0, 0, "设置壁纸"); 40 menu.add(0, 1, 1, "开机动画"); 41 return super.onCreateOptionsMenu(menu); 42 } 43 44 45 46 @Override 47 public boolean onOptionsItemSelected(MenuItem item) { 48 // TODO Auto-generated method stub 49 switch(item.getItemId()){ 50 51 case 0: 52 onSetWallPaper(); 53 break; 54 case 1: 55 Intent intent = new Intent(HomeActivity.this,SetActivity.class); 56 startActivity(intent); 57 break; 58 59 } 60 61 return super.onOptionsItemSelected(item); 62 } 63 64 65 66 void loadApps(){ 67 Intent mainIntent = new Intent(Intent.ACTION_MAIN,null); 68 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 69 mApp = this.getPackageManager().queryIntentActivities(mainIntent, 0); 70 Log.e("mApp", ""+mApp.size()); 71 } 72 73 void initsViews(){ 74 mGrid = (GridView)findViewById(R.id.appGrid); 75 mGrid.setAdapter(new AppsAdapter()); 76 77 mGrid.setOnItemClickListener(new GridView.OnItemClickListener(){ 78 79 @Override 80 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 81 long arg3) { 82 // TODO Auto-generated method stub 83 ResolveInfo info = mApp.get(arg2); 84 String pkg = info.activityInfo.packageName; 85 String cls = info.activityInfo.name; 86 ComponentName compoment = new ComponentName(pkg,cls); 87 Intent i = new Intent(); 88 i.setComponent(compoment); 89 startActivity(i); 90 } 91 92 }); 93 } 94 95 void onSetWallPaper(){ 96 97 Intent pickWallPager = new Intent(Intent.ACTION_SET_WALLPAPER); 98 Intent chooser = Intent.createChooser(pickWallPager, "chooser_wallpaper"); 99 startActivity(chooser);100 }101 102 class AppsAdapter extends BaseAdapter{103 104 @Override105 public int getCount() {106 // TODO Auto-generated method stub107 return mApp.size();108 }109 110 @Override111 public Object getItem(int position) {112 // TODO Auto-generated method stub113 return mApp.get(position);114 }115 116 @Override117 public long getItemId(int position) {118 // TODO Auto-generated method stub119 return position;120 }121 122 @Override123 public View getView(int position, View convertView, ViewGroup parent) {124 // TODO Auto-generated method stub125 ImageView i;126 if(convertView==null){127 i = new ImageView(HomeActivity.this);128 i.setScaleType(ImageView.ScaleType.FIT_CENTER);129 i.setLayoutParams(new GridView.LayoutParams(70, 70));130 131 }else{132 i = (ImageView)convertView;133 }134 ResolveInfo info = mApp.get(position);135 i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));136 return i;137 }138 139 140 }141 }
SettingActivity(开机动画设置界面)
1 package com.bvin.demo.launcher; 2 3 import java.io.DataOutputStream; 4 import java.io.File; 5 import java.io.FileNotFoundException; 6 import java.io.FileOutputStream; 7 import java.io.IOException; 8 import java.io.InputStream; 9 import java.io.OutputStream; 10 11 import android.app.Activity; 12 import android.app.ProgressDialog; 13 import android.os.Bundle; 14 import android.util.Log; 15 import android.view.View; 16 import android.widget.Button; 17 import android.widget.Toast; 18 19 public class SetActivity extends Activity{ 20 21 Button btDell; 22 Button byMi; 23 String apkRoot="chmod 777 /system/media"; 24 @Override 25 protected void onCreate(Bundle savedInstanceState) { 26 // TODO Auto-generated method stub 27 super.onCreate(savedInstanceState); 28 setContentView(R.layout.setwallpaper_layout); 29 initViews(); 30 } 31 32 void initViews(){ 33 btDell = (Button)findViewById(R.id.btDell); 34 byMi = (Button)findViewById(R.id.btMis1); 35 36 btDell.setOnClickListener(new View.OnClickListener() { 37 38 @Override 39 public void onClick(View v) { 40 // TODO Auto-generated method stub 41 try { 42 if(rootConmmand(apkRoot)){ 43 write2System(R.raw.dell); 44 setTitle("当前开机动画为戴尔原生动画"); 45 }else{ 46 Toast.makeText(SetActivity.this, "未获取root权限", Toast.LENGTH_SHORT).show(); 47 } 48 49 } catch (FileNotFoundException e) { 50 // TODO Auto-generated catch block 51 e.printStackTrace(); 52 } 53 } 54 }); 55 byMi.setOnClickListener(new View.OnClickListener() { 56 57 @Override 58 public void onClick(View v) { 59 // TODO Auto-generated method stub 60 try { 61 if(rootConmmand(apkRoot)){ 62 rootConmmand("chmod 777 /system/media/bootanimation.zip"); 63 write2System(R.raw.mi); 64 setTitle("当前开机动画为小米开机动画"); 65 }else{ 66 Toast.makeText(SetActivity.this, "未获取root权限", Toast.LENGTH_SHORT).show(); 67 } 68 } catch (FileNotFoundException e) { 69 // TODO Auto-generated catch block 70 e.printStackTrace(); 71 } 72 } 73 }); 74 75 } 76 77 public static boolean rootConmmand(String cmd){ 78 79 Process process = null; 80 DataOutputStream os = null; 81 82 try { 83 process = Runtime.getRuntime().exec("su"); 84 os = new DataOutputStream(process.getOutputStream()); 85 os.writeBytes(cmd+"\n"); 86 os.writeBytes("exit\n"); 87 os.flush(); 88 process.waitFor(); 89 90 } catch (IOException e) { 91 // TODO Auto-generated catch block 92 Log.d("*** DEBUG ***", "ROOT REE" + e.getMessage()); 93 e.printStackTrace(); 94 } catch (InterruptedException e) { 95 // TODO Auto-generated catch block 96 e.printStackTrace(); 97 }finally{ 98 99 try {100 if(os!=null){101 os.close();102 }103 process.destroy();104 } catch (IOException e) {105 // TODO Auto-generated catch block106 e.printStackTrace();107 }108 }109 Log.d("*** DEBUG ***", "Root SUC ");110 return true;111 }112 113 private void write2System(int src) throws FileNotFoundException{114 115 ProgressDialog pd = new ProgressDialog(this);116 pd.show();117 InputStream is = this.getResources().openRawResource(src);118 OutputStream os = null;119 File file = new File("/system/media","bootanimation.zip");120 121 os = new FileOutputStream(file);122 123 124 byte[] buf = null;125 int length;126 try {127 buf = new byte[1024];128 while((length=is.read(buf))!=-1){129 os.write(buf, 0, length);130 Log.e("写", ""+length);131 132 }133 } catch (IOException e) {134 // TODO Auto-generated catch block135 e.printStackTrace();136 }finally{137 if(is!=null){138 try {139 is.close();140 } catch (IOException e) {141 // TODO Auto-generated catch block142 e.printStackTrace();143 }144 }145 146 }147 rootConmmand("chmod 777 /system/media/bootanimation.zip");148 Log.e("dfg", "ok");149 pd.dismiss();150 Toast.makeText(this, "开机动画安装成功,可重启查看效果", Toast.LENGTH_LONG).show();151 152 }153 154 }
没有挂载为读写
加上mount -rw -o remount /dev/block/mmcblk0p4 /system
- Android自定义简易luancherDemo(有图有真相哦)
- Android自定义简易luancherDemo(有图有真相哦)
- android 自定义日历控件(有图有真相)
- Android自定义简易照相机
- Android 开发环境配置(有图有真相)
- Android自定义简易时间选择器
- Android ImageView.ScaleType有图有真相
- android自定义控件(二),简易的数值输入器
- Android Gallery 3D效果(有图有真相)
- android的第一个程序helloworld (有图有真相)
- Android自定义效果 简易示波器 (1)
- android自定义组件的简易实现
- Android 一个简易的自定义软键盘
- [Android]自定义简易版日历控件
- android 自定义控件 简易时间轴
- android 自定义控件 简易时间轴
- Android简易自定义日历控件实践
- android 自定义控件 简易时间轴 二
- Flashcache bypass: disabled Flashcache setup error is : ioctl failed 解决办法
- Androidの多线程之HandlerThread
- Androidの循环之常用循环积累
- Javaの算法之Fibonacci Sequence
- Androidの权限之平台签名
- Android自定义简易luancherDemo(有图有真相哦)
- AndroidのUI之Spinner箭头效果
- Androidの遇到的问题集合之MaginPadding
- C语言文件读写函数——fputc和fgetc
- Androidの多线程之数Looper通信
- Androidの多线程之更新ui(Thread+Handler+Message)
- Androidの多线程之更新ui(AsyncTask)
- Androidの多线程之Handler创建新线程
- Androidの多线程之多线程用法大集合(未整理)