diff --git a/app/src/main/java/com/lxj/xpopupdemo/MainActivity.java b/app/src/main/java/com/lxj/xpopupdemo/MainActivity.java index 1773202e..91239cde 100644 --- a/app/src/main/java/com/lxj/xpopupdemo/MainActivity.java +++ b/app/src/main/java/com/lxj/xpopupdemo/MainActivity.java @@ -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; diff --git a/app/src/main/java/com/lxj/xpopupdemo/fragment/CustomAnimatorDemo.java b/app/src/main/java/com/lxj/xpopupdemo/fragment/CustomAnimatorDemo.java index 84c0ba84..d7d53704 100644 --- a/app/src/main/java/com/lxj/xpopupdemo/fragment/CustomAnimatorDemo.java +++ b/app/src/main/java/com/lxj/xpopupdemo/fragment/CustomAnimatorDemo.java @@ -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; /** diff --git a/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java b/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java index 8cadd284..9cec4d23 100644 --- a/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java +++ b/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java @@ -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; @@ -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: diff --git a/library/build.gradle b/library/build.gradle index a9064af3..4eb89362 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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' diff --git a/library/src/main/java/com/lxj/xpopup/animator/TranslateAlphaAnimator.java b/library/src/main/java/com/lxj/xpopup/animator/TranslateAlphaAnimator.java index 7b3d1684..69803b46 100644 --- a/library/src/main/java/com/lxj/xpopup/animator/TranslateAlphaAnimator.java +++ b/library/src/main/java/com/lxj/xpopup/animator/TranslateAlphaAnimator.java @@ -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: 平移动画 @@ -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*/)); diff --git a/library/src/main/java/com/lxj/xpopup/animator/TranslateAnimator.java b/library/src/main/java/com/lxj/xpopup/animator/TranslateAnimator.java index b66a5e32..09264799 100644 --- a/library/src/main/java/com/lxj/xpopup/animator/TranslateAnimator.java +++ b/library/src/main/java/com/lxj/xpopup/animator/TranslateAnimator.java @@ -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: 平移动画,不带渐变 diff --git a/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java b/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java index 90578823..0d737d39 100644 --- a/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java @@ -6,7 +6,6 @@ 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; @@ -14,7 +13,7 @@ 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的弹窗 @@ -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); @@ -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; @@ -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上方 @@ -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上方 diff --git a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java index b3253922..80699a72 100644 --- a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java @@ -5,15 +5,14 @@ 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; @@ -21,7 +20,7 @@ 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; @@ -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()); } } diff --git a/library/src/main/java/com/lxj/xpopup/core/BottomPopupView.java b/library/src/main/java/com/lxj/xpopup/core/BottomPopupView.java index d9abdbeb..9562852a 100644 --- a/library/src/main/java/com/lxj/xpopup/core/BottomPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/BottomPopupView.java @@ -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; // } // diff --git a/library/src/main/java/com/lxj/xpopup/core/CenterPopupView.java b/library/src/main/java/com/lxj/xpopup/core/CenterPopupView.java index 8d148cd9..75156585 100644 --- a/library/src/main/java/com/lxj/xpopup/core/CenterPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/CenterPopupView.java @@ -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 @@ -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; } diff --git a/library/src/main/java/com/lxj/xpopup/impl/InputConfirmPopupView.java b/library/src/main/java/com/lxj/xpopup/impl/InputConfirmPopupView.java index cdd1b840..63a92f1f 100644 --- a/library/src/main/java/com/lxj/xpopup/impl/InputConfirmPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/impl/InputConfirmPopupView.java @@ -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: 带输入框,确定和取消的对话框 @@ -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)); } }); diff --git a/library/src/main/java/com/lxj/xpopup/impl/LoadingPopupView.java b/library/src/main/java/com/lxj/xpopup/impl/LoadingPopupView.java index f6c8fcad..1f4eabe5 100644 --- a/library/src/main/java/com/lxj/xpopup/impl/LoadingPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/impl/LoadingPopupView.java @@ -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: 确定和取消的对话框 @@ -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; } } diff --git a/library/src/main/java/com/lxj/xpopup/util/Utils.java b/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java similarity index 85% rename from library/src/main/java/com/lxj/xpopup/util/Utils.java rename to library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java index 6adaa5b6..3f838842 100644 --- a/library/src/main/java/com/lxj/xpopup/util/Utils.java +++ b/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java @@ -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(); } @@ -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) { @@ -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(); @@ -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. + *
e.g. Xiaomi
+ * + * @return the manufacturer of the product/hardware + */ + public static String getManufacturer() { + return Build.MANUFACTURER; + } + + /** + * Return the model of device. + *e.g. MI2SC
+ * + * @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; + } } diff --git a/library/src/main/java/com/lxj/xpopup/widget/CheckView.java b/library/src/main/java/com/lxj/xpopup/widget/CheckView.java index cf43f06b..da7d64e6 100644 --- a/library/src/main/java/com/lxj/xpopup/widget/CheckView.java +++ b/library/src/main/java/com/lxj/xpopup/widget/CheckView.java @@ -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 @@ -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); } diff --git a/library/src/main/java/com/lxj/xpopup/widget/LoadingView.java b/library/src/main/java/com/lxj/xpopup/widget/LoadingView.java index 0fca90d8..fcb21759 100644 --- a/library/src/main/java/com/lxj/xpopup/widget/LoadingView.java +++ b/library/src/main/java/com/lxj/xpopup/widget/LoadingView.java @@ -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 @@ -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); } @@ -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); } diff --git a/library/src/main/java/com/lxj/xpopup/widget/SmartDragLayout.java b/library/src/main/java/com/lxj/xpopup/widget/SmartDragLayout.java index 3819b4ed..bec0f4a4 100644 --- a/library/src/main/java/com/lxj/xpopup/widget/SmartDragLayout.java +++ b/library/src/main/java/com/lxj/xpopup/widget/SmartDragLayout.java @@ -6,14 +6,13 @@ import android.support.v4.view.ViewCompat; import android.support.v7.widget.CardView; import android.util.AttributeSet; -import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import android.widget.Scroller; import com.lxj.xpopup.animator.ShadowBgAnimator; -import com.lxj.xpopup.util.Utils; +import com.lxj.xpopup.util.XPopupUtils; /** * Description: 智能的拖拽布局,优先滚动整体,整体滚到头,则滚动内部能滚动的View @@ -35,7 +34,7 @@ public SmartDragLayout(Context context, AttributeSet attrs) { public SmartDragLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); scroller = new Scroller(context); - setCardElevation(Utils.dp2px(context, 10)); + setCardElevation(XPopupUtils.dp2px(context, 10)); setBackgroundColor(Color.TRANSPARENT); }