添加一个查询密码专用的Dialog,用于给用户输入md5码手动查询密码

master
ThankVinci 4 years ago
parent e59181c648
commit 7afbdc20a0

@ -53,7 +53,7 @@ public class FileUtils {
Message msg = new Message(); Message msg = new Message();
if (!zipFile.isValidZipFile()){ if (!zipFile.isValidZipFile()){
data.putString("error","压缩包已损坏"); data.putString("error","压缩包已损坏");
msg.what = FileHandler.ERROR; msg.what = FileHandler.FUNCTION_ERROR;
msg.setData(data); msg.setData(data);
handler.sendMessage(msg); handler.sendMessage(msg);
} }

@ -0,0 +1,113 @@
package com.thankvinci.CloudKey.Fragment;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import com.thankvinci.CloudKey.Files.FileUtils;
import com.thankvinci.CloudKey.NetUtils.NetCheck;
import com.thankvinci.CloudKey.NetUtils.NetHandler;
import com.thankvinci.CloudKey.NetUtils.NetThread;
import com.thankvinci.CloudKey.R;
import com.thankvinci.CloudKey.Utils.MyUtils;
public class QueryPWDDialogFragment extends DialogFragment {
private Fragment fragment;
private TextView copy2clip,getPWD,clear;
private EditText md5_edit,pwd_edit;
private ProgressBar progressBar;
private AlertDialog alertDialog;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
public AlertDialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = requireActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.query_pwd_dialog,null);
copy2clip = view.findViewById(R.id.copytoclip);
getPWD = view.findViewById(R.id.getPWD);
copy2clip.setClickable(false);
clear = view.findViewById(R.id.clear);
md5_edit = view.findViewById(R.id.md5_edit);
pwd_edit = view.findViewById(R.id.pwd_edit);
progressBar = view.findViewById(R.id.progress_bar);
progressBar.setVisibility(View.INVISIBLE);
builder.setView(view).setTitle("查询密码").setNegativeButton("取消",null);
alertDialog = builder.create();
return alertDialog;
}
@Override
public void onStart(){
super.onStart();
alertDialog.setCanceledOnTouchOutside(false);
fragment = this;
copy2clip.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onClick(View v) {
if (copy2clip.getFocusable() == TextView.FOCUSABLE){
MyUtils.copyToClipboard(getActivity(),pwd_edit.getText().toString());
Toast.makeText(v.getContext(),"已复制到剪贴板",Toast.LENGTH_SHORT).show();
}
}
});
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pwd_edit.setText("");
md5_edit.setText("");
}
});
getPWD.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onClick(View v) {
String md5 = md5_edit.getText().toString();
if(md5.length() != 32){
Toast.makeText(v.getContext(),"MD5码不合法",Toast.LENGTH_SHORT).show();
return ;
}
if("无网络".equals(NetCheck.getNetStatus(v.getContext()))){
Toast.makeText(getActivity(),"获取失败,当前网络不畅通"+NetCheck.getNetStatus(v.getContext()),Toast.LENGTH_SHORT).show();
return ;
}
StringBuilder builder = new StringBuilder();
builder.append("http://1.14.144.194:8080/cscp/cscp?para0=query&para1=");
builder.append(md5);
String url = builder.toString();
Handler handler = new NetHandler(getActivity(),fragment);
Thread nt = new Thread(new NetThread(handler,url));
nt.start();
}
});
}
public void setPwd(String pwd){
pwd_edit.setText(pwd);
pwd_edit.setFocusable(false);
copy2clip.setClickable(true);
copy2clip.setFocusable(true);
}
}

@ -7,11 +7,14 @@ import android.widget.Toast;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.thankvinci.CloudKey.Fragment.QueryPWDDialogFragment;
import com.thankvinci.CloudKey.Fragment.UnzipDialogFragment; import com.thankvinci.CloudKey.Fragment.UnzipDialogFragment;
import com.thankvinci.CloudKey.MainActivity; import com.thankvinci.CloudKey.MainActivity;
public class NetHandler extends Handler { public class NetHandler extends Handler {
public final static int FUNCTION_GET_MD5 = 0;
public final static int FUNCTION_ERROR = -1;
private Activity activity; private Activity activity;
private Fragment fragment; private Fragment fragment;
public NetHandler(Activity activity,Fragment fragment){ public NetHandler(Activity activity,Fragment fragment){
@ -22,14 +25,18 @@ public class NetHandler extends Handler {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
super.handleMessage(msg); super.handleMessage(msg);
switch (msg.what){ switch (msg.what){
case 0: case FUNCTION_GET_MD5:
if (fragment instanceof UnzipDialogFragment){ if (fragment instanceof UnzipDialogFragment){
((UnzipDialogFragment)fragment).setPasswd(msg.getData().getString("key")); ((UnzipDialogFragment)fragment).setPasswd(msg.getData().getString("key"));
((UnzipDialogFragment)fragment).setFromSQL(true); ((UnzipDialogFragment)fragment).setFromSQL(true);
Toast.makeText(activity,"获取成功",Toast.LENGTH_SHORT).show(); Toast.makeText(activity,"获取成功",Toast.LENGTH_SHORT).show();
} }
if (fragment instanceof QueryPWDDialogFragment){
((QueryPWDDialogFragment)fragment).setPwd(msg.getData().getString("key"));
Toast.makeText(activity,"获取成功",Toast.LENGTH_SHORT).show();
}
break; break;
case -1: case FUNCTION_ERROR:
Toast.makeText(activity,msg.getData().getString("ReturnData"),Toast.LENGTH_SHORT).show(); Toast.makeText(activity,msg.getData().getString("ReturnData"),Toast.LENGTH_SHORT).show();
break; break;
default: default:

@ -23,7 +23,7 @@ public class FileHandler extends Handler {
public final static int FUNCTION_GET_MD5 = 0; public final static int FUNCTION_GET_MD5 = 0;
public final static int FUNCTION_GET_PWD = 2; public final static int FUNCTION_GET_PWD = 2;
public final static int FUNCTION_DECOMPRESS = 1; public final static int FUNCTION_DECOMPRESS = 1;
public final static int ERROR = -1; public final static int FUNCTION_ERROR = -1;
private Activity activity; private Activity activity;
private Fragment fragment; private Fragment fragment;
@ -41,7 +41,7 @@ public class FileHandler extends Handler {
((UnzipDialogFragment)fragment).setMD5(msg.getData().getString("md5")); ((UnzipDialogFragment)fragment).setMD5(msg.getData().getString("md5"));
((UnzipDialogFragment)fragment).setProgressBar(View.INVISIBLE); ((UnzipDialogFragment)fragment).setProgressBar(View.INVISIBLE);
break; break;
case ERROR: case FUNCTION_ERROR:
Toast.makeText(activity,msg.getData().getString("error"),Toast.LENGTH_SHORT).show(); Toast.makeText(activity,msg.getData().getString("error"),Toast.LENGTH_SHORT).show();
break; break;
case FUNCTION_DECOMPRESS: case FUNCTION_DECOMPRESS:

@ -14,11 +14,6 @@ import java.io.IOException;
public class FileThread implements Runnable{ public class FileThread implements Runnable{
public final static int FUNCTION_GET_MD5 = 0;
public final static int FUNCTION_GET_PWD = 2;
public final static int FUNCTION_DECOMPRESS = 1;
public final static int ERROR = -1;
private String srcFile,desPath,md5,passwd; private String srcFile,desPath,md5,passwd;
private Handler handler; private Handler handler;
@ -36,32 +31,32 @@ public class FileThread implements Runnable{
Message msg = new Message(); Message msg = new Message();
Bundle data = new Bundle(); Bundle data = new Bundle();
switch (function){ switch (function){
case FUNCTION_GET_MD5: case FileHandler.FUNCTION_GET_MD5:
try { try {
md5 = FileUtils.getFileMD5(srcFile); md5 = FileUtils.getFileMD5(srcFile);
data.putString("md5",md5); data.putString("md5",md5);
msg.what = FUNCTION_GET_MD5; msg.what = FileHandler.FUNCTION_GET_MD5;
msg.setData(data); msg.setData(data);
handler.sendMessage(msg); handler.sendMessage(msg);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
break; break;
case FUNCTION_DECOMPRESS: case FileHandler.FUNCTION_DECOMPRESS:
try { try {
FileUtils.unzip(srcFile,desPath,passwd,handler); FileUtils.unzip(srcFile,desPath,passwd,handler);
Log.d("TAG:","解压完成"); Log.d("TAG:","解压完成");
md5 = FileUtils.getFileMD5(srcFile); md5 = FileUtils.getFileMD5(srcFile);
data.putString("md5",md5); data.putString("md5",md5);
msg.what = FUNCTION_GET_MD5; msg.what = FileHandler.FUNCTION_GET_MD5;
data.putBoolean("successful",true); data.putBoolean("successful",true);
msg.what = FUNCTION_DECOMPRESS; msg.what = FileHandler.FUNCTION_DECOMPRESS;
msg.setData(data); msg.setData(data);
handler.sendMessage(msg); handler.sendMessage(msg);
} catch (ZipException e) { } catch (ZipException e) {
e.printStackTrace(); e.printStackTrace();
data.putString("error","解压失败"); data.putString("error","解压失败");
msg.what = ERROR; msg.what = FileHandler.FUNCTION_ERROR;
msg.setData(data); msg.setData(data);
handler.sendMessage(msg); handler.sendMessage(msg);
} catch (IOException e) { } catch (IOException e) {

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Fragment.QueryPWDDialogFragment">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progress_bar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="MissingConstraints" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/md5_text"
android:textSize="14dp"
android:text=" MD5码:"
android:textColor="@color/blue_1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
tools:ignore="MissingConstraints" />
<EditText
android:layout_width="220dp"
android:layout_height="wrap_content"
android:textSize="14dp"
android:id="@+id/md5_edit"
android:textColor="@color/grey"
android:singleLine="true"
android:gravity="left"
tools:ignore="MissingConstraints"
app:layout_constraintLeft_toRightOf="@id/md5_text"
app:layout_constraintBaseline_toBaselineOf="@id/md5_text"
android:layout_marginLeft="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pwd_text"
android:textSize="14dp"
android:text="文件密码:"
android:textColor="@color/blue_1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/md5_text"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
tools:ignore="MissingConstraints" />
<EditText
android:layout_width="220dp"
android:layout_height="wrap_content"
android:textSize="14dp"
android:id="@+id/pwd_edit"
android:textColor="@color/grey"
android:singleLine="true"
android:focusable="false"
android:gravity="left"
tools:ignore="MissingConstraints"
app:layout_constraintLeft_toRightOf="@id/pwd_text"
app:layout_constraintBaseline_toBaselineOf="@id/pwd_text"
android:layout_marginLeft="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/copytoclip"
android:text="复制到剪贴板"
android:focusable="false"
android:textColor="@drawable/text_be_clicked"
app:layout_constraintTop_toBottomOf="@id/pwd_edit"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
tools:ignore="MissingConstraints" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/getPWD"
android:text="获取密码"
android:clickable="true"
android:textColor="@drawable/text_be_clicked"
app:layout_constraintRight_toRightOf="@id/pwd_edit"
app:layout_constraintTop_toTopOf="@id/copytoclip"
tools:ignore="MissingConstraints" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/clear"
android:text="清空"
android:clickable="true"
android:textColor="@drawable/text_be_clicked"
app:layout_constraintLeft_toRightOf="@id/copytoclip"
app:layout_constraintRight_toLeftOf="@id/getPWD"
app:layout_constraintTop_toTopOf="@id/copytoclip"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -5,6 +5,11 @@
<item android:id="@+id/fileManageFragment" android:title="我的文件"></item> <item android:id="@+id/fileManageFragment" android:title="我的文件"></item>
</menu> </menu>
</item> </item>
<item android:id="@+id/tool" android:title="工具" android:color="@color/black">
<menu>
<item android:id="@+id/queryPWDDialogFragment" android:title="查询密码"></item>
</menu>
</item>
<item android:id="@+id/bugSubFragment" android:title="提交bug"></item> <item android:id="@+id/bugSubFragment" android:title="提交bug"></item>
<item android:id="@+id/aboutFragment" android:title="关于"></item> <item android:id="@+id/aboutFragment" android:title="关于"></item>
</menu> </menu>

@ -33,4 +33,9 @@
android:name="com.thankvinci.CloudKey.Fragment.BugSubFragment" android:name="com.thankvinci.CloudKey.Fragment.BugSubFragment"
android:label="BUG提交" android:label="BUG提交"
tools:layout="@layout/bug_sub_fragment" /> tools:layout="@layout/bug_sub_fragment" />
<dialog
android:id="@+id/queryPWDDialogFragment"
android:name="com.thankvinci.CloudKey.Fragment.QueryPWDDialogFragment"
android:label="query_pwd_dialog"
tools:layout="@layout/query_pwd_dialog" />
</navigation> </navigation>

@ -333,4 +333,10 @@ FileHandler负责将获取到的md5码发到NetThread,然后将得到的密码
删除无用的Toast 删除无用的Toast
使dialog在解压过程中点击空白区域无效,点击取消无效 使dialog在解压过程中点击空白区域无效,点击取消无效
**2021/6/13**
添加一个查询密码专用的Dialog,用于给用户输入md5码手动查询密码
界面上有三个TextView控件,一个是将密码复制到剪贴板,一个是清空EditView,一个是获取密码
Loading…
Cancel
Save