主题+所有应用+手机卫士

2018-05-16  本文已影响0人  小妮詪拽

主题................................................................................................................................................

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >

<TextView

style="@style/mystyle" android:text="SIM卡变更" android:textColor="#00ff00" />

<TextView

style="@style/mystyle" android:text="GPS追踪"/>

<TextView

style="@style/mystyle" android:text="远程销毁数据"/>

<TextView

style="@style/mystyle" android:text="远程锁屏"/>

<TextView

android:layout_width="wrap_content" android:layout_height="wrap_content" style="@android:style/TextAppearance.DeviceDefault" android:text="远程锁屏"/>

/<LinearLayout>

所有应用......................................................................................................................

public class MainActivity extends Activity { private ListView lv_main;//列表控件 private Listdata;//数据源,数据的结合 private AppAdapter adapter;//适配器 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv_main=(ListView) findViewById(R.id.lv_main); data=getAllAppInfos(); adapter = new AppAdapter(); //显示列表 lv_main.setAdapter(adapter); //给listView设置Item的点击监听 lv_main.setOnItemClickListener(new OnItemClickListener() { /*parent * view 当前视图行的Item视图对象 * position 当前行的下标 * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long) */ @Override public void onItemClick(AdapterView?parent, View view, int position, long id) { // 显示当前行的应用名称 String appName = data.get(position).getAppName(); //提示 Toast.makeText(MainActivity.this, appName, Toast.LENGTH_SHORT).show(); } }); //给listview设置Item的长按监听 lv_main.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView?parent, View view, int position, long id) { /** * 删除当前行 * 删除当前行的数据 */ data.remove(position); //更新列表 // adapter.notifyDataSetChanged();//通知适配器更新列表,使用所有缓存的Item的视图对象 return true; } }); } /* * 得到手机中所有应用信息的列表 * AppInfo * Drawable icon 图片对象 * String appName 应用名称 * String packageName */ protected ListgetAllAppInfos() { Listlist = new ArrayList(); // 得到应用的packgeManager PackageManager packageManager = getPackageManager(); // 创建一个主界面的intent Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); // 得到包含应用信息的列表 List ResolveInfos = packageManager.queryIntentActivities( intent, 0); // 遍历 for (ResolveInfo ri : ResolveInfos) { // 得到包名 String packageName = ri.activityInfo.packageName; // 得到图标 Drawable icon = ri.loadIcon(packageManager); // 得到应用名称 String appName 

手机卫士.......................................................................................................................................

所有应用public class MainActivity extends Activity { private ListView lv_main;//列表控件 private Listdata;//数据源,数据的结合 private AppAdapter adapter;//适配器 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv_main=(ListView) findViewById(R.id.lv_main); data=getAllAppInfos(); adapter = new AppAdapter(); //显示列表 lv_main.setAdapter(adapter); //给listView设置Item的点击监听 lv_main.setOnItemClickListener(new OnItemClickListener() { /*parent * view 当前视图行的Item视图对象 * position 当前行的下标 * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long) */ @Override public void onItemClick(AdapterView?parent, View view, int position, long id) { // 显示当前行的应用名称 String appName = data.get(position).getAppName(); //提示 Toast.makeText(MainActivity.this, appName, Toast.LENGTH_SHORT).show(); } }); //给listview设置Item的长按监听 lv_main.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView?parent, View view, int position, long id) { /** * 删除当前行 * 删除当前行的数据 */ data.remove(position); //更新列表 // adapter.notifyDataSetChanged();//通知适配器更新列表,使用所有缓存的Item的视图对象 return true; } }); } /* * 得到手机中所有应用信息的列表 * AppInfo * Drawable icon 图片对象 * String appName 应用名称 * String packageName */ protected ListgetAllAppInfos() { Listlist = new ArrayList(); // 得到应用的packgeManager PackageManager packageManager = getPackageManager(); // 创建一个主界面的intent Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); // 得到包含应用信息的列表 ListResolveInfos = packageManager.queryIntentActivities( intent, 0); // 遍历 for (ResolveInfo ri : ResolveInfos) { // 得到包名 String packageName = ri.activityInfo.packageName; // 得到图标 Drawable icon = ri.loadIcon(packageManager); // 得到应用名称 String appName = ri.loadLabel(packageManager).toString(); // 封装应用信息对象 AppInfo appInfo = new AppInfo(icon, appName, packageName); // 添加到list list.add(appInfo); } return list; } class AppAdapter extends BaseAdapter{ @Override public int getCount() { // TODO Auto-generated method stub return data.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return data.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } //返回带数据当前行的Item视图对象 @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; // 如果convertView是null,加载Item的布局文件 if (convertView==null) { convertView = View.inflate(MainActivity.this, R.layout.item, null); holder = new ViewHolder(); //得到当前行需要更新的子view对象 holder.imageView = (ImageView) convertView.findViewById(R.id.lv_item_icon); holder.textView = (TextView) convertView.findViewById(R.id.tv_item_name); convertView.setTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); } //得到当前行数据对象 AppInfo appInfo =data.get(position); //给视图绑定数据 holder.imageView.setImageDrawable(appInfo.getIcon()); holder.textView.setText(appInfo.getAppName()); //返回convertView return convertView; } class ViewHolder{ ImageView imageView; TextView textView; } } }package com.example.app03_all;import android.graphics.drawable.Drawable;/** * 应用信息的封装类 * @author Administrator * */public class AppInfo { private Drawable icon; private String appName; private String packageName;//包名 public AppInfo() { super(); } public AppInfo(Drawable icon, String appName, String packageName) { super(); this.icon = icon; this.appName = appName; this.packageName = packageName; } public Drawable getIcon() { return icon; } public void setIcon(Drawable icon) { this.icon = icon; } public String getAppName() { return appName; } public void setAppName(String appName) { this.appName = appName; } public String getPackageName() { return packageName; } public void setPackageName(String packageName) { this.packageName = packageName; } } ?xml version="1.0" encoding="utf-8"?

<RelativeLayout

mlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent" >   

<ImageView

android:id="@+id/lv_item_icon"       android:layout_width="wrap_content"       android:layout_height="wrap_content"        android:src="@drawable/ic_launcher"        />

<TextView

android:id="@+id/tv_item_name"       android:layout_width="wrap_content"       android:layout_height="wrap_content"              android:layout_toRightOf="@+id/lv_item_icon"        android:text="应用名称"        android:textSize="20sp" />

</RelativeLayout>

上一篇下一篇

猜你喜欢

热点阅读