Android Open Source - location-sharing-android Fragment3






From Project

Back to project page location-sharing-android.

License

The source code is released under:

MIT License

If you think the Android project location-sharing-android 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 lv.lu.locationsharing;
/*from w  w w . j  a  v a2s.  c o  m*/
import java.util.ArrayList;

import lv.lu.locationsharing.application.LocationApplication;
import lv.lu.locationsharing.model.Friend;
import lv.lu.locationsharing.model.InviteFriends;
import lv.lu.locationsharing.requests.friends.InviteFriendsRequest;

import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.ResourceAccessException;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockFragment;
import com.octo.android.robospice.JacksonSpringAndroidSpiceService;
import com.octo.android.robospice.SpiceManager;
import com.octo.android.robospice.persistence.DurationInMillis;
import com.octo.android.robospice.persistence.exception.SpiceException;
import com.octo.android.robospice.request.listener.RequestListener;

public class Fragment3 extends SherlockFragment {
  protected SpiceManager spiceManager;
  protected LocationApplication mApp;
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment3, container, false);
    
    return rootView;
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mApp = (LocationApplication) getActivity().getApplication();
    spiceManager = new SpiceManager(JacksonSpringAndroidSpiceService.class);
    
    getView().findViewById(R.id.invite_button).setOnClickListener(
                 new View.OnClickListener() {
                         @Override
                         public void onClick(View view) {  
                                 inviteFriend(((EditText)getView().findViewById(R.id.email)).getText().toString(),mApp.getConfig().getUserToken());
                         }
                 });
    
  }
  
  @Override
  public void onStart() {
    super.onStart();
    spiceManager.start(getActivity());
  }

  
  public void inviteFriend(String mail, String userToken) {
    spiceManager.execute(new InviteFriendsRequest(getActivity(), mail, userToken),
        MainActivity.GET_FRIENDS_CACHE_KEY,
        DurationInMillis.ONE_MINUTE, new AuthenticationListener());
  }
  
  @Override
  public void onStop() {
    if (spiceManager.isStarted()) {
      spiceManager.shouldStop();
    }
    super.onStop();
  }
  
  // inner class of your spiced Activity
  private class AuthenticationListener implements RequestListener<InviteFriends> {

    private ArrayList<Friend> list;

    @Override
    public void onRequestFailure(SpiceException spiceException) {

      if (spiceException.getCause() instanceof HttpClientErrorException) {
        HttpClientErrorException cause = (HttpClientErrorException) spiceException
            .getCause();

        switch (Integer.valueOf(cause.getStatusCode().toString())) {
        case 401:
          Toast.makeText(getActivity(), "Neizdev?s uzaicin?t draugu", Toast.LENGTH_LONG).show();
          break;

        default:
          break;
        }
      } else if (spiceException.getCause() instanceof ResourceAccessException) {
                inviteFriend(((EditText)getView().findViewById(R.id.email)).getText().toString(),mApp.getConfig().getUserToken());
      }
      //showProgress(false);
    }

    @Override
    public void onRequestSuccess(InviteFriends authentication) {
      Log.v("Tag", "success");

      Toast.makeText(getActivity(), "Uzaicin?jums veiksm?gs", Toast.LENGTH_LONG).show();


    }
  }

  

}




Java Source Code List

lv.lu.locationsharing.Fragment1.java
lv.lu.locationsharing.Fragment2.java
lv.lu.locationsharing.Fragment3.java
lv.lu.locationsharing.Fragment4.java
lv.lu.locationsharing.Fragment5.java
lv.lu.locationsharing.LocationBroadcastReceiver.java
lv.lu.locationsharing.LoginActivity.java
lv.lu.locationsharing.MainActivity.java
lv.lu.locationsharing.MenuListAdapter.java
lv.lu.locationsharing.SignUpActivity.java
lv.lu.locationsharing.application.LocationApplication.java
lv.lu.locationsharing.config.Config.java
lv.lu.locationsharing.listview.adapter.RequestAdapter.java
lv.lu.locationsharing.model.AuthenticationStatus.java
lv.lu.locationsharing.model.Friend.java
lv.lu.locationsharing.model.GetFriends.java
lv.lu.locationsharing.model.InviteFriends.java
lv.lu.locationsharing.model.LocationPostStatus.java
lv.lu.locationsharing.model.Registration.java
lv.lu.locationsharing.requests.authentication.AuthenticationRequest.java
lv.lu.locationsharing.requests.authentication.AuthenticationStatusRequest.java
lv.lu.locationsharing.requests.friends.ConfirmFriendRequest.java
lv.lu.locationsharing.requests.friends.GetFriendsRequest.java
lv.lu.locationsharing.requests.friends.InviteFriendsRequest.java
lv.lu.locationsharing.requests.friends.PostLogout.java
lv.lu.locationsharing.requests.location.PostLocationUpdate.java
lv.lu.locationsharing.requests.registration.RegistrationRequest.java
lv.lu.locationsharing.utils.Constants.java
lv.lu.locationsharing.utils.Installation.java
lv.lu.locationsharing.utils.Url.java
lv.lu.locationsharing.utils.Utils.java