コード例 #1
0
  @Override
  public void onDialogPositiveClick(DialogFragment dialog) {
    Dialog dialogView = dialog.getDialog();
    String stringName =
        ((EditText) dialogView.findViewById(R.id.dialog_store_name)).getText().toString();
    if (editIndex == -1) {
      if (!stringName.isEmpty()) {
        Store store = new Store(stringName);
        long rowId = mStoreDbAdapter.insertStore(store);
        store.setId(rowId);
        mStoreList.add(store);
      }
    } else {
      mStoreList.get(editIndex).setName(stringName);
      mStoreDbAdapter.updateStore(mStoreList.get(editIndex));
      editIndex = -1;
    }

    if (!stringName.isEmpty()) {
      mStoreAdaptor.notifyDataSetChanged();
    }
  }
コード例 #2
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   String stringName;
   super.onActivityResult(requestCode, resultCode, data);
   switch (requestCode) {
     case Constants.RESULT_SPEECH_OUTPUT:
       if (resultCode == RESULT_OK && data != null) {
         ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
         stringName = text.get(0);
         if (stringName != null && !stringName.isEmpty()) {
           Store store = new Store(stringName);
           long rowId = mStoreDbAdapter.insertStore(store);
           Log.d(LOG_TAG, "Insert ret val: " + rowId);
           store.setId(rowId);
           mStoreList.add(store);
           mStoreAdaptor.notifyDataSetChanged();
         }
       }
       break;
     default:
       Log.w(LOG_TAG, "Not handled speech resultCode");
       break;
   }
 }
コード例 #3
0
  @Override
  public void run() {
    Log.v(Program.LOG, "DatabaseSearcher.run()");

    double radius =
        PreferenceManager.getDefaultSharedPreferences(context)
            .getInt(context.getResources().getString(R.string.radius), 20);

    Location l = StoreFinderApplication.getLastKnownLocation();

    double lat = l.getLatitude();
    double lon = l.getLongitude();

    database = database.open();
    db = database.getDatabase();

    Cursor c =
        db.query(
            "store",
            new String[] {
              "_id", "name", "address", "city", "state", "zip", "phone", "latitude", "longitude"
            },
            "latitude > "
                + (lat - radius / MILES_PER_LATLONG)
                + " AND latitude < "
                + (lat + radius / MILES_PER_LATLONG)
                + " AND longitude > "
                + (lon - radius / MILES_PER_LATLONG)
                + " AND longitude < "
                + (lon + radius / MILES_PER_LATLONG),
            null,
            null,
            null,
            null);

    double latitude, longitude;

    c.moveToFirst();
    if (c.getCount() > 0) {
      do {
        latitude = c.getDouble(7);
        longitude = c.getDouble(8);
        float[] results = new float[3];
        Location.distanceBetween(lat, lon, latitude, longitude, results);
        double distance = results[0] * Program.MILES_PER_METER;

        if (distance > radius) // Make user customizable search distance
        continue;

        Store store = new Store();
        store.setId(c.getInt(0));
        store.setName(c.getString(1));
        store.setAddress(c.getString(2));
        store.setCitystate(c.getString(3) + ", " + c.getString(4) + " " + c.getString(5));
        store.setPhone(c.getString(6));
        store.setDistance(distance);

        Location loc = new Location("");
        loc.setLatitude(latitude);
        loc.setLongitude(longitude);
        store.setLocation(loc);

        Message msg = new Message();
        Bundle b = new Bundle();
        b.putSerializable("store", store);
        msg.setData(b);
        msg.what = WHAT_SEARCHDB;
        handler.sendMessage(msg);
      } while (c.moveToNext());
    }

    c.close();
    database.close();

    Message finish = new Message();
    finish.what = WHAT_FINISHEDSEARCH;
    handler.sendMessage(finish);
  }