Skip to content

Commit

Permalink
Rename and do refactor, also update README file.
Browse files Browse the repository at this point in the history
  • Loading branch information
fengdai committed Nov 21, 2014
1 parent 2a31d39 commit 4c8a1be
Show file tree
Hide file tree
Showing 24 changed files with 347 additions and 210 deletions.
84 changes: 52 additions & 32 deletions README.md
Expand Up @@ -55,50 +55,70 @@ Usage

With AlertDialogPro, you can theme your dialog easily.

1. If one of the built-in themes can meet almost your requirements, but you want some slight changes. You can use following attributes:
1. If one of the built-in themes can meet almost your requirements, but you want to do some slight changes. You can use following attributes:

```xml
<!-- Specify the dialog's background -->
<item name="android:windowBackground">@drawable/dialog_background_material_dark</item>
<!-- Style the dialog's title -->
<item name="android:windowTitleStyle">@style/DialogWindowTitle.Material</item>
<!-- Style the dialog's message text -->
<item name="adpMessageTextAppearance">@style/TextAppearance.Material.Subhead</item>
<!-- Specify the item's height -->
<item name="adpListItemHeight">48dip</item>
<!-- Specify the item's text color -->
<item name="adpListItemTextColor">@color/primary_text_material_dark</item>
<!-- Specify the item's text appearance -->
<item name="adpListItemTextAppearance">@style/TextAppearance.Material.Subhead</item>
<!-- Specify the list selector -->
<item name="adpListItemBackground">@drawable/item_background_material_dark</item>
<!-- Specify the list divider -->
<item name="adpListDivider">@null</item>
<!-- Style the dialog's listView -->
<item name="android:listViewStyle">@style/Widget.Material.ListView</item>
<!-- Style the ButtonBar -->
<item name="adpButtonBarStyle">@style/Widget.Material.ButtonBar</item>
<!-- Style the Buttons -->
<item name="adpButtonBarButtonStyle">@style/Widget.Material.Button</item>
<!-- Style the Buttons respectively -->
<item name="adpButtonBarPositiveButtonStyle">?attr/adpButtonBarButtonStyle</item>
<item name="adpButtonBarNegativeButtonStyle">?attr/adpButtonBarButtonStyle</item>
<item name="adpButtonBarNeutralButtonStyle">?attr/adpButtonBarButtonStyle</item>
<!-- Minimum height of title panel-->
<attr name="adpTitleMinHeight" format="dimension" />

<!-- The text appearance for the dialog's message text -->
<attr name="adpMessageTextAppearance" format="reference" />

<!-- Minimum height of ListView's items -->
<attr name="adpListItemMinHeight" format="dimension" />

<!-- The text color for ListView's items -->
<attr name="adpListItemTextColor" format="reference|color" />

<!-- The text appearance for normal ListView's items -->
<attr name="adpListItemTextAppearance" format="reference" />

<!-- The text appearance for "multi-choice" ListView's items -->
<attr name="adpListMultiChoiceTextAppearance" format="reference" />

<!-- The text appearance for "single-choice" ListView's items -->
<attr name="adpListSingleChoiceTextAppearance" format="reference" />

<!-- Divider for the ListView -->
<attr name="adpListDivider" format="reference" />

<!-- Selector in a ListView -->
<attr name="adpListItemBackground" format="reference" />

<!-- Style for button bars -->
<attr name="adpButtonBarStyle" format="reference" />

<!-- Style for buttons within button bars -->
<attr name="adpButtonBarButtonStyle" format="reference" />

<!-- Style for the "positive" buttons within button bars -->
<attr name="adpButtonBarPositiveButtonStyle" format="reference" />

<!-- Style for the "negative" buttons within button bars -->
<attr name="adpButtonBarNegativeButtonStyle" format="reference" />

<!-- Style for the "neutral" buttons within button bars -->
<attr name="adpButtonBarNeutralButtonStyle" format="reference" />
```

2. You can also specify your own layout to the AlertDialogPro. This can be very useful when you want to use custom view or you want a very special dialog style.

```xml
<style name="AlertDialogPro.Material">
<!-- As HoneyComb's android:layout. Specify your AlertDialogPro's layout -->
<!-- As HoneyComb's android:layout.
Specify your AlertDialogPro's layout -->
<item name="adpLayout">@layout/alert_dialog_material</item>
<!-- As HoneyComb's android:listLayout. Specify your AlertDialogPro's ListView layout. -->
<!-- As HoneyComb's android:listLayout.
Specify your AlertDialogPro's ListView layout. -->
<item name="adpListLayout">@layout/select_dialog_material</item>
<!-- As HoneyComb's android:listItemLayout. Specify your AlertDialogPro's list item layout. -->
<!-- As HoneyComb's android:listItemLayout.
Specify your AlertDialogPro's list item layout. -->
<item name="adpListItemLayout">@layout/select_dialog_item_material</item>
<!-- As HoneyComb's android:multiChoiceItemLayout. Specify your AlertDialogPro's multi choice list item layout. -->
<!-- As HoneyComb's android:multiChoiceItemLayout.
Specify your AlertDialogPro's multi choice list item layout. -->
<item name="adpMultiChoiceItemLayout">@layout/select_dialog_multichoice_material</item>
<!-- As HoneyComb's android:singleChoiceItemLayout. Specify your AlertDialogPro's single choice list item layout. -->
<!-- As HoneyComb's android:singleChoiceItemLayout.
Specify your AlertDialogPro's single choice list item layout. -->
<item name="adpSingleChoiceItemLayout">@layout/select_dialog_singlechoice_material</item>
</style>
```
Expand Down
6 changes: 2 additions & 4 deletions alertdialogpro-core/res/values-v11/adp_core_themes.xml
@@ -1,13 +1,11 @@
<resources>

<style name="AlertDialogProTheme" parent="android:Theme.Holo.Dialog">
<item name="android:windowContentOverlay">@null</item>
<style name="BaseAdp" parent="Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>

<style name="AlertDialogProTheme.Light" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowContentOverlay">@null</item>
<style name="BaseAdp.Light" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>
Expand Down
75 changes: 56 additions & 19 deletions alertdialogpro-core/res/values/adp_core_attrs.xml
@@ -1,32 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Specify AlertDialogPro's theme -->
<attr name="alertDialogProTheme" format="reference" />

<!-- Specify AlertDialogPro's style -->
<attr name="alertDialogProStyle" format="reference" />

<declare-styleable name="AlertDialogPro">
<attr name="adpTitleDividerBackground" format="reference|color" />
<attr name="adpTitleDividerHeight" format="dimension" />
<attr name="adpTitleHeight" format="dimension" />
<attr name="adpMessageTextAppearance" format="reference" />
<attr name="adpListItemHeight" format="dimension" />
<attr name="adpListItemTextColor" format="reference|color" />
<attr name="adpListItemTextAppearance" format="reference" />
<attr name="adpListSingleChoiceTextAppearance" format="reference" />
<attr name="adpListMultiChoiceTextAppearance" format="reference" />
<attr name="adpListDivider" format="reference" />
<attr name="adpListItemBackground" format="reference" />
<attr name="adpButtonBarDividerHorizontal" format="reference" />
<attr name="adpButtonBarDividerVertical" format="reference" />
<attr name="adpButtonBarStyle" format="reference" />
<attr name="adpButtonBarPositiveButtonStyle" format="reference" />
<attr name="adpButtonBarNegativeButtonStyle" format="reference" />
<attr name="adpButtonBarNeutralButtonStyle" format="reference" />
<attr name="adpButtonBarButtonStyle" format="reference" />
<!-- Minimum height of title panel-->
<attr name="adpTitleMinHeight" format="dimension" />

<!-- The text appearance for the dialog's message text -->
<attr name="adpMessageTextAppearance" format="reference" />

<!-- Minimum height of ListView's items -->
<attr name="adpListItemMinHeight" format="dimension" />

<!-- The text color for ListView's items -->
<attr name="adpListItemTextColor" format="reference|color" />

<!-- The text appearance for normal ListView's items -->
<attr name="adpListItemTextAppearance" format="reference" />

<!-- The text appearance for "multi-choice" ListView's items -->
<attr name="adpListMultiChoiceTextAppearance" format="reference" />

<!-- The text appearance for "single-choice" ListView's items -->
<attr name="adpListSingleChoiceTextAppearance" format="reference" />

<!-- Divider for the ListView -->
<attr name="adpListDivider" format="reference" />

<!-- Selector in a ListView -->
<attr name="adpListItemBackground" format="reference" />

<!-- Style for button bars -->
<attr name="adpButtonBarStyle" format="reference" />

<!-- Style for buttons within button bars -->
<attr name="adpButtonBarButtonStyle" format="reference" />

<!-- Style for the "positive" buttons within button bars -->
<attr name="adpButtonBarPositiveButtonStyle" format="reference" />

<!-- Style for the "negative" buttons within button bars -->
<attr name="adpButtonBarNegativeButtonStyle" format="reference" />

<!-- Style for the "neutral" buttons within button bars -->
<attr name="adpButtonBarNeutralButtonStyle" format="reference" />

<!-- AlertDialogPro Styles -->
<declare-styleable name="AlertDialogPro">
<!-- As HoneyComb's android:layout.
Specify your AlertDialogPro's layout -->
<attr name="adpLayout" format="reference" />
<!-- As HoneyComb's android:listLayout.
Specify your AlertDialogPro's ListView layout. -->
<attr name="adpListLayout" format="reference" />
<!-- As HoneyComb's android:listItemLayout.
Specify your AlertDialogPro's list item layout. -->
<attr name="adpListItemLayout" format="reference" />
<!-- As HoneyComb's android:multiChoiceItemLayout.
Specify your AlertDialogPro's multi choice list item layout. -->
<attr name="adpMultiChoiceItemLayout" format="reference" />
<!-- As HoneyComb's android:singleChoiceItemLayout.
Specify your AlertDialogPro's single choice list item layout. -->
<attr name="adpSingleChoiceItemLayout" format="reference" />
</declare-styleable>

Expand Down
33 changes: 33 additions & 0 deletions alertdialogpro-core/res/values/adp_core_styles.xml
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Base text appearance for AlertDialogPro -->
<style name="TextAppearance.AlertDialogPro" parent="android:TextAppearance" />

<!-- Base text appearance for title of AlertDialogPro -->
<style name="TextAppearance.AlertDialogPro.DialogWindowTitle">
<item name="android:textSize">18sp</item>
</style>

<!-- Base style for widget of AlertDialogPro -->
<style name="Widget.AlertDialogPro" parent="android:Widget" />

<!-- Base style for AlertDialogPro -->
<style name="AlertDialogPro">
<!-- The core library has no default style -->
<item name="adpLayout">@null</item>
<item name="adpListLayout">@null</item>
<item name="adpListItemLayout">@null</item>
<item name="adpMultiChoiceItemLayout">@null</item>
<item name="adpSingleChoiceItemLayout">@null</item>
</style>

<!-- Base style for title of AlertDialogPro -->
<style name="DialogWindowTitle.AlertDialogPro" parent="">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">@style/TextAppearance.AlertDialogPro.DialogWindowTitle
</item>
</style>

</resources>
10 changes: 4 additions & 6 deletions alertdialogpro-core/res/values/adp_core_themes.xml
@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AlertDialogProTheme" parent="android:Theme.Dialog"></style>
<style name="BaseAdp" parent="Theme.AppCompat.Dialog"></style>

<style name="AlertDialogProTheme.Light" parent="android:Theme.Dialog"></style>
<style name="BaseAdp.Light" parent="Theme.AppCompat.Light.Dialog"></style>

<style name="AlertDialogProTheme.Base" parent="AlertDialogProTheme">
<item name="android:windowContentOverlay">@null</item>
<style name="Theme.AlertDialogPro" parent="BaseAdp">
<item name="adpButtonBarPositiveButtonStyle">?attr/adpButtonBarButtonStyle</item>
<item name="adpButtonBarNegativeButtonStyle">?attr/adpButtonBarButtonStyle</item>
<item name="adpButtonBarNeutralButtonStyle">?attr/adpButtonBarButtonStyle</item>
</style>

<style name="AlertDialogProTheme.Base.Light" parent="AlertDialogProTheme.Light">
<item name="android:windowContentOverlay">@null</item>
<style name="Theme.AlertDialogPro.Light" parent="BaseAdp.Light">
<item name="adpButtonBarPositiveButtonStyle">?attr/adpButtonBarButtonStyle</item>
<item name="adpButtonBarNegativeButtonStyle">?attr/adpButtonBarButtonStyle</item>
<item name="adpButtonBarNeutralButtonStyle">?attr/adpButtonBarButtonStyle</item>
Expand Down
6 changes: 6 additions & 0 deletions alertdialogpro-demo/res/layout/activity_my.xml
Expand Up @@ -90,5 +90,11 @@
android:layout_below="@id/showSingleChoiceList"
android:text="Show Custom View" />

<Button
android:id="@+id/showNativeAlert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/showCustomView"
android:text="Show Native Alert" />
</RelativeLayout>
</ScrollView>
6 changes: 3 additions & 3 deletions alertdialogpro-demo/res/values/styles.xml
Expand Up @@ -10,7 +10,7 @@
<item name="alertDialogProTheme">@style/AppTheme.FlavoredMaterialLight</item>
</style>

<style name="AppTheme.FlavoredMaterialLight" parent="AlertDialogProTheme.Material.Light">
<style name="AppTheme.FlavoredMaterialLight" parent="Theme.AlertDialogPro.Material.Light">
<item name="colorPrimary">#3F51B5</item>
<item name="colorPrimaryDark">#303F9F</item>
<item name="colorAccent">#FF4081</item>
Expand All @@ -19,11 +19,11 @@
<item name="adpButtonBarNeutralButtonStyle">@style/AdpNormalButtonStyle</item>
</style>

<style name="AdpTitleStyle" parent="DialogWindowTitle.Material.Light">
<style name="AdpTitleStyle" parent="DialogWindowTitle.AlertDialogPro.Material.Light">
<item name="android:textColor">?attr/colorPrimary</item>
</style>

<style name="AdpNormalButtonStyle" parent="Widget.Material.Button.Light">
<style name="AdpNormalButtonStyle" parent="Widget.AlertDialogPro.Material.Light.Button">
<item name="android:textColor">?android:attr/textColorPrimary</item>
</style>

Expand Down
35 changes: 31 additions & 4 deletions alertdialogpro-demo/src/com/alertdialogpro/demo/MainActivity.java
@@ -1,5 +1,6 @@
package com.alertdialogpro.demo;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
Expand Down Expand Up @@ -32,16 +33,16 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
mTheme = -1;
break;
case R.id.theme_material:
mTheme = R.style.AlertDialogProTheme_Material;
mTheme = R.style.Theme_AlertDialogPro_Material;
break;
case R.id.theme_material_light:
mTheme = R.style.AlertDialogProTheme_Material_Light;
mTheme = R.style.Theme_AlertDialogPro_Material_Light;
break;
case R.id.theme_holo:
mTheme = R.style.AlertDialogProTheme_Holo;
mTheme = R.style.Theme_AlertDialogPro_Holo;
break;
case R.id.theme_holo_light:
mTheme = R.style.AlertDialogProTheme_Holo_Light;
mTheme = R.style.Theme_AlertDialogPro_Holo_Light;
break;
default:
break;
Expand All @@ -54,6 +55,7 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
findViewById(R.id.showMultiChoiceList).setOnClickListener(this);
findViewById(R.id.showSingleChoiceList).setOnClickListener(this);
findViewById(R.id.showCustomView).setOnClickListener(this);
findViewById(R.id.showNativeAlert).setOnClickListener(this);
}

@Override
Expand All @@ -74,9 +76,34 @@ public void onClick(View v) {
case R.id.showCustomView:
showCustomViewDialog();
break;
case R.id.showNativeAlert:
showNativeAlert();
break;
}
}

private void showNativeAlert() {
final String[] list = new String[]{"Holo theme", "Material theme", "Custom theme"};
new AlertDialog.Builder(this).setTitle(R.string.app_name).
setMultiChoiceItems(list,
new boolean[]{false, false, false},
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked) {
mCheckedItems.add(list[which]);
} else {
mCheckedItems.remove(list[which]);
}
showToast(list[which] + " is " + (isChecked ? "checked" : "unchecked" + "."));
}
}).
setNeutralButton("More info", new ButtonClickedListener("More info")).
setNegativeButton("Cancel", new ButtonClickedListener("Cancel")).
setPositiveButton("Choose", new ButtonClickedListener("Chose " + mCheckedItems.toString())).show();

}

// Show a message dialog
private void showMessageAlertDialog() {
new AlertDialogPro.Builder(this, mTheme).setTitle(R.string.app_name).
Expand Down
Expand Up @@ -26,7 +26,7 @@
android:layout_marginLeft="16dip"
android:layout_marginRight="16dip"
android:gravity="center_vertical|start"
android:minHeight="?attr/adpTitleHeight"
android:minHeight="?attr/adpTitleMinHeight"
android:orientation="horizontal">

<ImageView
Expand Down
Expand Up @@ -5,7 +5,7 @@
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:minHeight="?attr/adpListItemHeight"
android:minHeight="?attr/adpListItemMinHeight"
android:paddingLeft="16dip"
android:paddingRight="16dip"
android:textAppearance="?attr/adpListItemTextAppearance"
Expand Down

0 comments on commit 4c8a1be

Please sign in to comment.