diff --git a/lib/build.gradle b/lib/build.gradle index f2df713..9211430 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -25,10 +25,8 @@ android { } dependencies { - compile 'com.github.zj565061763:poper:1.0.23' } - // 指定编码 tasks.withType(Javadoc) { options { diff --git a/lib/src/main/java/com/fanwe/lib/animator/FAnimatorSet.java b/lib/src/main/java/com/fanwe/lib/animator/FAnimatorSet.java index 31e6ab1..0e328fb 100644 --- a/lib/src/main/java/com/fanwe/lib/animator/FAnimatorSet.java +++ b/lib/src/main/java/com/fanwe/lib/animator/FAnimatorSet.java @@ -20,10 +20,9 @@ import android.animation.ObjectAnimator; import android.animation.TimeInterpolator; import android.app.Activity; +import android.content.Context; import android.view.View; -import com.fanwe.lib.poper.view.FPopImageView; - import java.util.ArrayList; import java.util.HashMap; @@ -220,7 +219,7 @@ public void startAsPop() { return; } - final HashMap mapTargetPoper = new HashMap<>(); + final HashMap mapTargetPoper = new HashMap<>(); for (Animator animator : listChild) { View target = (View) ((ObjectAnimator) animator).getTarget(); @@ -230,15 +229,15 @@ public void startAsPop() } if (!mapTargetPoper.containsKey(target)) { - if (target.getContext() instanceof Activity) + final Context context = target.getContext(); + if (context instanceof Activity) { - FPopImageView popView = new FPopImageView(target.getContext()); - popView.setDrawingCacheView(target); - popView.getPoper().setTarget(target).attach(true).setTarget(null); - - animator.setTarget(popView); + PopImageView imageView = new PopImageView(context); + imageView.setDrawingCacheView(target); + imageView.attachTarget(target); - mapTargetPoper.put(target, popView); + animator.setTarget(imageView); + mapTargetPoper.put(target, imageView); } } else { diff --git a/lib/src/main/java/com/fanwe/lib/animator/PopImageView.java b/lib/src/main/java/com/fanwe/lib/animator/PopImageView.java new file mode 100644 index 0000000..47a51cd --- /dev/null +++ b/lib/src/main/java/com/fanwe/lib/animator/PopImageView.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2017 zhengjun, fanwe (http://www.fanwe.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.fanwe.lib.animator; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Bitmap; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; +import android.widget.FrameLayout; +import android.widget.ImageView; + +class PopImageView extends ImageView +{ + private FrameLayout mFrameLayout; + + public PopImageView(Context context) + { + super(context); + if (!(context instanceof Activity)) + { + throw new IllegalArgumentException("context must be instance of Activity"); + } + Activity activity = (Activity) context; + mFrameLayout = activity.findViewById(android.R.id.content); + } + + /** + * 设置要截图的view + * + * @param view + * @return + */ + public void setDrawingCacheView(View view) + { + Bitmap bitmap = createViewBitmap(view); + setImageBitmap(bitmap); + } + + /** + * 依附到目标view + * + * @param target + */ + public void attachTarget(View target) + { + removeSelf(); + + int[] locationTarget = {0, 0}; + target.getLocationOnScreen(locationTarget); + int[] locationContainer = {0, 0}; + mFrameLayout.getLocationOnScreen(locationContainer); + + int left = locationTarget[0] - locationContainer[0]; + int top = locationTarget[1] - locationContainer[1]; + + final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT); + params.leftMargin = left; + params.topMargin = top; + + final ViewGroup.LayoutParams paramsTarget = target.getLayoutParams(); + if (paramsTarget != null) + { + params.width = paramsTarget.width; + params.height = paramsTarget.height; + } + setLayoutParams(params); + mFrameLayout.addView(this); + } + + private void removeSelf() + { + ViewParent parent = getParent(); + if (parent instanceof ViewGroup) + { + ViewGroup viewGroup = (ViewGroup) parent; + viewGroup.removeView(this); + } + } + + private static Bitmap createViewBitmap(View view) + { + if (view == null) + { + return null; + } + view.setDrawingCacheEnabled(true); + Bitmap drawingCache = view.getDrawingCache(); + if (drawingCache == null) + { + return null; + } + + Bitmap bmp = Bitmap.createBitmap(drawingCache); + view.destroyDrawingCache(); + return bmp; + } +}