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. cocos2d CCLayer 触摸相关

    要让一个  CCLayer 能够接受触摸输入  需要进行如下设置: [selfsetTouchEnabled:YES]; cocos2d-x提供了两种触摸事件处理机制, 分别是CCStandardTo ...

  2. 通过实验分析system_call中断处理过程

    作者:吴乐 山东师范大学 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 本实验目的:通过以一个简单的m ...

  3. bzoj 3629 [JLOI2014]聪明的燕姿(约数和,搜索)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3629 [题意] 给定S,找出所有约数和为S的数. [思路] 若n=p1^a1*p2^a ...

  4. matlab特征值分解和奇异值分解

    特征值分解 函数 eig 格式 d = eig(A)         %求矩阵A的特征值d,以向量形式存放d. d = eig(A,B)       %A.B为方阵,求广义特征值d,以向量形式存放d. ...

  5. Maven解决Missing artifact com.sun:tools:jar:1.5.0错误

    <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> ...

  6. ViewPager使用笔记

    1.ViewPager.setCurrentItem(position),即使已设置动画,但是没有动画效果 原因:因为ViewPager滑动之前的时间间隔太短,可以通过反射,去修改ViewPager自 ...

  7. linux下面的查找命令

    在linux下面经常用查找命令,我自己最常用的是find whereis locate 关于find 我常用find的基本功能,如 find / -name filename 在某个目录下寻找文件. ...

  8. Java IO (4) - Writer

    Java IO (4) - Writer 前言 JavaIO一共包括两种,一种是stream,一种是reader/writer,每种又包括in/out,所以一共是四种包.Java 流在处理上分为字符流 ...

  9. Linux(Centos)全自动异地备份数据(WEB+Mysql)

    文章开始之前,先问下各位站长一个问题:什么东西对于站长是十分重要的?其实对于站长而言,很多东西都是很重要的.但我们现在排除外在因素,把范围缩小到网站系统本身,哪些是非常重要的呢?网站数据就是其中之一了 ...

  10. UVaLive 7270 Osu! Master (统计)

    题意:给定 n 个元素,有的有一个值,如果是 S 那么是单独一个,其他的是一个,求从 1 开始的递增的数量是多少. 析:那么S 是单独的,要统计上,既然是从 1 开始递增的,那么再统计 1 的数量即可 ...