Android Open Source - Aviary-Android-SDK Aviary Nav Bar View Flipper






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  ww .ja v  a  2 s . c om
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewDebug.ExportedProperty;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextSwitcher;
import android.widget.ViewFlipper;
import android.widget.ViewSwitcher.ViewFactory;

import com.aviary.android.feather.R;

public class AviaryNavBarViewFlipper extends ViewFlipper implements ViewFactory {

  public static interface OnToolbarClickListener {
    void onDoneClick();

    void onApplyClick();

    void onRestoreClick();
  };

  private static class ViewState {
    static enum Status {
      Open, Close, Restore
    };

    void setCurrent( Status newState ) {
      previous = current;
      current = newState;
    }

    Status current;
    Status previous;
  }

  TextSwitcher mTextSwitcher;
  Button mButton2, mButton1, mButton3;
  OnToolbarClickListener mListener;
  ProgressBar mProgress1, mProgress2;

  boolean mClickable;
  ViewState mStatus;

  public AviaryNavBarViewFlipper ( Context context ) {
    super( context );
  }

  public AviaryNavBarViewFlipper ( Context context, AttributeSet attrs ) {
    super( context, attrs );
  }

  private boolean mButtonSizeChanged;

  @Override
  protected void onLayout( boolean changed, int left, int top, int right, int bottom ) {
    super.onLayout( changed, left, top, right, bottom );

    if ( !mButtonSizeChanged ) {
      int button1Size = mButton1.getMeasuredWidth();
      int button2Size = mButton2.getMeasuredWidth();

      int maxSize = Math.max( button1Size, button2Size );

      if ( button1Size != maxSize ) {
        mButton1.setWidth( maxSize );
      }

      if ( button2Size != maxSize ) {
        mButton2.setWidth( maxSize );
      }

      mButtonSizeChanged = true;
    }
  }

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

    mStatus = new ViewState();
    mStatus.current = ViewState.Status.Close;
    mStatus.previous = ViewState.Status.Close;

    mTextSwitcher = (TextSwitcher) findViewById( R.id.navbar_text2 );

    // done
    mButton1 = (Button) findViewById( R.id.navbar_button1 );
    mProgress1 = (ProgressBar) findViewById( R.id.navbar_progress1 );

    // apply
    mButton2 = (Button) findViewById( R.id.navbar_button2 );
    mProgress2 = (ProgressBar) findViewById( R.id.navbar_progress2 );

    // restore
    mButton3 = (Button) findViewById( R.id.navbar_button3 );

    mTextSwitcher.setFactory( this );

    mButton3.setOnClickListener( new OnClickListener() {

      @Override
      public void onClick( View v ) {
        if ( null != mListener && isClickable() && restored() ) {
          mListener.onRestoreClick();
        }
      }
    } );

    mButton2.setOnClickListener( new OnClickListener() {

      @Override
      public void onClick( View v ) {
        if ( mListener != null && isClickable() && opened() ) {
          mListener.onApplyClick();
        }
      }
    } );

    mButton1.setOnClickListener( new OnClickListener() {

      @Override
      public void onClick( View v ) {
        if ( mListener != null && isClickable() && !opened() ) {
          mListener.onDoneClick();
        }
      }
    } );
  }

  public void open() {
    if ( !opened() ) {
      mStatus.setCurrent( ViewState.Status.Open );
      setDisplayedChild( 1 );
    }
  }

  public void close() {
    if ( !closed() ) {
      mStatus.setCurrent( ViewState.Status.Close );
      setDisplayedChild( 0 );
    }
  }

  public void toggleRestore( boolean enabled ) {
    if ( enabled ) {
      if ( !restored() ) {
        mStatus.setCurrent( ViewState.Status.Restore );
        setDisplayedChild( 2 );
      }
    } else {
      if ( restored() ) {
        ViewState.Status oldState = mStatus.previous;
        if ( oldState == ViewState.Status.Close ) {
          close();
        } else {
          open();
        }
      }
    }
  }

  public boolean opened() {
    return mStatus.current == ViewState.Status.Open;
  }

  public boolean closed() {
    return mStatus.current == ViewState.Status.Close;
  }

  public boolean restored() {
    return mStatus.current == ViewState.Status.Restore;
  }

  @Override
  public void setClickable( boolean clickable ) {
    mClickable = clickable;
  }

  @Override
  @ExportedProperty
  public boolean isClickable() {
    return mClickable;
  }

  public void setOnToolbarClickListener( OnToolbarClickListener listener ) {
    mListener = listener;
  }

  public void setApplyEnabled( boolean enabled ) {
    mButton2.setEnabled( enabled );
  }

  public void setApplyVisible( boolean visible ) {
    mButton2.setVisibility( visible ? View.VISIBLE : View.INVISIBLE );
  }

  public void setApplyProgressVisible( boolean visible ) {
    mProgress2.setVisibility( visible ? View.VISIBLE : View.INVISIBLE );
  }

  public boolean getApplyProgressVisible() {
    return mProgress2.getVisibility() == View.VISIBLE;
  }

  public void setDoneEnabled( boolean enabled ) {
    mButton1.setEnabled( enabled );
  }

  public void setDoneProgressVisible( boolean visible ) {
    mProgress1.setVisibility( visible ? View.VISIBLE : View.INVISIBLE );
  }

  public boolean getDoneProgressVisible() {
    return mProgress1.getVisibility() == View.VISIBLE;
  }

  public void setTitle( CharSequence text ) {
    setTitle( text, true );
  }

  public void setTitle( CharSequence text, boolean animate ) {
    if ( !animate ) {
      Animation inAnimation = mTextSwitcher.getInAnimation();
      Animation outAnimation = mTextSwitcher.getOutAnimation();
      mTextSwitcher.setInAnimation( null );
      mTextSwitcher.setOutAnimation( null );
      mTextSwitcher.setText( text );
      mTextSwitcher.setInAnimation( inAnimation );
      mTextSwitcher.setOutAnimation( outAnimation );
    } else {
      mTextSwitcher.setText( text );
    }
  }

  public void setTitle( int resourceId ) {
    setTitle( resourceId, true );
  }

  public void setTitle( int resourceId, boolean animate ) {
    setTitle( getContext().getResources().getString( resourceId ), animate );
  }

  @Override
  public View makeView() {
    View view = LayoutInflater.from( getContext() ).inflate( R.layout.aviary_navbar_text, null );

    return view;
  }
}




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