Skip to content

Commit 50f3626

Browse files
committed
Add simple popup to provide basic functionality
Refactor other popups accordingly.
1 parent 3c28179 commit 50f3626

File tree

5 files changed

+282
-98
lines changed

5 files changed

+282
-98
lines changed

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/picker/color/popup/DynamicColorPopup.java

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@
3434
import com.pranavpandey.android.dynamic.support.dialog.DynamicDialog;
3535
import com.pranavpandey.android.dynamic.support.listener.DynamicColorListener;
3636
import com.pranavpandey.android.dynamic.support.picker.color.DynamicColorShape;
37-
import com.pranavpandey.android.dynamic.support.picker.color.view.DynamicColorView;
3837
import com.pranavpandey.android.dynamic.support.picker.color.dialog.DynamicColorDialog;
39-
import com.pranavpandey.android.dynamic.support.popup.DynamicPopup;
38+
import com.pranavpandey.android.dynamic.support.picker.color.view.DynamicColorView;
39+
import com.pranavpandey.android.dynamic.support.popup.DynamicSimplePopup;
4040
import com.pranavpandey.android.dynamic.support.setting.base.DynamicColorPreference;
4141
import com.pranavpandey.android.dynamic.support.theme.DynamicTheme;
4242
import com.pranavpandey.android.dynamic.support.theme.task.WallpaperColorsTask;
4343
import com.pranavpandey.android.dynamic.support.util.DynamicPickerUtils;
44-
import com.pranavpandey.android.dynamic.support.view.DynamicHeader;
4544
import com.pranavpandey.android.dynamic.theme.DynamicPalette;
4645
import com.pranavpandey.android.dynamic.theme.Theme;
4746
import com.pranavpandey.android.dynamic.util.DynamicColorUtils;
@@ -52,17 +51,11 @@
5251
import java.util.Map;
5352

5453
/**
55-
* A {@link PopupWindow} to display a grid of colors.
56-
* <p>It will be used internally by the
57-
* {@link DynamicColorPreference}
58-
* but can be used by the other views also.
54+
* A {@link DynamicSimplePopup} to display a grid of colors.
55+
* <p>It will be used internally by the {@link DynamicColorPreference} but can be used by
56+
* the other views also.
5957
*/
60-
public class DynamicColorPopup extends DynamicPopup {
61-
62-
/**
63-
* Title used by this popup.
64-
*/
65-
private CharSequence mTitle;
58+
public class DynamicColorPopup extends DynamicSimplePopup {
6659

6760
/**
6861
* Color entries used by this popup.
@@ -121,11 +114,6 @@ public class DynamicColorPopup extends DynamicPopup {
121114
*/
122115
private WallpaperColorsTask mWallpaperColorsTask;
123116

124-
/**
125-
* Header view for this popup.
126-
*/
127-
private View mHeaderView;
128-
129117
/**
130118
* Content view for this popup.
131119
*/
@@ -145,7 +133,8 @@ public class DynamicColorPopup extends DynamicPopup {
145133
*/
146134
public DynamicColorPopup(@NonNull View anchor, @NonNull Integer[] entries,
147135
@NonNull DynamicColorListener dynamicColorListener) {
148-
this.mAnchor = anchor;
136+
super(anchor);
137+
149138
this.mEntries = entries;
150139
this.mDynamicColorListener = dynamicColorListener;
151140
this.mDefaultColor = Theme.Color.UNKNOWN;
@@ -164,14 +153,6 @@ public DynamicColorPopup(@NonNull View anchor, @NonNull Integer[] entries,
164153

165154
this.mRecentColor = DynamicPickerUtils.getRecentColor();
166155

167-
if (getTitle() != null) {
168-
mHeaderView = new DynamicHeader(getAnchor().getContext());
169-
((DynamicHeader) mHeaderView).setColorType(Theme.ColorType.PRIMARY);
170-
((DynamicHeader) mHeaderView).setContrastWithColorType(Theme.ColorType.SURFACE);
171-
((DynamicHeader) mHeaderView).setTitle(mTitle);
172-
((DynamicHeader) mHeaderView).setFillSpace(true);
173-
}
174-
175156
final GridView gridView = mView.findViewById(R.id.ads_color_picker_presets);
176157
final ProgressBar progressBar = mView.findViewById(R.id.ads_color_picker_progress_bar);
177158
final View divider = mView.findViewById(R.id.ads_color_picker_divider);
@@ -387,11 +368,6 @@ public void onClick(View view) {
387368
});
388369
}
389370

390-
@Override
391-
protected @Nullable View getHeaderView() {
392-
return mHeaderView;
393-
}
394-
395371
@Override
396372
protected @Nullable View getView() {
397373
return mView;
@@ -402,24 +378,6 @@ public void onClick(View view) {
402378
return mFooterView;
403379
}
404380

405-
/**
406-
* Get the title used by this popup.
407-
*
408-
* @return The title used by this popup.
409-
*/
410-
public @Nullable CharSequence getTitle() {
411-
return mTitle;
412-
}
413-
414-
/**
415-
* Set the title used by this popup.
416-
*
417-
* @param title The title to be set.
418-
*/
419-
public void setTitle(@Nullable CharSequence title) {
420-
this.mTitle = title;
421-
}
422-
423381
/**
424382
* Get the color entries used by this popup.
425383
*

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/popup/DynamicMenuPopup.java

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,22 @@
3232
import com.pranavpandey.android.dynamic.support.model.DynamicMenu;
3333
import com.pranavpandey.android.dynamic.support.setting.base.DynamicSpinnerPreference;
3434
import com.pranavpandey.android.dynamic.support.util.DynamicLayoutUtils;
35-
import com.pranavpandey.android.dynamic.support.view.DynamicHeader;
36-
import com.pranavpandey.android.dynamic.theme.Theme;
3735

3836
import java.util.ArrayList;
3937
import java.util.List;
4038

4139
/**
42-
* A {@link DynamicPopup} to display a list of items.
40+
* A {@link DynamicSimplePopup} to display a list of items.
4341
* <p>It will be used internally by the {@link DynamicSpinnerPreference} but can be used by
4442
* the other views also.
4543
*/
46-
public class DynamicMenuPopup extends DynamicPopup {
47-
48-
/**
49-
* Header view for this popup.
50-
*/
51-
private View mHeaderView;
44+
public class DynamicMenuPopup extends DynamicSimplePopup {
5245

5346
/**
5447
* Content view for this popup.
5548
*/
5649
private View mView;
5750

58-
/**
59-
* Title used by this popup.
60-
*/
61-
private CharSequence mTitle;
62-
6351
/**
6452
* Menu icons used by this popup.
6553
*/
@@ -105,6 +93,8 @@ public class DynamicMenuPopup extends DynamicPopup {
10593
*/
10694
public DynamicMenuPopup(@NonNull View anchor, @NonNull List<DynamicMenu> menus,
10795
int selectedPosition, @NonNull AdapterView.OnItemClickListener onItemClickListener) {
96+
super(anchor);
97+
10898
List<Drawable> drawables = new ArrayList<>();
10999
List<CharSequence> titles = new ArrayList<>();
110100
List<CharSequence> subtitles = new ArrayList<>();
@@ -437,7 +427,8 @@ public DynamicMenuPopup(@NonNull View anchor, @Nullable int[] iconsRes,
437427
@Nullable CharSequence[] subtitles, @Nullable boolean[] hasSubmenus,
438428
int selectedPosition, @Nullable AdapterView.OnItemClickListener onItemClickListener,
439429
@Type int viewType) {
440-
this.mAnchor = anchor;
430+
super(anchor);
431+
441432
this.mIconsRes = iconsRes;
442433
this.mIcons = icons;
443434
this.mTitles = titles;
@@ -462,14 +453,6 @@ public DynamicMenuPopup(@NonNull View anchor, @Nullable int[] iconsRes,
462453
DynamicLayoutUtils.getGridCount(mView.getContext()));
463454
}
464455

465-
if (mTitle != null) {
466-
mHeaderView = new DynamicHeader(getAnchor().getContext());
467-
((DynamicHeader) mHeaderView).setColorType(Theme.ColorType.PRIMARY);
468-
((DynamicHeader) mHeaderView).setContrastWithColorType(Theme.ColorType.SURFACE);
469-
((DynamicHeader) mHeaderView).setTitle(mTitle);
470-
((DynamicHeader) mHeaderView).setFillSpace(true);
471-
}
472-
473456
if (mOnItemClickListener != null) {
474457
listView.setAdapter(new DynamicSpinnerChoiceAdapter(mIconsRes, mIcons,
475458
mTitles, mSubtitles, mHasSubmenus, mSelectedPosition,
@@ -488,34 +471,11 @@ public void onItemClick(AdapterView<?> adapterView,
488471
return this;
489472
}
490473

491-
@Override
492-
protected @Nullable View getHeaderView() {
493-
return mHeaderView;
494-
}
495-
496474
@Override
497475
protected @Nullable View getView() {
498476
return mView;
499477
}
500478

501-
/**
502-
* Get the title used by this popup.
503-
*
504-
* @return The title used by this popup.
505-
*/
506-
public @Nullable CharSequence getTitle() {
507-
return mTitle;
508-
}
509-
510-
/**
511-
* Set the title used by this popup.
512-
*
513-
* @param title The title to be set.
514-
*/
515-
public void setTitle(@Nullable CharSequence title) {
516-
this.mTitle = title;
517-
}
518-
519479
/**
520480
* Get the menu icons used by this popup.
521481
*

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/popup/DynamicPopup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ public void setPopupWindowColor(@ColorInt int popupWindowColor) {
208208
}
209209

210210
/**
211-
* Build this popup and make it ready to show. Please call {@link #show()} method
212-
* to show the popup.
211+
* Build this popup and make it ready to show.
212+
* <p>Please call {@link #show()} method to show the popup.
213213
*
214214
* @return The popup after building it according to the supplied parameters.
215215
*/

0 commit comments

Comments
 (0)