parent
e59181c648
commit
7afbdc20a0
@ -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¶1=");
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
Loading…
Reference in new issue