├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── dictionaries
│ └── pddstudio.xml
├── vcs.xml
├── runConfigurations.xml
├── compiler.xml
├── modules.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── pddstudio
│ │ │ └── androidbutlerdemo
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── pddstudio
│ │ │ └── androidbutlerdemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── pddstudio
│ │ └── androidbutlerdemo
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── james-core
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── pddstudio
│ │ │ └── james
│ │ │ └── core
│ │ │ ├── abstracts
│ │ │ └── AbstractService.java
│ │ │ ├── utils
│ │ │ ├── Log.java
│ │ │ └── Logger.java
│ │ │ ├── services
│ │ │ └── MediaPlayer.java
│ │ │ └── James.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── pddstudio
│ │ │ └── james
│ │ │ └── core
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── pddstudio
│ │ └── james
│ │ └── core
│ │ └── ApplicationTest.java
├── build.gradle
└── proguard-rules.pro
├── james-http
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── pddstudio
│ │ │ └── james
│ │ │ └── http
│ │ │ ├── interfaces
│ │ │ └── RemoteJamesCallback.java
│ │ │ ├── model
│ │ │ ├── TwilioResponseCarrier.java
│ │ │ └── TwilioResponse.java
│ │ │ ├── RemoteJamesService.java
│ │ │ └── TwilioService.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── pddstudio
│ │ │ └── james
│ │ │ └── http
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── pddstudio
│ │ └── james
│ │ └── http
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── james-utils
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── item_icon.xml
│ │ │ │ └── dialog_layout_material.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── pddstudio
│ │ │ └── james
│ │ │ └── utils
│ │ │ ├── adapters
│ │ │ └── IconAdapter.java
│ │ │ ├── IconicDialog.java
│ │ │ └── MaterialDialog.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── pddstudio
│ │ │ └── james
│ │ │ └── utils
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── pddstudio
│ │ └── james
│ │ └── utils
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── james-server
├── .gitignore
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── pddstudio
│ │ └── james
│ │ └── server
│ │ ├── utils
│ │ ├── Log.java
│ │ └── Logger.java
│ │ └── ServerJames.java
└── build.gradle
├── settings.gradle
├── start-james-server.sh
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | Android Butler
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/james-core/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/james-http/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/james-utils/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/james-server/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':james-core', ':james-utils', ':james-http', ':james-server'
2 |
--------------------------------------------------------------------------------
/start-james-server.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | clear
3 | java -jar james-server/build/libs/james-server-full-1.0.jar
4 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android Butler
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/android-butler/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/james-core/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | james-core
3 |
4 |
--------------------------------------------------------------------------------
/james-http/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | james-http
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/android-butler/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/android-butler/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/android-butler/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/android-butler/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/android-butler/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/dictionaries/pddstudio.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | twilio
5 |
6 |
7 |
--------------------------------------------------------------------------------
/james-utils/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | james-utils
3 | Pick an Icon
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/james-utils/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 24sp
4 | 18sp
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/james-http/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/james-core/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/james-utils/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/james-core/src/main/java/com/pddstudio/james/core/abstracts/AbstractService.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.core.abstracts;
2 |
3 | /**
4 | * This Class was created by Patrick J
5 | * on 16.03.16. For more Details and Licensing
6 | * have a look at the README.md
7 | */
8 | public abstract class AbstractService {
9 | public abstract String getServiceName();
10 | public abstract Class> getServiceClass();
11 | }
12 |
--------------------------------------------------------------------------------
/james-core/src/test/java/com/pddstudio/james/core/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.core;
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 | }
--------------------------------------------------------------------------------
/james-http/src/test/java/com/pddstudio/james/http/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.http;
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 | }
--------------------------------------------------------------------------------
/james-utils/src/test/java/com/pddstudio/james/utils/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.utils;
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 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/pddstudio/androidbutlerdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.androidbutlerdemo;
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 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/james-core/src/androidTest/java/com/pddstudio/james/core/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.core;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/james-http/src/androidTest/java/com/pddstudio/james/http/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.http;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/james-utils/src/androidTest/java/com/pddstudio/james/utils/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.utils;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/pddstudio/androidbutlerdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.androidbutlerdemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/james-http/src/main/java/com/pddstudio/james/http/interfaces/RemoteJamesCallback.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.http.interfaces;
2 |
3 | /**
4 | * This Class was created by Patrick J
5 | * on 22.03.16. For more Details and Licensing
6 | * have a look at the README.md
7 | */
8 | public interface RemoteJamesCallback {
9 | void onConnected();
10 | void onConnectionFailed(Throwable throwable);
11 | void onCallbackReceived(Object o);
12 | void onConnectionClosed();
13 | }
14 |
--------------------------------------------------------------------------------
/james-utils/src/main/res/layout/item_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/james-core/src/main/java/com/pddstudio/james/core/utils/Log.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.core.utils;
2 |
3 | /**
4 | * This Class was created by Patrick J
5 | * on 22.03.16. For more Details and Licensing
6 | * have a look at the README.md
7 | */
8 | public enum Log {
9 | DEBUG("D"),
10 | INFO("I"),
11 | WARNING("W"),
12 | ERROR("E");
13 |
14 | final String log;
15 |
16 | Log(String log) {
17 | this.log = log;
18 | }
19 |
20 | public String getPrefix() {
21 | return log;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/james-server/src/main/java/com/pddstudio/james/server/utils/Log.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.core.utils;
2 |
3 | /**
4 | * This Class was created by Patrick J
5 | * on 22.03.16. For more Details and Licensing
6 | * have a look at the README.md
7 | */
8 | public enum Log {
9 | DEBUG("D"),
10 | INFO("I"),
11 | WARNING("W"),
12 | ERROR("E");
13 |
14 | final String log;
15 |
16 | Log(String log) {
17 | this.log = log;
18 | }
19 |
20 | public String getPrefix() {
21 | return log;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/james-core/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "24.0.0 rc1"
6 |
7 | defaultConfig {
8 | minSdkVersion 10
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.2.1'
25 | }
26 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/pddstudio/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 | #}
18 |
--------------------------------------------------------------------------------
/james-core/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/pddstudio/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 | #}
18 |
--------------------------------------------------------------------------------
/james-http/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/pddstudio/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 | #}
18 |
--------------------------------------------------------------------------------
/james-utils/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/pddstudio/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 | #}
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/james-server/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | version = '1.0'
4 | sourceCompatibility = 1.7
5 | targetCompatibility = 1.7
6 |
7 | //create a single Jar with all dependencies
8 | task jamesServerJar(type: Jar) {
9 | manifest {
10 | attributes 'Implementation-Title': 'Gradle Jar File Example',
11 | 'Implementation-Version': version,
12 | 'Main-Class': 'com.pddstudio.james.server.ServerJames'
13 | }
14 | baseName = project.name + '-full'
15 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
16 | with jar
17 | }
18 |
19 | //Get dependencies from Maven central repository
20 | repositories {
21 | mavenCentral()
22 | }
23 |
24 | dependencies {
25 | compile fileTree(include: ['*.jar'], dir: 'libs')
26 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "24.0.0 rc1"
6 |
7 | defaultConfig {
8 | applicationId "com.pddstudio.androidbutlerdemo"
9 | minSdkVersion 16
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.2.1'
26 | compile project(':james-core')
27 | compile project(':james-utils')
28 | compile project(':james-http')
29 | }
30 |
--------------------------------------------------------------------------------
/james-utils/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "24.0.0 rc1"
6 |
7 | defaultConfig {
8 | minSdkVersion 10
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(include: ['*.jar'], dir: 'libs')
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.2.1'
25 | compile project(':james-core')
26 | //android iconics and fonts
27 | compile 'com.mikepenz:iconics-core:2.5.9@aar'
28 | compile 'com.mikepenz:community-material-typeface:1.3.41.1@aar'
29 | }
30 |
--------------------------------------------------------------------------------
/james-http/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "24.0.0 rc1"
6 |
7 | defaultConfig {
8 | minSdkVersion 10
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.2.1'
25 | compile project(':james-core')
26 | //okhttp for network requests
27 | compile 'com.squareup.okhttp3:okhttp:3.2.0'
28 | //gson for json parsing
29 | compile 'com.google.code.gson:gson:2.6.2'
30 | }
31 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
/james-core/src/main/java/com/pddstudio/james/core/services/MediaPlayer.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.core.services;
2 |
3 | import android.support.annotation.RawRes;
4 |
5 | import com.pddstudio.james.core.James;
6 | import com.pddstudio.james.core.abstracts.AbstractService;
7 |
8 | /**
9 | * This Class was created by Patrick J
10 | * on 21.03.16. For more Details and Licensing
11 | * have a look at the README.md
12 | */
13 | public class MediaPlayer extends AbstractService {
14 |
15 | private final James mJames;
16 | private android.media.MediaPlayer mMediaPlayer;
17 |
18 | public MediaPlayer(James james) {
19 | this.mJames = james;
20 | }
21 |
22 | public void play(@RawRes int rawId) {
23 | this.mMediaPlayer = android.media.MediaPlayer.create(mJames.getContext(), rawId);
24 | }
25 |
26 | @Override
27 | public String getServiceName() {
28 | return getClass().getSimpleName();
29 | }
30 |
31 | @Override
32 | public Class> getServiceClass() {
33 | return MediaPlayer.class;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/james-server/src/main/java/com/pddstudio/james/server/ServerJames.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.server;
2 |
3 | import com.pddstudio.james.core.utils.Logger;
4 |
5 | import java.io.IOException;
6 | import java.net.ServerSocket;
7 | import java.net.Socket;
8 |
9 | public class ServerJames {
10 |
11 | private static final int SERVER_PORT = 3012;
12 |
13 | private ServerSocket serverSocket;
14 |
15 | public static void main(String[] args) {
16 | ServerJames serverJames = new ServerJames();
17 | serverJames.startServer();
18 | }
19 |
20 | private void startServer() {
21 | Logger.log(this, "Starting Server on port " + SERVER_PORT);
22 | try {
23 | serverSocket = new ServerSocket(SERVER_PORT);
24 | while(true) {
25 | Socket clientSocket = serverSocket.accept();
26 | Logger.log(this, "Client connected: " + clientSocket.getInetAddress().getHostAddress());
27 | }
28 | } catch (IOException io) {
29 | io.printStackTrace();
30 | }
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/james-http/src/main/java/com/pddstudio/james/http/model/TwilioResponseCarrier.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.http.model;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * This Class was created by Patrick J
7 | * on 20.03.16. For more Details and Licensing
8 | * have a look at the README.md
9 | */
10 | public class TwilioResponseCarrier {
11 |
12 | @SerializedName("type")
13 | private String type;
14 | @SerializedName("error_code")
15 | private String errorCode;
16 | @SerializedName("mobile_network_code")
17 | private String mobileNetworkCode;
18 | @SerializedName("mobile_country_code")
19 | private String mobileCountryCode;
20 | @SerializedName("name")
21 | private String carrierName;
22 |
23 | public String getType() {
24 | return type;
25 | }
26 |
27 | public String getErrorCode() {
28 | return errorCode;
29 | }
30 |
31 | public String getMobileNetworkCode() {
32 | return mobileNetworkCode;
33 | }
34 |
35 | public String getMobileCountryCode() {
36 | return mobileCountryCode;
37 | }
38 |
39 | public String getCarrierName() {
40 | return carrierName;
41 | }
42 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/james-core/src/main/java/com/pddstudio/james/core/James.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.core;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import com.pddstudio.james.core.abstracts.AbstractService;
7 |
8 | import java.lang.reflect.Constructor;
9 |
10 | /*
11 | * This Class was created by Patrick J
12 | * on 16.03.16. For more Details and Licensing
13 | * have a look at the README.md
14 | */
15 | public final class James {
16 |
17 | private static final String LOG_TAG = "James";
18 |
19 | private final Context mContext;
20 |
21 | private James(Context context) {
22 | this.mContext = context;
23 | }
24 |
25 | public static James with(Context context) {
26 | return new James(context);
27 | }
28 |
29 | public T serve(Class serviceName) {
30 | try {
31 | Constructor> mConstructor = serviceName.getConstructor(James.class);
32 | return (T) mConstructor.newInstance(this);
33 | } catch (Exception e) {
34 | Log.e(LOG_TAG, "Unable to find, instantiate or cast the class you're looking for, Sir! Did you do something wrong?", e);
35 | throw new RuntimeException(e);
36 | }
37 | }
38 |
39 | public Context getContext() {
40 | return mContext;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/james-http/src/main/java/com/pddstudio/james/http/model/TwilioResponse.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.http.model;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * This Class was created by Patrick J
7 | * on 20.03.16. For more Details and Licensing
8 | * have a look at the README.md
9 | */
10 | public class TwilioResponse {
11 |
12 | @SerializedName("country_code") private String countryCode;
13 | @SerializedName("phone_number") private String phoneNumber;
14 | @SerializedName("national_format") private String nationalFormat;
15 | @SerializedName("url") private String url;
16 | @SerializedName("carrier") private TwilioResponseCarrier responseCarrier;
17 |
18 | public String getCountryCode() {
19 | return countryCode;
20 | }
21 |
22 | public String getPhoneNumber() {
23 | return phoneNumber;
24 | }
25 |
26 | public String getNationalFormat() {
27 | return nationalFormat;
28 | }
29 |
30 | public String getUrl() {
31 | return url;
32 | }
33 |
34 | public String getCarrierType() {
35 | return responseCarrier.getType();
36 | }
37 |
38 | public String getCarrierErrorCode() {
39 | return responseCarrier.getErrorCode();
40 | }
41 |
42 | public String getCarrierMobileNetworkCode() {
43 | return responseCarrier.getMobileNetworkCode();
44 | }
45 |
46 | public String getCarrierMobileCountryCode() {
47 | return responseCarrier.getMobileCountryCode();
48 | }
49 |
50 | public String getCarrierName() {
51 | return responseCarrier.getCarrierName();
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/james-utils/src/main/res/layout/dialog_layout_material.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
17 |
18 |
23 |
24 |
25 |
26 |
38 |
39 |
46 |
47 |
--------------------------------------------------------------------------------
/james-utils/src/main/java/com/pddstudio/james/utils/adapters/IconAdapter.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.utils.adapters;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.support.annotation.ColorInt;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.BaseAdapter;
9 |
10 | import com.mikepenz.community_material_typeface_library.CommunityMaterial;
11 | import com.mikepenz.iconics.view.IconicsImageView;
12 | import com.pddstudio.james.utils.R;
13 |
14 | /**
15 | * This Class was created by Patrick J
16 | * on 16.03.16. For more Details and Licensing
17 | * have a look at the README.md
18 | */
19 | public class IconAdapter extends BaseAdapter {
20 |
21 |
22 | private Context context;
23 | private CommunityMaterial.Icon[] itemList;
24 | @ColorInt
25 | private int iconColor = Color.BLACK;
26 |
27 | public IconAdapter(Context mContext) {
28 | context = mContext;
29 | itemList = CommunityMaterial.Icon.values();
30 | }
31 |
32 | public IconAdapter withColoredIcons(@ColorInt int color) {
33 | this.iconColor = color;
34 | return this;
35 | }
36 |
37 | public IconAdapter withColoredIcons(String hexValue) {
38 | this.iconColor = Color.parseColor(hexValue);
39 | return this;
40 | }
41 |
42 | @Override
43 | public int getCount() {
44 | return itemList.length;
45 | }
46 |
47 | @Override
48 | public CommunityMaterial.Icon getItem(int position) {
49 | if(position > 0 && position < itemList.length) {
50 | return itemList[position];
51 | }
52 | return null;
53 | }
54 |
55 | @Override
56 | public long getItemId(int position) {
57 | return 0;
58 | }
59 |
60 | @Override
61 | public View getView(int position, View convertView, ViewGroup parent) {
62 | if(convertView == null) convertView = View.inflate(context, R.layout.item_icon, null);
63 | IconicsImageView icon = (IconicsImageView) convertView.findViewById(R.id.icon_list_icon);
64 | icon.setColor(iconColor);
65 | icon.setIcon(itemList[position]);
66 | return convertView;
67 | }
68 |
69 | }
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/james-core/src/main/java/com/pddstudio/james/core/utils/Logger.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.core.utils;
2 |
3 | import java.util.Calendar;
4 | import java.util.GregorianCalendar;
5 |
6 | /**
7 | * This Class was created by Patrick J
8 | * on 22.03.16. For more Details and Licensing
9 | * have a look at the README.md
10 | */
11 | public class Logger {
12 |
13 | private Logger() {}
14 |
15 | public static void log(Class className, String message) {
16 | log(className.getSimpleName(), message);
17 | }
18 |
19 | public static void log(String logPrefix, String message) {
20 | String logMsg = getSystemTime() + "[" + logPrefix + "::/" + Log.DEBUG.getPrefix() + "] " + message;
21 | printLogMessage(logMsg);
22 | }
23 |
24 | public static void log(Object object, String message) {
25 | log(object, Log.DEBUG, message);
26 | }
27 |
28 | public static void log(Object object, Log logType, String message) {
29 | String logMsg = getSystemTime() + "[" + object.getClass().getSimpleName() + "::/" + logType.getPrefix() + "] " + message;
30 | printLogMessage(logMsg);
31 | }
32 |
33 | private static synchronized void printLogMessage(String logMessage) {
34 | System.out.println(logMessage);
35 | }
36 |
37 | private static String getSystemTime() {
38 | Calendar calendar = GregorianCalendar.getInstance();
39 | int day = calendar.get(Calendar.DAY_OF_MONTH);
40 | String newday;
41 | String newmnth;
42 |
43 | if(day < 10) {
44 | newday = "0" + day;
45 | } else {
46 | newday = "" + day;
47 | }
48 |
49 | int mnth = calendar.get(Calendar.MONTH);
50 | //cuz of stupid month -1 rule
51 | mnth++;
52 |
53 | if(mnth < 10) {
54 | newmnth = "0" + mnth;
55 | } else {
56 | newmnth = "" + mnth;
57 | }
58 |
59 | int year = calendar.get(Calendar.YEAR);
60 | int hr = calendar.get(Calendar.HOUR_OF_DAY);
61 | int min = calendar.get(Calendar.MINUTE);
62 | int sec = calendar.get(Calendar.SECOND);
63 | String secs;
64 | if(sec < 10) {
65 | secs = "0" + sec;
66 | } else {
67 | secs = "" + sec;
68 | }
69 | return "[" + newmnth + "-" + newday + "-" + year + "|" + hr + ":" + min + ":" +secs + "]";
70 | }
71 |
72 | }
--------------------------------------------------------------------------------
/james-server/src/main/java/com/pddstudio/james/server/utils/Logger.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.core.utils;
2 |
3 | import java.util.Calendar;
4 | import java.util.GregorianCalendar;
5 |
6 | /**
7 | * This Class was created by Patrick J
8 | * on 22.03.16. For more Details and Licensing
9 | * have a look at the README.md
10 | */
11 | public class Logger {
12 |
13 | private Logger() {}
14 |
15 | public static void log(Class className, String message) {
16 | log(className.getSimpleName(), message);
17 | }
18 |
19 | public static void log(String logPrefix, String message) {
20 | String logMsg = getSystemTime() + "[" + logPrefix + "::/" + Log.DEBUG.getPrefix() + "] " + message;
21 | printLogMessage(logMsg);
22 | }
23 |
24 | public static void log(Object object, String message) {
25 | log(object, Log.DEBUG, message);
26 | }
27 |
28 | public static void log(Object object, Log logType, String message) {
29 | String logMsg = getSystemTime() + "[" + object.getClass().getSimpleName() + "::/" + logType.getPrefix() + "] " + message;
30 | printLogMessage(logMsg);
31 | }
32 |
33 | private static synchronized void printLogMessage(String logMessage) {
34 | System.out.println(logMessage);
35 | }
36 |
37 | private static String getSystemTime() {
38 | Calendar calendar = GregorianCalendar.getInstance();
39 | int day = calendar.get(Calendar.DAY_OF_MONTH);
40 | String newday;
41 | String newmnth;
42 |
43 | if(day < 10) {
44 | newday = "0" + day;
45 | } else {
46 | newday = "" + day;
47 | }
48 |
49 | int mnth = calendar.get(Calendar.MONTH);
50 | //cuz of stupid month -1 rule
51 | mnth++;
52 |
53 | if(mnth < 10) {
54 | newmnth = "0" + mnth;
55 | } else {
56 | newmnth = "" + mnth;
57 | }
58 |
59 | int year = calendar.get(Calendar.YEAR);
60 | int hr = calendar.get(Calendar.HOUR_OF_DAY);
61 | int min = calendar.get(Calendar.MINUTE);
62 | int sec = calendar.get(Calendar.SECOND);
63 | String secs;
64 | if(sec < 10) {
65 | secs = "0" + sec;
66 | } else {
67 | secs = "" + sec;
68 | }
69 | return "[" + newmnth + "-" + newday + "-" + year + "|" + hr + ":" + min + ":" +secs + "]";
70 | }
71 |
72 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/james-http/src/main/java/com/pddstudio/james/http/RemoteJamesService.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.http;
2 |
3 | import android.os.AsyncTask;
4 |
5 | import com.pddstudio.james.core.James;
6 | import com.pddstudio.james.core.abstracts.AbstractService;
7 | import com.pddstudio.james.core.utils.Logger;
8 | import com.pddstudio.james.http.interfaces.RemoteJamesCallback;
9 |
10 | import java.io.BufferedReader;
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 | import java.io.InputStreamReader;
14 | import java.net.Socket;
15 |
16 | /**
17 | * This Class was created by Patrick J
18 | * on 22.03.16. For more Details and Licensing
19 | * have a look at the README.md
20 | */
21 | public class RemoteJamesService extends AbstractService {
22 |
23 | private final James mJames;
24 |
25 | private String mRemoteAddress = "localhost";
26 | private int mRemotePort = 1337; //lol, geeky stuff
27 | private RemoteJamesCallback mRemoteCallback;
28 |
29 | public RemoteJamesService(James james) {
30 | this.mJames = james;
31 | }
32 |
33 | public void setConnectionInfo(String remoteAddress, int remotePort) {
34 | this.mRemoteAddress = remoteAddress;
35 | this.mRemotePort = remotePort;
36 | }
37 |
38 | public void setRemoteCallback(RemoteJamesCallback remoteCallback) {
39 | this.mRemoteCallback = remoteCallback;
40 | }
41 |
42 | public void connect() {
43 | new ConnectionService().execute();
44 | }
45 |
46 | @Override
47 | public String getServiceName() {
48 | return null;
49 | }
50 |
51 | @Override
52 | public Class> getServiceClass() {
53 | return null;
54 | }
55 |
56 | private class ConnectionService extends AsyncTask {
57 |
58 | private Throwable mThrowable;
59 |
60 | @Override
61 | protected Void doInBackground(Void... params) {
62 | try {
63 | Socket socket = new Socket(mRemoteAddress, mRemotePort);
64 | Logger.log(this, "Connection successful: " + socket.isConnected());
65 | if(mRemoteCallback != null && socket.isConnected()) {
66 | publishProgress(true);
67 | }
68 | InputStream inputStream = socket.getInputStream();
69 | InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
70 | BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
71 | String line;
72 | while((line = bufferedReader.readLine()) != null) {
73 | publishProgress(line);
74 | }
75 | } catch (IOException io) {
76 | mThrowable = io;
77 | this.cancel(true);
78 | }
79 | return null;
80 | }
81 |
82 | @Override
83 | protected void onCancelled() {
84 | if(mRemoteCallback != null) mRemoteCallback.onConnectionFailed(mThrowable);
85 | }
86 |
87 | @Override
88 | protected void onProgressUpdate(Object... objects) {
89 | if(objects[0] instanceof Boolean && mRemoteCallback != null) mRemoteCallback.onConnected();
90 | if(objects[0] instanceof String && mRemoteCallback != null) mRemoteCallback.onCallbackReceived(objects[0]);
91 | }
92 |
93 | @Override
94 | protected void onPostExecute(Void aVoid) {
95 | if(mRemoteCallback != null) mRemoteCallback.onConnectionClosed();
96 | }
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/james-utils/src/main/java/com/pddstudio/james/utils/IconicDialog.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.utils;
2 |
3 | import android.app.Dialog;
4 | import android.os.Bundle;
5 | import android.support.v4.app.DialogFragment;
6 | import android.support.v7.app.AlertDialog;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.widget.AdapterView;
11 | import android.widget.GridView;
12 |
13 | import com.mikepenz.iconics.typeface.IIcon;
14 | import com.pddstudio.james.core.James;
15 | import com.pddstudio.james.core.abstracts.AbstractService;
16 | import com.pddstudio.james.utils.adapters.IconAdapter;
17 |
18 | /*
19 | * This Class was created by Patrick J
20 | * on 16.03.16. For more Details and Licensing
21 | * have a look at the README.md
22 | */
23 | public class IconicDialog extends AbstractService implements AdapterView.OnItemClickListener {
24 |
25 | public interface IconCallback {
26 | void onIconSelected(IIcon selectedIcon);
27 | }
28 |
29 |
30 | private final James mJames;
31 | private AppCompatActivity mActivity;
32 | private IconDialog mIconDialog;
33 | private AlertDialog mAlertDialog;
34 | private IconCallback mIconCallback;
35 | private IconAdapter mIconAdapter;
36 | private GridView mGridView;
37 |
38 | public IconicDialog(James james) {
39 | this.mJames = james;
40 | this.mActivity = (AppCompatActivity) james.getContext();
41 | buildDialog();
42 | }
43 |
44 | public IconicDialog withIconCallback(IconCallback iconCallback) {
45 | this.mIconCallback = iconCallback;
46 | return this;
47 | }
48 |
49 | private void buildDialog() {
50 | //create the dialog layout and adapter
51 | this.mGridView = new GridView(mActivity);
52 | this.mIconAdapter = new IconAdapter(mActivity);
53 |
54 | //prepare the dialog layout
55 | mGridView.setAdapter(mIconAdapter);
56 | mGridView.setNumColumns(5);
57 | mGridView.setOnItemClickListener(this);
58 |
59 | this.mAlertDialog = new AlertDialog.Builder(mActivity)
60 | .setTitle(R.string.icon_chooser_dialog_title)
61 | .setView(mGridView)
62 | .create();
63 |
64 | mIconDialog = new IconDialog().withDialog(mAlertDialog);
65 | }
66 |
67 | public void show() {
68 | mIconDialog.show(mActivity.getSupportFragmentManager(), "ICONIC_DIALOG");
69 | }
70 |
71 | public void hide() {
72 | mIconDialog.dismiss();
73 | }
74 |
75 | @Override
76 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
77 | Log.d("IconicDialog", "Clicked on Icon: " + position);
78 | hide();
79 | if(mIconCallback != null) mIconCallback.onIconSelected(mIconAdapter.getItem(position));
80 | }
81 |
82 | @Override
83 | public String getServiceName() {
84 | return getClass().getSimpleName();
85 | }
86 |
87 | @Override
88 | public Class> getServiceClass() {
89 | return IconicDialog.class;
90 | }
91 |
92 | public static class IconDialog extends DialogFragment {
93 |
94 | private AlertDialog mAlertDialog;
95 |
96 | public IconDialog() {}
97 |
98 | public IconDialog withDialog(AlertDialog alertDialog) {
99 | this.mAlertDialog = alertDialog;
100 | return this;
101 | }
102 |
103 | @Override
104 | public Dialog onCreateDialog(Bundle savedInstance) {
105 | return mAlertDialog;
106 | }
107 |
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pddstudio/androidbutlerdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.androidbutlerdemo;
2 |
3 | import android.content.DialogInterface;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.view.Window;
9 | import android.widget.Button;
10 |
11 | import com.mikepenz.community_material_typeface_library.CommunityMaterial;
12 | import com.mikepenz.iconics.typeface.IIcon;
13 | import com.pddstudio.james.core.James;
14 | import com.pddstudio.james.core.utils.Logger;
15 | import com.pddstudio.james.http.RemoteJamesService;
16 | import com.pddstudio.james.http.TwilioService;
17 | import com.pddstudio.james.http.interfaces.RemoteJamesCallback;
18 | import com.pddstudio.james.utils.IconicDialog;
19 | import com.pddstudio.james.utils.MaterialDialog;
20 |
21 | public class MainActivity extends AppCompatActivity implements IconicDialog.IconCallback, View.OnClickListener {
22 |
23 | Button demoButton;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | requestWindowFeature(Window.FEATURE_NO_TITLE);
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 | demoButton = (Button) findViewById(R.id.demoButton);
31 | demoButton.setOnClickListener(this);
32 | //showDialog();
33 | }
34 |
35 | private void showDialog() {
36 | IconicDialog iconicDialog = James.with(this).serve(IconicDialog.class);
37 | iconicDialog.withIconCallback(this);
38 | iconicDialog.show();
39 | }
40 |
41 | private void showMaterialDialog() {
42 | MaterialDialog materialDialog = James.with(this).serve(MaterialDialog.class);
43 | materialDialog.withActivity(this)
44 | .withHeaderBackgroundColor(getResources().getColor(R.color.colorPrimary))
45 | .withTitleString("Material Dialogs")
46 | .withContentString("This is a demo Dialog\nServed for you, by James!\n\nWe hope you enjoy, Sir ;-)")
47 | .withHeaderIcon(CommunityMaterial.Icon.cmd_github_circle)
48 | .withPositiveButtonText("Okay", new DialogInterface.OnClickListener() {
49 | @Override
50 | public void onClick(DialogInterface dialog, int which) {
51 |
52 | }
53 | }).show();
54 | }
55 |
56 | private void demoTwilioRequest() {
57 | TwilioService twilioService = James.with(this).serve(TwilioService.class).setCredentials("", "");
58 | }
59 |
60 | private void demoConnection() {
61 | RemoteJamesService remoteJamesService = James.with(MainActivity.this).serve(RemoteJamesService.class);
62 | remoteJamesService.setConnectionInfo("10.128.64.173", 3012);
63 | remoteJamesService.setRemoteCallback(new RemoteJamesCallback() {
64 | @Override
65 | public void onConnected() {
66 | Logger.log(this, "Connected!");
67 | }
68 |
69 | @Override
70 | public void onConnectionFailed(Throwable throwable) {
71 | Logger.log(this, "Connection failed!");
72 | throwable.printStackTrace();
73 | }
74 |
75 | @Override
76 | public void onCallbackReceived(Object o) {
77 | Logger.log(this, o.toString());
78 | }
79 |
80 | @Override
81 | public void onConnectionClosed() {
82 | Logger.log(this, "Connection closed.");
83 | }
84 | });
85 | remoteJamesService.connect();
86 | }
87 |
88 | @Override
89 | public void onIconSelected(IIcon selectedIcon) {
90 | Log.d("MainActivity", "Selected Icon: " + selectedIcon.getFormattedName() + " | " + selectedIcon.getName());
91 | }
92 |
93 | @Override
94 | public void onClick(View v) {
95 | if(v.getId() == R.id.demoButton) {
96 | //showMaterialDialog();
97 | demoConnection();
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/james-http/src/main/java/com/pddstudio/james/http/TwilioService.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.http;
2 |
3 | import android.os.AsyncTask;
4 | import android.support.annotation.Nullable;
5 |
6 | import com.google.gson.Gson;
7 | import com.pddstudio.james.core.James;
8 | import com.pddstudio.james.core.abstracts.AbstractService;
9 | import com.pddstudio.james.http.model.TwilioResponse;
10 |
11 | import java.io.IOException;
12 |
13 | import okhttp3.OkHttpClient;
14 | import okhttp3.Request;
15 | import okhttp3.Response;
16 |
17 | /**
18 | * This Class was created by Patrick J
19 | * on 19.03.16. For more Details and Licensing
20 | * have a look at the README.md
21 | */
22 | public class TwilioService extends AbstractService {
23 |
24 | public interface ResponseCallback {
25 | void onRequestStarted();
26 | void onRequestFailed();
27 | void onRequestFinished(@Nullable TwilioResponse twilioResponse);
28 | }
29 |
30 | private final James mJames;
31 | private String mAccountSid;
32 | private String mToken;
33 | private String mTargetAddress;
34 | private ResponseCallback mResponseCallback;
35 |
36 | public TwilioService(James james) {
37 | this.mJames = james;
38 | }
39 |
40 | public TwilioService setCredentials(String accountSid, String token) {
41 | this.mAccountSid = accountSid;
42 | this.mToken = token;
43 | return this;
44 | }
45 |
46 | public TwilioService setResponseCallback(ResponseCallback responseCallback) {
47 | this.mResponseCallback = responseCallback;
48 | return this;
49 | }
50 |
51 | private void validateService() {
52 | if(mAccountSid == null || mAccountSid.isEmpty()) throw new RuntimeException("TwilioService AccountSID can't be null or empty.");
53 | if(mToken == null || mToken.isEmpty()) throw new RuntimeException("TwilioService Token can't be null or empty");
54 | if(mResponseCallback == null) throw new RuntimeException("TwilioService can't be executed without a callback.");
55 | }
56 |
57 | public void lookup(String phoneNumber) {
58 | //assign the target address
59 | this.mTargetAddress = phoneNumber;
60 | //validate that everything is correct
61 | if(mTargetAddress == null || mTargetAddress.isEmpty()) throw new RuntimeException("Can't execute a request on a phone number which is null or empty.");
62 | validateService();
63 | //execute the task
64 | new RequestTask().execute();
65 | }
66 |
67 | @Override
68 | public String getServiceName() {
69 | return getClass().getSimpleName();
70 | }
71 |
72 | @Override
73 | public Class> getServiceClass() {
74 | return TwilioService.class;
75 | }
76 |
77 | private class RequestTask extends AsyncTask {
78 |
79 | private static final String TWILIO_URL_PRE = "https://lookups.twilio.com/v1/PhoneNumbers/";
80 | private static final String TWILIO_URL_POST = "?Type=carrier";
81 |
82 | private RequestTask() {}
83 |
84 | @Override
85 | public void onPreExecute() {
86 | mResponseCallback.onRequestStarted();
87 | }
88 |
89 | @Override
90 | protected TwilioResponse doInBackground(Void... params) {
91 |
92 | OkHttpClient okHttpClient = new OkHttpClient();
93 | Gson gson = new Gson();
94 |
95 | try {
96 |
97 | Request request = new Request.Builder()
98 | .url(TWILIO_URL_PRE + mTargetAddress + TWILIO_URL_POST)
99 | .addHeader(mAccountSid, mToken)
100 | .build();
101 |
102 | Response response = okHttpClient.newCall(request).execute();
103 | if(response.isSuccessful()) return gson.fromJson(response.body().charStream(), TwilioResponse.class);
104 | else throw new IOException("Request wasn't successful");
105 | } catch (IOException io) {
106 | io.printStackTrace();
107 | this.cancel(true);
108 | }
109 | return null;
110 | }
111 |
112 | @Override
113 | protected void onCancelled() {
114 | mResponseCallback.onRequestFailed();
115 | }
116 |
117 | @Override
118 | public void onPostExecute(TwilioResponse twilioResponse) {
119 | mResponseCallback.onRequestFinished(twilioResponse);
120 | }
121 |
122 | }
123 |
124 | }
125 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/james-utils/src/main/java/com/pddstudio/james/utils/MaterialDialog.java:
--------------------------------------------------------------------------------
1 | package com.pddstudio.james.utils;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.graphics.Color;
7 | import android.os.Bundle;
8 | import android.support.annotation.ColorInt;
9 | import android.support.annotation.StringRes;
10 | import android.support.v4.app.DialogFragment;
11 | import android.support.v7.app.AlertDialog;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.widget.ImageView;
16 | import android.widget.TextView;
17 |
18 | import com.mikepenz.iconics.IconicsDrawable;
19 | import com.mikepenz.iconics.typeface.IIcon;
20 | import com.mikepenz.iconics.view.IconicsImageView;
21 | import com.pddstudio.james.core.James;
22 | import com.pddstudio.james.core.abstracts.AbstractService;
23 |
24 | /**
25 | * This Class was created by Patrick J
26 | * on 21.03.16. For more Details and Licensing
27 | * have a look at the README.md
28 | */
29 | public class MaterialDialog extends AbstractService implements DialogInterface.OnShowListener {
30 |
31 | private final James mJames;
32 | private final Context mContext;
33 |
34 | //dialog variables
35 | private AppCompatActivity mActivity;
36 | @ColorInt private int mHeaderColor = Color.TRANSPARENT;
37 | @ColorInt private int mHeaderIconColor = Color.WHITE;
38 | private String mTitleString;
39 | private String mContentString;
40 | private String mPositiveButton;
41 | private String mNegativeButton;
42 | private String mNeutralButton;
43 | private IIcon mDialogIcon;
44 | private String mDialogIconName;
45 |
46 | private DialogInterface.OnClickListener mNeutralOnClickListener;
47 | private DialogInterface.OnClickListener mPositiveOnClickListener;
48 | private DialogInterface.OnClickListener mNegativeOnClickListener;
49 |
50 | private AlertDialog mAlertDialog;
51 |
52 | public MaterialDialog(James james) {
53 | this.mJames = james;
54 | this.mContext = james.getContext();
55 | }
56 |
57 | private void prepareDialog() {
58 | LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
59 | View dialogLayout = layoutInflater.inflate(R.layout.dialog_layout_material, null);
60 | }
61 |
62 | public MaterialDialog withActivity(AppCompatActivity activity) {
63 | this.mActivity = activity;
64 | return this;
65 | }
66 |
67 | public MaterialDialog withHeaderBackgroundColor(String color) {
68 | this.mHeaderColor = Color.parseColor(color);
69 | return this;
70 | }
71 |
72 | public MaterialDialog withHeaderBackgroundColor(@ColorInt int color) {
73 | this.mHeaderColor = color;
74 | return this;
75 | }
76 |
77 | public MaterialDialog withHeaderIcon(String iconName) {
78 | this.mDialogIconName = iconName;
79 | return this;
80 | }
81 |
82 | public MaterialDialog withHeaderIcon(IIcon icon) {
83 | this.mDialogIcon = icon;
84 | return this;
85 | }
86 |
87 | public MaterialDialog withHeaderIconColor(@ColorInt int iconColor) {
88 | this.mHeaderIconColor = iconColor;
89 | return this;
90 | }
91 |
92 | public MaterialDialog withHeaderIconColor(String iconColor) {
93 | this.mHeaderIconColor = Color.parseColor(iconColor);
94 | return this;
95 | }
96 |
97 | public MaterialDialog withTitleString(String titleString) {
98 | this.mTitleString = titleString;
99 | return this;
100 | }
101 |
102 | public MaterialDialog withTitleString(@StringRes int titleString) {
103 | this.mTitleString = mContext.getString(titleString);
104 | return this;
105 | }
106 |
107 | public MaterialDialog withContentString(String contentString) {
108 | this.mContentString = contentString;
109 | return this;
110 | }
111 |
112 | public MaterialDialog withContentString(@StringRes int contentString) {
113 | this.mContentString = mContext.getString(contentString);
114 | return this;
115 | }
116 |
117 | public MaterialDialog withPositiveButtonText(String positiveButtonText, DialogInterface.OnClickListener onClickListener) {
118 | this.mPositiveButton = positiveButtonText;
119 | this.mPositiveOnClickListener = onClickListener;
120 | return this;
121 | }
122 |
123 | public MaterialDialog withPositiveButtonText(@StringRes int positiveButtonText, DialogInterface.OnClickListener onClickListener) {
124 | this.mPositiveButton = mContext.getString(positiveButtonText);
125 | this.mPositiveOnClickListener = onClickListener;
126 | return this;
127 | }
128 |
129 | public MaterialDialog withNegativeButtonText(String negativeButtonText, DialogInterface.OnClickListener onClickListener) {
130 | this.mNegativeButton = negativeButtonText;
131 | this.mNegativeOnClickListener = onClickListener;
132 | return this;
133 | }
134 |
135 | public MaterialDialog withNegativeButtonText(@StringRes int negativeButtonText, DialogInterface.OnClickListener onClickListener) {
136 | this.mNegativeButton = mContext.getString(negativeButtonText);
137 | this.mNegativeOnClickListener = onClickListener;
138 | return this;
139 | }
140 |
141 | public MaterialDialog withNeutralButtonText(String neutralButtonText, DialogInterface.OnClickListener onClickListener) {
142 | this.mNeutralButton = neutralButtonText;
143 | this.mNeutralOnClickListener = onClickListener;
144 | return this;
145 | }
146 |
147 | public MaterialDialog withNeutralButtonText(@StringRes int neutralButtonText, DialogInterface.OnClickListener onClickListener) {
148 | this.mNeutralButton = mContext.getString(neutralButtonText);
149 | this.mNeutralOnClickListener = onClickListener;
150 | return this;
151 | }
152 |
153 | public void show() {
154 | if(mActivity == null) throw new RuntimeException("You must specify an Activity for this Dialog!");
155 | View layoutView = mActivity.getLayoutInflater().inflate(R.layout.dialog_layout_material, null);
156 | //set the layout
157 | AlertDialog.Builder builder = new AlertDialog.Builder(mContext)
158 | .setView(layoutView);
159 | //set the buttons
160 | if(mNeutralButton != null) builder.setNeutralButton(mNeutralButton, mNeutralOnClickListener);
161 | if(mPositiveButton != null) builder.setPositiveButton(mPositiveButton, mPositiveOnClickListener);
162 | if(mNegativeButton != null) builder.setNegativeButton(mNegativeButton, mNegativeOnClickListener);
163 |
164 | //build the dialog and set the other config
165 | mAlertDialog = builder.create();
166 | mAlertDialog.setOnShowListener(this);
167 |
168 | //set the icon
169 | if(mDialogIcon != null) {
170 | IconicsImageView iconicsImageView = (IconicsImageView) layoutView.findViewById(R.id.dialog_header_icon);
171 | iconicsImageView.setIcon(new IconicsDrawable(mContext).icon(mDialogIcon).color(mHeaderIconColor));
172 | } else if(mDialogIconName != null) {
173 | IconicsImageView iconicsImageView = (IconicsImageView) layoutView.findViewById(R.id.dialog_header_icon);
174 | iconicsImageView.setIcon(new IconicsDrawable(mContext).icon(mDialogIconName).color(mHeaderIconColor));
175 | }
176 |
177 | //set the custom title
178 | if(mTitleString != null) {
179 | TextView titleText = (TextView) layoutView.findViewById(R.id.dialog_title);
180 | if(titleText != null) titleText.setText(mTitleString);
181 | }
182 | //set the custom content
183 | if(mContentString != null) {
184 | TextView contentText = (TextView) layoutView.findViewById(R.id.dialog_content);
185 | if(contentText != null) contentText.setText(mContentString);
186 | }
187 | //set the background color
188 | ImageView headerView = (ImageView) layoutView.findViewById(R.id.dialog_header_view);
189 | if(headerView != null) headerView.setBackgroundColor(mHeaderColor);
190 |
191 | MaterializedDialog materializedDialog = new MaterializedDialog().withDialog(mAlertDialog);
192 | materializedDialog.show(mActivity.getSupportFragmentManager(), "MATERIAL_DIALOG");
193 | }
194 |
195 | @Override
196 | public String getServiceName() {
197 | return getClass().getSimpleName();
198 | }
199 |
200 | @Override
201 | public Class> getServiceClass() {
202 | return MaterialDialog.class;
203 | }
204 |
205 | @Override
206 | public void onShow(DialogInterface dialog) {
207 | if(mHeaderColor != Color.TRANSPARENT) {
208 | if(mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) != null) mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mHeaderColor);
209 | if(mAlertDialog.getButton(AlertDialog.BUTTON_NEUTRAL) != null) mAlertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(mHeaderColor);
210 | if(mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE) != null) mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mHeaderColor);
211 | }
212 | }
213 |
214 | public static class MaterializedDialog extends DialogFragment {
215 |
216 | private AlertDialog mAlertDialog;
217 |
218 | public MaterializedDialog withDialog(AlertDialog alertDialog) {
219 | this.mAlertDialog = alertDialog;
220 | return this;
221 | }
222 |
223 | @Override
224 | public Dialog onCreateDialog(Bundle savedInstance) {
225 | return mAlertDialog;
226 | }
227 |
228 | }
229 |
230 |
231 | }
232 |
--------------------------------------------------------------------------------