private void resolveTheme() {
   // Look up the guidedStepTheme in the currently specified theme.  If it exists,
   // replace the theme with its value.
   FragmentActivity activity = getActivity();
   if (mTheme == -1 && !isGuidedStepTheme(activity)) {
     // Look up the guidedStepTheme in the activity's currently specified theme.  If it
     // exists, replace the theme with its value.
     int resId = R.attr.guidedStepTheme;
     TypedValue typedValue = new TypedValue();
     boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
     if (DEBUG) Log.v(TAG, "Found guided step theme reference? " + found);
     if (found) {
       ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
       if (isGuidedStepTheme(themeWrapper)) {
         mTheme = typedValue.resourceId;
         mThemeWrapper = themeWrapper;
       } else {
         found = false;
         mThemeWrapper = null;
       }
     }
     if (!found) {
       Log.e(TAG, "GuidedStepSupportFragment does not have an appropriate theme set.");
     }
   } else if (mTheme != -1) {
     mThemeWrapper = new ContextThemeWrapper(activity, mTheme);
   }
 }
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      FragmentActivity activity = getActivity();
      Context themedContext = null;
      if (!isGuidedStepTheme(activity)) {
        // Look up the guidedStepTheme in the activity's currently specified theme.  If it
        // exists, replace the theme with its value.
        int resId = R.attr.guidedStepTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG) Log.v(TAG, "Found guided step theme reference? " + found);
        if (found) {
          ContextThemeWrapper themeWrapper =
              new ContextThemeWrapper(activity, typedValue.resourceId);
          if (isGuidedStepTheme(themeWrapper)) {
            themedContext = themeWrapper;
          }
        }
        if (!found) {
          Log.e(TAG, "GuidedStepSupportFragment does not have an appropriate theme set.");
        }
      }

      if (themedContext != null) {
        inflater = inflater.cloneInContext(themedContext);
      }

      return inflater.inflate(R.layout.lb_guidedstep_background, container, false);
    }
Exemplo n.º 3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final FragmentActivity ctx = getActivity();
    View v = inflater.inflate(R.layout.split_parts_list, container, false);
    View emptyView = v.findViewById(R.id.empty);
    Resources.Theme theme = ctx.getTheme();
    TypedValue color = new TypedValue();
    theme.resolveAttribute(R.attr.colorExpense, color, true);
    colorExpense = color.data;
    theme.resolveAttribute(R.attr.colorIncome, color, true);
    colorIncome = color.data;
    balanceTv = (TextView) v.findViewById(R.id.end);

    ListView lv = (ListView) v.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 = " / ";
    ctx.getSupportLoaderManager().initLoader(ExpenseEdit.TRANSACTION_CURSOR, getArguments(), this);
    ctx.getSupportLoaderManager().initLoader(ExpenseEdit.SUM_CURSOR, getArguments(), this);
    // 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,
                        Account.getInstanceFromDb(getArguments().getLong(KEY_ACCOUNTID)).currency);
            }
            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);
            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);
    lv.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            Intent i = new Intent(ctx, ExpenseEdit.class);
            i.putExtra(KEY_ROWID, id);
            // i.putExtra("operationType", operationType);
            startActivityForResult(i, MyExpenses.EDIT_TRANSACTION_REQUEST);
          }
        });
    registerForContextMenu(lv);
    return v;
  }