Browse Source

Merge branch 'fixAnnotationAttributeWindowNotShow' into 'master'

修正右側工具欄AnnotationAttributeWindow在Android 5.0以下不會顯示的錯誤

See merge request kdanandroid/pdf/pdfreaderreadermodule!26
Wayne Huang 5 years ago
parent
commit
f6421fa933

+ 13 - 4
src/main/java/com/kdanmobile/reader/view/AnnotationAttributeWindow.kt

@@ -1,8 +1,11 @@
 package com.kdanmobile.reader.view
 
 import android.content.Context
+import android.graphics.Color
 import android.os.Build
 import android.support.v4.content.ContextCompat
+import android.support.v7.widget.MyRoundRectDrawableWithShadow
+import android.widget.LinearLayout
 import android.widget.PopupWindow
 import com.kdanmobile.reader.R
 
@@ -10,14 +13,20 @@ class AnnotationAttributeWindow(context: Context, isSimpleMode: Boolean) : Popup
     val annotationAttributeView: AnnotationAttributeView
 
     init {
+        width = LinearLayout.LayoutParams.WRAP_CONTENT
+        height = LinearLayout.LayoutParams.WRAP_CONTENT
         isOutsideTouchable = true
         isFocusable = true
-        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
-            elevation = context.resources.getDimension(R.dimen.reader_annotation_property_setting_window_elevation)
-        }
-        setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.bg_annotation_property_setting_window))
         annotationAttributeView = AnnotationAttributeView(context)
         annotationAttributeView.isSimpleMode = isSimpleMode
         contentView = annotationAttributeView
+
+        val elevationSize = context.resources.getDimension(R.dimen.reader_annotation_property_setting_window_elevation)
+        when {
+            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP -> elevation = elevationSize
+            Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN -> contentView.background = MyRoundRectDrawableWithShadow(context.resources, Color.TRANSPARENT, 0f, elevationSize, elevationSize)
+            else -> contentView.setBackgroundDrawable(MyRoundRectDrawableWithShadow(context.resources, Color.TRANSPARENT, 0f, elevationSize, elevationSize))
+        }
+        setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.bg_annotation_property_setting_window))
     }
 }

+ 1 - 0
src/main/res/layout/view_reader_annotation_property.xml

@@ -5,6 +5,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="240dp"
     android:layout_height="wrap_content"
+    android:background="@drawable/bg_annotation_property_setting_window"
     android:orientation="vertical">
 
     <android.support.constraint.Group