在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例Android平台开发 → android 手机小卫士完整源码下载

android 手机小卫士完整源码下载

Android平台开发

下载此实例
  • 开发语言:Java
  • 实例大小:10.93M
  • 下载次数:26
  • 浏览次数:258
  • 发布时间:2014-10-20
  • 实例类别:Android平台开发
  • 发 布 人:14726932514
  • 文件格式:.rar
  • 所需积分:2
 相关标签:

实例介绍

【实例简介】手机卫士源码,内涵apk,源码,密钥,关键地方含有注释

【实例截图】

【核心代码】

部分代码如下:


package com.mowen.mobilesafe;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.StatFs;
import android.text.format.Formatter;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.mowen.mobilesafe.domain.AppInfo;
import com.mowen.mobilesafe.engine.AppInfoProvider;
import com.mowen.mobilesafe.utils.DensityUtil;
/**
 * ============================================================
 * 
 * 版权 :手机卫士    版权所有 (c) 2014
 * 
 * 作者:mowen
 * 
 * 版本 :1.0
 * 
 * 创建日期 : 2014-9-10 上午12:45
 * 
 * 描述 :软件管理
 * 
 * 修订历史 :
 * 
 * ============================================================
 **/
public class AppManagerActivity extends Activity implements OnClickListener {
	private static final String TAG = "AppManagerActivity";
	private TextView tv_avail_rom;
	private TextView tv_avail_sd;
	private ListView lv_appmanager;
	private LinearLayout ll_loading;
	private List<AppInfo> appInfos;
	private TextView tv_status;

	private LinearLayout ll_start;
	private LinearLayout ll_share;
	private LinearLayout ll_uninstall;
	
	
	/**
	 * 被点击的条目
	 */
	private AppInfo appInfo;

	/**
	 * 用户程序集合
	 */
	private List<AppInfo> userAppInfos;

	/**
	 * 系统程序集合
	 */
	private List<AppInfo> systemAppInfos;

	private PopupWindow popupWindow;

	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			ll_loading.setVisibility(View.GONE);
			lv_appmanager.setAdapter(new AppInfoAdapter());
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_app_manager);
		tv_avail_rom = (TextView) findViewById(R.id.tv_avail_rom);
		tv_avail_sd = (TextView) findViewById(R.id.tv_avail_sd);
		tv_avail_sd.setText("SD卡可用:"
				  getTotalSpace(Environment.getExternalStorageDirectory()
						.getAbsolutePath()));
		tv_avail_rom.setText("内存可用:"
				  getTotalSpace(Environment.getDataDirectory()
						.getAbsolutePath()));
		lv_appmanager = (ListView) findViewById(R.id.lv_appmanager);
		tv_status = (TextView) findViewById(R.id.tv_status);

		lv_appmanager.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Object obj = lv_appmanager.getItemAtPosition(position);
				if (obj != null) {
					dismissPopupWindow();
					appInfo = (AppInfo) obj;
					View contentView = View.inflate(getApplicationContext(),
							R.layout.popup_item, null);
					ll_uninstall = (LinearLayout) contentView
							.findViewById(R.id.ll_uninstall);
					ll_start = (LinearLayout) contentView
							.findViewById(R.id.ll_start);
					ll_share = (LinearLayout) contentView
							.findViewById(R.id.ll_share);
					ll_share.setOnClickListener(AppManagerActivity.this);
					ll_start.setOnClickListener(AppManagerActivity.this);
					ll_uninstall.setOnClickListener(AppManagerActivity.this);

					// 播放动画有一个前提 就是窗体必须有背景
					popupWindow = new PopupWindow(contentView,
							LayoutParams.WRAP_CONTENT,
							LayoutParams.WRAP_CONTENT);
					// ☆ 注意: 必须要设置背景
					popupWindow.setBackgroundDrawable(new ColorDrawable(
							Color.TRANSPARENT));
					int[] location = new int[2];
					view.getLocationInWindow(location);
					//根据手机手机的分辨率 把60dip 转化成 不同的值 px
					int px = DensityUtil.dip2px(getApplicationContext(), 60);
					popupWindow.showAtLocation(parent, Gravity.TOP
							  Gravity.LEFT, px, location[1]);
					AlphaAnimation aa = new AlphaAnimation(0.5f, 1.0f);
					aa.setDuration(200);
					ScaleAnimation sa = new ScaleAnimation(0.5f, 1.0f, 0.5f,
							1.0f, Animation.RELATIVE_TO_SELF, 0,
							Animation.RELATIVE_TO_SELF, 0.5f);
					sa.setDuration(200);
					AnimationSet set = new AnimationSet(false);
					set.addAnimation(sa);
					set.addAnimation(aa);
					contentView.startAnimation(set);
				}

			}
		});
		// tv_status.setPadding(0, 0, 0, 0);
		lv_appmanager.setOnScrollListener(new OnScrollListener() {
			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {

			}

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				dismissPopupWindow();
				if (userAppInfos != null && systemAppInfos != null) {
					if (firstVisibleItem > userAppInfos.size()) {
						tv_status.setText("系统程序("   systemAppInfos.size()   ")");
					} else {
						tv_status.setText("用户程序("   userAppInfos.size()   ")");
					}
				}
			}
		});

		ll_loading = (LinearLayout) findViewById(R.id.ll_loading);

		fillData();

	}

	private void fillData() {
		ll_loading.setVisibility(View.VISIBLE);
		new Thread() {
			public void run() {
				appInfos = AppInfoProvider.getAppInfos(getApplicationContext());
				userAppInfos = new ArrayList<AppInfo>();
				systemAppInfos = new ArrayList<AppInfo>();
				for (AppInfo appinfo : appInfos) {
					if (appinfo.isUserApp()) {
						userAppInfos.add(appinfo);
					} else {
						systemAppInfos.add(appinfo);
					}
				}

				handler.sendEmptyMessage(0);
			};
		}.start();
	}

	/**
	 * 获取某个路径可用的空间
	 * 
	 * @param path
	 * @return
	 */
	public String getTotalSpace(String path) {
		StatFs stat = new StatFs(path);
		long count = stat.getAvailableBlocks();
		long size = stat.getBlockSize();
		return Formatter.formatFileSize(this, count * size);
	}

	private void dismissPopupWindow() {
		if (popupWindow != null && popupWindow.isShowing()) {
			popupWindow.dismiss();
			popupWindow = null;
		}
	}

	private class AppInfoAdapter extends BaseAdapter {
		@Override
		public int getCount() {
			// 多了两个textview的item 所以  1  1
			return userAppInfos.size()   1   systemAppInfos.size()   1;
		}

		// 控制每个位置显示的内容。
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			final AppInfo appInfo;

			if (position == 0) {// 显示一个textview告诉用户有多少个用户应用
				TextView tv = new TextView(getApplicationContext());
				tv.setText("用户程序  ("   userAppInfos.size()   ")");
				tv.setTextColor(Color.WHITE);
				tv.setBackgroundColor(Color.GRAY);
				return tv;
			} else if (position == (userAppInfos.size()   1)) {
				TextView tv = new TextView(getApplicationContext());
				tv.setText("系统程序  ("   systemAppInfos.size()   ")");
				tv.setTextColor(Color.WHITE);
				tv.setBackgroundColor(Color.GRAY);
				return tv;
			} else if (position <= userAppInfos.size()) {
				// 用户程序。
				int newposition = position - 1;
				appInfo = userAppInfos.get(newposition);
			} else {
				// 系统程序
				int newposition = position - 1 - userAppInfos.size() - 1;
				appInfo = systemAppInfos.get(newposition);
			}
			View view;
			ViewHolder holder;
			if (convertView != null && convertView instanceof RelativeLayout) {
				view = convertView;
				holder = (ViewHolder) view.getTag();
			} else {
				view = View.inflate(getApplicationContext(),
						R.layout.list_app_item, null);
				holder = new ViewHolder();
				holder.iv = (ImageView) view.findViewById(R.id.iv_icon);
				holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
				holder.tv_location = (TextView) view
						.findViewById(R.id.tv_location);
				view.setTag(holder);
				holder.bt_uninstall = (Button) view.findViewById(R.id.bt_uninstall);
			}
			holder.tv_location.setTextColor(Color.GRAY);
			holder.iv.setImageDrawable(appInfo.getIcon());
			holder.tv_name.setText(appInfo.getName());
			if (appInfo.isInRom()) {
				holder.tv_location.setText("手机内存");
			} else {
				holder.tv_location.setText("外部存储卡");
			}
			holder.bt_uninstall.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					uninstall(appInfo);
				}
			});
			
			return view;
		}

		@Override
		public Object getItem(int position) {
			AppInfo appInfo;
			if (position == 0) {// 显示一个textview告诉用户有多少个用户应用
				return null;
			} else if (position == (userAppInfos.size()   1)) {
				return null;
			} else if (position <= userAppInfos.size()) {
				// 用户程序。
				int newposition = position - 1;
				appInfo = userAppInfos.get(newposition);
			} else {
				// 系统程序
				int newposition = position - 1 - userAppInfos.size() - 1;
				appInfo = systemAppInfos.get(newposition);
			}
			return appInfo;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

	}

	static class ViewHolder {
		ImageView iv;
		TextView tv_name;
		TextView tv_location;
		Button bt_uninstall;
	}

	@Override
	public void onClick(View v) {
		dismissPopupWindow();
		switch (v.getId()) {
		case R.id.ll_share:
			Log.i(TAG, "分享:"   appInfo.getName());
			shareApplication();
			break;
		case R.id.ll_start:
			Log.i(TAG, "启动:"   appInfo.getName());
			startApplication();
			break;
		case R.id.ll_uninstall:
			Log.i(TAG, "卸载:"   appInfo.getName());
			uninstall(appInfo);
			break;
		}
	}
	
	
	/**
	 * 开启应用
	 */
	private void startApplication() {
		Intent intent = new Intent();
		String packname = appInfo.getPackname();
		PackageManager pm = getPackageManager();
		try {
			PackageInfo  packinfo = pm.getPackageInfo(packname, PackageManager.GET_ACTIVITIES);
			ActivityInfo[] activityInfos = packinfo.activities;
			if(activityInfos!=null&&activityInfos.length>0){
				ActivityInfo activityinfo = activityInfos[0];
				intent.setClassName(packname, activityinfo.name);
				startActivity(intent);
			}else{
				Toast.makeText(this, "哎呀,这个应用程序没界面", 0).show();
			}
		} catch (NameNotFoundException e) {
			e.printStackTrace();
			Toast.makeText(this, "没法开这个应用。", 0).show();
		}
	}

	/**
	 * 分享应用程序
	 */
	private void shareApplication() {
		Intent intent = new Intent();
		// <action android:name="android.intent.action.SEND" />
		// <category android:name="android.intent.category.DEFAULT" />
		// <data android:mimeType="text/plain" />
		intent.setAction("android.intent.action.SEND");
		intent.addCategory("android.intent.category.DEFAULT");
		intent.setType("text/plain");
		intent.putExtra(Intent.EXTRA_TEXT,
				"推荐你使用一个软件,软件的名称叫:"  appInfo.getName()
						  ",下载地址:https://play.google.com/store/apps/details?id=" appInfo.getPackname());
		startActivity(intent);
	}

	private void uninstall(AppInfo appInfo) {
		if (appInfo.isUserApp()) {
			Intent intent = new Intent();
			intent.setAction(Intent.ACTION_DELETE);
			intent.addCategory(Intent.CATEGORY_DEFAULT);
			intent.setData(Uri.parse("package:"   appInfo.getPackname()));
			startActivityForResult(intent, 0);
		} else {
			Toast.makeText(this, "系统应用需要有root权限后才能卸载", 0).show();
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		fillData();
	}
}


标签:

实例下载地址

android 手机小卫士完整源码下载

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警