/**
  * check if database must be created or is already existing
  *
  * @param context context from main activity
  */
 public DataSource(Context context) {
   dbHelper = new DatabaseHelper(context);
   //// NanoHTTPD.myOut.println("I'm alive");
   try {
     dbHelper.createDataBase();
   } catch (IOException ioe) {
     throw new Error("Unable to create database");
   }
   try {
     dbHelper.openDataBase();
   } catch (SQLException sqle) {
     throw sqle;
   }
 }
Пример #2
0
  private void initDatabase() {
    myDbHelper = new DatabaseHelper(this);

    try {
      myDbHelper.createDataBase();
    } catch (IOException ioe) {
      throw new Error("Unable to create database");
    }

    try {
      myDbHelper.openDataBase();
    } catch (SQLException sqle) {
      Log.d(TAG, "openfailed");
      throw sqle;
    }
  }
Пример #3
0
 public void init_db() {
   myDb = new DatabaseHelper(this);
   {
     try {
       myDb.createDataBase();
     } catch (IOException ioe) {
       throw new Error("Unable to create database");
     }
     try {
       myDb.openDataBase();
     } catch (SQLException sqle) {
       throw sqle;
     }
     myDb.getReadableDatabase();
     c = myDb.getNotes();
     if (c.moveToFirst()) {
       do {} while (c.moveToNext());
     }
   }
 }
Пример #4
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    /* Create the Database (no Errors if it already exists) */
    dbhelper = DatabaseHelper.getInstance(this);

    try {
      dbhelper.createDataBase();
    } catch (IOException ioe) {
      throw new Error("Unable to create database");
    }

    if (savedInstanceState != null) {
      // restore position state of listview
      listviewSelPos = savedInstanceState.getInt("listviewSelection", 0);
      // restore position of spinner
      spinPos = savedInstanceState.getInt("spinnerSelection", 0);
    }

    // register context menu
    registerForContextMenu(getListView());

    // get Resources pointer
    myResources = getResources();

    // AssetManager asd = getAssets();
    spin_buslines = (Spinner) findViewById(R.id.lines);
    togbut_directions = (Button) findViewById(R.id.toggleDirection);
    autocompl_search = (AutoCompleteTextView) findViewById(R.id.autoCompLineSearch);
    autocompl_search.setThreshold(1);

    selDirection = 1;

    spin_buslines.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> arg0, View view, int pos, long id) {
            cursorBusLineNames.moveToPosition(pos);
            selLineid = cursorBusLineNames.getInt(cursorBusLineNames.getColumnIndex("_id"));

            loadStopsList();

            if (listviewSelPos != 0) {
              getListView().setSelection(listviewSelPos);
              listviewSelPos = 0;
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

          }
        });

    togbut_directions.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            if (selDirection == 1) {
              selDirection = 2;

              togbut_directions.setCompoundDrawablesWithIntrinsicBounds(
                  0, 0, R.drawable.arrow_left, 0);
              togbut_directions.setText(R.string.msg_but_direction_return);
            } else {
              selDirection = 1;
              togbut_directions.setCompoundDrawablesWithIntrinsicBounds(
                  0, 0, R.drawable.arrow_right, 0);
              togbut_directions.setText(R.string.msg_but_direction_going);
            }
            loadStopsList();
          }
        });
  }
Пример #5
0
  public void loadStopsList() {
    String busStopStr[];

    /* Create the Database (no Errors if it already exists) */
    // dbhelper = new DataBaseHelper(this);

    try {
      dbhelper.createDataBase();

    } catch (IOException ioe) {
      throw new Error("Unable to create database");
    }

    SQLiteDatabase myDB = dbhelper.getMyWritableDatabase();

    try {
      /* Query for some results with Selection and Projection. */

      // Cursor c = myDB
      // .rawQuery(
      // "select v_stop.stopid as stopid , v_stop.sorder || '. ' || v_stop.stopname as stopstr,
      // v_stop.routeid as routeid "
      // + " from v_stop  where v_stop.direction = "
      // + selDirection
      // + " and v_stop.lineid = "
      // + selLineid, null);
      Cursor c =
          myDB.rawQuery(
              myResources.getString(R.string.sql_select_stops),
              new String[] {selDirection + "", selLineid + ""});

      /* Get the indices of the Columns we will need */
      int idColumn = c.getColumnIndex("stopid");
      int strColumn = c.getColumnIndex("stopstr");
      // int routeIDColumn = c.getColumnIndex("routeid");

      busStopStr = new String[1];
      busStopsId = new int[1];

      /* Check if our result was valid. */
      if (c != null) {
        /* Check if at least one Result was returned. */
        busStopStr = new String[c.getCount()];
        busStopsId = new int[c.getCount()];

        if (c.moveToFirst()) {
          int i = 0;
          // selRouteid = c.getInt(routeIDColumn);

          do {
            busStopStr[i] = c.getString(strColumn);
            busStopsId[i++] = c.getInt(idColumn);

            // android.util.Log.d("Line :", "Position: " + (i -
            // 1)
            // + " " + qID + " " + qStr);
          } while (c.moveToNext());
        }
      }

      // close cursor
      c.close();

      setListAdapter(
          new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, busStopStr));

    } catch (SQLiteException e) {
      android.util.Log.e("Database error", e.getLocalizedMessage());
    } finally {
      if (myDB != null) myDB.close();
      dbhelper.close();
    }
  }