Codota Logo
ToolbarIndicator
Code IndexAdd Codota to your IDE (free)

How to use
ToolbarIndicator
in
cn.nekocode.toolbarindicator

Best Java code snippets using cn.nekocode.toolbarindicator.ToolbarIndicator (Showing top 8 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ArrayList a =
  • Codota Iconnew ArrayList<String>()
  • Codota Iconnew ArrayList()
  • Codota Iconnew ArrayList<Object>()
  • Smart code suggestions by Codota
}
origin: nekocode/ToolbarIndicator

private void createIndicators(ViewPager viewPager) {
  removeAllViews();
  int count = viewPager.getAdapter().getCount();
  if (count <= 0) {
    return;
  }
  addIndicator(mIndicatorBackground);
  for (int i = 1; i < count; i++) {
    addIndicator(mIndicatorUnselectedBackground);
  }
  mAnimationOut.setTarget(getChildAt(mCurrentPosition));
  mAnimationOut.start();
}
origin: nekocode/ToolbarIndicator

private void addIndicator(@DrawableRes int backgroundDrawableId) {
  View Indicator = new View(getContext());
  Indicator.setBackgroundResource(backgroundDrawableId);
  addView(Indicator, mIndicatorWidth, mIndicatorHeight);
  LayoutParams lp = (LayoutParams) Indicator.getLayoutParams();
  lp.leftMargin = mIndicatorMargin;
  lp.rightMargin = mIndicatorMargin;
  Indicator.setLayoutParams(lp);
  mAnimationOut.setTarget(Indicator);
  mAnimationOut.start();
}
origin: nekocode/ToolbarIndicator

public void setViewPager(ViewPager viewPager) {
  mViewpager = viewPager;
  mCurrentPosition = mViewpager.getCurrentItem();
  createIndicators(viewPager);
  mViewpager.addOnPageChangeListener(this);
  onPageSelected(mCurrentPosition);
  this.title = new String[viewPager.getAdapter().getCount()];
  for(int i=0; i<title.length; i++) {
    title[i] = String.valueOf(viewPager.getAdapter().getPageTitle(i));
  }
}
origin: nekocode/ToolbarIndicator

private void init(Context context, AttributeSet attrs) {
  setOrientation(LinearLayout.HORIZONTAL);
  setGravity(Gravity.CENTER);
  handleTypedArray(context, attrs);
  mAnimationOut = AnimatorInflater.loadAnimator(context, mAnimatorResId);
  if (mAnimatorReverseResId == -1) {
    mAnimationIn = AnimatorInflater.loadAnimator(context, mAnimatorResId);
    mAnimationIn.setInterpolator(new ReverseInterpolator());
  } else {
    mAnimationIn = AnimatorInflater.loadAnimator(context, mAnimatorReverseResId);
  }
  setPadding(0, dip2px(TEXT_SIZE + 8), 0, 0);
  setBackgroundColor(0x00000000);
  textPaint = new TextPaint();
  textPaint.setColor(Color.WHITE);
  textPaint.setAntiAlias(true);
  textPaint.setTextSize(dip2px(TEXT_SIZE));
  textPaint.setTextAlign(Paint.Align.CENTER);
}
origin: nekocode/ToolbarIndicator

@Override
protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  int width = getWidth();
  int center = width/2;
  int x, y;
  int alpha;
  int alphaOffsetXMax = (int) (center * 1.0f);
  float ratio = (scrollX * 1.0f) / mViewpager.getWidth();
  for(int i =0; i<title.length; i++) {
    x = (int) (i * width - ratio * width + center);
    y = (int) (getHeight()*0.5f + dip2px(TEXT_SIZE + 8)*0.25f);
    int alphaOffsetX = Math.abs(x-center);
    if(alphaOffsetX > alphaOffsetXMax) {
      alpha = 0;
    } else {
      alpha = (int) ((1.0f - ((alphaOffsetX * 1.0f) / alphaOffsetXMax)) * 255);
    }
    textPaint.setAlpha(alpha);
    canvas.drawText(title[i], x, y, textPaint);
  }
}
origin: nekocode/ToolbarIndicator

public int dip2px(float dpValue) {
  final float scale = getResources().getDisplayMetrics().density;
  return (int) (dpValue * scale + 0.5f);
}
origin: nekocode/ToolbarIndicator

private void handleTypedArray(Context context, AttributeSet attrs) {
  if (attrs != null) {
    TypedArray typedArray =
        context.obtainStyledAttributes(attrs, R.styleable.ToolbarIndicator);
    mIndicatorWidth =
        typedArray.getDimensionPixelSize(R.styleable.ToolbarIndicator_ti_width, -1);
    mIndicatorHeight =
        typedArray.getDimensionPixelSize(R.styleable.ToolbarIndicator_ti_height, -1);
    mIndicatorMargin =
        typedArray.getDimensionPixelSize(R.styleable.ToolbarIndicator_ti_margin, -1);
    mAnimatorResId = typedArray.getResourceId(R.styleable.ToolbarIndicator_ti_animator,
        R.animator.scale_with_alpha);
    mAnimatorReverseResId =
        typedArray.getResourceId(R.styleable.ToolbarIndicator_ti_animator_reverse, -1);
    mIndicatorBackground = typedArray.getResourceId(R.styleable.ToolbarIndicator_ti_drawable,
        R.drawable.white_radius);
    mIndicatorUnselectedBackground =
        typedArray.getResourceId(R.styleable.ToolbarIndicator_ti_drawable_unselected,
            mIndicatorBackground);
    typedArray.recycle();
  }
  mIndicatorWidth =
      (mIndicatorWidth == -1) ? dip2px(DEFAULT_INDICATOR_WIDTH) : mIndicatorWidth;
  mIndicatorHeight =
      (mIndicatorHeight == -1) ? dip2px(DEFAULT_INDICATOR_WIDTH) : mIndicatorHeight;
  mIndicatorMargin =
      (mIndicatorMargin == -1) ? dip2px(DEFAULT_INDICATOR_WIDTH) : mIndicatorMargin;
}
origin: nekocode/ToolbarIndicator

@Override
public void onPageSelected(int position) {
  if (mAnimationIn.isRunning()) mAnimationIn.cancel();
  if (mAnimationOut.isRunning()) mAnimationOut.cancel();
  View currentIndicator = getChildAt(mCurrentPosition);
  currentIndicator.setBackgroundResource(mIndicatorUnselectedBackground);
  mAnimationIn.setTarget(currentIndicator);
  mAnimationIn.start();
  View selectedIndicator = getChildAt(position);
  selectedIndicator.setBackgroundResource(mIndicatorBackground);
  mAnimationOut.setTarget(selectedIndicator);
  mAnimationOut.start();
  mCurrentPosition = position;
}
cn.nekocode.toolbarindicatorToolbarIndicator

Most used methods

  • addIndicator
  • addView
  • createIndicators
  • dip2px
  • getChildAt
  • getContext
  • getHeight
  • getResources
  • getWidth
  • handleTypedArray
  • init
  • invalidate
  • init,
  • invalidate,
  • onPageSelected,
  • removeAllViews,
  • setBackgroundColor,
  • setGravity,
  • setOrientation,
  • setPadding,
  • setViewPager

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSystemService (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • findViewById (Activity)
  • Color (java.awt)
    The Color class is used encapsulate colors in the default sRGB color space or colors in arbitrary co
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now