コード例 #1
0
  private void getUsageInfo() {
    final Calendar now = Calendar.getInstance();
    final Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(Calendar.YEAR, now.get(Calendar.YEAR));
    cal.set(Calendar.MONTH, now.get(Calendar.MONTH));
    final int dayMin = now.getActualMinimum(Calendar.DAY_OF_MONTH);
    final int dayMax = now.getActualMaximum(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.DAY_OF_MONTH, dayMin);
    cal.setTimeZone(now.getTimeZone());
    final Date start = cal.getTime();
    cal.set(Calendar.DAY_OF_MONTH, dayMax);
    cal.add(Calendar.DATE, 1);
    final Date end = cal.getTime();
    final TaskRunnable<Object[], NetworkUsageInfo, NetworkUsageSummaryPreferences> task;
    task =
        new TaskRunnable<Object[], NetworkUsageInfo, NetworkUsageSummaryPreferences>() {
          @Override
          public NetworkUsageInfo doLongOperation(Object[] params) throws InterruptedException {
            final int[] network = {ConnectivityManager.TYPE_MOBILE};
            return NetworkUsageInfo.get(
                (Context) params[0], (Date) params[1], (Date) params[2], dayMin, dayMax, network);
          }

          @Override
          public void callback(NetworkUsageSummaryPreferences handler, NetworkUsageInfo result) {
            handler.setUsage(result);
          }
        };
    task.setResultHandler(this);
    task.setParams(new Object[] {getContext(), start, end});
    AsyncManager.runBackgroundTask(task);
  }
コード例 #2
0
  @Override
  public boolean triggerRefresh() {
    super.triggerRefresh();
    AsyncManager.runBackgroundTask(
        new TaskRunnable<Object, long[][], CursorStatusesFragment>() {
          @Override
          public long[][] doLongOperation(Object o) throws InterruptedException {
            final long[][] result = new long[3][];
            result[0] = getAccountIds();
            result[2] = getNewestStatusIds(result[0]);
            return result;
          }

          @Override
          public void callback(CursorStatusesFragment fragment, long[][] result) {
            fragment.getStatuses(result[0], result[1], result[2]);
          }
        }.setResultHandler(this));
    return true;
  }
コード例 #3
0
  @Override
  public void onLoadMoreContents(boolean fromStart) {
    if (fromStart) return;
    //noinspection ConstantConditions
    super.onLoadMoreContents(fromStart);
    AsyncManager.runBackgroundTask(
        new TaskRunnable<Object, long[][], CursorStatusesFragment>() {
          @Override
          public long[][] doLongOperation(Object o) throws InterruptedException {
            final long[][] result = new long[3][];
            result[0] = getAccountIds();
            result[1] = getOldestStatusIds(result[0]);
            return result;
          }

          @Override
          public void callback(CursorStatusesFragment fragment, long[][] result) {
            fragment.getStatuses(result[0], result[1], result[2]);
          }
        }.setResultHandler(this));
  }