コード例 #1
0
 /** Loads initial blog posts. */
 public void loadPosts(boolean reload) {
   LoaderManager loaderManager = getLoaderManager();
   if (reload) {
     loaderManager.restartLoader(BLOG_LOADER_ID, null, this);
   } else {
     loaderManager.initLoader(BLOG_LOADER_ID, null, this);
   }
 }
コード例 #2
0
  public static void restartFromCursor(
      LoaderManager manager, int loaderId, LoaderCallbacks<Cursor> callbacks, Cursor c) {
    // If there urls without in-memory favicons, trigger a new loader
    // to load the images from disk to memory.
    ArrayList<String> urls = getUrlsWithoutFavicon(c);
    if (urls.size() > 0) {
      Bundle args = new Bundle();
      args.putStringArrayList(FAVICONS_LOADER_URLS_ARG, urls);

      manager.restartLoader(loaderId, args, callbacks);
    }
  }
コード例 #3
0
 private void restartGroupingLoader() {
   mGroupingCursor = null;
   if (mManager == null) {
     // can happen after an orientation change in ExportDialogFragment, when resetting multiple
     // accounts
     mManager = getLoaderManager();
   }
   if (mManager.getLoader(GROUPING_CURSOR) != null
       && !mManager.getLoader(GROUPING_CURSOR).isReset())
     mManager.restartLoader(GROUPING_CURSOR, null, this);
   else mManager.initLoader(GROUPING_CURSOR, null, this);
 }
コード例 #4
0
  /**
   * Helper method to restart the loader for the next page of data.
   *
   * <p>Starts a new or restarts an existing {@link android.content.Loader} in this manager,
   * registers the callbacks to it, and (if the activity/fragment is currently started) starts
   * loading it. If a loader with the same id has previously been started it will automatically be
   * destroyed when the new loader completes its work. The callback will be delivered before the old
   * loader is destroyed.
   *
   * @param loaderId
   * @param context
   * @param loaderManager
   * @param loaderListener
   * @param url
   * @param pagingDirection
   * @param dataSource
   */
  public static void restartLoader(
      @PhotosLoaderId int loaderId,
      Context context,
      LoaderManager loaderManager,
      PhotosLoaderListener loaderListener,
      @NonNull String url,
      int pagingDirection,
      int dataSource) {
    Bundle args = new Bundle(3);
    args.putInt(ARG_DATASOURCE, dataSource);
    args.putString(ARG_PAGE_URL, url);
    args.putInt(ARG_PAGING_DIRECTION, pagingDirection);

    // call loader manager's restart loader
    loaderManager.restartLoader(loaderId, args, new PhotosLoaderCallbacks(context, loaderListener));
  }
コード例 #5
0
ファイル: HomePager.java プロジェクト: sandhua/gecko-dev
  /**
   * Loads and initializes the pager.
   *
   * @param fm FragmentManager for the adapter
   */
  public void show(
      LoaderManager lm, FragmentManager fm, String panelId, PropertyAnimator animator) {
    mLoaded = true;
    mInitialPanelId = panelId;

    // Only animate on post-HC devices, when a non-null animator is given
    final boolean shouldAnimate = (animator != null && Build.VERSION.SDK_INT >= 11);

    final HomeAdapter adapter = new HomeAdapter(mContext, fm);
    adapter.setOnAddPanelListener(mAddPanelListener);
    adapter.setCanLoadHint(!shouldAnimate);
    setAdapter(adapter);

    setVisibility(VISIBLE);

    // Don't show the tabs strip until we have the
    // list of panels in place.
    mTabStrip.setVisibility(View.INVISIBLE);

    // Load list of panels from configuration. Restart the loader if necessary.
    if (mRestartLoader) {
      lm.restartLoader(LOADER_ID_CONFIG, null, mConfigLoaderCallbacks);
      mRestartLoader = false;
    } else {
      lm.initLoader(LOADER_ID_CONFIG, null, mConfigLoaderCallbacks);
    }

    if (shouldAnimate) {
      animator.addPropertyAnimationListener(
          new PropertyAnimator.PropertyAnimationListener() {
            @Override
            public void onPropertyAnimationStart() {
              setLayerType(View.LAYER_TYPE_HARDWARE, null);
            }

            @Override
            public void onPropertyAnimationEnd() {
              setLayerType(View.LAYER_TYPE_NONE, null);
              adapter.setCanLoadHint(true);
            }
          });

      ViewHelper.setAlpha(this, 0.0f);

      animator.attach(this, PropertyAnimator.Property.ALPHA, 1.0f);
    }
  }
コード例 #6
0
  @Override
  public void onDayClicked(AdapterView<?> adapter, View view, int position, long id, Day day) {
    Log.d(TAG, "Click on some day");
    loaderManager = getSupportLoaderManager();
    Bundle bundle = new Bundle();
    String dateString = FormatHelper.shortLocalDateFormatter.format(day.getCal().getTime());
    Log.d(TAG, "select date " + dateString);
    try {
      bundle.putString(
          START_OF_DAY, FormatHelper.fromLocalDateTimeStringToUTCString(dateString + " 12:00 AM"));
      bundle.putString(
          END_OF_DAY, FormatHelper.fromLocalDateTimeStringToUTCString(dateString + " 11:59 PM"));
      switch (day.getDayOfWeek()) {
        case Calendar.MONDAY:
          bundle.putString(DAY_OF_WEEK, "1");
          break;
        case Calendar.TUESDAY:
          bundle.putString(DAY_OF_WEEK, "2");
          break;
        case Calendar.WEDNESDAY:
          bundle.putString(DAY_OF_WEEK, "4");
          break;
        case Calendar.THURSDAY:
          bundle.putString(DAY_OF_WEEK, "8");
          break;
        case Calendar.FRIDAY:
          bundle.putString(DAY_OF_WEEK, "16");
          break;
        case Calendar.SATURDAY:
          bundle.putString(DAY_OF_WEEK, "32");
          break;
        case Calendar.SUNDAY:
          bundle.putString(DAY_OF_WEEK, "64");
          break;
      }

      loaderManager.restartLoader(0, bundle, this);
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
コード例 #7
0
ファイル: LookFragment.java プロジェクト: vidak92/Catroid
  private void loadImageIntoCatroid(Intent intent) {
    String originalImagePath = "";

    // get path of image - will work for most applications
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
      originalImagePath = bundle.getString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT);
    }

    if (originalImagePath == null || originalImagePath.equals("")) {
      Bundle arguments = new Bundle();
      arguments.putParcelable(LOADER_ARGUMENTS_IMAGE_URI, intent.getData());

      LoaderManager loaderManager = getLoaderManager();

      if (loaderManager.getLoader(ID_LOADER_MEDIA_IMAGE) == null) {
        loaderManager.initLoader(ID_LOADER_MEDIA_IMAGE, arguments, this);
      } else {
        loaderManager.restartLoader(ID_LOADER_MEDIA_IMAGE, arguments, this);
      }
    } else {
      copyImageToCatroid(originalImagePath);
    }
  }
コード例 #8
0
 @Override
 public void onContentsLoaded(ContentListFragment fragment, List<RepositoryContents> contents) {
   if (contents == null) {
     return;
   }
   mContentCache.put(fragment.getPath(), new ArrayList<>(contents));
   if (fragment.getPath() == null) {
     for (RepositoryContents content : contents) {
       if (RepositoryContents.TYPE_FILE.equals(content.getType())) {
         if (content.getName().equals(".gitmodules")) {
           LoaderManager lm = getActivity().getSupportLoaderManager();
           lm.restartLoader(LOADER_MODULEMAP, null, mGitModuleCallback);
           break;
         }
       }
     }
   }
   if (mInitialPathToLoad != null && !mInitialPathToLoad.isEmpty()) {
     String itemToLoad = mInitialPathToLoad.get(0);
     boolean found = false;
     for (RepositoryContents content : contents) {
       if (RepositoryContents.TYPE_DIR.equals(content.getType())) {
         if (content.getPath().equals(itemToLoad)) {
           onTreeSelected(content);
           found = true;
           break;
         }
       }
     }
     if (found) {
       mInitialPathToLoad.remove(0);
     } else {
       mInitialPathToLoad = null;
     }
   }
 }
コード例 #9
0
 private void getList() {
   mLoader.restartLoader(0, null, this);
 }
コード例 #10
0
 @Override
 public void retryLoading() {
   loader = new RxCitiesLoader((Context) citiesView);
   loaderManager.restartLoader(CITIES_LOADER, Bundle.EMPTY, this);
 }
コード例 #11
0
 @Override
 public void onResume() {
   gestor.restartLoader(IMAGENES_LOADER, null, this);
   super.onResume();
 }
コード例 #12
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    final MyExpenses ctx = (MyExpenses) getActivity();
    Context wrappedCtx = DialogUtils.wrapContext2(ctx);
    if (mTransaction == null) {
      return new AlertDialog.Builder(wrappedCtx)
          .setMessage("Transaction has been deleted")
          .create();
    }
    final LayoutInflater li = LayoutInflater.from(wrappedCtx);
    View view = li.inflate(R.layout.transaction_detail, null);
    int title;
    boolean type =
        mTransaction.amount.getAmountMinor() > 0 ? ExpenseEdit.INCOME : ExpenseEdit.EXPENSE;
    if (mTransaction instanceof SplitTransaction) {
      // TODO: refactor duplicated code with SplitPartList
      title = R.string.split_transaction;
      View emptyView = view.findViewById(R.id.empty);
      Resources.Theme theme = ctx.getTheme();
      TypedValue color = new TypedValue();
      theme.resolveAttribute(R.attr.colorExpense, color, true);
      final int colorExpense = color.data;
      theme.resolveAttribute(R.attr.colorIncome, color, true);
      final int colorIncome = color.data;

      ListView lv = (ListView) view.findViewById(R.id.list);
      // Create an array to specify the fields we want to display in the list
      String[] from = new String[] {KEY_LABEL_MAIN, KEY_AMOUNT};

      // and an array of the fields we want to bind those fields to
      int[] to = new int[] {R.id.category, R.id.amount};

      final String categorySeparator, commentSeparator;
      categorySeparator = " : ";
      commentSeparator = " / ";
      // Now create a simple cursor adapter and set it to display
      mAdapter =
          new SimpleCursorAdapter(ctx, R.layout.split_part_row, null, from, to, 0) {
            /* (non-Javadoc)
             * calls {@link #convText for formatting the values retrieved from the cursor}
             * @see android.widget.SimpleCursorAdapter#setViewText(android.widget.TextView, java.lang.String)
             */
            @Override
            public void setViewText(TextView v, String text) {
              switch (v.getId()) {
                case R.id.amount:
                  text = Utils.convAmount(text, mTransaction.amount.getCurrency());
              }
              super.setViewText(v, text);
            }
            /* (non-Javadoc)
             * manipulates the view for amount (setting expenses to red) and
             * category (indicate transfer direction with => or <=
             * @see android.widget.CursorAdapter#getView(int, android.view.View, android.view.ViewGroup)
             */
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
              View row = super.getView(position, convertView, parent);
              TextView tv1 = (TextView) row.findViewById(R.id.amount);
              Cursor c = getCursor();
              c.moveToPosition(position);
              int col = c.getColumnIndex(KEY_AMOUNT);
              long amount = c.getLong(col);
              if (amount < 0) {
                tv1.setTextColor(colorExpense);
                // Set the background color of the text.
              } else {
                tv1.setTextColor(colorIncome);
              }
              TextView tv2 = (TextView) row.findViewById(R.id.category);
              if (Build.VERSION.SDK_INT < 11) tv2.setTextColor(Color.WHITE);
              String catText = tv2.getText().toString();
              if (DbUtils.getLongOrNull(c, KEY_TRANSFER_PEER) != null) {
                catText = ((amount < 0) ? "=&gt; " : "&lt;= ") + catText;
              } else {
                Long catId = DbUtils.getLongOrNull(c, KEY_CATID);
                if (catId == null) {
                  catText = getString(R.string.no_category_assigned);
                } else {
                  col = c.getColumnIndex(KEY_LABEL_SUB);
                  String label_sub = c.getString(col);
                  if (label_sub != null && label_sub.length() > 0) {
                    catText += categorySeparator + label_sub;
                  }
                }
              }
              col = c.getColumnIndex(KEY_COMMENT);
              String comment = c.getString(col);
              if (comment != null && comment.length() > 0) {
                catText += (catText.equals("") ? "" : commentSeparator) + "<i>" + comment + "</i>";
              }
              tv2.setText(Html.fromHtml(catText));
              return row;
            }
          };
      lv.setAdapter(mAdapter);
      lv.setEmptyView(emptyView);
      LoaderManager manager = ctx.getSupportLoaderManager();
      if (manager.getLoader(MyExpenses.SPLIT_PART_CURSOR) != null
          && !manager.getLoader(MyExpenses.SPLIT_PART_CURSOR).isReset())
        manager.restartLoader(MyExpenses.SPLIT_PART_CURSOR, null, this);
      else manager.initLoader(MyExpenses.SPLIT_PART_CURSOR, null, this);
    } else {
      view.findViewById(R.id.SplitContainer).setVisibility(View.GONE);
      if (mTransaction instanceof Transfer) {
        title = R.string.transfer;
        ((TextView) view.findViewById(R.id.AccountLabel)).setText(R.string.transfer_from_account);
        ((TextView) view.findViewById(R.id.CategoryLabel)).setText(R.string.transfer_to_account);
      } else title = type ? R.string.income : R.string.expense;
    }
    String accountLabel = Account.getInstanceFromDb(mTransaction.accountId).label;
    if (mTransaction instanceof Transfer) {
      ((TextView) view.findViewById(R.id.Account))
          .setText(type ? mTransaction.label : accountLabel);
      ((TextView) view.findViewById(R.id.Category))
          .setText(type ? accountLabel : mTransaction.label);
    } else {
      ((TextView) view.findViewById(R.id.Account)).setText(accountLabel);
      if ((mTransaction.catId != null && mTransaction.catId > 0)) {
        ((TextView) view.findViewById(R.id.Category)).setText(mTransaction.label);
      } else {
        view.findViewById(R.id.CategoryRow).setVisibility(View.GONE);
      }
    }
    ((TextView) view.findViewById(R.id.Date))
        .setText(
            DateFormat.getDateInstance(DateFormat.FULL).format(mTransaction.getDate())
                + " "
                + DateFormat.getTimeInstance(DateFormat.SHORT).format(mTransaction.getDate()));
    ((TextView) view.findViewById(R.id.Amount))
        .setText(
            Utils.formatCurrency(
                new Money(
                    mTransaction.amount.getCurrency(),
                    Math.abs(mTransaction.amount.getAmountMinor()))));
    if (!mTransaction.comment.equals(""))
      ((TextView) view.findViewById(R.id.Comment)).setText(mTransaction.comment);
    else view.findViewById(R.id.CommentRow).setVisibility(View.GONE);
    if (!mTransaction.referenceNumber.equals(""))
      ((TextView) view.findViewById(R.id.Number)).setText(mTransaction.referenceNumber);
    else view.findViewById(R.id.NumberRow).setVisibility(View.GONE);
    if (!mTransaction.payee.equals(""))
      ((TextView) view.findViewById(R.id.Payee)).setText(mTransaction.payee);
    else view.findViewById(R.id.PayeeRow).setVisibility(View.GONE);
    if (mTransaction.methodId != null)
      ((TextView) view.findViewById(R.id.Method))
          .setText(PaymentMethod.getInstanceFromDb(mTransaction.methodId).getDisplayLabel());
    else view.findViewById(R.id.MethodRow).setVisibility(View.GONE);
    if (Account.getInstanceFromDb(mTransaction.accountId).type.equals(Type.CASH))
      view.findViewById(R.id.StatusRow).setVisibility(View.GONE);
    else {
      TextView tv = (TextView) view.findViewById(R.id.Status);
      tv.setBackgroundColor(mTransaction.crStatus.color);
      tv.setText(mTransaction.crStatus.toString());
    }
    return new AlertDialog.Builder(getActivity())
        .setTitle(title)
        .setView(view)
        .setNegativeButton(android.R.string.ok, this)
        .setPositiveButton(R.string.menu_edit, this)
        .create();
  }