-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
507 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
app/src/main/java/com/zyyoona7/easypopup/easypop/EverywherePopup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.zyyoona7.easypopup.easypop; | ||
|
||
import android.content.Context; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
|
||
import com.blankj.utilcode.util.ScreenUtils; | ||
import com.zyyoona7.easypopup.R; | ||
import com.zyyoona7.lib.BasePopup; | ||
|
||
public class EverywherePopup extends BasePopup<EverywherePopup> { | ||
|
||
public static EverywherePopup create(Context context) { | ||
return new EverywherePopup(context); | ||
} | ||
|
||
private EverywherePopup(Context context) { | ||
setContext(context); | ||
} | ||
|
||
@Override | ||
protected void initAttributes() { | ||
setContentView(R.layout.layout_everywhere_pop) | ||
.setAnimationStyle(R.style.LeftTopPopAnim); | ||
} | ||
|
||
@Override | ||
protected void initViews(View view) { | ||
|
||
// setOnRealWHAlreadyListener(new OnRealWHAlreadyListener() { | ||
// @Override | ||
// public void onRealWHAlready(BasePopup basePopup, int popWidth, int popHeight, int anchorW, int anchorH) { | ||
// | ||
// } | ||
// }); | ||
} | ||
|
||
/** | ||
* 自适应触摸点 弹出 | ||
* @param parent | ||
* @param touchX | ||
* @param touchY | ||
* @return | ||
*/ | ||
public EverywherePopup showEverywhere(View parent,int touchX, int touchY) { | ||
// if (isRealWHAlready()) { | ||
int screenHeight = ScreenUtils.getScreenHeight(); | ||
int screenWidth = ScreenUtils.getScreenWidth(); | ||
int offsetX=touchX; | ||
int offsetY=touchY; | ||
if (touchX<getWidth() && screenHeight-touchY<getHeight()){ | ||
//左下弹出动画 | ||
getPopupWindow().setAnimationStyle(R.style.LeftBottomPopAnim); | ||
offsetY=touchY-getHeight(); | ||
}else if (touchX+getWidth()>screenWidth && touchY+getHeight()>screenHeight){ | ||
//右下弹出动画 | ||
getPopupWindow().setAnimationStyle(R.style.RightBottomPopAnim); | ||
offsetX=(touchX-getWidth()); | ||
offsetY=touchY-getHeight(); | ||
}else if (touchX+getWidth()>screenWidth){ | ||
getPopupWindow().setAnimationStyle(R.style.RightTopPopAnim); | ||
offsetX=(touchX-getWidth()); | ||
}else { | ||
getPopupWindow().setAnimationStyle(R.style.LeftTopPopAnim); | ||
} | ||
|
||
showAtLocation(parent, Gravity.NO_GRAVITY,offsetX,offsetY); | ||
// } | ||
return this; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
app/src/main/java/com/zyyoona7/easypopup/views/TriangleDrawable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.zyyoona7.easypopup.views; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.ColorFilter; | ||
import android.graphics.Paint; | ||
import android.graphics.Path; | ||
import android.graphics.PixelFormat; | ||
import android.graphics.Rect; | ||
import android.graphics.drawable.Drawable; | ||
import android.support.annotation.IntDef; | ||
import android.support.annotation.IntRange; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** | ||
* Created by jiang on 2017/5/19. | ||
*/ | ||
|
||
public class TriangleDrawable extends Drawable { | ||
public static final int TOP = 12; | ||
public static final int BOTTOM = 13; | ||
public static final int LEFT = 14; | ||
public static final int RIGHT = 15; | ||
|
||
private int bgColor = Color.WHITE; | ||
@ARROWDIRECTION | ||
private int arrowDirection; | ||
|
||
public TriangleDrawable(@ARROWDIRECTION int arrowDirection, int bgColor) { | ||
this.arrowDirection = arrowDirection; | ||
this.bgColor = bgColor; | ||
} | ||
|
||
@Override | ||
public void draw(@NonNull Canvas canvas) { | ||
|
||
Paint paint = new Paint(); | ||
paint.setAntiAlias(true); | ||
paint.setColor(bgColor); | ||
paint.setStyle(Paint.Style.FILL); | ||
Path path = createPath(); | ||
canvas.drawPath(path, paint); | ||
} | ||
|
||
private Path createPath() { | ||
Rect bound = getBounds(); | ||
Path path = new Path(); | ||
if (arrowDirection == TOP) { | ||
path.moveTo(bound.right / 2, 0); | ||
path.lineTo(0, bound.bottom); | ||
path.lineTo(bound.right, bound.bottom); | ||
path.close(); | ||
} else if (arrowDirection == BOTTOM) { | ||
path.moveTo(bound.right / 2, bound.bottom); | ||
path.lineTo(0, 0); | ||
path.lineTo(bound.right, 0); | ||
path.close(); | ||
|
||
} else if (arrowDirection == LEFT) { | ||
path.moveTo(0, bound.bottom / 2); | ||
path.lineTo(bound.right, 0); | ||
path.lineTo(bound.right, bound.bottom); | ||
path.close(); | ||
} else { | ||
path.moveTo(bound.right, bound.bottom / 2); | ||
path.lineTo(0, 0); | ||
path.lineTo(0, bound.bottom); | ||
path.close(); | ||
} | ||
return path; | ||
|
||
} | ||
|
||
@Override | ||
public void setAlpha(@IntRange(from = 0, to = 255) int alpha) { | ||
|
||
} | ||
|
||
@Override | ||
public void setColorFilter(@Nullable ColorFilter colorFilter) { | ||
|
||
} | ||
|
||
@Override | ||
public int getOpacity() { | ||
return PixelFormat.TRANSPARENT; | ||
} | ||
|
||
@IntDef({TOP, BOTTOM, LEFT, RIGHT}) | ||
@Retention(RetentionPolicy.SOURCE) | ||
public @interface ARROWDIRECTION { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<scale | ||
android:duration="@android:integer/config_shortAnimTime" | ||
android:fromXScale="0" | ||
android:fromYScale="0" | ||
android:interpolator="@android:anim/accelerate_interpolator" | ||
android:pivotX="80%" | ||
android:pivotY="0" | ||
android:toXScale="100%" | ||
android:toYScale="100%" | ||
/> | ||
|
||
<alpha | ||
android:duration="@android:integer/config_shortAnimTime" | ||
android:fromAlpha="0" | ||
android:interpolator="@android:anim/accelerate_interpolator" | ||
android:toAlpha="1" | ||
/> | ||
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<scale | ||
android:duration="@android:integer/config_shortAnimTime" | ||
android:fromXScale="100%" | ||
android:fromYScale="100%" | ||
android:interpolator="@android:anim/accelerate_interpolator" | ||
android:pivotX="80%" | ||
android:pivotY="0" | ||
android:toXScale="0" | ||
android:toYScale="0" | ||
/> | ||
|
||
<alpha | ||
android:duration="@android:integer/config_shortAnimTime" | ||
android:fromAlpha="1" | ||
android:interpolator="@android:anim/accelerate_interpolator" | ||
android:toAlpha="0" | ||
/> | ||
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<solid android:color="#FFFFFF"/> | ||
<corners android:radius="5dp"/> | ||
</shape> |
Oops, something went wrong.