Skip to content

Commit

Permalink
Add helper method to dismiss popup window
Browse files Browse the repository at this point in the history
Update other popups accordingly.
  • Loading branch information
pranavpandey committed Jul 23, 2022
1 parent 1056fe1 commit ad78819
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ public DynamicColorPopup(@NonNull View anchor, @NonNull Integer[] entries,
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getPopupWindow().dismiss();

if (mOnMoreColorsListener == null) {
DynamicColorDialog.newInstance().setColors(
DynamicPalette.MATERIAL_COLORS,
Expand Down Expand Up @@ -222,6 +220,8 @@ public void onColorSelected(
} else {
mOnMoreColorsListener.onClick(view);
}

dismiss();
}
});

Expand All @@ -230,12 +230,13 @@ public void onColorSelected(
new DynamicColorListener() {
@Override
public void onColorSelected(@Nullable String tag, int position, int color) {
getPopupWindow().dismiss();
DynamicPickerUtils.setRecentColor(color);

if (mDynamicColorListener != null) {
mDynamicColorListener.onColorSelected(tag, position, color);
}

dismiss();
}
}));

Expand Down Expand Up @@ -291,12 +292,13 @@ protected void setDynamics(@Nullable GridView gridView, @Nullable View divider)
new DynamicColorListener() {
@Override
public void onColorSelected(@Nullable String tag, int position, int color) {
getPopupWindow().dismiss();
DynamicPickerUtils.setRecentColor(color);

if (mDynamicColorListener != null) {
mDynamicColorListener.onColorSelected(tag, position, color);
}

dismiss();
}
}));
} else {
Expand Down Expand Up @@ -357,13 +359,14 @@ private void setColorView(final @NonNull DynamicColorView colorView,
@Override
public void onClick(View view) {
colorView.setSelected(true);
getPopupWindow().dismiss();
DynamicPickerUtils.setRecentColor(colorView.getColor());

if (mDynamicColorListener != null) {
mDynamicColorListener.onColorSelected(
null, 0, colorView.getColor());
}

dismiss();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public void onItemClick(AdapterView<?> adapterView,
View view, int position, long id) {
mOnItemClickListener.onItemClick(adapterView, view, position, id);

getPopupWindow().dismiss();
dismiss();
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,16 @@ public void run() {
viewCenterX + OFFSET_X, screenPos[1] - OFFSET_Y);
}
}

/**
* Try to dismiss the popup window.
*
* @see #getPopupWindow()
* @see PopupWindow#dismiss()
*/
public void dismiss() {
if (getPopupWindow() != null) {
getPopupWindow().dismiss();
}
}
}

0 comments on commit ad78819

Please sign in to comment.