├── .classpath
├── .gitignore
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── Image1.png
├── README.md
├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── anim
│ ├── pophidden_anim.xml
│ ├── popshow_anim.xml
│ ├── popup_in.xml
│ ├── popup_out.xml
│ └── push_bottom_in2.xml
├── drawable-hdpi
│ ├── ic_input_code_delete.png
│ ├── ic_launcher.png
│ ├── login_del.png
│ └── toast_background.9.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── drawable
│ ├── bg_numbers_layout.xml
│ ├── item_border.xml
│ ├── item_border_selected.xml
│ └── list_selector.xml
├── layout
│ ├── activity_main.xml
│ ├── content_main.xml
│ ├── fragment_new.xml
│ ├── item_view_input_group_code.xml
│ ├── pop_view.xml
│ ├── view_input_group_code.xml
│ └── view_toast.xml
├── values-w820dp
│ └── dimens.xml
└── values
│ ├── attr.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── example
└── textpassword
├── ExpandGridView.java
├── MainActivity.java
├── NewFragment.java
├── NumberAdapter.java
├── PassValitationPopwindow.java
└── ToastPopupwindow.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | TestPassWord
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/Image1.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TestPassword
2 | 和支付宝一样的密码验证框
3 |
4 | 
5 |
6 |
7 | new PassValitationPopwindow(MainActivity.this,1,findViewById(R.id.main),new OnInputNumberCodeCallback() {
8 | @Override
9 | public void onSuccess() {
10 | }
11 | });
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/res/anim/pophidden_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/res/anim/popshow_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
12 |
--------------------------------------------------------------------------------
/res/anim/popup_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
15 |
--------------------------------------------------------------------------------
/res/anim/popup_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 |
15 |
--------------------------------------------------------------------------------
/res/anim/push_bottom_in2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_input_code_delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/res/drawable-hdpi/ic_input_code_delete.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/login_del.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/res/drawable-hdpi/login_del.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/toast_background.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/res/drawable-hdpi/toast_background.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fanbaolong/TestPassword/03f3f2310e89a5ec3e443dcb985d2b9354d27ff2/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/bg_numbers_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/res/drawable/item_border.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/res/drawable/item_border_selected.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/res/drawable/list_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
22 |
23 |
27 |
28 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/res/layout/fragment_new.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/res/layout/item_view_input_group_code.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
25 |
26 |
--------------------------------------------------------------------------------
/res/layout/pop_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
18 |
19 |
23 |
24 |
32 |
33 |
39 |
40 |
41 |
49 |
50 |
53 |
54 |
55 |
56 |
59 |
60 |
61 |
62 |
65 |
66 |
67 |
68 |
71 |
72 |
73 |
74 |
77 |
78 |
79 |
80 |
83 |
84 |
85 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/res/layout/view_input_group_code.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
24 |
25 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
37 |
40 |
41 |
42 |
43 |
46 |
47 |
48 |
49 |
52 |
53 |
54 |
55 |
58 |
59 |
60 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/res/layout/view_toast.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
23 |
24 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #FFFFFF
8 | #303030
9 | #e0e0e0
10 | #dadada
11 | #FF4444
12 | #1de192
13 | #a1a4a4
14 |
15 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TextPassWord
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
28 |
29 |
35 |
36 |
41 |
42 |
46 |
47 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/com/example/textpassword/ExpandGridView.java:
--------------------------------------------------------------------------------
1 | package com.example.textpassword;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.GridView;
6 |
7 | public class ExpandGridView extends GridView {
8 |
9 | public ExpandGridView(Context context) {
10 | super(context);
11 | }
12 |
13 | public ExpandGridView(Context context, AttributeSet attrs) {
14 | super(context, attrs);
15 | }
16 |
17 |
18 | @Override
19 | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
20 | int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
21 | super.onMeasure(widthMeasureSpec, expandSpec);
22 | }
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/example/textpassword/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.textpassword;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.FragmentActivity;
5 | import android.view.Gravity;
6 | import android.view.View;
7 | import android.view.View.OnClickListener;
8 | import android.widget.Toast;
9 |
10 | import com.example.textpassword.PassValitationPopwindow.OnInputNumberCodeCallback;
11 |
12 | public class MainActivity extends FragmentActivity {
13 |
14 | // TextPassPopWindow mPop;
15 | private PassValitationPopwindow mPopup;
16 |
17 | private NewFragment newFragment;
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 |
23 | findViewById(R.id.main).setOnClickListener(new OnClickListener() {
24 |
25 | @Override
26 | public void onClick(View view) {
27 | // mPop = new TextPassPopWindow(MainActivity.this, itemsOnClick);
28 | // //显示窗口
29 | // mPop.showAtLocation(MainActivity.this.findViewById(R.id.main),
30 | // Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0); //设置layout在PopupWindow中显示的位置
31 |
32 | new PassValitationPopwindow(MainActivity.this,1,findViewById(R.id.main),new OnInputNumberCodeCallback() {
33 |
34 | @Override
35 | public void onSuccess() {
36 |
37 | }
38 | });
39 |
40 | }
41 | });
42 |
43 | if (newFragment == null)
44 | {
45 | newFragment = new NewFragment();
46 | }
47 | getSupportFragmentManager().beginTransaction()
48 | .replace(R.id.menu_fragment, newFragment).commit(); // 将左菜单默认VIEW替换为左菜单Fragment
49 |
50 |
51 | }
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/com/example/textpassword/NewFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.textpassword;
2 |
3 | import com.example.textpassword.PassValitationPopwindow.OnInputNumberCodeCallback;
4 |
5 | import android.app.Activity;
6 | import android.os.Bundle;
7 | import android.support.v4.app.Fragment;
8 | import android.view.Gravity;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.View.OnClickListener;
12 | import android.view.ViewGroup;
13 | import android.widget.Button;
14 | import android.widget.Toast;
15 |
16 | public class NewFragment extends Fragment{
17 |
18 | private PassValitationPopwindow mPopup;
19 |
20 | @Override
21 | public void onAttach(Activity activity) {
22 | super.onAttach(activity);
23 | }
24 |
25 | @Override
26 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
27 | Bundle savedInstanceState) {
28 |
29 | View view = View.inflate(getActivity(), R.layout.fragment_new, null);
30 |
31 | final Button mButton = (Button) view.findViewById(R.id.button);
32 | mButton.setOnClickListener(new OnClickListener() {
33 |
34 | @Override
35 | public void onClick(View view) {
36 | mPopup = new PassValitationPopwindow(getActivity(),0,mButton,new OnInputNumberCodeCallback() {
37 |
38 | @Override
39 | public void onSuccess() {
40 |
41 | }});
42 | }
43 | });
44 | return view;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/example/textpassword/NumberAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.textpassword;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.RelativeLayout;
10 | import android.widget.TextView;
11 |
12 | public class NumberAdapter extends BaseAdapter{
13 |
14 | private String mNumbers = "123456789C0#";
15 | private Context mContext;
16 |
17 | public NumberAdapter(Context mContext) {
18 | this.mContext = mContext;
19 | }
20 |
21 | @Override
22 | public int getCount() {
23 | return mNumbers.length();
24 | }
25 |
26 | @Override
27 | public String getItem(int position) {
28 | return String.valueOf(mNumbers.charAt(position));
29 | }
30 |
31 | @Override
32 | public long getItemId(int position) {
33 | return position;
34 | }
35 |
36 | @Override
37 | public View getView(int position, View convertView, ViewGroup parent) {
38 | ItemHolder itemHolder;
39 | if (convertView == null) {
40 | itemHolder = new ItemHolder();
41 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_view_input_group_code, null);
42 | itemHolder.mRootView = (RelativeLayout) convertView.findViewById(R.id.number_root_view);
43 | itemHolder.mNumberTextView = (TextView) convertView.findViewById(R.id.number_textView);
44 | itemHolder.mDeleteImageView = (ImageView) convertView.findViewById(R.id.number_delete_imageView);
45 | convertView.setTag(itemHolder);
46 | } else {
47 | itemHolder = (ItemHolder) convertView.getTag();
48 | }
49 | String curNumber = getItem(position);
50 | if ("C".equals(curNumber)) {
51 | itemHolder.mDeleteImageView.setVisibility(View.GONE);
52 | itemHolder.mNumberTextView.setVisibility(View.VISIBLE);
53 | itemHolder.mNumberTextView.setText(curNumber);
54 | itemHolder.mRootView.setBackgroundColor(mContext.getResources().getColor(R.color.gray));
55 | } else if ("#".equals(curNumber)) {
56 | itemHolder.mRootView.setBackgroundColor(mContext.getResources().getColor(R.color.gray));
57 | itemHolder.mNumberTextView.setVisibility(View.GONE);
58 | itemHolder.mDeleteImageView.setVisibility(View.VISIBLE);
59 | } else {
60 | itemHolder.mRootView.setBackgroundResource(R.drawable.list_selector);
61 | itemHolder.mDeleteImageView.setVisibility(View.GONE);
62 | itemHolder.mNumberTextView.setVisibility(View.VISIBLE);
63 | itemHolder.mNumberTextView.setText(curNumber);
64 | }
65 | return convertView;
66 | }
67 |
68 |
69 | private static class ItemHolder{
70 | RelativeLayout mRootView;
71 | TextView mNumberTextView;
72 | ImageView mDeleteImageView;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/com/example/textpassword/PassValitationPopwindow.java:
--------------------------------------------------------------------------------
1 | package com.example.textpassword;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Stack;
6 |
7 | import android.annotation.SuppressLint;
8 | import android.content.Context;
9 | import android.graphics.drawable.ColorDrawable;
10 | import android.view.Gravity;
11 | import android.view.LayoutInflater;
12 | import android.view.MotionEvent;
13 | import android.view.View;
14 | import android.view.View.OnClickListener;
15 | import android.view.View.OnTouchListener;
16 | import android.view.ViewGroup.LayoutParams;
17 | import android.widget.AdapterView;
18 | import android.widget.ImageView;
19 | import android.widget.PopupWindow;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 |
23 | /**
24 | * @author fanbaolong
25 | *
26 | * 弹出主管授权弹框
27 | */
28 | public class PassValitationPopwindow extends PopupWindow implements
29 | OnClickListener,AdapterView.OnItemClickListener{
30 |
31 | private Context mContext;
32 |
33 | private Stack mNumberStack;//保存输入的数字
34 | private List mNumberViewList;//保存密码显示的几个text
35 | private final static int NUMBER_BUTTON_DELETE = 11; //删除键
36 | private final static int NUMBER_BUTTON_ZERO = 10;//0号按键
37 | private final static int NUMBER_BUTTON_CLEAR = 9;//清除按键
38 | private final static int NUMBER_COUNT = 6;
39 |
40 | private TextView mNumber1TextView;
41 | private TextView mNumber2TextView;
42 | private TextView mNumber3TextView;
43 | private TextView mNumber4TextView;
44 | private TextView mNumber5TextView;
45 | private TextView mNumber6TextView;
46 | private ExpandGridView mNumbersGridView; // 密码gridView
47 | private NumberAdapter mNumberAdapter; // 数字adapter
48 | private boolean mIsPassword = true;
49 | private final static String PASSWORD_NUMBER_SYMBOL = "●";
50 |
51 | private ImageView ivLeft;
52 | private TextView tvTitle;
53 |
54 | private OnInputNumberCodeCallback mCallback; // 返回结果的回调
55 |
56 | private View mMenuView;
57 | private int type = 1;
58 | private View view;
59 |
60 | public PassValitationPopwindow() {
61 | }
62 |
63 | /**
64 | * @param mContext
65 | * @param type 1为主管授权,0为系统管理员授权
66 | * @param view 设置位置时候需要有个view值
67 | * @param mCallback 返回输入的6位验证密码
68 | */
69 | @SuppressWarnings("deprecation")
70 | @SuppressLint("InflateParams")
71 | public PassValitationPopwindow(Context mContext, int type , View view , OnInputNumberCodeCallback mCallback){
72 | super(mContext);
73 | this.mContext = mContext;
74 | this.type = type;
75 | this.mCallback = mCallback;
76 | this.view = view;
77 |
78 | mNumberStack = new Stack<>();
79 | mNumberViewList = new ArrayList();
80 | mNumberAdapter = new NumberAdapter(mContext);
81 |
82 |
83 | LayoutInflater inflater = (LayoutInflater) mContext
84 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
85 | mMenuView = inflater.inflate(R.layout.pop_view, null);
86 |
87 | // mMenuView = LayoutInflater.from(mContext).inflate(R.layout.pop_view, null);
88 |
89 | mNumber1TextView = (TextView) mMenuView.findViewById(R.id.number_1_textView);
90 | mNumber2TextView = (TextView) mMenuView.findViewById(R.id.number_2_textView);
91 | mNumber3TextView = (TextView) mMenuView.findViewById(R.id.number_3_textView);
92 | mNumber4TextView = (TextView) mMenuView.findViewById(R.id.number_4_textView);
93 | mNumber5TextView = (TextView) mMenuView.findViewById(R.id.number_5_textView);
94 | mNumber6TextView = (TextView) mMenuView.findViewById(R.id.number_6_textView);
95 | ivLeft = (ImageView) mMenuView.findViewById(R.id.iv_pop_dismiss);
96 | tvTitle = (TextView) mMenuView.findViewById(R.id.tv_pop_title);
97 |
98 | //根据传来的type判断是主管授权还是管理员授权
99 | tvTitle.setText(type == 0 ? "主管授权":"管理员授权");
100 |
101 | mNumberViewList.add(mNumber1TextView);
102 | mNumberViewList.add(mNumber2TextView);
103 | mNumberViewList.add(mNumber3TextView);
104 | mNumberViewList.add(mNumber4TextView);
105 | mNumberViewList.add(mNumber5TextView);
106 | mNumberViewList.add(mNumber6TextView);
107 |
108 | mNumbersGridView = (ExpandGridView) mMenuView.findViewById(R.id.numbers_gridView);
109 | mNumbersGridView.setAdapter(mNumberAdapter);
110 | mNumbersGridView.setOnItemClickListener(this);
111 | ivLeft.setOnClickListener(this);
112 |
113 | //设置SelectPicPopupWindow的View
114 | this.setContentView(mMenuView);
115 | //设置SelectPicPopupWindow弹出窗体的宽
116 | this.setWidth(LayoutParams.FILL_PARENT);
117 | //设置SelectPicPopupWindow弹出窗体的高
118 | this.setHeight(LayoutParams.WRAP_CONTENT);
119 | //设置SelectPicPopupWindow弹出窗体可点击
120 | this.setFocusable(true);
121 | //设置SelectPicPopupWindow弹出窗体动画效果
122 | this.setAnimationStyle(R.style.AnimBottom);
123 | //实例化一个ColorDrawable颜色为半透明
124 | ColorDrawable dw = new ColorDrawable(0xb0000000);
125 | //设置SelectPicPopupWindow弹出窗体的背景
126 | this.setBackgroundDrawable(dw);
127 | //设置popup的位置
128 | this.showAtLocation(view,
129 | Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
130 | //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
131 | mMenuView.setOnTouchListener(new OnTouchListener() {
132 | @SuppressLint("ClickableViewAccessibility")
133 | public boolean onTouch(View v, MotionEvent event) {
134 |
135 | int height = mMenuView.findViewById(R.id.pop_layout).getTop();
136 | int y=(int) event.getY();
137 | if(event.getAction()==MotionEvent.ACTION_UP){
138 | if(y parent, View view, int position, long id) {
162 |
163 | if (position == NUMBER_BUTTON_CLEAR) {
164 | clearnNumber();
165 | return;
166 | }
167 | if (position == NUMBER_BUTTON_DELETE) {
168 | deleteNumber();
169 | } else {
170 | if (position == NUMBER_BUTTON_ZERO) {
171 | mNumberStack.push(0);
172 | } else {
173 | mNumberStack.push(++position);
174 | }
175 | }
176 | refreshNumberViews(mNumberStack);
177 | //input 6 numbers complete
178 | if (mNumberStack.size() == NUMBER_COUNT) {
179 | StringBuilder codeBuilder = new StringBuilder();
180 | for (int number : mNumberStack) {
181 | codeBuilder.append(number);
182 | }
183 | validation(codeBuilder.toString());
184 | }
185 |
186 | }
187 |
188 | /**
189 | * 验证密码,这里直接写在本地验证了
190 | * @param code
191 | */
192 | private void validation(String code){
193 |
194 | if("123456".equals(code) && type == 0){
195 | mCallback.onSuccess();
196 | dismiss();
197 | }else if("123456".equals(code) && type == 1){
198 | mCallback.onSuccess();
199 | dismiss();
200 | }else {
201 | clearnNumber();
202 | // Toast.makeText(mContext, "验证失败,请重新验证", Toast.LENGTH_SHORT).show();
203 | new ToastPopupwindow(mContext, view, "验证失败,请重新验证");
204 | }
205 |
206 | }
207 |
208 | /**
209 | * 返回输出的结果
210 | */
211 | public interface OnInputNumberCodeCallback {
212 | void onSuccess();
213 | }
214 |
215 | /**
216 | * 清空mNumberStack的内容并刷新密码格
217 | */
218 | public void clearnNumber() {
219 | mNumberStack.clear();
220 | refreshNumberViews(mNumberStack);
221 | }
222 |
223 | /**
224 | * 删除密码位数
225 | */
226 | public void deleteNumber() {
227 | if (mNumberStack.empty() || mNumberStack.size() > NUMBER_COUNT) {
228 | return;
229 | }
230 | mNumberStack.pop();
231 | }
232 |
233 |
234 | /**
235 | * 刷新输入框显示
236 | * @param mNumberStack
237 | */
238 | public void refreshNumberViews(Stack mNumberStack) {
239 |
240 | for (int i = 0, size = mNumberViewList.size(); i < size; i++) {
241 | int numSize = mNumberStack.size();
242 | if (i < numSize) {
243 | if (mIsPassword) {
244 | mNumberViewList.get(i).setText(PASSWORD_NUMBER_SYMBOL);
245 | } else {
246 | mNumberViewList.get(i).setText(String.valueOf(mNumberStack.get(i)));
247 | }
248 | } else {
249 | mNumberViewList.get(i).setText("");
250 | }
251 | }
252 |
253 | }
254 |
255 |
256 |
257 | }
258 |
--------------------------------------------------------------------------------
/src/com/example/textpassword/ToastPopupwindow.java:
--------------------------------------------------------------------------------
1 | package com.example.textpassword;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.drawable.ColorDrawable;
6 | import android.os.Handler;
7 | import android.os.Message;
8 | import android.view.Gravity;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup.LayoutParams;
12 | import android.widget.PopupWindow;
13 | import android.widget.TextView;
14 |
15 | /**
16 | * @author fanbaolong
17 | * 自己定义的一个toast作用的popupwindow
18 | * 主要是为了弹出验证框的时候有时会遮住toast导致不显示,一般情况下直接用myApplication.showToast(); 就行了
19 | */
20 | public class ToastPopupwindow extends PopupWindow{
21 |
22 | private View mMenuView;
23 | private TextView mToastTv;
24 |
25 | public ToastPopupwindow() {
26 | }
27 |
28 |
29 | @SuppressLint("InflateParams")
30 | public ToastPopupwindow(Context mContext ,View view ,String ss){
31 | super(mContext);
32 |
33 | LayoutInflater inflater = (LayoutInflater) mContext
34 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
35 | mMenuView = inflater.inflate(R.layout.view_toast, null);
36 |
37 | mToastTv = (TextView) mMenuView.findViewById(R.id.title_tv);
38 | mToastTv.setText(ss);
39 |
40 | //设置ToastPopupwindow的View
41 | this.setContentView(mMenuView);
42 | //设置ToastPopupwindow弹出窗体的宽
43 | this.setWidth(LayoutParams.WRAP_CONTENT);
44 | //设置ToastPopupwindow弹出窗体的高
45 | this.setHeight(LayoutParams.WRAP_CONTENT);
46 | //设置ToastPopupwindow弹出窗体可点击
47 | this.setFocusable(false);
48 | //设置ToastPopupwindow弹出窗体动画效果
49 | this.setAnimationStyle(R.style.AnimBottom);
50 | //实例化一个ColorDrawable颜色为半透明
51 | ColorDrawable dw = new ColorDrawable(0xb0000000);
52 | //设置SelectPicPopupWindow弹出窗体的背景
53 | this.setBackgroundDrawable(dw);
54 | //设置popup的位置
55 | this.showAtLocation(view,
56 | Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 10);
57 |
58 | Message message = handler.obtainMessage(1); // Message
59 | handler.sendMessageDelayed(message, 1000);
60 |
61 | }
62 |
63 | @SuppressLint("HandlerLeak")
64 | Handler handler = new Handler(){
65 | public void dispatchMessage(Message msg) {
66 | switch (msg.what) {
67 | case 1:
68 | dismiss();
69 | break;
70 |
71 | default:
72 | break;
73 | }
74 | };
75 | };
76 |
77 |
78 | }
79 |
--------------------------------------------------------------------------------