Skip to content

Commit 61b3aa0

Browse files
authored
Merge pull request hbb20#508 from aminrz3/master
ripple enable/disable feature added
2 parents 3d0a327 + e03f0d4 commit 61b3aa0

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
lines changed

ccp/src/main/java/com/hbb20/CountryCodeAdapter.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import androidx.recyclerview.widget.RecyclerView;
66
import android.text.Editable;
77
import android.text.TextWatcher;
8+
import android.util.TypedValue;
89
import android.view.KeyEvent;
910
import android.view.LayoutInflater;
1011
import android.view.View;
@@ -210,7 +211,7 @@ public String getSectionTitle(int position) {
210211
}
211212

212213
class CountryCodeViewHolder extends RecyclerView.ViewHolder {
213-
RelativeLayout relativeLayout_main;
214+
RelativeLayout relativeLayout_main,rootRowCountryTile;
214215
TextView textView_name, textView_code;
215216
ImageView imageViewFlag;
216217
LinearLayout linearFlagHolder;
@@ -219,6 +220,7 @@ class CountryCodeViewHolder extends RecyclerView.ViewHolder {
219220
public CountryCodeViewHolder(View itemView) {
220221
super(itemView);
221222
relativeLayout_main = (RelativeLayout) itemView;
223+
222224
textView_name = (TextView) relativeLayout_main.findViewById(R.id.textView_countryName);
223225
textView_code = (TextView) relativeLayout_main.findViewById(R.id.textView_code);
224226
imageViewFlag = (ImageView) relativeLayout_main.findViewById(R.id.image_flag);
@@ -231,6 +233,15 @@ public CountryCodeViewHolder(View itemView) {
231233
divider.setBackgroundColor(codePicker.getDialogTextColor());
232234
}
233235

236+
if(codePicker.getCcpDialogRippleEnable()){
237+
TypedValue outValue = new TypedValue();
238+
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
239+
if(outValue.resourceId!=0)
240+
relativeLayout_main.setBackgroundResource(outValue.resourceId);
241+
else
242+
relativeLayout_main.setBackgroundResource(outValue.data);
243+
}
244+
234245
try {
235246
if (codePicker.getDialogTypeFace() != null) {
236247
if (codePicker.getDialogTypeFaceStyle() != CountryCodePicker.DEFAULT_UNSET) {

ccp/src/main/java/com/hbb20/CountryCodePicker.java

+37
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.content.res.TypedArray;
88
import android.graphics.PorterDuff;
99
import android.graphics.Typeface;
10+
import android.graphics.drawable.Drawable;
1011
import android.os.Build;
1112
import android.telephony.PhoneNumberUtils;
1213
import android.telephony.TelephonyManager;
@@ -75,6 +76,7 @@ public class CountryCodePicker extends RelativeLayout {
7576
// see attr.xml to see corresponding values for pref
7677
AutoDetectionPref selectedAutoDetectionPref = AutoDetectionPref.SIM_NETWORK_LOCALE;
7778
PhoneNumberUtil phoneUtil;
79+
boolean rippleEnable = true;
7880
boolean showNameCode = true;
7981
boolean showPhoneCode = true;
8082
boolean ccpDialogShowPhoneCode = true;
@@ -83,6 +85,7 @@ public class CountryCodePicker extends RelativeLayout {
8385
boolean showFastScroller = true;
8486
boolean ccpDialogShowTitle = true;
8587
boolean ccpDialogShowFlag = true;
88+
boolean ccpDialogRippleEnable = true;
8689
boolean searchAllowed = true;
8790
boolean showArrow = true;
8891
boolean showCloseIcon = false;
@@ -264,6 +267,9 @@ private void applyCustomProperty(AttributeSet attrs) {
264267
//ccpDialog initial scroll to selection
265268
ccpDialogInitialScrollToSelection = a.getBoolean(R.styleable.CountryCodePicker_ccpDialog_initialScrollToSelection, false);
266269

270+
//ripple enable on dialog
271+
ccpDialogRippleEnable = a.getBoolean(R.styleable.CountryCodePicker_ccpDialog_rippleEnable, true);
272+
267273
//show full name
268274
showFullName = a.getBoolean(R.styleable.CountryCodePicker_ccp_showFullName, false);
269275

@@ -322,6 +328,10 @@ private void applyCustomProperty(AttributeSet attrs) {
322328
//show close icon
323329
showCloseIcon = a.getBoolean(R.styleable.CountryCodePicker_ccpDialog_showCloseIcon, false);
324330

331+
//ripple enable
332+
rippleEnable = a.getBoolean(R.styleable.CountryCodePicker_ccp_rippleEnable, true);
333+
refreshEnableRipple();
334+
325335
//show flag
326336
showFlag(a.getBoolean(R.styleable.CountryCodePicker_ccp_showFlag, true));
327337

@@ -494,6 +504,17 @@ private void refreshArrowViewVisibility() {
494504
}
495505
}
496506

507+
private void refreshEnableRipple() {
508+
if (rippleEnable) {
509+
TypedValue outValue = new TypedValue();
510+
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
511+
if(outValue.resourceId!=0)
512+
relativeClickConsumer.setBackgroundResource(outValue.resourceId);
513+
else
514+
relativeClickConsumer.setBackgroundResource(outValue.data);
515+
}
516+
}
517+
497518
/**
498519
* this will read last selected country name code from the shared pref.
499520
* if that name code is not null, load that country in the CCP
@@ -594,6 +615,22 @@ public void setCcpDialogShowFlag(boolean ccpDialogShowFlag) {
594615
this.ccpDialogShowFlag = ccpDialogShowFlag;
595616
}
596617

618+
/**
619+
* To show/hide ripple from country selection dialog
620+
*/
621+
public boolean getCcpDialogRippleEnable() {
622+
return this.ccpDialogRippleEnable;
623+
}
624+
625+
/**
626+
* To show/hide ripple from country selection dialog
627+
*
628+
* @param ccpDialogRippleEnable
629+
*/
630+
public void setCcpDialogRippleEnable(boolean ccpDialogRippleEnable) {
631+
this.ccpDialogRippleEnable = ccpDialogRippleEnable;
632+
}
633+
597634
boolean isShowPhoneCode() {
598635
return showPhoneCode;
599636
}

ccp/src/main/res/layout/layout_code_picker.xml

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
android:id="@+id/rlClickConsumer"
1212
android:layout_width="wrap_content"
1313
android:layout_height="wrap_content"
14-
android:foreground="?android:attr/selectableItemBackground"
1514
android:padding="@dimen/ccp_padding"
1615
>
1716

ccp/src/main/res/layout/layout_full_width_code_picker.xml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
android:id="@+id/rlClickConsumer"
1313
android:layout_width="match_parent"
1414
android:layout_height="wrap_content"
15-
android:foreground="?android:attr/selectableItemBackground"
1615
android:padding="@dimen/ccp_padding"
1716
>
1817

ccp/src/main/res/layout/layout_recycler_country_tile.xml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
55
android:layout_height="wrap_content"
6-
android:foreground="?android:attr/selectableItemBackground"
76
android:clickable="true">
87

98
<LinearLayout

ccp/src/main/res/values/attrs.xml

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<attr name="ccp_hintExampleNumber" format="boolean" />
5656
<attr name="ccp_rememberLastSelection" format="boolean" />
5757
<attr name="ccp_showArrow" format="boolean" />
58+
<attr name="ccp_rippleEnable" format="boolean" />
5859

5960
<!--CCP Dialog properties-->
6061
<attr name="ccpDialog_keyboardAutoPopup" format="boolean" />
@@ -74,6 +75,7 @@
7475
<attr name="ccpDialog_showCloseIcon" format="boolean" />
7576
<attr name="ccpDialog_showTitle" format="boolean" />
7677
<attr name="ccpDialog_initialScrollToSelection" format="boolean" />
78+
<attr name="ccpDialog_rippleEnable" format="boolean" />
7779
<!--list of languages-->
7880
<!--Make sure: order in this list must match order of Language Enum in CountryCodePicker.java. Values must be ascending starting from 0.-->
7981
<attr name="ccp_defaultLanguage" format="enum">

0 commit comments

Comments
 (0)