Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Commit

Permalink
0.8.6.2, resolved #1116, resolved #1119, resolved #1112
Browse files Browse the repository at this point in the history
  • Loading branch information
afollestad committed Jul 18, 2016
1 parent 5d6179b commit 769e613
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 50 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
5. [Dismissing Dialogs](https://github.com/afollestad/material-dialogs#dismissing-dialogs)
5. [Migration from AlertDialogs](https://github.com/afollestad/material-dialogs#migration-from-alertdialogs)
6. [Displaying an Icon](https://github.com/afollestad/material-dialogs#displaying-an-icon)
7. [Stacked Action Buttons](https://github.com/afollestad/material-dialogs#stacked-action-buttons)
7. [Stacked Action Buttons](https://github.com/afollestad/material-dialogs#s1tacked-action-buttons)
1. [Stacking Behavior](https://github.com/afollestad/material-dialogs#stacking-behavior)
8. [Neutral Action Button](https://github.com/afollestad/material-dialogs#neutral-action-button)
9. [Callbacks](https://github.com/afollestad/material-dialogs#callbacks)
10. [List Dialogs](https://github.com/afollestad/material-dialogs#list-dialogs)
Expand Down Expand Up @@ -98,7 +99,7 @@ You can create basic, list, single/multi choice, progress, input, etc. dialogs w
```gradle
dependencies {
// ... other dependencies here
compile 'com.afollestad.material-dialogs:core:0.8.6.1'
compile 'com.afollestad.material-dialogs:core:0.8.6.2'
}
```

Expand All @@ -110,7 +111,7 @@ The *commons* module contains extensions to the library that not everyone may ne
```gradle
dependencies {
// ... other dependencies here
compile 'com.afollestad.material-dialogs:commons:0.8.6.1'
compile 'com.afollestad.material-dialogs:commons:0.8.6.2'
}
```

Expand Down Expand Up @@ -250,7 +251,16 @@ new MaterialDialog.Builder(this)
.show();
```

You can also force the dialog to stack its buttons with the `forceStacking()` method of the `Builder`.
### Stacking Behavior

You can set stacking behavior from the `Builder`:

```java
new MaterialDialog.Builder(this)
...
.stackingBehavior(StackingBehavior.ADAPTIVE) // the default value
.show();
```

---

Expand Down
6 changes: 3 additions & 3 deletions commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'com.afollestad.material-dialogs'
PUBLISH_ARTIFACT_ID = 'commons'
PUBLISH_VERSION = '0.8.6.1'
SUPPORT_LIBRARY_VERSION = '24.0.0'
PUBLISH_VERSION = '0.8.6.2'
SUPPORT_LIBRARY_VERSION = '24.1.0'
BUILD_TOOLS = "24.0.0"
TARGET_SDK = 24
}
Expand All @@ -26,7 +26,7 @@ android {
}

dependencies {
compile "com.android.support:appcompat-v7:${SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
// compile "com.afollestad.material-dialogs:core:${PUBLISH_VERSION}"
compile project(':core')
}
Expand Down
14 changes: 7 additions & 7 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'com.afollestad.material-dialogs'
PUBLISH_ARTIFACT_ID = 'core'
PUBLISH_VERSION = '0.8.6.1'
SUPPORT_LIBRARY_VERSION = '24.0.0'
PUBLISH_VERSION = '0.8.6.2'
SUPPORT_LIBRARY_VERSION = '24.1.0'
BUILD_TOOLS = "24.0.0"
TARGET_SDK = 24
}
Expand All @@ -27,11 +27,11 @@ android {
}

dependencies {
compile "com.android.support:support-v4:${SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:appcompat-v7:${SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:recyclerview-v7:${SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:support-annotations:${SUPPORT_LIBRARY_VERSION}"
compile "me.zhanghai.android.materialprogressbar:library:1.1.6"
compile "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
compile "me.zhanghai.android.materialprogressbar:library:1.1.7"
}

apply from: 'https://raw.githubusercontent.com/afollestad/aidanfollestad.com/master/android-lib-release.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.widget.TextView;

import com.afollestad.materialdialogs.internal.MDTintHelper;
import com.afollestad.materialdialogs.util.DialogUtils;

class DefaultAdapter extends BaseAdapter {

Expand Down Expand Up @@ -57,6 +58,7 @@ public long getItemId(int position) {
public View getView(final int index, View view, ViewGroup parent) {
if (view == null)
view = LayoutInflater.from(dialog.getContext()).inflate(layout, parent, false);
boolean disabled = DialogUtils.isIn(index, dialog.mBuilder.disabledIndices);

TextView tv = (TextView) view.findViewById(R.id.title);
switch (dialog.listType) {
Expand All @@ -66,6 +68,7 @@ public View getView(final int index, View view, ViewGroup parent) {
boolean selected = dialog.mBuilder.selectedIndex == index;
MDTintHelper.setTint(radio, dialog.mBuilder.widgetColor);
radio.setChecked(selected);
radio.setEnabled(!disabled);
break;
}
case MULTI: {
Expand All @@ -74,9 +77,11 @@ public View getView(final int index, View view, ViewGroup parent) {
boolean selected = dialog.selectedIndicesList.contains(index);
MDTintHelper.setTint(checkbox, dialog.mBuilder.widgetColor);
checkbox.setChecked(selected);
checkbox.setEnabled(!disabled);
break;
}
}

tv.setText(dialog.mBuilder.items[index]);
tv.setTextColor(dialog.mBuilder.itemColor);
dialog.setTypeface(tv, dialog.mBuilder.regularFont);
Expand Down
19 changes: 17 additions & 2 deletions core/src/main/java/com/afollestad/materialdialogs/DialogInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public static void init(final MaterialDialog dialog) {
// Setup action buttons
dialog.view.setButtonGravity(builder.buttonsGravity);
dialog.view.setButtonStackedGravity(builder.btnStackedGravity);
dialog.view.setForceStack(builder.forceStacking);
dialog.view.setStackingBehavior(builder.stackingBehavior);
boolean textAllCaps;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
textAllCaps = DialogUtils.resolveBoolean(builder.context, android.R.attr.textAllCaps, true);
Expand Down Expand Up @@ -353,6 +353,17 @@ public static void init(final MaterialDialog dialog) {
dialog.checkIfListInitScroll();
}

private static void fixCanvasScalingWhenHardwareAccelerated(ProgressBar pb) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB &&
Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
// Canvas scaling when hardware accelerated results in artifacts on older API levels, so
// we need to use software rendering
if (pb.isHardwareAccelerated() && pb.getLayerType() != View.LAYER_TYPE_SOFTWARE) {
pb.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
}

private static void setupProgressDialog(final MaterialDialog dialog) {
final MaterialDialog.Builder builder = dialog.mBuilder;
if (builder.indeterminateProgress || builder.progress > -2) {
Expand Down Expand Up @@ -412,6 +423,10 @@ private static void setupProgressDialog(final MaterialDialog dialog) {
}
}
}

if (dialog.mProgress != null) {
fixCanvasScalingWhenHardwareAccelerated(dialog.mProgress);
}
}

private static void setupInputDialog(final MaterialDialog dialog) {
Expand All @@ -430,7 +445,7 @@ private static void setupInputDialog(final MaterialDialog dialog) {

if (builder.inputType != -1) {
dialog.input.setInputType(builder.inputType);
if (builder.inputType != InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &&
if (builder.inputType != InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &&
(builder.inputType & InputType.TYPE_TEXT_VARIATION_PASSWORD) == InputType.TYPE_TEXT_VARIATION_PASSWORD) {
// If the flags contain TYPE_TEXT_VARIATION_PASSWORD, apply the password transformation method automatically
dialog.input.setTransformationMethod(PasswordTransformationMethod.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ else if ((mBuilder.items == null || mBuilder.items.length == 0) && mBuilder.adap

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (!view.isEnabled()) return;
if (mBuilder.listCallbackCustom != null) {
// Custom adapter
CharSequence text = null;
if (view instanceof TextView)
if (view instanceof TextView) {
text = ((TextView) view).getText();
} else {
final TextView tv = (TextView) view.findViewById(android.R.id.title);
if (tv != null) text = tv.getText();
}
mBuilder.listCallbackCustom.onSelection(this, view, position, text);
} else if (listType == null || listType == ListType.REGULAR) {
// Default adapter, non choice mode
Expand All @@ -181,8 +186,9 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
} else {
// Default adapter, choice mode
if (listType == ListType.MULTI) {
final boolean shouldBeChecked = !selectedIndicesList.contains(position);
final CheckBox cb = (CheckBox) view.findViewById(R.id.control);
if (!cb.isEnabled()) return;
final boolean shouldBeChecked = !selectedIndicesList.contains(position);
if (shouldBeChecked) {
// Add the selection to the states first so the callback includes it (when alwaysCallMultiChoiceCallback)
selectedIndicesList.add(position);
Expand All @@ -206,9 +212,10 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
sendMultichoiceCallback();
}
} else if (listType == ListType.SINGLE) {
final RadioButton radio = (RadioButton) view.findViewById(R.id.control);
if (!radio.isEnabled()) return;
boolean allowSelection = true;
final DefaultAdapter adapter = (DefaultAdapter) mBuilder.adapter;
final RadioButton radio = (RadioButton) view.findViewById(R.id.control);

if (mBuilder.autoDismiss && mBuilder.positiveText == null) {
// If auto dismiss is enabled, and no action button is visible to approve the selection, dismiss the dialog
Expand Down Expand Up @@ -350,7 +357,7 @@ public final void onClick(View v) {
}
if (mBuilder.onNegativeCallback != null)
mBuilder.onNegativeCallback.onClick(this, tag);
if (mBuilder.autoDismiss) dismiss();
if (mBuilder.autoDismiss) cancel();
break;
}
case NEUTRAL: {
Expand Down Expand Up @@ -411,6 +418,7 @@ public static class Builder {
protected float contentLineSpacingMultiplier = 1.2f;
protected int selectedIndex = -1;
protected Integer[] selectedIndices = null;
protected Integer[] disabledIndices = null;
protected boolean autoDismiss = true;
protected Typeface regularFont;
protected Typeface mediumFont;
Expand All @@ -422,7 +430,7 @@ public static class Builder {
protected OnCancelListener cancelListener;
protected OnKeyListener keyListener;
protected OnShowListener showListener;
protected boolean forceStacking;
protected StackingBehavior stackingBehavior;
protected boolean wrapCustomViewInScroll;
protected int dividerColor;
protected int backgroundColor;
Expand Down Expand Up @@ -851,6 +859,18 @@ public Builder itemsCallbackMultiChoice(@Nullable Integer[] selectedIndices, @No
return this;
}

/**
* Sets indices of items that are not clickable. If they are checkboxes or radio buttons,
* they will not be toggleable.
*
* @param disabledIndices The item indices that will be disabled from selection.
* @return The Builder instance so you can chain calls to it.
*/
public Builder itemsDisabledIndices(@Nullable Integer... disabledIndices) {
this.disabledIndices = disabledIndices;
return this;
}

/**
* By default, the multi choice callback is only called when the user clicks the positive button
* or if there are no buttons. Call this to force it to always call on item clicks even if the
Expand Down Expand Up @@ -1101,7 +1121,7 @@ public Builder widgetColorRes(@ColorRes int colorRes) {
}

public Builder widgetColorAttr(@AttrRes int colorAttr) {
return widgetColorRes(DialogUtils.resolveColor(this.context, colorAttr));
return widgetColor(DialogUtils.resolveColor(this.context, colorAttr));
}

public Builder dividerColor(@ColorInt int color) {
Expand Down Expand Up @@ -1237,11 +1257,27 @@ public Builder keyListener(@NonNull OnKeyListener listener) {
return this;
}

public Builder forceStacking(boolean stacked) {
this.forceStacking = stacked;
/**
* Sets action button stacking behavior.
*
* @param behavior The behavior of the action button stacking logic.
* @return The Builder instance so you can chain calls to it.
*/
public Builder stackingBehavior(@NonNull StackingBehavior behavior) {
this.stackingBehavior = behavior;
return this;
}

/**
* @param stacked When true, action button stacking is forced.
* @return The Builder instance so you can chain calls to it.
* @deprecated Use {@link #stackingBehavior(StackingBehavior)} instead.
*/
@Deprecated
public Builder forceStacking(boolean stacked) {
return stackingBehavior(stacked ? StackingBehavior.ALWAYS : StackingBehavior.ADAPTIVE);
}

public Builder input(@Nullable CharSequence hint, @Nullable CharSequence prefill, boolean allowEmptyInput, @NonNull InputCallback callback) {
if (this.customView != null)
throw new IllegalStateException("You cannot set content() when you're using a custom view.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.afollestad.materialdialogs;

/**
* @author Aidan Follestad (afollestad)
*/
public enum StackingBehavior {
/**
* The action buttons are always stacked vertically.
*/
ALWAYS,
/**
* The action buttons are stacked vertically IF it is necessary for them to fit in the dialog.
*/
ADAPTIVE,
/**
* The action buttons are never stacked, even if they should be.
*/
NEVER
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.afollestad.materialdialogs.GravityEnum;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.R;
import com.afollestad.materialdialogs.StackingBehavior;
import com.afollestad.materialdialogs.util.DialogUtils;

/**
Expand All @@ -43,7 +44,7 @@ public class MDRootLayout extends ViewGroup {
private boolean mDrawTopDivider = false;
private boolean mDrawBottomDivider = false;
private final MDButton[] mButtons = new MDButton[3];
private boolean mForceStack = false;
private StackingBehavior mStackBehavior = StackingBehavior.ADAPTIVE;
private boolean mIsStacked = false;
private boolean mUseFullPadding = true;
private boolean mReducePaddingNoTitleNoButtons;
Expand Down Expand Up @@ -137,7 +138,11 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
boolean hasButtons = false;

final boolean stacked;
if (!mForceStack) {
if (mStackBehavior == StackingBehavior.ALWAYS) {
stacked = true;
} else if (mStackBehavior == StackingBehavior.NEVER) {
stacked = false;
} else {
int buttonsWidth = 0;
for (MDButton button : mButtons) {
if (button != null && isVisible(button)) {
Expand All @@ -152,8 +157,6 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
.getDimensionPixelSize(R.dimen.md_neutral_button_margin);
final int buttonFrameWidth = width - 2 * buttonBarPadding;
stacked = buttonsWidth > buttonFrameWidth;
} else {
stacked = true;
}

int stackedHeight = 0;
Expand Down Expand Up @@ -343,8 +346,8 @@ protected void onLayout(boolean changed, final int l, int t, final int r, int b)
setUpDividersVisibility(mContent, true, true);
}

public void setForceStack(boolean forceStack) {
mForceStack = forceStack;
public void setStackingBehavior(StackingBehavior behavior) {
mStackBehavior = behavior;
invalidate();
}

Expand Down
Loading

0 comments on commit 769e613

Please sign in to comment.