Skip to content

Commit

Permalink
Support Appcompat and alert dialogs in the support library
Browse files Browse the repository at this point in the history
- resolves #42
  • Loading branch information
hameno committed Jun 8, 2015
1 parent 8a9fe35 commit 93333b8
Show file tree
Hide file tree
Showing 14 changed files with 525 additions and 257 deletions.
6 changes: 3 additions & 3 deletions library/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1007000"
android:versionName="1.7.0-SNAPSHOT"
android:versionCode="1008000"
android:versionName="1.8.0-SNAPSHOT"
package="de.psdev.licensesdialog">

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
android:targetSdkVersion="22" />
<application />
</manifest>
8 changes: 7 additions & 1 deletion library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.psdev.licensesdialog</groupId>
<artifactId>parent</artifactId>
<version>1.7.1-SNAPSHOT</version>
<version>1.8.0-SNAPSHOT</version>
</parent>

<artifactId>licensesdialog</artifactId>
Expand Down Expand Up @@ -36,6 +36,12 @@
<artifactId>support-v4</artifactId>
<type>aar</type>
</dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<type>aar</type>
<optional>true</optional>
</dependency>

<!-- Nullable support -->
<dependency>
Expand Down
12 changes: 0 additions & 12 deletions library/project.properties

This file was deleted.

63 changes: 61 additions & 2 deletions library/src/main/java/de/psdev/licensesdialog/LicensesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ public class LicensesDialog {
private final int mThemeResourceId;
private final int mDividerColor;

//
private DialogInterface.OnDismissListener mOnDismissListener;

// ==========================================================================================================================
// Constructor
// ==========================================================================================================================

private LicensesDialog(final Context context, final String licensesText, final String titleText, final String closeText, final int themeResourceId,
final int dividerColor) {
mContext = context;
Expand All @@ -56,6 +59,10 @@ private LicensesDialog(final Context context, final String licensesText, final S
mDividerColor = dividerColor;
}

// ==========================================================================================================================
// Public API
// ==========================================================================================================================

public LicensesDialog setOnDismissListener(final DialogInterface.OnDismissListener onDismissListener) {
mOnDismissListener = onDismissListener;
return this;
Expand Down Expand Up @@ -103,13 +110,63 @@ public void onShow(final DialogInterface dialogInterface) {
return dialog;
}

public Dialog createAppCompat() {
//Get resources
final WebView webView = new WebView(mContext);
webView.loadDataWithBaseURL(null, mLicensesText, "text/html", "utf-8", null);
final android.support.v7.app.AlertDialog.Builder builder;
if (mThemeResourceId != 0) {
builder = new android.support.v7.app.AlertDialog.Builder(new ContextThemeWrapper(mContext, mThemeResourceId));
} else {
builder = new android.support.v7.app.AlertDialog.Builder(mContext);
}
builder.setTitle(mTitleText)
.setView(webView)
.setPositiveButton(mCloseText, new Dialog.OnClickListener() {
public void onClick(final DialogInterface dialogInterface, final int i) {
dialogInterface.dismiss();
}
});
final android.support.v7.app.AlertDialog dialog = builder.create();
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(final DialogInterface dialog) {
if (mOnDismissListener != null) {
mOnDismissListener.onDismiss(dialog);
}
}
});
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialogInterface) {
if (mDividerColor != 0) {
// Set title divider color
final int titleDividerId = mContext.getResources().getIdentifier("titleDivider", "id", "android");
final View titleDivider = dialog.findViewById(titleDividerId);
if (titleDivider != null) {
titleDivider.setBackgroundColor(mDividerColor);
}
}
}
});
return dialog;
}

public Dialog show() {
final Dialog dialog = create();
dialog.show();
return dialog;
}

//
public Dialog showAppCompat() {
final Dialog dialog = createAppCompat();
dialog.show();
return dialog;
}

// ==========================================================================================================================
// Private API
// ==========================================================================================================================

private static Notices getNotices(final Context context, final int rawNoticesResourceId) {
try {
Expand Down Expand Up @@ -144,7 +201,9 @@ private static Notices getSingleNoticeNotices(final Notice notice) {
return notices;
}

// ==========================================================================================================================
// Inner classes
// ==========================================================================================================================

public static final class Builder {

Expand Down
Loading

0 comments on commit 93333b8

Please sign in to comment.