Tabnine Logo
ToolbarIndicator
Code IndexAdd Tabnine 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)

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

  • Reactive rest calls using spring rest template
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getSystemService (Context)
  • getSharedPreferences (Context)
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Path (java.nio.file)
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • JLabel (javax.swing)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now