Skip to content

Commit c88a08f

Browse files
committed
Merge branch 'release/1.0.0'
2 parents f068406 + 0ae17a5 commit c88a08f

56 files changed

Lines changed: 3078 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#Android generated
2+
bin/
3+
gen/
4+
lint.xml
5+
6+
#Eclipse
7+
.project
8+
.classpath
9+
.settings
10+
.checkstyle
11+
12+
#IntelliJ IDEA
13+
.idea
14+
*.iml
15+
*.ipr
16+
*.iws
17+
18+
# Android Studio Navigation editor temp files
19+
.navigation/
20+
21+
# Android Studio captures folder
22+
captures/
23+
24+
gen-external-apklibs
25+
.gradle/
26+
local.properties
27+
28+
#Maven
29+
target
30+
release.properties
31+
pom.xml.*
32+
33+
#Other
34+
.DS_Store
35+
dist
36+
37+
# Gradle
38+
build
39+
out
40+
41+
# Proguard folder generated by Eclipse
42+
proguard/
43+
44+
# Log Files
45+
*.log

README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
DialogAlchemy
2+
========
3+
4+
This is a dialog utility library. It provides a easy way to let developers deal with screen rotation issue.
5+
6+
Installation
7+
--------
8+
```gradle
9+
repositories {
10+
...
11+
maven { url "https://jitpack.io" }
12+
}
13+
dependencies {
14+
...
15+
compile 'com.github.NeoLSN:DialogAlchemy:1.0.0'
16+
}
17+
```
18+
API
19+
--------
20+
- Alchemist - Dialog fragment
21+
- Material - Basic dialog model
22+
- PhilosopherStone - A interface for custom view
23+
- TransmutationCircle - A interface for dialog creation factory
24+
- DialogAlchemy - A utility class to show a dialog
25+
26+
Usage
27+
--------
28+
##### Basic Usage
29+
```Java
30+
Material material = new Material.Builder(getActivity())
31+
.setTitle("Dialog Title")
32+
.setMessage("Dialog message")
33+
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
34+
@Override
35+
public void onClick(DialogInterface dialog, int which) {
36+
... do something ...
37+
}
38+
})
39+
.setNegativeButton(android.R.string.cancel, null)
40+
.build();
41+
42+
Alchemist alchemist = DialogAlchemy.show(getFragmentManager(), material);
43+
```
44+
45+
##### Advanced Usage
46+
```Java
47+
//Create a custom view
48+
PhilosopherStone stone = new EditTextStone.Builder()
49+
.setText(...)
50+
.setOnTextAcceptedListener(listener)
51+
.build();
52+
53+
Material material = new Material.Builder(getActivity())
54+
.setTitle("Dialog Title")
55+
.setMessage("Dialog message")
56+
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
57+
@Override
58+
public void onClick(DialogInterface dialog, int which) {
59+
... do something ...
60+
}
61+
})
62+
.setNegativeButton(android.R.string.cancel, null)
63+
.setPhilosopherStone(stone) // incre
64+
.build();
65+
66+
Alchemist alchemist = DialogAlchemy.show(getFragmentManager(), material);
67+
```
68+
69+
#### Reset listener or callback
70+
71+
When ```DialogAlchemy.show()``` called, it will set a tag to ```Alchemist``` automatically. You can use this tag to find this fragment after screen rotated.
72+
73+
##### For Activity
74+
```Java
75+
private Alchemist alchemist;
76+
77+
@Override
78+
public void onCreate(Bundle savedInstanceState) {
79+
...
80+
if (savedInstanceState != null) {
81+
String tag = savedInstanceState.getString(TAG_KEY);
82+
alchemist = (Alchemist) getSupportFragmentManager().findFragmentByTag(tag);
83+
Material material = alchemist.getMaterial();
84+
Material.Builder builder = material.rebuild(this);
85+
86+
// reset listner or callback in here
87+
88+
Material newMaterial = builder.build();
89+
alchemist.setMaterial(newMaterial);
90+
}
91+
}
92+
93+
@Override
94+
public void onSaveInstanceState(Bundle outState) {
95+
outState.putString(TAG_KEY, alchemist.getTag());
96+
97+
super.onSaveInstanceState(outState);
98+
}
99+
```
100+
##### For fragment
101+
```Java
102+
private Alchemist alchemist;
103+
104+
public void onViewCreated(View view, Bundle savedInstanceState) {
105+
...
106+
if (savedInstanceState != null) {
107+
String tag = savedInstanceState.getString(TAG_KEY);
108+
alchemist = (Alchemist) getFragmentManager().findFragmentByTag(tag);
109+
Material material = alchemist.getMaterial();
110+
Material.Builder builder = material.rebuild(this);
111+
112+
// reset listner or callback in here
113+
114+
Material newMaterial = builder.build();
115+
alchemist.setMaterial(newMaterial);
116+
}
117+
}
118+
119+
@Override
120+
public void onSaveInstanceState(Bundle outState) {
121+
outState.putString(TAG_KEY, alchemist.getTag());
122+
123+
super.onSaveInstanceState(outState);
124+
}
125+
```

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.3"
6+
defaultConfig {
7+
applicationId "ui.android.dialogalchemy.example"
8+
minSdkVersion 16
9+
targetSdkVersion 23
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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 project(path: ':library')
24+
compile fileTree(dir: 'libs', include: ['*.jar'])
25+
compile 'com.android.support:appcompat-v7:23.4.0'
26+
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3'
27+
testCompile 'junit:junit:4.12'
28+
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
29+
androidTestCompile 'com.android.support.test:runner:0.5'
30+
androidTestCompile 'com.android.support:support-annotations:23.4.0'
31+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
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 /Users/JasonYang/Library/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+
#}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ui.android.dialogalchemy;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.filters.MediumTest;
6+
import android.support.test.runner.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
/**
14+
* Instrumentation test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@MediumTest
19+
@RunWith(AndroidJUnit4.class)
20+
public class ExampleInstrumentationTest {
21+
@Test
22+
public void useAppContext() throws Exception {
23+
// Context of the app under test.
24+
Context appContext = InstrumentationRegistry.getTargetContext();
25+
26+
assertEquals("ui.android.dialogalchemy", appContext.getPackageName());
27+
}
28+
}

app/src/main/AndroidManifest.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="ui.android.dialogalchemy.example">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN"/>
14+
15+
<category android:name="android.intent.category.LAUNCHER"/>
16+
</intent-filter>
17+
</activity>
18+
</application>
19+
20+
</manifest>

0 commit comments

Comments
 (0)