diff --git a/myutils/.gitignore b/myutils/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/myutils/.gitignore @@ -0,0 +1 @@ +/build diff --git a/myutils/build.gradle b/myutils/build.gradle new file mode 100644 index 0000000000..b9a52bf7d3 --- /dev/null +++ b/myutils/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 26 + + + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 26 + 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']) + + implementation 'com.android.support:appcompat-v7:26.1.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.1' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' +} diff --git a/myutils/proguard-rules.pro b/myutils/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/myutils/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/myutils/src/androidTest/java/com/sun/myutils/ExampleInstrumentedTest.java b/myutils/src/androidTest/java/com/sun/myutils/ExampleInstrumentedTest.java new file mode 100644 index 0000000000..b4dda6d368 --- /dev/null +++ b/myutils/src/androidTest/java/com/sun/myutils/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.sun.myutils; + +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("com.sun.myutils.test", appContext.getPackageName()); + } +} diff --git a/myutils/src/main/AndroidManifest.xml b/myutils/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..8811441e47 --- /dev/null +++ b/myutils/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/myutils/src/main/java/com/sun/myutils/Installation.java b/myutils/src/main/java/com/sun/myutils/Installation.java new file mode 100644 index 0000000000..1b79abb8b2 --- /dev/null +++ b/myutils/src/main/java/com/sun/myutils/Installation.java @@ -0,0 +1,47 @@ +package com.sun.myutils; + +import android.content.Context; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.UUID; + +/** + * Created by Administrator on 2018/1/2. + */ + +public class Installation { + private static String sID = null; + private static final String INSTALLATION = "INSTALLATION"; + + public synchronized static String id(Context context) { + if (sID == null) { + File installation = new File(context.getFilesDir(), INSTALLATION); + try { + if (!installation.exists()) + writeInstallationFile(installation); + sID = readInstallationFile(installation); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + return sID; + } + + private static String readInstallationFile(File installation) throws IOException { + RandomAccessFile f = new RandomAccessFile(installation, "r"); + byte[] bytes = new byte[(int) f.length()]; + f.readFully(bytes); + f.close(); + return new String(bytes); + } + + private static void writeInstallationFile(File installation) throws IOException { + FileOutputStream out = new FileOutputStream(installation); + String id = UUID.randomUUID().toString(); + out.write(id.getBytes()); + out.close(); + } +} diff --git a/myutils/src/main/res/values/strings.xml b/myutils/src/main/res/values/strings.xml new file mode 100644 index 0000000000..9081883473 --- /dev/null +++ b/myutils/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + MyUtils + diff --git a/myutils/src/test/java/com/sun/myutils/ExampleUnitTest.java b/myutils/src/test/java/com/sun/myutils/ExampleUnitTest.java new file mode 100644 index 0000000000..bec38aaf5a --- /dev/null +++ b/myutils/src/test/java/com/sun/myutils/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.sun.myutils; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7e181230c0..d940d9fc19 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,3 @@ -include ':app', +include ':app', ':myutils', ':utilcode', ':subutil'