-
-
Notifications
You must be signed in to change notification settings - Fork 506
Full Number Support
Along with country and phone code selection, CCP offers all features which are required to support full number.
- Setup
- Auto-Formatting
- Number Validation
- Number Validity Change Listener
- Load Full Number
- Read Full Number
Full Number is concatenation of country code and carrier number i.e. if the country code is +1 and carrier number is 469 663 1766 then the full number will be +14696631766 or 14696631766.
-
Add this to your Gradle file and sync
dependencies { compile 'com.hbb20:ccp:X.Y.Z' }
*Check latest version from README file.
-
Add CCP view and editText of carrier number to XML layout
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> <com.hbb20.CountryCodePicker android:id="@+id/ccp" android:layout_width="wrap_content" android:layout_height="wrap_content" app:ccp_countryPreference="us,in" /> <EditText android:id="@+id/editText_carrierNumber" android:layout_width="match_parent" android:layout_height="wrap_content" android:editable="false" android:hint="phone" android:inputType="phone" android:singleLine="true" /> </LinearLayout>
-
Add CCP object in Activity / Fragment
CountryCodePicker ccp; EditText editTextCarrierNumber;
-
Bind CCP and Carrier Number editText from layout
ccp = (CountryCodePicker) findViewById(R.id.ccp); editTextCarrierNumber = (EditText) findViewById(R.id.editText_carrierNumber);
-
Attach CarrierNumber editText to CCP.
ccp.registerCarrierNumberEditText(editTextCarrierNumber);
Auto formatting will keep carrier number formatted for selected country standerd. When you select country US (+1) and type 4696641777 in Carrier Edit Text, it will be formatted for US number format (469) 664-1777 as you type in.
By default, auto formatting is enabled for registered carrier number editText. So after successful setup , number in editTextCarrierNumber will be auto formatted as you type or load fullNumber in CCP.
To disable auto-formatting, add app:ccp_autoFormatNumber="false"
property to CCP XML entry or call ccp.setNumberAutoFormattingEnabled(false);
.
Once the setup is completed, you can validate entered full-number using ccp.isValidFullNumber();
. Using this, a developer can keep end user from submitting wrong phone or invalid phone number.
Validity Change Listener will get callBack every time validity of entered number changes.
ccp.setPhoneNumberValidityChangeListener(new CountryCodePicker.PhoneNumberValidityChangeListener() {
@Override
public void onValidityChanged(boolean isValidNumber) {
// your code
}
});
After setup, if you need to load existing full number, i.e. Edit Profile screen where you already have user's full phone number, then ccp.setFullNumber(existingFullNumber);
should be used. This will auto-detect country & carrier number from full number and load in CCP & carrier number editText.
"+" in beginning of existingFullNumber is optional. "14696641766" or "+14696641766", both will set US +1 in CCP and 469-664-1766 in carrier number edittext.
After successful setup when the user has entered a number, you can read that full number in 3 different versions.
//get formatted number i.e "+1 469-664-1766"
ccp.getFormattedFullNumber();
//get unformatted number i.e. "14696641766"
ccp,.getFullNumber();
//get unformatted number with prefix "+" i.e "+14696641766"
ccp.getFullNumberWithPlus();
- How to Integrate into your project
- Full Number Support
- Use as a Country Selector
- Auto detect country
- Auto detect language
- Remember last selection
- Country Preference
- Custom Mater List
- Exclude Countries
- Example phonenumber as hint
- Multi Language Support
- Default Country
- Country Selection Listener
- Dialog events listener
- CCP Theme Customization
- CCP Dialog Theme Customization
- Custom TypeFace
- Read Selected Country
- XML Properties
- Update Guide to v2
- Guide to Add New Language Support
- Guide to add New Country
- Change contry names for local project
- Handle CCP ClickListener Manually
- Custom Dialog Title/Hint/Empty Result ACK
- Flag Emoji Support (BETA)
- Change Log