Skip to content

Commit

Permalink
Add simple popup to provide basic functionality
Browse files Browse the repository at this point in the history
Refactor other popups accordingly.
  • Loading branch information
pranavpandey committed Jul 15, 2022
1 parent 3c28179 commit 50f3626
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@
import com.pranavpandey.android.dynamic.support.dialog.DynamicDialog;
import com.pranavpandey.android.dynamic.support.listener.DynamicColorListener;
import com.pranavpandey.android.dynamic.support.picker.color.DynamicColorShape;
import com.pranavpandey.android.dynamic.support.picker.color.view.DynamicColorView;
import com.pranavpandey.android.dynamic.support.picker.color.dialog.DynamicColorDialog;
import com.pranavpandey.android.dynamic.support.popup.DynamicPopup;
import com.pranavpandey.android.dynamic.support.picker.color.view.DynamicColorView;
import com.pranavpandey.android.dynamic.support.popup.DynamicSimplePopup;
import com.pranavpandey.android.dynamic.support.setting.base.DynamicColorPreference;
import com.pranavpandey.android.dynamic.support.theme.DynamicTheme;
import com.pranavpandey.android.dynamic.support.theme.task.WallpaperColorsTask;
import com.pranavpandey.android.dynamic.support.util.DynamicPickerUtils;
import com.pranavpandey.android.dynamic.support.view.DynamicHeader;
import com.pranavpandey.android.dynamic.theme.DynamicPalette;
import com.pranavpandey.android.dynamic.theme.Theme;
import com.pranavpandey.android.dynamic.util.DynamicColorUtils;
Expand All @@ -52,17 +51,11 @@
import java.util.Map;

/**
* A {@link PopupWindow} to display a grid of colors.
* <p>It will be used internally by the
* {@link DynamicColorPreference}
* but can be used by the other views also.
* A {@link DynamicSimplePopup} to display a grid of colors.
* <p>It will be used internally by the {@link DynamicColorPreference} but can be used by
* the other views also.
*/
public class DynamicColorPopup extends DynamicPopup {

/**
* Title used by this popup.
*/
private CharSequence mTitle;
public class DynamicColorPopup extends DynamicSimplePopup {

/**
* Color entries used by this popup.
Expand Down Expand Up @@ -121,11 +114,6 @@ public class DynamicColorPopup extends DynamicPopup {
*/
private WallpaperColorsTask mWallpaperColorsTask;

/**
* Header view for this popup.
*/
private View mHeaderView;

/**
* Content view for this popup.
*/
Expand All @@ -145,7 +133,8 @@ public class DynamicColorPopup extends DynamicPopup {
*/
public DynamicColorPopup(@NonNull View anchor, @NonNull Integer[] entries,
@NonNull DynamicColorListener dynamicColorListener) {
this.mAnchor = anchor;
super(anchor);

this.mEntries = entries;
this.mDynamicColorListener = dynamicColorListener;
this.mDefaultColor = Theme.Color.UNKNOWN;
Expand All @@ -164,14 +153,6 @@ public DynamicColorPopup(@NonNull View anchor, @NonNull Integer[] entries,

this.mRecentColor = DynamicPickerUtils.getRecentColor();

if (getTitle() != null) {
mHeaderView = new DynamicHeader(getAnchor().getContext());
((DynamicHeader) mHeaderView).setColorType(Theme.ColorType.PRIMARY);
((DynamicHeader) mHeaderView).setContrastWithColorType(Theme.ColorType.SURFACE);
((DynamicHeader) mHeaderView).setTitle(mTitle);
((DynamicHeader) mHeaderView).setFillSpace(true);
}

final GridView gridView = mView.findViewById(R.id.ads_color_picker_presets);
final ProgressBar progressBar = mView.findViewById(R.id.ads_color_picker_progress_bar);
final View divider = mView.findViewById(R.id.ads_color_picker_divider);
Expand Down Expand Up @@ -387,11 +368,6 @@ public void onClick(View view) {
});
}

@Override
protected @Nullable View getHeaderView() {
return mHeaderView;
}

@Override
protected @Nullable View getView() {
return mView;
Expand All @@ -402,24 +378,6 @@ public void onClick(View view) {
return mFooterView;
}

/**
* Get the title used by this popup.
*
* @return The title used by this popup.
*/
public @Nullable CharSequence getTitle() {
return mTitle;
}

/**
* Set the title used by this popup.
*
* @param title The title to be set.
*/
public void setTitle(@Nullable CharSequence title) {
this.mTitle = title;
}

/**
* Get the color entries used by this popup.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,22 @@
import com.pranavpandey.android.dynamic.support.model.DynamicMenu;
import com.pranavpandey.android.dynamic.support.setting.base.DynamicSpinnerPreference;
import com.pranavpandey.android.dynamic.support.util.DynamicLayoutUtils;
import com.pranavpandey.android.dynamic.support.view.DynamicHeader;
import com.pranavpandey.android.dynamic.theme.Theme;

import java.util.ArrayList;
import java.util.List;

/**
* A {@link DynamicPopup} to display a list of items.
* A {@link DynamicSimplePopup} to display a list of items.
* <p>It will be used internally by the {@link DynamicSpinnerPreference} but can be used by
* the other views also.
*/
public class DynamicMenuPopup extends DynamicPopup {

/**
* Header view for this popup.
*/
private View mHeaderView;
public class DynamicMenuPopup extends DynamicSimplePopup {

/**
* Content view for this popup.
*/
private View mView;

/**
* Title used by this popup.
*/
private CharSequence mTitle;

/**
* Menu icons used by this popup.
*/
Expand Down Expand Up @@ -105,6 +93,8 @@ public class DynamicMenuPopup extends DynamicPopup {
*/
public DynamicMenuPopup(@NonNull View anchor, @NonNull List<DynamicMenu> menus,
int selectedPosition, @NonNull AdapterView.OnItemClickListener onItemClickListener) {
super(anchor);

List<Drawable> drawables = new ArrayList<>();
List<CharSequence> titles = new ArrayList<>();
List<CharSequence> subtitles = new ArrayList<>();
Expand Down Expand Up @@ -437,7 +427,8 @@ public DynamicMenuPopup(@NonNull View anchor, @Nullable int[] iconsRes,
@Nullable CharSequence[] subtitles, @Nullable boolean[] hasSubmenus,
int selectedPosition, @Nullable AdapterView.OnItemClickListener onItemClickListener,
@Type int viewType) {
this.mAnchor = anchor;
super(anchor);

this.mIconsRes = iconsRes;
this.mIcons = icons;
this.mTitles = titles;
Expand All @@ -462,14 +453,6 @@ public DynamicMenuPopup(@NonNull View anchor, @Nullable int[] iconsRes,
DynamicLayoutUtils.getGridCount(mView.getContext()));
}

if (mTitle != null) {
mHeaderView = new DynamicHeader(getAnchor().getContext());
((DynamicHeader) mHeaderView).setColorType(Theme.ColorType.PRIMARY);
((DynamicHeader) mHeaderView).setContrastWithColorType(Theme.ColorType.SURFACE);
((DynamicHeader) mHeaderView).setTitle(mTitle);
((DynamicHeader) mHeaderView).setFillSpace(true);
}

if (mOnItemClickListener != null) {
listView.setAdapter(new DynamicSpinnerChoiceAdapter(mIconsRes, mIcons,
mTitles, mSubtitles, mHasSubmenus, mSelectedPosition,
Expand All @@ -488,34 +471,11 @@ public void onItemClick(AdapterView<?> adapterView,
return this;
}

@Override
protected @Nullable View getHeaderView() {
return mHeaderView;
}

@Override
protected @Nullable View getView() {
return mView;
}

/**
* Get the title used by this popup.
*
* @return The title used by this popup.
*/
public @Nullable CharSequence getTitle() {
return mTitle;
}

/**
* Set the title used by this popup.
*
* @param title The title to be set.
*/
public void setTitle(@Nullable CharSequence title) {
this.mTitle = title;
}

/**
* Get the menu icons used by this popup.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ public void setPopupWindowColor(@ColorInt int popupWindowColor) {
}

/**
* Build this popup and make it ready to show. Please call {@link #show()} method
* to show the popup.
* Build this popup and make it ready to show.
* <p>Please call {@link #show()} method to show the popup.
*
* @return The popup after building it according to the supplied parameters.
*/
Expand Down

0 comments on commit 50f3626

Please sign in to comment.