Skip to content

Commit

Permalink
重构
Browse files Browse the repository at this point in the history
  • Loading branch information
zj565061763 committed Jan 10, 2018
1 parent f3075ec commit 4b8b7cf
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 12 deletions.
2 changes: 0 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ android {
}

dependencies {
compile 'com.github.zj565061763:poper:1.0.23'
}


// 指定编码
tasks.withType(Javadoc) {
options {
Expand Down
19 changes: 9 additions & 10 deletions lib/src/main/java/com/fanwe/lib/animator/FAnimatorSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -220,7 +219,7 @@ public void startAsPop()
{
return;
}
final HashMap<View, FPopImageView> mapTargetPoper = new HashMap<>();
final HashMap<View, PopImageView> mapTargetPoper = new HashMap<>();
for (Animator animator : listChild)
{
View target = (View) ((ObjectAnimator) animator).getTarget();
Expand All @@ -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
{
Expand Down
113 changes: 113 additions & 0 deletions lib/src/main/java/com/fanwe/lib/animator/PopImageView.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 4b8b7cf

Please sign in to comment.