diff --git a/.idea/misc.xml b/.idea/misc.xml
index 47166006..93ceef35 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,6 +3,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/build.gradle b/app/build.gradle
index e84d5a0d..45d51acd 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -20,7 +20,10 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
+ compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
+ compile project(':countrycodepicker')
compile 'com.android.support:appcompat-v7:23.1.1'
+ compile 'com.android.support:support-v4:23.1.1'
+ compile 'com.android.support:cardview-v7:23.1.1'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 8694b416..7e9ab8d5 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,11 +4,12 @@
-
+
diff --git a/app/src/main/java/in/hbb20/countrycodepickerproject/CustomColorFragment.java b/app/src/main/java/in/hbb20/countrycodepickerproject/CustomColorFragment.java
new file mode 100644
index 00000000..45feaafc
--- /dev/null
+++ b/app/src/main/java/in/hbb20/countrycodepickerproject/CustomColorFragment.java
@@ -0,0 +1,109 @@
+package in.hbb20.countrycodepickerproject;
+
+import android.content.res.ColorStateList;
+import android.graphics.PorterDuff;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.EditText;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import in.hbb20.CountryCodePicker;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class CustomColorFragment extends Fragment {
+
+ public CustomColorFragment() {
+ }
+
+ TextView textViewTitle;
+ EditText editTextPhone;
+ CountryCodePicker ccp;
+ RelativeLayout relativeColor1,relativeColor2,relativeColor3;
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_custom_color, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ assignViews();
+ setClickListener();
+ }
+
+ private void setClickListener() {
+ relativeColor1.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ setColor(1, getActivity().getResources().getColor(R.color.color1));
+ }
+ });
+
+ relativeColor2.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ setColor(2, getActivity().getResources().getColor(R.color.color2));
+ }
+ });
+
+ relativeColor3.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ setColor(3,getActivity().getResources().getColor(R.color.color3));
+ }
+ });
+ }
+
+ private void setColor(int selection,int color) {
+ ccp.setContentColor(color);
+
+ //textView
+ textViewTitle.setTextColor(color);
+
+ //editText
+ editTextPhone.setTextColor(color);
+ editTextPhone.setHintTextColor(color);
+ editTextPhone.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
+
+ //remove selected bg
+ resetBG();
+
+ //set selected bg
+ int selectedBGColor=getActivity().getResources().getColor(R.color.selectedTile);
+ switch (selection){
+ case 1:
+ relativeColor1.setBackgroundColor(selectedBGColor);
+ break;
+ case 2:
+ relativeColor2.setBackgroundColor(selectedBGColor);
+ break;
+ case 3:
+ relativeColor3.setBackgroundColor(selectedBGColor);
+ break;
+ }
+ }
+
+ private void resetBG() {
+ relativeColor1.setBackgroundColor(getActivity().getResources().getColor(R.color.dullBG));
+ relativeColor2.setBackgroundColor(getActivity().getResources().getColor(R.color.dullBG));
+ relativeColor3.setBackgroundColor(getActivity().getResources().getColor(R.color.dullBG));
+ }
+
+ private void assignViews() {
+ textViewTitle =(TextView)getView().findViewById(R.id.textView_title);
+ editTextPhone =(EditText)getView().findViewById(R.id.editText_phone);
+ ccp=(CountryCodePicker)getView().findViewById(R.id.ccp);
+ relativeColor1=(RelativeLayout)getView().findViewById(R.id.relative_color1);
+ relativeColor2=(RelativeLayout)getView().findViewById(R.id.relative_color2);
+ relativeColor3=(RelativeLayout)getView().findViewById(R.id.relative_color3);
+ }
+}
diff --git a/app/src/main/java/in/hbb20/countrycodepickerproject/DefaultCountryFragment.java b/app/src/main/java/in/hbb20/countrycodepickerproject/DefaultCountryFragment.java
new file mode 100644
index 00000000..7bf5e893
--- /dev/null
+++ b/app/src/main/java/in/hbb20/countrycodepickerproject/DefaultCountryFragment.java
@@ -0,0 +1,107 @@
+package in.hbb20.countrycodepickerproject;
+
+
+import android.graphics.PorterDuff;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import in.hbb20.CountryCodePicker;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class DefaultCountryFragment extends Fragment {
+
+
+ EditText editTextDefaultCode;
+ Button buttonSetNewDefaultCode,buttonResetToDefault;
+ CountryCodePicker ccp;
+ Button buttonNext;
+ public DefaultCountryFragment() {
+ // Required empty public constructor
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_default_country, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ assignViews();
+ editTextWatcher();
+ addClickListeners();
+ }
+
+ private void addClickListeners() {
+ buttonSetNewDefaultCode.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ int code=-1;
+ try{
+ code=Integer.parseInt(editTextDefaultCode.getText().toString());
+ ccp.setDefaultCountryCode(code);
+ Toast.makeText(getActivity(),"Now default country is "+ccp.getDefaultCountryName()+" with phone code "+ccp.getDefaultCountryCode() ,Toast.LENGTH_LONG).show();
+ }catch (Exception ex){
+ Toast.makeText(getActivity(),"Invalid number format",Toast.LENGTH_LONG).show();
+ }
+ }
+ });
+
+ buttonResetToDefault.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ccp.resetToDefaultCountry();
+ }
+ });
+
+ buttonNext.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ((ExampleActivity) getActivity()).viewPager.setCurrentItem(((ExampleActivity) getActivity()).viewPager.getCurrentItem() + 1);
+ }
+ });
+ }
+
+ private void editTextWatcher() {
+ editTextDefaultCode.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ buttonSetNewDefaultCode.setText("set "+s+" as Default Country Code");
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+
+ }
+ });
+ }
+
+ private void assignViews() {
+ editTextDefaultCode=(EditText)getView().findViewById(R.id.editText_defaultCode);
+ ccp=(CountryCodePicker)getView().findViewById(R.id.ccp);
+ buttonSetNewDefaultCode=(Button) getView().findViewById(R.id.button_setDefault);
+ buttonResetToDefault=(Button) getView().findViewById(R.id.button_resetToDefault);
+
+ buttonNext=(Button)getView().findViewById(R.id.button_next);
+ buttonNext.getBackground().setColorFilter(getActivity().getResources().getColor(R.color.colorPrimary), PorterDuff.Mode.MULTIPLY);
+ }
+}
diff --git a/app/src/main/java/in/hbb20/countrycodepickerproject/ExampleActivity.java b/app/src/main/java/in/hbb20/countrycodepickerproject/ExampleActivity.java
index 6db8e9a8..0149e5ec 100644
--- a/app/src/main/java/in/hbb20/countrycodepickerproject/ExampleActivity.java
+++ b/app/src/main/java/in/hbb20/countrycodepickerproject/ExampleActivity.java
@@ -1,13 +1,69 @@
package in.hbb20.countrycodepickerproject;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class ExampleActivity extends AppCompatActivity {
+ ViewPager viewPager;
+ PagerAdapter pagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
+ assignViews();
+ setUpViewPager();
+ }
+
+ /**
+ * Assign adapter to viewPager
+ */
+ private void setUpViewPager() {
+ if(pagerAdapter==null){
+ pagerAdapter=new PagerAdapter(getSupportFragmentManager());
+ }
+ viewPager.setAdapter(pagerAdapter);
+ }
+
+ /**
+ * assign views to object from layout
+ */
+ private void assignViews() {
+ viewPager=(ViewPager)findViewById(R.id.viewPager);
+ }
+
+ class PagerAdapter extends FragmentPagerAdapter{
+
+ public PagerAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ switch (position){
+ case 0:
+ return new IntroductionFragment();
+ case 1:
+ return new DefaultCountryFragment();
+ case 2:
+ return new SetCountryFragment();
+ case 3:
+ return new GetCountryFragment();
+ case 4:
+ return new FullNumberFragment();
+ case 5:
+ return new CustomColorFragment();
+ }
+ return null;
+ }
+
+ @Override
+ public int getCount() {
+ return 6;
+ }
}
}
diff --git a/app/src/main/java/in/hbb20/countrycodepickerproject/FullNumberFragment.java b/app/src/main/java/in/hbb20/countrycodepickerproject/FullNumberFragment.java
new file mode 100644
index 00000000..a890fbfa
--- /dev/null
+++ b/app/src/main/java/in/hbb20/countrycodepickerproject/FullNumberFragment.java
@@ -0,0 +1,118 @@
+package in.hbb20.countrycodepickerproject;
+
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+
+import in.hbb20.CountryCodePicker;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class FullNumberFragment extends Fragment {
+
+
+ EditText editTextLoadFullNumber,editTextLoadCarrierNumber,editTextGetFullNumber,editTextGetCarrierNumber;
+ CountryCodePicker ccpLoadNumber,ccpGetNumber;
+ Button buttonLoadNumber,buttonGetNumber,buttonGetNumberWithPlus;
+ Button buttonNext;
+ public FullNumberFragment() {
+ // Required empty public constructor
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_full_number, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ assignView();
+ registerCarrierEditText();
+ setClickListener();
+ addTextWatcher();
+ }
+
+ private void addTextWatcher() {
+ editTextLoadFullNumber.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ buttonLoadNumber.setText("Load "+s+" to CCP.");
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+
+ }
+ });
+ }
+
+ private void setClickListener() {
+ buttonLoadNumber.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ccpLoadNumber.setFullNumber(editTextLoadFullNumber.getText().toString());
+ }
+ });
+
+ buttonGetNumber.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ editTextGetFullNumber.setText(ccpGetNumber.getFullNumber());
+ }
+ });
+
+ buttonGetNumberWithPlus.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ editTextGetFullNumber.setText(ccpGetNumber.getFullNumberWithPlus());
+ }
+ });
+
+ buttonNext.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ((ExampleActivity) getActivity()).viewPager.setCurrentItem(((ExampleActivity) getActivity()).viewPager.getCurrentItem() + 1);
+ }
+ });
+ }
+
+ private void registerCarrierEditText() {
+ ccpLoadNumber.registerCarrierNumberEditText(editTextLoadCarrierNumber);
+ ccpGetNumber.registerCarrierNumberEditText(editTextGetCarrierNumber);
+ }
+
+ private void assignView() {
+ //load number
+ editTextLoadFullNumber=(EditText)getView().findViewById(R.id.editText_loadFullNumber);
+ editTextLoadCarrierNumber=(EditText)getView().findViewById(R.id.editText_loadCarrierNumber);
+ ccpLoadNumber=(CountryCodePicker)getView().findViewById(R.id.ccp_loadFullNumber);
+ buttonLoadNumber=(Button)getView().findViewById(R.id.button_loadFullNumber);
+
+ //get number
+ editTextGetCarrierNumber=(EditText)getView().findViewById(R.id.editText_getCarrierNumber);
+ editTextGetFullNumber=(EditText)getView().findViewById(R.id.editText_getFullNumber);
+ buttonGetNumber=(Button)getView().findViewById(R.id.button_getFullNumber);
+ buttonGetNumberWithPlus=(Button)getView().findViewById(R.id.button_getFullNumberWithPlus);
+ ccpGetNumber=(CountryCodePicker)getView().findViewById(R.id.ccp_getFullNumber);
+
+ buttonNext=(Button)getView().findViewById(R.id.button_next);
+ }
+}
diff --git a/app/src/main/java/in/hbb20/countrycodepickerproject/GetCountryFragment.java b/app/src/main/java/in/hbb20/countrycodepickerproject/GetCountryFragment.java
new file mode 100644
index 00000000..023ff4bd
--- /dev/null
+++ b/app/src/main/java/in/hbb20/countrycodepickerproject/GetCountryFragment.java
@@ -0,0 +1,70 @@
+package in.hbb20.countrycodepickerproject;
+
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+
+import in.hbb20.CountryCodePicker;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class GetCountryFragment extends Fragment {
+
+
+ TextView textViewCountryName,textViewCountryCode,textViewCountryNameCode;
+ Button buttonReadCountry;
+ CountryCodePicker ccp;
+ Button buttonNext;
+ public GetCountryFragment() {
+ // Required empty public constructor
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_get_country, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ assignViews();
+ setClickListener();
+ }
+
+ private void setClickListener() {
+ buttonReadCountry.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ textViewCountryName.setText(ccp.getSelectedCountryName());
+ textViewCountryCode.setText(ccp.getSelectedCountryCode());
+ textViewCountryNameCode.setText(ccp.getSelectedCountryNameCode());
+ }
+ });
+
+ buttonNext.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ((ExampleActivity) getActivity()).viewPager.setCurrentItem(((ExampleActivity) getActivity()).viewPager.getCurrentItem() + 1);
+ }
+ });
+ }
+
+ private void assignViews() {
+ ccp=(CountryCodePicker)getView().findViewById(R.id.ccp);
+ textViewCountryCode=(TextView)getView().findViewById(R.id.textView_countryCode);
+ textViewCountryName=(TextView)getView().findViewById(R.id.textView_countryName);
+ textViewCountryNameCode=(TextView)getView().findViewById(R.id.textView_countryNameCode);
+ buttonReadCountry=(Button)getView().findViewById(R.id.button_readCountry);
+ buttonNext=(Button)getView().findViewById(R.id.button_next);
+ }
+}
diff --git a/app/src/main/java/in/hbb20/countrycodepickerproject/IntroductionFragment.java b/app/src/main/java/in/hbb20/countrycodepickerproject/IntroductionFragment.java
new file mode 100644
index 00000000..ba46c1f3
--- /dev/null
+++ b/app/src/main/java/in/hbb20/countrycodepickerproject/IntroductionFragment.java
@@ -0,0 +1,50 @@
+package in.hbb20.countrycodepickerproject;
+
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class IntroductionFragment extends Fragment {
+
+
+ Button buttonGo;
+ public IntroductionFragment() {
+ // Required empty public constructor
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_introduction, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ assignViews();
+ setClickListener();
+ }
+
+ private void setClickListener() {
+ buttonGo.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ((ExampleActivity)getActivity()).viewPager.setCurrentItem(1);
+ }
+ });
+ }
+
+ private void assignViews() {
+ buttonGo=(Button)getView().findViewById(R.id.button_letsGo);
+ }
+}
diff --git a/app/src/main/java/in/hbb20/countrycodepickerproject/SetCountryFragment.java b/app/src/main/java/in/hbb20/countrycodepickerproject/SetCountryFragment.java
new file mode 100644
index 00000000..aad4264e
--- /dev/null
+++ b/app/src/main/java/in/hbb20/countrycodepickerproject/SetCountryFragment.java
@@ -0,0 +1,95 @@
+package in.hbb20.countrycodepickerproject;
+
+import android.content.Context;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import in.hbb20.CountryCodePicker;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ * create an instance of this fragment.
+ */
+public class SetCountryFragment extends Fragment {
+
+ EditText editTextCode;
+ Button buttonSetCode;
+ CountryCodePicker ccp;
+ Button buttonNext;
+ public SetCountryFragment() {
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_set_country, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ assignViews();
+ editTextWatcher();
+ addClickListeners();
+ }
+
+ private void addClickListeners() {
+ buttonSetCode.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ int code=-1;
+ try{
+ code=Integer.parseInt(editTextCode.getText().toString());
+ ccp.setCountryForCode(code);
+ }catch (Exception ex){
+ Toast.makeText(getActivity(),"Invalid number format",Toast.LENGTH_LONG).show();
+ }
+ }
+ });
+
+ buttonNext.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ((ExampleActivity) getActivity()).viewPager.setCurrentItem(((ExampleActivity) getActivity()).viewPager.getCurrentItem()+1);
+ }
+ });
+ }
+
+ private void editTextWatcher() {
+ editTextCode.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ buttonSetCode.setText("Set country with code "+s);
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+
+ }
+ });
+ }
+
+ private void assignViews() {
+ editTextCode=(EditText)getView().findViewById(R.id.editText_countryCode);
+ ccp=(CountryCodePicker)getView().findViewById(R.id.ccp);
+ buttonSetCode=(Button) getView().findViewById(R.id.button_setCountry);
+ buttonNext=(Button)getView().findViewById(R.id.button_next);
+ }
+
+}
diff --git a/app/src/main/res/drawable/card.xml b/app/src/main/res/drawable/card.xml
new file mode 100644
index 00000000..418675f2
--- /dev/null
+++ b/app/src/main/res/drawable/card.xml
@@ -0,0 +1,46 @@
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/color1Cpp.png b/app/src/main/res/drawable/color1Cpp.png
new file mode 100644
index 00000000..f6f9169b
Binary files /dev/null and b/app/src/main/res/drawable/color1Cpp.png differ
diff --git a/app/src/main/res/drawable/color2Cpp.png b/app/src/main/res/drawable/color2Cpp.png
new file mode 100644
index 00000000..adf25d5c
Binary files /dev/null and b/app/src/main/res/drawable/color2Cpp.png differ
diff --git a/app/src/main/res/drawable/ic_ccp_launcher.png b/app/src/main/res/drawable/ic_ccp_launcher.png
new file mode 100644
index 00000000..949a3561
Binary files /dev/null and b/app/src/main/res/drawable/ic_ccp_launcher.png differ
diff --git a/app/src/main/res/drawable/nonCpp.png b/app/src/main/res/drawable/nonCpp.png
new file mode 100644
index 00000000..c8ef5d6a
Binary files /dev/null and b/app/src/main/res/drawable/nonCpp.png differ
diff --git a/app/src/main/res/drawable/withCpp.png b/app/src/main/res/drawable/withCpp.png
new file mode 100644
index 00000000..ea1cf643
Binary files /dev/null and b/app/src/main/res/drawable/withCpp.png differ
diff --git a/app/src/main/res/layout/activity_example.xml b/app/src/main/res/layout/activity_example.xml
index caecacea..e9470632 100644
--- a/app/src/main/res/layout/activity_example.xml
+++ b/app/src/main/res/layout/activity_example.xml
@@ -3,14 +3,12 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="in.hbb20.countrycodepickerproject.ExampleActivity">
-
+
diff --git a/app/src/main/res/layout/fragment_custom_color.xml b/app/src/main/res/layout/fragment_custom_color.xml
new file mode 100644
index 00000000..74718b26
--- /dev/null
+++ b/app/src/main/res/layout/fragment_custom_color.xml
@@ -0,0 +1,166 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_default_country.xml b/app/src/main/res/layout/fragment_default_country.xml
new file mode 100644
index 00000000..6ed54527
--- /dev/null
+++ b/app/src/main/res/layout/fragment_default_country.xml
@@ -0,0 +1,209 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_full_number.xml b/app/src/main/res/layout/fragment_full_number.xml
new file mode 100644
index 00000000..b2fc2241
--- /dev/null
+++ b/app/src/main/res/layout/fragment_full_number.xml
@@ -0,0 +1,229 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_get_country.xml b/app/src/main/res/layout/fragment_get_country.xml
new file mode 100644
index 00000000..deb185ba
--- /dev/null
+++ b/app/src/main/res/layout/fragment_get_country.xml
@@ -0,0 +1,179 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_introduction.xml b/app/src/main/res/layout/fragment_introduction.xml
new file mode 100644
index 00000000..6f99d2f0
--- /dev/null
+++ b/app/src/main/res/layout/fragment_introduction.xml
@@ -0,0 +1,137 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_set_country.xml b/app/src/main/res/layout/fragment_set_country.xml
new file mode 100644
index 00000000..0b646249
--- /dev/null
+++ b/app/src/main/res/layout/fragment_set_country.xml
@@ -0,0 +1,172 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/values-v16/styles.xml b/app/src/main/res/values-v16/styles.xml
new file mode 100644
index 00000000..864f421e
--- /dev/null
+++ b/app/src/main/res/values-v16/styles.xml
@@ -0,0 +1,11 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 3ab3e9cb..b6c185be 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -3,4 +3,11 @@
#3F51B5
#303F9F
#FF4081
+ #d4d4d4
+ #dddddd
+ #ffffff
+ #fff
+ #222124
+ #69f0ae
+ #7c4dff
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index 47c82246..3f996579 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -2,4 +2,6 @@
16dp
16dp
+ 2dp
+ 8dp
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e37cd1a3..94b66d5c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,3 +1,6 @@
- CountryCodePickerProject
+ CCP library features
+
+
+ Hello blank fragment
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 5885930d..13303a64 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -8,4 +8,78 @@
- @color/colorAccent
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #e5e5e5
diff --git a/countrycodepicker/src/main/java/in/hbb20/CountryCodePicker.java b/countrycodepicker/src/main/java/in/hbb20/CountryCodePicker.java
index a4331d29..365a6c62 100644
--- a/countrycodepicker/src/main/java/in/hbb20/CountryCodePicker.java
+++ b/countrycodepicker/src/main/java/in/hbb20/CountryCodePicker.java
@@ -3,8 +3,12 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.system.Os;
import android.util.AttributeSet;
import android.util.Log;
+import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
@@ -18,12 +22,14 @@
public class CountryCodePicker extends RelativeLayout {
static String TAG = "CCP";
+ static String BUNDLE_SELECTED_CODE="selctedCode";
static int LIB_DEFAULT_COUNTRY_CODE = 91;
int defaultCountryCode;
Context context;
View holderView;
LayoutInflater mInflater;
TextView textView_selectedCountry;
+ EditText editText_registeredCarrierNumber;
RelativeLayout relative_holder;
ImageView imageViewArrow;
Country selectedCountry;
@@ -49,8 +55,8 @@ public CountryCodePicker(Context context, AttributeSet attrs, int defStyleAttr)
init(attrs);
}
-
private void init(AttributeSet attrs) {
+ Log.d(TAG,"Initialization of CCP");
mInflater = LayoutInflater.from(context);
holderView = mInflater.inflate(R.layout.layout_code_picker, this, true);
textView_selectedCountry = (TextView) holderView.findViewById(R.id.textView_selectedCountry);
@@ -64,6 +70,7 @@ private void init(AttributeSet attrs) {
private void applyCustomProperty(AttributeSet attrs) {
+ Log.d(TAG,"Applying custom property");
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.CountryCodePicker,
@@ -74,7 +81,12 @@ private void applyCustomProperty(AttributeSet attrs) {
//default country
//if no country code is specified, 1 will be the default countryCode.
if (!isInEditMode()) {
- int defaultCountryCode = a.getInteger(R.styleable.CountryCodePicker_defaultCode, 91);
+ int defaultCountryCode = a.getInteger(R.styleable.CountryCodePicker_defaultCode, LIB_DEFAULT_COUNTRY_CODE);
+
+ //if invalid country is set using xml, it will be replaced with LIB_DEFAULT_COUNTRY_CODE
+ if(Country.getCountryForCode(context,defaultCountryCode)==null){
+ defaultCountryCode=LIB_DEFAULT_COUNTRY_CODE;
+ }
setDefaultCountryCode(defaultCountryCode);
setSelectedCountry(defaultCountry);
}
@@ -140,6 +152,7 @@ void setSelectedCountry(Country selectedCountry) {
selectedCountry = Country.getCountryForCode(context, defaultCountryCode);
}
textView_selectedCountry.setText("(" + selectedCountry.getNameCode() + ") +" + selectedCountry.getPhoneCode());
+ Log.d(TAG, "Setting selected country:"+selectedCountry.logString());
}
private View getHolderView() {
@@ -158,6 +171,14 @@ private void setRelative_holder(RelativeLayout relative_holder) {
this.relative_holder = relative_holder;
}
+ EditText getEditText_registeredCarrierNumber() {
+ return editText_registeredCarrierNumber;
+ }
+
+ void setEditText_registeredCarrierNumber(EditText editText_registeredCarrierNumber) {
+ this.editText_registeredCarrierNumber = editText_registeredCarrierNumber;
+ }
+
private LayoutInflater getmInflater() {
return mInflater;
}
@@ -199,20 +220,19 @@ private String detectCarrierNumber(String fullNumber, Country country) {
* Default country code defines your default country.
* Whenever invalid / improper number is found in setCountryForCode() / setFullNumber(), it CCP will set to default country.
* This function will not set default country as selected in CCP. To set default country in CCP call resetToDefaultCountry() right after this call.
- *
+ * If invalid defaultCountryCode is applied, it won't be changed.
* @param defaultCountryCode code of your default country
* if you want to set IN +91(India) as default country, defaultCountryCode => 91
* if you want to set JP +81(Japan) as default country, defaultCountryCode => 81
*/
public void setDefaultCountryCode(int defaultCountryCode) {
- this.defaultCountryCode = defaultCountryCode;
Country defaultCountry = Country.getCountryForCode(context, defaultCountryCode); //xml stores data in string format, but want to allow only numeric value to country code to user.
- if (defaultCountry == null) {
+ if (defaultCountry == null) { //if no correct country is found
Log.d(TAG, "No country for code " + defaultCountryCode + " is found");
- this.defaultCountryCode = LIB_DEFAULT_COUNTRY_CODE;
- defaultCountry = Country.getCountryForCode(context, LIB_DEFAULT_COUNTRY_CODE);
+ }else{ //if correct country is found, set the country
+ this.defaultCountryCode = defaultCountryCode;
+ setDefaultCountry(defaultCountry);
}
- setDefaultCountry(defaultCountry);
}
/**
@@ -362,25 +382,38 @@ public void setCountryForCode(int countryCode) {
setSelectedCountry(country);
}
+ /**
+ * All functions that work with fullNumber need an editText to write and read carrier number of full number.
+ * An editText for carrier number must be registered in order to use functions like setFullNumber() and getFullNumber().
+ * @param editTextCarrierNumber - an editText where user types carrier number ( the part of full number other than country code).
+ */
+ public void registerCarrierNumberEditText(EditText editTextCarrierNumber){
+ setEditText_registeredCarrierNumber(editTextCarrierNumber);
+ }
+
/**
* This function combines selected country code from CCP and carrier number from @param editTextCarrierNumber
*
- * @param editTextCarrierNumber is the editText where carrier phone number will be inserted.
* @return Full number is countryCode + carrierNumber i.e countryCode=>91 and carrier number=>8866667722, this will return "918866667722"
*/
- public String getFullNumber(EditText editTextCarrierNumber) {
- String fullNumber = getSelectedCountry().getPhoneCode() + editTextCarrierNumber.getText().toString();
+ public String getFullNumber() {
+ String fullNumber;
+ if(editText_registeredCarrierNumber!=null) {
+ fullNumber = getSelectedCountry().getPhoneCode() + editText_registeredCarrierNumber.getText().toString();
+ }else {
+ fullNumber = getSelectedCountry().getPhoneCode();
+ Log.w(TAG,"EditText for carrier number is not registered. Register it using registerCarrierNumberEditText() before getFullNumber() or setFullNumber().");
+ }
return fullNumber;
}
/**
* This function combines selected country code from CCP and carrier number from @param editTextCarrierNumber and prefix "+"
*
- * @param editTextCarrierNumber is the editText where carrier phone number will be inserted.
* @return Full number is countryCode + carrierNumber i.e countryCode=>91 and carrier number=>8866667722, this will return "+918866667722"
*/
- public String getFullNumberWithPlus(EditText editTextCarrierNumber) {
- String fullNumber = "+" + getFullNumber(editTextCarrierNumber);
+ public String getFullNumberWithPlus() {
+ String fullNumber = "+" + getFullNumber();
return fullNumber;
}
@@ -390,14 +423,15 @@ public String getFullNumberWithPlus(EditText editTextCarrierNumber) {
* If no valid country code is found from full number, CCP will be set to default country code and full number will be set as carrier number to editTextCarrierNumber.
*
* @param fullNumber is combination of country code and carrier number, (country_code+carrier_number) for example if country is India (+91) and carrier/mobile number is 8866667722 then full number will be 9188666667722 or +918866667722. "+" in starting of number is optional.
- * @param editTextCarrierNumber is the edit text where you want to put the carrier number
*/
- public void setFullNumber(String fullNumber, EditText editTextCarrierNumber) {
+ public void setFullNumber(String fullNumber) {
Country country = Country.getCountryForNumber(context, fullNumber);
setSelectedCountry(country);
String carrierNumber = detectCarrierNumber(fullNumber, country);
- if (editTextCarrierNumber != null) {
- editTextCarrierNumber.setText(carrierNumber);
+ if (getEditText_registeredCarrierNumber() != null) {
+ getEditText_registeredCarrierNumber().setText(carrierNumber);
+ }else{
+ Log.w(TAG,"EditText for carrier number is not registered. Register it using registerCarrierNumberEditText() before getFullNumber() or setFullNumber().");
}
}
diff --git a/countrycodepicker/src/main/res/layout/layout_code_picker.xml b/countrycodepicker/src/main/res/layout/layout_code_picker.xml
index 3dfab416..2ae33dc1 100644
--- a/countrycodepicker/src/main/res/layout/layout_code_picker.xml
+++ b/countrycodepicker/src/main/res/layout/layout_code_picker.xml
@@ -4,7 +4,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
- android:background="?attr/selectableItemBackground"
+ android:foreground="?attr/selectableItemBackground"
android:padding="8dp"
android:gravity="center"
android:layout_gravity="right">
@@ -14,7 +14,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(IN) +91"
- android:textColor="@android:color/primary_text_light"
+ android:textColor="@android:color/black"
android:textSize="18sp" />
+ android:tint="@android:color/black" />
\ No newline at end of file
diff --git a/countrycodepicker/src/main/res/layout/layout_picker_dialog.xml b/countrycodepicker/src/main/res/layout/layout_picker_dialog.xml
index 0b7eb2c9..4f40d435 100644
--- a/countrycodepicker/src/main/res/layout/layout_picker_dialog.xml
+++ b/countrycodepicker/src/main/res/layout/layout_picker_dialog.xml
@@ -20,6 +20,7 @@
android:layout_height="wrap_content"
android:layout_below="@+id/textView_title"
android:hint="search..."
+ android:singleLine="true"
android:textColor="@android:color/primary_text_light_nodisable" />
+
\ No newline at end of file