Android Open Source - Aviary-Android-SDK Aviary Badge Tool 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  ww.ja v a2  s  .  co m
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aviary.android.feather.AviaryMainController;
import com.aviary.android.feather.FeatherActivity;
import com.aviary.android.feather.R;
import com.aviary.android.feather.library.content.ToolEntry;
import com.aviary.android.feather.library.filters.FilterLoaderFactory.Filters;
import com.aviary.android.feather.library.services.BadgeService;
import com.aviary.android.feather.library.services.BadgeService.OnToolBadgesUpdateListener;

/**
 * Special {@link LinearLayout} view which will manage the visibility
 * of the badge icon.<br />
 * This view will register itself as listener to the {@link BadgeService} service.<br />
 * When there is an update to the badges this view will manage the visibility change of
 * its badge-view.<br />
 * It is also used to mark the badge as read. When the user clicks to open a panel, the
 * {@link #markAsRead()} should be
 * called and this method will first hide the badge view and secondly it will invoke the
 * {@link BadgeService#markAsRead(Filters)}.
 * 
 * @author alessandro
 */
public class AviaryBadgeToolLayout extends LinearLayout implements OnToolBadgesUpdateListener {

  public static final class ViewHolder {
    public ToolEntry entry;
  }

  static final String LOG_TAG = "AviaryBadgeToolLayout";

  /** the badge-view contained in the xml layout */
  View mBadgeView;
  /** tool icon */
  ImageView mImageView;
  /** tool label */
  TextView mTextView;
  /** {@link BadgeService} reference */
  BadgeService mBadgeService;

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

  public AviaryBadgeToolLayout ( Context context, AttributeSet attrs ) {
    this( context, attrs, 0 );
  }

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

  @Override
  public void setTag( Object tag ) {
    super.setTag( tag );
    onTagChanged( tag );
  }

  protected void onTagChanged( Object tag ) {
    if ( null != tag ) {
      ToolEntry entry = (ToolEntry) tag;
      mImageView.setImageResource( entry.iconResourceId );
      mTextView.setText( entry.labelResourceId );

      if ( null != getContext() ) {
        setContentDescription( getContext().getString( entry.labelResourceId ) );
      }

      if( null != mBadgeService ) {
        onToolBadgesUpdate( mBadgeService );
      }
      postInvalidate();
    }
  }

  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();
    mBadgeView = findViewById( R.id.aviary_badge );
    mTextView = (TextView) findViewById( R.id.aviary_text );
    mImageView = (ImageView) findViewById( R.id.aviary_image );

    registerToService();
  }

  protected void registerToService() {
    FeatherActivity activity = (FeatherActivity) getContext();
    if ( null != activity ) {
      AviaryMainController controller = activity.getMainController();
      if ( null != controller ) {
        mBadgeService = controller.getService( BadgeService.class );
        mBadgeService.registerOnToolBadgesUpdateListener( this );
      }
    }
  }

  protected void removeFromService() {
    if ( null != mBadgeService ) {
      mBadgeService.removeOnToolBadgesUpdateListener( this );
    }
  }

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

    if ( null != mBadgeService ) {
      onToolBadgesUpdate( mBadgeService );
    }
  }

  @Override
  protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
  }

  @Override
  protected void finalize() throws Throwable {
    removeFromService();
    super.finalize();
  }

  @Override
  public void onToolBadgesUpdate( BadgeService service ) {

    ToolEntry entry = (ToolEntry) getTag();

    if ( null != entry ) {
      if ( service.getIsActive( entry.name ) ) {
        showBadge();
      } else {
        hideBadge();
      }
    }
  }

  @Override
  public void onToolBadgeSingleUpdate( BadgeService service, Filters type ) {

    ToolEntry entry = (ToolEntry) getTag();

    if ( null != entry && entry.name == type ) {

      Log.i( LOG_TAG, "onToolBadgeSingleUpdate: " + type );

      if ( service.getIsActive( entry.name ) ) {
        showBadge();
      } else {
        hideBadge();
      }
    }
  }

  protected void hideBadge() {
    if ( null != mBadgeView ) {
      mBadgeView.setVisibility( View.GONE );
    }
  }

  protected void showBadge() {
    if ( null != mBadgeView ) {
      mBadgeView.setVisibility( View.VISIBLE );
    }
  }

}




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