Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.11 KB | None | 0 0
  1. package com.foxtrapp.mysmallcommunity.ui.activities;
  2.  
  3. import android.app.Activity;
  4. import android.app.ProgressDialog;
  5. import android.content.Intent;
  6. import android.graphics.Bitmap;
  7. import android.graphics.BitmapFactory;
  8. import android.graphics.Color;
  9. import android.net.Uri;
  10. import android.nfc.Tag;
  11. import android.os.AsyncTask;
  12. import android.os.Bundle;
  13. import android.support.annotation.Nullable;
  14. import android.support.v7.widget.Toolbar;
  15. import android.text.Editable;
  16. import android.text.TextWatcher;
  17. import android.util.Log;
  18. import android.view.KeyEvent;
  19. import android.view.LayoutInflater;
  20. import android.view.MenuItem;
  21. import android.view.View;
  22. import android.view.ViewGroup;
  23. import android.view.Window;
  24. import android.view.WindowManager;
  25. import android.widget.AdapterView;
  26. import android.widget.ArrayAdapter;
  27. import android.widget.Button;
  28. import android.widget.EditText;
  29. import android.widget.Spinner;
  30. import android.widget.TextView;
  31. import android.widget.Toast;
  32.  
  33. import com.foxtrapp.mysmallcommunity.R;
  34. import com.foxtrapp.mysmallcommunity.api.ErrorHandler;
  35. import com.foxtrapp.mysmallcommunity.api.RetrofitAdapter;
  36. import com.foxtrapp.mysmallcommunity.base.BaseActivity;
  37. import com.foxtrapp.mysmallcommunity.global.Constants;
  38. import com.foxtrapp.mysmallcommunity.global.Tags;
  39. import com.foxtrapp.mysmallcommunity.interfaces.PhotoChooser;
  40. import com.foxtrapp.mysmallcommunity.models.APIModel.FormRegistrationError;
  41. import com.foxtrapp.mysmallcommunity.models.ErrorField;
  42. import com.foxtrapp.mysmallcommunity.ui.errors.ErrorsShower;
  43. import com.foxtrapp.mysmallcommunity.ui.fragments.dialog_fragment.ChooseDialogFragment;
  44. import com.foxtrapp.mysmallcommunity.utilities.KeyBoard;
  45. import com.foxtrapp.mysmallcommunity.utilities.PhotoUploadManager;
  46. import com.foxtrapp.mysmallcommunity.utilities.RquestBodyConvertor;
  47. import com.foxtrapp.mysmallcommunity.utilities.TokenProvider;
  48. import com.foxtrapp.mysmallcommunity.utilities.Waiters;
  49. import com.foxtrapp.mysmallcommunity.utility.CameraUntil;
  50. import com.foxtrapp.mysmallcommunity.utility.StreamContent;
  51. import com.nvanbenschoten.motion.ParallaxImageView;
  52.  
  53. import java.util.ArrayList;
  54. import java.util.List;
  55.  
  56. import de.hdodenhof.circleimageview.CircleImageView;
  57. import okhttp3.MediaType;
  58. import okhttp3.MultipartBody;
  59. import okhttp3.RequestBody;
  60. import retrofit2.Call;
  61. import retrofit2.Callback;
  62. import retrofit2.Response;
  63.  
  64.  
  65. /**
  66.  * Created by root on 26/12/16.
  67.  */
  68.  
  69. public class RegisterByEmailActivity extends BaseActivity implements PhotoChooser {
  70.     Button confirm;
  71.     EditText firstName;
  72.     EditText familyName;
  73.     EditText email;
  74.     EditText password;
  75.     EditText confirmPassword;
  76.     TextView errorFirstName, errorFamilyName, errorEmail, errorPassword, errorConfirmPassword, errorGender;
  77.     Spinner gender;
  78.     CircleImageView profilePicture;
  79.     private ProgressDialog progressDialog;
  80.     ParallaxImageView mBackground;
  81.     boolean firstTime = true;
  82.  
  83.  
  84.     boolean firstNameV = false, familyNameV = false,
  85.             emailValid = false, passwordValid = false,
  86.             confirmPasswordValid = false, genderValid = false;
  87.     private Callback<Object> registerCallBack;
  88.     private Uri uri;
  89.     private Bitmap mBitmap;
  90.     private boolean myFirst = true;
  91.  
  92.     @Override
  93.     protected void onPause() {
  94.         super.onPause();
  95.         mBackground.unregisterSensorManager();
  96.     }
  97.  
  98.     @Override
  99.     public void onCreate(@Nullable Bundle savedInstanceState) {
  100.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  101.         this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  102.         super.onCreate(savedInstanceState);
  103.  
  104.         setContentView(R.layout.register_by_email);
  105.         Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
  106.         myToolbar.setTitle("");
  107.         setSupportActionBar(myToolbar);
  108.         android.support.v7.app.ActionBar bar = getSupportActionBar();
  109.         bar.setDisplayShowCustomEnabled(true);
  110.         bar.setDisplayHomeAsUpEnabled(true);
  111.         findUI();
  112.         setEvents();
  113.  
  114.  
  115.  
  116.     }
  117.  
  118.     @Override
  119.     protected void onResume() {
  120.         super.onResume();
  121.  
  122. // Register a SensorManager to begin effect
  123.         mBackground.registerSensorManager();
  124.     }
  125.  
  126.     private void findUI() {
  127.         confirm = (Button) findViewById(R.id.confirm);
  128.         firstName = (EditText) findViewById(R.id.first_name);
  129.         familyName = (EditText) findViewById(R.id.family_name);
  130.         email = (EditText) findViewById(R.id.email);
  131.         password = (EditText) findViewById(R.id.password);
  132.         confirmPassword = (EditText) findViewById(R.id.confirm_password);
  133.         gender = $(R.id.gender);
  134.         profilePicture = (CircleImageView) findViewById(R.id.ivUserPhoto);
  135.         progressDialog = Waiters.getProgressDialoge(this);
  136.         mBackground = $(R.id.background_image);
  137.         errorFirstName = $(R.id.error_first_name);
  138.         errorFamilyName = $(R.id.error_family_name);
  139.         errorEmail = $(R.id.error_email);
  140.         errorPassword = $(R.id.error_password);
  141.         errorConfirmPassword = $(R.id.error_confirm_password);
  142.         errorGender = $(R.id.error_gender);
  143.         List<SpinnerItem> items = new ArrayList<SpinnerItem>();
  144.         items.add(new SpinnerItem("Gender"));
  145.         items.add(new SpinnerItem("Male"));
  146.         items.add(new SpinnerItem("Female"));
  147.  
  148.         SpinnerHintAdapter adapter = new SpinnerHintAdapter(this,R.id.gender, R.id.main_text, items, gender);
  149.         adapter.setDropDownViewResource(R.layout.gender_drop_down_item);
  150.         gender.setAdapter(adapter);
  151.         gender.setSelection(0);
  152.         confirm.setTransformationMethod(null);
  153.         password.setTypeface(email.getTypeface());
  154.         confirmPassword.setTypeface(email.getTypeface());
  155.         checkConfirmValidity();
  156.  
  157.  
  158.     }
  159.     void checkFirstName(boolean hasFocus){
  160.         String err = "";
  161.         if (!hasFocus) {
  162.             if (firstName.getText().length() < Constants.F_NAME_MIN_LENGTH) {
  163.                 firstNameV = false;
  164.                 err = "First name is too short";
  165.             } else if (firstName.getText().length() > Constants.F_NAME_MAX_LENGTH) {
  166.                 firstNameV = false;
  167.                 err = "Family name is too long";
  168.             } else
  169.                 firstNameV = true;
  170.         }
  171.         ErrorsShower.setError(this,firstName, errorFirstName, err);
  172.         checkConfirmValidity();
  173.     }
  174.     private void setEvents() {
  175.         firstName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  176.             @Override
  177.             public void onFocusChange(View v, boolean hasFocus) {
  178.                 checkFirstName(hasFocus);
  179.             }
  180.         });
  181.         familyName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  182.             @Override
  183.             public void onFocusChange(View v, boolean hasFocus) {
  184.                 checkFamilyName(hasFocus);
  185.             }
  186.         });
  187.         email.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  188.             @Override
  189.             public void onFocusChange(View v, boolean hasFocus) {
  190.                 checkEmail(hasFocus);
  191.             }
  192.         });
  193.         password.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  194.             @Override
  195.             public void onFocusChange(View v, boolean hasFocus) {
  196.                 checkPassword(hasFocus);
  197.             }
  198.         });
  199.         confirmPassword.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  200.             @Override
  201.             public void onFocusChange(View v, boolean hasFocus) {
  202.                checkConfirmPassword(hasFocus);
  203. //                KeyBoard.hideKeyboard();
  204.             }
  205.         });
  206.         confirmPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  207.             @Override
  208.             public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  209.                 checkConfirmPassword(false);
  210.                 checkConfirmValidity();
  211.                 return false;
  212.             }
  213.         });
  214.         confirmPassword.addTextChangedListener(new TextWatcher() {
  215.             @Override
  216.             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  217.  
  218.             }
  219.  
  220.             @Override
  221.             public void onTextChanged(CharSequence s, int start, int before, int count) {
  222.  
  223.             }
  224.  
  225.             @Override
  226.             public void afterTextChanged(Editable s) {
  227.                 checkConfirmPassword(false);
  228.                 checkConfirmValidity();
  229.             }
  230.         });
  231.  
  232.  
  233.  
  234.         gender.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  235.             @Override
  236.             public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  237.                 checkGender(position);
  238.                 Log.i(Tags.byEmail, "on item slected");;
  239.                 if(position == 0 && !firstTime){
  240.                     gender.setBackground(getResources().getDrawable(R.drawable.red_rounded_text_field));
  241.                     if(view != null){
  242.                         Log.i(Tags.byEmail, "setting the text:" + ((SpinnerItem)gender.getSelectedItem()).getName());
  243.                         ((TextView)view).setText(((SpinnerItem)gender.getSelectedItem()).getName());
  244.                     }
  245.                 }
  246.                 else{
  247.                     gender.setBackground(getResources().getDrawable(R.drawable.normal_rounded_text_field));
  248.                     Log.i(Tags.byEmail, "setting the text2:"+((SpinnerItem)gender.getSelectedItem()).getName());
  249.                     if(view != null) {
  250.                         ((TextView) view).setText(((SpinnerItem) gender.getSelectedItem()).getName());
  251.                     }
  252.  
  253.                 }
  254.                 firstTime = false;
  255.             }
  256.  
  257.             @Override
  258.             public void onNothingSelected(AdapterView<?> parent) {
  259.             }
  260.         });
  261.  
  262.         confirm.setOnClickListener(new View.OnClickListener() {
  263.             @Override
  264.             public void onClick(View v) {
  265.                 firstTime = false;
  266.                 confirmPasswordValid = confirmPassword.getText().toString().equals(password.getText().toString());
  267.                 if (firstNameV && familyNameV && emailValid && passwordValid && confirmPasswordValid && genderValid) {
  268.                     RegisterByEmailActivity.this.login();
  269.                 } else {
  270.                     Toast.makeText(RegisterByEmailActivity.this, getResources().getString(R.string.validation_err_msg), Toast.LENGTH_LONG).show();
  271.                     checkFirstName(false);
  272.                     checkFamilyName(false);
  273.                     checkEmail(false);
  274.                     checkPassword(false);
  275.                     checkConfirmPassword(false);
  276.                     checkGender(gender.getSelectedItemPosition());
  277.  
  278.                 }
  279.             }
  280.         });
  281.         profilePicture.setOnClickListener(new View.OnClickListener() {
  282.             @Override
  283.             public void onClick(View v) {
  284.                 openPhotoDialog();
  285.             }
  286.         });
  287.         registerCallBack = new Callback<Object>() {
  288.             @Override
  289.             public void onResponse(Call<Object> call, Response<Object> response) {
  290.                 progressDialog.dismiss();
  291.                 Log.i(Tags.byEmail, "code = " + response.code());
  292.                 if (response.isSuccessful()) {
  293.                     Log.i(Tags.byEmail, "the user has been registered");
  294.                     Toast.makeText(RegisterByEmailActivity.this, getResources().getString(R.string.register_msg), Toast.LENGTH_LONG).show();
  295.                     goToLogin();
  296.                     finish();
  297.                 } else if (response.code() == 400) {
  298.                     FormRegistrationError errors = ErrorHandler.getErrors(response.errorBody());
  299.                     applyErrors(errors);
  300.                 }
  301.             }
  302.  
  303.             @Override
  304.             public void onFailure(Call<Object> call, Throwable t) {
  305.                 progressDialog.dismiss();
  306.             }
  307.         };
  308.     }
  309.  
  310.     void applyErrors(FormRegistrationError errors){
  311.         for(ErrorField error: errors.getData()){
  312.             Log.i(Tags.byEmail, "error = " + error.getErrorMessage());
  313.             switch (error.getFieldName()){
  314.                 case "firstName":
  315.                     ErrorsShower.setError(this,firstName, errorFirstName, error.getErrorMessage());
  316.                     break;
  317.                 case "lastName":
  318.                     ErrorsShower.setError(this,familyName, errorFamilyName, error.getErrorMessage());
  319.                     break;
  320.                 case "gender":
  321.                     break;
  322.                 case "email":
  323.                     ErrorsShower.setError(this,email, errorEmail, error.getErrorMessage());
  324.                     break;
  325.                 case "deviceToken":
  326.                     break;
  327.                 case "password":
  328.                     ErrorsShower.setError(this,password, errorPassword, error.getErrorMessage());
  329.                     break;
  330.                 case "confirmPassword":
  331.                     break;
  332.                 case "post_image":
  333.                     break;
  334.                 default:
  335.                     Toast.makeText(this, error.getErrorMessage(), Toast.LENGTH_LONG).show();
  336.                     break;
  337.             }
  338.         }
  339.     }
  340.     private void checkConfirmValidity() {
  341.         if(emailValid && passwordValid && confirmPasswordValid && firstNameV && familyNameV){
  342.             confirm.setAlpha(Constants.FULL_ALPHA);
  343.             return;
  344.         }
  345.         confirm.setAlpha(Constants.DISABLED_BUTTON_ALPHA);
  346.     }
  347.     private void checkGender(int position) {
  348.         if(firstTime){
  349.             return;
  350.         }
  351.         if(position == 0){
  352.             Log.i(Tags.byEmail, "position= " + position);
  353.             Log.i(Tags.byEmail, "checkinng the gender");
  354.             gender.setBackground(getResources().getDrawable(R.drawable.red_rounded_text_field));
  355.             errorGender.setText("Gender can not be empty");
  356.             errorGender.setVisibility(View.VISIBLE);
  357.             genderValid = false;
  358.             return;
  359.         }
  360.         gender.setBackground(getResources().getDrawable(R.drawable.normal_rounded_text_field));
  361.         errorGender.setVisibility(View.GONE);
  362.         genderValid = true;
  363.         checkConfirmValidity();
  364.     }
  365.  
  366.     private void checkConfirmPassword(boolean hasFocus) {
  367.         String err = "";
  368.         Log.i(Tags.byEmail, "inside on focus");
  369.             if (!confirmPassword.getText().toString().equals(password.getText().toString())) {
  370.                 err = "The two passwords should be identical";
  371.                 confirmPasswordValid = false;
  372.             } else
  373.                 confirmPasswordValid = true;
  374.         ErrorsShower.setError(this,confirmPassword, errorConfirmPassword, err);
  375.         checkConfirmValidity();
  376.  
  377.     }
  378.  
  379.     private void checkPassword(boolean hasFocus) {
  380.         String err = "";
  381.         if (!hasFocus) {
  382.             if (password.getText().length() < Constants.PASSWORD_MIN_LENGTH) {
  383.                 err = "the new password is too short";
  384.                 passwordValid = false;
  385.             } else
  386.                 passwordValid = true;
  387.         }
  388.         ErrorsShower.setError(this,password, errorPassword, err);
  389.         checkConfirmValidity();
  390.  
  391.     }
  392.  
  393.     private void checkEmail(boolean hasFocus) {
  394.         if (!hasFocus) {
  395.             emailValid = android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText()).matches();
  396.             ErrorsShower.setError(this,email, errorEmail, emailValid ? "" : "Email is not valid email addressret");
  397.         }
  398.         checkConfirmValidity();
  399.     }
  400.  
  401.     private void checkFamilyName(boolean hasFocus) {
  402.         String err = "";
  403.         if (!hasFocus) {
  404.             Log.i(Tags.byEmail, "something could be changed");
  405.             if (familyName.getText().length() < Constants.F_NAME_MIN_LENGTH) {
  406.                 err = "Family name is too short";
  407.                 familyNameV = false;
  408.             } else if (familyName.getText().length() > Constants.F_NAME_MAX_LENGTH) {
  409.                 err = "Family name is too long";
  410.                 familyNameV = false;
  411.             } else
  412.                 familyNameV = true;
  413.         }
  414.         ErrorsShower.setError(this,familyName, errorFamilyName, err);
  415.         checkConfirmValidity();
  416.     }
  417.  
  418.     private void goToLogin() {
  419.         Intent intent = new Intent(this, LoginByEmailActivity.class);
  420.         String emailValue = email.getText().toString();
  421.         String passwordValue = password.getText().toString();
  422.         intent.putExtra("email", emailValue);
  423.         intent.putExtra("password", passwordValue );
  424.         startActivity(intent);
  425.     }
  426.  
  427.     private void login() {
  428.         registerBackground();
  429.     }
  430.     private void registerBackground() {
  431.             new AsyncTask<Void,String,String>() {
  432.                 @Override
  433.                 protected String doInBackground(Void... params) {
  434.                     try {
  435.                         return TokenProvider.getToken(RegisterByEmailActivity.this);
  436.                     }
  437.                     catch (Exception e){
  438.                         e.printStackTrace();
  439.                         return "";
  440.                     }
  441.                 }
  442.  
  443.                 @Override
  444.                 protected void onPostExecute(String token) {
  445.                     sendUserData(token);
  446.                 }
  447.             }.execute(null, null, null);
  448.         }
  449.     private void openPhotoDialog(){
  450.         Bundle bundle = new Bundle();
  451. //        bundle.putString("type", "event");
  452.         uri = CameraUntil.getOutputMediaFileUri(CameraUntil.MEDIA_TYPE_IMAGE);
  453.         bundle.putParcelable(Constants.PHOTO_URI, uri);
  454.         ChooseDialogFragment dialog = new ChooseDialogFragment();
  455.         dialog.setArguments(bundle);
  456.         dialog.show(getSupportFragmentManager(), "Choose");
  457.         KeyBoard.hideKeyboard(this);
  458.     }
  459.     @Override
  460.     public void onActivityResult(int requestCode, int resultCode, Intent data) {
  461.         super.onActivityResult(requestCode, resultCode, data);
  462.         if(resultCode == Activity.RESULT_OK){
  463.             if(requestCode == Constants.REQUEST_CAMERA){
  464.                 Log.i(Tags.byEmail, "requesting the camera");
  465.                 Log.i(Tags.byEmail, "uri = " + uri.getPath());
  466.                 Intent intent = new Intent(this, CropActivity.class);
  467.                 intent.putExtra(Constants.TYPE, Constants.CAMERA_CAPTURE);
  468.                 intent.putExtra(Constants.PHOTO_URI, uri);
  469.                 intent.putExtra(Constants.FORM_CROPS, Constants.CIRCLE);
  470.                 startActivityForResult(intent,Constants.PIC_CROP);
  471.             } else if(requestCode == Constants.SELECT_PHOTO){
  472.                 Intent intent = new Intent(this, CropActivity.class);
  473. //                Uri selectedImage = data.getData();
  474.                 String chosenPhotoPath = PhotoUploadManager.getChosenPhoto(data, this);
  475.                 if(chosenPhotoPath == null)
  476.                     return;
  477.                 uri = Uri.parse(chosenPhotoPath);
  478.                 Log.i(Tags.byEmail, "uri = "  + uri);
  479.                 intent.putExtra(Constants.TYPE, Constants.SELECT_PHOTO);
  480.                 intent.putExtra(Constants.PHOTO_URI, uri);
  481.                 intent.putExtra(Constants.FORM_CROPS, Constants.SQUARE);
  482.                 startActivityForResult(intent, Constants.PIC_CROP);
  483.             }else if(requestCode == Constants.PIC_CROP){
  484.                 uri = data.getParcelableExtra(Constants.URI_DATA);
  485.                 mBitmap =BitmapFactory.decodeFile(uri.getPath());
  486.                 profilePicture.setImageBitmap(mBitmap);
  487.             }
  488.         }
  489.     }
  490.  
  491.     @Override
  492.     public void choose() {
  493.         PhotoUploadManager.openSinglePhoto(this);
  494.     }
  495.  
  496.     public void sendUserData(String tokenS){
  497.         progressDialog.show();
  498.         RequestBody fName = RquestBodyConvertor.String2RequestBody(firstName.getText().toString());
  499.         RequestBody token = RquestBodyConvertor.String2RequestBody(tokenS);
  500.         RequestBody lName = RquestBodyConvertor.String2RequestBody(familyName.getText().toString());
  501.         RequestBody pass = RquestBodyConvertor.String2RequestBody(password.getText().toString());
  502.         RequestBody gen = RquestBodyConvertor.String2RequestBody(((SpinnerItem)gender.getSelectedItem()).getName().toString().toLowerCase());
  503.         RequestBody mail = RquestBodyConvertor.String2RequestBody(email.getText().toString());
  504.         MultipartBody.Part body = null;
  505.         if(mBitmap != null){
  506.             StreamContent s = new StreamContent(mBitmap);
  507.             final RequestBody requestFile =
  508.                     RequestBody.create(MediaType.parse("multipart/form-data"), s.getInputStream());
  509.             body =
  510.                     MultipartBody.Part.createFormData("post_image", "test.jpg", requestFile);
  511.  
  512.         }
  513.  
  514.         RetrofitAdapter.getInterface().registerUserByEmail(
  515.                 fName,
  516.                 lName,
  517.                 gen,
  518.                 mail,
  519.                 token,
  520.                 pass,
  521.                 pass,
  522.                 body
  523.         ).enqueue(registerCallBack);
  524.     }
  525.  
  526.     @Override
  527.     public boolean onOptionsItemSelected(MenuItem item) {
  528.         int id = item.getItemId();
  529.  
  530.         if (id == android.R.id.home) {
  531.             onBackPressed();
  532.             return true;
  533.         }
  534.  
  535.         return super.onOptionsItemSelected(item);
  536.     }
  537.  
  538.  
  539.  
  540. }
  541.  
  542. class SpinnerItem {
  543.     public SpinnerItem(String name){
  544.         this.name = name;
  545.     }
  546.     public String getName(){
  547.         return name;
  548.     }
  549.     String name;
  550.  
  551.     public void setName(String name) {
  552.         this.name = name;
  553.     }
  554. }
  555.  class SpinnerHintAdapter extends ArrayAdapter<SpinnerItem> {
  556.  
  557.      LayoutInflater flater;
  558.      List<SpinnerItem> items;
  559.      boolean firstTime = true;
  560.      Spinner gender;
  561.  
  562.      public SpinnerHintAdapter(Activity context, int resourceId, int textViewId, List<SpinnerItem> list, Spinner parent){
  563.  
  564.         super(context,resourceId,textViewId, list);
  565.         flater = context.getLayoutInflater();
  566.         this.items = list;
  567.         this.gender = parent;
  568.  
  569.     }
  570.  
  571.      @Override
  572.      public int getCount() {
  573.          return items.size();
  574.      }
  575.  
  576.      @Nullable
  577.      @Override
  578.      public SpinnerItem getItem(int position) {
  579.          return items.get(position);
  580.      }
  581.  
  582.      @Override
  583.      public long getItemId(int position) {
  584.          return position;
  585.      }
  586.  
  587.      @Override
  588.     public View getView(int position, View convertView, ViewGroup parent) {
  589.          SpinnerItem spinnerItem = getItem(position);
  590.          View rowView = flater.inflate(R.layout.gender_item ,null,true);
  591.          TextView txtTitle = (TextView) rowView.findViewById(R.id.main_text);
  592.          txtTitle.setText(spinnerItem.getName());
  593.          txtTitle.setTextColor(txtTitle.getResources().getColor(R.color.color_white));
  594.          Log.i(Tags.byEmail, "*****"+ spinnerItem.getName());
  595.          gender.setVisibility(View.VISIBLE);
  596.          return rowView;
  597.     }
  598.  
  599.  
  600.      @Override
  601.      public View getDropDownView(int position, View convertView, ViewGroup parent) {
  602.          firstTime = false;
  603.          SpinnerItem rowItem = getItem(position);
  604.          View rowView = flater.inflate(R.layout.gender_drop_down_item ,null,true);
  605.          TextView txtTitle = (TextView) rowView.findViewById(R.id.drop_down_text);
  606.          txtTitle.setText(rowItem.getName());
  607.          if(!isEnabled(position)){
  608.              txtTitle.setBackground(txtTitle.getResources().getDrawable(R.drawable.normal_rounded_text_field));
  609.              txtTitle.setTextColor(Color.parseColor("#777777"));
  610.          }
  611. //         TextView selectedItem = (TextView) gender.getSelectedView();
  612. //         selectedItem.setBackground(null);
  613. //         gender.setBackground(null);
  614. //         selectedItem.setText("");
  615. //         Log.i(Tags.byEmail, "====" + rowItem.getName());
  616.          parent.setBackground(parent.getResources().getDrawable(R.drawable.normal_rounded_text_field));
  617.          txtTitle.setEnabled(isEnabled(position));
  618.          gender.setVisibility(View.INVISIBLE);
  619.          return rowView;
  620.      }
  621.  
  622.      @Override
  623.      public boolean isEnabled(int position) {
  624.          if(position == 0)
  625.              return false;
  626.          return super.isEnabled(position);
  627.      }
  628.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement