android launcher 源码 自己开发启动桌面
/*5k桌面 源码
作者:基哥
AndroidManifest.xml重要配置:
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
壁纸背景(三选一):
android:theme="@android:style/Theme.Wallpaper"
android:theme="@android:style/Theme.Wallpaper.NoTitleBar"
android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"
*/
package l.l;
import android.app.*;
import android.content.*;
import android.content.pm.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.widget.AdapterView.*;
import java.util.*;
import android.util.*;
import android.net.*;
import android.provider.*;
public class l extends Activity {
GridView g;
private List<ResolveInfo> apps;
int w,h,p;
Context c;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Wallpaper_NoTitleBar);
/*
在AndroidManifest.xml添加
android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"
再用setTheme,就型成一种启动效果
*/
if(Build.VERSION.SDK_INT==Build.VERSION_CODES.KITKAT)
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(0x00000000);
}
c=this;
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
w = metric.widthPixels;
h = metric.heightPixels;
p=w/60;
apps = getPackageManager().queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER), 0);
g = new GridView(this);
g.setAdapter(new AppsAdapter());
g.setOnItemLongClickListener(new OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView<?> a, View v, int i, long l)
{
String s=apps.get(i).activityInfo.packageName;
Intent localIntent = new Intent();
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= 9) {
localIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
localIntent.setData(Uri.fromParts("package", s, null));
} else if (Build.VERSION.SDK_INT <= 8) {
localIntent.setAction(Intent.ACTION_VIEW);
localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
localIntent.putExtra("com.android.settings.ApplicationPkgName", s);
}
startActivity(localIntent);
return true;
}
});
g.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
ActivityInfo a=apps.get(i).activityInfo;
startActivity(new Intent().setComponent(new ComponentName(a.packageName, a.name)));
}
});
g.setNumColumns(5);
addContentView(g,new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
}
public class AppsAdapter extends BaseAdapter {
@Override
public int getCount() {
return apps.size();
}
@Override
public Object getItem(int i) {
return apps.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int in, View view, ViewGroup viewGroup) {
app a;
if(view == null){
a = new app();
ImageView i;
LinearLayout l;
TextView t;
l=new LinearLayout(c);
l.setOrientation(LinearLayout.VERTICAL);
l.setGravity(Gravity.CENTER);
i = new ImageView(c);
i.setPadding(p,p,p,p);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new GridView.LayoutParams(w/6, w/6));
l.addView(i);
t=new TextView(c);
t.setMaxLines(1);
t.setGravity(Gravity.CENTER);
l.addView(t);
a.i=i;
a.t=t;
view=l;
view.setTag(a);
} else {
a=(app) view.getTag();
}
ActivityInfo app=apps.get(in).activityInfo;
a.i.setImageDrawable(app.loadIcon(getPackageManager()));
a.t.setText(app.loadLabel(getPackageManager()));
return view;
}
class app
{
ImageView i;
TextView t;
}
}
} 不明觉厉{:1_908:}
页:
[1]