Android Open Source - Aviary-Android-SDK Aviary Seek Bar






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.widget;
//from  w  w w .j av  a2 s  .c  o  m
import android.content.Context;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet;
import android.widget.SeekBar;

import com.aviary.android.feather.R;

public class AviarySeekBar extends SeekBar {

  @SuppressWarnings ( "unused" )
  private static final String LOG_TAG = "seekbar";

  protected Drawable mSecondary;
  protected Drawable mSecondaryInverted;
  protected Drawable mSecondaryCenter;

  protected int mSecondaryMinWidth;
  protected int mSecondaryMinHeight;
  protected double mSecondaryCenterOffset;
  protected int mBackgroundOffset;
  private int mRealWidth;
  private Drawable mCurrentDrawable;

  public AviarySeekBar ( Context context ) {
    this( context, null );
  }

  public AviarySeekBar ( Context context, AttributeSet attrs ) {
    this( context, attrs, R.attr.aviarySeekBarStyle );
  }

  public AviarySeekBar ( Context context, AttributeSet attrs, int defStyle ) {
    super( context, attrs, defStyle );

    final Theme theme = context.getTheme();
    TypedArray typedArray = theme.obtainStyledAttributes( attrs, R.styleable.AviarySeekBar, defStyle, 0 );
    Drawable thumb = typedArray.getDrawable( R.styleable.AviarySeekBar_aviarySeekBarThumb );
    int offset = typedArray.getDimensionPixelOffset( R.styleable.AviarySeekBar_aviarySeekBarThumbOffset, 0 );
    mSecondary = typedArray.getDrawable( R.styleable.AviarySeekBar_aviarySeekBarSecondary );
    mSecondaryInverted = typedArray.getDrawable( R.styleable.AviarySeekBar_aviarySeekBarSecondaryInverted );
    mSecondaryCenter = typedArray.getDrawable( R.styleable.AviarySeekBar_aviarySeekBarSecondaryCenter );
    typedArray.recycle();

    mSecondaryMinWidth = mSecondary.getIntrinsicWidth();
    mSecondaryMinHeight = mSecondary.getIntrinsicHeight();
    mSecondaryCenterOffset = (double) mSecondaryMinWidth * 0.5;

    mBackgroundOffset = (int) ( getProgressDrawable().getIntrinsicWidth() * 0.12 );

    // thumb.setAlpha( 50 );
    setThumb( thumb );
    setThumbOffset( offset );
  }

  @Override
  protected void drawableStateChanged() {
    super.drawableStateChanged();

    int[] state = getDrawableState();
    mSecondary.setState( state );
    mSecondaryInverted.setState( state );
    mSecondaryCenter.setState( state );
  }

  @Override
  protected void onSizeChanged( int w, int h, int oldw, int oldh ) {
    super.onSizeChanged( w, h, oldw, oldh );
    mRealWidth = ( w - ( getPaddingLeft() + getPaddingRight() ) ) - mBackgroundOffset;
  }

  @Override
  protected synchronized void onDraw( Canvas canvas ) {

    if ( mRealWidth < 1 ) return;

    double progress = ( getProgress() - 50.0 ) / 50.0; // 0.0 - 1.0
    double center = -getPaddingLeft() + ( getWidth() / 2.0 );
    double w = progress * mRealWidth / 2.0;

    if ( getProgressDrawable() instanceof LayerDrawable ) {

      // retrieve the current drawable state ( selected, pressed, ... )
      LayerDrawable layerDrawable = (LayerDrawable) getProgressDrawable();

      int left = 0;
      int right = 0;
      Drawable drawable = null;

      if ( progress > 0 ) {
        // right
        left = (int) ( center - mSecondaryCenterOffset );
        right = (int) ( left + w + mSecondaryCenterOffset );
        drawable = mSecondary;
      } else if ( progress < 0 ) {
        // left
        left = (int) ( center + w );
        right = (int) ( center + mSecondaryCenterOffset );
        drawable = mSecondaryInverted;
      }

      if ( ( right - left ) < mSecondaryMinWidth ) {
        // center
        left = (int) ( center - ( mSecondaryMinWidth / 2 ) );
        right = (int) ( center + ( mSecondaryMinWidth / 2 ) );
        drawable = mSecondaryCenter;
      }

      if ( mCurrentDrawable != drawable ) {
        mCurrentDrawable = drawable;
        layerDrawable.setDrawableByLayerId( android.R.id.secondaryProgress, mCurrentDrawable );
      }

      if ( null != drawable ) {
        drawable.setBounds( left, 0, right, mSecondaryMinHeight );
      }
    }
    super.onDraw( canvas );
  }
}




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