Android Open Source - MentorMe Edit Profile Location Fragment






From Project

Back to project page MentorMe.

License

The source code is released under:

MIT License

If you think the Android project MentorMe listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.codepath.wwcmentorme.fragments;
/*from   w  w  w .  ja  v a  2 s.  co m*/
import android.location.Address;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

import com.codepath.wwcmentorme.R;
import com.codepath.wwcmentorme.helpers.Async;
import com.codepath.wwcmentorme.helpers.Utils;
import com.codepath.wwcmentorme.models.User;
import com.parse.ParseGeoPoint;

public class EditProfileLocationFragment extends AbstractEditProfileFragment {  
  private EditText etAddress;
  private EditText etAboutme;
  private Button btnGoToStep2;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_edit_profile_location, container, false);
    setupViews(v);
    return v;
  }
    
  private void setupViews(View v) {
    v.setFocusableInTouchMode(true);
    v.requestFocus();
    // Suppress back button for this fragment.
    v.setOnKeyListener(new OnKeyListener() {
      @Override
      public boolean onKey(View v, int keyCode, KeyEvent event) {
        if( keyCode == KeyEvent.KEYCODE_BACK)
        {
          return true;
        }
        return false;
      }
    });
    etAddress = (EditText) v.findViewById(R.id.etAddress);
    etAboutme = (EditText) v.findViewById(R.id.etAboutme);
    btnGoToStep2 = (Button) v.findViewById(R.id.btnGoToStep2);
    OnEditorActionListener listener = new OnEditorActionListener() {
      @Override
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT) {
          saveUserData();
        }
        return false;
      }
    };
    etAddress.setOnEditorActionListener(listener);
  }
  
  @Override
  protected void updateProfile(final User profileUser) {
    if (etAddress.getText() != null) {
      profileUser.setAddress(etAddress.getText().toString().trim());
      profileUser.setAboutMe(etAboutme.getText().toString().trim());
      Utils.geocode(getActivity(), new Utils.LocationParams(etAddress.getText().toString()), new Async.Block<Address>() {
        @Override
        public void call(final Address address) {
          if (address != null) {
            profileUser.setLocation(new ParseGeoPoint(address.getLatitude(), address.getLongitude()));
          }
        }
      });
    }
  }

  @Override
  void updateViews(User profileUser) {
    etAddress.setText(profileUser.getAddress());
    etAboutme.setText(profileUser.getAboutMe());
  }
  
  @Override 
  public void validateInputs(final Async.Block<View> invalidView) {
    View view = null;
    if (TextUtils.getTrimmedLength(etAddress.getText().toString()) == 0) view = etAddress;
    if (view == null && TextUtils.getTrimmedLength(etAboutme.getText().toString()) == 0) view = etAboutme;
    if (view == null) {
      Utils.geocode(getActivity(), new Utils.LocationParams(etAddress.getText().toString()), new Async.Block<Address>() {
        @Override
        public void call(final Address address) {
          if (address == null) {
            invalidView.call(etAddress);
          } else {
            invalidView.call(null);
          }
        }
      });
    } else {
      invalidView.call(view);
    }
  }
}




Java Source Code List

com.codepath.wwcmentorme.activities.AppActivity.java
com.codepath.wwcmentorme.activities.ChatActivity.java
com.codepath.wwcmentorme.activities.EditProfileActivity.java
com.codepath.wwcmentorme.activities.HomeActivity.java
com.codepath.wwcmentorme.activities.MapActivity.java
com.codepath.wwcmentorme.activities.MentorListActivity.java
com.codepath.wwcmentorme.activities.ThankMentorActivity.java
com.codepath.wwcmentorme.activities.UserListActivity.java
com.codepath.wwcmentorme.activities.ViewProfileActivity.java
com.codepath.wwcmentorme.adapters.ChatAdapter.java
com.codepath.wwcmentorme.adapters.DrawerListAdapter.java
com.codepath.wwcmentorme.adapters.MentorListAdapter.java
com.codepath.wwcmentorme.app.MentorMeApp.java
com.codepath.wwcmentorme.data.DataService.java
com.codepath.wwcmentorme.fragments.AbstractEditProfileFragment.java
com.codepath.wwcmentorme.fragments.EditProfileExperiencesFragment.java
com.codepath.wwcmentorme.fragments.EditProfileLocationFragment.java
com.codepath.wwcmentorme.fragments.EditProfileSkillsFragment.java
com.codepath.wwcmentorme.fragments.RefineResultsDialogFragment.java
com.codepath.wwcmentorme.helpers.Async.java
com.codepath.wwcmentorme.helpers.Constants.java
com.codepath.wwcmentorme.helpers.MentorMeReceiver.java
com.codepath.wwcmentorme.helpers.NotificationCenter.java
com.codepath.wwcmentorme.helpers.RoundedImageView.java
com.codepath.wwcmentorme.helpers.UIUtils.java
com.codepath.wwcmentorme.helpers.Utils.java
com.codepath.wwcmentorme.helpers.ViewHolder.java
com.codepath.wwcmentorme.models.Message.java
com.codepath.wwcmentorme.models.Rating.java
com.codepath.wwcmentorme.models.Request.java
com.codepath.wwcmentorme.models.User.java