Android Open Source - hitch-hiker Main Activity






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.app;
//from ww w . jav  a  2  s . com
import java.util.ArrayList;

import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.Menu;
import autostoppista.android.fragments.ExtendedFragment;
import autostoppista.android.fragments.Fragment_Login;
import autostoppista.android.fragments.Fragment_userDetail;
import autostoppista.android.fragments.Fragment_userWaiting;
import autostoppista.core.gcm.GCM;
import autostoppista.core.gcm.GcmBroadcastReceiver;
import autostoppista.core.gps.GPSManager;
import autostoppista.core.gps.Position;
import autostoppista.core.restcall.Login;
import autostoppista.core.restcall.LoginSaver;
import autostoppista.core.restcall.UserInfo;
import autostoppista.core.restcall.RestCalls;

public class MainActivity extends Activity{
  protected Login l;
  protected LoginSaver ls;
  protected GPSManager gps;
  protected UserInfo prin;
  protected ModeUse mode;
  private ArrayList<String> ids = new ArrayList<String>();
  private GCM a;
  public static boolean IsRunning = false;
  private ExtendedFragment actualFragment = Fragment_Login.newAssignParent(this);
  public Login getLogin() {
    return l;
  }
  public void clearListIDs() {
    ids.clear();
  }
  public ArrayList<String> getListIDs() {
    return  ids;
  }
  public Position getPosition() {
    return gps.getPosition();
  }
  public LoginSaver getLoginSaver() {
    return ls;
  }
  public String getRole() {
    return prin.getRole();
  }
  public UserInfo getProfileInfo() {
    return prin;
  }
  public void setProfileInfo(UserInfo prin) {
    this.prin = prin;
  }
  public GCM getGCM() {
    return a;
  }
  public void Init() {
    if (ls == null) {
      ls = new LoginSaver(this);
    }
    if (ls != null) {
      l = ls.getLoginData();
    }
    if (a == null) {
      a = new GCM(this);
      a.Init();
    }
    if (gps == null) {
      gps = new GPSManager(getApplicationContext());
    }
  }
  public void switchFragment(ExtendedFragment f) {
    actualFragment = f;
    FragmentTransaction ft = this.getFragmentManager().beginTransaction();
    ft.replace(R.id.main_container, f);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();
    Init();
  }
  public void setMode(ModeUse m) {
    mode = m;
  }
  public ModeUse getMode() {
    return mode;
  }
  public void closeApplication() {
    finish();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // TODO set domine server
    RestCalls.setDOMINE(/*put-your-domine-here*/);
    Init();
    setContentView(R.layout.activity_main);
    switchFragment(Fragment_Login.newAssignParent(this));
  }
  @Override
  protected void onDestroy() {
    super.onDestroy();
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }
  public void HandleGCMMessage(Bundle bu)  {
    String msgtype = bu.getString("Type","");
    String msgmess = bu.getString("Message");
    if ("UPL".equals(msgtype) && getRole().equals(RestCalls.DRIVER)) { 
      if (actualFragment instanceof Fragment_userWaiting) {
        actualFragment.putMessage(null);
      }
    }
    if ("PCO".equals(msgtype) && getRole().equals(RestCalls.PASSENGER)) { 
      if (actualFragment instanceof Fragment_userWaiting) {
        actualFragment.putMessage(msgmess);
      }
    }
    if ("ACC".equals(msgtype) && getRole().equals(RestCalls.DRIVER)) { 
      if (actualFragment instanceof Fragment_userDetail) {
        actualFragment.putMessage(msgmess);
      }
    }
  }
  @Override
  protected void onResume() {
    IsRunning = true;
    Init();
    GcmBroadcastReceiver.main = this;
    super.onResume();
  }
  @Override
  protected void onPause() {
    super.onPause();
    IsRunning = true;
    GcmBroadcastReceiver.main = null;
  }
}




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