init
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package net.droidtech.agct;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import net.droidtech.utils.AGCT;
|
||||
|
||||
/**
|
||||
* Created by root on 2019/7/17.
|
||||
*/
|
||||
|
||||
public class DecodeThread extends Thread {
|
||||
|
||||
private String data;
|
||||
private Handler handler;
|
||||
|
||||
public void putEncodedData(String data){
|
||||
this.data=data;
|
||||
}
|
||||
|
||||
public void setHandler(Handler handler){
|
||||
this.handler=handler;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
|
||||
Message msg=handler.obtainMessage();
|
||||
|
||||
byte[] result=AGCT.decode(this.data);
|
||||
|
||||
if(result!=null){
|
||||
|
||||
msg.what=4;
|
||||
|
||||
msg.obj=result;
|
||||
|
||||
}else{
|
||||
|
||||
msg.what=1;
|
||||
|
||||
}
|
||||
|
||||
msg.sendToTarget();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.droidtech.agct;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import net.droidtech.utils.AGCT;
|
||||
|
||||
/**
|
||||
* Created by root on 2019/7/16.
|
||||
*/
|
||||
|
||||
public class EncodeThread extends Thread {
|
||||
|
||||
private byte[] data;
|
||||
private Handler handler;
|
||||
|
||||
public void putRawData(byte[] data){
|
||||
this.data=data;
|
||||
}
|
||||
|
||||
public void setHandler(Handler handler){
|
||||
this.handler=handler;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
|
||||
Message msg=handler.obtainMessage();
|
||||
|
||||
String result=AGCT.encode(this.data);
|
||||
|
||||
if(result!=null){
|
||||
|
||||
msg.what=2;
|
||||
|
||||
msg.obj=result;
|
||||
|
||||
}else{
|
||||
|
||||
msg.what=1;
|
||||
|
||||
}
|
||||
|
||||
msg.sendToTarget();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package net.droidtech.agct;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
private ProgressDialog inProgress;
|
||||
private EditText msgInput;
|
||||
private EditText output;
|
||||
private static ThreadResultHandler threadHandler;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
inProgress=new ProgressDialog(this);
|
||||
inProgress.setTitle(R.string.please_wait);
|
||||
inProgress.setMessage(this.getApplicationContext().getResources().getString(R.string.in_progress));
|
||||
inProgress.setCancelable(false);
|
||||
|
||||
threadHandler = new ThreadResultHandler();
|
||||
;
|
||||
this.msgInput=this.findViewById(R.id.messageInput);
|
||||
this.output=this.findViewById(R.id.output);
|
||||
|
||||
output.setEnabled(false);
|
||||
|
||||
Button encode=this.findViewById(R.id.encode);
|
||||
encode.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View view){
|
||||
|
||||
EncodeThread thread=new EncodeThread();
|
||||
|
||||
try {
|
||||
|
||||
thread.putRawData(msgInput.getText().toString().getBytes("UTF-8"));
|
||||
|
||||
}catch (Exception e){
|
||||
|
||||
Toast.makeText(MainActivity.this,R.string.encoding_error,Toast.LENGTH_LONG).show();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
thread.setHandler(threadHandler);
|
||||
inProgress.show();
|
||||
thread.start();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Button decode=findViewById(R.id.decode);
|
||||
decode.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
DecodeThread thread=new DecodeThread();
|
||||
thread.setHandler(threadHandler);
|
||||
|
||||
if(msgInput.getText().toString().trim().isEmpty()){
|
||||
|
||||
String first=((ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE)).getPrimaryClip().getItemAt(0).getText().toString();
|
||||
|
||||
Toast.makeText(MainActivity.this,R.string.read_clipboard,Toast.LENGTH_LONG).show();
|
||||
thread.putEncodedData(first);
|
||||
|
||||
}else {
|
||||
|
||||
thread.putEncodedData(msgInput.getText().toString());
|
||||
|
||||
}
|
||||
|
||||
inProgress.show();
|
||||
thread.start();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
Button copy_output=findViewById(R.id.copy_output);
|
||||
copy_output.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if(threadHandler.lastOutputMessage!=null){
|
||||
|
||||
ClipboardManager cm =(ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
|
||||
ClipData cd = ClipData.newPlainText("output",threadHandler.lastOutputMessage);
|
||||
|
||||
cm.setPrimaryClip(cd);
|
||||
|
||||
Toast.makeText(MainActivity.this,R.string.copied,Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private class ThreadResultHandler extends Handler{
|
||||
|
||||
private String lastOutputMessage=null;
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg){
|
||||
try {
|
||||
|
||||
if (msg.what == 2) {
|
||||
|
||||
output.setEnabled(false);
|
||||
|
||||
if(((String)msg.obj).length()>1024){
|
||||
|
||||
output.setText(MainActivity.this.getResources().getText(R.string.message_too_long));
|
||||
|
||||
}else {
|
||||
|
||||
output.setText((String) msg.obj);
|
||||
|
||||
}
|
||||
|
||||
lastOutputMessage=(String)msg.obj;
|
||||
|
||||
} else if (msg.what == 4) {
|
||||
|
||||
output.setEnabled(true);
|
||||
|
||||
output.setText(new String(((byte[]) msg.obj), "UTF-8"));
|
||||
|
||||
this.lastOutputMessage=new String(((byte[]) msg.obj), "UTF-8");
|
||||
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
|
||||
output.setText(MainActivity.this.getResources().getString(R.string.error));
|
||||
output.setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
if(msg.what==1) {
|
||||
|
||||
output.setText(R.string.error);
|
||||
lastOutputMessage=MainActivity.this.getString(R.string.error);
|
||||
output.setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
inProgress.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user