@Override public void onClick(View v) { mExplosionField.explode(v); v.setOnClickListener(null); } });
public static ExplosionField attach2Window(Activity activity) { ViewGroup rootView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); ExplosionField explosionField = new ExplosionField(activity); rootView.addView(explosionField, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return explosionField; }
public ExplosionField(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); }
public void explode(final View view) { Rect r = new Rect(); view.getGlobalVisibleRect(r); int[] location = new int[2]; getLocationOnScreen(location); r.offset(-location[0], -location[1]); r.inset(-mExpandInset[0], -mExpandInset[1]); int startDelay = 100; ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration(150); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { Random random = new Random(); @Override public void onAnimationUpdate(ValueAnimator animation) { view.setTranslationX((random.nextFloat() - 0.5f) * view.getWidth() * 0.05f); view.setTranslationY((random.nextFloat() - 0.5f) * view.getHeight() * 0.05f); } }); animator.start(); view.animate().setDuration(150).setStartDelay(startDelay).scaleX(0f).scaleY(0f).alpha(0f).start(); explode(Utils.createBitmapFromView(view), r, startDelay, ExplosionAnimator.DEFAULT_DURATION); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mExplosionField = ExplosionField.attach2Window(this); addListener(findViewById(R.id.root)); }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_reset) { View root = findViewById(R.id.root); reset(root); addListener(root); mExplosionField.clear(); return true; } return super.onOptionsItemSelected(item); }
public void clear() { mExplosions.clear(); invalidate(); }
@Override protected void initData() { explosionField = ExplosionField.attach2Window(this); searchHistoryAdapter = new SearchHistoryAdapter(); searchBookAdapter = new SearchBookAdapter(); } @Override
@Override protected void onDestroy() { super.onDestroy(); explosionField.clear(); } @Override
@Override public void onClick(View v) { for (int i = 0; i < tflSearchHistory.getChildCount(); i++) { explosionField.explode(tflSearchHistory.getChildAt(i)); } mPresenter.cleanSearchHistory(); } });
explosionField = ExplosionField.attach2Window(this);
public ExplosionField(Context context) { super(context); init(); }
@Override public void onDeleteClick(View v, int position) { explosionField.explode(v); realm.beginTransaction(); results.get(position).deleteFromRealm(); if (mAdapter != null) { mAdapter.notifyItemRemoved(position); } realm.commitTransaction(); } };
public ExplosionField(Context context, AttributeSet attrs) { super(context, attrs); init(); }