Android Open Source - EatDudeAndroid Load Restaurant






From Project

Back to project page EatDudeAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project EatDudeAndroid 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

/*
 * //from w  ww .  ja v  a 2 s .  c  om
    Copyright (C) 2012  Wiley Snyder

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or 
     any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
  Any other questions or concerns contact wiley@wileynet.com

*/

package com.wileynet.eatdude.db;

import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import android.content.Context;

import com.wileynet.eatdude.MainHome;
import com.wileynet.eatdude.RestaurantSelection;

public class LoadRestaurant {
  /* load restaurant into the db */
  private RestaurantDbAdapter mDbHelper;
  private final Context mCtx;
  private HashMap<String, String> menumap = new HashMap<String, String>();
  private int count = 0;
  
  public LoadRestaurant(Context ctx){
    this.mCtx = ctx;
  }

  public void load() {
    
    mDbHelper = new RestaurantDbAdapter(mCtx);
    menumap = RestaurantSelection.r.getMenu();
    
    try {
      mDbHelper.open();
      if (RestaurantSelection.dbClear == 0) {
        // clear all tables
        mDbHelper.clearTables();
        
        MainHome.restaurant_address = RestaurantSelection.r.getRestaurant_address();
        MainHome.restaurant_phone = RestaurantSelection.r.getRestaurant_phone();
        MainHome.restaurant_name = RestaurantSelection.r.getRestaurant_name();
        
        // restaurant
        mDbHelper.insertRestaurant(
            RestaurantSelection.r.getRestaurant_id(),
            MainHome.restaurant_address,
            MainHome.restaurant_phone,
            MainHome.restaurant_address);

        // menu
        for (Map.Entry<String, String> m : menumap.entrySet()) {
          String menu_id = m.getKey();
          String menu_name = m.getValue();
          mDbHelper.insertMenu(menu_id, menu_name);
          // System.out.println(">> menu : " + menu_id + " => " +
          // menu_name);

          // category
          for (Map.Entry<String, String> cat : RestaurantSelection.r
              .getMenu_category().entrySet()) {
            String _key = cat.getKey();
            String _value = cat.getValue();

            String ckeys[];
            ckeys = new String[2]; // 0=menu_id,1=cat_id
            StringTokenizer ctoken = new StringTokenizer(_key, "|");

            count = 0;
            while (ctoken.hasMoreElements()) {
              ckeys[count] = (String) ctoken.nextElement();
              count++;
            }
            
            if (ckeys[0].equals(menu_id)) {
              // System.out.println("-------------> " + ckeys[1] +
              // " => " + _value );
              mDbHelper.insertCategory(menu_id, ckeys[1], _value);
            }
            

          }

          // item
          for (Map.Entry<String, String> entry : RestaurantSelection.r
              .getMenu_item().entrySet()) {

            String key = entry.getKey();// item id
            String value = entry.getValue();// string menu_id |
                            // cat_id | name |
                            // description | price |
                            // number
            // System.out.println("==============================");
            // System.out.println("KEY = " + key);
            // System.out.println("VALUE = " + value);
            // System.out.println("==============================");

            String meta[];
            meta = new String[6]; // 0=menu_id,1=cat_id,2=name,3=desc,4=price,5=number

            StringTokenizer token = new StringTokenizer(value, "|");

            count = 0;

            while (token.hasMoreElements()) {

              if (count <= 5) {
                meta[count] = (String) token.nextElement();
              }
              count++;
            }

            if (meta[0].equals(menu_id)) {
              // System.out.println(menu_id + "      item ----> " +
              // key + " => " + meta[2] );
              // insertItem(String id, String menu_id, String
              // cat_id, String name, String desc, String price,
              // String number)
              /*
               * System.out.println("=============================="
               * ); System.out.println("key : " + key);
               * System.out.println("m0 : " + meta[0]);
               * System.out.println("m1 : " + meta[1]);
               * System.out.println("m2 : " + meta[2]);
               * System.out.println("m3 : " + meta[3]);
               * System.out.println("m4 : " + meta[4]);
               * System.out.println("m5 : " + meta[5]);
               * System.out.
               * println("==============================");
               */

              mDbHelper.insertItem(key, meta[0], meta[1],
                  meta[2], meta[3], meta[4], meta[5]);
            }

          }
          RestaurantSelection.dbClear = 1;
          MainHome.menu_success = true;
          
        }
        mDbHelper.close();
      }
      

    } catch (Exception e) {
      e.printStackTrace();
    }

  }

}




Java Source Code List

com.wileynet.eatdude.CategorySelection.java
com.wileynet.eatdude.CitySelection.java
com.wileynet.eatdude.CountrySelection.java
com.wileynet.eatdude.EatDudeSplash.java
com.wileynet.eatdude.HelpHome.java
com.wileynet.eatdude.ItemDisplay.java
com.wileynet.eatdude.ItemSelection.java
com.wileynet.eatdude.MainHome.java
com.wileynet.eatdude.MenuSelection.java
com.wileynet.eatdude.RestaurantSearch.java
com.wileynet.eatdude.RestaurantSelection.java
com.wileynet.eatdude.Restaurant.java
com.wileynet.eatdude.StateSelection.java
com.wileynet.eatdude.db.LoadRestaurant.java
com.wileynet.eatdude.db.RestaurantDbAdapter.java
com.wileynet.eatdude.db.RestaurantDbHelper.java
com.wileynet.eatdude.util.SpinnerData.java
com.wileynet.eatdude.util.StringUtils.java
com.wileynet.eatdude.xml.GeoDefaultHandler.java
com.wileynet.eatdude.xml.GeoSaxHelper.java
com.wileynet.eatdude.xml.MessageDefaultHandler.java
com.wileynet.eatdude.xml.MessageSaxHelper.java
com.wileynet.eatdude.xml.MyDefaultHandler.java
com.wileynet.eatdude.xml.SAXHelper.java