Android Open Source - qshuttle_driver Data Operator






From Project

Back to project page qshuttle_driver.

License

The source code is released under:

MIT License

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

/**
 * /*w  w  w  .  j  a v  a2  s .com*/
 */
package com.qshuttle.car;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;


import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.location.Location;
import android.net.Uri;

/**
 * @author wangpeifeng
 *
 */
public class DataOperator {
  
  private static final String TAG = "DataOperator";
  
  private Context context;
  private ContentResolver resolver;

  public DataOperator(Context context){
    this.context = context;
    resolver = context.getContentResolver();
    
  }

  /********************************************************************************
   * public ??
   */
  
  /*
   * ???????
   */
  
  public void close(){
    
    
  }
  
  /*
   * ?????????
   */
  public Uri recordPosition(String number, Location location){

    //Uri.Builder builder = new Uri.Builder();
    Uri uri = new Uri.Builder().build().parse(DatabaseHelper.URI_HEADER
      +DatabaseHelper.URI_CAR_TRACKER);

    ContentValues values = new ContentValues();
    values.put(DatabaseHelper.DB_COLUMN_CAR_NUMBER, number);
    values.put(DatabaseHelper.DB_COLUMN_CAR_POS_LATE6,""+(int)(location.getLatitude()*1E6));
    values.put(DatabaseHelper.DB_COLUMN_CAR_POS_LONGE6, ""+(int)(location.getLongitude()*1E6));
    values.put(DatabaseHelper.DB_COLUMN_CAR_POS_STAMP, Utilities.StampToString(location.getTime()));
    values.put(DatabaseHelper.DB_COLUMN_CAR_POS_PROVIDER, location.getProvider());
    values.put(DatabaseHelper.DB_COLUMN_CAR_POS_SPEEDE6, ""+(int)(location.getSpeed()*1E6));
    values.put(DatabaseHelper.DB_COLUMN_CAR_POS_BEARINGE6, ""+(int)(location.getBearing()*1E6));
    values.put(DatabaseHelper.DB_COLUMN_CAR_POS_ACCURACY, ""+(int)(location.getAccuracy()));
    
    return resolver.insert(uri, values);

  }

  /*
   * ?????????
   */
  
  public void reportPosition(){

    
    Uri uri = new Uri.Builder().build().parse(DatabaseHelper.URI_HEADER
        +DatabaseHelper.URI_CAR_TRACKER
        +DatabaseHelper.URI_LIMIT_1);
    
    
    String[] table = DatabaseHelper.Db_Table_Car_Tracker;
    int l = table.length;
    
    String[] projection = new String[l+1];
    int i =0;
    while (i<l){
      projection[i] = table[i];
      i++;
    }
    projection[i] = DatabaseHelper.DB_COLUMN_ROWID;
    
    String selection = null;
    String sortOrder = null;
    String[] selectionArgs = null;
    
    Cursor cursor = null;
    
    cursor = resolver.query(uri,projection, selection, selectionArgs, sortOrder);
  
    int rows = 0, columns = 0;
    if(cursor!=null){
      rows = cursor.getCount();
      columns = cursor.getColumnCount();
    }
    if(rows>0 && columns>0){
    
      cursor.moveToFirst();
    
      String number = cursor.getString(getProjectionIndex(projection,DatabaseHelper.DB_COLUMN_CAR_NUMBER));
      String late6 = cursor.getString(getProjectionIndex(projection,DatabaseHelper.DB_COLUMN_CAR_POS_LATE6));
      String longe6 = cursor.getString(getProjectionIndex(projection,DatabaseHelper.DB_COLUMN_CAR_POS_LONGE6));
      String stamp = cursor.getString(getProjectionIndex(projection,DatabaseHelper.DB_COLUMN_CAR_POS_STAMP));
      String type = cursor.getString(getProjectionIndex(projection,DatabaseHelper.DB_COLUMN_CAR_POS_PROVIDER));
      String speed = cursor.getString(getProjectionIndex(projection,DatabaseHelper.DB_COLUMN_CAR_POS_SPEEDE6));
      String bearing = cursor.getString(getProjectionIndex(projection,DatabaseHelper.DB_COLUMN_CAR_POS_BEARINGE6));
      String accuracy = cursor.getString(getProjectionIndex(projection,DatabaseHelper.DB_COLUMN_CAR_POS_ACCURACY));
      int rowid = cursor.getInt(getProjectionIndex(projection,DatabaseHelper.DB_COLUMN_ROWID));
      
      WebApi webApi = new WebApi(context);
      webApi.reportPosition(late6, longe6, number, type, stamp,speed,bearing,accuracy, uri, rowid, this);
    }  
    if(cursor!=null)
      cursor.close();

  }
  
  /*
   * ?????????????
   */
  
  public int deletePosRecord(Uri uri, int rowid){
    
    int result = 0;

    String where = DatabaseHelper.DB_COLUMN_ROWID +"=?";
    String[] selectionArgs = new String[1];
    selectionArgs[0] =""+rowid;
    result = resolver.delete(uri,where, selectionArgs);
    
    return result;
    
  }
  
  /*
   * ??WebApi??????????
   */
  
  public boolean checkResponse(String response){
    boolean flag = false;
    
    try {
      JSONObject obj = new JSONObject(response);
      if(obj.getBoolean(WebApi.API_RESP_SUCCESS)){
        flag = true;
      }
      
    }
    catch (Exception e){
      e.printStackTrace();
    }
    
    return flag;
  }
  

  /*
   * private ??
   */
  
  /*
   * ??????????????????
   */
  private int getProjectionIndex(String[] projection,String column){
    int index = 0;

    int i = 0;
    int l = projection.length;
    while(i<l){
      if(projection[i].equals(column)){
        index = i;
        return index;
      }
      i++;
    }

    
    return index;
  }
  
  
}




Java Source Code List

com.qshuttle.car.ActivityAddress.java
com.qshuttle.car.ActivityInfoRequest.java
com.qshuttle.car.ActivityMain.java
com.qshuttle.car.ActivityOfflineMap.java
com.qshuttle.car.DataOperator.java
com.qshuttle.car.DataProvider.java
com.qshuttle.car.DatabaseHelper.java
com.qshuttle.car.ExpandableListAdapter.java
com.qshuttle.car.GPSLocationOverlay.java
com.qshuttle.car.HostSettingActivity.java
com.qshuttle.car.ListAdapterAddress.java
com.qshuttle.car.ListAdapter.java
com.qshuttle.car.LongPressPopupOverlay.java
com.qshuttle.car.MapGestureDetectorOverlay.java
com.qshuttle.car.OverlayMapLocation.java
com.qshuttle.car.PassengerScheduleOverlay.java
com.qshuttle.car.PrefProxy.java
com.qshuttle.car.ThreadHttpPost.java
com.qshuttle.car.ThreadTimer.java
com.qshuttle.car.TimerCallBack.java
com.qshuttle.car.Timer.java
com.qshuttle.car.Utilities.java
com.qshuttle.car.WebApi.java