diff --git a/.travis.yml b/.travis.yml index df54535..309aff6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ osx_image: xcode7.3 language: objective-c script: xcodebuild -workspace ios/Example/TPSDropDown.xcworkspace -scheme TPSDropDown-Example -sdk iphonesimulator -destination 'name=iPhone 6' build test | xcpretty -c && exit ${PIPESTATUS[0]} +after_script: cd android/TPSDropDown/ && .travis.yml diff --git a/android/TPSDropDown/.gitignore b/android/TPSDropDown/.gitignore new file mode 100644 index 0000000..39c4e29 --- /dev/null +++ b/android/TPSDropDown/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle/ +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +local.properties diff --git a/android/TPSDropDown/.travis.yml b/android/TPSDropDown/.travis.yml new file mode 100644 index 0000000..f28ab10 --- /dev/null +++ b/android/TPSDropDown/.travis.yml @@ -0,0 +1,21 @@ +language: android +jdk: oraclejdk8 +sudo: false + +android: + components: + - platform-tools + - tools + - build-tools-23.0.3 + - android-22 + - android-23 + - sys-img-armeabi-v7a-android-22 + - extra-android-m2repository + +before_script: + - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a + - emulator -avd test -no-skin -no-audio -no-window & + - android-wait-for-emulator + - adb shell input keyevent 82 & + +script: ./gradlew connectedAndroidTest diff --git a/android/TPSDropDown/TPSDropDown.iml b/android/TPSDropDown/TPSDropDown.iml new file mode 100644 index 0000000..abcda3e --- /dev/null +++ b/android/TPSDropDown/TPSDropDown.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/TPSDropDown/app/.gitignore b/android/TPSDropDown/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/android/TPSDropDown/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/android/TPSDropDown/app/build.gradle b/android/TPSDropDown/app/build.gradle new file mode 100644 index 0000000..0716615 --- /dev/null +++ b/android/TPSDropDown/app/build.gradle @@ -0,0 +1,51 @@ +apply plugin: 'com.android.library' +apply plugin: 'com.github.dcendents.android-maven' + +group='com.github.tipsi' + +android { + compileSdkVersion 24 + buildToolsVersion "23.0.3" + + defaultConfig { + + minSdkVersion 16 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' +} + +task javadoc(type: Javadoc) { + failOnError false + source = android.sourceSets.main.java.sourceFiles + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + classpath += configurations.compile +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +artifacts { + archives sourcesJar + archives javadocJar +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:24.2.0' + androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' +} diff --git a/android/TPSDropDown/app/proguard-rules.pro b/android/TPSDropDown/app/proguard-rules.pro new file mode 100644 index 0000000..4cd6204 --- /dev/null +++ b/android/TPSDropDown/app/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/dima/Library/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/TPSDropDown/app/src/main/AndroidManifest.xml b/android/TPSDropDown/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..3140471 --- /dev/null +++ b/android/TPSDropDown/app/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/TPSDropDown/app/src/main/java/com/gettipsi/tpsdropdown/Adapter.java b/android/TPSDropDown/app/src/main/java/com/gettipsi/tpsdropdown/Adapter.java new file mode 100644 index 0000000..583b713 --- /dev/null +++ b/android/TPSDropDown/app/src/main/java/com/gettipsi/tpsdropdown/Adapter.java @@ -0,0 +1,39 @@ +package com.gettipsi.tpsdropdown; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import java.util.List; + +public class Adapter extends ArrayAdapter { + + public Adapter(Context context, int resource, List objects) { + super(context, resource, objects); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder holder; + if (convertView == null) { + convertView = LayoutInflater.from(getContext()).inflate(R.layout.dropdown_line, parent, false); + holder = new ViewHolder(convertView); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } + holder.text.setText(getItem(position).toString()); + return convertView; + } + + private class ViewHolder { + TextView text; + + public ViewHolder(View view) { + text = (TextView) view.findViewById(R.id.dropdownTextItemId); + } + } +} \ No newline at end of file diff --git a/android/TPSDropDown/app/src/main/java/com/gettipsi/tpsdropdown/Dropdown.java b/android/TPSDropDown/app/src/main/java/com/gettipsi/tpsdropdown/Dropdown.java new file mode 100644 index 0000000..b0016de --- /dev/null +++ b/android/TPSDropDown/app/src/main/java/com/gettipsi/tpsdropdown/Dropdown.java @@ -0,0 +1,106 @@ +package com.gettipsi.tpsdropdown; + +import android.content.Context; +import android.support.v7.widget.AppCompatSpinner; +import android.view.View; +import android.widget.AdapterView; +import android.widget.SpinnerAdapter; + +import java.util.List; + +public class Dropdown extends AppCompatSpinner { + + private Context context; + private boolean firstEventFired = false; + private int selectedIndex = 0; + private int selected = 0; + private DropdownUpdateEvent dropdownUpdateEvent; + + public Dropdown(Context context) { + super(context, 0); + this.context = context; + setOnItemSelectedListener(ON_ITEM_SELECTED_LISTENER); + } + + public void setDropdownUpdateEvent(DropdownUpdateEvent dropdownUpdateEvent) { + this.dropdownUpdateEvent = dropdownUpdateEvent; + } + + public void setupWithElements(List values) { + final Adapter spinnerArrayAdapter = new Adapter(context, + android.R.layout.simple_spinner_item, values); + spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + post(new Runnable() { + @Override + public void run() { + setAdapter(spinnerArrayAdapter); + setSelection(selectedIndex); + } + }); + } + + public void selectElementWithName(String name) { + SpinnerAdapter adapter = getAdapter(); + if (adapter != null) { + int index = 0; + for (int i = 0; i < adapter.getCount(); i++) { + if (adapter.getItem(i).toString().equals(name)) { + index = i; + break; + } + } + setSelected(index); + } + } + + public void setSelected(final int selected) { + post(new Runnable() { + @Override + public void run() { + if (selected == selectedIndex && selected == Dropdown.this.selected) { + return; + } + selectedIndex = selected; + setSelection(selectedIndex); + } + }); + } + + private final OnItemSelectedListener ON_ITEM_SELECTED_LISTENER = + new OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int pos, long id) { + selected = pos; + if (!firstEventFired) { + firstEventFired = true; + return; + } + if (dropdownUpdateEvent != null) { + dropdownUpdateEvent.onUpdate(view, getId(), pos, parent.getSelectedItem().toString()); + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }; + + private final Runnable mLayoutRunnable = new Runnable() { + @Override + public void run() { + measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY)); + layout(getLeft(), getTop(), getRight(), getBottom()); + } + }; + + @Override + public void requestLayout() { + super.requestLayout(); + post(mLayoutRunnable); + } + + public interface DropdownUpdateEvent { + void onUpdate(View view, int id, int pos, String selectedItem); + } +} \ No newline at end of file diff --git a/android/TPSDropDown/app/src/main/java/com/gettipsi/tpsdropdown/DropdownContainer.java b/android/TPSDropDown/app/src/main/java/com/gettipsi/tpsdropdown/DropdownContainer.java new file mode 100644 index 0000000..e040ab3 --- /dev/null +++ b/android/TPSDropDown/app/src/main/java/com/gettipsi/tpsdropdown/DropdownContainer.java @@ -0,0 +1,40 @@ +package com.gettipsi.tpsdropdown; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.ViewGroup; +import android.widget.FrameLayout; + +public class DropdownContainer extends FrameLayout { + + private Dropdown dropdown; + + public DropdownContainer(Context context) { + super(context); + initDropdown(); + } + + public DropdownContainer(Context context, AttributeSet attrs) { + super(context, attrs); + initDropdown(); + } + + public DropdownContainer(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initDropdown(); + } + + private void initDropdown() { + dropdown = new Dropdown(getContext()); + ViewGroup.LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.START); + dropdown.setId(R.id.dropdownId); + dropdown.setLayoutParams(params); + addView(dropdown); + } + + public Dropdown getDropdown() { + return dropdown; + } +} diff --git a/android/TPSDropDown/app/src/main/res/layout/dropdown_line.xml b/android/TPSDropDown/app/src/main/res/layout/dropdown_line.xml new file mode 100644 index 0000000..246df92 --- /dev/null +++ b/android/TPSDropDown/app/src/main/res/layout/dropdown_line.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/android/TPSDropDown/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/TPSDropDown/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/android/TPSDropDown/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/TPSDropDown/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/android/TPSDropDown/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/TPSDropDown/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/android/TPSDropDown/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/TPSDropDown/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/android/TPSDropDown/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/TPSDropDown/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/android/TPSDropDown/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/app/src/main/res/values-w820dp/dimens.xml b/android/TPSDropDown/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..8542005 --- /dev/null +++ b/android/TPSDropDown/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,2 @@ + + diff --git a/android/TPSDropDown/app/src/main/res/values/colors.xml b/android/TPSDropDown/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/android/TPSDropDown/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/android/TPSDropDown/app/src/main/res/values/dimens.xml b/android/TPSDropDown/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..2dd232d --- /dev/null +++ b/android/TPSDropDown/app/src/main/res/values/dimens.xml @@ -0,0 +1,3 @@ + + 8dp + diff --git a/android/TPSDropDown/app/src/main/res/values/ids.xml b/android/TPSDropDown/app/src/main/res/values/ids.xml new file mode 100644 index 0000000..c4b3de5 --- /dev/null +++ b/android/TPSDropDown/app/src/main/res/values/ids.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/TPSDropDown/app/src/main/res/values/strings.xml b/android/TPSDropDown/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..86a80d4 --- /dev/null +++ b/android/TPSDropDown/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + TPSDropDown + diff --git a/android/TPSDropDown/app/src/main/res/values/styles.xml b/android/TPSDropDown/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..5885930 --- /dev/null +++ b/android/TPSDropDown/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/android/TPSDropDown/build.gradle b/android/TPSDropDown/build.gradle new file mode 100644 index 0000000..a697592 --- /dev/null +++ b/android/TPSDropDown/build.gradle @@ -0,0 +1,26 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + mavenLocal() + jcenter() + maven { url "https://jitpack.io" } + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/android/TPSDropDown/gradle.properties b/android/TPSDropDown/gradle.properties new file mode 100644 index 0000000..1d3591c --- /dev/null +++ b/android/TPSDropDown/gradle.properties @@ -0,0 +1,18 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true \ No newline at end of file diff --git a/android/TPSDropDown/gradle/wrapper/gradle-wrapper.jar b/android/TPSDropDown/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/android/TPSDropDown/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/TPSDropDown/gradle/wrapper/gradle-wrapper.properties b/android/TPSDropDown/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..4518eb6 --- /dev/null +++ b/android/TPSDropDown/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Sep 07 12:23:23 EEST 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/android/TPSDropDown/gradlew b/android/TPSDropDown/gradlew new file mode 100755 index 0000000..9d82f78 --- /dev/null +++ b/android/TPSDropDown/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/android/TPSDropDown/gradlew.bat b/android/TPSDropDown/gradlew.bat new file mode 100644 index 0000000..aec9973 --- /dev/null +++ b/android/TPSDropDown/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/android/TPSDropDown/settings.gradle b/android/TPSDropDown/settings.gradle new file mode 100644 index 0000000..a77560b --- /dev/null +++ b/android/TPSDropDown/settings.gradle @@ -0,0 +1 @@ +include ':app', ':testmodule' diff --git a/android/TPSDropDown/testmodule/.gitignore b/android/TPSDropDown/testmodule/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/android/TPSDropDown/testmodule/.gitignore @@ -0,0 +1 @@ +/build diff --git a/android/TPSDropDown/testmodule/build.gradle b/android/TPSDropDown/testmodule/build.gradle new file mode 100644 index 0000000..d645ed4 --- /dev/null +++ b/android/TPSDropDown/testmodule/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion "23.0.3" + + defaultConfig { + applicationId "com.gettipsi.testmodule" + minSdkVersion 16 + targetSdkVersion 24 + 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']) + testCompile 'junit:junit:4.12' + compile project(':app') + androidTestCompile 'com.android.support:support-annotations:24.2.0' + androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' +} diff --git a/android/TPSDropDown/testmodule/proguard-rules.pro b/android/TPSDropDown/testmodule/proguard-rules.pro new file mode 100644 index 0000000..4cd6204 --- /dev/null +++ b/android/TPSDropDown/testmodule/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/dima/Library/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/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/DropdownTests.java b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/DropdownTests.java new file mode 100644 index 0000000..a368ab3 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/DropdownTests.java @@ -0,0 +1,139 @@ +package com.gettipsi.testmodule; + +import android.os.SystemClock; +import android.support.test.espresso.assertion.ViewAssertions; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.LargeTest; + +import com.gettipsi.testmodule.action.SelectElementWithNameAction; +import com.gettipsi.testmodule.action.SetSelectedAction; +import com.gettipsi.testmodule.action.SetupElementsAction; +import com.gettipsi.testmodule.matcher.DropdownMatcher; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.List; + +import static android.support.test.espresso.Espresso.onData; +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.withClassName; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withSpinnerText; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; + +@RunWith(AndroidJUnit4.class) +@LargeTest +public class DropdownTests { + + private List items; + + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(MainActivity.class); + + + @Before + public void initValidData() { + items = Arrays.asList("One", "Two", "Three", "Four"); + } + + @Test + public void checkForCorrectViews() { + onView(withId(R.id.dropdown)) + .check(matches(withClassName(endsWith("DropdownContainer")))); + onView(withId(R.id.dropdownId)) + .check(matches(withClassName(endsWith("Dropdown")))); + } + + @Test + public void checkItemsSelection() { + setupItems(); + + onView(withId(R.id.dropdownId)) + .perform(new SetSelectedAction(0)) + .check(matches(withSpinnerText(items.get(0).toString()))); + + SystemClock.sleep(1000); + onView(withId(R.id.dropdownId)) + .perform(new SetSelectedAction(1)) + .check(matches(withSpinnerText(items.get(1).toString()))); + + SystemClock.sleep(1000); + onView(withId(R.id.dropdownId)) + .perform(new SetSelectedAction(2)) + .check(matches(withSpinnerText(items.get(2).toString()))); + + SystemClock.sleep(1000); + onView(withId(R.id.dropdownId)) + .perform(new SetSelectedAction(3)) + .check(matches(withSpinnerText(items.get(3).toString()))); + + SystemClock.sleep(1000); + } + + @Test + public void checkItemsWithNameSelection() { + setupItems(); + onView(withId(R.id.dropdownId)) + .perform(new SelectElementWithNameAction(items.get(0).toString())) + .check(matches(withSpinnerText(items.get(0).toString()))); + + SystemClock.sleep(1000); + onView(withId(R.id.dropdownId)) + .perform(new SelectElementWithNameAction(items.get(1).toString())) + .check(matches(withSpinnerText(items.get(1).toString()))); + + SystemClock.sleep(1000); + onView(withId(R.id.dropdownId)) + .perform(new SelectElementWithNameAction(items.get(2).toString())) + .check(matches(withSpinnerText(items.get(2).toString()))); + + SystemClock.sleep(1000); + onView(withId(R.id.dropdownId)) + .perform(new SelectElementWithNameAction(items.get(3).toString())) + .check(matches(withSpinnerText(items.get(3).toString()))); + + SystemClock.sleep(1000); + } + + @Test + public void checkItemsClickSelection() { + setupItems(); + String item = items.get(0).toString(); + onView(withId(R.id.dropdownId)).perform(click()); + onData(allOf(is(instanceOf(String.class)), is(item))).perform(click()); + onView(withId(R.id.dropdownId)).check(matches(withSpinnerText(containsString(item)))); + + String item1 = items.get(1).toString(); + onView(withId(R.id.dropdownId)).perform(click()); + onData(allOf(is(instanceOf(String.class)), is(item1))).perform(click()); + onView(withId(R.id.dropdownId)).check(matches(withSpinnerText(containsString(item1)))); + + String item2 = items.get(2).toString(); + onView(withId(R.id.dropdownId)).perform(click()); + onData(allOf(is(instanceOf(String.class)), is(item2))).perform(click()); + onView(withId(R.id.dropdownId)).check(matches(withSpinnerText(containsString(item2)))); + + String item3 = items.get(3).toString(); + onView(withId(R.id.dropdownId)).perform(click()); + onData(allOf(is(instanceOf(String.class)), is(item3))).perform(click()); + onView(withId(R.id.dropdownId)).check(matches(withSpinnerText(containsString(item3)))); + } + + private void setupItems() { + onView(withId(R.id.dropdownId)) + .perform(new SetupElementsAction(items)) + .check(ViewAssertions.matches(DropdownMatcher.withListSize(items.size()))); + } + +} diff --git a/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/action/SelectElementWithNameAction.java b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/action/SelectElementWithNameAction.java new file mode 100644 index 0000000..63206e9 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/action/SelectElementWithNameAction.java @@ -0,0 +1,34 @@ +package com.gettipsi.testmodule.action; + +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.espresso.matcher.ViewMatchers; +import android.view.View; + +import com.gettipsi.tpsdropdown.Dropdown; + +import org.hamcrest.Matcher; + +public class SelectElementWithNameAction implements ViewAction { + + private String name; + + public SelectElementWithNameAction(String name) { + this.name = name; + } + + @Override + public Matcher getConstraints() { + return ViewMatchers.isAssignableFrom(Dropdown.class); + } + + @Override + public String getDescription() { + return "SelectElementWithNameAction"; + } + + @Override + public void perform(UiController uiController, View view) { + ((Dropdown) view).selectElementWithName(name); + } +} diff --git a/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/action/SetSelectedAction.java b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/action/SetSelectedAction.java new file mode 100644 index 0000000..4f5cedc --- /dev/null +++ b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/action/SetSelectedAction.java @@ -0,0 +1,35 @@ +package com.gettipsi.testmodule.action; + +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.view.View; + +import com.gettipsi.tpsdropdown.Dropdown; + +import org.hamcrest.Matcher; + +import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; + +public class SetSelectedAction implements ViewAction { + + private int selectionId; + + public SetSelectedAction(int selectionId) { + this.selectionId = selectionId; + } + + @Override + public Matcher getConstraints() { + return isAssignableFrom(Dropdown.class); + } + + @Override + public String getDescription() { + return "DropdownSelectionAction"; + } + + @Override + public void perform(UiController uiController, View view) { + ((Dropdown) view).setSelected(selectionId); + } +} diff --git a/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/action/SetupElementsAction.java b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/action/SetupElementsAction.java new file mode 100644 index 0000000..5907c41 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/action/SetupElementsAction.java @@ -0,0 +1,37 @@ +package com.gettipsi.testmodule.action; + +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.espresso.matcher.ViewMatchers; +import android.view.View; + +import com.gettipsi.tpsdropdown.Dropdown; + +import org.hamcrest.Matcher; + +import java.util.List; + +public class SetupElementsAction implements ViewAction { + + private List items; + + public SetupElementsAction(List items) { + this.items = items; + } + + @Override + public Matcher getConstraints() { + return ViewMatchers.isAssignableFrom(Dropdown.class); + } + + @Override + public String getDescription() { + return "SetupElementsAction"; + } + + @Override + public void perform(UiController uiController, View view) { + Dropdown dropdown = (Dropdown) view; + dropdown.setupWithElements(items); + } +} diff --git a/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/matcher/DropdownMatcher.java b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/matcher/DropdownMatcher.java new file mode 100644 index 0000000..0df5c87 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/androidTest/java/com/gettipsi/testmodule/matcher/DropdownMatcher.java @@ -0,0 +1,28 @@ +package com.gettipsi.testmodule.matcher; + +import android.view.View; +import android.widget.AdapterView; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class DropdownMatcher { + + public static Matcher withListSize(final int size) { + return new TypeSafeMatcher() { + int length; + + @Override + public boolean matchesSafely(final View view) { + length = ((AdapterView) view).getAdapter().getCount(); + return length == size; + } + + @Override + public void describeTo(final Description description) { + description.appendText("ListView should have " + size + " items, the actual size is " + length); + } + }; + } +} diff --git a/android/TPSDropDown/testmodule/src/main/AndroidManifest.xml b/android/TPSDropDown/testmodule/src/main/AndroidManifest.xml new file mode 100644 index 0000000..65a0ec6 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/main/AndroidManifest.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/TPSDropDown/testmodule/src/main/java/com/gettipsi/testmodule/MainActivity.java b/android/TPSDropDown/testmodule/src/main/java/com/gettipsi/testmodule/MainActivity.java new file mode 100644 index 0000000..79e49b8 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/main/java/com/gettipsi/testmodule/MainActivity.java @@ -0,0 +1,13 @@ +package com.gettipsi.testmodule; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } +} diff --git a/android/TPSDropDown/testmodule/src/main/res/layout/activity_main.xml b/android/TPSDropDown/testmodule/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..2721a04 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/main/res/layout/activity_main.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/android/TPSDropDown/testmodule/src/main/res/mipmap-hdpi/ic_launcher.png b/android/TPSDropDown/testmodule/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/android/TPSDropDown/testmodule/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/testmodule/src/main/res/mipmap-mdpi/ic_launcher.png b/android/TPSDropDown/testmodule/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/android/TPSDropDown/testmodule/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/testmodule/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/TPSDropDown/testmodule/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/android/TPSDropDown/testmodule/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/testmodule/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/TPSDropDown/testmodule/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/android/TPSDropDown/testmodule/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/testmodule/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/TPSDropDown/testmodule/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/android/TPSDropDown/testmodule/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/TPSDropDown/testmodule/src/main/res/values-w820dp/dimens.xml b/android/TPSDropDown/testmodule/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..8542005 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,2 @@ + + diff --git a/android/TPSDropDown/testmodule/src/main/res/values/colors.xml b/android/TPSDropDown/testmodule/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/android/TPSDropDown/testmodule/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/android/TPSDropDown/testmodule/src/main/res/values/dimens.xml b/android/TPSDropDown/testmodule/src/main/res/values/dimens.xml new file mode 100644 index 0000000..8542005 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/main/res/values/dimens.xml @@ -0,0 +1,2 @@ + + diff --git a/android/TPSDropDown/testmodule/src/main/res/values/strings.xml b/android/TPSDropDown/testmodule/src/main/res/values/strings.xml new file mode 100644 index 0000000..20e5f6c --- /dev/null +++ b/android/TPSDropDown/testmodule/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + TestModule + diff --git a/android/TPSDropDown/testmodule/src/main/res/values/styles.xml b/android/TPSDropDown/testmodule/src/main/res/values/styles.xml new file mode 100644 index 0000000..5885930 --- /dev/null +++ b/android/TPSDropDown/testmodule/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + +