-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
3,078 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 *; | ||
#} |
28 changes: 28 additions & 0 deletions
28
app/src/androidTest/java/ui/android/dialogalchemy/ExampleInstrumentationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.