Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Added test module and tests for main library #3

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions android/TPSDropDown/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle/
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
local.properties
21 changes: 21 additions & 0 deletions android/TPSDropDown/.travis.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions android/TPSDropDown/TPSDropDown.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="TPSDropDown" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
1 change: 1 addition & 0 deletions android/TPSDropDown/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
51 changes: 51 additions & 0 deletions android/TPSDropDown/app/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
17 changes: 17 additions & 0 deletions android/TPSDropDown/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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 *;
#}
20 changes: 20 additions & 0 deletions android/TPSDropDown/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gettipsi.tpsdropdown">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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<Object> {

public Adapter(Context context, int resource, List<Object> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Object> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 16 additions & 0 deletions android/TPSDropDown/app/src/main/res/layout/dropdown_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="@dimen/item_padding"
android:paddingRight="@dimen/item_padding"
android:minHeight="?android:attr/listPreferredItemHeightSmall">

<TextView
android:id="@id/dropdownTextItemId"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions android/TPSDropDown/app/src/main/res/values-w820dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<resources>
</resources>
6 changes: 6 additions & 0 deletions android/TPSDropDown/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
3 changes: 3 additions & 0 deletions android/TPSDropDown/app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<dimen name="item_padding">8dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions android/TPSDropDown/app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="dropdown" type="id" />
<item name="dropdownId" type="id" />
<item name="dropdownTextItemId" type="id" />
</resources>
3 changes: 3 additions & 0 deletions android/TPSDropDown/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">TPSDropDown</string>
</resources>
11 changes: 11 additions & 0 deletions android/TPSDropDown/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
Loading