Android Open Source - TacoTool Manage Activity






From Project

Back to project page TacoTool.

License

The source code is released under:

GNU General Public License

If you think the Android project TacoTool 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.example.tacotool;
// ww w . ja  va2  s . c o  m
import database.DBManager;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment.SavedState;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

@SuppressLint("NewApi")
public class ManageActivity extends Activity {
  private DBManager dbm;
  private ListView listViewRecs;
  private ListView listViewIngrs;
  private ArrayAdapter<Object> adapterRecs;
  private ArrayAdapter<Object> adapterIngrs;
  private Bundle st;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage);
    dbm = new DBManager(getBaseContext());
    st = savedInstanceState;

    ActionBar ab = getActionBar();
    ab.setTitle(R.string.manage_tacos);
    
    listViewRecs = (ListView) findViewById(R.id.list_recipes);


    adapterRecs = new ArrayAdapter(getBaseContext(), android.R.layout.simple_list_item_1);

    listViewRecs.setAdapter(adapterRecs);
    dbm.open();
    adapterRecs.addAll(dbm.getRecipes());
    dbm.close();
    listViewRecs.setOnItemClickListener(new OnItemClickListener() {

      @Override
      public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
        //        System.out.println("item: " + view.getI + " removed");
        String s = listViewRecs.getItemAtPosition(position).toString();
        dbm.open();
        dbm.removeRecipe(s);
        adapterRecs.clear();
        adapterRecs.addAll(dbm.getRecipes());
        dbm.close();
      }
    });






    listViewIngrs = (ListView) findViewById(R.id.list_ingreds);


    adapterIngrs = new ArrayAdapter(getBaseContext(), android.R.layout.simple_list_item_1);

    listViewIngrs.setAdapter(adapterIngrs);
    dbm.open();
    adapterIngrs.addAll(dbm.getIngredients());
    dbm.close();
    listViewIngrs.setOnItemClickListener(new OnItemClickListener() {

      @Override
      public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
        //        System.out.println("item: " + view.getI + " removed");
        String s = listViewIngrs.getItemAtPosition(position).toString();
        dbm.open();
        dbm.removeIngredient(s);
        adapterIngrs.clear();
        adapterIngrs.addAll(dbm.getIngredients());
        dbm.close();
      }
    });


  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.manage, menu);
    return true;
  }

  public void clearDatabase(View view) {
    dbm.open();
    dbm.clearTable();
    adapterRecs.clear();
    adapterIngrs.clear();
    adapterRecs.addAll(dbm.getRecipes());
    adapterIngrs.addAll(dbm.getIngredients());
    dbm.close();
  }

}




Java Source Code List

com.example.tacotool.CreateActivity.java
com.example.tacotool.MainActivity.java
com.example.tacotool.ManageActivity.java
com.example.tacotool.SettingsActivity.java
com.example.tacotool.Taco.java
database.DBManager.java
database.DBSQLiteHelper.java