Android Open Source - hitch-hiker Fragment_ Login






From Project

Back to project page hitch-hiker.

License

The source code is released under:

MIT License

If you think the Android project hitch-hiker 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 autostoppista.android.fragments;
//  w  w w.ja va  2  s.  c o  m
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import autostoppista.app.MainActivity;
import autostoppista.core.http.HTTPOutput;
import autostoppista.core.http.HTTPonCompleteListener;
import autostoppista.core.restcall.Login;
import autostoppista.core.restcall.UserInfo;
import autostoppista.core.restcall.RestCalls;
import autostoppista.app.R;

import com.google.gson.Gson;

public class Fragment_Login extends ExtendedFragment{
  private Button save, cancel;
  private EditText username, password;
  @Override
  public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.login_form,container, false);
    save = (Button) view.findViewById(R.id.login_button_save);
    cancel = (Button) view.findViewById(R.id.login_button_cancel);
    username = (EditText) view.findViewById(R.id.login_userName);
    password = (EditText) view.findViewById(R.id.login_password);
    save.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View arg0) {
        RestCalls.getProfileInfo(cfi,
        new HTTPonCompleteListener() {
          @Override
          public void onComplete(HTTPOutput r) {
            if (r.getCode()>=400){
              setWaitMode(false);
              Toast.makeText(parent.getApplicationContext(),
                  "Si ? verificato un errore:\n"+r.getMessage(),
                  Toast.LENGTH_LONG).show();
            } else {
              if (!r.getData().contains("ERROR ")){
                setWaitMode(false);
                Gson js = new Gson();
                UserInfo prin = js.fromJson(r.getData(), UserInfo.class);
                
                Login l = new Login();
                l.setLoginInfo(username.getText().toString(),password.getText().toString());
                getLoginSaver().saveLoginData(l);
                getParent().Init();
                prin.setGCM_ID(parent.getGCM().getRegId());
                RestCalls.miSonoConnesso(parent.getGCM().getRegId(), null, null, l);
                getParent().setProfileInfo(prin);
                if (getRole().equalsIgnoreCase(RestCalls.PASSENGER)) {
                  getParent().switchFragment(Fragment_userMainpage.newAssignParent(parent));
                } else if (getRole().equalsIgnoreCase(RestCalls.DRIVER)) {
                  getParent().switchFragment(Fragment_userWaiting.newAssignParent(parent));
                } else {
                  Toast.makeText(parent.getApplicationContext(),
                      "Versione non supportata!",
                      Toast.LENGTH_LONG).show();
                }
              } else {
                Toast.makeText(parent.getApplicationContext(),
                  "Si ? verificato un errore:\n"+r.getData(),
                  Toast.LENGTH_LONG).show();
              }
            }
          }
        },
        new Login().setLoginInfo(username.getText().toString(), password.getText().toString()));
      }
    });
    cancel.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View arg0) {
        parent.closeApplication();        
      }
    });
    username.setText(getLoginSaver().getLoginData().getUsername());
    password.setText(getLoginSaver().getLoginData().getPassword());
    ll = (ViewGroup) view;
    setWaitMode(false);
    return view;
  }
  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
  }
  public static final Fragment_Login newAssignParent(MainActivity parent) {
    Fragment_Login fl = new Fragment_Login();
    fl.parent = parent;
    return fl;
  }
}




Java Source Code List

autostoppista.android.adapters.AdapterFeedbackItem.java
autostoppista.android.adapters.AdapterUserItem.java
autostoppista.android.adapters.ObservableCollection.java
autostoppista.android.fragments.ExtendedFragment.java
autostoppista.android.fragments.Fragment_Login.java
autostoppista.android.fragments.Fragment_feedbackForm.java
autostoppista.android.fragments.Fragment_userDetail.java
autostoppista.android.fragments.Fragment_userMainpage.java
autostoppista.android.fragments.Fragment_userWaiting.java
autostoppista.app.MainActivity.java
autostoppista.app.ModeUse.java
autostoppista.core.gcm.GCM.java
autostoppista.core.gcm.GcmBroadcastReceiver.java
autostoppista.core.gcm.Message.java
autostoppista.core.gps.GPSManager.java
autostoppista.core.gps.Position.java
autostoppista.core.http.HTTPAsyncBasic.java
autostoppista.core.http.HTTPAsync.java
autostoppista.core.http.HTTPCalls.java
autostoppista.core.http.HTTPInputBasic.java
autostoppista.core.http.HTTPInput.java
autostoppista.core.http.HTTPOutput.java
autostoppista.core.http.HTTPStartListener.java
autostoppista.core.http.HTTPonCompleteListener.java
autostoppista.core.restcall.FeedbackReturn.java
autostoppista.core.restcall.FeedbackSummary.java
autostoppista.core.restcall.LoginSaver.java
autostoppista.core.restcall.Login.java
autostoppista.core.restcall.RestCalls.java
autostoppista.core.restcall.UserInfo.java