Search in sources :

Example 1 with Sprite

use of com.github.ybq.android.spinkit.sprite.Sprite in project Android-SpinKit by ybq.

the class FoldingCube method onBoundsChange.

@Override
protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);
    bounds = clipSquare(bounds);
    int size = Math.min(bounds.width(), bounds.height());
    if (wrapContent) {
        size = (int) Math.sqrt((size * size) / 2);
        int oW = (bounds.width() - size) / 2;
        int oH = (bounds.height() - size) / 2;
        bounds = new Rect(bounds.left + oW, bounds.top + oH, bounds.right - oW, bounds.bottom - oH);
    }
    int px = bounds.left + size / 2 + 1;
    int py = bounds.top + size / 2 + 1;
    for (int i = 0; i < getChildCount(); i++) {
        Sprite sprite = getChildAt(i);
        sprite.setDrawBounds(bounds.left, bounds.top, px, py);
        sprite.setPivotX(sprite.getDrawBounds().right);
        sprite.setPivotY(sprite.getDrawBounds().bottom);
    }
}
Also used : Rect(android.graphics.Rect) RectSprite(com.github.ybq.android.spinkit.sprite.RectSprite) Sprite(com.github.ybq.android.spinkit.sprite.Sprite)

Example 2 with Sprite

use of com.github.ybq.android.spinkit.sprite.Sprite in project Android-SpinKit by ybq.

the class WanderingCubes method onBoundsChange.

@Override
protected void onBoundsChange(Rect bounds) {
    bounds = clipSquare(bounds);
    super.onBoundsChange(bounds);
    for (int i = 0; i < getChildCount(); i++) {
        Sprite sprite = getChildAt(i);
        sprite.setDrawBounds(bounds.left, bounds.top, bounds.left + bounds.width() / 4, bounds.top + bounds.height() / 4);
    }
}
Also used : RectSprite(com.github.ybq.android.spinkit.sprite.RectSprite) Sprite(com.github.ybq.android.spinkit.sprite.Sprite)

Example 3 with Sprite

use of com.github.ybq.android.spinkit.sprite.Sprite in project Android-SpinKit by ybq.

the class DetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    viewPager.setOffscreenPageLimit(0);
    viewPager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return Style.values().length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            @SuppressLint("InflateParams") View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_pager, null);
            SpinKitView spinKitView = (SpinKitView) view.findViewById(R.id.spin_kit);
            TextView name = (TextView) view.findViewById(R.id.name);
            Style style = Style.values()[position];
            name.setText(style.name());
            Sprite drawable = SpriteFactory.create(style);
            spinKitView.setIndeterminateDrawable(drawable);
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            int color = (int) ArgbEvaluator.getInstance().evaluate(positionOffset, colors[position % colors.length], colors[(position + 1) % colors.length]);
            getWindow().getDecorView().setBackgroundColor(color);
        }

        @Override
        public void onPageSelected(int position) {
            getWindow().getDecorView().setBackgroundColor(colors[position % colors.length]);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    viewPager.setCurrentItem(getIntent().getIntExtra("position", 0));
}
Also used : Sprite(com.github.ybq.android.spinkit.sprite.Sprite) ViewGroup(android.view.ViewGroup) ViewPager(android.support.v4.view.ViewPager) SpinKitView(com.github.ybq.android.spinkit.SpinKitView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) SuppressLint(android.annotation.SuppressLint) Style(com.github.ybq.android.spinkit.Style) TextView(android.widget.TextView) SpinKitView(com.github.ybq.android.spinkit.SpinKitView)

Example 4 with Sprite

use of com.github.ybq.android.spinkit.sprite.Sprite in project Android-SpinKit by ybq.

the class FoldingCube method drawChild.

@Override
public void drawChild(Canvas canvas) {
    Rect bounds = clipSquare(getBounds());
    for (int i = 0; i < getChildCount(); i++) {
        int count = canvas.save();
        canvas.rotate(45 + i * 90, bounds.centerX(), bounds.centerY());
        Sprite sprite = getChildAt(i);
        sprite.draw(canvas);
        canvas.restoreToCount(count);
    }
}
Also used : Rect(android.graphics.Rect) RectSprite(com.github.ybq.android.spinkit.sprite.RectSprite) Sprite(com.github.ybq.android.spinkit.sprite.Sprite)

Example 5 with Sprite

use of com.github.ybq.android.spinkit.sprite.Sprite in project Android-SpinKit by ybq.

the class SpinKitView method init.

private void init() {
    Sprite sprite = SpriteFactory.create(mStyle);
    setIndeterminateDrawable(sprite);
}
Also used : Sprite(com.github.ybq.android.spinkit.sprite.Sprite)

Aggregations

Sprite (com.github.ybq.android.spinkit.sprite.Sprite)7 RectSprite (com.github.ybq.android.spinkit.sprite.RectSprite)5 Rect (android.graphics.Rect)2 SuppressLint (android.annotation.SuppressLint)1 PagerAdapter (android.support.v4.view.PagerAdapter)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 SpinKitView (com.github.ybq.android.spinkit.SpinKitView)1 Style (com.github.ybq.android.spinkit.Style)1