Commit ce1517b59679e310aaf891ec846f007fdfc39322
1 parent
afd7573c
1 修复pop控件在安卓6.0以下点击空白区域,无法消失的问题
Showing
11 changed files
with
74 additions
and
11 deletions
app/build.gradle
| 1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
| 2 | + | ||
| 2 | static def stringValue(def value) { | 3 | static def stringValue(def value) { |
| 3 | return "\"${value}\"" | 4 | return "\"${value}\"" |
| 4 | } | 5 | } |
| 6 | + | ||
| 5 | android { | 7 | android { |
| 6 | compileSdkVersion 28 | 8 | compileSdkVersion 28 |
| 7 | defaultConfig { | 9 | defaultConfig { |
| @@ -61,6 +63,7 @@ android { | @@ -61,6 +63,7 @@ android { | ||
| 61 | 63 | ||
| 62 | dependencies { | 64 | dependencies { |
| 63 | implementation fileTree(dir: 'libs', include: ['*.jar']) | 65 | implementation fileTree(dir: 'libs', include: ['*.jar']) |
| 66 | + implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
| 64 | testImplementation 'junit:junit:4.12' | 67 | testImplementation 'junit:junit:4.12' |
| 65 | implementation project(path: ':module_xiaojiaSoundBox') | 68 | implementation project(path: ':module_xiaojiaSoundBox') |
| 66 | implementation "com.android.support:support-v4:$rootProject.supportV4" | 69 | implementation "com.android.support:support-v4:$rootProject.supportV4" |
app/src/main/AndroidManifest.xml
| @@ -2,8 +2,6 @@ | @@ -2,8 +2,6 @@ | ||
| 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | package="com.cnlive.strike.speaker"> | 3 | package="com.cnlive.strike.speaker"> |
| 4 | 4 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | <application | 5 | <application |
| 8 | android:allowBackup="true" | 6 | android:allowBackup="true" |
| 9 | android:icon="@mipmap/ic_launcher" | 7 | android:icon="@mipmap/ic_launcher" |
| @@ -11,6 +9,7 @@ | @@ -11,6 +9,7 @@ | ||
| 11 | android:roundIcon="@mipmap/ic_launcher_round" | 9 | android:roundIcon="@mipmap/ic_launcher_round" |
| 12 | android:supportsRtl="true" | 10 | android:supportsRtl="true" |
| 13 | android:theme="@style/AppTheme"> | 11 | android:theme="@style/AppTheme"> |
| 12 | + <activity android:name="com.cnlive.strike.xiaojiaspeaker.ToolBarTestActivity"></activity> | ||
| 14 | <activity android:name="com.cnlive.strike.xiaojiaspeaker.MainActivity"> | 13 | <activity android:name="com.cnlive.strike.xiaojiaspeaker.MainActivity"> |
| 15 | <intent-filter> | 14 | <intent-filter> |
| 16 | <action android:name="android.intent.action.MAIN" /> | 15 | <action android:name="android.intent.action.MAIN" /> |
app/src/main/java/com/cnlive/strike/xiaojiaspeaker/MainActivity.java
| @@ -13,6 +13,7 @@ import com.cnlive.strike.xiaojiaspeaker.ui.activity.DeviceInstructionActivity; | @@ -13,6 +13,7 @@ import com.cnlive.strike.xiaojiaspeaker.ui.activity.DeviceInstructionActivity; | ||
| 13 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.DeviceManagerActivity; | 13 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.DeviceManagerActivity; |
| 14 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.FirmwareUpdateActivity; | 14 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.FirmwareUpdateActivity; |
| 15 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.SearchDeviceActivity; | 15 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.SearchDeviceActivity; |
| 16 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.SelectWifiActivity; | ||
| 16 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.SpeakerMainActivity; | 17 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.SpeakerMainActivity; |
| 17 | 18 | ||
| 18 | public class MainActivity extends AppCompatActivity { | 19 | public class MainActivity extends AppCompatActivity { |
| @@ -21,7 +22,7 @@ public class MainActivity extends AppCompatActivity { | @@ -21,7 +22,7 @@ public class MainActivity extends AppCompatActivity { | ||
| 21 | protected void onCreate(Bundle savedInstanceState) { | 22 | protected void onCreate(Bundle savedInstanceState) { |
| 22 | super.onCreate(savedInstanceState); | 23 | super.onCreate(savedInstanceState); |
| 23 | setContentView(R.layout.activity_speaker_main); | 24 | setContentView(R.layout.activity_speaker_main); |
| 24 | -// startActivity(new Intent(MainActivity.this, SpeakerMainActivity.class)); | 25 | +// startActivity(new Intent(MainActivity.this, ToolBarTestActivity.class)); |
| 25 | // startActivity(new Intent(MainActivity.this, BluetoothConnActivity.class)); | 26 | // startActivity(new Intent(MainActivity.this, BluetoothConnActivity.class)); |
| 26 | // startActivity(new Intent(MainActivity.this, BlueToothStep1Activity.class)); | 27 | // startActivity(new Intent(MainActivity.this, BlueToothStep1Activity.class)); |
| 27 | // startActivity(new Intent(MainActivity.this, ConnBluetoothSuccessActivity.class)); | 28 | // startActivity(new Intent(MainActivity.this, ConnBluetoothSuccessActivity.class)); |
| @@ -29,6 +30,8 @@ public class MainActivity extends AppCompatActivity { | @@ -29,6 +30,8 @@ public class MainActivity extends AppCompatActivity { | ||
| 29 | // startActivity(new Intent(MainActivity.this, DeviceInstructionActivity.class)); | 30 | // startActivity(new Intent(MainActivity.this, DeviceInstructionActivity.class)); |
| 30 | // startActivity(new Intent(MainActivity.this, DeviceManagerActivity.class)); | 31 | // startActivity(new Intent(MainActivity.this, DeviceManagerActivity.class)); |
| 31 | // startActivity(new Intent(MainActivity.this, FirmwareUpdateActivity.class)); | 32 | // startActivity(new Intent(MainActivity.this, FirmwareUpdateActivity.class)); |
| 33 | +// startActivity(new Intent(MainActivity.this, SelectWifiActivity.class)); | ||
| 34 | + | ||
| 32 | finish(); | 35 | finish(); |
| 33 | } | 36 | } |
| 34 | 37 |
app/src/main/java/com/cnlive/strike/xiaojiaspeaker/ToolBarTestActivity.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker; | ||
| 2 | + | ||
| 3 | +import android.databinding.DataBindingUtil; | ||
| 4 | +import android.support.design.widget.AppBarLayout; | ||
| 5 | +import android.support.v4.content.ContextCompat; | ||
| 6 | +import android.support.v7.app.AppCompatActivity; | ||
| 7 | +import android.os.Bundle; | ||
| 8 | +import android.util.Log; | ||
| 9 | + | ||
| 10 | +import com.cnlive.strike.speaker.R; | ||
| 11 | +import com.cnlive.strike.speaker.databinding.ActivityToolBarTestBinding; | ||
| 12 | + | ||
| 13 | +public class ToolBarTestActivity extends AppCompatActivity { | ||
| 14 | + private ActivityToolBarTestBinding binding; | ||
| 15 | + private String TAG = "ToolBarTestActivity"; | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + protected void onCreate(Bundle savedInstanceState) { | ||
| 19 | + super.onCreate(savedInstanceState); | ||
| 20 | + binding = DataBindingUtil.setContentView(this, R.layout.activity_tool_bar_test); | ||
| 21 | + } | ||
| 22 | +} |
app/src/main/res/layout/activity_tool_bar_test.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<layout> | ||
| 3 | + | ||
| 4 | + <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 5 | + xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| 6 | + xmlns:tools="http://schemas.android.com/tools" | ||
| 7 | + android:layout_width="match_parent" | ||
| 8 | + android:layout_height="match_parent" | ||
| 9 | + android:orientation="vertical" | ||
| 10 | + tools:context="com.cnlive.strike.xiaojiaspeaker.ToolBarTestActivity" | ||
| 11 | + tools:ignore="MissingDefaultResource"> | ||
| 12 | + | ||
| 13 | + <android.support.design.chip.Chip | ||
| 14 | + android:layout_width="wrap_content" | ||
| 15 | + android:layout_height="wrap_content" | ||
| 16 | + android:text="text" /> | ||
| 17 | + | ||
| 18 | + </android.support.design.widget.CoordinatorLayout> | ||
| 19 | +</layout> | ||
| 0 | \ No newline at end of file | 20 | \ No newline at end of file |
app/src/main/res/values/strings.xml
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/AllDeviceFragmentView.java
| @@ -2,8 +2,11 @@ package com.cnlive.strike.xiaojiaspeaker.frame.view; | @@ -2,8 +2,11 @@ package com.cnlive.strike.xiaojiaspeaker.frame.view; | ||
| 2 | 2 | ||
| 3 | import android.app.Activity; | 3 | import android.app.Activity; |
| 4 | import android.graphics.Color; | 4 | import android.graphics.Color; |
| 5 | +import android.support.design.widget.BottomSheetBehavior; | ||
| 6 | +import android.support.design.widget.BottomSheetDialog; | ||
| 5 | import android.support.v7.widget.LinearLayoutManager; | 7 | import android.support.v7.widget.LinearLayoutManager; |
| 6 | import android.util.Log; | 8 | import android.util.Log; |
| 9 | +import android.view.LayoutInflater; | ||
| 7 | import android.view.View; | 10 | import android.view.View; |
| 8 | 11 | ||
| 9 | import com.cnlive.strike.xiaojiaspeaker.R; | 12 | import com.cnlive.strike.xiaojiaspeaker.R; |
| @@ -59,6 +62,18 @@ public class AllDeviceFragmentView implements MvpView { | @@ -59,6 +62,18 @@ public class AllDeviceFragmentView implements MvpView { | ||
| 59 | } | 62 | } |
| 60 | 63 | ||
| 61 | public void initPopView() { | 64 | public void initPopView() { |
| 65 | +// View contentView = LayoutInflater.from(getContext()) | ||
| 66 | +// .inflate(R.layout.activity_all_device, null); | ||
| 67 | +// BottomSheetDialog dialog = new BottomSheetDialog(getContext()); | ||
| 68 | +// dialog.setContentView(contentView); | ||
| 69 | +// dialog.setCancelable(false); | ||
| 70 | +// BottomSheetBehavior sheetBehavior = BottomSheetBehavior.from((View) contentView.getParent()); | ||
| 71 | +// sheetBehavior.setPeekHeight(200); | ||
| 72 | + //给布局设置透明背景色,让图片突出来 | ||
| 73 | +// bottomSheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet) | ||
| 74 | +// .setBackgroundColor(getResources().getColor(android.R.color.transparent)); | ||
| 75 | +// dialog.show(); | ||
| 76 | + | ||
| 62 | popMenuInfoList = new ArrayList<>(); | 77 | popMenuInfoList = new ArrayList<>(); |
| 63 | PopMenuInfo popMenuInfo = new PopMenuInfo(); | 78 | PopMenuInfo popMenuInfo = new PopMenuInfo(); |
| 64 | popMenuInfo.setTitle("使用者管理"); | 79 | popMenuInfo.setTitle("使用者管理"); |
| @@ -84,7 +99,7 @@ public class AllDeviceFragmentView implements MvpView { | @@ -84,7 +99,7 @@ public class AllDeviceFragmentView implements MvpView { | ||
| 84 | .setLineVisible(View.VISIBLE) | 99 | .setLineVisible(View.VISIBLE) |
| 85 | // .setArrowHeight(30f) | 100 | // .setArrowHeight(30f) |
| 86 | // .setArrowHeight(30f) | 101 | // .setArrowHeight(30f) |
| 87 | - //.setCancelable(false) | 102 | + .setCancelable(false) |
| 88 | .setCornerRadius(10f) | 103 | .setCornerRadius(10f) |
| 89 | .build(); | 104 | .build(); |
| 90 | } | 105 | } |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/AllDeviceAdapter.java
| @@ -93,12 +93,10 @@ public class AllDeviceAdapter extends RecyclerView.Adapter { | @@ -93,12 +93,10 @@ public class AllDeviceAdapter extends RecyclerView.Adapter { | ||
| 93 | if (null != onItemClickListener) { | 93 | if (null != onItemClickListener) { |
| 94 | onItemClickListener.onItemClick(getAdapterPosition(), allDeviceInfos.get(getAdapterPosition())); | 94 | onItemClickListener.onItemClick(getAdapterPosition(), allDeviceInfos.get(getAdapterPosition())); |
| 95 | } | 95 | } |
| 96 | - Log.e(TAG, "onClick: " + getAdapterPosition()); | ||
| 97 | } else if (R.id.ll_add == view.getId()) { | 96 | } else if (R.id.ll_add == view.getId()) { |
| 98 | if (null != onAddClickListener) { | 97 | if (null != onAddClickListener) { |
| 99 | onAddClickListener.onAddClick(); | 98 | onAddClickListener.onAddClick(); |
| 100 | } | 99 | } |
| 101 | - Log.e(TAG, "onAddClickListener: " + getAdapterPosition()); | ||
| 102 | } | 100 | } |
| 103 | } | 101 | } |
| 104 | } | 102 | } |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/AllDeviceFragment.java
| @@ -24,7 +24,6 @@ import java.util.List; | @@ -24,7 +24,6 @@ import java.util.List; | ||
| 24 | public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, AllDeviceFragmentPresenter, Object, FragmentAllDeviceBinding> { | 24 | public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, AllDeviceFragmentPresenter, Object, FragmentAllDeviceBinding> { |
| 25 | private UIPopup qmuiPopup; | 25 | private UIPopup qmuiPopup; |
| 26 | private QMUIAlphaImageButton addButton; | 26 | private QMUIAlphaImageButton addButton; |
| 27 | - ; | ||
| 28 | 27 | ||
| 29 | public static AllDeviceFragment newInstance() { | 28 | public static AllDeviceFragment newInstance() { |
| 30 | AllDeviceFragment fragment = new AllDeviceFragment(); | 29 | AllDeviceFragment fragment = new AllDeviceFragment(); |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/popmenu/PopMenu.java
| @@ -7,11 +7,13 @@ import android.app.Activity; | @@ -7,11 +7,13 @@ import android.app.Activity; | ||
| 7 | import android.graphics.Color; | 7 | import android.graphics.Color; |
| 8 | import android.graphics.PointF; | 8 | import android.graphics.PointF; |
| 9 | import android.graphics.RectF; | 9 | import android.graphics.RectF; |
| 10 | +import android.graphics.drawable.BitmapDrawable; | ||
| 10 | import android.graphics.drawable.GradientDrawable; | 11 | import android.graphics.drawable.GradientDrawable; |
| 11 | import android.os.Build; | 12 | import android.os.Build; |
| 12 | import android.support.annotation.ColorInt; | 13 | import android.support.annotation.ColorInt; |
| 13 | import android.support.annotation.DimenRes; | 14 | import android.support.annotation.DimenRes; |
| 14 | import android.support.annotation.NonNull; | 15 | import android.support.annotation.NonNull; |
| 16 | +import android.support.design.widget.BottomSheetDialog; | ||
| 15 | import android.support.v7.widget.LinearLayoutManager; | 17 | import android.support.v7.widget.LinearLayoutManager; |
| 16 | import android.support.v7.widget.RecyclerView; | 18 | import android.support.v7.widget.RecyclerView; |
| 17 | import android.util.DisplayMetrics; | 19 | import android.util.DisplayMetrics; |
| @@ -84,8 +86,8 @@ public final class PopMenu { | @@ -84,8 +86,8 @@ public final class PopMenu { | ||
| 84 | mScreenHeightPixels = dm.heightPixels; | 86 | mScreenHeightPixels = dm.heightPixels; |
| 85 | mScreenWidthPixels = dm.widthPixels; | 87 | mScreenWidthPixels = dm.widthPixels; |
| 86 | mPopupWindow = new PopupWindow(builder.mContext); | 88 | mPopupWindow = new PopupWindow(builder.mContext); |
| 87 | - mPopupWindow.setBackgroundDrawable(null); | ||
| 88 | - mPopupWindow.setClippingEnabled(false); | 89 | +// mPopupWindow.setBackgroundDrawable(null); |
| 90 | + mPopupWindow.setBackgroundDrawable(new BitmapDrawable());//必须这么设置,要不安卓6.0以后,点击空白区域,无法消失 | ||
| 89 | mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); | 91 | mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); |
| 90 | mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | 92 | mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); |
| 91 | mPopupWindow.setContentView(getContentView(builder)); | 93 | mPopupWindow.setContentView(getContentView(builder)); |
| @@ -182,6 +184,7 @@ public final class PopMenu { | @@ -182,6 +184,7 @@ public final class PopMenu { | ||
| 182 | } | 184 | } |
| 183 | 185 | ||
| 184 | public void show(final View anchorView) { | 186 | public void show(final View anchorView) { |
| 187 | + | ||
| 185 | if (!isShowing()) { | 188 | if (!isShowing()) { |
| 186 | // 是否设置设置背景颜色变暗 | 189 | // 是否设置设置背景颜色变暗 |
| 187 | if (builder.isShowDarkenBackground) { | 190 | if (builder.isShowDarkenBackground) { |
| @@ -202,6 +205,8 @@ public final class PopMenu { | @@ -202,6 +205,8 @@ public final class PopMenu { | ||
| 202 | mPopupWindow.showAtLocation(mAnchorView, 0, 0, 0); | 205 | mPopupWindow.showAtLocation(mAnchorView, 0, 0, 0); |
| 203 | } | 206 | } |
| 204 | }); | 207 | }); |
| 208 | + } else { | ||
| 209 | + mPopupWindow.dismiss(); | ||
| 205 | } | 210 | } |
| 206 | } | 211 | } |
| 207 | 212 |
module_xiaojiaSoundBox/src/main/res/layout/fragment_search_device.xml
| @@ -25,6 +25,7 @@ | @@ -25,6 +25,7 @@ | ||
| 25 | android:id="@+id/rvBlueTooth" | 25 | android:id="@+id/rvBlueTooth" |
| 26 | android:layout_width="match_parent" | 26 | android:layout_width="match_parent" |
| 27 | android:layout_height="match_parent" | 27 | android:layout_height="match_parent" |
| 28 | + android:overScrollMode="never" | ||
| 28 | android:paddingTop="10dp" /> | 29 | android:paddingTop="10dp" /> |
| 29 | <!-- loading视图--> | 30 | <!-- loading视图--> |
| 30 | <LinearLayout | 31 | <LinearLayout |
| @@ -49,7 +50,6 @@ | @@ -49,7 +50,6 @@ | ||
| 49 | android:id="@+id/ll_retry" | 50 | android:id="@+id/ll_retry" |
| 50 | android:layout_width="match_parent" | 51 | android:layout_width="match_parent" |
| 51 | android:layout_height="match_parent" | 52 | android:layout_height="match_parent" |
| 52 | - android:background="@color/white" | ||
| 53 | android:gravity="center" | 53 | android:gravity="center" |
| 54 | android:orientation="vertical" | 54 | android:orientation="vertical" |
| 55 | android:visibility="gone"> | 55 | android:visibility="gone"> |