commit 6158a7ad2b77e6e6e8fa979565954719611807e7 Author: ecpvint Date: Thu Aug 15 18:35:25 2024 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..956c004 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/build +/release \ No newline at end of file diff --git a/app.iml b/app.iml new file mode 100644 index 0000000..d99b865 --- /dev/null +++ b/app.iml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..9ef114a --- /dev/null +++ b/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + defaultConfig { + applicationId "net.droidtech.agct" + minSdkVersion 14 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation files('libs/Utils.jar') + +} diff --git a/libs/Utils.jar b/libs/Utils.jar new file mode 100644 index 0000000..498b61e Binary files /dev/null and b/libs/Utils.jar differ diff --git a/proguard-rules.pro b/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..bb66de1 --- /dev/null +++ b/readme.md @@ -0,0 +1,7 @@ +## 影沐纪念项目 + +#### AGCT 编码器 + +

利用AGCT四种碱基字符编码任何字符串

+ +

安卓项目

\ No newline at end of file diff --git a/src/androidTest/java/net/droidtech/agct/ExampleInstrumentedTest.java b/src/androidTest/java/net/droidtech/agct/ExampleInstrumentedTest.java new file mode 100644 index 0000000..84f1e20 --- /dev/null +++ b/src/androidTest/java/net/droidtech/agct/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package net.droidtech.agct; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("net.droidtech.acgt", appContext.getPackageName()); + } +} diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml new file mode 100644 index 0000000..501185a --- /dev/null +++ b/src/main/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/net/droidtech/agct/DecodeThread.java b/src/main/java/net/droidtech/agct/DecodeThread.java new file mode 100644 index 0000000..1721fdc --- /dev/null +++ b/src/main/java/net/droidtech/agct/DecodeThread.java @@ -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(); + + } +} + diff --git a/src/main/java/net/droidtech/agct/EncodeThread.java b/src/main/java/net/droidtech/agct/EncodeThread.java new file mode 100644 index 0000000..72c883b --- /dev/null +++ b/src/main/java/net/droidtech/agct/EncodeThread.java @@ -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(); + + } + +} diff --git a/src/main/java/net/droidtech/agct/MainActivity.java b/src/main/java/net/droidtech/agct/MainActivity.java new file mode 100644 index 0000000..ab78475 --- /dev/null +++ b/src/main/java/net/droidtech/agct/MainActivity.java @@ -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(); + } + } + +} diff --git a/src/main/res/drawable-v24/ic_launcher_foreground.xml b/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/src/main/res/drawable/ic_launcher_background.xml b/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..d5fccc5 --- /dev/null +++ b/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/res/layout/activity_main.xml b/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..9d72e95 --- /dev/null +++ b/src/main/res/layout/activity_main.xml @@ -0,0 +1,62 @@ + + + + + + + + + + +