|
@@ -43,6 +43,12 @@ public abstract class AbstractPopup {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public abstract LinearLayout getScrollableItemLayout();
|
|
|
|
+
|
|
|
|
+ public View getRootView(){
|
|
|
|
+ return this.rootView;
|
|
|
|
+ }
|
|
|
|
+
|
|
public void addItem(final AbstractPopupItem item) {
|
|
public void addItem(final AbstractPopupItem item) {
|
|
View view = item.getItemView();
|
|
View view = item.getItemView();
|
|
|
|
|
|
@@ -51,15 +57,17 @@ public abstract class AbstractPopup {
|
|
this.configureView(this.rootView);
|
|
this.configureView(this.rootView);
|
|
}
|
|
}
|
|
if (this.rootView != null){
|
|
if (this.rootView != null){
|
|
- this.rootView.addView(view);
|
|
|
|
|
|
+ this.getScrollableItemLayout().addView(view);
|
|
|
|
+ //this.rootView.addView(view);
|
|
view.setOnTouchListener(new View.OnTouchListener() {
|
|
view.setOnTouchListener(new View.OnTouchListener() {
|
|
@Override
|
|
@Override
|
|
public boolean onTouch(View view, MotionEvent event) {
|
|
public boolean onTouch(View view, MotionEvent event) {
|
|
if(event.getAction() == MotionEvent.ACTION_DOWN){
|
|
if(event.getAction() == MotionEvent.ACTION_DOWN){
|
|
- item.onItemDown(event);
|
|
|
|
- } else if (event.getAction() == MotionEvent.ACTION_UP){
|
|
|
|
- item.onItemUp(event);
|
|
|
|
-
|
|
|
|
|
|
+ item.onItemSelect(event);
|
|
|
|
+ } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_MOVE){
|
|
|
|
+ item.onItemDeselect(event);
|
|
|
|
+ } else if (event.getAction() == MotionEvent.ACTION_UP){
|
|
|
|
+ item.onItemDeselect(event);
|
|
AbstractPopup.this.onPopupItemClickListener.onItemClick(item.onClickedResult(event));
|
|
AbstractPopup.this.onPopupItemClickListener.onItemClick(item.onClickedResult(event));
|
|
AbstractPopup.this.popupWindow.dismiss();
|
|
AbstractPopup.this.popupWindow.dismiss();
|
|
}
|
|
}
|
|
@@ -90,9 +98,9 @@ public abstract class AbstractPopup {
|
|
|
|
|
|
Window window = this.context.getWindow();
|
|
Window window = this.context.getWindow();
|
|
window.getDecorView().getWindowVisibleDisplayFrame(windowFrame);
|
|
window.getDecorView().getWindowVisibleDisplayFrame(windowFrame);
|
|
- int orientation = 1; //this.context.getResources().getConfiguration().orientation;
|
|
|
|
- int windowWidth = orientation == ORIENTATION_LANDSCAPE ? windowFrame.height() : windowFrame.width();
|
|
|
|
- int windowHeight = orientation == ORIENTATION_LANDSCAPE ? windowFrame.width() : windowFrame.height();
|
|
|
|
|
|
+ int orientation = this.context.getResources().getConfiguration().orientation;
|
|
|
|
+ int windowWidth = windowFrame.width();
|
|
|
|
+ int windowHeight = windowFrame.height();
|
|
|
|
|
|
final int[] position = new int[2];
|
|
final int[] position = new int[2];
|
|
anchorView.getLocationOnScreen(position);
|
|
anchorView.getLocationOnScreen(position);
|
|
@@ -104,15 +112,22 @@ public abstract class AbstractPopup {
|
|
|
|
|
|
//int alh = (position[0] + width) - windowFrame.width();
|
|
//int alh = (position[0] + width) - windowFrame.width();
|
|
//if (alh < 0) alh = 0;
|
|
//if (alh < 0) alh = 0;
|
|
|
|
+ int offset = windowFrame.top;
|
|
|
|
|
|
int x = position[0] + (anchorWidth / 2) - (width / 2);
|
|
int x = position[0] + (anchorWidth / 2) - (width / 2);
|
|
- int y = position[1] - height;
|
|
|
|
|
|
+ int y = (position[1] - height) + offset;
|
|
|
|
+
|
|
|
|
+ height+=(offset/2);
|
|
|
|
+
|
|
|
|
+ width = windowWidth < width ? windowWidth : width;
|
|
|
|
|
|
x = Math.max(0, x);
|
|
x = Math.max(0, x);
|
|
x = Math.min(windowWidth - width, x);
|
|
x = Math.min(windowWidth - width, x);
|
|
|
|
|
|
- y = Math.min(0,y);
|
|
|
|
- y = Math.max(windowHeight - height, y);
|
|
|
|
|
|
+ height = windowHeight < height ? windowHeight : height;
|
|
|
|
+
|
|
|
|
+ y = Math.max(0, y);
|
|
|
|
+ y = Math.min(windowHeight - height, y);
|
|
|
|
|
|
AbstractPopup.this.configureView(this.rootView);
|
|
AbstractPopup.this.configureView(this.rootView);
|
|
|
|
|
|
@@ -121,44 +136,6 @@ public abstract class AbstractPopup {
|
|
this.popupWindow.setHeight(height);
|
|
this.popupWindow.setHeight(height);
|
|
this.popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY, x, y-smallBottomOffset);
|
|
this.popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY, x, y-smallBottomOffset);
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
- // TO SET THE REAL SIZE
|
|
|
|
- ViewTreeObserver viewTreeObserver = this.rootView.getViewTreeObserver();
|
|
|
|
- if (viewTreeObserver != null && viewTreeObserver.isAlive()) {
|
|
|
|
- viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onGlobalLayout() {
|
|
|
|
- ViewTreeObserver observer= AbstractPopup.this.rootView.getViewTreeObserver();
|
|
|
|
- if (observer != null)observer.removeOnGlobalLayoutListener(this);
|
|
|
|
-
|
|
|
|
- View rootView = AbstractPopup.this.rootView;
|
|
|
|
-
|
|
|
|
- int width = rootView.getWidth();
|
|
|
|
- int height = rootView.getHeight();
|
|
|
|
-
|
|
|
|
- int x = position[0] + (anchorWidth / 2) - (width / 2);
|
|
|
|
- int y = position[1] - height;
|
|
|
|
-
|
|
|
|
- x = Math.min(0,x);
|
|
|
|
- x = Math.max(windowFrame.width() - width, x);
|
|
|
|
-
|
|
|
|
- y = Math.min(0,y);
|
|
|
|
- y = Math.max(windowFrame.height() - height, y);
|
|
|
|
-
|
|
|
|
- AbstractPopup.this.configureView(rootView);
|
|
|
|
-
|
|
|
|
- int smallBottomOffset = 10;
|
|
|
|
- AbstractPopup.this.popupWindow.dismiss();
|
|
|
|
- AbstractPopup.this.popupWindow.setWidth(width);
|
|
|
|
- AbstractPopup.this.popupWindow.setHeight(height + smallBottomOffset);
|
|
|
|
- AbstractPopup.this.popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY, x, y-smallBottomOffset);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|