首页>代码>安卓客户端开发的锁屏4*4的图案布局源码下载>/锁屏44/src/com/weiqiang/lockpoint/PasswordFragment.java
package com.weiqiang.lockpoint;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weiqiang.lockpoint.LockPatternView.OnPatterChangeListner;

/**
 * 密码碎片
 * 
 * @author Administrator
 * 
 */
public class PasswordFragment extends Fragment implements OnPatterChangeListner, OnClickListener {
	public static final String TYPE_SETTING = "setting";
	public static final String TYPE_CHECK = "check";
	private TextView mainLock;
	private LockPatternView lockPatternView;
	private LinearLayout btnLinearLayout;
	private static final String ARG_TYPE = "type";
	private String passString;

	public PasswordFragment() {
	}

	public static android.app.Fragment newInstance(String arg_type) {
		PasswordFragment fragment = new PasswordFragment();
		Bundle args = new Bundle();
		args.putString(ARG_TYPE, arg_type);
		fragment.setArguments(args);
		return fragment;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	@Nullable
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_password, container, false);
		mainLock = (TextView) v.findViewById(R.id.fragment_password_lock_hint);
		lockPatternView = (LockPatternView) v
				.findViewById(R.id.fragment_password_lock);
		btnLinearLayout = (LinearLayout) v
				.findViewById(R.id.fragment_password_btn_layout);
		// 设置密码
		if (getArguments() != null) {
			if (TYPE_SETTING.equals(getArguments().getString(ARG_TYPE))) {
				btnLinearLayout.setVisibility(View.VISIBLE);
			}
		}
		v.findViewById(R.id.fragment_password_btn_commit).setOnClickListener(
				this);
		lockPatternView.setPatterChangeListner(this);
		return v;
	}

	@Override
	public void onPatterChange(String passString) {
		this.passString = passString;
		if (!TextUtils.isEmpty(passString)) {
			mainLock.setText(passString);
			//没有密码直接进入主页面
			// 检查密码
			 if (getArguments() != null) {
				if (TYPE_CHECK.equals(getArguments().getString(ARG_TYPE))) {
					SharedPreferences sp = getActivity().getSharedPreferences("sp", Context.MODE_PRIVATE);
					// 检查成功
					if (passString.equals(sp.getString("password", ""))) {
						getActivity().startActivity(new Intent(getActivity(), MainActivity.class));
						getActivity().finish();
						// 检查失败
					} else {
						mainLock.setText("密码错误");
						lockPatternView.errorPoint();
					}
				}
			}
		} else {
			mainLock.setText("请设置至少5位密码");
		}
	}

	@Override
	public void onPatterStart(boolean isStart) {
		if (isStart) {
			mainLock.setText("请绘制图案");
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.fragment_password_btn_commit:
			SharedPreferences sp = getActivity().getSharedPreferences("sp",
					Context.MODE_PRIVATE);
			// 设置密码
			sp.edit().putString("password", passString).commit();
			getActivity().finish();
			break;
		}
	}
}
最近下载更多
zzzxxcc  LV6 2020年6月17日
开心的一只鱼  LV8 2020年6月16日
花花滑滑画画瓜瓜  LV9 2020年1月9日
871978898  LV1 2019年12月25日
zb1095876169  LV2 2019年12月24日
藤井旋风  LV4 2019年12月14日
lyt1234567890  LV5 2019年12月4日
1198903926  LV9 2019年11月25日
阿凝是个小可爱  LV14 2019年6月29日
那一丝涟漪  LV8 2019年5月26日
最近浏览更多
wzm123530  LV4 2023年5月30日
xiaoqiaothq  LV2 2023年4月2日
MoerPerfect  LV1 2022年9月2日
GZW012345  LV8 2022年3月21日
674100273  LV1 2021年11月22日
melon_yan  LV2 2021年6月24日
Jason137  LV8 2021年6月9日
ewewrfas  LV2 2021年6月1日
fredemma  LV1 2021年3月29日
sizeking  LV8 2021年3月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友