Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpandey committed Nov 18, 2022
1 parent febe3ed commit 1892e16
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import androidx.annotation.Nullable;

/**
* An interface to get the various callbacks related to the automatic color generation.
* An interface to get the various callbacks related to the auto color generation.
*/
public interface DynamicColorResolver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,25 @@
public class DynamicColorView extends DynamicFrameLayout {

/**
* Constant for color view icon divisor.
* Constant for the color view icon divisor.
*/
private static final float ICON_DIVISOR = 2.2f;

/**
* Alpha constant for color view state.
* Alpha constant for the color view state.
*/
private static final int ALPHA_STATE = 60;

/**
* Alpha constant for color view selector.
* Alpha constant for the color view selector.
*/
private static final int ALPHA_SELECTOR = 100;

/**
* Size constant for the alpha pattern paint in DP.
*/
private static final int ALPHA_PATTERN_SIZE = 4;

/**
* RectF to draw the color view.
*/
Expand Down Expand Up @@ -175,7 +180,7 @@ public void loadFromAttributes(@Nullable AttributeSet attrs) {
}

mAlphaPaint = DynamicPickerUtils.getAlphaPatternPaint(
DynamicUnitUtils.convertDpToPixels(4));
DynamicUnitUtils.convertDpToPixels(ALPHA_PATTERN_SIZE));
mColorPaint = new DynamicPaint();
mColorStrokePaint = new DynamicPaint();
mSelectorPaint = new DynamicPaint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.pranavpandey.android.dynamic.support.R;
import com.pranavpandey.android.dynamic.support.theme.DynamicTheme;
import com.pranavpandey.android.dynamic.util.DynamicSdkUtils;
import com.pranavpandey.android.dynamic.util.DynamicUnitUtils;
import com.pranavpandey.android.dynamic.util.DynamicViewUtils;
import com.pranavpandey.android.dynamic.util.DynamicWindowUtils;

Expand Down Expand Up @@ -236,6 +235,26 @@ protected int getSizeOffset() {
.getDimension(R.dimen.ads_popup_offset);
}

/**
* The offset to adjust the location of the window on the x-axis.
*
* @return The offset to adjust the location of the window on the x-axis.
*/
protected int getLocationOffsetX() {
return (int) getAnchor().getContext().getResources()
.getDimension(R.dimen.ads_popup_offset_x);
}

/**
* The offset to adjust the location of the window on the y-axis.
*
* @return The offset to adjust the location of the window on the y-axis.
*/
protected int getLocationOffsetY() {
return (int) getAnchor().getContext().getResources()
.getDimension(R.dimen.ads_popup_offset_y);
}

/**
* This method will be called just before showing this popup.
*
Expand Down Expand Up @@ -354,8 +373,8 @@ public void run() {
getAnchor().getLocationInWindow(screenPos);

int viewCenterX = screenPos[0];
int OFFSET_X = DynamicUnitUtils.convertDpToPixels(36);
final int OFFSET_Y = DynamicUnitUtils.convertDpToPixels(20);
int OFFSET_X = getLocationOffsetX();
final int OFFSET_Y = getLocationOffsetY();

// Check for RTL language.
if (DynamicViewUtils.isLayoutRtl(getAnchor())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ protected void setTutorials(int page, boolean smoothScroll, boolean reload) {
mViewPager.setOffscreenPageLimit(getTutorialsCount());
mViewPager.setAdapter(mAdapter);
mPageIndicator.setViewPager(mViewPager);
mViewPager.setCurrentItem(page < getTutorialsCount() ? page : 0, smoothScroll);
mViewPager.setCurrentItem(page >= 0 && page < getTutorialsCount()
? page : 0, smoothScroll);

// A hack to update the tutorials properly on lower API levels.
mViewPager.post(mAdapterRunnable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void setEnabled(boolean enabled) {
setAlpha(enabled ? Defaults.ADS_ALPHA_ENABLED : Defaults.ADS_ALPHA_DISABLED);
}

@SuppressLint({"RestrictedApi"})
@SuppressLint("RestrictedApi")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void setColor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,17 @@ public void setContrast(int contrast) {
}

@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);

setAlpha(enabled ? Defaults.ADS_ALPHA_ENABLED : Defaults.ADS_ALPHA_DISABLED);
setBackgroundColor(getBackgroundColor());
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);

setBackgroundColor(getBackgroundColor());
setAlpha(enabled ? Defaults.ADS_ALPHA_ENABLED : Defaults.ADS_ALPHA_DISABLED);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions dynamic-support/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
<dimen name="ads_popup_max_width">300dp</dimen>
<dimen name="ads_popup_max_width_large">340dp</dimen>
<dimen name="ads_popup_offset">@dimen/ads_margin_large</dimen>
<dimen name="ads_popup_offset_x">@dimen/ads_margin_large_big</dimen>
<dimen name="ads_popup_offset_y">@dimen/ads_card_view_margin_floating</dimen>
<dimen name="ads_popup_selector_icon_size">24dp</dimen>

<!-- Bottom Sheet -->
Expand Down

0 comments on commit 1892e16

Please sign in to comment.