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);
 }
Beispiel #2
0
 @Override
 public void onStart() {
   super.onStart();
   LoaderManager lm = getLoaderManager();
   if (lm.getLoader(1) != null) {
     lm.initLoader(1, null, this);
   }
   getLoaderManager().initLoader(1, null, this);
 }
        @Override
        public void onLoadFinished(
            final Loader<List<StoredBlock>> loader, final List<StoredBlock> blocks) {
          adapter.replace(blocks);

          final Loader<Set<Transaction>> transactionLoader =
              loaderManager.getLoader(ID_TRANSACTION_LOADER);
          if (transactionLoader != null && transactionLoader.isStarted())
            transactionLoader.forceLoad();
        }
  @Override
  public void onCursorChanged(Cursor cursor) {
    if (mAdapter == null) {
      // The adapter is set in onAttach(), and is guaranteed to be non-null. We have magically
      // received an onCursorChanged without attaching to an activity. Ignore this cursor
      // change.
      return;
    }
    // FLAG: There is a problem here:
    // If the cursor changes, and new items are added at an earlier position than
    // the current item, we will switch photos here. Really we should probably
    // try to find a photo with the same url and move the cursor to that position.
    if (cursor.moveToPosition(mPosition) && !isPhotoBound()) {
      mCallback.onCursorChanged(this, cursor);

      final LoaderManager manager = getLoaderManager();

      final Loader<BitmapResult> fakePhotoLoader =
          manager.getLoader(PhotoViewCallbacks.BITMAP_LOADER_PHOTO);
      if (fakePhotoLoader != null) {
        final PhotoBitmapLoaderInterface loader = (PhotoBitmapLoaderInterface) fakePhotoLoader;
        mResolvedPhotoUri = mAdapter.getPhotoUri(cursor);
        loader.setPhotoUri(mResolvedPhotoUri);
        loader.forceLoad();
      }

      if (!mThumbnailShown) {
        final Loader<BitmapResult> fakeThumbnailLoader =
            manager.getLoader(PhotoViewCallbacks.BITMAP_LOADER_THUMBNAIL);
        if (fakeThumbnailLoader != null) {
          final PhotoBitmapLoaderInterface loader =
              (PhotoBitmapLoaderInterface) fakeThumbnailLoader;
          mThumbnailUri = mAdapter.getThumbnailUri(cursor);
          loader.setPhotoUri(mThumbnailUri);
          loader.forceLoad();
        }
      }
    }
  }
Beispiel #5
0
    @Override
    public void resetDataset(int viewIndex) {
      Log.d(LOGTAG, "Resetting dataset: " + viewIndex);

      final LoaderManager lm = getLoaderManager();

      // Release any resources associated with the dataset if
      // it's currently loaded in memory.
      final Loader<?> datasetLoader = lm.getLoader(viewIndex);
      if (datasetLoader != null) {
        datasetLoader.reset();
      }
    }
Beispiel #6
0
  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);
    }
  }
  @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();
  }