Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.myanmarmusicstore.mms;
- import java.util.ArrayList;
- import android.app.Dialog;
- import android.content.Intent;
- import android.graphics.Color;
- import android.graphics.Rect;
- import android.os.Bundle;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.util.Log;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewTreeObserver.OnGlobalLayoutListener;
- import android.view.Window;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemSelectedListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.Spinner;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.myanmarmusicstore.mms.adapter.SpinnerListAdapter;
- import com.myanmarmusicstore.mms.asyn.RegisterAsyn;
- import com.myanmarmusicstore.mms.base.BaseActivity;
- import com.myanmarmusicstore.mms.db.CountryListDao;
- import com.myanmarmusicstore.mms.db.DatabaseManager;
- import com.myanmarmusicstore.mms.obj.ObjCountryList;
- import com.myanmarmusicstore.mms.util.Constant;
- import com.myanmarmusicstore.mms.util.NetworkListener;
- import com.myanmarmusicstore.mms.util.Util;
- public class RegisterActivity extends BaseActivity {
- private TextView tvRegisterTitle;
- private EditText etUsername, etPassword, etEmail, etPhone;
- private Button btnRegister;
- private LinearLayout backgroundView ;
- private Spinner spinnerCountry;
- private String shortCountryName;
- private TextView isvalidMessage_tv;
- private ArrayList<ObjCountryList> list;
- private RadioGroup radioGroup;
- private RadioButton radioMale, radioFemale;
- private String strGender;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- tvRegisterTitle = (TextView) findViewById(R.id.tvRegisterTitle);
- etUsername = (EditText) findViewById(R.id.etRegisterUsername);
- etPassword = (EditText) findViewById(R.id.etRegisterPassword);
- etEmail = (EditText) findViewById(R.id.etRegisterEmail);
- etPhone = (EditText)findViewById(R.id.etRegisterPhone);
- btnRegister = (Button) findViewById(R.id.btnRegisterRegister);
- backgroundView = (LinearLayout)findViewById(R.id.register_background_image);
- spinnerCountry = (Spinner)findViewById(R.id.spinnerCountryList);
- isvalidMessage_tv = (TextView)findViewById(R.id.message_tv);
- radioGroup = (RadioGroup) findViewById(R.id.registerRadioGroup);
- radioMale = (RadioButton) findViewById(R.id.male);
- radioFemale = (RadioButton) findViewById(R.id.female);
- etEmail.addTextChangedListener(filterTextWatcher );
- if (pref.getBoolean(Constant.isFontEmbeded, false)) {
- tvRegisterTitle.setTypeface(Util.userChooseFont(ctx));
- etUsername.setTypeface(Util.userChooseFont(ctx));
- etPassword.setTypeface(Util.userChooseFont(ctx));
- etEmail.setTypeface(Util.userChooseFont(ctx));
- btnRegister.setTypeface(Util.userChooseFont(ctx));
- } else {
- tvRegisterTitle.setTypeface(null);
- etUsername.setTypeface(null);
- etPassword.setTypeface(null);
- etEmail.setTypeface(null);
- btnRegister.setTypeface(null);
- }
- btnRegister.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- int selectedId = radioGroup.getCheckedRadioButtonId();
- if(selectedId == radioMale.getId()) {
- strGender = "Male";
- } else if(selectedId == radioFemale.getId()) {
- strGender = "Female";
- }
- Log.i("kglay","GENDER >>> " + strGender);
- if(checkForm()) {
- if (NetworkListener.isOnline(ctx)) {
- new RegisterAsyn(RegisterActivity.this, ctx, etUsername
- .getText().toString(), etPassword.getText()
- .toString(), etEmail.getText().toString(),
- shortCountryName, etPhone.getText().toString(),strGender).execute();
- } else {
- Toast.makeText(ctx, "You are offline.", Toast.LENGTH_SHORT)
- .show();
- }
- }
- }
- });
- detectKeyboard();
- setSpinnerAdapter();
- }
- private boolean checkForm() {
- boolean isCheckOK = false;
- if(etUsername.getText().toString().equalsIgnoreCase("")) {
- Toast.makeText(ctx, "Username can't be blank", Toast.LENGTH_SHORT).show();
- isCheckOK = false;
- }
- else if(etPassword.getText().toString().equalsIgnoreCase("")) {
- Toast.makeText(ctx, "Password can't be blank", Toast.LENGTH_SHORT).show();
- isCheckOK = false;
- }
- else if(etEmail.getText().toString().equalsIgnoreCase("")) {
- Toast.makeText(ctx, "Email can't be blank", Toast.LENGTH_SHORT).show();
- isCheckOK = false;
- }
- else if(etPhone.getText().toString().equalsIgnoreCase("")) {
- Toast.makeText(ctx, "PhoneNumber can't be blank", Toast.LENGTH_SHORT).show();
- isCheckOK = false;
- }
- else {
- isCheckOK = true;
- }
- return isCheckOK ;
- }
- private void setSpinnerAdapter(){
- list = new ArrayList<ObjCountryList>();
- CountryListDao dao = new CountryListDao(new DatabaseManager(ctx));
- list = dao.getAll();
- SpinnerListAdapter dataAdapter = new SpinnerListAdapter(ctx, list);
- // ArrayAdapter<ObjCountryList> dataAdapter = new ArrayAdapter<ObjCountryList>(this,android.R.layout.simple_spinner_item, list);
- // dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- spinnerCountry.setAdapter(dataAdapter);
- spinnerCountry.setOnItemSelectedListener(new OnItemSelectedListener() {
- public void onItemSelected(AdapterView<?> parent, View arg1,
- int arg2, long arg3) {
- // TODO Auto-generated method stub
- // ((TextView)parent.getChildAt(0)).setTextSize(5);
- Log.i("Spinner Choose", list.get(arg2).getCountryNameFull()
- + " = " + list.get(arg2).getCountryNameShort());
- shortCountryName = list.get(arg2).getCountryNameShort();
- }
- public void onNothingSelected(AdapterView<?> arg0) {
- // TODO Auto-generated method stub
- }
- });
- }
- public void registerState(boolean state , String message) {
- if (state) {
- registerSuccess(message);
- } else if (!state) {
- Util.showAlertDialog(message, RegisterActivity.this);
- }
- }
- private void registerSuccess(String message) {
- final Dialog dialog = new Dialog(RegisterActivity.this);
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- dialog.setContentView(R.layout.kglay_alert);
- TextView tvMessage = (TextView) dialog.findViewById(R.id.tvAlertMessage);
- tvMessage.setText(message);
- Button btnOK = (Button) dialog.findViewById(R.id.btnAlertOK);
- btnOK.setText("Login");
- btnOK.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- dialog.dismiss();
- // Toast.makeText(ctx, text, Toast.LENGTH_LONG)
- Intent it = new Intent(getApplicationContext(),
- LoginActivity.class);
- it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(it);
- }
- });
- dialog.show();
- }
- // public void showErrorAlertDialog(String Message) {
- // final Dialog dialog = new Dialog(RegisterActivity.this);
- // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- // dialog.setContentView(R.layout.kglay_alert);
- //
- // TextView message = (TextView) dialog.findViewById(R.id.tvAlertMessage);
- // message.setText("Fail !.");
- //
- // Button btnOK = (Button) dialog.findViewById(R.id.btnAlertOK);
- //
- // btnOK.setOnClickListener(new OnClickListener() {
- // @Override
- // public void onClick(View v) {
- // dialog.dismiss();
- // // Toast.makeText(ctx, text, Toast.LENGTH_LONG)
- // }
- // });
- //
- // dialog.show();
- // }
- private void detectKeyboard() {
- final View activityRootView = findViewById(R.id.registerActivityLayout);
- activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- Rect r = new Rect();
- //r will be populated with the coordinates of your view that area still visible.
- activityRootView.getWindowVisibleDisplayFrame(r);
- int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
- if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
- //... do something here
- Log.i("Kglay","Keyboard showing ...");
- backgroundView.setVisibility(View.GONE);
- }
- else {
- backgroundView.setVisibility(View.VISIBLE);
- }
- }
- });
- }
- private TextWatcher filterTextWatcher = new TextWatcher() {
- public void afterTextChanged(Editable s) {
- isvalidMessage_tv.setVisibility(View.VISIBLE);
- if(Util.isEmailValid(s.toString())){
- isvalidMessage_tv.setTextColor(Color.GREEN);
- isvalidMessage_tv.setText("Valid email address");
- }else{
- isvalidMessage_tv.setTextColor(Color.RED);
- isvalidMessage_tv.setText("Invalid email address");
- }
- }
- public void beforeTextChanged(CharSequence s, int start, int count,
- int after) {
- }
- public void onTextChanged(CharSequence s, int start, int before,
- int count) {
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement