// 设置ListView
  protected void setListData(String date) {
    itemAccess = new ItemTableAccess(sqlHelper.getReadableDatabase());
    list = itemAccess.findAnalyzeJieHuanDetail(date);
    itemAccess.close();
    adapter =
        new SimpleAdapter(
            this,
            list,
            R.layout.list_analyzejiehuan,
            new String[] {
              "itembuydate", "jiechuprice", "huanruprice", "jieruprice", "huanchuprice"
            },
            new int[] {
              R.id.tv_analyze_itembuydate,
              R.id.tv_analyze_jiechu,
              R.id.tv_analyze_huanru,
              R.id.tv_analyze_jieru,
              R.id.tv_analyze_huanchu
            });
    listAnalyzeJieHuanDetail.setAdapter(adapter);

    // 设置empty
    if (list.size() == 0) {
      layNoItem.setVisibility(View.VISIBLE);
    } else {
      layNoItem.setVisibility(View.GONE);
    }
  }
 public Cursor query(
     Uri paramUri,
     String[] paramArrayOfString1,
     String paramString1,
     String[] paramArrayOfString2,
     String paramString2) {
   paramString2 = mOpenHelper.getReadableDatabase();
   if (TextUtils.isEmpty(paramArrayOfString2[0])) {
     paramArrayOfString1 = null;
     paramString1 = null;
   }
   for (; ; ) {
     paramArrayOfString1 =
         paramString2.query(
             "suggestions",
             createProjection(paramArrayOfString2),
             paramArrayOfString1,
             paramString1,
             null,
             null,
             "date DESC",
             null);
     paramArrayOfString1.setNotificationUri(getContext().getContentResolver(), paramUri);
     return paramArrayOfString1;
     paramArrayOfString1 = "%" + paramArrayOfString2[0] + "%";
     paramString1 = new String[1];
     paramString1[0] = paramArrayOfString1;
     paramArrayOfString1 = mSuggestSuggestionClause;
   }
 }
Example #3
0
 public HistoryItem buildHistoryItem(int number) {
   SQLiteOpenHelper helper = new DBHelper(activity);
   SQLiteDatabase db = null;
   Cursor cursor = null;
   try {
     db = helper.getReadableDatabase();
     cursor =
         db.query(
             DBHelper.TABLE_NAME,
             COLUMNS,
             null,
             null,
             null,
             null,
             DBHelper.TIMESTAMP_COL + " DESC");
     cursor.move(number + 1);
     String text = cursor.getString(0);
     String display = cursor.getString(1);
     String format = cursor.getString(2);
     long timestamp = cursor.getLong(3);
     String details = cursor.getString(4);
     Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
     return new HistoryItem(result, display, details);
   } finally {
     close(cursor, db);
   }
 }
Example #4
0
 public List<HistoryItem> buildHistoryItems() {
   SQLiteOpenHelper helper = new DBHelper(activity);
   List<HistoryItem> items = new ArrayList<>();
   SQLiteDatabase db = null;
   Cursor cursor = null;
   try {
     db = helper.getReadableDatabase();
     cursor =
         db.query(
             DBHelper.TABLE_NAME,
             COLUMNS,
             null,
             null,
             null,
             null,
             DBHelper.TIMESTAMP_COL + " DESC");
     while (cursor.moveToNext()) {
       String text = cursor.getString(0);
       String display = cursor.getString(1);
       String format = cursor.getString(2);
       long timestamp = cursor.getLong(3);
       String details = cursor.getString(4);
       Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
       items.add(new HistoryItem(result, display, details));
     }
   } finally {
     close(cursor, db);
   }
   return items;
 }
  public ProfileResultAdapter(Context context) {
    ViewInspector.runtimeComponentMap
        .get(((ContextThemeWrapper) context).getBaseContext())
        .inject(this);
    mLayoutInflater = LayoutInflater.from(context);

    String avgsql =
        "select avg("
            + ViewProfile.MEASURE_DURATION
            + "), "
            + "avg("
            + ViewProfile.LAYOUT_DURATION
            + "), "
            + "avg("
            + ViewProfile.DRAW_DURATION
            + ") "
            + "from "
            + ViewProfile.TABLE;
    Cursor cursor = db.getReadableDatabase().rawQuery(avgsql, null);
    cursor.moveToNext();
    mAvgMeasure = cursor.getLong(0) / 1000.0;
    mAvgLayout = cursor.getLong(1) / 1000.0;
    mAvgDraw = cursor.getLong(2) / 1000.0;
    cursor.close();
  }
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    // Resolve the URI.
    int match = mUriMatcher.match(uri);
    if (match == UriMatcher.NO_MATCH) {
      throw new IllegalArgumentException("Invalid URI: " + uri);
    }

    // Add the ID predicate if needed.
    Mapping mapping = mMappings.get(match);
    if (mapping.hasId) {
      selection = whereWithId(uri, selection);
    }

    // System.out.println("QUERY " + uri + " WHERE (" + selection + ")");

    // Run the query.
    String tableName = mapping.table.getTableName();
    Cursor cursor =
        mDatabase
            .getReadableDatabase()
            .query(tableName, projection, selection, selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
  }
  @Override
  public Cursor query(
      @NonNull Uri uri,
      String[] projection,
      String selection,
      String[] selectionArgs,
      String sortOrder) {
    int match = uriMatcher.match(uri);
    String table;
    String useSelection = selection;
    String[] useSelectionArgs = selectionArgs;
    switch (match) {
      case ALL_ROWS:
        table = uri.getLastPathSegment();
        break;
      case ROW_BY_ID:
        List<String> segments = uri.getPathSegments();
        table = segments.get(TABLE_SEGMENT);
        useSelection = WHERE_MATCHES_ID;
        useSelectionArgs = new String[] {segments.get(ID_SEGMENT)};
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    boolean distinct = false;
    String limit = null;

    // If have query parameters, see if any exist interested in.
    if (!TextUtils.isEmpty(uri.getQuery())) {
      distinct = uri.getBooleanQueryParameter(DISTINCT_PARAMETER, false);
      limit = uri.getQueryParameter(LIMIT_PARAMETER);
    }

    SQLiteDatabase db = dbHelper.getReadableDatabase();
    db.acquireReference();

    try {
      Cursor cursor =
          db.query(
              distinct,
              table,
              projection,
              useSelection,
              useSelectionArgs,
              null,
              null,
              sortOrder,
              limit);
      // Register the cursor with the requested URI so the caller will receive
      // future database change notifications. Useful for "loaders" which take advantage
      // of this concept.
      cursor.setNotificationUri(getContext().getContentResolver(), uri);
      return cursor;
    } finally {
      db.releaseReference();
    }
  }
 @Override
 protected Boolean doInBackground(String... params) {
   Query query = new Query();
   SQLiteOpenHelper openHelper = new DatabaseHelper(SettingConnections.context);
   SQLiteDatabase db = openHelper.getReadableDatabase();
   cities = CitiesFactory.getCitiesFromCursor(query.selectCityLikeName(db, params[0]));
   db.close();
   return true;
 }
 public void printPostFrequencies(PrintWriter pw, String indent, DumpFilter filter) {
   SQLiteDatabase db = mHelper.getReadableDatabase();
   long midnight = getMidnightMs();
   String q =
       "SELECT "
           + COL_EVENT_USER_ID
           + ", "
           + COL_PKG
           + ", "
           +
           // Bucket by day by looking at 'floor((midnight - eventTimeMs) / dayMs)'
           "CAST((("
           + midnight
           + " - "
           + COL_EVENT_TIME
           + ") / "
           + DAY_MS
           + ") AS int) "
           + "AS day, "
           + "COUNT(*) AS cnt "
           + "FROM "
           + TAB_LOG
           + " "
           + "WHERE "
           + COL_EVENT_TYPE
           + "="
           + EVENT_TYPE_POST
           + " "
           + "GROUP BY "
           + COL_EVENT_USER_ID
           + ", day, "
           + COL_PKG;
   Cursor cursor = db.rawQuery(q, null);
   try {
     for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
       int userId = cursor.getInt(0);
       String pkg = cursor.getString(1);
       if (filter != null && !filter.matches(pkg)) continue;
       int day = cursor.getInt(2);
       int count = cursor.getInt(3);
       pw.println(
           indent
               + "post_frequency{user_id="
               + userId
               + ",pkg="
               + pkg
               + ",day="
               + day
               + ",count="
               + count
               + "}");
     }
   } finally {
     cursor.close();
   }
 }
 private JSONArray JsonPostFrequencies(DumpFilter filter) throws JSONException {
   JSONArray frequencies = new JSONArray();
   SQLiteDatabase db = mHelper.getReadableDatabase();
   long midnight = getMidnightMs();
   String q =
       "SELECT "
           + COL_EVENT_USER_ID
           + ", "
           + COL_PKG
           + ", "
           +
           // Bucket by day by looking at 'floor((midnight - eventTimeMs) / dayMs)'
           "CAST((("
           + midnight
           + " - "
           + COL_EVENT_TIME
           + ") / "
           + DAY_MS
           + ") AS int) "
           + "AS day, "
           + "COUNT(*) AS cnt "
           + "FROM "
           + TAB_LOG
           + " "
           + "WHERE "
           + COL_EVENT_TYPE
           + "="
           + EVENT_TYPE_POST
           + " AND "
           + COL_EVENT_TIME
           + " > "
           + filter.since
           + " GROUP BY "
           + COL_EVENT_USER_ID
           + ", day, "
           + COL_PKG;
   Cursor cursor = db.rawQuery(q, null);
   try {
     for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
       int userId = cursor.getInt(0);
       String pkg = cursor.getString(1);
       if (filter != null && !filter.matches(pkg)) continue;
       int day = cursor.getInt(2);
       int count = cursor.getInt(3);
       JSONObject row = new JSONObject();
       row.put("user_id", userId);
       row.put("package", pkg);
       row.put("day", day);
       row.put("count", count);
       frequencies.put(row);
     }
   } finally {
     cursor.close();
   }
   return frequencies;
 }
Example #11
0
 private void runArchive(String databaseName) {
   SQLiteOpenHelper dbHelper = getOrCreateDatabaseHelper(databaseName);
   File dbFile = new File(dbHelper.getReadableDatabase().getPath());
   Log.i(LogUtil.TAG, "Running archive: " + dbFile.getAbsolutePath());
   dbHelper.close();
   FileArchive archive = getArchive(databaseName);
   if (archive.add(dbFile)) {
     dbFile.delete();
   }
 }
Example #12
0
 public static MeetingDAO getMeetingDAOFromID(SQLiteOpenHelper sqLiteOpenHelper, int id) {
   final SQLiteDatabase readableDatabase = sqLiteOpenHelper.getReadableDatabase();
   final Cursor rawQuery =
       readableDatabase.rawQuery("select * from meetings where _id=" + id, null);
   while (rawQuery.moveToNext()) {
     return getMeetingDAOFromCursor(rawQuery);
   }
   readableDatabase.close();
   return null;
 }
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(args.table);

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    Cursor result = qb.query(db, projection, args.where, args.args, args.groupby, null, sortOrder);
    // result.setNotificationUri(getContext().getContentResolver(), uri);
    return result;
  }
Example #14
0
 public boolean hasHistoryItems() {
   SQLiteOpenHelper helper = new DBHelper(activity);
   SQLiteDatabase db = null;
   Cursor cursor = null;
   try {
     db = helper.getReadableDatabase();
     cursor = db.query(DBHelper.TABLE_NAME, COUNT_COLUMN, null, null, null, null, null);
     cursor.moveToFirst();
     return cursor.getInt(0) > 0;
   } finally {
     close(cursor, db);
   }
 }
 @Override
 public Cursor query(
     Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
   Log.i(TAG, "query " + TAG);
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           Contacto.TABLE_NAME,
           projection,
           selection,
           selectionArgs,
           null,
           null,
           sortOrder + " ASC");
   Log.i(TAG, "query size" + cursor.getCount());
   return cursor;
 }
  @Override
  public Cursor query(
      Uri uri, String[] projectionIn, String selection, String[] selectionArgs, String sort) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    // Generate the body of the query
    int match = uriMatcher.match(uri);
    switch (match) {
      case CHATS:
      case RCSAPI_CHATS:
        qb.setTables(TABLE_CHAT);
        break;
      case MESSAGES:
      case RCSAPI_MESSAGES:
        qb.setTables(TABLE_MESSAGE);
        break;
      case CHAT_ID:
      case RCSAPI_CHAT_ID:
        qb.setTables(TABLE_CHAT);
        qb.appendWhere(ChatData.KEY_CHAT_ID + "=");
        qb.appendWhere(uri.getPathSegments().get(1));
        break;
      case MESSAGE_ID:
      case RCSAPI_MESSAGE_ID:
        qb.setTables(TABLE_MESSAGE);
        qb.appendWhere(
            MessageData.KEY_CHAT_ID
                + "= '"
                + PhoneUtils.formatNumberToInternational(uri.getPathSegments().get(1))
                + "'");
        break;
      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    SQLiteDatabase db = openHelper.getReadableDatabase();
    Cursor c = qb.query(db, projectionIn, selection, selectionArgs, null, null, sort);

    // Register the contexts ContentResolver to be notified if the cursor result set changes
    if (c != null) {
      c.setNotificationUri(getContext().getContentResolver(), uri);
    }

    return c;
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_drinks);
   // Get the drink from the intent
   int drinkNo;
   drinkNo = (Integer) getIntent().getExtras().get(EXTRA_DRINKNO);
   // Create a cursor
   try {
     SQLiteOpenHelper mcdolandDatabaseHelper = new McDolandDatabaseHelper(this);
     SQLiteDatabase db = mcdolandDatabaseHelper.getReadableDatabase();
     Cursor cursor =
         db.query(
             "DRINK",
             new String[] {"NAME", "DESCRIPTION", "IMAGE_RESOURCE_ID"},
             "_id = ?",
             new String[] {Integer.toString(drinkNo)},
             null,
             null,
             null);
     // Move to the first record in the Cursor
     if (cursor.moveToFirst()) {
       // Get the drink details from the cursor
       String nameText = cursor.getString(0);
       String descriptionText = cursor.getString(1);
       int photoId = cursor.getInt(2);
       // Populate the drink name
       TextView name = (TextView) findViewById(R.id.drinknameTV);
       name.setText(nameText);
       // Populate the drink description
       TextView description = (TextView) findViewById(R.id.drinkdescTV);
       description.setText(descriptionText);
       // Populate the drink image
       ImageView photo = (ImageView) findViewById(R.id.picIV);
       photo.setImageResource(photoId);
       photo.setContentDescription(nameText);
     }
     cursor.close();
     db.close();
   } catch (SQLiteException e) {
     Toast toast = Toast.makeText(this, "Database unavailable", Toast.LENGTH_SHORT);
     toast.show();
   }
 }
Example #18
0
  public static Client getClientByName(SQLiteOpenHelper helper, Client client) {
    SQLiteDatabase db = helper.getReadableDatabase();
    Cursor cursor =
        db.query(
            ClientTable.TABLE_NAME,
            ALL_COLUMNS,
            ClientTable.FIND_BY_NAME_QUERY,
            new String[] {client.getName()},
            null,
            null,
            null,
            null);

    Client existing_client = null;
    if (cursor.moveToFirst()) {
      existing_client = cursorToObject(cursor);
    }
    return existing_client;
  }
Example #19
0
  public static Client getClient(SQLiteOpenHelper helper, int id) {
    SQLiteDatabase db = helper.getReadableDatabase();
    Cursor cursor =
        db.query(
            ClientTable.TABLE_NAME,
            ALL_COLUMNS,
            ClientTable.FIND_BY_ID_QUERY,
            new String[] {String.valueOf(id)},
            null,
            null,
            null,
            null);

    Client client = null;
    if (cursor.moveToFirst()) {
      client = cursorToObject(cursor);
    }
    return client;
  }
Example #20
0
 public void init(SQLiteOpenHelper helper) {
   this.helper = helper;
   Note note = null;
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
   String sql = "SELECT id,date,refer,content FROM " + "note" + " WHERE nid=? ORDER BY date,id";
   String selectionArgs[] = new String[] {String.valueOf(nid)};
   SQLiteDatabase db = helper.getReadableDatabase();
   Cursor result = db.rawQuery(sql, selectionArgs);
   for (result.moveToFirst(); !result.isAfterLast(); result.moveToNext()) {
     try {
       note = new Note(result.getInt(0));
       note.setDate(sdf.parse(result.getString(1)));
       note.setRefer(result.getInt(2));
       note.setContent(result.getString(3));
       notes.add(note);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   db.close();
 }
Example #21
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ListView listBarang = (ListView) findViewById(R.id.listBarang);

    SQLiteOpenHelper aturBarangDB = new AturBarangDB(this);
    db = aturBarangDB.getReadableDatabase();

    cursor =
        db.query(
            AturBarangDB.TABEL_BARANG,
            new String[] {
              AturBarangDB.ID_BARANG,
              AturBarangDB.KODE_SKU,
              AturBarangDB.NAMA_BARANG,
              AturBarangDB.GAMBAR
            },
            null,
            null,
            null,
            null,
            AturBarangDB.NAMA_BARANG);

    BarangCursorAdapter barangCursorAdapter = new BarangCursorAdapter(this, cursor);

    listBarang.setAdapter(barangCursorAdapter);

    AdapterView.OnItemClickListener itemClickListener =
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> listView, View view, int nomorBerapa, long id) {

            clickItemListBarang(listView, view, nomorBerapa, id);
          }
        };
    listBarang.setOnItemClickListener(itemClickListener);
  }
 @Override
 public Cursor query(
     Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
   String groupBy = uri.getQueryParameter(QUERY_GROUP_BY);
   String having = uri.getQueryParameter(QUERY_HAVING);
   String limit = uri.getQueryParameter(QUERY_LIMIT);
   QueryParams queryParams = getQueryParams(uri, selection, projection);
   projection = ensureIdIsFullyQualified(projection, queryParams.table, queryParams.idColumn);
   Cursor res =
       mSqLiteOpenHelper
           .getReadableDatabase()
           .query(
               queryParams.tablesWithJoins,
               projection,
               queryParams.selection,
               selectionArgs,
               groupBy,
               having,
               sortOrder == null ? queryParams.orderBy : sortOrder,
               limit);
   res.setNotificationUri(getContext().getContentResolver(), uri);
   return res;
 }
  public WalletModel selectByUserId(int userId) {

    WalletModel wallet = new WalletModel();

    String selectQuery =
        "SELECT * FROM " + TABLE_WALLETS + " WHERE " + COLUMN_USER_ID + " = " + userId;

    SQLiteDatabase db = openHelper.getReadableDatabase();

    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
      wallet.setId(cursor.getInt(0));
      wallet.setUserId(cursor.getInt(1));
      wallet.setAddress(cursor.getString(2));
      wallet.setBalance(cursor.getString(3));
    }

    cursor.close();
    db.close();

    return wallet;
  }
  /**
   * Return a cursor for the cell broadcast table.
   *
   * @param uri the URI to query.
   * @param projection the list of columns to put into the cursor, or null.
   * @param selection the selection criteria to apply when filtering rows, or null.
   * @param selectionArgs values to replace ?s in selection string.
   * @param sortOrder how the rows in the cursor should be sorted, or null to sort from most
   *     recently received to least recently received.
   * @return a Cursor or null.
   */
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(CellBroadcastDatabaseHelper.TABLE_NAME);

    int match = sUriMatcher.match(uri);
    switch (match) {
      case CB_ALL:
        // get all broadcasts
        break;

      case CB_ALL_ID:
        // get broadcast by ID
        qb.appendWhere("(_id=" + uri.getPathSegments().get(0) + ')');
        break;

      default:
        Log.e(TAG, "Invalid query: " + uri);
        throw new IllegalArgumentException("Unknown URI: " + uri);
    }

    String orderBy;
    if (!TextUtils.isEmpty(sortOrder)) {
      orderBy = sortOrder;
    } else {
      orderBy = Telephony.CellBroadcasts.DEFAULT_SORT_ORDER;
    }

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
    if (c != null) {
      c.setNotificationUri(getContext().getContentResolver(), CONTENT_URI);
    }
    return c;
  }
Example #25
0
 public static List<Client> getAllClients(SQLiteOpenHelper helper) {
   SQLiteDatabase db = helper.getReadableDatabase();
   List<Client> clients = getAllClients(db);
   db.close();
   return clients;
 }
Example #26
0
  /** Starts a database query */
  @Override
  public Cursor query(
      final Uri uri,
      String[] projection,
      final String selection,
      final String[] selectionArgs,
      final String sort) {

    Helpers.validateSelection(selection, sAppReadableColumnsSet);

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();

    int match = sURIMatcher.match(uri);
    if (match == -1) {
      if (Constants.LOGV) {
        Log.v(Constants.TAG, "querying unknown URI: " + uri);
      }
      throw new IllegalArgumentException("Unknown URI: " + uri);
    }

    if (match == REQUEST_HEADERS_URI) {
      if (projection != null || selection != null || sort != null) {
        throw new UnsupportedOperationException(
            "Request header queries do not support " + "projections, selections or sorting");
      }
      return queryRequestHeaders(db, uri);
    }

    SqlSelection fullSelection = getWhereClause(uri, selection, selectionArgs, match);

    if (Constants.LOGVV) {
      logVerboseQueryInfo(projection, selection, selectionArgs, sort, db);
    }

    Cursor ret =
        db.query(
            DB_TABLE,
            projection,
            fullSelection.getSelection(),
            fullSelection.getParameters(),
            null,
            null,
            sort);

    if (ret != null) {
      ret = new ReadOnlyCursorWrapper(ret);
    }

    if (ret != null) {
      ret.setNotificationUri(getContext().getContentResolver(), uri);
      if (Constants.LOGVV) {
        Log.v(Constants.TAG, "created cursor " + ret + " on behalf of " + Binder.getCallingPid());
      }
    } else {
      if (Constants.LOGV) {
        Log.v(Constants.TAG, "query failed in downloads database");
      }
    }

    return ret;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
      convertView =
          mLayoutInflater.inflate(R.layout.view_inspector_profile_result_listitem, parent, false);
      viewHolder = new ViewHolder();
      viewHolder.viewClass = (TextView) convertView.findViewById(R.id.view_class);
      viewHolder.viewId = (TextView) convertView.findViewById(R.id.view_id);
      viewHolder.measureTime = (TextView) convertView.findViewById(R.id.column1);
      viewHolder.layoutTime = (TextView) convertView.findViewById(R.id.column2);
      viewHolder.drawTime = (TextView) convertView.findViewById(R.id.column3);
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }

    View view = viewSuspects.get(position);
    viewHolder.viewClass.setText(ViewUtil.getClassName(view));
    viewHolder.viewId.setText(ViewUtil.getSimpleViewId(view));

    String sql =
        "select avg("
            + ViewProfile.MEASURE_DURATION
            + "), "
            + "avg("
            + ViewProfile.LAYOUT_DURATION
            + "), "
            + "avg("
            + ViewProfile.DRAW_DURATION
            + ") "
            + " from "
            + ViewProfile.TABLE
            + " where "
            + ViewProfile.VIEW_HASHCODE
            + " = ?";
    Cursor cursor =
        db.getReadableDatabase().rawQuery(sql, new String[] {Integer.toHexString(view.hashCode())});
    if (cursor.moveToNext()) {
      double measure = cursor.getInt(0) / 1000.0;
      double layout = cursor.getInt(1) / 1000.0;
      double draw = cursor.getInt(2) / 1000.0;

      viewHolder.measureTime.setText(String.format("%4.2f", measure));
      viewHolder.layoutTime.setText(String.format("%4.2f", layout));
      viewHolder.drawTime.setText(String.format("%4.2f", draw));

      if (measure > mAvgMeasure) {
        viewHolder.measureTime.setBackgroundColor(Color.RED);
      } else if (measure == mAvgMeasure) {
        viewHolder.measureTime.setBackgroundColor(Color.YELLOW);
      } else {
        viewHolder.measureTime.setBackgroundColor(Color.TRANSPARENT);
      }

      if (layout > mAvgLayout) {
        viewHolder.layoutTime.setBackgroundColor(Color.RED);
      } else if (layout == mAvgLayout) {
        viewHolder.layoutTime.setBackgroundColor(Color.YELLOW);
      } else {
        viewHolder.layoutTime.setBackgroundColor(Color.TRANSPARENT);
      }

      if (draw > mAvgDraw) {
        viewHolder.drawTime.setBackgroundColor(Color.RED);
      } else if (draw == mAvgDraw) {
        viewHolder.drawTime.setBackgroundColor(Color.YELLOW);
      } else {
        viewHolder.drawTime.setBackgroundColor(Color.TRANSPARENT);
      }
    }
    cursor.close();

    return convertView;
  }
  /** Is called in connection with a broadcast. Handles both bootup and alarm broadcasts. */
  @Override
  public void onReceive(Context context, Intent intent) {
    SQLiteOpenHelper dBHelper = TaskProvider.getDatabaseHelperStatic(context);
    SQLiteDatabase db = dBHelper.getReadableDatabase();

    try {
      boolean silent = intent.getBooleanExtra(EXTRA_SILENT_NOTIFICATION, false);

      if (intent.hasExtra(EXTRA_TASK_START_TIME)) {
        long currentStartTime =
            intent.getLongExtra(EXTRA_TASK_START_TIME, System.currentTimeMillis());
        long nextStartTime = currentStartTime + 1000;

        // calculate UTC offset
        Time startTime = new Time(TimeZone.getDefault().getID());
        startTime.setToNow();
        long defaultMillis = startTime.toMillis(true);

        Time utcStartTime = new Time("UTC");
        utcStartTime.set(
            startTime.second,
            startTime.minute,
            startTime.hour,
            startTime.monthDay,
            startTime.month,
            startTime.year);
        long offsetMillis = utcStartTime.toMillis(true) - defaultMillis;

        long currentUTCStartTime = currentStartTime + offsetMillis;
        long nextUTCStartTime = nextStartTime + offsetMillis;

        // check for all tasks which are due since the start alarm was set plus 1 second
        String selection =
            "(( "
                + nextStartTime
                + " > "
                + Instances.INSTANCE_START
                + " AND "
                + currentStartTime
                + " <= "
                + Instances.INSTANCE_START
                + " AND "
                + Instances.IS_ALLDAY
                + " = 0 ) or ( "
                + nextUTCStartTime
                + " > "
                + Instances.INSTANCE_START
                + " AND "
                + currentUTCStartTime
                + " <= "
                + Instances.INSTANCE_START
                + " AND "
                + Instances.IS_ALLDAY
                + " = 1 )) AND "
                + Instances.IS_CLOSED
                + " = 0 AND "
                + Tasks._DELETED
                + "=0";
        Cursor cursor =
            db.query(
                Tables.INSTANCE_VIEW,
                PROJECTION,
                selection,
                null,
                null,
                null,
                Instances.INSTANCE_START);

        try {
          while (cursor.moveToNext()) {
            // inform the application
            sendTaskStartAlarmBroadcast(
                context,
                cursor.getLong(0),
                cursor.getLong(1),
                cursor.getInt(3) != 0,
                cursor.getString(2),
                silent);
          }
        } finally {
          cursor.close();
        }

        // Set the next alarm
        setUpcomingStartAlarm(context, db, nextStartTime);
      } else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())
          || ACTION_QUICKBOOT_POWERON.equals(intent.getAction())) {
        // device booted -> set upcoming alarm
        setUpcomingStartAlarm(context, db, System.currentTimeMillis());
      }
    } finally {
      if (db != null) {
        db.close();
      }
    }
  }
  @Override
  public Cursor query(
      Uri argUri,
      String[] argProjection,
      String argSelection,
      String[] argSelectionArgs,
      String argSortOrder) {
    // TODO Auto-generated method stub
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    String groupBy = null;
    String having = null;

    switch (sUriMatcher.match(argUri)) {
      case CUSTOMQUERY:
        return mOpenHelper.getReadableDatabase().rawQuery(argSelection, null);
      case MAIN:
        qb.setTables(MAIN_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(mainProjectionMap);
        }
        break;
      case MAIN_ID:
        qb.setTables(MAIN_TABLE_NAME);
        argSelection = DataProvider.Main.ID + "=" + argUri.getPathSegments().get(1);
        break;

      case SECOND_GENERATION:
        qb.setTables(SECOND_GENERATION_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(secondgenerationProjectionMap);
        }
        break;
      case SECOND_GENERATION_ID:
        qb.setTables(SECOND_GENERATION_TABLE_NAME);
        argSelection = DataProvider.Second_Generation.ID + "=" + argUri.getPathSegments().get(1);
        break;

      case THIRD_GENERATION:
        qb.setTables(THIRD_GENERATION_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(thirdgenerationProjectionMap);
        }
        break;
      case THIRD_GENERATION_ID:
        qb.setTables(THIRD_GENERATION_TABLE_NAME);
        argSelection = DataProvider.Third_Generation.ID + "=" + argUri.getPathSegments().get(1);
        break;

      case LEAF_NODE:
        qb.setTables(LEAF_NODE_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(leafnodeProjectionMap);
        }
        break;
      case LEAF_NODE_ID:
        qb.setTables(LEAF_NODE_TABLE_NAME);
        argSelection = DataProvider.Leaf_Node.ID + "=" + argUri.getPathSegments().get(1);
        break;

      case SUMMARY_VALUES:
        qb.setTables(SUMMARY_VALUES_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(summaryvaluesProjectionMap);
        }
        break;
      case SUMMARY_VALUES_ID:
        qb.setTables(SUMMARY_VALUES_TABLE_NAME);
        argSelection = DataProvider.Summary_Values.ID + "=" + argUri.getPathSegments().get(1);
        break;

      case MATERIAL_LOG:
        qb.setTables(MATERIAL_LOG_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(materiallogProjectionMap);
        }
        break;
      case MATERIAL_LOG_ID:
        qb.setTables(MATERIAL_LOG_TABLE_NAME);
        argSelection = DataProvider.Material_Log.ID + "=" + argUri.getPathSegments().get(1);
        break;
      case SERVICES:
        qb.setTables(SERVICES_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(servicesProjectionMap);
        }
        break;
      case SERVICES_ID:
        qb.setTables(SERVICES_TABLE_NAME);
        argSelection = DataProvider.Services.ID + "=" + argUri.getPathSegments().get(1);
        break;
      case TASKS:
        qb.setTables(TASKS_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(tasksProjectionMap);
        }
        break;
      case TASKS_ID:
        qb.setTables(TASKS_TABLE_NAME);
        argSelection = DataProvider.Tasks.ID + "=" + argUri.getPathSegments().get(1);
        break;
      case CHILDLEAF:
        qb.setTables(CHILD_LEAF_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(childleafProjectionMap);
        }
        break;
      case CHILDLEAF_ID:
        qb.setTables(CHILD_LEAF_TABLE_NAME);
        argSelection = DataProvider.Child_Leaf.ID + "=" + argUri.getPathSegments().get(1);
        break;
      case MILL:
        qb.setTables(MILL_TABLE_NAME);
        if (argProjection == null) {
          qb.setProjectionMap(millProjectionMap);
        }
        break;
      case MILL_ID:
        qb.setTables(MILL_TABLE_NAME);
        argSelection = DataProvider.Mill.ID + "=" + argUri.getPathSegments().get(1);
        break;

      default:
        throw new IllegalArgumentException("Unknown URI " + argUri);
    }
    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    Cursor curssor =
        qb.query(db, argProjection, argSelection, argSelectionArgs, groupBy, having, argSortOrder);
    return curssor;
  }
Example #30
0
  public SQLiteDatabase getDb() {

    return databaseHelper.getReadableDatabase();
  }