Skip to content

Commit 88c4c52

Browse files
committed
Initial commit.
0 parents  commit 88c4c52

File tree

32 files changed

+590
-0
lines changed

32 files changed

+590
-0
lines changed

build.gradle

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:2.1.0-alpha5'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
jcenter()
18+
}
19+
}
20+
21+
task clean(type: Delete) {
22+
delete rootProject.buildDir
23+
}

command/build.gradle

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.2"
6+
7+
defaultConfig {
8+
minSdkVersion 9
9+
targetSdkVersion 23
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
21+
dataBinding {
22+
enabled = true
23+
}
24+
}
25+
26+
dependencies {
27+
compile fileTree(dir: 'libs', include: ['*.jar'])
28+
testCompile 'junit:junit:4.12'
29+
compile 'com.android.support:appcompat-v7:23.2.1'
30+
}

command/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:\Tools\Android\sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package net.droidlabs.binding.command;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

command/src/main/AndroidManifest.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="net.droidlabs.binding.command">
3+
4+
<application android:allowBackup="true"
5+
android:label="@string/app_name"
6+
android:supportsRtl="true"
7+
>
8+
9+
</application>
10+
11+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.droidlabs.binding.command;
2+
3+
import android.databinding.ObservableBoolean;
4+
5+
public abstract class Command implements ICommand
6+
{
7+
private final ObservableBoolean enabled;
8+
private final ObservableBoolean inProgress;
9+
10+
public Command()
11+
{
12+
this.enabled = new ObservableBoolean(true);
13+
this.inProgress = new ObservableBoolean(false);
14+
}
15+
16+
@Override
17+
public ObservableBoolean canExecute()
18+
{
19+
return this.enabled;
20+
}
21+
22+
@Override
23+
public void canExecute(boolean enabled)
24+
{
25+
this.enabled.set(enabled);
26+
}
27+
28+
@Override
29+
public void isRefreshing(boolean inProgress)
30+
{
31+
this.inProgress.set(inProgress);
32+
}
33+
34+
@Override
35+
public ObservableBoolean isRefreshing()
36+
{
37+
return this.inProgress;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.droidlabs.binding.command;
2+
3+
import android.databinding.ObservableBoolean;
4+
5+
public interface ICommand
6+
{
7+
ObservableBoolean canExecute();
8+
9+
void canExecute(boolean enabled);
10+
11+
void isRefreshing(boolean inProgress);
12+
13+
ObservableBoolean isRefreshing();
14+
15+
void execute();
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package net.droidlabs.binding.command;
2+
3+
public class SynchronousCommand
4+
{
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.droidlabs.binding.command;
2+
3+
import android.databinding.BindingAdapter;
4+
import android.view.View;
5+
6+
public class ViewBindings
7+
{
8+
@BindingAdapter({"command"})
9+
public static void bindEditText(View view, final ICommand command)
10+
{
11+
if (view.getTag(R.id.commandBinded) == null)
12+
{
13+
view.setTag(R.id.commandBinded, true);
14+
view.setOnClickListener(new View.OnClickListener()
15+
{
16+
@Override
17+
public void onClick(View v)
18+
{
19+
command.execute();
20+
}
21+
});
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package net.droidlabs.binding.command;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* To work on unit tests, switch the Test Artifact in the Build Variants view.
9+
*/
10+
public class ExampleUnitTest {
11+
@Test
12+
public void addition_isCorrect() throws Exception {
13+
assertEquals(4, 2 + 2);
14+
}
15+
}

gradle.properties

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE (e.g. Android Studio) users:
4+
# Gradle settings configured through the IDE *will override*
5+
# any settings specified in this file.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
# Default value: -Xmx10248m -XX:MaxPermSize=256m
13+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14+
15+
# When configured, Gradle will run in incubating parallel mode.
16+
# This option should only be used with decoupled projects. More details, visit
17+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18+
# org.gradle.parallel=true

sample/build.gradle

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.2"
6+
7+
defaultConfig {
8+
applicationId "net.droidlabs.binding.commandsample"
9+
minSdkVersion 15
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
22+
dataBinding {
23+
enabled = true
24+
}
25+
}
26+
27+
dependencies {
28+
compile fileTree(include: ['*.jar'], dir: 'libs')
29+
testCompile 'junit:junit:4.12'
30+
compile 'com.android.support:appcompat-v7:23.2.1'
31+
compile 'com.android.support:design:23.2.1'
32+
33+
compile 'com.jakewharton.timber:timber:4.1.0'
34+
compile 'com.innahema:collections-query:0.2.9'
35+
36+
compile 'io.reactivex:rxandroid:1.1.0'
37+
compile 'io.reactivex:rxjava:1.1.0'
38+
compile 'com.artemzin.rxjava:proguard-rules:1.1.0.0'
39+
40+
compile 'com.jakewharton.rxbinding:rxbinding:0.3.0'
41+
compile 'com.jakewharton.rxbinding:rxbinding-recyclerview-v7:0.3.0'
42+
compile 'com.jakewharton.rxbinding:rxbinding-design:0.3.0'
43+
compile 'com.jakewharton.rxbinding:rxbinding-support-v4:0.3.0'
44+
compile 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:0.3.0'
45+
46+
compile project(':command')
47+
}

sample/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:\Tools\Android\sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package net.droidlabs.binding.command.sample;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application>
10+
{
11+
public ApplicationTest()
12+
{
13+
super(Application.class);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package net.droidlabs.binding.commandsample.view;
2+
3+
public interface IMainView
4+
{
5+
void showMessage(String message);
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.droidlabs.binding.commandsample.view;
2+
3+
import android.databinding.DataBindingUtil;
4+
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.widget.Toast;
7+
import net.droidlabs.binding.commandsample.R;
8+
import net.droidlabs.binding.commandsample.databinding.ActivityMainBinding;
9+
import net.droidlabs.binding.commandsample.viewmodel.MainActivityViewModel;
10+
11+
public class MainActivity extends AppCompatActivity implements IMainView
12+
{
13+
private ActivityMainBinding binding;
14+
private MainActivityViewModel viewModel;
15+
16+
@Override
17+
protected void onCreate(Bundle savedInstanceState)
18+
{
19+
super.onCreate(savedInstanceState);
20+
21+
viewModel = new MainActivityViewModel(this);
22+
23+
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
24+
binding.setViewModel(viewModel);
25+
26+
initToolbar(binding);
27+
}
28+
29+
private void initToolbar(ActivityMainBinding binding)
30+
{
31+
setSupportActionBar(binding.toolbar);
32+
}
33+
34+
@Override
35+
public void showMessage(String message)
36+
{
37+
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
38+
}
39+
}

0 commit comments

Comments
 (0)