コード例 #1
0
  public QuranPageLayout(Context context) {
    super(context);
    this.context = context;
    ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR);
    Resources resources = context.getResources();
    final boolean isLandscape =
        resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    innerView = generateContentView(context, isLandscape);
    viewPaddingSmall = resources.getDimensionPixelSize(R.dimen.page_margin_small);
    viewPaddingLarge = resources.getDimensionPixelSize(R.dimen.page_margin_large);

    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    if (isLandscape && shouldWrapWithScrollView()) {
      scrollView = new ObservableScrollView(context);
      scrollView.setFillViewport(true);
      addView(scrollView, lp);
      scrollView.addView(innerView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
      scrollView.setOnScrollListener(this);
    } else {
      addView(innerView, lp);
    }

    if (areGradientsLandscape != isLandscape) {
      leftGradient = null;
      rightGradient = null;
      areGradientsLandscape = isLandscape;
    }

    if (lineDrawable == null) {
      lineDrawable = new ShapeDrawable(new RectShape());
      lineDrawable.setIntrinsicWidth(1);
      lineDrawable.setIntrinsicHeight(1);

      // these bitmaps are 11x1, so fairly small to keep both day and night versions around
      leftPageBorder =
          new BitmapDrawable(
              resources, BitmapFactory.decodeResource(resources, R.drawable.border_left));
      leftPageBorderNight =
          new BitmapDrawable(
              resources, BitmapFactory.decodeResource(resources, R.drawable.night_left_border));
      rightPageBorder =
          new BitmapDrawable(
              resources, BitmapFactory.decodeResource(resources, R.drawable.border_right));
      rightPageBorderNight =
          new BitmapDrawable(
              resources, BitmapFactory.decodeResource(resources, R.drawable.night_right_border));
    }
    setWillNotDraw(false);
  }
コード例 #2
0
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    ViewHolder viewHolder = (ViewHolder) view.getTag();

    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
    drawable.setIntrinsicHeight(24);
    drawable.setIntrinsicWidth(24);
    drawable.getPaint().setColor(Color.parseColor("#BCAAA4"));
    viewHolder.statusView.setBackground(drawable);

    String status =
        cursor.getString(cursor.getColumnIndex(LikeWorkContract.OperationEntry.COLUMN_STATUS));
    viewHolder.statusView.setText(status);

    String name =
        cursor.getString(cursor.getColumnIndex(LikeWorkContract.OperationEntry.COLUMN_NAME));
    viewHolder.nameView.setText(name);

    String catnumber =
        cursor.getString(cursor.getColumnIndex(LikeWorkContract.OperationEntry.COLUMN_CODE_1C));
    viewHolder.catnumberView.setText(catnumber);

    double amount =
        cursor.getDouble(cursor.getColumnIndex(LikeWorkContract.OperationEntry.COLUMN_AMOUNT));
    DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols();
    unusualSymbols.setDecimalSeparator('.');
    unusualSymbols.setGroupingSeparator(' ');

    DecimalFormat myFormatter = new DecimalFormat("###,###.##", unusualSymbols);
    myFormatter.setGroupingSize(3);
    viewHolder.amountView.setText(myFormatter.format(amount));

    double sum =
        cursor.getDouble(cursor.getColumnIndex(LikeWorkContract.OperationEntry.COLUMN_SUM));
    myFormatter = new DecimalFormat("###,##0.00", unusualSymbols);
    myFormatter.setGroupingSize(3);
    viewHolder.sumView.setText(myFormatter.format(sum));
  }
コード例 #3
0
  @Override
  public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
      throws XmlPullParserException, IOException {
    super.inflate(r, parser, attrs);

    TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.ShapeDrawable);

    int color = mShapeState.mPaint.getColor();
    color = a.getColor(com.android.internal.R.styleable.ShapeDrawable_color, color);
    mShapeState.mPaint.setColor(color);

    boolean dither = a.getBoolean(com.android.internal.R.styleable.ShapeDrawable_dither, false);
    mShapeState.mPaint.setDither(dither);

    setIntrinsicWidth(
        (int) a.getDimension(com.android.internal.R.styleable.ShapeDrawable_width, 0f));
    setIntrinsicHeight(
        (int) a.getDimension(com.android.internal.R.styleable.ShapeDrawable_height, 0f));

    a.recycle();

    int type;
    final int outerDepth = parser.getDepth();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
        && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
      if (type != XmlPullParser.START_TAG) {
        continue;
      }

      final String name = parser.getName();
      // call our subclass
      if (!inflateTag(name, r, parser, attrs)) {
        android.util.Log.w("drawable", "Unknown element: " + name + " for ShapeDrawable " + this);
      }
    }
  }
コード例 #4
0
ファイル: MuPDFActivity.java プロジェクト: BrandonGk/Mupdf
  public void OnSepsButtonClick(final View v) {
    if (isProofing()) {

      //  get the current page
      final int currentPage = mDocView.getDisplayedViewIndex();

      //  buid a popup menu based on the given separations
      final PopupMenu menu = new PopupMenu(this, v);

      //  This makes the popup menu display icons, which by default it does not do.
      //  I worry that this relies on the internals of PopupMenu, which could change.
      try {
        Field[] fields = menu.getClass().getDeclaredFields();
        for (Field field : fields) {
          if ("mPopup".equals(field.getName())) {
            field.setAccessible(true);
            Object menuPopupHelper = field.get(menu);
            Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
            Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
            setForceIcons.invoke(menuPopupHelper, true);
            break;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      //  get the maximum number of seps on any page.
      //  We use this to dimension an array further down
      int maxSeps = 0;
      int numPages = core.countPages();
      for (int page = 0; page < numPages; page++) {
        int numSeps = core.getNumSepsOnPage(page);
        if (numSeps > maxSeps) maxSeps = numSeps;
      }

      //  if this is the first time, create the "enabled" array
      if (mSepEnabled == null) {
        mSepEnabled = new boolean[numPages][maxSeps];
        for (int page = 0; page < numPages; page++) {
          for (int i = 0; i < maxSeps; i++) mSepEnabled[page][i] = true;
        }
      }

      //  count the seps on this page
      int numSeps = core.getNumSepsOnPage(currentPage);

      //  for each sep,
      for (int i = 0; i < numSeps; i++) {

        //				//  Robin use this to skip separations
        //				if (i==12)
        //					break;

        //  get the name
        Separation sep = core.getSep(currentPage, i);
        String name = sep.name;

        //  make a checkable menu item with that name
        //  and the separation index as the id
        MenuItem item = menu.getMenu().add(0, i, 0, name + "    ");
        item.setCheckable(true);

        //  set an icon that's the right color
        int iconSize = 48;
        int alpha = (sep.rgba >> 24) & 0xFF;
        int red = (sep.rgba >> 16) & 0xFF;
        int green = (sep.rgba >> 8) & 0xFF;
        int blue = (sep.rgba >> 0) & 0xFF;
        int color = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);

        ShapeDrawable swatch = new ShapeDrawable(new RectShape());
        swatch.setIntrinsicHeight(iconSize);
        swatch.setIntrinsicWidth(iconSize);
        swatch.setBounds(new Rect(0, 0, iconSize, iconSize));
        swatch.getPaint().setColor(color);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        item.setIcon(swatch);

        //  check it (or not)
        item.setChecked(mSepEnabled[currentPage][i]);

        //  establishing a menu item listener
        item.setOnMenuItemClickListener(
            new OnMenuItemClickListener() {
              @Override
              public boolean onMenuItemClick(MenuItem item) {
                //  someone tapped a menu item.  get the ID
                int sep = item.getItemId();

                //  toggle the sep
                mSepEnabled[currentPage][sep] = !mSepEnabled[currentPage][sep];
                item.setChecked(mSepEnabled[currentPage][sep]);
                core.controlSepOnPage(currentPage, sep, !mSepEnabled[currentPage][sep]);

                //  prevent the menu from being dismissed by these items
                item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
                item.setActionView(new View(v.getContext()));
                item.setOnActionExpandListener(
                    new MenuItem.OnActionExpandListener() {
                      @Override
                      public boolean onMenuItemActionExpand(MenuItem item) {
                        return false;
                      }

                      @Override
                      public boolean onMenuItemActionCollapse(MenuItem item) {
                        return false;
                      }
                    });
                return false;
              }
            });

        //  tell core to enable or disable each sep as appropriate
        //  but don't refresh the page yet.
        core.controlSepOnPage(currentPage, i, !mSepEnabled[currentPage][i]);
      }

      //  add one for done
      MenuItem itemDone = menu.getMenu().add(0, 0, 0, "Done");
      itemDone.setOnMenuItemClickListener(
          new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
              //  refresh the view
              mDocView.refresh(false);
              return true;
            }
          });

      //  show the menu
      menu.show();
    }
  }