From 81f4b0cecbde2104b9c7b7a58d56e44525c4b326 Mon Sep 17 00:00:00 2001 From: liaoziyao Date: Wed, 30 Aug 2017 23:10:29 +0800 Subject: [PATCH 1/4] update gradle, version, readme --- app/build.gradle | 2 +- imagepicker/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4633d44..0e87b4f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,6 +31,6 @@ dependencies { compile 'com.lzy.widget:view-core:0.2.1' - //compile 'com.lzy.widget:imagepicker:0.5.5' + //compile 'com.lzy.widget:imagepicker:0.6.0' compile project(':imagepicker') } diff --git a/imagepicker/build.gradle b/imagepicker/build.gradle index 718bc3f..eab8365 100644 --- a/imagepicker/build.gradle +++ b/imagepicker/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' android { compileSdkVersion 25 - buildToolsVersion "25.0.2" + buildToolsVersion "25.0.3" defaultConfig { minSdkVersion 11 From 5f4aaca5084ca9005f52cdc3921fc6a2c53d00d5 Mon Sep 17 00:00:00 2001 From: zchu Date: Mon, 4 Sep 2017 14:41:41 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=80=82=E9=85=8D=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E6=A8=AA=E7=AB=96=E5=B1=8F=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imagepicker/src/main/AndroidManifest.xml | 1 + .../imagepicker/ui/ImagePreviewActivity.java | 46 +++++++-- .../ui/ImagePreviewDelActivity.java | 14 +++ .../util/NavigationBarChangeListener.java | 97 +++++++++++++++++++ 4 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 imagepicker/src/main/java/com/lzy/imagepicker/util/NavigationBarChangeListener.java diff --git a/imagepicker/src/main/AndroidManifest.xml b/imagepicker/src/main/AndroidManifest.xml index 16bf7ad..11bb666 100644 --- a/imagepicker/src/main/AndroidManifest.xml +++ b/imagepicker/src/main/AndroidManifest.xml @@ -30,6 +30,7 @@ = Build.VERSION_CODES.KITKAT && Utils.hasVirtualNavigationBar(this)) { - View marginView = findViewById(R.id.margin_bottom); - ViewGroup.LayoutParams layoutParams = marginView.getLayoutParams(); - layoutParams.height = Utils.getNavigationBarHeight(this); - marginView.requestLayout(); - } + mCbCheck = (SuperCheckBox) findViewById(R.id.cb_check); mCbOrigin = (SuperCheckBox) findViewById(R.id.cb_origin); + marginView = findViewById(R.id.margin_bottom); mCbOrigin.setText(getString(R.string.ip_origin)); mCbOrigin.setOnCheckedChangeListener(this); mCbOrigin.setChecked(isOrigin); @@ -94,8 +90,40 @@ public void onClick(View v) { } } }); + NavigationBarChangeListener.with(this).setListener(new NavigationBarChangeListener.OnSoftInputStateChangeListener() { + @Override + public void onNavigationBarShow(int orientation, int height) { + marginView.setVisibility(View.VISIBLE); + ViewGroup.LayoutParams layoutParams = marginView.getLayoutParams(); + if (layoutParams.height == 0) { + layoutParams.height = Utils.getNavigationBarHeight(ImagePreviewActivity.this); + marginView.requestLayout(); + } + } + + @Override + public void onNavigationBarHide(int orientation) { + marginView.setVisibility(View.GONE); + } + }); + NavigationBarChangeListener.with(this, NavigationBarChangeListener.ORIENTATION_HORIZONTAL) + .setListener(new NavigationBarChangeListener.OnSoftInputStateChangeListener() { + @Override + public void onNavigationBarShow(int orientation, int height) { + topBar.setPadding(0, 0, height, 0); + bottomBar.setPadding(0, 0, height, 0); + } + + @Override + public void onNavigationBarHide(int orientation) { + topBar.setPadding(0, 0, 0, 0); + bottomBar.setPadding(0, 0, 0, 0); + } + }); } + + /** * 图片添加成功后,修改当前图片的选中数量 * 当调用 addSelectedImageItem 或 deleteSelectedImageItem 都会触发当前回调 diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewDelActivity.java b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewDelActivity.java index 5d2f1cf..642fa52 100644 --- a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewDelActivity.java +++ b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewDelActivity.java @@ -2,6 +2,7 @@ import android.content.DialogInterface; import android.content.Intent; +import android.content.res.Configuration; import android.graphics.Color; import android.os.Bundle; import android.support.v4.view.ViewPager; @@ -12,6 +13,7 @@ import com.lzy.imagepicker.ImagePicker; import com.lzy.imagepicker.R; +import com.lzy.imagepicker.util.NavigationBarChangeListener; /** * ================================================ @@ -42,6 +44,18 @@ public void onPageSelected(int position) { mTitleCount.setText(getString(R.string.ip_preview_image_count, mCurrentPosition + 1, mImageItems.size())); } }); + NavigationBarChangeListener.with(this, NavigationBarChangeListener.ORIENTATION_HORIZONTAL) + .setListener(new NavigationBarChangeListener.OnSoftInputStateChangeListener() { + @Override + public void onNavigationBarShow(int orientation, int height) { + topBar.setPadding(0, 0, height, 0); + } + + @Override + public void onNavigationBarHide(int orientation) { + topBar.setPadding(0, 0, 0, 0); + } + }); } @Override diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/util/NavigationBarChangeListener.java b/imagepicker/src/main/java/com/lzy/imagepicker/util/NavigationBarChangeListener.java new file mode 100644 index 0000000..2e2d279 --- /dev/null +++ b/imagepicker/src/main/java/com/lzy/imagepicker/util/NavigationBarChangeListener.java @@ -0,0 +1,97 @@ +package com.lzy.imagepicker.util; + +import android.app.Activity; +import android.graphics.Rect; +import android.view.View; +import android.view.ViewTreeObserver; + + +/** + * Created by z-chu on 2017/9/4 + * 用于监听导航栏的显示和隐藏,主要用于适配华为EMUI系统上虚拟导航栏可随时收起和展开的情况 + */ + +public class NavigationBarChangeListener implements ViewTreeObserver.OnGlobalLayoutListener { + + + /** + * 监听竖屏模式导航栏的显示和隐藏 + */ + public static final int ORIENTATION_VERTICAL = 1; + + /** + * 监听横屏模式导航栏的显示和隐藏 + */ + public static final int ORIENTATION_HORIZONTAL = 2; + + private Rect rect; + + private View rootView; + + private boolean isShowNavigationBar = false; + + private int orientation; + + private OnSoftInputStateChangeListener listener; + + + public NavigationBarChangeListener(View rootView, int orientation) { + this.rootView = rootView; + this.orientation = orientation; + rect = new Rect(); + } + + @Override + public void onGlobalLayout() { + rect.setEmpty(); + rootView.getWindowVisibleDisplayFrame(rect); + int heightDiff = 0; + if (orientation == ORIENTATION_VERTICAL) { + heightDiff = rootView.getHeight() - (rect.bottom - rect.top); + } else if (orientation == ORIENTATION_HORIZONTAL) { + heightDiff = rootView.getWidth() - (rect.right - rect.left); + } + int navigationBarHeight = Utils.hasVirtualNavigationBar(rootView.getContext()) ? + Utils.getNavigationBarHeight(rootView.getContext()) : 0; + if (heightDiff >= navigationBarHeight && heightDiff < navigationBarHeight * 2) { + if (!isShowNavigationBar && listener != null) { + listener.onNavigationBarShow(orientation, navigationBarHeight); + } + isShowNavigationBar = true; + } else { + + if (isShowNavigationBar && listener != null) { + listener.onNavigationBarHide(orientation); + } + isShowNavigationBar = false; + } + } + + public void setListener(OnSoftInputStateChangeListener listener) { + this.listener = listener; + } + + public interface OnSoftInputStateChangeListener { + void onNavigationBarShow(int orientation, int height); + + void onNavigationBarHide(int orientation); + } + + public static NavigationBarChangeListener with(View rootView) { + return with(rootView, ORIENTATION_VERTICAL); + } + + public static NavigationBarChangeListener with(Activity activity) { + return with(activity.findViewById(android.R.id.content), ORIENTATION_VERTICAL); + } + + public static NavigationBarChangeListener with(View rootView, int orientation) { + NavigationBarChangeListener softInputHeightListener = new NavigationBarChangeListener(rootView, orientation); + rootView.getViewTreeObserver().addOnGlobalLayoutListener(softInputHeightListener); + return softInputHeightListener; + } + + public static NavigationBarChangeListener with(Activity activity, int orientation) { + return with(activity.findViewById(android.R.id.content), orientation); + } +} From 06e15faeffc6ce8276865b213c2592c00f7e9b2f Mon Sep 17 00:00:00 2001 From: zchu Date: Mon, 4 Sep 2017 14:45:52 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A1=B5UI=EF=BC=8C=E5=9C=A8=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=8A=E9=93=BA=E4=B8=8A=E4=B8=80=E5=B1=82=E9=98=B4?= =?UTF-8?q?=E5=BD=B1=EF=BC=8C=E9=98=B2=E6=AD=A2=E7=99=BD=E8=89=B2=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=9C=8B=E4=B8=8D=E5=88=B0=E9=80=89=E4=B8=AD=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lzy/imagepicker/ui/ImagePreviewDelActivity.java | 1 - imagepicker/src/main/res/drawable/ic_cover_shade.xml | 8 ++++++++ .../src/main/res/layout/adapter_image_list_item.xml | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 imagepicker/src/main/res/drawable/ic_cover_shade.xml diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewDelActivity.java b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewDelActivity.java index 642fa52..a2f2299 100644 --- a/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewDelActivity.java +++ b/imagepicker/src/main/java/com/lzy/imagepicker/ui/ImagePreviewDelActivity.java @@ -2,7 +2,6 @@ import android.content.DialogInterface; import android.content.Intent; -import android.content.res.Configuration; import android.graphics.Color; import android.os.Bundle; import android.support.v4.view.ViewPager; diff --git a/imagepicker/src/main/res/drawable/ic_cover_shade.xml b/imagepicker/src/main/res/drawable/ic_cover_shade.xml new file mode 100644 index 0000000..7a0b130 --- /dev/null +++ b/imagepicker/src/main/res/drawable/ic_cover_shade.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/imagepicker/src/main/res/layout/adapter_image_list_item.xml b/imagepicker/src/main/res/layout/adapter_image_list_item.xml index 03826ea..e69960a 100644 --- a/imagepicker/src/main/res/layout/adapter_image_list_item.xml +++ b/imagepicker/src/main/res/layout/adapter_image_list_item.xml @@ -11,6 +11,11 @@ android:scaleType="centerCrop" android:src="@drawable/ic_default_image" /> + + Date: Mon, 4 Sep 2017 15:11:57 +0800 Subject: [PATCH 4/4] Update NavigationBarChangeListener --- .../com/lzy/imagepicker/util/NavigationBarChangeListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imagepicker/src/main/java/com/lzy/imagepicker/util/NavigationBarChangeListener.java b/imagepicker/src/main/java/com/lzy/imagepicker/util/NavigationBarChangeListener.java index 2e2d279..83d6e07 100644 --- a/imagepicker/src/main/java/com/lzy/imagepicker/util/NavigationBarChangeListener.java +++ b/imagepicker/src/main/java/com/lzy/imagepicker/util/NavigationBarChangeListener.java @@ -55,7 +55,7 @@ public void onGlobalLayout() { Utils.getNavigationBarHeight(rootView.getContext()) : 0; if (heightDiff >= navigationBarHeight && heightDiff < navigationBarHeight * 2) { if (!isShowNavigationBar && listener != null) { - listener.onNavigationBarShow(orientation, navigationBarHeight); + listener.onNavigationBarShow(orientation, heightDiff); } isShowNavigationBar = true; } else {