Search in sources :

Example 1 with Country

use of im.actor.sdk.util.country.Country in project actor-platform by actorapp.

the class PickCountryFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_country_select, null);
    v.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    countriesListView = (ListView) v.findViewById(R.id.lv_countries);
    countriesListView.setDivider(new ColorDrawable(ActorSDK.sharedActor().style.getDividerColor()));
    countriesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (adapter != null) {
                final Country country = adapter.getItem(position);
                getActivity().setResult(Activity.RESULT_OK, new Intent().putExtra("country_id", country.fullNameRes).putExtra("country_code", country.phoneCode).putExtra("country_shortname", country.shortName));
                getActivity().finish();
            }
        }
    });
    adapter = new CountryAdapter(Countries.getInstance().getCountries());
    countriesListView.setAdapter(adapter);
    return v;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Country(im.actor.sdk.util.country.Country) AdapterView(android.widget.AdapterView) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 2 with Country

use of im.actor.sdk.util.country.Country in project actor-platform by actorapp.

the class SignPhoneFragment method initView.

private void initView(View v) {
    ((TextView) v.findViewById(R.id.phone_sign_hint)).setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    countrySelectButton = (Button) v.findViewById(R.id.button_country_select);
    countrySelectButton.setTextColor(ActorSDK.sharedActor().style.getMainColor());
    onClick(countrySelectButton, new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            keyboardHelper.setImeVisibility(phoneNumberEditText, false);
            startActivityForResult(new Intent(getActivity(), PickCountryActivity.class), REQUEST_COUNTRY);
        }
    });
    countryCodeEditText = (EditText) v.findViewById(R.id.tv_country_code);
    countryCodeEditText.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    countryCodeEditText.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) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            final Activity a = getActivity();
            if (a != null) {
                final String str = s.toString();
                if (str.length() == 4 && countryDb != null) {
                    if (countryDb.getCountryByPhoneCode(str) != null) {
                        focusPhone();
                    } else if (countryDb.getCountryByPhoneCode(str.substring(0, 3)) != null) {
                        countryCodeEditText.setText(str.substring(0, 3));
                        phoneNumberEditText.setText(str.substring(3, 4));
                        focusPhone();
                        return;
                    } else if (countryDb.getCountryByPhoneCode(str.substring(0, 2)) != null) {
                        countryCodeEditText.setText(str.substring(0, 2));
                        phoneNumberEditText.setText(str.substring(2, 4));
                        focusPhone();
                        return;
                    } else if (countryDb.getCountryByPhoneCode(str.substring(0, 1)) != null) {
                        countryCodeEditText.setText(str.substring(0, 1));
                        phoneNumberEditText.setText(str.substring(1, 4));
                        focusPhone();
                        return;
                    }
                }
                if (!ignoreNextCodeChange) {
                    if (TextUtils.isEmpty(s)) {
                        countrySelectButton.setText(R.string.auth_phone_country_title);
                    } else {
                        if (countryDb != null) {
                            final Country country = countryDb.getCountryByPhoneCode(s.toString());
                            if (country == null) {
                                countrySelectButton.setText(R.string.auth_phone_error_invalid_country);
                            } else {
                                setCountryName(country);
                            }
                        }
                    }
                } else {
                    ignoreNextCodeChange = false;
                }
            }
        }
    });
    phoneNumberEditText = (BackspaceKeyEditText) v.findViewById(R.id.tv_phone_number);
    phoneNumberEditText.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    phoneNumberEditText.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
    phoneNumberEditText.setBackspaceListener(new BackspaceKeyEditText.BackspacePressListener() {

        @Override
        public boolean onBackspacePressed() {
            if (phoneNumberEditText.getText().length() == 0) {
                focusCode();
                return false;
            } else {
                return true;
            }
        }
    });
    phoneNumberEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == EditorInfo.IME_ACTION_GO) {
                requestCode();
                return true;
            }
            return false;
        }
    });
    phoneNumberEditText.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) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    countryCodeEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_GO) {
                focusPhone();
                return true;
            }
            return false;
        }
    });
    String savedCountryCode = messenger().getPreferences().getString("auth_county_code");
    countryCodeEditText.setText(savedCountryCode);
    String savedPhoneNumber = messenger().getPreferences().getString("auth_phone_number");
    phoneNumberEditText.setText(savedPhoneNumber);
    v.findViewById(R.id.button_why).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(getActivity()).setMessage(R.string.auth_phone_why_description).setPositiveButton(R.string.auth_phone_why_done, null).show().setCanceledOnTouchOutside(true);
        }
    });
    TextView switchToEmail = (TextView) v.findViewById(R.id.button_switch_to_email);
    switchToEmail.setTextColor(ActorSDK.sharedActor().style.getMainColor());
    onClick(switchToEmail, new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            switchToEmail();
        }
    });
    if ((ActorSDK.sharedActor().getAuthType() & AuthActivity.AUTH_TYPE_EMAIL) == AuthActivity.AUTH_TYPE_EMAIL) {
        switchToEmail.setVisibility(View.VISIBLE);
    } else {
        switchToEmail.setVisibility(View.GONE);
    }
    Button singIn = (Button) v.findViewById(R.id.button_sign_in);
    singIn.setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    onClick(singIn, new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startSignIn();
        }
    });
    onClick(v, R.id.button_continue, new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            requestCode();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) Activity(android.app.Activity) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) PhoneNumberFormattingTextWatcher(android.telephony.PhoneNumberFormattingTextWatcher) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Country(im.actor.sdk.util.country.Country) TextView(android.widget.TextView) PhoneNumberFormattingTextWatcher(android.telephony.PhoneNumberFormattingTextWatcher)

Example 3 with Country

use of im.actor.sdk.util.country.Country in project actor-platform by actorapp.

the class SignPhoneFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_sign_phone, container, false);
    v.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    TextView buttonContinue = (TextView) v.findViewById(R.id.button_continue_text);
    StateListDrawable states = SelectorFactory.get(ActorSDK.sharedActor().style.getMainColor(), getActivity());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        buttonContinue.setBackground(states);
    } else {
        buttonContinue.setBackgroundDrawable(states);
    }
    buttonContinue.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    buttonContinue.setTypeface(Fonts.medium());
    ((TextView) v.findViewById(R.id.button_why)).setTypeface(Fonts.medium());
    ((TextView) v.findViewById(R.id.button_why)).setTextColor(ActorSDK.sharedActor().style.getMainColor());
    keyboardHelper = new KeyboardHelper(getActivity());
    initView(v);
    countryDb = Countries.getInstance();
    String deviceCountry = Devices.getDeviceCountry();
    if (!TextUtils.isEmpty(deviceCountry)) {
        Country country = countryDb.getCountryByShortName(deviceCountry);
        setCountryName(country);
        if (country != null) {
            countryCodeEditText.setText(country.phoneCode);
            focusPhone();
        } else {
            focusCode();
        }
    } else {
        setCountryName(null);
        countryCodeEditText.setText("");
        focusCode();
    }
    v.findViewById(R.id.divider).setBackgroundColor(style.getDividerColor());
    setTosAndPrivacy((TextView) v.findViewById(R.id.disclaimer));
    return v;
}
Also used : Country(im.actor.sdk.util.country.Country) TextView(android.widget.TextView) StateListDrawable(android.graphics.drawable.StateListDrawable) KeyboardHelper(im.actor.sdk.util.KeyboardHelper) View(android.view.View) TextView(android.widget.TextView)

Aggregations

View (android.view.View)3 TextView (android.widget.TextView)3 Country (im.actor.sdk.util.country.Country)3 Intent (android.content.Intent)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 StateListDrawable (android.graphics.drawable.StateListDrawable)1 PhoneNumberFormattingTextWatcher (android.telephony.PhoneNumberFormattingTextWatcher)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 KeyEvent (android.view.KeyEvent)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 KeyboardHelper (im.actor.sdk.util.KeyboardHelper)1