coding
志鸿思荣的gravatar头像
志鸿思荣2015-11-20 14:55:59

安卓客户端开发的锁屏源码demo下载,可直接应用到APP中

安卓程序锁屏

好多安卓APP中都用到锁屏技术在这里只是一个Demo 但是可以直接运用到已经做好的APP中,在绘制锁屏中用到许多的Math函数。

安卓客户端开发的锁屏源码demo下载,可直接应用到APP中

package com.weiqiang.lockpoint;

import com.infohold.lockpoint.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
  
/**
 * Email 1107438082@.com
 * @author 魏强
 * 密码绘制成功界面
 */
public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		
	}
}
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.infohold.lockpoint.R;
import com.weiqiang.lockpoint.LockPatternView.OnPatterChangeListner;

/**
 * 密码碎片
 * 
 * @author 魏强
 * 
 */
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);
		v.findViewById(R.id.fragment_password_btn_forget).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;
		case R.id.fragment_password_btn_forget:
			 sp = getActivity().getSharedPreferences("sp",Context.MODE_PRIVATE);
			// 设置密码
			sp.edit().putString("password", "").commit();
			startActivity(new Intent(getActivity(), SettingPasswordActivity.class));
			getActivity().finish();
			break;
		}
	}
}
package com.weiqiang.lockpoint;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
/**
*设置密码
*Email 1107438082@qq.com
* @author 魏强
*/
public class SettingPasswordActivity extends  Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getFragmentManager().beginTransaction().replace(android.R.id.content, PasswordFragment.newInstance(PasswordFragment.TYPE_SETTING)).commit();
	}

}
package com.weiqiang.lockpoint;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.Window;
/**
*Email 1107438082@qq.com
*@author 魏强
*欢迎界面 判断是否存在密码
*/
public class WelcomeActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		new Handler().postDelayed(new Runnable() {
			
			@Override
			public void run() {
				SharedPreferences sp = getSharedPreferences("sp", Context.MODE_PRIVATE);
				String passwordStr = sp.getString("password", "");
				//判断是否已经设置过密码
				//没有设置过密码
				if(TextUtils.isEmpty(passwordStr)){
					startActivity(new Intent(WelcomeActivity.this, SettingPasswordActivity.class));
					finish();
					//解锁
				}else {
					getFragmentManager().beginTransaction().replace(android.R.id.content, PasswordFragment.newInstance(PasswordFragment.TYPE_CHECK)).commit();
					
				}
			}
		}, 1000);
	}
}

安卓客户端开发的锁屏源码demo下载,可直接应用到APP中安卓客户端开发的锁屏源码demo下载,可直接应用到APP中


打赏

文件名:锁屏.rar,文件大小:2683.106K下载
顶部客服微信二维码底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友