Android Open Source - Aviary-Android-SDK Effect Thumb Layout






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;
/*w w  w.ja va2 s.  co m*/
import it.sephiroth.android.library.imagezoom.easing.Easing;
import it.sephiroth.android.library.imagezoom.easing.Linear;
import android.content.Context;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.Checkable;
import android.widget.RelativeLayout;

import com.aviary.android.feather.R;

public class EffectThumbLayout extends RelativeLayout implements Checkable {

  private boolean mChecked;
  private boolean mOpened;
  private int mThumbAnimationDuration;
  private View mHiddenView;
  private View mImageView;

  public EffectThumbLayout ( Context context, AttributeSet attrs ) {
    super( context, attrs );
    init( context, attrs, R.attr.aviaryEffectThumbLayoutStyle );
    mOpened = false;
    mChecked = false;
  }

  private void init( Context context, AttributeSet attrs, int defStyle ) {
    Log.i( VIEW_LOG_TAG, "init" );
    Theme theme = context.getTheme();
    TypedArray array = theme.obtainStyledAttributes( attrs, R.styleable.AviaryEffectThumbLayout, defStyle, 0 );
    mThumbAnimationDuration = array.getInteger( R.styleable.AviaryEffectThumbLayout_aviary_animationDuration, 100 );
    array.recycle();
  }

  public boolean isOpened() {
    return mOpened;
  }

  @Override
  public boolean isChecked() {
    return mChecked;
  }

  @Override
  public void setChecked( boolean checked ) {
    boolean animate = isChecked() != checked;
    mChecked = checked;

    if ( null != getParent() && animate ) {
      if ( checked ) {
        open();
      } else {
        close();
      }
    } else {
      mOpened = checked;
    }
  }

  @Override
  public void toggle() {
    setChecked( !isChecked() );
  }

  @Override
  public void setSelected( boolean selected ) {
    boolean animate = isSelected() != selected;
    super.setSelected( selected );

    if ( null != getParent() && animate ) {
      if ( selected ) {
        open();
      } else {
        close();
      }
    } else {
      mOpened = selected;
    }

  }

  void open() {
    animateView( mThumbAnimationDuration, false );
  }

  void close() {
    animateView( mThumbAnimationDuration, true );
  }

  void setIsOpened( boolean value ) {
    mOpened = value;

    if ( null != mHiddenView ) {
      postSetIsOpened( mOpened );
    }

  }

  protected void postSetIsOpened( final boolean opened ) {

    if ( null == mHiddenView ) return;

    if ( mHiddenView.getHeight() < 1 ) {
      if ( null != getHandler() ) {
        getHandler().postDelayed( new Runnable() {

          @Override
          public void run() {
            postSetIsOpened( opened );
          }
        }, 10 );
      }
      return;
    }

    mHiddenView.setVisibility( mOpened ? View.VISIBLE : View.INVISIBLE );

    boolean shouldApplyLayoutParams = false;
    int targetBottomMargin = opened ? mHiddenView.getHeight() + ( mHiddenView.getPaddingTop() + mHiddenView.getPaddingBottom() ) : 0;

    LayoutParams params = (LayoutParams) mImageView.getLayoutParams();

    if ( params.bottomMargin != targetBottomMargin ) {
      shouldApplyLayoutParams = true;
      params.bottomMargin = targetBottomMargin;
    }

    if ( shouldApplyLayoutParams ) {
      mImageView.setLayoutParams( params );
      requestLayout();
    }
  }

  @Override
  protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    mHiddenView = null;
    mImageView = null;
  }

  @Override
  protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    mOpened = isChecked();
    mHiddenView = findViewById( R.id.aviary_hidden );
    mImageView = findViewById( R.id.aviary_image );
    setIsOpened( mOpened );
  }

  @Override
  protected void onRestoreInstanceState( Parcelable state ) {
    super.onRestoreInstanceState( state );
  }

  @Override
  protected Parcelable onSaveInstanceState() {
    return super.onSaveInstanceState();
  }

  protected void postAnimateView( final int durationMs, final boolean isClosing ) {
    if ( null != getHandler() ) {
      getHandler().post( new Runnable() {

        @Override
        public void run() {
          animateView( durationMs, isClosing );
        }
      } );
    }
  }

  protected void animateView( final int durationMs, final boolean isClosing ) {

    if ( !isClosing ) {
      mHiddenView.setVisibility( View.VISIBLE );
    }

    final boolean is_valid = mHiddenView != null && mImageView != null;

    if ( !is_valid ) return;

    if ( mHiddenView.getHeight() == 0 ) {
      postAnimateView( durationMs, isClosing );
    }

    final long startTime = System.currentTimeMillis();
    final float startHeight = 0;
    final float endHeight = isClosing ? 0 : ( mHiddenView.getHeight() + mHiddenView.getPaddingTop() + mHiddenView.getPaddingBottom() );

    final Easing easing = new Linear();

    if ( null != mHiddenView && null != getParent() && null != getHandler() ) {

      getHandler().post( new Runnable() {

        @Override
        public void run() {

          if ( null != mHiddenView ) {
            long now = System.currentTimeMillis();

            float currentMs = Math.min( durationMs, now - startTime );
            float newHeight = (float) easing.easeOut( currentMs, startHeight, endHeight, durationMs );

            int height = isClosing ? (int) ( endHeight - newHeight ) : (int) newHeight;

            LayoutParams params = (LayoutParams) mImageView.getLayoutParams();
            params.bottomMargin = height;

            mImageView.setLayoutParams( params );

            if ( currentMs < durationMs ) {
              if ( null != getHandler() ) {
                getHandler().post( this );
                invalidate();
              }
            } else {
              mOpened = !isClosing;
              if ( null != getParent() ) {
                if ( !mOpened ) mHiddenView.setVisibility( View.INVISIBLE );
                else mHiddenView.setVisibility( View.VISIBLE );
              }
              postInvalidate();
            }
          }
        }
      } );
    }
  }

}




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