Android Open Source - Aviary-Android-SDK Plugin Divider Drawable






From Project

Back to project page Aviary-Android-SDK.

License

The source code is released under:

AVIARY API TERMS OF USE Full Legal Agreement The following terms and conditions and the terms and conditions at http://www.aviary.com/terms (collectively, the ?Terms??) govern your use of any and ...

If you think the Android project Aviary-Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.aviary.android.feather.graphics;
// w  ww .  jav a 2 s .com
import android.content.Context;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.FontMetrics;
import android.graphics.Paint.Style;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;

import com.aviary.android.feather.R;
import com.aviary.android.feather.utils.TypefaceUtils;

public class PluginDividerDrawable extends Drawable {

  public static final String LOG_TAG = "Drawable";

  private float mTextSize = 10;

  private int mStrokeWidth;
  private int mStrokeColor;
  private int mFillColor;
  private float mTextDivider;

  private FontMetrics mMetrics;
  private String mLabel;
  private Paint mTextPaint;
  private Paint mTextStrokePaint;

  private Rect mBounds;
  private int mWidth;
  private int mHeight;

  public PluginDividerDrawable ( Context context, int styleid, final String string ) {

    Typeface font = Typeface.DEFAULT;

    Theme theme = context.getTheme();
    TypedArray array = theme.obtainStyledAttributes( null, R.styleable.AviaryPluginDividerDrawable, R.attr.aviaryEffectThumbDividerTextStyle, -1 );

    mFillColor = array.getColor( R.styleable.AviaryPluginDividerDrawable_android_textColor, 0 );
    mStrokeWidth = array.getDimensionPixelSize( R.styleable.AviaryPluginDividerDrawable_aviary_strokeWidth, 0 );
    mStrokeColor = array.getColor( R.styleable.AviaryPluginDividerDrawable_aviary_strokeColor, 0 );
    mTextDivider = array.getFloat( R.styleable.AviaryPluginDividerDrawable_aviary_textPerc, 0.9f );

    String fontname = array.getString( R.styleable.AviaryPluginDividerDrawable_aviary_typeface );

    try {
      font = TypefaceUtils.createFromAsset( context.getAssets(), fontname );
    } catch ( Throwable t ) {
      t.printStackTrace();
    }

    array.recycle();

    mLabel = string;

    mTextPaint = new Paint( Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.DEV_KERN_TEXT_FLAG );
    mTextPaint.setColor( mFillColor );
    mTextPaint.setStyle( Style.FILL );

    if ( null != font ) {
      mTextPaint.setTypeface( font );
    }

    mTextStrokePaint = new Paint( mTextPaint );
    mTextStrokePaint.setColor( mStrokeColor );
    mTextStrokePaint.setStyle( Style.STROKE );
    mTextStrokePaint.setStrokeWidth( mStrokeWidth );

    mBounds = new Rect();
    mMetrics = new FontMetrics();
  }

  public void setTitle( final String value ) {
    mLabel = value;
    onBoundsChange( getBounds() );
    invalidateSelf();
  }

  public final String getTitle() {
    return mLabel;
  }

  @Override
  public int getOpacity() {
    return PixelFormat.TRANSLUCENT;
  }

  @Override
  public void setAlpha( int alpha ) {}

  @Override
  public void setColorFilter( ColorFilter cf ) {}

  @Override
  public void clearColorFilter() {}

  @Override
  public int getIntrinsicHeight() {
    return super.getIntrinsicHeight();
  }

  @Override
  public int getIntrinsicWidth() {
    return super.getIntrinsicWidth();
  }

  @Override
  public int getMinimumHeight() {
    return super.getMinimumHeight();
  }

  @Override
  public int getMinimumWidth() {
    return super.getMinimumWidth();
  }

  @Override
  protected void onBoundsChange( Rect bounds ) {
    super.onBoundsChange( bounds );

    mWidth = bounds.width();
    mHeight = bounds.height();

    onTextBoundsChanged();
  }

  private int mTextY = 0;
  private int mMaxHeight;

  protected final void onTextBoundsChanged() {
    mTextSize = mWidth * mTextDivider;

    mTextPaint.setTextSize( mTextSize );
    mTextStrokePaint.setTextSize( mTextSize );
    mTextPaint.getTextBounds( mLabel, 0, mLabel.length(), mBounds );
    mTextPaint.getFontMetrics( mMetrics );

    mTextY = (int) ( ( ( mWidth / 2.0f ) + mTextSize / 2.0f ) - mMetrics.bottom / 2.0f );

    /*
     * if ( mBounds.width() >= ( mHeight * 0.95 ) ) {
     * if ( mLabel.length() > 4 ) {
     * mLabel = mLabel.substring( 0, mLabel.length() - 4 ) + "..";
     * onTextBoundsChanged();
     * }
     * }
     */

    mMaxHeight = (int) ( (double) mHeight * 0.9 );
  }

  @Override
  public void draw( Canvas canvas ) {

    int saveCount = canvas.save( Canvas.MATRIX_SAVE_FLAG );
    canvas.rotate( -90 );
    canvas.translate( -mHeight + ( mHeight - mBounds.width() ) / 2, mTextY );

    if ( mBounds.width() > mMaxHeight ) {
      float diff = (float) mMaxHeight / mBounds.width();
      canvas.scale( diff, diff, mBounds.centerX(), mBounds.centerY() );
    }

    if ( mStrokeWidth > 0 ) {
      canvas.drawText( mLabel, 0, 0, mTextStrokePaint );
    }
    canvas.drawText( mLabel, 0, 0, mTextPaint );
    canvas.restoreToCount( saveCount );

  }

}




Java Source Code List

com.aviary.android.feather.AlertActivity.java
com.aviary.android.feather.AviaryMainController.java
com.aviary.android.feather.FeatherActivity.java
com.aviary.android.feather.async_tasks.AsyncImageManager.java
com.aviary.android.feather.async_tasks.DownloadImageAsyncTask.java
com.aviary.android.feather.async_tasks.ExifTask.java
com.aviary.android.feather.effects.AbstractContentPanel.java
com.aviary.android.feather.effects.AbstractOptionPanel.java
com.aviary.android.feather.effects.AbstractPanelLoaderService.java
com.aviary.android.feather.effects.AbstractPanel.java
com.aviary.android.feather.effects.AdjustEffectPanel.java
com.aviary.android.feather.effects.BordersPanel.java
com.aviary.android.feather.effects.ColorSplashPanel.java
com.aviary.android.feather.effects.CropPanel.java
com.aviary.android.feather.effects.DelayedSpotDrawPanel.java
com.aviary.android.feather.effects.DrawingPanel.java
com.aviary.android.feather.effects.EffectsPanel.java
com.aviary.android.feather.effects.EnhanceEffectPanel.java
com.aviary.android.feather.effects.MemePanel.java
com.aviary.android.feather.effects.NativeEffectRangePanel.java
com.aviary.android.feather.effects.SimpleStatusMachine.java
com.aviary.android.feather.effects.SliderEffectPanel.java
com.aviary.android.feather.effects.StickersPanel.java
com.aviary.android.feather.effects.TextPanel.java
com.aviary.android.feather.effects.TiltShiftPanel.java
com.aviary.android.feather.graphics.CdsPreviewTransformer.java
com.aviary.android.feather.graphics.GalleryBottomIndicatorDrawable.java
com.aviary.android.feather.graphics.GalleryTopIndicatorDrawable.java
com.aviary.android.feather.graphics.GlowBitmapDrawable.java
com.aviary.android.feather.graphics.GlowDrawable.java
com.aviary.android.feather.graphics.PluginDividerDrawable.java
com.aviary.android.feather.graphics.PreviewFillColorDrawable.java
com.aviary.android.feather.graphics.PreviewSpotDrawable.java
com.aviary.android.feather.graphics.RepeatableHorizontalDrawable.java
com.aviary.android.feather.opengl.AviaryGLSurfaceView.java
com.aviary.android.feather.utils.PackIconCallable.java
com.aviary.android.feather.utils.SimpleBitmapCache.java
com.aviary.android.feather.utils.ThreadUtils.java
com.aviary.android.feather.utils.TypefaceUtils.java
com.aviary.android.feather.utils.UIUtils.java
com.aviary.android.feather.widget.AdjustImageView.java
com.aviary.android.feather.widget.AviaryAbsSpinner.java
com.aviary.android.feather.widget.AviaryAdapterView.java
com.aviary.android.feather.widget.AviaryBadgeToolLayout.java
com.aviary.android.feather.widget.AviaryBottomBarViewFlipper.java
com.aviary.android.feather.widget.AviaryButton.java
com.aviary.android.feather.widget.AviaryEdgeEffect.java
com.aviary.android.feather.widget.AviaryGalleryTopIndicatorView.java
com.aviary.android.feather.widget.AviaryGallery.java
com.aviary.android.feather.widget.AviaryHighlightImageButton.java
com.aviary.android.feather.widget.AviaryImageRestoreSwitcher.java
com.aviary.android.feather.widget.AviaryImageSwitcher.java
com.aviary.android.feather.widget.AviaryNavBarViewFlipper.java
com.aviary.android.feather.widget.AviarySeekBar.java
com.aviary.android.feather.widget.AviaryTextView.java
com.aviary.android.feather.widget.AviaryToast.java
com.aviary.android.feather.widget.AviaryToggleButton.java
com.aviary.android.feather.widget.AviaryWheel.java
com.aviary.android.feather.widget.AviaryWorkspaceIndicator.java
com.aviary.android.feather.widget.AviaryWorkspace.java
com.aviary.android.feather.widget.CellLayout.java
com.aviary.android.feather.widget.CropImageView.java
com.aviary.android.feather.widget.DrawableHighlightView.java
com.aviary.android.feather.widget.EffectThumbLayout.java
com.aviary.android.feather.widget.HighlightView.java
com.aviary.android.feather.widget.IAPBuyButton.java
com.aviary.android.feather.widget.IAPDialogDetail.java
com.aviary.android.feather.widget.IAPDialogList.java
com.aviary.android.feather.widget.IAPDialogMain.java
com.aviary.android.feather.widget.ImageViewDrawableOverlay.java
com.aviary.android.feather.widget.ImageViewSpotDraw.java
com.aviary.android.feather.widget.ImageViewTiltiShiftTouch.java
com.aviary.android.feather.widget.ImageViewTouchAndDraw.java
com.aviary.android.feather.widget.PointCloud.java
com.aviary.android.feather.widget.ScrollerRunnable.java
com.aviary.android.feather.widget.VibrationHelper.java
com.aviary.android.feather.widget.VibrationWidget.java