コード例 #1
0
 public static int getCurrentStation(Context context) {
   int currentStation = FIXED_STATION_FREQ;
   Cursor cur =
       context
           .getContentResolver()
           .query(
               Station.CONTENT_URI,
               new String[] {Station.COLUMN_STATION_FREQ},
               Station.COLUMN_STATION_TYPE + "=?",
               new String[] {String.valueOf(STATION_TYPE_CURRENT)},
               null);
   if (null != cur) {
     try {
       if (cur.moveToFirst()) {
         currentStation = cur.getInt(0);
         if (currentStation < LOWEST_STATION || currentStation > HIGHEST_STATION) {
           // Update the database
           currentStation = FIXED_STATION_FREQ;
           setCurrentStation(context, currentStation);
           FMTxLogUtils.d(
               TAG,
               "FMTransmitterStation.getCurrentStation: current station is invalid, use default!");
         }
       }
     } finally {
       cur.close();
       cur = null;
     }
   }
   FMTxLogUtils.d(TAG, "getCurrentStation: " + currentStation);
   return currentStation;
 }
コード例 #2
0
 public static void insertStationToDB(
     Context context, String stationName, int stationFreq, int stationType) {
   FMTxLogUtils.d(TAG, "insertStationToDB Start");
   ContentValues values = new ContentValues(3);
   values.put(Station.COLUMN_STATION_NAME, stationName);
   values.put(Station.COLUMN_STATION_FREQ, stationFreq);
   values.put(Station.COLUMN_STATION_TYPE, stationType);
   context.getContentResolver().insert(Station.CONTENT_URI, values);
   FMTxLogUtils.d(TAG, "insertStationToDB End");
 }
コード例 #3
0
 public static void cleanSearchedStations(Context context) {
   FMTxLogUtils.d(TAG, "cleanSearchedStations Start");
   context
       .getContentResolver()
       .delete(
           Station.CONTENT_URI,
           Station.COLUMN_STATION_TYPE + "=" + String.valueOf(STATION_TYPE_SEARCHED),
           null);
   FMTxLogUtils.d(TAG, "cleanSearchedStations End");
 }
コード例 #4
0
 public static void deleteStationInDB(Context context, int stationFreq, int stationType) {
   context
       .getContentResolver()
       .delete(
           Station.CONTENT_URI,
           Station.COLUMN_STATION_FREQ + "=? AND " + Station.COLUMN_STATION_TYPE + "=?",
           new String[] {String.valueOf(stationFreq), String.valueOf(stationType)});
   FMTxLogUtils.d(TAG, "deleteStationInDB: Freq = " + stationFreq + ", FreqType = " + stationType);
 }
コード例 #5
0
 public static void updateStationToDB(
     Context context, String stationName, int stationFreq, int stationType) {
   ContentValues values = new ContentValues(3);
   values.put(Station.COLUMN_STATION_NAME, stationName);
   values.put(Station.COLUMN_STATION_FREQ, stationFreq);
   values.put(Station.COLUMN_STATION_TYPE, stationType);
   context
       .getContentResolver()
       .update(
           Station.CONTENT_URI,
           values,
           Station.COLUMN_STATION_FREQ + "=? AND " + Station.COLUMN_STATION_TYPE + "=?",
           new String[] {String.valueOf(stationFreq), String.valueOf(stationType)});
   FMTxLogUtils.d(TAG, "updateStationToDB: Name= " + stationName + ", FreqType = " + stationType);
 }
コード例 #6
0
 public static boolean isDBEmpty(Context context) {
   boolean isEmpty = true;
   Cursor cur =
       context
           .getContentResolver()
           .query(
               Station.CONTENT_URI, new String[] {Station.COLUMN_STATION_NAME}, null, null, null);
   if (null != cur) {
     if (cur.getCount() > 0) {
       isEmpty = false;
     }
     cur.close();
     cur = null;
   }
   FMTxLogUtils.d(TAG, "isDBEmpty: " + isEmpty);
   return isEmpty;
 }
コード例 #7
0
 public static void setCurrentStation(Context context, int iStation) {
   ContentValues values = new ContentValues(3);
   values.put(Station.COLUMN_STATION_NAME, CURRENT_STATION_NAME);
   values.put(Station.COLUMN_STATION_FREQ, iStation);
   values.put(Station.COLUMN_STATION_TYPE, STATION_TYPE_CURRENT);
   if (getStationCount(context, STATION_TYPE_CURRENT) == 1) {
     context
         .getContentResolver()
         .update(
             Station.CONTENT_URI,
             values,
             Station.COLUMN_STATION_NAME + "=? AND " + Station.COLUMN_STATION_TYPE + "=?",
             new String[] {CURRENT_STATION_NAME, String.valueOf(STATION_TYPE_CURRENT)});
   } else {
     context.getContentResolver().insert(Station.CONTENT_URI, values);
   }
   FMTxLogUtils.d(TAG, "setCurrentStation: " + iStation);
 }
コード例 #8
0
 public static int getStationCount(Context context, int stationType) {
   int stationCount = 0;
   Cursor cur =
       context
           .getContentResolver()
           .query(
               Station.CONTENT_URI,
               COLUMNS,
               Station.COLUMN_STATION_TYPE + "=?",
               new String[] {String.valueOf(stationType)},
               null);
   if (null != cur) {
     stationCount = cur.getCount();
     cur.close();
     cur = null;
   }
   FMTxLogUtils.d(TAG, "getStationCount: " + stationCount);
   return stationCount;
 }
コード例 #9
0
  public static boolean isStationExist(Context context, int stationFreq, int stationType) {
    boolean isExist = false;
    Cursor cur =
        context
            .getContentResolver()
            .query(
                Station.CONTENT_URI,
                new String[] {Station.COLUMN_STATION_NAME},
                Station.COLUMN_STATION_FREQ + "=? AND " + Station.COLUMN_STATION_TYPE + "=?",
                new String[] {String.valueOf(stationFreq), String.valueOf(stationType)},
                null);

    if (null != cur) {
      if (cur.getCount() > 0) {
        isExist = true;
      }
      cur.close();
      cur = null;
    }
    FMTxLogUtils.d(TAG, "isStationExist: " + isExist);
    return isExist;
  }
コード例 #10
0
 public static void cleanDB(Context context) {
   FMTxLogUtils.d(TAG, "cleanDB Start");
   context.getContentResolver().delete(Station.CONTENT_URI, null, null);
   FMTxLogUtils.d(TAG, "cleanDB End");
 }