diff --git a/.travis.yml b/.travis.yml index f2442f0..de29070 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,10 +16,25 @@ android: - 'android-sdk-license-.+' - 'google-gdk-license-.+' +# Emulator Management: Create, Start and Wait before_script: + - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a + - emulator -avd test -no-audio -no-window & - chmod +x gradlew script: - echo "Travis branch is $TRAVIS_BRANCH" - echo "Travis branch is in pull request $TRAVIS_PULL+REQUEST" - - ./gradlew clean build :lib:test :tinypinyin-lexicons-android-cncity:test :tinypinyin-android-asset-lexicons:test \ No newline at end of file + - android-wait-for-emulator + - adb shell input keyevent 82 + - ./gradlew clean build :lib:test :tinypinyin-lexicons-android-cncity:test :tinypinyin-android-asset-lexicons:test :android-sample:connectedAndroidTest + + +notifications: + email: + - gyacong@gmail.com + +cache: + directories: + - $HOME/.m2 + - $HOME/.gradle \ No newline at end of file diff --git a/README.md b/README.md index b977eff..7d8f55a 100644 --- a/README.md +++ b/README.md @@ -59,11 +59,11 @@ buildscript { } dependencies { - compile 'com.github.promeg:tinypinyin:2.0.1' // TinyPinyin核心包,约80KB + compile 'com.github.promeg:tinypinyin:2.0.2' // TinyPinyin核心包,约80KB - compile 'com.github.promeg:tinypinyin-lexicons-android-cncity:2.0.1' // 可选,适用于Android的中国地区词典 + compile 'com.github.promeg:tinypinyin-lexicons-android-cncity:2.0.2' // 可选,适用于Android的中国地区词典 - compile 'com.github.promeg:tinypinyin-lexicons-java-cncity:2.0.1' // 可选,适用于Java的中国地区词典 + compile 'com.github.promeg:tinypinyin-lexicons-java-cncity:2.0.2' // 可选,适用于Java的中国地区词典 } } ``` @@ -100,7 +100,7 @@ buildscript { 采用以下命令运行test: ```groovy -./gradlew clean build :lib:test :tinypinyin-lexicons-android-cncity:test :tinypinyin-android-asset-lexicons:test +./gradlew clean build :lib:test :tinypinyin-lexicons-android-cncity:test :tinypinyin-android-asset-lexicons:test :android-sample:connectedAndroidTest ``` ### 3\. Effectiveness diff --git a/android-sample/.gitignore b/android-sample/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/android-sample/.gitignore @@ -0,0 +1 @@ +/build diff --git a/android-sample/build.gradle b/android-sample/build.gradle new file mode 100644 index 0000000..5c9ffad --- /dev/null +++ b/android-sample/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.github.promeg:tinypinyin-lexicons-android-cncity:' + rootProject.ext.releaseVersionName + + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + testCompile 'junit:junit:4.12' +} diff --git a/android-sample/proguard-rules.pro b/android-sample/proguard-rules.pro new file mode 100644 index 0000000..3b52b43 --- /dev/null +++ b/android-sample/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/guyacong/Documents/android-sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# 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 *; +#} diff --git a/android-sample/src/androidTest/java/com/github/promeg/tinypinyin/android_sample/MainActivityTest.java b/android-sample/src/androidTest/java/com/github/promeg/tinypinyin/android_sample/MainActivityTest.java new file mode 100644 index 0000000..eaa10b9 --- /dev/null +++ b/android-sample/src/androidTest/java/com/github/promeg/tinypinyin/android_sample/MainActivityTest.java @@ -0,0 +1,27 @@ +package com.github.promeg.tinypinyin.android_sample; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; + +/** + * Created by guyacong on 2017/2/5. + */ +@RunWith(AndroidJUnit4.class) +public class MainActivityTest { + @Rule + public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void tinypinyin_should_work(){ + onView(withId(R.id.mTvText)).check(matches(withText("ZHONGGUOCHONGQING"))); + } +} diff --git a/android-sample/src/main/AndroidManifest.xml b/android-sample/src/main/AndroidManifest.xml new file mode 100644 index 0000000..79cc975 --- /dev/null +++ b/android-sample/src/main/AndroidManifest.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/android-sample/src/main/java/com/github/promeg/tinypinyin/android_sample/MainActivity.java b/android-sample/src/main/java/com/github/promeg/tinypinyin/android_sample/MainActivity.java new file mode 100644 index 0000000..d977488 --- /dev/null +++ b/android-sample/src/main/java/com/github/promeg/tinypinyin/android_sample/MainActivity.java @@ -0,0 +1,25 @@ +package com.github.promeg.tinypinyin.android_sample; + +import com.github.promeg.pinyinhelper.Pinyin; +import com.github.promeg.tinypinyin.lexicons.android.cncity.CnCityDict; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +public class MainActivity extends Activity { + + TextView mTvText; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mTvText = (TextView) findViewById(R.id.mTvText); + + Pinyin.init(Pinyin.newConfig().with(CnCityDict.getInstance(MainActivity.this))); + + mTvText.setText(Pinyin.toPinyin("中国重庆", "")); + } +} diff --git a/android-sample/src/main/res/layout/activity_main.xml b/android-sample/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..448784b --- /dev/null +++ b/android-sample/src/main/res/layout/activity_main.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/android-sample/src/main/res/values/strings.xml b/android-sample/src/main/res/values/strings.xml new file mode 100644 index 0000000..561de34 --- /dev/null +++ b/android-sample/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + TinyPinyin-Sample + diff --git a/android-sample/src/test/java/com/github/promeg/tinypinyin/android_sample/ExampleUnitTest.java b/android-sample/src/test/java/com/github/promeg/tinypinyin/android_sample/ExampleUnitTest.java new file mode 100644 index 0000000..db600a1 --- /dev/null +++ b/android-sample/src/test/java/com/github/promeg/tinypinyin/android_sample/ExampleUnitTest.java @@ -0,0 +1,18 @@ +package com.github.promeg.tinypinyin.android_sample; + +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/build.gradle b/build.gradle index ea03124..790aca5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,16 @@ -group 'com.github.promeg' -version '1.0-SNAPSHOT' - - buildscript { repositories { jcenter() + maven { + url "https://plugins.gradle.org/m2/" + } } dependencies { - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1' + classpath 'com.android.tools.build:gradle:2.2.3' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1" + classpath "gradle.plugin.com.kageiit:lintrules:1.1.2" } } @@ -38,7 +40,7 @@ ext { groupName = 'com.github.promeg' - releaseVersionName = "2.0.1" + releaseVersionName = "2.0.2" releaseVersionCode = 4 // Android diff --git a/settings.gradle b/settings.gradle index c324854..dc2bcdf 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ include ':tinypinyin-lexicons-android-cncity', ':tinypinyin-lexicons-java-cncity', + ':android-sample', ':tinypinyin-android-asset-lexicons' rootProject.name = 'tinypinyin' include 'lib' diff --git a/tinypinyin-android-asset-lexicons/build.gradle b/tinypinyin-android-asset-lexicons/build.gradle index e695d19..266775d 100644 --- a/tinypinyin-android-asset-lexicons/build.gradle +++ b/tinypinyin-android-asset-lexicons/build.gradle @@ -17,7 +17,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' + classpath 'com.android.tools.build:gradle:2.2.3' } } diff --git a/tinypinyin-lexicons-android-cncity/build.gradle b/tinypinyin-lexicons-android-cncity/build.gradle index cc75a1d..966ae55 100644 --- a/tinypinyin-lexicons-android-cncity/build.gradle +++ b/tinypinyin-lexicons-android-cncity/build.gradle @@ -17,7 +17,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' + classpath 'com.android.tools.build:gradle:2.2.3' } } @@ -62,7 +62,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.github.promeg:tinypinyin:' + rootProject.ext.releaseVersionName compile 'com.github.promeg:tinypinyin-android-asset-lexicons:' + rootProject.ext.releaseVersionName androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {