package com.itheima.mobileguard.fragment;

import java.util.ArrayList;
import java.util.List; import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import com.itheima.mobileguard.R;
import com.itheima.mobileguard.db.dao.AppLockDao;
import com.itheima.mobileguard.domain.AppInfo;
import com.itheima.mobileguard.engine.AppInfoParser;
import com.lidroid.xutils.DbUtils.DaoConfig; public class LockFragment extends Fragment { private ListView list_view;
private TextView tv_lock;
private List<AppInfo> lockLists;
private AppLockDao dao;
private LockAdapter adapter; @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_lock_fragment, null);
list_view = (ListView) view.findViewById(R.id.list_view);
tv_lock = (TextView) view.findViewById(R.id.tv_lock);
return view;
} @Override
public void onStart() {// 每次页面可见就会调用这个方法
super.onStart();
// 拿到所有的应用程序
List<AppInfo> appInfos = AppInfoParser.getAppInfos(getActivity());
// 初始化一个加锁的集合 lockLists = new ArrayList<AppInfo>();
dao = new AppLockDao(getActivity());
for (AppInfo appInfo : appInfos) {
// 如果能找到当前的包名说明在程序锁的数据库里面
if (dao.find(appInfo.getPackname())) {
lockLists.add(appInfo);
} else {
}
}
adapter = new LockAdapter();
list_view.setAdapter(adapter);
} private class LockAdapter extends BaseAdapter {
@Override
public int getCount() {
tv_lock.setText("已加锁(" + lockLists.size() + ")个");
return lockLists.size();
} @Override
public Object getItem(int position) {
return lockLists.get(position);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(final int position, View convertView,
ViewGroup parent) {
final View view;
ViewHolder holder = null;
if (convertView == null) {
view = View.inflate(getActivity(), R.layout.item_lock, null);
holder = new ViewHolder();
holder.iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
holder.iv_lock = (ImageView) view.findViewById(R.id.iv_lock);
view.setTag(holder);
} else {
view = convertView; holder = (ViewHolder) view.getTag();
}
final AppInfo appInfo = lockLists.get(position);
holder.iv_icon.setImageDrawable(appInfo.getIcon());
holder.tv_name.setText(appInfo.getName()); holder.iv_lock.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,//X的起始位置
Animation.RELATIVE_TO_SELF, -1.0f,//x的终止位置(左滑)
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0);
translateAnimation.setDuration(5000);
view.startAnimation(translateAnimation); new Thread() {
public void run() {
SystemClock.sleep(5000);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
dao.delete(appInfo.getPackname());
lockLists.remove(position);
adapter.notifyDataSetChanged();
}
});
};
}.start();
}
});
return view;
}
} static class ViewHolder {
ImageView iv_icon;
TextView tv_name;
ImageView iv_lock;
}
}

页面:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/tv_lock"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView> </LinearLayout>

UnLockFragment

package com.itheima.mobileguard.fragment;

import java.util.ArrayList;
import java.util.List; import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import com.itheima.mobileguard.R;
import com.itheima.mobileguard.db.dao.AppLockDao;
import com.itheima.mobileguard.domain.AppInfo;
import com.itheima.mobileguard.engine.AppInfoParser;
//页面消失了再调用onStop()方法,onDestory()方法,不是调用onStop()方法,onDestory()方法再销毁页面。
public class UnLockFragment extends Fragment { private View view;
private TextView tv_unlock;
private ListView list_view;
private List<AppInfo> appInfos;
private AppLockDao dao;
private List<AppInfo> unLockLists;
private UnLockAdapter adapter; /*
* 类似activity里面的setContentView,初始化界面在onCreateView()方法中,
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { view = inflater.inflate(R.layout.item_unlock_fragment, null);
list_view = (ListView) view.findViewById(R.id.list_view);
tv_unlock = (TextView) view.findViewById(R.id.tv_unlock);
return view;
} //初始化数据要在onStart()方法中,因为onCreateView()方法只调用一次。
@Override
public void onStart() {
super.onStart();
appInfos = AppInfoParser.getAppInfos(getActivity()); // 获取到程序锁的dao
dao = new AppLockDao(getActivity());
// 初始化一个没有加锁的集合 unLockLists = new ArrayList<AppInfo>();
for (AppInfo appInfo : appInfos) {
// 判断当前的应用是否在程序所的数据里面
if (dao.find(appInfo.getPackname())) {
} else {
// 如果查询不到说明没有在程序锁的数据库里面
unLockLists.add(appInfo);
}
} adapter = new UnLockAdapter();
list_view.setAdapter(adapter);
} public class UnLockAdapter extends BaseAdapter { @Override
public int getCount() {//数量减少的时候会重新刷新,getCount()方法会执行,
tv_unlock.setText("未加锁(" + unLockLists.size() + ")个");
return unLockLists.size();
} @Override
public Object getItem(int position) {
return unLockLists.get(position);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(final int position, View convertView,
ViewGroup parent) {
ViewHolder holder = null;
final View view;
final AppInfo appInfo;
if (convertView == null) {
view = View.inflate(getActivity(), R.layout.item_unlock, null);
/*<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/iv_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1111"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="程序锁" />
<ImageView
android:id="@+id/iv_unlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/list_button_lock_default" />
</LinearLayout>*/
holder = new ViewHolder();
holder.iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
holder.iv_unlock = (ImageView) view
.findViewById(R.id.iv_unlock);
view.setTag(holder);
} else {
view = convertView;
holder = (ViewHolder) view.getTag();
}
// 获取到当前的对象
appInfo = unLockLists.get(position);
holder.iv_icon
.setImageDrawable(unLockLists.get(position).getIcon());
holder.tv_name.setText(unLockLists.get(position).getName());
// 把程序添加到程序锁数据库里面,添加一个位移动画。
holder.iv_unlock.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 初始化一个位移动画
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,//X轴的开始位置
Animation.RELATIVE_TO_SELF, 1.0f,//X轴的结束位置(右滑)
Animation.RELATIVE_TO_SELF, 0,//Y轴的开始位置
Animation.RELATIVE_TO_SELF, 0);//Y轴的结束位置
// 设置动画时间
translateAnimation.setDuration(5000);
// 开始动画,动画作用在整个View上面。
view.startAnimation(translateAnimation);
new Thread(){
public void run() {
SystemClock.sleep(5000);//动画是开启了子线城,不然这行代码就先执行了。
getActivity().runOnUiThread(new Runnable() {//刷新界面所有要在主线程执行
@Override
public void run() {
// 添加到数据库里面
dao.add(appInfo.getPackname());
// 从当前的页面移除对象
unLockLists.remove(position);
// 刷新界面
adapter.notifyDataSetChanged();
}
});
};
}.start();
}
});
return view;
}
} static class ViewHolder {
ImageView iv_icon;
TextView tv_name;
ImageView iv_unlock;
}
}

item_unlock_fragment

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_unlock"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TextView>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>

android147 360 程序锁fragment的更多相关文章

  1. android147 360 程序锁

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  2. android149 360 程序锁输入密码

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  3. Android学习笔记_63_手机安全卫士知识点归纳(3)分享 程序锁 服务 进程管理 widget

    1.分享: Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setT ...

  4. Android项目实战_手机安全卫士程序锁

    ###1.两个页面切换的实现1. 可以使用Fragment,调用FragmentTransaction的hide和show方法2. 可以使用两个布局,设置visibility的VISIABLE和INV ...

  5. CAD调试时抛出“正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码”异常的解决方法

    这些天重装了电脑Win10系统,安装了CAD2012和VS2012,准备进行软件开发.在调试程序的时候,CAD没有进入界面就抛出 “正试图在 os 加载程序锁内执行托管代码.不要尝试在 DllMain ...

  6. 正尝试在 OS 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样...

    出错提示: 正尝试在 OS 加载程序锁内执行托管代码.不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起. 原因分析: .NET2.0中增加了42种非常强大的调试助手 ...

  7. 检测到 LoaderLock:DLL"XXXX"正试图在OS加载程序锁内执行

    解决方法: ctrl+D+E或alt+ctl+e或使用菜单调试——>异常——>异常窗口——>Managed Debugging Assistants——>去掉LoaderLoc ...

  8. 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码

    来自:http://www.cnblogs.com/lcxu2/archive/2011/01/16/2004016.html 正试图在 os 加载程序锁内执行托管代码.不要尝试在 DllMain 或 ...

  9. Android安全问题 程序锁

    导读:本文介绍如何实现对应用加锁的功能,无须root权限 某些人有时候会有这样一种需求,小A下载了个软件,只是软件中的美女过于诱惑与暴露,所以他不想让别人知道这是个什么软件,起码不想让别人打开浏 览. ...

随机推荐

  1. HDU5794 A Simple Chess 容斥+lucas

    分析:转自http://blog.csdn.net/mengzhengnan/article/details/47031777 一点感想:其实这个题应该是可以想到的,但是赛场上并不会 dp[i]的定义 ...

  2. 修改linux主机名称

    linux修改主机名如下操作即可: [root@kel ~]# cat /etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=no HOSTNAM ...

  3. ASP.NET MVC中使用ASP.NET AJAX异步访问WebService

    使用过ASP.NET AJAX的朋友都知道,怎么通过ASP.NET AJAX在客户端访问WebService,其实在ASP.NET MVC中使用ASP.NET AJAX异步访问WebService 也 ...

  4. 《Genesis-3D开源游戏引擎-FQA常见问题解答》2014年01月10号版本

    1.Genesis-3D开源游戏引擎主要面向哪些用户人群?有限制吗? 1.我们的引擎没有限制,只要您想了解和使用我们的引擎,就可以加入Genesis-3D的大家庭.2.我们的主要用户群是各个相关的企业 ...

  5. 迁移web.py项目至git@osc的项目演示平台

    1. 开启演示平台 选择WSGI,输入应用名称,即是演示网页的网址. 2. web.py代码迁移 将Python的site-packages目录下的web文件夹复制到代码目录下,与网页程序在同一个文件 ...

  6. poj 3268 Silver Cow Party(最短路)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17017   Accepted: 7767 ...

  7. 12个有趣的C语言面试题

    摘要:12个C语言面试题,涉及指针.进程.运算.结构体.函数.内存,看看你能做出几个! 1.gets()函数 问:请找出下面代码里的问题: #include<stdio.h> int ma ...

  8. 山东理工大学ACM平台题答案关于C语言 1137 C/C++经典程序训练7---求某个范围内的所有素数

    C/C++经典程序训练7---求某个范围内的所有素数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 求小于n的所有素数,按照每行 ...

  9. Android之基于HTTP协议的下载

    Android之基于HTTP协议的下载 http://www.blogjava.net/zh-weir/archive/2010/05/02/319892.html http://www.qianfa ...

  10. python字符串相关的函数

    有些是字符串对象的方法,有些是内建库的方法 split分割字符串 find 查找字符串 for c in str:  遍历字符串 len 获取字符串长度 int    将字符串转换成int str   ...