Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
junixapp committed Dec 26, 2018
2 parents 10ad9dd + a2ffb87 commit e375d71
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 58 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/com/lxj/xpopupdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.util.XPopupUtils;
import com.lxj.xpopupdemo.fragment.AllAnimatorDemo;
import com.lxj.xpopupdemo.fragment.BaseFragment;
import com.lxj.xpopupdemo.fragment.CustomAnimatorDemo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.View;
import android.view.animation.OvershootInterpolator;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.animator.PopupAnimator;
import com.lxj.xpopup.enums.PopupAnimation;
import com.lxj.xpopup.enums.PopupType;
import com.lxj.xpopup.util.Utils;
import com.lxj.xpopupdemo.R;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.lxj.xpopupdemo.fragment;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

Expand All @@ -14,8 +10,8 @@
import com.lxj.xpopup.interfaces.XPopupCallback;
import com.lxj.xpopup.widget.PopupDrawerLayout;
import com.lxj.xpopupdemo.R;
import com.lxj.xpopupdemo.custompopup.ZhihuCommentPopup;
import com.lxj.xpopupdemo.custompopup.CustomDrawerPopupView;
import com.lxj.xpopupdemo.custompopup.ZhihuCommentPopup;

/**
* Description:
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ publish {
userOrg = 'li-xiaojun'
groupId = 'com.lxj'
artifactId = 'xpopup'
publishVersion = '1.0.0'
publishVersion = '1.0.1'
repoName = 'jrepo'
desc = '功能强大,UI简洁,交互优雅的通用弹窗!可以替代Dialog,PopupWindow,PopupMenu,BottomSheet,DrawerLayout等组件,自带十几种效果良好的动画, 支持完全的UI和动画自定义!'
website = 'https://github.com/li-xiaojun/XPopup'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.lxj.xpopup.animator;

import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.OvershootInterpolator;

import com.lxj.xpopup.enums.PopupAnimation;
import com.lxj.xpopup.util.Utils;
import com.lxj.xpopup.util.XPopupUtils;

/**
* Description: 平移动画
Expand All @@ -34,8 +31,8 @@ public void initAnimator() {
}

private void applyTranslation() {
int halfWidthOffset = Utils.getWindowWidth(targetView.getContext())/2 - targetView.getMeasuredWidth()/2;
int halfHeightOffset = Utils.getWindowHeight(targetView.getContext())/2 - targetView.getMeasuredHeight()/2;
int halfWidthOffset = XPopupUtils.getWindowWidth(targetView.getContext())/2 - targetView.getMeasuredWidth()/2;
int halfHeightOffset = XPopupUtils.getWindowHeight(targetView.getContext())/2 - targetView.getMeasuredHeight()/2;
switch (popupAnimation){
case TranslateAlphaFromLeft:
targetView.setTranslationX(-(targetView.getMeasuredWidth()/* + halfWidthOffset*/));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.lxj.xpopup.animator;

import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;

import com.lxj.xpopup.enums.PopupAnimation;
import com.lxj.xpopup.util.Utils;

/**
* Description: 平移动画,不带渐变
Expand Down
13 changes: 6 additions & 7 deletions library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import com.lxj.xpopup.R;
import com.lxj.xpopup.animator.PopupAnimator;
import com.lxj.xpopup.animator.ScrollScaleAnimator;
import com.lxj.xpopup.enums.PopupAnimation;
import com.lxj.xpopup.util.Utils;
import com.lxj.xpopup.util.XPopupUtils;

/**
* Description: 依附于某个View的弹窗
Expand All @@ -27,8 +26,8 @@ public abstract class AttachPopupView extends BasePopupView {

public AttachPopupView(@NonNull Context context) {
super(context);
defaultOffsetY = Utils.dp2px(context, defaultOffsetY);
defaultOffsetX = Utils.dp2px(context, defaultOffsetX);
defaultOffsetY = XPopupUtils.dp2px(context, defaultOffsetY);
defaultOffsetX = XPopupUtils.dp2px(context, defaultOffsetX);
attachPopupContainer = findViewById(R.id.attachPopupContainer);

View contentView = LayoutInflater.from(getContext()).inflate(getImplLayoutId(), attachPopupContainer, false);
Expand Down Expand Up @@ -69,7 +68,7 @@ public void run() {
*/
protected void doAttach(){
// 弹窗显示的位置不能超越Window高度
float maxY = Utils.getWindowHeight(getContext()) ;
float maxY = XPopupUtils.getWindowHeight(getContext()) ;
float maxX = 0; // 显示在右边时候的最大值

float translationX = 0, translationY = 0;
Expand All @@ -79,7 +78,7 @@ protected void doAttach(){
maxX = Math.max(popupInfo.touchPoint.x - getPopupContentView().getMeasuredWidth(), 0);
// 尽量优先放在下方,当不够的时候在显示在上方
isShowUp = (popupInfo.touchPoint.y + getPopupContentView().getMeasuredHeight()) > maxY ;
isShowLeft = popupInfo.touchPoint.x < Utils.getWindowWidth(getContext()) / 2;
isShowLeft = popupInfo.touchPoint.x < XPopupUtils.getWindowWidth(getContext()) / 2;

if (isShowUp) {
// 应显示在point上方
Expand All @@ -103,7 +102,7 @@ protected void doAttach(){

// 尽量优先放在下方,当不够的时候在显示在上方
isShowUp = (rect.bottom + getPopupContentView().getMeasuredHeight()) > maxY ; // 不能正好贴着底边
isShowLeft = centerX < Utils.getWindowWidth(getContext()) / 2;
isShowLeft = centerX < XPopupUtils.getWindowWidth(getContext()) / 2;

if (isShowUp) {
//说明上面的空间比较大,应显示在atView上方
Expand Down
11 changes: 5 additions & 6 deletions library/src/main/java/com/lxj/xpopup/core/BasePopupView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.animator.PopupAnimator;
import com.lxj.xpopup.animator.ScaleAlphaAnimator;
import com.lxj.xpopup.animator.ScrollScaleAnimator;
import com.lxj.xpopup.animator.ShadowBgAnimator;
import com.lxj.xpopup.animator.TranslateAlphaAnimator;
import com.lxj.xpopup.animator.TranslateAnimator;
import com.lxj.xpopup.interfaces.PopupInterface;
import com.lxj.xpopup.util.Utils;
import com.lxj.xpopup.util.XPopupUtils;

import static com.lxj.xpopup.enums.PopupAnimation.ScaleAlphaFromCenter;
import static com.lxj.xpopup.enums.PopupAnimation.ScrollAlphaFromLeftTop;
Expand All @@ -47,9 +46,9 @@ public BasePopupView(@NonNull Context context) {
// 事先隐藏,等测量完毕恢复。避免View影子跳动现象
contentView.setAlpha(0);
addView(contentView);
// 如果有导航栏,则不能覆盖导航栏
if(Utils.hasNavigationBar(getContext())){
setPadding(0,0,0, Utils.getNavBarHeight());
// 如果有导航栏,则不能覆盖导航栏,排除特殊设备
if(XPopupUtils.hasNavigationBar(getContext()) && !XPopupUtils.isFuckDevice()){
setPadding(0,0,0, XPopupUtils.getNavBarHeight());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected int getImplLayoutId() {
}

// public int getMaxHeight() {
// return popupInfo.maxHeight == 0 ? (int) (Utils.getWindowHeight(getContext()) * 0.85f)
// return popupInfo.maxHeight == 0 ? (int) (XPopupUtils.getWindowHeight(getContext()) * 0.85f)
// : popupInfo.maxHeight;
// }
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.lxj.xpopup.R;
import com.lxj.xpopup.util.Utils;
import com.lxj.xpopup.util.XPopupUtils;

/**
* Description: 在中间显示的Popup
Expand Down Expand Up @@ -60,12 +59,12 @@ protected int getImplLayoutId() {
}

protected int getMaxWidth() {
return popupInfo.maxWidth==0 ? (int) (Utils.getWindowWidth(getContext()) * 0.86f)
return popupInfo.maxWidth==0 ? (int) (XPopupUtils.getWindowWidth(getContext()) * 0.86f)
: popupInfo.maxWidth;
}

protected int getMaxHeight() {
return popupInfo.maxHeight==0 ? (int) (Utils.getWindowHeight(getContext()) * 0.85f)
return popupInfo.maxHeight==0 ? (int) (XPopupUtils.getWindowHeight(getContext()) * 0.85f)
: popupInfo.maxHeight;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.interfaces.OnCancelListener;
import com.lxj.xpopup.interfaces.OnInputConfirmListener;
import com.lxj.xpopup.util.Utils;
import com.lxj.xpopup.util.XPopupUtils;

/**
* Description: 带输入框,确定和取消的对话框
Expand Down Expand Up @@ -61,13 +61,13 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {

protected void applyPrimaryColor(){
super.applyPrimaryColor();
Utils.setCursorDrawableColor(tv_input, XPopup.get(getContext()).getPrimaryColor());
XPopupUtils.setCursorDrawableColor(tv_input, XPopup.get(getContext()).getPrimaryColor());
tv_input.post(new Runnable() {
@Override
public void run() {
BitmapDrawable defaultDrawable = Utils.createBitmapDrawable(getResources(), tv_input.getMeasuredWidth(), Color.parseColor("#888888"));
BitmapDrawable focusDrawable = Utils.createBitmapDrawable(getResources(), tv_input.getMeasuredWidth(), XPopup.get(getContext()).getPrimaryColor());
tv_input.setBackgroundDrawable(Utils.createSelector(defaultDrawable, focusDrawable));
BitmapDrawable defaultDrawable = XPopupUtils.createBitmapDrawable(getResources(), tv_input.getMeasuredWidth(), Color.parseColor("#888888"));
BitmapDrawable focusDrawable = XPopupUtils.createBitmapDrawable(getResources(), tv_input.getMeasuredWidth(), XPopup.get(getContext()).getPrimaryColor());
tv_input.setBackgroundDrawable(XPopupUtils.createSelector(defaultDrawable, focusDrawable));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.lxj.xpopup.R;
import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.util.Utils;
import com.lxj.xpopup.util.XPopupUtils;

/**
* Description: 确定和取消的对话框
Expand All @@ -30,7 +30,7 @@ protected void initPopupContent() {

@Override
protected int getMaxWidth() {
return popupInfo.maxWidth==0?Utils.dp2px(getContext(), 85)
return popupInfo.maxWidth==0?XPopupUtils.dp2px(getContext(), 85)
: popupInfo.maxWidth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Description:
* Create by lxj, at 2018/12/7
*/
public class Utils {
public class XPopupUtils {
public static int getWindowWidth(Context context) {
return ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public static int getNavBarHeight() {
public static boolean hasNavigationBar(Context context) {
Point appUsableSize = getAppUsableScreenSize(context);
Point realScreenSize = getRealScreenSize(context);
return appUsableSize.y + Utils.getStatusBarHeight() < realScreenSize.y;
return appUsableSize.y + XPopupUtils.getStatusBarHeight() < realScreenSize.y;
}

public static Point getAppUsableScreenSize(Context context) {
Expand Down Expand Up @@ -97,7 +97,14 @@ public static Point getRealScreenSize(Context context) {
return size;
}


/**
* 是否是特殊设备,目前发现有:小米MIX系列
* @return
*/
public static boolean isFuckDevice(){
String model = XPopupUtils.getModel();
return model.equalsIgnoreCase("MIX2") || model.equalsIgnoreCase("MIX2S");
}

public static void limitWidthAndHeight(View target, int maxWidth, int maxHeight){
ViewGroup.LayoutParams params = target.getLayoutParams();
Expand Down Expand Up @@ -149,4 +156,30 @@ public static StateListDrawable createSelector(Drawable defaultDrawable, Drawabl
stateListDrawable.addState(new int[]{}, defaultDrawable);
return stateListDrawable;
}

/**
* Return the manufacturer of the product/hardware.
* <p>e.g. Xiaomi</p>
*
* @return the manufacturer of the product/hardware
*/
public static String getManufacturer() {
return Build.MANUFACTURER;
}

/**
* Return the model of device.
* <p>e.g. MI2SC</p>
*
* @return the model of device
*/
public static String getModel() {
String model = Build.MODEL;
if (model != null) {
model = model.trim().replaceAll("\\s*", "");
} else {
model = "";
}
return model;
}
}
4 changes: 2 additions & 2 deletions library/src/main/java/com/lxj/xpopup/widget/CheckView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.util.AttributeSet;
import android.view.View;

import com.lxj.xpopup.util.Utils;
import com.lxj.xpopup.util.XPopupUtils;

/**
* Description: 对勾View
Expand All @@ -28,7 +28,7 @@ public CheckView(Context context, AttributeSet attrs) {
public CheckView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(Utils.dp2px(context, 2));
paint.setStrokeWidth(XPopupUtils.dp2px(context, 2));
paint.setStyle(Paint.Style.STROKE);
}

Expand Down
6 changes: 3 additions & 3 deletions library/src/main/java/com/lxj/xpopup/widget/LoadingView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.util.AttributeSet;
import android.view.View;

import com.lxj.xpopup.util.Utils;
import com.lxj.xpopup.util.XPopupUtils;

/**
* Description: 加载View
Expand Down Expand Up @@ -38,7 +38,7 @@ public LoadingView(Context context, AttributeSet attrs) {
public LoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
stokeWidth = Utils.dp2px(context, stokeWidth);
stokeWidth = XPopupUtils.dp2px(context, stokeWidth);
paint.setStrokeWidth(stokeWidth);
}

Expand All @@ -51,7 +51,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
centerX = getMeasuredWidth() / 2;
centerY = getMeasuredHeight() / 2;

stokeWidth *= getMeasuredWidth()*1f / Utils.dp2px(getContext(), 30);
stokeWidth *= getMeasuredWidth()*1f / XPopupUtils.dp2px(getContext(), 30);
paint.setStrokeWidth(stokeWidth);
}

Expand Down
Loading

0 comments on commit e375d71

Please sign in to comment.