import android.graphics.Bitmap; import android.graphics.PointF; import android.graphics.drawable.BitmapDrawable; import android.support.v4.content.res.ResourcesCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private DivergeViewSecond mDivergeView; private ImageView mImageView; private List<bitmap> mList= new ArrayList<bitmap>(); private int mIndex = 0 ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); mImageView =findViewById(R.id.iv_start); mList = new ArrayList<>(); mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.a2, null )).getBitmap()); mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.a3, null )).getBitmap()); mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.a4, null )).getBitmap()); mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.a5, null )).getBitmap()); mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.a6, null )).getBitmap()); mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.a7, null )).getBitmap()); mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.a8, null )).getBitmap()); mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.a9, null )).getBitmap()); //mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.a10, null)).getBitmap()); mImageView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mIndex == 8 ){ mIndex = 0 ; } mDivergeView.startDiverges(mIndex); mIndex ++; } }); mDivergeView =findViewById(R.id.pergeView); mDivergeView.post( new Runnable() { @Override public void run() { mDivergeView.setEndPoint( new PointF(mDivergeView.getMeasuredWidth()/ 2 , 0 )); mDivergeView.setDivergeViewProvider( new Provider()); } }); } @Override protected void onDestroy() { super .onDestroy(); if (mList != null ){ mList.clear(); mList = null ; } } class Provider implements DivergeViewSecond.DivergeViewProvider{ @Override public Bitmap getBitmap(Object obj) { return mList == null ? null : mList.get(( int )obj); } } }</bitmap></bitmap> |