|
@@ -16,14 +16,10 @@ import android.support.annotation.ArrayRes;
|
|
|
import android.support.annotation.AttrRes;
|
|
|
import android.support.annotation.ColorRes;
|
|
|
import android.support.annotation.DrawableRes;
|
|
|
-import android.support.annotation.IntDef;
|
|
|
import android.support.annotation.LayoutRes;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.annotation.StringRes;
|
|
|
-import android.support.v7.widget.GridLayoutManager;
|
|
|
-import android.support.v7.widget.LinearLayoutManager;
|
|
|
-import android.support.v7.widget.RecyclerView;
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
import android.view.ContextThemeWrapper;
|
|
|
import android.view.Gravity;
|
|
@@ -57,17 +53,6 @@ import java.util.List;
|
|
|
*/
|
|
|
public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
|
|
|
- @IntDef({START, CENTER, END})
|
|
|
- public @interface GravityInt {
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressWarnings("WeakerAccess")
|
|
|
- public static final int START = 0;
|
|
|
- @SuppressWarnings("WeakerAccess")
|
|
|
- public static final int CENTER = 1;
|
|
|
- @SuppressWarnings("WeakerAccess")
|
|
|
- public static final int END = 2;
|
|
|
-
|
|
|
protected final View view;
|
|
|
protected final Builder mBuilder;
|
|
|
protected ListView listView;
|
|
@@ -296,7 +281,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static int gravityIntToGravity(@GravityInt int gravity) {
|
|
|
+ private static int gravityIntToGravity(GravityEnum gravity) {
|
|
|
switch (gravity) {
|
|
|
case CENTER:
|
|
|
return Gravity.CENTER_HORIZONTAL;
|
|
@@ -308,7 +293,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
}
|
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
|
|
- private static int gravityToAlignment(@GravityInt int gravity) {
|
|
|
+ private static int gravityToAlignment(GravityEnum gravity) {
|
|
|
switch (gravity) {
|
|
|
case CENTER:
|
|
|
return View.TEXT_ALIGNMENT_CENTER;
|
|
@@ -535,8 +520,8 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
return canAdapterViewScroll((AdapterView) view);
|
|
|
} else if (view instanceof WebView) {
|
|
|
return canWebViewScroll((WebView) view);
|
|
|
- } else if (view instanceof RecyclerView) {
|
|
|
- return canRecyclerViewScroll((RecyclerView) view);
|
|
|
+ } else if (isRecyclerView(view)) {
|
|
|
+ return RecyclerUtil.canRecyclerViewScroll(view);
|
|
|
} else {
|
|
|
if (atBottom) {
|
|
|
return canViewOrChildScroll(getBottomView((ViewGroup) view), true);
|
|
@@ -546,6 +531,17 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static boolean isRecyclerView(View view) {
|
|
|
+ boolean isRecyclerView = false;
|
|
|
+ try {
|
|
|
+ Class.forName("android.support.v7.widget.RecyclerView");
|
|
|
+
|
|
|
+ // We got here, so now we can safely check
|
|
|
+ isRecyclerView = RecyclerUtil.isRecyclerView(view);
|
|
|
+ } catch (ClassNotFoundException ignored) {}
|
|
|
+
|
|
|
+ return isRecyclerView;
|
|
|
+ }
|
|
|
|
|
|
private static boolean canWebViewScroll(WebView view) {
|
|
|
return view.getMeasuredHeight() > view.getContentHeight();
|
|
@@ -571,28 +567,6 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static boolean canRecyclerViewScroll(RecyclerView rv) {
|
|
|
- final RecyclerView.LayoutManager lm = rv.getLayoutManager();
|
|
|
- final int count = rv.getAdapter().getItemCount();
|
|
|
- int lastVisible;
|
|
|
-
|
|
|
- if (lm instanceof LinearLayoutManager) {
|
|
|
- LinearLayoutManager llm = (LinearLayoutManager) lm;
|
|
|
- lastVisible = llm.findLastVisibleItemPosition();
|
|
|
- } else if (lm instanceof GridLayoutManager) {
|
|
|
- GridLayoutManager glm = (GridLayoutManager) lm;
|
|
|
- lastVisible = glm.findLastVisibleItemPosition();
|
|
|
- } else {
|
|
|
- throw new NotImplementedException("Material Dialogs currently only supports LinearLayoutManager and GridLayoutManager. Please report any new layout managers.");
|
|
|
- }
|
|
|
-
|
|
|
- if (lastVisible == -1)
|
|
|
- return false;
|
|
|
- /* We scroll if the last item is not visible */
|
|
|
- final boolean lastItemVisible = lastVisible == count - 1;
|
|
|
- return !lastItemVisible || rv.getChildAt(rv.getChildCount() - 1).getBottom() > rv.getHeight() - rv.getPaddingBottom();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Detects whether or not the content TextView can be scrolled.
|
|
|
*/
|
|
@@ -814,12 +788,8 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
|
|
|
protected final Context context;
|
|
|
protected CharSequence title;
|
|
|
- protected
|
|
|
- @GravityInt
|
|
|
- int titleGravity = Gravity.START;
|
|
|
- protected
|
|
|
- @GravityInt
|
|
|
- int contentGravity = Gravity.START;
|
|
|
+ protected GravityEnum titleGravity = GravityEnum.START;
|
|
|
+ protected GravityEnum contentGravity = GravityEnum.START;
|
|
|
protected int titleColor = -1;
|
|
|
protected int contentColor = -1;
|
|
|
protected CharSequence content;
|
|
@@ -919,7 +889,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Builder titleGravity(@GravityInt int gravity) {
|
|
|
+ public Builder titleGravity(GravityEnum gravity) {
|
|
|
this.titleGravity = gravity;
|
|
|
return this;
|
|
|
}
|
|
@@ -987,7 +957,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Builder contentGravity(@GravityInt int gravity) {
|
|
|
+ public Builder contentGravity(GravityEnum gravity) {
|
|
|
this.contentGravity = gravity;
|
|
|
return this;
|
|
|
}
|
|
@@ -1549,6 +1519,10 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static enum GravityEnum {
|
|
|
+ START, CENTER, END
|
|
|
+ }
|
|
|
+
|
|
|
public static interface ListCallback {
|
|
|
void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text);
|
|
|
}
|