Android Open Source - GasTracker Main Menu






From Project

Back to project page GasTracker.

License

The source code is released under:

Copyright 2014 kurtzy317

If you think the Android project GasTracker 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.mindalsoblown.gastracker;
/*from  w w w  . j a  va2s  .  co m*/
import java.io.File;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainMenu extends ActionBarActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_menu);

    if (savedInstanceState == null) {
      getSupportFragmentManager().beginTransaction()
          .add(R.id.container, new PlaceholderFragment()).commit();
    }
    File id = new File(this.getFilesDir(), "ID");
    if (!id.exists())
    {
      Intent intent = new Intent(MainMenu.this, Login.class);
        startActivity(intent);
    }
  }

  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main_menu, menu);
    
    //get list and give it entries for new fillup and get fill ups
    ListView lstMain = (ListView)findViewById(R.id.lstMain);
    ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    listAdapter.add("Add Fill Up");
    listAdapter.add("Fill Ups");
    listAdapter.add("Stats");
    lstMain.setAdapter(listAdapter);
    
    lstMain.setOnItemClickListener(new OnItemClickListener(){

      @Override
      
      //base on the item selected open the correct activity
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
          long arg3) {
        if (arg2 == 1)
        {
          Intent intent = new Intent(MainMenu.this, History.class);
            startActivity(intent);
        }
        if (arg2 == 0)
        {
          Intent intent = new Intent(MainMenu.this, AddEntry.class);
            startActivity(intent);
        }
        if (arg2 == 2)
        {
          Intent intent = new Intent(MainMenu.this, Stats.class);
            startActivity(intent);
        }
      }
    });
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
      return true;
    }
    return super.onOptionsItemSelected(item);
  }

  /**
   * A placeholder fragment containing a simple view.
   */
  public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_main_menu,
          container, false);
      return rootView;
    }
  }
}




Java Source Code List

com.mindalsoblown.gastracker.AddEntry.java
com.mindalsoblown.gastracker.DatabaseConnector.java
com.mindalsoblown.gastracker.Entry.java
com.mindalsoblown.gastracker.FillUpDetail.java
com.mindalsoblown.gastracker.History.java
com.mindalsoblown.gastracker.Login.java
com.mindalsoblown.gastracker.MainMenu.java
com.mindalsoblown.gastracker.Register.java
com.mindalsoblown.gastracker.Stats.java
com.mindalsoblown.gastracker.User.java