1.1. 上下文

Context

|--ContextWrapper  getBaseContext():  没有getToken();

|--Application   getApplication()  getApplicationContext(); <application标签代表上下文

一个应用只有一个 项目实战:登录成功后保存 用户名密码 (保存全局单例的变量) getToken();

|--Activity  getToken();

|--子类都可以。

|--Service

|--MockContext  Junit mContext 只在Junit 测试时用到

1.Toast  对Token 没有要求

2.Dialog  对Contex有要求  要token .只有Activity才能提供

3.View.inflate();  对Token 没有要求

Activity是一个页面,对话框可以看作Activity的一部分

android.view.WindowManager$BadTokenException:

Unable to add window -- token null is not for an application

Token  令牌  指示Dialog显示在哪个Activity

应用的范围包含  Activity Serivce  provider receiver

是一个集合。

<span style="font-size:14px;">ublic class SafeApplication extends Application{@Overridepublic void onCreate() {// TODO Auto-generated method stubsuper.onCreate();Log.i("wzx", "-onCreate--安全卫士应用的上下文-"+this);}
}<applicationandroid:name="com.itheima.mobilesafe.SafeApplication"</span>

Context 上下文

重要参数/对象的集合

getSysteService();

getPackageManger();

getApplication

2. 软件管家

需求:帮助用户 管理 已安装软件. 查看 ,分享 ,卸载

① Activity   布局 a.继承 b.重写 c.配置 d.启动

减少嵌套,可以提高性能 。

② 空间参数值 获取  内部/sd

<span style="font-size:14px;">private static String formate(Context context,long size){return Formatter.formatFileSize(context, size);}@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_soft_manager);ViewUtils.inject(this);// ① Activity 布局 a.继承 b.重写 c.配置 d.启动// ② 空间参数值 获取 内部/sd// mnt/sdcard/ Environment// data/// getFreeSpace剩余空间  23232232   KB MB Glong sizePhone = Environment.getDataDirectory().getFreeSpace();long sizeSd = Environment.getExternalStorageDirectory().getFreeSpace();space_phone.setText("手机可用 :"+formate(this, sizePhone));space_sd.setText("sd可用:"+formate(this, sizeSd));}</span>

③ 已经安装程序信息的集合。

④ flags特性参数:通常都是移位表示的类型再或的结果

最高2000人群

1<<0

00000000000000001

成长加速权

1<<1

00000000000000010

QQ等级加速

1<<2

00000000000000100

云消息加速

1<<3

00000000000001000

好友上线提醒

1<<4

00000000000010000

土豪账号

flags

1.判断是否包含某种权限

111111111111111111

跟类型 与 结果等于该类型

代表包含

00000000000000000

2.分配权限 或

0

00000000000010000|00000000000001000|00000000000000001

=

00000000000011001

00000000000000001

&

1111111111111111111

=

00000000000000001 包含

00000000000000001

&00000000000000000

=

00000000000000000不包含

00000000000011001&

00000000000010000

=

00000000000010000

00000000000000100

&

1111111111111111111

=

00000000000000100

大宝剑  flags

0001|0100|01000|010000 分配

=011111

011111 &0001==0001 有

加攻击 1<<1

加敏捷 1<<2

加力量 1<<3

加智力 1<<4

<span style="font-size:14px;">public static List<ApkInfo> findAll(Context context) {List<ApkInfo> list = new ArrayList<ApkInfo>();// 必须获取包管理者PackageManager pm = context.getPackageManager();// 获取安装程序集合List<PackageInfo> packages = pm.getInstalledPackages(0);// 默认值 flags// PackageInfo-->ApkInfofor (PackageInfo info : packages) {ApkInfo bean = new ApkInfo();// 图标ApplicationInfo applicationInfo = info.applicationInfo;bean.appIcon = applicationInfo.loadIcon(pm);// 获取小图标// 名称bean.appName = applicationInfo.loadLabel(pm).toString();// 获取应用名bean.packagename = info.packageName;// 位置bean.path = applicationInfo.sourceDir;// system/app data/app// 大小File apk = new File(bean.path);bean.apkSize = apk.length();// 当flags通过与指定类型的常量 做与 操作 结果等待该常量 代表包含//安装位置if ((applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo.FLAG_EXTERNAL_STORAGE) {bean.isInPhone = false;} else {bean.isInPhone = true;}//用户 or 系统if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM) {bean.isSystem = true;} else {bean.isSystem = false;}//添加集合list.add(bean);}return list;}</span>

⑤ 复杂ListView  a.Listview显示集合的列表控件 b.初始化集合  c.创建内容适配器

<span style="font-size:14px;">private class ApkAdapter extends BaseAdapter {// 总行数据@Overridepublic int getCount() {return 2 + userapps.size() + systemapps.size();}// 普通列表 :只一种行视图 1// 复杂列表:有两种以上的行视图@Overridepublic int getViewTypeCount() {return 2; // 两个类 0 标题 1 应用信息}// 返回指定下标的视图类型@Overridepublic int getItemViewType(int position) {// --->给getView使用if (position == 0)// 下标是第一个{return 0;// 标题}if (position == (1 + userapps.size())) // 第二个标签{return 0;// 标题}return 1;}// 返回指定下标的数据对象@Overridepublic Object getItem(int position) {return null;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn 0;}// 返回行视图 显示指定下标的数据@Overridepublic View getView(int position, View convertView, ViewGroup parent) {int type = getItemViewType(position);if (type == 0)// 标题{return View.inflate(getBaseContext(), R.layout.view_type_title, null);} else {return View.inflate(getBaseContext(), R.layout.view_item_soft_info, null);}}</span>

⑥ 复杂ListView的优化

<span style="font-size:14px;">/ 返回行视图 显示指定下标的数据// 优化上跟普通列表 一样// 代码量是普通列表的N倍class ViewHolder {public TextView type_title;public ImageView icon;public Button uninstall;public TextView apk_size;public TextView appname;public TextView location;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {int type = getItemViewType(position);if (type == 0)// 标题{View view = null;ViewHolder holder = null;if (convertView == null) {view = View.inflate(getBaseContext(), R.layout.view_type_title, null);holder = new ViewHolder();holder.type_title = (TextView) view.findViewById(R.id.type_title);view.setTag(holder);// 把ViewHolder绑定在View} else {view = convertView;holder = (ViewHolder) view.getTag();// 从View获取Holder}// 设置值if (position == 0) {holder.type_title.setText("用户程序(" + userapps.size() + ")");} else if (position == (1 + userapps.size())) {holder.type_title.setText("系统程序(" + systemapps.size() + ")");}return view;} else {// view ----startViewHolder holder;View view = null;if (convertView == null){view = View.inflate(getBaseContext(), R.layout.view_item_soft_info, null);holder = new ViewHolder();// findViewById 从 Activity setContentView// view.findViewById 从viewc对象条目holder.icon = (ImageView) view.findViewById(R.id.icon);holder.uninstall = (Button) view.findViewById(R.id.uninstall);holder.apk_size = (TextView) view.findViewById(R.id.apk_size);holder.location = (TextView) view.findViewById(R.id.location);holder.appname = (TextView) view.findViewById(R.id.appname);view.setTag(holder);} else {view = convertView;holder = (ViewHolder) view.getTag();}// view ----end// 取出数据ApkInfo info = (ApkInfo) getItem(position);if (info != null) {// 设置值holder.icon.setImageDrawable(info.appIcon);holder.appname.setText(info.appName);if (info.isInPhone) {holder.location.setText("手机内部");} else {holder.location.setText("sd卡");}holder.location.setVisibility(info.isSystem ? View.INVISIBLE : View.VISIBLE);holder.apk_size.setText(formate(getBaseContext(), info.apkSize));}return view;}}// 返回指定下标的数据对象@Overridepublic Object getItem(int position) {if (position >= 1 && position <= userapps.size()) {// 取得用户程序信息return userapps.get(position - 1);} else if (position >= (2 + userapps.size())) {// 取得系统程序信息return systemapps.get(position - 2 - userapps.size());}return null;}</span>

⑦ 获取应用名的拼音

jpinyin-1.0.jar 汉字转拼音的开发库

PinYinHelper

汉字转拼音

PinyinFormat

声调

1.带声调

2.不带声调

String text="今天你看段子了吗?";

//09-18 07:04:15.342: I/wzx(7856): jīntiānnǐkànduànzǐlema?

//09-18 07:04:48.048: I/wzx(7979): jintiannikanduanzilema?

//String result=PinyinHelper.convertToPinyinString(汉字, 分割符,格式);

String result=PinyinHelper.convertToPinyinString(text, "",PinyinFormat.WITHOUT_TONE);

Log.i("wzx", result);

⑧ 如何进行排序

Collections

集合工具类  排序

Comparator

比较器 接口  代表是一种标准

ALIBABA

DONGGUANG

排序

Comparator<ApkInfo>  cmp=new Comparator<ApkInfo>() {

@Override

public int compare(ApkInfo lhs, ApkInfo rhs) {

return lhs.pinyin.compareTo(rhs.pinyin);

}

};

Collections.sort(userapps,cmp);

Collections.sort(systemapps,cmp);

⑨ 滚动显示首字母

a.布局 首字母

b.OnScollListner  显示 隐藏  更新值

<!--         fastScrollEnabled滑动显示 --><ListViewandroid:fastScrollEnabled="true"listview.setOnScrollListener(new OnScrollListener() {// 状态改变// 1.拖动// 2.惯性滑动// 3.空闲private boolean isScroll = false;@Overridepublic void onScrollStateChanged(AbsListView view, int scrollState) {// first_letterswitch (scrollState) {case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:first_letter.setVisibility(View.VISIBLE);isScroll = true;break;case OnScrollListener.SCROLL_STATE_FLING://只调用一次break;case OnScrollListener.SCROLL_STATE_IDLE:first_letter.setVisibility(View.GONE);isScroll = false;break;}}@Overridepublic void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {if (isScroll) {Log.i("wzx", "---onScroll-");ApkInfo bean = (ApkInfo) adapter.getItem(firstVisibleItem);if (bean != null) {// 应用程序信息 用户与 系统String letter = bean.pinyin.substring(0, 1);first_letter.setText(letter);first_letter.setVisibility(View.VISIBLE);} else {first_letter.setVisibility(View.GONE);}}}});

⑩ 操作菜单

Dialog

将视图弹出显示的对象

1.居中

2.背景变暗

PopupWindow

将视图弹出显示的对象

指定位置坐标弹出

a. 布局弹出内容

b. 创建弹出PopupWindow

c. 获取坐标  弹出

<span style="font-size:14px;">listview.setOnItemClickListener(new ListView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {// TODO Auto-generated method stubLog.i("wzx", "###onItemClick "+position);if(popupWindow!=null){popupWindow.dismiss();popupWindow=null;}//
//              a.布局弹出内容View viewPop=View.inflate(getBaseContext(), R.layout.view_pop_menu, null);
//              b.创建弹出PopupWindow
//              PopupWindow  popupWindow=new PopupWindow(弹出视图, 宽, 高);popupWindow=new PopupWindow(viewPop,//LinearLayout.LayoutParams.WRAP_CONTENT, //layout_widhtLinearLayout.LayoutParams.WRAP_CONTENT);//layout_height//响应返回键popupWindow.setFocusable(true);//获取焦点返回键自动生效popupWindow.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));//支持视图以外范围的点击关闭popupWindow.setOutsideTouchable(true);
//              c.获取坐标  弹出int[] location=new int[2];view.getLocationOnScreen(location);popupWindow.showAtLocation(view, Gravity.LEFT|Gravity.TOP, location[0]+70, location[1]-10);}});</span>

11 使用PackageManager获取已经安装应用

12 隐式意图的调用 1.分享 2.卸载 3.详情 4.启动

a.启动   Intent:意图  打开Actvity或者Service.2.Map传值

// Action Main category Launch-Intent

// 包管理者

PackageManager pm = getPackageManager();

Intent mainIntent = pm.getLaunchIntentForPackage(packageName);

if(mainIntent!=null)

{

startActivity(mainIntent);//启动

}else

{

//例:provider 应用contacts

Toast.makeText(getBaseContext(), "不能启动", 0).show();

}

显示意图

1.使用Class 参数

2.使用ComponentName 参数  包名+类名

隐式意图

1.使用请求参数

action 动用  cetegory类别 data数据

public void open(View view) {

// 查询功能清单里面的请求参数 action category data

// <intent-filter>

// <action android:name="itheima.intent.action.SOFT_MANAGER" />

// <category android:name="android.intent.category.DEFAULT"/>

// </intent-filter>

// 意图

Intent intent = new Intent();

intent.setAction("itheima.intent.action.SOFT_MANAGER");

intent.addCategory("android.intent.category.DEFAULT");

startActivity(intent);

}

怎么获取 Intent请求参数 使用ActivityManager(进程管理者)作 tag 过滤

a. 分享

Log.i("wzx", "share");

// <intent-filter>

//               <action android:name="android.intent.action.SEND" />

//               <category android:name="android.intent.category.DEFAULT" />

//               <data android:mimeType="text/plain" />

//           </intent-filter>

Intent intent=new Intent();

intent.setAction("android.intent.action.SEND");

intent.addCategory("android.intent.category.DEFAULT");

intent.setType("text/plain");

//Intent  1打开页面 或者服务  2.Map

intent.putExtra("sms_body", "好东西分享http://www.itheima.com/downloadapk?p="+packageName);

startActivity(intent);

b详情

// <intent-filter>

// <action

// android:name="android.settings.APPLICATION_DETAILS_SETTINGS"

// />

// <category android:name="android.intent.category.DEFAULT" />

// <data android:scheme="package" />

// </intent-filter>

Intent intent = new Intent();

intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");

intent.addCategory("android.intent.category.DEFAULT");

intent.setData(Uri.parse("package:" + packageName));

startActivity(intent);

卸载

如果应用程序 被安装器 app 卸载到 将会产生一个广播

b. 创建广播接收者

c. 设置参数

d. onReceive 调用

e. 销毁 移除

意图调用

//                <intent-filter>
//                  <action android:name="android.intent.action.VIEW" />
//                  <action android:name="android.intent.action.DELETE" />
//                  <category android:name="android.intent.category.DEFAULT" />
//                  <data android:scheme="package" />
//              </intent-filter>Intent intent=new Intent();intent.setAction("android.intent.action.DELETE");intent.addCategory("android.intent.category.DEFAULT");intent.setData(Uri.parse("package:"+packageName));startActivity(intent);query();
//      b.创建广播接收者
//      c.设置参数IntentFilter filter=new IntentFilter();filter.addAction(Intent.ACTION_PACKAGE_REMOVED);filter.addDataScheme("package");//必须加强  Scheme  http://www.baidu.com  package:包名
//      d.onReceive 调用registerReceiver(receiver, filter);
//      e.销毁 移除}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();unregisterReceiver(receiver);}private BroadcastReceiver receiver=new BroadcastReceiver(){public void onReceive(Context context, Intent intent) {if(popupWindow!=null){popupWindow.dismiss();popupWindow=null;}query();// 重新查询刷新 Toast.makeText(getBaseContext(), "卸载成功:黑马!", 0).show();};};

上下文flags特性参数复杂ListView(多种布局)获取应用名的拼音(首字母拼音滑动改变)PopupWindow相关推荐

  1. 给下拉框加上可输入查询特性,包括中文与拼音首字母

    升级版本链接地址:点击这里 js源文件: 1 var PinYin = { "a": "\u554a\u963f\u9515\u57c3\u6328\u54ce\u550 ...

  2. RecyclerView显示加载多种布局的原理

    RecyclerView是对ListView的封装,所以ListView上能用的方法对RecyclerView同样适用,并且会更简单 在实际开发中,我们可能需要一个列表,显示多种布局,getItemV ...

  3. CSS深入理解流体特性和BFC特性下多栏自适应布局

    一.块状元素的流体特性与自适应布局 块状元素像放在容器中的水流一样,内容区域会随着margin, padding, border的出现自动填满剩余空间,这就是块状元素的流体特性. 来一个小实验: di ...

  4. CSS 多种布局方式

    ​css布局是工作中最常碰到的,同时也是笔试 or 面试中会被问到的问题,故在本文整理了css多种布局方式,以供参考. 此篇较长四千五百字左右,读者可分三部分阅读,水平居中布局,垂直居中布局,水平居中 ...

  5. 光纤的特性参数有哪些?

    光纤的特性参数可以分为三大类:几何特性参数.光学特性参数与传输特性参数.包括:衰耗系数(即衰减).色散.非线性特性等. 衰耗系数(衰减) 衰耗系数是多模光纤和单模光纤最重要的特性参数之一,在很大程度上 ...

  6. 大功率继电器的工作原理是什么?解读大功率继电器特性参数

    为增进大家对大功率继电器的认识,本文将对大功率继电器的工作原理.大功率继电器的触点形式以及特性参数予以介绍. 继电器" target="_blank">大功率继电器 ...

  7. 基于Matlab的定容燃烧弹喷雾宏观特性参数获取

    喷雾宏观特性参数获取(喷雾贯穿距离.喷雾锥角.喷雾面积) 文中出现的程序只针对某一张图片,未将批处理程序完整贴出 喷雾图像处理介绍见:https://blog.csdn.net/yusuhuayu/a ...

  8. android 分组 listview,Android实现的ListView分组布局改进示例

    本文实例讲述了android实现的listview分组布局改进方法.分享给大家供大家参考,具体如下: 由于是在网上转载的一篇文章,在这里就不多说废话了,首先看一下最终的效果图: 然后是实现该listv ...

  9. [C#]Attribute特性(2)——方法的特性及特性参数

    上篇博文[C#]Attribute特性介绍了特性的定义,类的特性,字段的特性,这篇博文将介绍方法的特性及特性参数相关概念. 3.方法的特性 之所以将这部分单列出来进行讨论,是因为对方法的特性查询的反射 ...

最新文章

  1. mysql原理~undo
  2. ssm商务会员管理系统_会员管理商城开发
  3. BZOJ 3669: [Noi2014]魔法森林( LCT )
  4. 把握不好数组边界的危害(记洛谷P1789题RE+WA的经历,Java语言描述)
  5. php 函数strtr 替换函数实例解析 strtr 速度比较快
  6. linux下华为HSPA模块MU609的驱动问题
  7. python类中变量作用域_python进阶14变量作用域LEGB
  8. idea 配置maven一直停留在loading archetype list
  9. wdos相关问题解答
  10. 转载一朋友的qq空间,感觉都是至理名言啊!
  11. 计算与编程思维-Python实践【Python Crash Course】
  12. linux关闭rpcbind服务,rpcbind服务 关闭
  13. python爬虫实例(一) b站篇
  14. Java下载及环境配置
  15. Android移动端性能测试工具mobileperf
  16. RedHat认证笔记-RH124
  17. 分时线的9代表什么_一位从亏损到稳赚的老股民告诉你:为什么要打板?
  18. C++入门经典(第三版Ivor Horton著 ) 第一章习题答案
  19. 求一个n*n矩阵对角线元素之和C语言,求一个n*n矩阵主对角线之和,次对角线元素之和.用指针完成...
  20. 五个经典漏斗模型,看漏斗思维穿透流程化的本质

热门文章

  1. linux l7filter命令行,Ubuntu下l7-filter-userspace安装
  2. 【软件工程】软件测试目标定义 黑盒测试、白盒测试
  3. Android 雪花飘落
  4. java swing中国象棋聊天室对战游戏
  5. innerText和innerHTML的区别
  6. ★6-2 消除连续字符(升序)
  7. CDL3的模拟信号采集和CAN发送
  8. 浏览器假死,浏览器堵塞,浏览器卡的原因
  9. Java hook qpi_*信bA0 6.1.1 hook
  10. SketchUp 2018 适用的联合推拉(超级推拉)扩展插件Joint Push Pull下载