Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoLSN committed Jun 11, 2016
2 parents f068406 + 0ae17a5 commit c88a08f
Show file tree
Hide file tree
Showing 56 changed files with 3,078 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#Android generated
bin/
gen/
lint.xml

#Eclipse
.project
.classpath
.settings
.checkstyle

#IntelliJ IDEA
.idea
*.iml
*.ipr
*.iws

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

gen-external-apklibs
.gradle/
local.properties

#Maven
target
release.properties
pom.xml.*

#Other
.DS_Store
dist

# Gradle
build
out

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
DialogAlchemy
========

This is a dialog utility library. It provides a easy way to let developers deal with screen rotation issue.

Installation
--------
```gradle
repositories {
...
maven { url "https://jitpack.io" }
}
dependencies {
...
compile 'com.github.NeoLSN:DialogAlchemy:1.0.0'
}
```
API
--------
- Alchemist - Dialog fragment
- Material - Basic dialog model
- PhilosopherStone - A interface for custom view
- TransmutationCircle - A interface for dialog creation factory
- DialogAlchemy - A utility class to show a dialog

Usage
--------
##### Basic Usage
```Java
Material material = new Material.Builder(getActivity())
.setTitle("Dialog Title")
.setMessage("Dialog message")
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
... do something ...
}
})
.setNegativeButton(android.R.string.cancel, null)
.build();

Alchemist alchemist = DialogAlchemy.show(getFragmentManager(), material);
```

##### Advanced Usage
```Java
//Create a custom view
PhilosopherStone stone = new EditTextStone.Builder()
.setText(...)
.setOnTextAcceptedListener(listener)
.build();

Material material = new Material.Builder(getActivity())
.setTitle("Dialog Title")
.setMessage("Dialog message")
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
... do something ...
}
})
.setNegativeButton(android.R.string.cancel, null)
.setPhilosopherStone(stone) // incre
.build();

Alchemist alchemist = DialogAlchemy.show(getFragmentManager(), material);
```

#### Reset listener or callback

When ```DialogAlchemy.show()``` called, it will set a tag to ```Alchemist``` automatically. You can use this tag to find this fragment after screen rotated.

##### For Activity
```Java
private Alchemist alchemist;

@Override
public void onCreate(Bundle savedInstanceState) {
...
if (savedInstanceState != null) {
String tag = savedInstanceState.getString(TAG_KEY);
alchemist = (Alchemist) getSupportFragmentManager().findFragmentByTag(tag);
Material material = alchemist.getMaterial();
Material.Builder builder = material.rebuild(this);

// reset listner or callback in here

Material newMaterial = builder.build();
alchemist.setMaterial(newMaterial);
}
}

@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString(TAG_KEY, alchemist.getTag());

super.onSaveInstanceState(outState);
}
```
##### For fragment
```Java
private Alchemist alchemist;

public void onViewCreated(View view, Bundle savedInstanceState) {
...
if (savedInstanceState != null) {
String tag = savedInstanceState.getString(TAG_KEY);
alchemist = (Alchemist) getFragmentManager().findFragmentByTag(tag);
Material material = alchemist.getMaterial();
Material.Builder builder = material.rebuild(this);

// reset listner or callback in here

Material newMaterial = builder.build();
alchemist.setMaterial(newMaterial);
}
}

@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString(TAG_KEY, alchemist.getTag());

super.onSaveInstanceState(outState);
}
```
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "ui.android.dialogalchemy.example"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile project(path: ':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
}
17 changes: 17 additions & 0 deletions 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/JasonYang/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 *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ui.android.dialogalchemy;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@MediumTest
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentationTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("ui.android.dialogalchemy", appContext.getPackageName());
}
}
20 changes: 20 additions & 0 deletions 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="ui.android.dialogalchemy.example">

<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>
Loading

0 comments on commit c88a08f

Please sign in to comment.