|
@@ -9,9 +9,9 @@ import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.ArrayAdapter;
|
|
|
import android.widget.CheckBox;
|
|
|
+import android.widget.CompoundButton;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.RadioButton;
|
|
|
-import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.afollestad.materialdialogs.util.DialogUtils;
|
|
@@ -62,76 +62,51 @@ class MaterialDialogAdapter extends ArrayAdapter<CharSequence> {
|
|
|
tv.setTextColor(itemColor);
|
|
|
dialog.setTypeface(tv, dialog.mBuilder.regularFont);
|
|
|
view.setTag(index + ":" + dialog.mBuilder.items[index]);
|
|
|
- setupGravity(view);
|
|
|
- return view;
|
|
|
- }
|
|
|
+ setupGravity((ViewGroup) view);
|
|
|
|
|
|
- private void setupGravity(View view) {
|
|
|
- if (view instanceof LinearLayout) {
|
|
|
- // Basic list item
|
|
|
- final LinearLayout itemRoot = (LinearLayout) view;
|
|
|
- final int gravityInt = MaterialDialog.gravityEnumToGravity(itemGravity);
|
|
|
- itemRoot.setGravity(gravityInt | Gravity.CENTER_VERTICAL);
|
|
|
- for (int i = 0; i < itemRoot.getChildCount(); i++)
|
|
|
- ((LinearLayout.LayoutParams) itemRoot.getChildAt(i).getLayoutParams()).gravity = gravityInt;
|
|
|
- } else {
|
|
|
- // Choice list item
|
|
|
- final RelativeLayout itemRoot = (RelativeLayout) view;
|
|
|
- for (int i = 0; i < itemRoot.getChildCount(); i++)
|
|
|
- setupGravityRelative(itemRoot.getChildAt(i), i);
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ ViewGroup group = (ViewGroup) view;
|
|
|
+ if (group.getChildCount() == 2) {
|
|
|
+ // Remove circular selector from check boxes and radio buttons on Lollipop
|
|
|
+ if (group.getChildAt(0) instanceof CompoundButton)
|
|
|
+ group.getChildAt(0).setBackground(null);
|
|
|
+ else if (group.getChildAt(1) instanceof CompoundButton)
|
|
|
+ group.getChildAt(1).setBackground(null);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return view;
|
|
|
}
|
|
|
|
|
|
- private void setupGravityRelative(View child, int index) {
|
|
|
- RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) child.getLayoutParams();
|
|
|
-
|
|
|
- // Layout alignment
|
|
|
- if (itemGravity == GravityEnum.CENTER) {
|
|
|
- params.addRule(RelativeLayout.CENTER_HORIZONTAL);
|
|
|
- } else if (index == 0) {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
|
- params.addRule(itemGravity == GravityEnum.START ?
|
|
|
- RelativeLayout.ALIGN_PARENT_START : RelativeLayout.ALIGN_PARENT_END);
|
|
|
- } else {
|
|
|
- params.addRule(itemGravity == GravityEnum.START ?
|
|
|
- RelativeLayout.ALIGN_PARENT_LEFT : RelativeLayout.ALIGN_PARENT_RIGHT);
|
|
|
- }
|
|
|
- }
|
|
|
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
|
|
+ private void setupGravity(ViewGroup view) {
|
|
|
+ final LinearLayout itemRoot = (LinearLayout) view;
|
|
|
+ final int gravityInt = MaterialDialog.gravityEnumToGravity(itemGravity);
|
|
|
+ itemRoot.setGravity(gravityInt | Gravity.CENTER_VERTICAL);
|
|
|
|
|
|
- if (index == 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
- // Removes the circular background selector from checkboxes or radio buttons on Lollipop
|
|
|
- child.setBackground(null);
|
|
|
- }
|
|
|
+ if (view.getChildCount() == 2) {
|
|
|
+ if (itemGravity == GravityEnum.END && !isRTL() && view.getChildAt(0) instanceof CompoundButton) {
|
|
|
+ CompoundButton first = (CompoundButton) view.getChildAt(0);
|
|
|
+ view.removeView(first);
|
|
|
|
|
|
- // Relative positioning
|
|
|
- if (index == 1) {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
|
- params.addRule(itemGravity == GravityEnum.START || itemGravity == GravityEnum.CENTER ?
|
|
|
- RelativeLayout.END_OF : RelativeLayout.START_OF, R.id.control);
|
|
|
- } else {
|
|
|
- params.addRule(itemGravity == GravityEnum.START || itemGravity == GravityEnum.CENTER ?
|
|
|
- RelativeLayout.RIGHT_OF : RelativeLayout.LEFT_OF, R.id.control);
|
|
|
- }
|
|
|
- }
|
|
|
+ TextView second = (TextView) view.getChildAt(0);
|
|
|
+ view.removeView(second);
|
|
|
+ second.setPadding(second.getPaddingRight(), second.getPaddingTop(),
|
|
|
+ second.getPaddingLeft(), second.getPaddingBottom());
|
|
|
|
|
|
- // Margin
|
|
|
- final int frameMargin = (int) getContext().getResources().getDimension(R.dimen.md_dialog_frame_margin);
|
|
|
- final int controlMargin = (int) getContext().getResources().getDimension(R.dimen.md_listitem_control_margin);
|
|
|
- if (index == 0) {
|
|
|
- if (itemGravity == GravityEnum.START || itemGravity == GravityEnum.CENTER) {
|
|
|
- params.leftMargin = !isRTL() ? frameMargin : controlMargin;
|
|
|
- params.rightMargin = isRTL() ? frameMargin : controlMargin;
|
|
|
- } else {
|
|
|
- params.leftMargin = !isRTL() ? controlMargin : frameMargin;
|
|
|
- params.rightMargin = isRTL() ? controlMargin : frameMargin;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (itemGravity == GravityEnum.START || itemGravity == GravityEnum.CENTER) {
|
|
|
- params.leftMargin = !isRTL() ? 0 : frameMargin;
|
|
|
- params.rightMargin = isRTL() ? frameMargin : 0;
|
|
|
- } else {
|
|
|
- params.leftMargin = !isRTL() ? frameMargin : 0;
|
|
|
- params.rightMargin = isRTL() ? 0 : frameMargin;
|
|
|
+ view.addView(second);
|
|
|
+ view.addView(first);
|
|
|
+ } else if (itemGravity == GravityEnum.START && isRTL() && view.getChildAt(1) instanceof CompoundButton) {
|
|
|
+ CompoundButton first = (CompoundButton) view.getChildAt(1);
|
|
|
+ view.removeView(first);
|
|
|
+
|
|
|
+ TextView second = (TextView) view.getChildAt(0);
|
|
|
+ view.removeView(second);
|
|
|
+ second.setPadding(second.getPaddingRight(), second.getPaddingTop(),
|
|
|
+ second.getPaddingRight(), second.getPaddingBottom());
|
|
|
+
|
|
|
+ view.addView(first);
|
|
|
+ view.addView(second);
|
|
|
}
|
|
|
}
|
|
|
}
|