diff --git a/README.md b/README.md index e6641b5..936fea1 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ List options = Arrays.asList(getResources().getStringArray(R.array.month PickerUISettings pickerUISettings = new PickerUISettings.Builder() .withItems(options) + .withPopupLocation(PickerUISettings.POPUP_AT_BOTTOM) .withBackgroundColor(getRandomColor()) .withAutoDismiss(true) .withItemsClickables(false) diff --git a/app/src/main/java/com/dpizarro/libraries/uipickerlibrary/MainActivity.java b/app/src/main/java/com/dpizarro/libraries/uipickerlibrary/MainActivity.java index 49f63af..4a62bdd 100644 --- a/app/src/main/java/com/dpizarro/libraries/uipickerlibrary/MainActivity.java +++ b/app/src/main/java/com/dpizarro/libraries/uipickerlibrary/MainActivity.java @@ -77,25 +77,25 @@ public void onClick(View v) { int randomColor = -1; - if(mRandomColor.isChecked()){ + if (mRandomColor.isChecked()) { randomColor = getRandomColor(); } PickerUISettings pickerUISettings = new PickerUISettings.Builder().withItems(options) - .withBackgroundColor(randomColor) - .withAutoDismiss(mAutoDismiss.isChecked()) - .withItemsClickables( - mItemsClickables.isChecked()) - .withUseBlur(mUseBlur.isChecked()) - .build(); + .withPopupLocation(PickerUISettings.POPUP_AT_BOTTOM) + .withBackgroundColor(randomColor) + .withAutoDismiss(mAutoDismiss.isChecked()) + .withItemsClickables( + mItemsClickables.isChecked()) + .withUseBlur(mUseBlur.isChecked()) + .build(); mPickerUI.setSettings(pickerUISettings); - if(currentPosition==-1) { + if (currentPosition == -1) { mPickerUI.slide(); - } - else{ + } else { mPickerUI.slide(currentPosition); } } diff --git a/library/src/main/java/com/dpizarro/uipicker/library/picker/PickerUI.java b/library/src/main/java/com/dpizarro/uipicker/library/picker/PickerUI.java index 91c7950..9bfcbf2 100644 --- a/library/src/main/java/com/dpizarro/uipicker/library/picker/PickerUI.java +++ b/library/src/main/java/com/dpizarro/uipicker/library/picker/PickerUI.java @@ -41,7 +41,7 @@ public class PickerUI extends RelativeLayout implements PickerUIBlurHelper.BlurF private static final String LOG_TAG = PickerUI.class.getSimpleName(); - private boolean autoDismiss = PickerUISettings.DEFAULT_AUTO_DISMISS; + private boolean autoDismiss = PickerUISettings.DEFAULT_AUTO_DISMISS; private boolean itemsClickables = PickerUISettings.DEFAULT_ITEMS_CLICKABLES; private PickerUIItemClickListener mPickerUIListener; @@ -55,6 +55,7 @@ public class PickerUI extends RelativeLayout implements PickerUIBlurHelper.BlurF private int colorLines; private int mColorTextCenterListView; private int mColorTextNoCenterListView; + private int mPopupLocation; private PickerUISettings mPickerUISettings; /** @@ -120,6 +121,21 @@ private void createView(AttributeSet attrs) { mPickerUIBlurHelper.setBlurFinishedListener(this); } + /** + * Set view popupLocation + */ + private void setViewPopupLocation(int popupLocation) { + RelativeLayout hidePanel = (RelativeLayout) findViewById(R.id.hidden_panel); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) hidePanel.getLayoutParams(); + if (popupLocation == PickerUISettings.POPUP_AT_BOTTOM) { + params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + hidePanel.setLayoutParams(params); + } else if (popupLocation == PickerUISettings.POPUP_AT_TOP) { + params.addRule(RelativeLayout.ALIGN_PARENT_TOP); + hidePanel.setLayoutParams(params); + } + } + /** * Retrieve styles attributes */ @@ -144,7 +160,8 @@ private void getAttributes(AttributeSet attrs) { mColorTextNoCenterListView = typedArray .getColor(R.styleable.PickerUI_textNoCenterColor, getResources().getColor(R.color.text_no_center_pickerui)); - + mPopupLocation = typedArray.getInteger(R.styleable.PickerUI_popupLocation, PickerUISettings.POPUP_AT_UNSPECIFIED); + setViewPopupLocation(mPopupLocation); int idItems; idItems = typedArray.getResourceId(R.styleable.PickerUI_entries, -1); if (idItems != -1) { @@ -361,7 +378,7 @@ public void setUseRenderScript(boolean useRenderScript) { /** * Apply custom down scale factor - * + *

* By default down scale factor is set to {@link PickerUIBlur#MIN_DOWNSCALE} * * @param downScaleFactor Factor customized down scale factor, must be at least 1.0 @@ -374,7 +391,7 @@ public void setDownScaleFactor(float downScaleFactor) { /** * Select your preferred blur radius to apply - * + *

* By default blur radius is set to {@link PickerUIBlur#MIN_BLUR_RADIUS} * * @param radius The radius to blur the image, radius must be at least 1 @@ -501,7 +518,7 @@ public void setOnClickItemPickerUIListener(final PickerUIItemClickListener liste new PickerUIListView.PickerUIItemClickListener() { @Override public void onItemClickItemPickerUI(int which, int position, - String valueResult) { + String valueResult) { if (autoDismiss) { slide(position); } @@ -534,6 +551,7 @@ public void setSettings(PickerUISettings pickerUISettings) { setBlurRadius(pickerUISettings.getBlurRadius()); setDownScaleFactor(pickerUISettings.getBlurDownScaleFactor()); setFilterColor(pickerUISettings.getBlurFilterColor()); + setViewPopupLocation(pickerUISettings.getPopupLocation()); } /** @@ -561,7 +579,7 @@ public void onRestoreInstanceState(Parcelable state) { Bundle bundle = (Bundle) state; //load everything PickerUISettings pickerUISettings = bundle.getParcelable("stateSettings"); - if(pickerUISettings!=null){ + if (pickerUISettings != null) { setSettings(pickerUISettings); } diff --git a/library/src/main/java/com/dpizarro/uipicker/library/picker/PickerUISettings.java b/library/src/main/java/com/dpizarro/uipicker/library/picker/PickerUISettings.java index 7871a22..d580147 100644 --- a/library/src/main/java/com/dpizarro/uipicker/library/picker/PickerUISettings.java +++ b/library/src/main/java/com/dpizarro/uipicker/library/picker/PickerUISettings.java @@ -55,9 +55,14 @@ public PickerUISettings[] newArray(int size) { private int mBlurFilterColor; private boolean mUseBlur; private boolean mUseBlurRenderscript; + private int mPopupLocation; + public static int POPUP_AT_BOTTOM = 1; + public static int POPUP_AT_TOP = 2; + public static int POPUP_AT_UNSPECIFIED = 0; private PickerUISettings(Builder builder) { setItems(builder.mItems); + setPopupLocation(builder.mPopupLocation); setColorTextCenter(builder.mColorTextCenter); setColorTextNoCenter(builder.mColorTextNoCenter); setBackgroundColor(builder.mBackgroundColor); @@ -94,6 +99,14 @@ void setItems(List items) { mItems = items; } + public int getPopupLocation() { + return mPopupLocation; + } + + public void setPopupLocation(int mPopupLocation) { + this.mPopupLocation = mPopupLocation; + } + public int getColorTextCenter() { return mColorTextCenter; } @@ -182,6 +195,7 @@ void setBlurFilterColor(int blurFilterColor) { mBlurFilterColor = blurFilterColor; } + @Override public int describeContents() { return 0; @@ -206,17 +220,18 @@ public void writeToParcel(Parcel dest, int flags) { public static final class Builder { private List mItems; - private int mColorTextCenter = R.color.text_center_pickerui; - private int mColorTextNoCenter = R.color.text_no_center_pickerui; - private int mBackgroundColor = R.color.background_panel_pickerui; - private int mLinesColor = R.color.lines_panel_pickerui; - private boolean mUseBlur = PickerUIBlur.DEFAULT_USE_BLUR; - private boolean mUseBlurRenderscript = PickerUIBlur.DEFAULT_USE_BLUR_RENDERSCRIPT; - private boolean mItemsClickables = DEFAULT_ITEMS_CLICKABLES; - private float mDownScaleFactor = PickerUIBlur.DEFAULT_DOWNSCALE_FACTOR; - private int mRadius = PickerUIBlur.DEFAULT_BLUR_RADIUS; - private boolean mAutoDismiss = DEFAULT_AUTO_DISMISS; - private int mFilterColor = -1; + private int mColorTextCenter = R.color.text_center_pickerui; + private int mColorTextNoCenter = R.color.text_no_center_pickerui; + private int mBackgroundColor = R.color.background_panel_pickerui; + private int mLinesColor = R.color.lines_panel_pickerui; + private boolean mUseBlur = PickerUIBlur.DEFAULT_USE_BLUR; + private boolean mUseBlurRenderscript = PickerUIBlur.DEFAULT_USE_BLUR_RENDERSCRIPT; + private boolean mItemsClickables = DEFAULT_ITEMS_CLICKABLES; + private float mDownScaleFactor = PickerUIBlur.DEFAULT_DOWNSCALE_FACTOR; + private int mRadius = PickerUIBlur.DEFAULT_BLUR_RADIUS; + private boolean mAutoDismiss = DEFAULT_AUTO_DISMISS; + private int mFilterColor = -1; + private int mPopupLocation = 0; public Builder() { } @@ -231,6 +246,11 @@ public Builder withItems(List mItems) { return this; } + public Builder withPopupLocation(int mPopupLocation){ + this.mPopupLocation = mPopupLocation; + return this; + } + public Builder withColorTextCenter(int mColorTextCenter) { this.mColorTextCenter = mColorTextCenter; return this; diff --git a/library/src/main/res/layout/pickerui.xml b/library/src/main/res/layout/pickerui.xml index 219f246..bb923c2 100644 --- a/library/src/main/res/layout/pickerui.xml +++ b/library/src/main/res/layout/pickerui.xml @@ -6,7 +6,6 @@ android:layout_width="match_parent" android:layout_height="@dimen/height_hidden_panel_pickerui" android:visibility="gone" - android:layout_alignParentBottom="true" android:background="@drawable/container_dropshadow" android:animateLayoutChanges="true" tools:visibility="visible" diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 0660bc8..49a66a0 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -2,24 +2,29 @@ - - + + + + + + + - - - + + + - - + + - - - - - + + + + + \ No newline at end of file