popupwindow中的edittext无法复制粘贴问题

chengzhenyu преди 8 години
родител
ревизия
c4c034c7c1

+ 4 - 5
app/src/main/java/ai/pai/client/activity/PhotoDetailsActivity.java

@@ -12,7 +12,6 @@ import android.view.ViewGroup;
12 12
 import android.widget.ImageView;
13 13
 import android.widget.LinearLayout;
14 14
 import android.widget.TextView;
15
-import android.widget.Toast;
16 15
 
17 16
 import com.android.common.executors.ThreadExecutor;
18 17
 import com.android.common.utils.DeviceUtils;
@@ -54,8 +53,8 @@ import ai.pai.client.utils.SystemUtils;
54 53
 import ai.pai.client.utils.ToastUtils;
55 54
 import ai.pai.client.utils.UmengEvent;
56 55
 import ai.pai.client.utils.UrlContainer;
56
+import ai.pai.client.views.CommentDialog;
57 57
 import ai.pai.client.views.CountView;
58
-import ai.pai.client.views.InputPopup;
59 58
 import ai.pai.client.views.NestedListView;
60 59
 import ai.pai.client.views.PhotoSharePopup;
61 60
 import ai.pai.client.wxapi.PayListenerManager;
@@ -94,7 +93,7 @@ public class PhotoDetailsActivity extends BaseActivity implements View.OnClickLi
94 93
 
95 94
     private UMShareAPI mShareAPI;
96 95
     private PhotoSharePopup sharePop;
97
-    private InputPopup inputPopup;
96
+    private CommentDialog inputPopup;
98 97
 
99 98
     private HttpPostTask fetchThumbUpListTask;
100 99
     private HttpPostTask fetchCommentListTask;
@@ -334,8 +333,8 @@ public class PhotoDetailsActivity extends BaseActivity implements View.OnClickLi
334 333
                 break;
335 334
             case R.id.floating_btn_comment:
336 335
                 MobclickAgent.onEvent(this, UmengEvent.detail_comment_btn_click);
337
-                inputPopup = new InputPopup(this,this);
338
-                inputPopup.showPopupWindow();
336
+                inputPopup = new CommentDialog(this,this);
337
+                inputPopup.show();
339 338
                 break;
340 339
             case R.id.btn_comment_send:
341 340
                 MobclickAgent.onEvent(this, UmengEvent.detail_comment_send_btn_click);

+ 96 - 0
app/src/main/java/ai/pai/client/views/CommentDialog.java

@@ -0,0 +1,96 @@
1
+package ai.pai.client.views;
2
+
3
+import android.app.Activity;
4
+import android.app.Dialog;
5
+import android.content.Context;
6
+import android.text.Editable;
7
+import android.text.TextWatcher;
8
+import android.view.Gravity;
9
+import android.view.LayoutInflater;
10
+import android.view.MotionEvent;
11
+import android.view.View;
12
+import android.view.Window;
13
+import android.view.WindowManager;
14
+import android.widget.Button;
15
+import android.widget.EditText;
16
+
17
+import ai.pai.client.R;
18
+
19
+public class CommentDialog extends Dialog {
20
+
21
+    private View rootView;
22
+    private Button mSendBtn;
23
+    private EditText mInputEdit;
24
+
25
+    private View.OnClickListener listener;
26
+
27
+    public CommentDialog(Activity context, View.OnClickListener listener) {
28
+        super(context, R.style.inputDialog);
29
+        this.listener = listener;
30
+        initViews(context);
31
+    }
32
+
33
+    private void initViews(Context context) {
34
+        LayoutInflater inflater = (LayoutInflater) context
35
+                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
36
+        rootView = inflater.inflate(R.layout.popup_comment_input, null);
37
+        mSendBtn = (Button) rootView.findViewById(R.id.btn_comment_send);
38
+        mInputEdit = (EditText) rootView.findViewById(R.id.et_comment_content);
39
+        mInputEdit.addTextChangedListener(new TextWatcher() {
40
+            @Override
41
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
42
+
43
+            }
44
+
45
+            @Override
46
+            public void onTextChanged(CharSequence s, int start, int before, int count) {
47
+
48
+            }
49
+
50
+            @Override
51
+            public void afterTextChanged(Editable s) {
52
+                mSendBtn.setEnabled(s.toString().length() > 0);
53
+            }
54
+        });
55
+        this.setContentView(rootView);
56
+        mSendBtn.setOnClickListener(listener);
57
+        rootView.setOnTouchListener(new View.OnTouchListener() {
58
+
59
+            public boolean onTouch(View v, MotionEvent event) {
60
+                int height = rootView.findViewById(R.id.popup_anima).getTop();
61
+                int y = (int) event.getY();
62
+                if (event.getAction() == MotionEvent.ACTION_UP) {
63
+                    if (y < height) {
64
+                        dismiss();
65
+                    }
66
+                }
67
+                return true;
68
+            }
69
+        });
70
+    }
71
+
72
+    @Override
73
+    public void show() {
74
+        Window window = getWindow();
75
+        window.setGravity(Gravity.BOTTOM);  //此处可以设置dialog显示的位置
76
+        window.setWindowAnimations(R.style.AnimBottom);  //添加动画
77
+
78
+        WindowManager.LayoutParams layoutParams = window.getAttributes();
79
+        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
80
+        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
81
+        window.setAttributes(layoutParams);
82
+        super.show();
83
+    }
84
+
85
+    public String getInputContent() {
86
+        if (mInputEdit.getText() != null) {
87
+            return mInputEdit.getText().toString();
88
+        }
89
+        return null;
90
+    }
91
+
92
+    public View getInputView() {
93
+        return mInputEdit;
94
+    }
95
+
96
+}

+ 15 - 0
app/src/main/res/anim/push_bottom_in.xml

@@ -0,0 +1,15 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<!-- 上下滑入式 -->
3
+<set xmlns:android="http://schemas.android.com/apk/res/android" >
4
+
5
+    <translate
6
+        android:duration="300"
7
+        android:fromYDelta="100%p"
8
+        android:toYDelta="0"        
9
+     />   
10
+    <!--  <alpha
11
+	android:fromAlpha="0.0"
12
+	android:toAlpha="1.0"
13
+	android:duration="200"
14
+	/>  -->    
15
+</set>

+ 15 - 0
app/src/main/res/anim/push_bottom_out.xml

@@ -0,0 +1,15 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<!-- 上下滑入式 -->
3
+<set xmlns:android="http://schemas.android.com/apk/res/android" >
4
+
5
+    
6
+    <translate
7
+        android:duration="300"
8
+        android:fromYDelta="0"
9
+        android:toYDelta="100%p" />
10
+<!--  <alpha
11
+	android:fromAlpha="1.0"
12
+	android:toAlpha="0.0"
13
+	android:duration="200"
14
+	/>   -->
15
+</set>

+ 3 - 2
app/src/main/res/layout/content_main.xml

@@ -15,14 +15,15 @@
15 15
             android:layout_width="wrap_content"
16 16
             android:layout_height="wrap_content"
17 17
             android:layout_centerVertical="true"
18
-            android:layout_marginLeft="8dp"
18
+            android:paddingLeft="8dp"
19
+            android:paddingRight="8dp"
19 20
             android:src="@drawable/three_dot"/>
20 21
 
21 22
         <com.android.views.roundrect.RoundedImageView
22 23
             android:id="@+id/drawer_toggle"
23 24
             android:layout_width="32dp"
24 25
             android:layout_height="32dp"
25
-            android:layout_marginLeft="10dp"
26
+            android:layout_marginLeft="2dp"
26 27
             android:layout_toRightOf="@id/iv_three_dot"
27 28
             app:riv_corner_radius="5dip"
28 29
             app:riv_border_width="1px"

+ 14 - 0
app/src/main/res/values/styles.xml

@@ -59,4 +59,18 @@
59 59
         <item name="android:windowAnimationStyle">@android:style/Animation</item>
60 60
     </style>
61 61
 
62
+    <!--带输入框-->
63
+    <style name="inputDialog"  parent="@android:style/Theme.Dialog">
64
+        <item name="android:windowIsFloating">true</item>
65
+        <item name="android:windowSoftInputMode">stateAlwaysVisible|adjustResize</item>
66
+        <item name="android:backgroundDimEnabled">false</item>
67
+        <item name="android:windowNoTitle">true</item>
68
+        <item name="android:windowBackground">@android:color/transparent</item>
69
+        <item name="android:windowFrame">@android:color/transparent</item>
70
+    </style>
71
+
72
+    <style name="AnimBottom" parent="@android:style/Animation">
73
+        <item name="android:windowEnterAnimation">@anim/push_bottom_in</item>
74
+        <item name="android:windowExitAnimation">@anim/push_bottom_out</item>
75
+    </style>
62 76
 </resources>