/**
   * 进行数据周使用量查询
   *
   * @param sqlDataBase sqlDataBase
   * @param year 输入查询的年份2000.
   * @param month 输入查询的月份.
   * @param monthDay 单月的日期
   * @param weekDay 星期
   * @return 星期一的具体的日期格式
   */
  private String selectWeekStart(
      SQLiteDatabase sqlDataBase, int year, int month, int monthDay, int weekDay) {
    // if (weekDay == 0) {
    // weekDay = 6;
    // } else {
    // weekDay = weekDay - 1;
    // }
    // Calendar calendar = Calendar.getInstance();
    // // calendar.getFirstDayOfWeek();
    // Logs.d(TAG, calendar.get(Calendar.DAY_OF_WEEK) + "DAY_OF_WEEK");
    // calendar.setTimeInMillis(calendar.getTimeInMillis() - 1000 * 60 * 60
    // * 24);
    // Logs.d(TAG, calendar.get(Calendar.DAY_OF_WEEK) + "DAY_OF_WEEK");
    // Logs.d(TAG, Calendar.SUNDAY + "sunday");

    Calendar c = Calendar.getInstance();
    int mondayPlus = getMondayPlus(c);
    Logs.d(TAG, "mondayPlus=" + mondayPlus);
    GregorianCalendar currentDate = new GregorianCalendar();
    Logs.d(TAG, "currentDate=" + currentDate);
    currentDate.add(GregorianCalendar.DATE, mondayPlus);
    Date monday = currentDate.getTime();
    Logs.d(TAG, "monday=" + monday);
    c.setTime(monday);
    year = c.get(Calendar.YEAR);
    month = c.get(Calendar.MONTH) + 1;
    int day = c.get(Calendar.DAY_OF_MONTH);
    weekStart = MonthDay.formatDate(year, month, day);
    // String month2;
    // if (month < 10)
    // month2 = "0" + month;
    // else {
    // month2 = month + "";
    // }
    // String day2;
    // if (day < 10) {
    // day2 = "0" + day;
    // } else {
    // day2 = day + "";
    // }
    // Logs.d(TAG, "month2=" + month2);
    // String weekStart = null;
    // StringBuilder stringB = new StringBuilder();
    // stringB.append(c.get(Calendar.YEAR)).append("-").append(month2)
    // .append("-").append(day2);
    // weekStart = stringB.toString();
    return weekStart;
  }
示例#2
0
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    Logs.d(TAG, "onKeyDown");
    if (keyCode == KeyEvent.KEYCODE_BACK) {
      if (isExit == false) {
        isExit = true;
        Toast.makeText(context, "再按一次即退出监控", Toast.LENGTH_SHORT).show();
        tExit.cancel();
        task.cancel();
        tExit = new Timer();
        task =
            new TimerTask() {
              @Override
              public void run() {
                isExit = false;
              }
            };
        tExit.schedule(task, 8000);

        return false;
      }
      OnExit exit = new OnExit();
      exit.onExit(context);
      tExit.cancel();
      task.cancel();
    }
    return super.onKeyDown(keyCode, event);
  }
  private HashMap<Integer, DatauidHash> SelectUiddownloadAndupload(
      SQLiteDatabase sqlDataBase,
      HashMap<Integer, DatauidHash> mp,
      int[] uidnumbers,
      int flagFire) {
    initTime();
    weekStart = selectWeekStart(sqlDataBase, year, month, monthDay, weekDay);
    if (SQLStatic.uiddataCache == null) {
      mp = SelectUiddownloadAnduploadAll(sqlDataBase, mp, uidnumbers);
    } else {

      switch (flagFire) {
        case 1:
          Logs.d(TAG, weekStart);
          mp = SelectUiddownloadAnduploadPart(sqlDataBase, mp, uidnumbers, flagFire);
          break;
        case 2:
          mp = SelectUiddownloadAnduploadPart(sqlDataBase, mp, uidnumbers, flagFire);
          break;
        default:
          mp = SelectUiddownloadAnduploadPart(sqlDataBase, mp, uidnumbers, flagFire);
          break;
      }
    }
    return mp;
  }
 @Override
 public void onReceive(Context context, Intent intent) {
   Logs.d(TAG, "beforeDate");
   this.context = context;
   alset.StartAlarm(context);
   if (SQLStatic.ConnectSleepWaiting == false) {
     new AsyncTaskonWaitingDayChange().execute(context);
   }
 }
示例#5
0
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   Logs.d(TAG, "onCreateOptionsMenu");
   showMenuMain();
   return false;
 }
 /**
  * 依据网络状态选择对应的之前流量。
  *
  * @param mySQL
  * @param uidnumber
  * @param network
  * @return a[0]为总计流量a[1]总计上传流量a[2]总计下载流量
  */
 private long[] getSQLuidtotalData(
     SQLiteDatabase mySQL, int uidnumber, String network, int flagFire) {
   StringBuilder string = new StringBuilder();
   String strDate = getDateString(mySQL, flagFire);
   if (network == NETWORK_FLAG) {
     // select oldest upload and download 之前记录的数据的查询操作
     string =
         string
             .append(SelectTable)
             .append("uid")
             .append(uidnumber)
             .append(Where)
             .append("other='")
             .append(NETWORK_FLAG)
             .append("'")
             .append(AND_A)
             .append(" type=")
             .append(2)
             .append(strDate);
   } else {
     string =
         string
             .append(SelectTable)
             .append("uid")
             .append(uidnumber)
             .append(Where)
             .append("other='")
             .append(WIFI_FLAG)
             .append("'")
             .append(AND_A)
             .append(" type=")
             .append(2)
             .append(strDate);
   }
   // Logs.d(TAG, string.toString());
   try {
     cur = mySQL.rawQuery(string.toString(), null);
   } catch (Exception e) {
     Logs.d(TAG, "error+CreateTable" + string);
     SQLHelperUidSelectFail selectFail = new SQLHelperUidSelectFail();
     selectFail.selectfails(mySQL, "uid" + uidnumber, uidnumber);
   }
   long[] a = new long[3];
   if (cur != null) {
     try {
       int minup = cur.getColumnIndex("upload");
       int mindown = cur.getColumnIndex("download");
       // showLog(cur.getColumnIndex("minute") + "");
       if (cur.moveToFirst()) {
         a[1] = cur.getLong(minup);
         a[2] = cur.getLong(mindown);
       }
       while (cur.moveToNext()) {
         a[1] += cur.getLong(minup);
         a[2] += cur.getLong(mindown);
       }
     } catch (Exception e) {
       Logs.d(TAG, "cur-searchfail" + e);
     }
   }
   if (cur != null) {
     cur.close();
   }
   a[0] = a[1] + a[2];
   return a;
 }
 @Override
 public void onReceive(Context context, Intent intent) {
   Logs.d(TAG, "afterDate");
   resetRecordData(context);
 }