dxh 5 年之前
父节点
当前提交
d346a7d2bd

+ 2 - 2
app/src/main/java/com/electric/chargingpile/activity/PublishPicTopicActivity.java

@ -482,9 +482,9 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
482 482
    }
483 483
484 484
    @Override
485
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
485
    protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
486 486
        super.onActivityResult(requestCode, resultCode, data);
487
        if (requestCode == reqTopic && resultCode == -100) {
487
        if (requestCode == 100 && resultCode == -100) {
488 488
            talkRecommendBean = (TalkRecommendBean) data.getSerializableExtra("topic");
489 489
            if (talkRecommendBean != null) {
490 490
                mPublishtopicChooseTopic.setText("# " + talkRecommendBean.topicName);

+ 413 - 412
app/src/main/java/com/electric/chargingpile/activity/PublishTopicActivity.java

@ -1,412 +1,413 @@
1
package com.electric.chargingpile.activity;
2

3
import android.app.Activity;
4
import android.content.Context;
5
import android.content.DialogInterface;
6
import android.content.Intent;
7
import android.graphics.drawable.Drawable;
8
import android.net.Uri;
9
import android.os.Bundle;
10
import android.os.Environment;
11
import android.support.annotation.Nullable;
12
import android.support.v7.app.AlertDialog;
13
import android.text.Editable;
14
import android.text.Html;
15
import android.text.TextUtils;
16
import android.text.TextWatcher;
17
import android.util.Log;
18
import android.view.KeyEvent;
19
import android.view.View;
20
import android.view.View.OnClickListener;
21
import android.widget.EditText;
22
import android.widget.ImageView;
23
import android.widget.RelativeLayout;
24
import android.widget.TextView;
25
import android.widget.Toast;
26

27
import com.blankj.utilcode.util.ToastUtils;
28
import com.bumptech.glide.Glide;
29
import com.bumptech.glide.load.DataSource;
30
import com.bumptech.glide.load.engine.GlideException;
31
import com.bumptech.glide.request.RequestListener;
32
import com.bumptech.glide.request.RequestOptions;
33
import com.bumptech.glide.request.target.Target;
34
import com.electric.chargingpile.R;
35
import com.electric.chargingpile.application.MainApplication;
36
import com.electric.chargingpile.data.AuthSignBean;
37
import com.electric.chargingpile.data.TalkRecommendBean;
38
import com.electric.chargingpile.util.BarColorUtil;
39
import com.electric.chargingpile.util.JsonUtils;
40
import com.electric.chargingpile.util.ToastUtil;
41
import com.luck.picture.lib.PictureSelector;
42
import com.luck.picture.lib.compress.Luban;
43
import com.luck.picture.lib.config.PictureConfig;
44
import com.luck.picture.lib.config.PictureMimeType;
45
import com.luck.picture.lib.entity.LocalMedia;
46
import com.umeng.analytics.MobclickAgent;
47
import com.upyun.library.common.UploadEngine;
48
import com.upyun.library.listener.UpCompleteListener;
49
import com.upyun.library.listener.UpProgressListener;
50
import com.zhy.http.okhttp.OkHttpUtils;
51
import com.zhy.http.okhttp.callback.StringCallback;
52

53
import java.io.File;
54
import java.util.ArrayList;
55
import java.util.HashMap;
56
import java.util.List;
57
import java.util.Map;
58

59
import okhttp3.Call;
60

61
public class PublishTopicActivity extends Activity implements OnClickListener {
62
    Context mContext;
63
    private ImageView mPublishtopicBack;
64
    private TextView mPublishtopicPublish;
65
    private EditText mPublishtopicCon;
66
    private ImageView mPublishtopicGv;
67
    private TextView mPublishtopicChooseTopic;
68
    private TextView mPublishtopicChoosePreview;
69
    private TextView mPublishtopicWordNum;
70
    private ImageView mPublishTopicDe;
71

72
    private RelativeLayout mItemVideoLl;
73
    private ImageView mItemVideol;
74
    private View mItemVideoDelete;
75

76

77
    public static final String CACHE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath() + "/cdz";
78

79

80
    public static final String IMAGE_CACHE = CACHE_DIR + "/cache/image/";
81
    LocalMedia media;
82

83
    @Override
84
    protected void onCreate(Bundle savedInstanceState) {
85
        super.onCreate(savedInstanceState);
86
        setContentView(R.layout.activity_publishtopic);
87
        mContext = this;
88
        BarColorUtil.initStatusBarColor(PublishTopicActivity.this);
89
        initView();
90
    }
91

92
    private void initView() {
93
        mPublishtopicBack = (ImageView) findViewById(R.id.publishtopic_back);
94
        mPublishtopicPublish = (TextView) findViewById(R.id.publishtopic_publish);
95
        mPublishtopicCon = (EditText) findViewById(R.id.publishtopic_con);
96
        mPublishtopicGv = (ImageView) findViewById(R.id.item_choose_video);
97
        mPublishtopicChooseTopic = (TextView) findViewById(R.id.publishtopic_choose_topic);
98
        mPublishtopicChoosePreview = (TextView) findViewById(R.id.publishtopic_choose_preview);
99
        mPublishtopicWordNum = (TextView) findViewById(R.id.publishtopic_word_num);
100
        mPublishTopicDe = (ImageView) findViewById(R.id.publishtopic_choose_topic_de);
101

102
        mItemVideoLl = (RelativeLayout) findViewById(R.id.item_video_ll);
103
        mItemVideo = (ImageView) findViewById(R.id.item_video);
104
        mItemVideoDelete = (View) findViewById(R.id.item_video_delete);
105

106

107
        mPublishtopicCon.addTextChangedListener(new TextWatcher() {
108
            @Override
109
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
110

111
            }
112

113
            @Override
114
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
115

116

117
            }
118

119
            @Override
120
            public void afterTextChanged(Editable editable) {
121
                int length = editable.length();
122
                if (length > 500) {
123
                    mPublishtopicWordNum.setText(Html.fromHtml("<font  color=\"#FF4E4E\">" + length + "</font>/500"));
124
                } else {
125
                    mPublishtopicWordNum.setText(length + "/500");
126
                }
127
            }
128
        });
129

130

131
        mPublishtopicBack.setOnClickListener(this);
132
        mPublishtopicPublish.setOnClickListener(this);
133
        mPublishtopicChoosePreview.setOnClickListener(this);
134
        mPublishtopicChooseTopic.setOnClickListener(this);
135
        mPublishTopicDe.setOnClickListener(this);
136
        mItemVideoDelete.setOnClickListener(this);
137
        mPublishtopicGv.setOnClickListener(this);
138
    }
139

140

141
    @Override
142
    public void onClick(View v) {
143
        switch (v.getId()) {
144
            case R.id.publishtopic_back:
145
                showDialogToExit();
146
//                finish();
147
                break;
148
            case R.id.publishtopic_publish:
149
                if (media == null) {
150
                    ToastUtils.showLong("请选择视频!");
151
                    return;
152
                }
153
                if (talkRecommendBean == null) {
154
                    ToastUtils.showLong("请选择话题!");
155
                    return;
156
                }
157
                getYouPaiData();
158
                break;
159

160
            case R.id.publishtopic_choose_topic:
161
                startActivityForResult(new Intent(this, TopicActivity.class), reqTopic);
162
                break;
163
            case R.id.publishtopic_choose_preview:
164
                break;
165
            case R.id.publishtopic_choose_topic_de:
166
                mPublishtopicChooseTopic.setText("# 选择话题");
167
                mPublishTopicDe.setVisibility(View.GONE);
168
                talkRecommendBean = null;
169
                break;
170
            case R.id.item_choose_video:
171
                PictureSelector.create(this)
172
                        .openGallery(PictureMimeType.ofVideo())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()
173
                        .theme(R.style.picture_default_style)// 主题样式设置 具体参考 libray中values/styles
174
                        .maxSelectNum(9)// 最大图片选择数量
175
                        .minSelectNum(1)// 最小选择数量
176
                        .imageSpanCount(4)// 每行显示个数
177
                        .selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 PictureConfig.MULTIPLE : PictureConfig.SINGLE
178
                        .previewImage(true)// 是否可预览图片
179
                        .previewVideo(true)// 是否可预览视频
180
                        .enablePreviewAudio(false)// 是否预览音频
181
                        .isCamera(true)// 是否显示拍照按钮
182
                        .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
183
                        .setOutputCameraPath(IMAGE_CACHE)// 自定义拍照保存路径
184
                        .compress(true)// 是否压缩
185
                        .compressMode(PictureConfig.LUBAN_COMPRESS_MODE)//系统自带 or 鲁班压缩 PictureConfig.SYSTEM_COMPRESS_MODE or LUBAN_COMPRESS_MODE
186
                        .glideOverride(160, 160)// glide 加载宽高,越小图片列表越流畅,但会影响列表图片浏览的清晰度
187
                        .isGif(false)// 是否显示gif图片
188
                        .openClickSound(false)// 是否开启点击声音
189
                        .compressGrade(Luban.CUSTOM_GEAR)
190
                        .compressMaxKB(1024)//压缩最大值kb compressGrade()为Luban.CUSTOM_GEAR有效
191
                        .minimumCompressSize(500) //add by tanhaiqin, 图片大小 <= 500KB(数字可变) 不需要压缩
192
                        .videoSecond(5 * 60)//显示多少秒以内的视频
193
                        .recordVideoSecond(15)//录制视频秒数 默认60秒
194
                        .forResult(PictureConfig.CHOOSE_REQUEST);
195
                break;
196
            case R.id.item_video_delete:
197
                mItemVideoLl.setVisibility(View.GONE);
198
                mPublishtopicGv.setVisibility(View.VISIBLE);
199
                media = null;
200
                break;
201
            default:
202
                break;
203
        }
204
    }
205

206
    private void getYouPaiData() {
207
        String fileNames = media.getPath().substring(media.getPath().lastIndexOf("/") + 1);
208
        String url = MainApplication.urlNew + "/topic/sign.do";
209
        Map<String, String> map = new HashMap<>();
210
        map.put("fileNames", fileNames);
211
        Log.e("fileNameDir fileName", fileNames);
212
        map.put("targetType", "23");//23视频/24图片
213
        OkHttpUtils
214
                .post()
215
                .params(map)
216
                .url(url)
217
                .build()
218
                .connTimeOut(6000)
219
                .readTimeOut(6000)
220
                .execute(new StringCallback() {
221
                    @Override
222
                    public void onError(Call call, Exception e) {
223
                    }
224

225
                    @Override
226
                    public void onResponse(String response) {
227
                        String rtnCode = JsonUtils.getKeyResult(response, "code");
228
                        if ("1000".equals(rtnCode)) {
229
                            String rtnMsg = JsonUtils.getKeyResult(response, "data");
230
                            ArrayList<AuthSignBean> signBeans = (ArrayList<AuthSignBean>) JsonUtils.parseToObjectList(rtnMsg, AuthSignBean.class);
231

232
                            if (null != signBeans && signBeans.size() > 0) {
233
                                    String sign = signBeans.get(0).sign;
234
                                    String policy = signBeans.get(0).policy;
235
                                    formUpload(media.getPath(), sign, policy);
236
                            }
237
                        }
238
                    }
239
                });
240

241
    }
242

243
    /**
244
     * 表单上传
245
     *
246
     * @param SAMPLE_PIC_FILE
247
     * @param sign
248
     * @param policyServer
249
     */
250
    private void formUpload(String SAMPLE_PIC_FILE, String sign, String policyServer) {
251
        File temp = new File(SAMPLE_PIC_FILE);
252
//        //进度回调,可为空
253
        UpProgressListener progressListener = new UpProgressListener() {
254
            @Override
255
            public void onRequestProgress(long bytesWrite, long contentLength) {
256
            }
257
        };
258

259
        //结束回调,不可为空
260
        UpCompleteListener completeListener = new UpCompleteListener() {
261
            @Override
262
            public void onComplete(boolean isSuccess, String result) {
263
                if (isSuccess) {
264
                    requestPublishServer("["+result+"]");
265
                }
266
            }
267
        };
268

269
        //表单上传(服务器签名方式)
270
        UploadEngine.getInstance().formUpload(temp, policyServer, "d1evvideo01", sign, completeListener,
271
                progressListener);
272

273
    }
274

275
    private void requestPublishServer(String urls) {
276
        String url = MainApplication.urlNew + "/topic/publish.do";
277
        Map<String, String> map = new HashMap<>();
278
        map.put("content", mPublishtopicCon.getText().toString());
279
        map.put("urls", urls);
280
        map.put("topicId", talkRecommendBean.targetId + "");
281
        map.put("targetType",  "23");
282
        if (MainApplication.isLogin()) {
283
            map.put("userId", MainApplication.userId);
284
            map.put("appToken", MainApplication.messageToken);
285
        }
286
        OkHttpUtils.post().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
287
            @Override
288
            public void onError(Call call, Exception e) {
289
                ToastUtil.showToast(getApplicationContext(), "发布失败,请重试", Toast.LENGTH_SHORT);
290
            }
291

292
            @Override
293
            public void onResponse(String response) {
294
                String rtnCode = JsonUtils.getKeyResult(response, "code");
295
                if ("1000".equals(rtnCode)) {
296
                    ToastUtil.showToast(getApplicationContext(), "发布成功", Toast.LENGTH_SHORT);
297
                    finish();
298
                } else {
299
                    String message = JsonUtils.getKeyResult(response, "desc");
300
                    ToastUtil.showToast(getApplicationContext(), message, Toast.LENGTH_SHORT);
301
                }
302
            }
303
        });
304
    }
305

306

307
    final int reqTopic = 100;
308

309
    TalkRecommendBean talkRecommendBean = null;
310

311
    @Override
312
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
313
        super.onActivityResult(requestCode, resultCode, data);
314

315
        if (requestCode == reqTopic && resultCode == -100) {
316
            talkRecommendBean = (TalkRecommendBean) data.getSerializableExtra("topic");
317
            if (talkRecommendBean != null) {
318
                mPublishtopicChooseTopic.setText("# " + talkRecommendBean.topicName);
319
                mPublishTopicDe.setVisibility(View.VISIBLE);
320
            }
321
        } else if (requestCode == PictureConfig.CHOOSE_REQUEST && resultCode == RESULT_OK) {
322
            List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
323
            if (selectList != null && selectList.size() > 0) {
324
                media = selectList.get(0);
325
                if (TextUtils.isEmpty(media.getPath())) {
326
                    return;
327
                }
328
                if (!fileIsExists(media.getPath())) {
329
                    Log.e("yopic", "文件可能不存在了~");
330
                    return;
331
                }
332

333
                Glide.with(this).load(Uri.fromFile(new File(media.getPath())))
334
                        .listener(new RequestListener<Drawable>() {
335
                            @Override
336
                            public boolean onLoadFailed(@Nullable GlideException e, Object model,
337
                                                        Target<Drawable> target, boolean isFirstResource) {
338
                                return false;
339
                            }
340

341
                            @Override
342
                            public boolean onResourceReady(Drawable resource, Object model,
343
                                                           Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
344
                                return false;
345
                            }
346
                        })
347
                        .apply(new RequestOptions().centerCrop())
348
                        .into(mItemVideo);
349
                mItemVideoLl.setVisibility(View.VISIBLE);
350
                mPublishtopicGv.setVisibility(View.GONE);
351
                Log.e("yopic", "TEST===> video path = " + media.getPath()
352
                        + ",  compressPath = " + media.getCompressPath()
353
                        + ", height = " + media.getHeight()
354
                        + ", width = " + media.getWidth());
355
            }
356

357
        }
358
    }
359

360
    public static boolean fileIsExists(String strFile) {
361
        if (TextUtils.isEmpty(strFile)) {
362
            return false;
363
        }
364
        try {
365
            File f = new File(strFile);
366
            if (!f.exists()) {
367
                return false;
368
            }
369

370
        } catch (Exception e) {
371
            return false;
372
        }
373

374
        return true;
375
    }
376

377
    @Override
378
    protected void onResume() {
379
        super.onResume();
380
        MobclickAgent.onResume(this);
381
    }
382

383
    @Override
384
    protected void onPause() {
385
        super.onPause();
386
        MobclickAgent.onPause(this);
387
    }
388

389
    private void showDialogToExit(){
390
        AlertDialog.Builder builder = new AlertDialog.Builder(PublishTopicActivity.this);
391
        builder.setTitle("提示");
392
        builder.setMessage("确认取消发布?");
393
        builder.setCancelable(false);
394
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
395
            @Override
396
            public void onClick(DialogInterface dialog, int which) {
397
                finish();
398
            }
399
        });
400
        builder.setNegativeButton("取消", null);
401
        builder.create().show();
402
    }
403

404
    @Override
405
    public boolean onKeyUp(int keyCode, KeyEvent event) {
406
        if (keyCode == KeyEvent.KEYCODE_BACK) {
407
            showDialogToExit();
408
            return true;
409
        }
410
        return false;
411
    }
412
   }
1
package com.electric.chargingpile.activity;
2
3
import android.app.Activity;
4
import android.content.Context;
5
import android.content.DialogInterface;
6
import android.content.Intent;
7
import android.graphics.drawable.Drawable;
8
import android.net.Uri;
9
import android.os.Bundle;
10
import android.os.Environment;
11
import android.support.annotation.Nullable;
12
import android.support.v7.app.AlertDialog;
13
import android.text.Editable;
14
import android.text.Html;
15
import android.text.TextUtils;
16
import android.text.TextWatcher;
17
import android.util.Log;
18
import android.view.KeyEvent;
19
import android.view.View;
20
import android.view.View.OnClickListener;
21
import android.widget.EditText;
22
import android.widget.ImageView;
23
import android.widget.RelativeLayout;
24
import android.widget.TextView;
25
import android.widget.Toast;
26
27
import com.blankj.utilcode.util.ToastUtils;
28
import com.bumptech.glide.Glide;
29
import com.bumptech.glide.load.DataSource;
30
import com.bumptech.glide.load.engine.GlideException;
31
import com.bumptech.glide.request.RequestListener;
32
import com.bumptech.glide.request.RequestOptions;
33
import com.bumptech.glide.request.target.Target;
34
import com.electric.chargingpile.R;
35
import com.electric.chargingpile.application.MainApplication;
36
import com.electric.chargingpile.data.AuthSignBean;
37
import com.electric.chargingpile.data.TalkRecommendBean;
38
import com.electric.chargingpile.util.BarColorUtil;
39
import com.electric.chargingpile.util.JsonUtils;
40
import com.electric.chargingpile.util.LoadingDialog;
41
import com.electric.chargingpile.util.ToastUtil;
42
import com.luck.picture.lib.PictureSelector;
43
import com.luck.picture.lib.compress.Luban;
44
import com.luck.picture.lib.config.PictureConfig;
45
import com.luck.picture.lib.config.PictureMimeType;
46
import com.luck.picture.lib.entity.LocalMedia;
47
import com.umeng.analytics.MobclickAgent;
48
import com.upyun.library.common.UploadEngine;
49
import com.upyun.library.listener.UpCompleteListener;
50
import com.upyun.library.listener.UpProgressListener;
51
import com.zhy.http.okhttp.OkHttpUtils;
52
import com.zhy.http.okhttp.callback.StringCallback;
53
54
import java.io.File;
55
import java.util.ArrayList;
56
import java.util.HashMap;
57
import java.util.List;
58
import java.util.Map;
59
60
import okhttp3.Call;
61
62
public class PublishTopicActivity extends Activity implements OnClickListener {
63
    Context mContext;
64
    private ImageView mPublishtopicBack;
65
    private TextView mPublishtopicPublish;
66
    private EditText mPublishtopicCon;
67
    private ImageView mPublishtopicGv;
68
    private TextView mPublishtopicChooseTopic;
69
    private TextView mPublishtopicChoosePreview;
70
    private TextView mPublishtopicWordNum;
71
    private ImageView mPublishTopicDe;
72
73
    private RelativeLayout mItemVideoLll;
74
    private ImageView mItemVideo;
75
    private View mItemVideoDelete;
76
77
78
    public static final String CACHE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath() + "/cdz";
79
80
81
    public static final String IMAGE_CACHE = CACHE_DIR + "/cache/image/";
82
    LocalMedia media;
83
    LoadingDialog loadingDialog;
84
85
    @Override
86
    protected void onCreate(Bundle savedInstanceState) {
87
        super.onCreate(savedInstanceState);
88
        setContentView(R.layout.activity_publishtopic);
89
        mContext = this;
90
        loadingDialog = new LoadingDialog(this);
91
        loadingDialog.setCanceledOnTouchOutside(false);
92
        BarColorUtil.initStatusBarColor(PublishTopicActivity.this);
93
        initView();
94
    }
95
96
    private void initView() {
97
        mPublishtopicBack = (ImageView) findViewById(R.id.publishtopic_back);
98
        mPublishtopicPublish = (TextView) findViewById(R.id.publishtopic_publish);
99
        mPublishtopicCon = (EditText) findViewById(R.id.publishtopic_con);
100
        mPublishtopicGv = (ImageView) findViewById(R.id.item_choose_video);
101
        mPublishtopicChooseTopic = (TextView) findViewById(R.id.publishtopic_choose_topic);
102
        mPublishtopicChoosePreview = (TextView) findViewById(R.id.publishtopic_choose_preview);
103
        mPublishtopicWordNum = (TextView) findViewById(R.id.publishtopic_word_num);
104
        mPublishTopicDe = (ImageView) findViewById(R.id.publishtopic_choose_topic_de);
105
106
        mItemVideoLl = (RelativeLayout) findViewById(R.id.item_video_ll);
107
        mItemVideo = (ImageView) findViewById(R.id.item_video);
108
        mItemVideoDelete = (View) findViewById(R.id.item_video_delete);
109
110
111
        mPublishtopicCon.addTextChangedListener(new TextWatcher() {
112
            @Override
113
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
114
115
            }
116
117
            @Override
118
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
119
120
121
            }
122
123
            @Override
124
            public void afterTextChanged(Editable editable) {
125
                int length = editable.length();
126
                if (length > 500) {
127
                    mPublishtopicWordNum.setText(Html.fromHtml("<font  color=\"#FF4E4E\">" + length + "</font>/500"));
128
                } else {
129
                    mPublishtopicWordNum.setText(length + "/500");
130
                }
131
            }
132
        });
133
134
135
        mPublishtopicBack.setOnClickListener(this);
136
        mPublishtopicPublish.setOnClickListener(this);
137
        mPublishtopicChoosePreview.setOnClickListener(this);
138
        mPublishtopicChooseTopic.setOnClickListener(this);
139
        mPublishTopicDe.setOnClickListener(this);
140
        mItemVideoDelete.setOnClickListener(this);
141
        mPublishtopicGv.setOnClickListener(this);
142
    }
143
144
145
    @Override
146
    public void onClick(View v) {
147
        switch (v.getId()) {
148
            case R.id.publishtopic_back:
149
                showDialogToExit();
150
//                finish();
151
                break;
152
            case R.id.publishtopic_publish:
153
                if (media == null) {
154
                    ToastUtils.showLong("请选择视频!");
155
                    return;
156
                }
157
                if (talkRecommendBean == null) {
158
                    ToastUtils.showLong("请选择话题!");
159
                    return;
160
                }
161
                getYouPaiData();
162
                break;
163
164
            case R.id.publishtopic_choose_topic:
165
                startActivityForResult(new Intent(this, TopicActivity.class), reqTopic);
166
                break;
167
            case R.id.publishtopic_choose_preview:
168
                break;
169
            case R.id.publishtopic_choose_topic_de:
170
                mPublishtopicChooseTopic.setText("# 选择话题");
171
                mPublishTopicDe.setVisibility(View.GONE);
172
                talkRecommendBean = null;
173
                break;
174
            case R.id.item_choose_video:
175
                PictureSelector.create(this)
176
                        .openGallery(PictureMimeType.ofVideo())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()
177
                        .theme(R.style.picture_default_style)// 主题样式设置 具体参考 libray中values/styles
178
                        .maxSelectNum(9)// 最大图片选择数量
179
                        .minSelectNum(1)// 最小选择数量
180
                        .imageSpanCount(4)// 每行显示个数
181
                        .selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 PictureConfig.MULTIPLE : PictureConfig.SINGLE
182
                        .previewImage(true)// 是否可预览图片
183
                        .previewVideo(true)// 是否可预览视频
184
                        .enablePreviewAudio(false)// 是否预览音频
185
                        .isCamera(true)// 是否显示拍照按钮
186
                        .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
187
                        .setOutputCameraPath(IMAGE_CACHE)// 自定义拍照保存路径
188
                        .compress(true)// 是否压缩
189
                        .compressMode(PictureConfig.LUBAN_COMPRESS_MODE)//系统自带 or 鲁班压缩 PictureConfig.SYSTEM_COMPRESS_MODE or LUBAN_COMPRESS_MODE
190
                        .glideOverride(160, 160)// glide 加载宽高,越小图片列表越流畅,但会影响列表图片浏览的清晰度
191
                        .isGif(false)// 是否显示gif图片
192
                        .openClickSound(false)// 是否开启点击声音
193
                        .compressGrade(Luban.CUSTOM_GEAR)
194
                        .compressMaxKB(1024)//压缩最大值kb compressGrade()为Luban.CUSTOM_GEAR有效
195
                        .minimumCompressSize(500) //add by tanhaiqin, 图片大小 <= 500KB(数字可变) 不需要压缩
196
                        .videoSecond(5 * 60)//显示多少秒以内的视频
197
                        .recordVideoSecond(15)//录制视频秒数 默认60秒
198
                        .forResult(PictureConfig.CHOOSE_REQUEST);
199
                break;
200
            case R.id.item_video_delete:
201
                mItemVideoLl.setVisibility(View.GONE);
202
                mPublishtopicGv.setVisibility(View.VISIBLE);
203
                media = null;
204
                break;
205
            default:
206
                break;
207
        }
208
    }
209
210
    private void getYouPaiData() {
211
        String fileNames = media.getPath().substring(media.getPath().lastIndexOf("/") + 1);
212
        String url = MainApplication.urlNew + "/topic/sign.do";
213
        Map<String, String> map = new HashMap<>();
214
        map.put("fileNames", fileNames);
215
        Log.e("fileNameDir fileName", fileNames);
216
        map.put("targetType", "23");//23视频/24图片
217
        OkHttpUtils
218
                .post()
219
                .params(map)
220
                .url(url)
221
                .build()
222
                .connTimeOut(6000)
223
                .readTimeOut(6000)
224
                .execute(new StringCallback() {
225
                    @Override
226
                    public void onError(Call call, Exception e) {
227
                        ToastUtil.showToast(getApplicationContext(), "发布失败,请重试", Toast.LENGTH_SHORT);
228
                        loadingDialog.dismiss();
229
                    }
230
231
                    @Override
232
                    public void onResponse(String response) {
233
                        String rtnCode = JsonUtils.getKeyResult(response, "code");
234
                        if ("1000".equals(rtnCode)) {
235
                            String rtnMsg = JsonUtils.getKeyResult(response, "data");
236
                            ArrayList<AuthSignBean> signBeans = (ArrayList<AuthSignBean>) JsonUtils.parseToObjectList(rtnMsg, AuthSignBean.class);
237
238
                            if (null != signBeans && signBeans.size() > 0) {
239
                                String sign = signBeans.get(0).sign;
240
                                String policy = signBeans.get(0).policy;
241
                                formUpload(media.getPath(), sign, policy);
242
                            }
243
                        }
244
                    }
245
                });
246
247
    }
248
249
    /**
250
     * 表单上传
251
     *
252
     * @param SAMPLE_PIC_FILE
253
     * @param sign
254
     * @param policyServer
255
     */
256
    private void formUpload(String SAMPLE_PIC_FILE, String sign, String policyServer) {
257
        File temp = new File(SAMPLE_PIC_FILE);
258
//        //进度回调,可为空
259
        UpProgressListener progressListener = new UpProgressListener() {
260
            @Override
261
            public void onRequestProgress(long bytesWrite, long contentLength) {
262
            }
263
        };
264
265
        //结束回调,不可为空
266
        UpCompleteListener completeListener = new UpCompleteListener() {
267
            @Override
268
            public void onComplete(boolean isSuccess, String result) {
269
                if (isSuccess) {
270
                    requestPublishServer("[" + result + "]");
271
                } else {
272
                    ToastUtil.showToast(getApplicationContext(), "发布失败,请重试", Toast.LENGTH_SHORT);
273
                    loadingDialog.dismiss();
274
                }
275
            }
276
        };
277
278
        //表单上传(服务器签名方式)
279
        UploadEngine.getInstance().formUpload(temp, policyServer, "d1evvideo01", sign, completeListener,
280
                progressListener);
281
282
    }
283
284
    private void requestPublishServer(String urls) {
285
        String url = MainApplication.urlNew + "/topic/publish.do";
286
        Map<String, String> map = new HashMap<>();
287
        map.put("content", mPublishtopicCon.getText().toString());
288
        map.put("urls", urls);
289
        map.put("topicId", talkRecommendBean.targetId + "");
290
        map.put("targetType",  "23");
291
        if (MainApplication.isLogin()) {
292
            map.put("userId", MainApplication.userId);
293
            map.put("appToken", MainApplication.messageToken);
294
        }
295
        OkHttpUtils.post().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
296
            @Override
297
            public void onError(Call call, Exception e) {
298
                ToastUtil.showToast(getApplicationContext(), "发布失败,请重试", Toast.LENGTH_SHORT);
299
300
                loadingDialog.dismiss();
301
            }
302
303
            @Override
304
            public void onResponse(String response) {
305
                String rtnCode = JsonUtils.getKeyResult(response, "code");
306
                if ("1000".equals(rtnCode)) {
307
                    ToastUtil.showToast(getApplicationContext(), "发布成功", Toast.LENGTH_SHORT);
308
                    finish();
309
                } else {
310
                    String message = JsonUtils.getKeyResult(response, "desc");
311
                    ToastUtil.showToast(getApplicationContext(), message, Toast.LENGTH_SHORT);
312
                }
313
                loadingDialog.dismiss();
314
            }
315
        });
316
    }
317
318
319
    final int reqTopic = 100;
320
321
    TalkRecommendBean talkRecommendBean = null;
322
323
    @Override
324
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
325
        super.onActivityResult(requestCode, resultCode, data);
326
327
        if (requestCode == reqTopic && resultCode == -100) {
328
            talkRecommendBean = (TalkRecommendBean) data.getSerializableExtra("topic");
329
            if (talkRecommendBean != null) {
330
                mPublishtopicChooseTopic.setText("# " + talkRecommendBean.topicName);
331
                mPublishTopicDe.setVisibility(View.VISIBLE);
332
            }
333
        } else if (requestCode == PictureConfig.CHOOSE_REQUEST && resultCode == RESULT_OK) {
334
            List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
335
            if (selectList != null && selectList.size() > 0) {
336
                media = selectList.get(0);
337
                if (TextUtils.isEmpty(media.getPath())) {
338
                    return;
339
                }
340
                if (!fileIsExists(media.getPath())) {
341
                    Log.e("yopic", "文件可能不存在了~");
342
                    return;
343
                }
344
345
                Glide
346
                        .with(this)
347
                        .load(Uri.fromFile(new File(media.getPath())))
348
                        .apply(new RequestOptions().centerCrop())
349
                        .into(mItemVideo);
350
                mItemVideoLl.setVisibility(View.VISIBLE);
351
                mPublishtopicGv.setVisibility(View.GONE);
352
                Log.e("yopic", "TEST===> video path = " + media.getPath()
353
                        + ",  compressPath = " + media.getCompressPath()
354
                        + ", height = " + media.getHeight()
355
                        + ", width = " + media.getWidth());
356
            }
357
358
        }
359
    }
360
361
    public static boolean fileIsExists(String strFile) {
362
        if (TextUtils.isEmpty(strFile)) {
363
            return false;
364
        }
365
        try {
366
            File f = new File(strFile);
367
            if (!f.exists()) {
368
                return false;
369
            }
370
371
        } catch (Exception e) {
372
            return false;
373
        }
374
375
        return true;
376
    }
377
378
    @Override
379
    protected void onResume() {
380
        super.onResume();
381
        MobclickAgent.onResume(this);
382
    }
383
384
    @Override
385
    protected void onPause() {
386
        super.onPause();
387
        MobclickAgent.onPause(this);
388
    }
389
390
    private void showDialogToExit(){
391
        AlertDialog.Builder builder = new AlertDialog.Builder(PublishTopicActivity.this);
392
        builder.setTitle("提示");
393
        builder.setMessage("确认取消发布?");
394
        builder.setCancelable(false);
395
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
396
            @Override
397
            public void onClick(DialogInterface dialog, int which) {
398
                finish();
399
            }
400
        });
401
        builder.setNegativeButton("取消", null);
402
        builder.create().show();
403
    }
404
405
    @Override
406
    public boolean onKeyUp(int keyCode, KeyEvent event) {
407
        if (keyCode == KeyEvent.KEYCODE_BACK) {
408
            showDialogToExit();
409
            return true;
410
        }
411
        return false;
412
       }
413
}

+ 16 - 14
app/src/main/java/com/electric/chargingpile/fragment/SvVideoShowView.java

@ -36,6 +36,7 @@ import com.electric.chargingpile.view.VideoCommentDialog;
36 36
import com.electric.chargingpile.view.VideoPubilshDialog;
37 37
import com.electric.chargingpile.widge.photoview.PhotoView;
38 38
import com.electric.chargingpile.widge.photoview.ZoomingViewpager;
39
import com.mabeijianxi.smallvideorecord2.Log;
39 40
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet;
40 41
import com.squareup.picasso.Picasso;
41 42
import com.zhy.http.okhttp.OkHttpUtils;
@ -318,7 +319,7 @@ public class SvVideoShowView implements View.OnClickListener {
318 319
    }
319 320
320 321
    ZoomingViewpager zoomingViewpager;
321
    ImageAdapter imageAdapter = new ImageAdapter();
322
    ImageAdapter imageAdapter;
322 323
323 324
    private void initZoomPhoto(View view) {
324 325
        vd_title_tv = view.findViewById(R.id.vd_title_tv);
@ -342,6 +343,7 @@ public class SvVideoShowView implements View.OnClickListener {
342 343
343 344
            }
344 345
        });
346
        imageAdapter = new ImageAdapter();
345 347
        zoomingViewpager.setAdapter(imageAdapter);
346 348
347 349
    }
@ -384,28 +386,28 @@ public class SvVideoShowView implements View.OnClickListener {
384 386
385 387
    public void updateView() {
386 388
        String title = talkRecommendBean.title;
387
        if (TextUtils.isEmpty(title)) {
388
            sv_show_tvcon_more.setVisibility(View.GONE);
389
        } else {
390
            int length = title.length();
391
            if (length > 100) {
392
                sv_show_tvcon.setMaxLines(3);
393
                sv_show_tvcon.setEllipsize(TextUtils.TruncateAt.END);
394
                sv_show_tvcon_more.setVisibility(View.VISIBLE);
395
                sv_show_tvcon.setText(talkRecommendBean.title);
396 389
397
            } else {
398
                sv_show_tvcon_more.setVisibility(View.GONE);
390
        sv_show_tvcon_more.setVisibility(View.GONE);
391
        int length = title.length();
392
        if (length > 100) {
393
            sv_show_tvcon.setMaxLines(3);
394
            sv_show_tvcon.setEllipsize(TextUtils.TruncateAt.END);
395
            sv_show_tvcon_more.setVisibility(View.VISIBLE);
399 396
400
                sv_show_tvcon.setMaxLines(100);
401
            }
397
        } else {
398
            sv_show_tvcon_more.setVisibility(View.GONE);
402 399
400
            sv_show_tvcon.setMaxLines(100);
403 401
        }
404 402
403
        sv_show_tvcon.setText(talkRecommendBean.title);
405 404
    }
406 405
406
407 407
    public void initAndPlay() {
408 408
        if (talkRecommendBean.targetType == 24) {
409
            String s = talkRecommendBean.imgUrls.toString();
410
            LogUtils.d("demo 11",s);
409 411
            imageAdapter.notifyDataSetChanged();
410 412
        } else {
411 413
            if (upVideoView2 != null && !TextUtils.isEmpty(talkRecommendBean.videoUrl)) {

+ 35 - 14
app/src/main/java/com/electric/chargingpile/fragment/TalkRecommendFragment.java

@ -33,11 +33,18 @@ import com.electric.chargingpile.util.ToastUtil;
33 33
import com.zhy.http.okhttp.OkHttpUtils;
34 34
import com.zhy.http.okhttp.callback.StringCallback;
35 35
36
import java.io.Serializable;
36 37
import java.util.ArrayList;
37 38
import java.util.HashMap;
38 39
import java.util.List;
39 40
import java.util.Map;
40 41
42
import io.reactivex.Observable;
43
import io.reactivex.android.schedulers.AndroidSchedulers;
44
import io.reactivex.disposables.Disposable;
45
import io.reactivex.functions.Consumer;
46
import io.reactivex.functions.Predicate;
47
import io.reactivex.schedulers.Schedulers;
41 48
import okhttp3.Call;
42 49
43 50
public class TalkRecommendFragment extends Fragment implements View.OnClickListener {
@ -52,8 +59,8 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
52 59
    private static final String TAG = "TalkRecommendFragment";
53 60
    private int page = 1;
54 61
55
    public void refreshList(){
56
        if(view == null)
62
    public void refreshList() {
63
        if (view == null)
57 64
            return;
58 65
        xRefreshView.startRefresh();
59 66
        page = 1;
@ -133,25 +140,41 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
133 140
        layoutAdapter.setOnRecyclerItemClickListener(new RecyclerItemTypeClickListener() {
134 141
            @Override
135 142
            public void onItemClickListener(int position, int type) {
136
                int pos = position - 1;
143
                final int pos = position - 1;
137 144
                ArrayList<TalkRecommendBean> talkRecommendBeans = layoutAdapter.getCurrentData();
138 145
139 146
                if (!NetUtil.CheckNetwork(getActivity())) {
140 147
                    Toast.makeText(getActivity(), "请检查网络", Toast.LENGTH_SHORT).show();
141 148
                    return;
142 149
                }
143
                if(type == 2){
144
                    startActivity(new Intent(getActivity(), PersonalPageActivity.class).putExtra("targetUserId", talkRecommendBeans.get(pos).addUserId+""));
150
                if (type == 2) {
151
                    startActivity(new Intent(getActivity(), PersonalPageActivity.class).putExtra("targetUserId", talkRecommendBeans.get(pos).addUserId + ""));
145 152
                    return;
146 153
                }
147 154
148
                if(talkRecommendBeans.get(pos).targetType == 25){
149
                    startActivity(new Intent(getActivity(), TopicDetailsActivity.class).putExtra("topicId", talkRecommendBeans.get(pos).topicId+""));
150
                }else {
151
                    Intent intent = new Intent(getActivity(), VideoDetaislActivity.class);
152
                    intent.putExtra("list", talkRecommendBeans);
153
                    intent.putExtra("pos", pos);
154
                    startActivity(intent);
155
                if (talkRecommendBeans.get(pos).targetType == 25) {
156
                    startActivity(new Intent(getActivity(), TopicDetailsActivity.class).putExtra("topicId", talkRecommendBeans.get(pos).topicId + ""));
157
                } else {
158
                    Disposable disposable = Observable
159
                            .fromIterable(talkRecommendBeans)
160
                            .filter(new Predicate<TalkRecommendBean>() {
161
                                @Override
162
                                public boolean test(TalkRecommendBean talkRecommendBean) throws Exception {
163
                                    return talkRecommendBean.targetType != 25;
164
                                }
165
                            }).toList()
166
                            .subscribeOn(Schedulers.io())
167
                            .observeOn(AndroidSchedulers.mainThread())
168
                            .subscribe(new Consumer<List<TalkRecommendBean>>() {
169
                                @Override
170
                                public void accept(List<TalkRecommendBean> list) throws Exception {
171
                                    Intent intent = new Intent(getActivity(), VideoDetaislActivity.class);
172
                                    intent.putExtra("list", (Serializable) list);
173
                                    intent.putExtra("pos", pos);
174
                                    startActivity(intent);
175
176
                                }
177
                            });
155 178
                }
156 179
            }
157 180
        });
@ -300,6 +323,4 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
300 323
            }
301 324
        });
302 325
    }
303
304
305 326
}

+ 233 - 224
app/src/main/java/com/electric/chargingpile/view/sview/VerticalViewPager.java

@ -1685,136 +1685,140 @@ public class VerticalViewPager extends ViewGroup {
1685 1685
         * If we return true, onMotionEvent will be called and we do the actual
1686 1686
         * scrolling there.
1687 1687
         */
1688
        try {
1688 1689
1689
        final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
1690
            final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
1690 1691
1691
        // Always take care of the touch gesture being complete.
1692
        if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
1693
            // Release the drag.
1694
            if (DEBUG) Log.v(TAG, "Intercept done!");
1695
            mIsBeingDragged = false;
1696
            mIsUnableToDrag = false;
1697
            mActivePointerId = INVALID_POINTER;
1698
            if (mVelocityTracker != null) {
1699
                mVelocityTracker.recycle();
1700
                mVelocityTracker = null;
1701
            }
1702
            return false;
1703
        }
1704
1705
        // Nothing more to do here if we have decided whether or not we
1706
        // are dragging.
1707
        if (action != MotionEvent.ACTION_DOWN) {
1708
            if (mIsBeingDragged) {
1709
                if (DEBUG) Log.v(TAG, "Intercept returning true!");
1710
                return true;
1711
            }
1712
            if (mIsUnableToDrag) {
1713
                if (DEBUG) Log.v(TAG, "Intercept returning false!");
1692
            // Always take care of the touch gesture being complete.
1693
            if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
1694
                // Release the drag.
1695
                if (DEBUG) Log.v(TAG, "Intercept done!");
1696
                mIsBeingDragged = false;
1697
                mIsUnableToDrag = false;
1698
                mActivePointerId = INVALID_POINTER;
1699
                if (mVelocityTracker != null) {
1700
                    mVelocityTracker.recycle();
1701
                    mVelocityTracker = null;
1702
                }
1714 1703
                return false;
1715 1704
            }
1716
        }
1717 1705
1718
        switch (action) {
1719
            case MotionEvent.ACTION_MOVE: {
1720
                /*
1721
                 * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
1722
                 * whether the user has moved far enough from his original down touch.
1723
                 */
1724
1725
                /*
1726
                 * Locally do absolute value. mLastMotionY is set to the y value
1727
                 * of the down event.
1728
                 */
1729
                final int activePointerId = mActivePointerId;
1730
                if (activePointerId == INVALID_POINTER) {
1731
                    // If we don't have a valid id, the touch down wasn't on content.
1732
                    break;
1706
            // Nothing more to do here if we have decided whether or not we
1707
            // are dragging.
1708
            if (action != MotionEvent.ACTION_DOWN) {
1709
                if (mIsBeingDragged) {
1710
                    if (DEBUG) Log.v(TAG, "Intercept returning true!");
1711
                    return true;
1733 1712
                }
1734
1735
                final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
1736
                final float y = MotionEventCompat.getY(ev, pointerIndex);
1737
                final float dy = y - mLastMotionY;
1738
                final float yDiff = Math.abs(dy);
1739
                final float x = MotionEventCompat.getX(ev, pointerIndex);
1740
                final float xDiff = Math.abs(x - mInitialMotionX);
1741
                if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
1742
1743
                if (dy != 0 && !isGutterDrag(mLastMotionY, dy) &&
1744
                        canScroll(this, false, (int) dy, (int) x, (int) y)) {
1745
                    // Nested view has scrollable area under this point. Let it be handled there.
1746
                    mLastMotionX = x;
1747
                    mLastMotionY = y;
1748
                    mIsUnableToDrag = true;
1713
                if (mIsUnableToDrag) {
1714
                    if (DEBUG) Log.v(TAG, "Intercept returning false!");
1749 1715
                    return false;
1750 1716
                }
1751
                if (yDiff > mTouchSlop && yDiff * 0.5f > xDiff) {
1752
                    if (DEBUG) Log.v(TAG, "Starting drag!");
1753
                    mIsBeingDragged = true;
1754
                    requestParentDisallowInterceptTouchEvent(true);
1755
                    setScrollState(SCROLL_STATE_DRAGGING);
1756
                    mLastMotionY = dy > 0 ? mInitialMotionY + mTouchSlop :
1757
                            mInitialMotionY - mTouchSlop;
1758
                    mLastMotionX = x;
1759
                    setScrollingCacheEnabled(true);
1760
                } else if (xDiff > mTouchSlop) {
1761
                    // The finger has moved enough in the vertical
1762
                    // direction to be counted as a drag...  abort
1763
                    // any attempt to drag horizontally, to work correctly
1764
                    // with children that have scrolling containers.
1765
                    if (DEBUG) Log.v(TAG, "Starting unable to drag!");
1766
                    mIsUnableToDrag = true;
1767
                }
1768
                if (mIsBeingDragged) {
1769
                    // Scroll to follow the motion event
1770
                    if (performDrag(y)) {
1771
                        ViewCompat.postInvalidateOnAnimation(this);
1717
            }
1718
1719
            switch (action) {
1720
                case MotionEvent.ACTION_MOVE: {
1721
                    /*
1722
                     * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
1723
                     * whether the user has moved far enough from his original down touch.
1724
                     */
1725
1726
                    /*
1727
                     * Locally do absolute value. mLastMotionY is set to the y value
1728
                     * of the down event.
1729
                     */
1730
                    final int activePointerId = mActivePointerId;
1731
                    if (activePointerId == INVALID_POINTER) {
1732
                        // If we don't have a valid id, the touch down wasn't on content.
1733
                        break;
1734
                    }
1735
1736
                    final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
1737
                    final float y = MotionEventCompat.getY(ev, pointerIndex);
1738
                    final float dy = y - mLastMotionY;
1739
                    final float yDiff = Math.abs(dy);
1740
                    final float x = MotionEventCompat.getX(ev, pointerIndex);
1741
                    final float xDiff = Math.abs(x - mInitialMotionX);
1742
                    if (DEBUG)
1743
                        Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
1744
1745
                    if (dy != 0 && !isGutterDrag(mLastMotionY, dy) &&
1746
                            canScroll(this, false, (int) dy, (int) x, (int) y)) {
1747
                        // Nested view has scrollable area under this point. Let it be handled there.
1748
                        mLastMotionX = x;
1749
                        mLastMotionY = y;
1750
                        mIsUnableToDrag = true;
1751
                        return false;
1752
                    }
1753
                    if (yDiff > mTouchSlop && yDiff * 0.5f > xDiff) {
1754
                        if (DEBUG) Log.v(TAG, "Starting drag!");
1755
                        mIsBeingDragged = true;
1756
                        requestParentDisallowInterceptTouchEvent(true);
1757
                        setScrollState(SCROLL_STATE_DRAGGING);
1758
                        mLastMotionY = dy > 0 ? mInitialMotionY + mTouchSlop :
1759
                                mInitialMotionY - mTouchSlop;
1760
                        mLastMotionX = x;
1761
                        setScrollingCacheEnabled(true);
1762
                    } else if (xDiff > mTouchSlop) {
1763
                        // The finger has moved enough in the vertical
1764
                        // direction to be counted as a drag...  abort
1765
                        // any attempt to drag horizontally, to work correctly
1766
                        // with children that have scrolling containers.
1767
                        if (DEBUG) Log.v(TAG, "Starting unable to drag!");
1768
                        mIsUnableToDrag = true;
1769
                    }
1770
                    if (mIsBeingDragged) {
1771
                        // Scroll to follow the motion event
1772
                        if (performDrag(y)) {
1773
                            ViewCompat.postInvalidateOnAnimation(this);
1774
                        }
1772 1775
                    }
1776
                    break;
1773 1777
                }
1774
                break;
1775
            }
1776 1778
1777
            case MotionEvent.ACTION_DOWN: {
1778
                /*
1779
                 * Remember location of down touch.
1780
                 * ACTION_DOWN always refers to pointer index 0.
1781
                 */
1782
                mLastMotionX = mInitialMotionX = ev.getX();
1783
                mLastMotionY = mInitialMotionY = ev.getY();
1784
                mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
1785
                mIsUnableToDrag = false;
1779
                case MotionEvent.ACTION_DOWN: {
1780
                    /*
1781
                     * Remember location of down touch.
1782
                     * ACTION_DOWN always refers to pointer index 0.
1783
                     */
1784
                    mLastMotionX = mInitialMotionX = ev.getX();
1785
                    mLastMotionY = mInitialMotionY = ev.getY();
1786
                    mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
1787
                    mIsUnableToDrag = false;
1788
1789
                    mScroller.computeScrollOffset();
1790
                    if (mScrollState == SCROLL_STATE_SETTLING &&
1791
                            Math.abs(mScroller.getFinalY() - mScroller.getCurrY()) > mCloseEnough) {
1792
                        // Let the user 'catch' the pager as it animates.
1793
                        mScroller.abortAnimation();
1794
                        mPopulatePending = false;
1795
                        populate();
1796
                        mIsBeingDragged = true;
1797
                        requestParentDisallowInterceptTouchEvent(true);
1798
                        setScrollState(SCROLL_STATE_DRAGGING);
1799
                    } else {
1800
                        completeScroll(false);
1801
                        mIsBeingDragged = false;
1802
                    }
1786 1803
1787
                mScroller.computeScrollOffset();
1788
                if (mScrollState == SCROLL_STATE_SETTLING &&
1789
                        Math.abs(mScroller.getFinalY() - mScroller.getCurrY()) > mCloseEnough) {
1790
                    // Let the user 'catch' the pager as it animates.
1791
                    mScroller.abortAnimation();
1792
                    mPopulatePending = false;
1793
                    populate();
1794
                    mIsBeingDragged = true;
1795
                    requestParentDisallowInterceptTouchEvent(true);
1796
                    setScrollState(SCROLL_STATE_DRAGGING);
1797
                } else {
1798
                    completeScroll(false);
1799
                    mIsBeingDragged = false;
1804
                    if (DEBUG) Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY
1805
                            + " mIsBeingDragged=" + mIsBeingDragged
1806
                            + "mIsUnableToDrag=" + mIsUnableToDrag);
1807
                    break;
1800 1808
                }
1801 1809
1802
                if (DEBUG) Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY
1803
                        + " mIsBeingDragged=" + mIsBeingDragged
1804
                        + "mIsUnableToDrag=" + mIsUnableToDrag);
1805
                break;
1810
                case MotionEventCompat.ACTION_POINTER_UP:
1811
                    onSecondaryPointerUp(ev);
1812
                    break;
1806 1813
            }
1807 1814
1808
            case MotionEventCompat.ACTION_POINTER_UP:
1809
                onSecondaryPointerUp(ev);
1810
                break;
1811
        }
1812
1813
        if (mVelocityTracker == null) {
1814
            mVelocityTracker = VelocityTracker.obtain();
1815
            if (mVelocityTracker == null) {
1816
                mVelocityTracker = VelocityTracker.obtain();
1817
            }
1818
            mVelocityTracker.addMovement(ev);
1819
        } catch (IllegalArgumentException ex) {
1820
            ex.printStackTrace();
1815 1821
        }
1816
        mVelocityTracker.addMovement(ev);
1817
1818 1822
        /*
1819 1823
         * The only time we want to intercept motion events is if we are in the
1820 1824
         * drag mode.
@ -1824,128 +1828,133 @@ public class VerticalViewPager extends ViewGroup {
1824 1828
1825 1829
    @Override
1826 1830
    public boolean onTouchEvent(MotionEvent ev) {
1827
        if (mFakeDragging) {
1828
            // A fake drag is in progress already, ignore this real one
1829
            // but still eat the touch events.
1830
            // (It is likely that the user is multi-touching the screen.)
1831
            return true;
1832
        }
1833
1834
        if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
1835
            // Don't handle edge touches immediately -- they may actually belong to one of our
1836
            // descendants.
1837
            return false;
1838
        }
1831
        try {
1832
            if (mFakeDragging) {
1833
                // A fake drag is in progress already, ignore this real one
1834
                // but still eat the touch events.
1835
                // (It is likely that the user is multi-touching the screen.)
1836
                return true;
1837
            }
1839 1838
1840
        if (mAdapter == null || mAdapter.getCount() == 0) {
1841
            // Nothing to present or scroll; nothing to touch.
1842
            return false;
1843
        }
1839
            if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
1840
                // Don't handle edge touches immediately -- they may actually belong to one of our
1841
                // descendants.
1842
                return false;
1843
            }
1844 1844
1845
        if (mVelocityTracker == null) {
1846
            mVelocityTracker = VelocityTracker.obtain();
1847
        }
1848
        mVelocityTracker.addMovement(ev);
1845
            if (mAdapter == null || mAdapter.getCount() == 0) {
1846
                // Nothing to present or scroll; nothing to touch.
1847
                return false;
1848
            }
1849 1849
1850
        final int action = ev.getAction();
1851
        boolean needsInvalidate = false;
1850
            if (mVelocityTracker == null) {
1851
                mVelocityTracker = VelocityTracker.obtain();
1852
            }
1853
            mVelocityTracker.addMovement(ev);
1852 1854
1853
        switch (action & MotionEventCompat.ACTION_MASK) {
1854
            case MotionEvent.ACTION_DOWN: {
1855
                mScroller.abortAnimation();
1856
                mPopulatePending = false;
1857
                populate();
1855
            final int action = ev.getAction();
1856
            boolean needsInvalidate = false;
1858 1857
1859
                // Remember where the motion event started
1860
                mLastMotionX = mInitialMotionX = ev.getX();
1861
                mLastMotionY = mInitialMotionY = ev.getY();
1862
                mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
1863
                break;
1864
            }
1865
            case MotionEvent.ACTION_MOVE:
1866
                if (!mIsBeingDragged) {
1867
                    final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
1868
                    final float y = MotionEventCompat.getY(ev, pointerIndex);
1869
                    final float yDiff = Math.abs(y - mLastMotionY);
1870
                    final float x = MotionEventCompat.getX(ev, pointerIndex);
1871
                    final float xDiff = Math.abs(x - mLastMotionX);
1872
                    if (DEBUG)
1873
                        Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
1874
                    if (yDiff > mTouchSlop && yDiff > xDiff) {
1875
                        if (DEBUG) Log.v(TAG, "Starting drag!");
1876
                        mIsBeingDragged = true;
1877
                        requestParentDisallowInterceptTouchEvent(true);
1878
                        mLastMotionY = y - mInitialMotionY > 0 ? mInitialMotionY + mTouchSlop :
1879
                                mInitialMotionY - mTouchSlop;
1880
                        mLastMotionX = x;
1881
                        setScrollState(SCROLL_STATE_DRAGGING);
1882
                        setScrollingCacheEnabled(true);
1858
            switch (action & MotionEventCompat.ACTION_MASK) {
1859
                case MotionEvent.ACTION_DOWN: {
1860
                    mScroller.abortAnimation();
1861
                    mPopulatePending = false;
1862
                    populate();
1883 1863
1884
                        // Disallow Parent Intercept, just in case
1885
                        ViewParent parent = getParent();
1886
                        if (parent != null) {
1887
                            parent.requestDisallowInterceptTouchEvent(true);
1864
                    // Remember where the motion event started
1865
                    mLastMotionX = mInitialMotionX = ev.getX();
1866
                    mLastMotionY = mInitialMotionY = ev.getY();
1867
                    mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
1868
                    break;
1869
                }
1870
                case MotionEvent.ACTION_MOVE:
1871
                    if (!mIsBeingDragged) {
1872
                        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
1873
                        final float y = MotionEventCompat.getY(ev, pointerIndex);
1874
                        final float yDiff = Math.abs(y - mLastMotionY);
1875
                        final float x = MotionEventCompat.getX(ev, pointerIndex);
1876
                        final float xDiff = Math.abs(x - mLastMotionX);
1877
                        if (DEBUG)
1878
                            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
1879
                        if (yDiff > mTouchSlop && yDiff > xDiff) {
1880
                            if (DEBUG) Log.v(TAG, "Starting drag!");
1881
                            mIsBeingDragged = true;
1882
                            requestParentDisallowInterceptTouchEvent(true);
1883
                            mLastMotionY = y - mInitialMotionY > 0 ? mInitialMotionY + mTouchSlop :
1884
                                    mInitialMotionY - mTouchSlop;
1885
                            mLastMotionX = x;
1886
                            setScrollState(SCROLL_STATE_DRAGGING);
1887
                            setScrollingCacheEnabled(true);
1888
1889
                            // Disallow Parent Intercept, just in case
1890
                            ViewParent parent = getParent();
1891
                            if (parent != null) {
1892
                                parent.requestDisallowInterceptTouchEvent(true);
1893
                            }
1888 1894
                        }
1889 1895
                    }
1896
                    // Not else! Note that mIsBeingDragged can be set above.
1897
                    if (mIsBeingDragged) {
1898
                        // Scroll to follow the motion event
1899
                        final int activePointerIndex = MotionEventCompat.findPointerIndex(
1900
                                ev, mActivePointerId);
1901
                        final float y = MotionEventCompat.getY(ev, activePointerIndex);
1902
                        needsInvalidate |= performDrag(y);
1903
                    }
1904
                    break;
1905
                case MotionEvent.ACTION_UP:
1906
                    if (mIsBeingDragged) {
1907
                        final VelocityTracker velocityTracker = mVelocityTracker;
1908
                        velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
1909
                        int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
1910
                                velocityTracker, mActivePointerId);
1911
                        mPopulatePending = true;
1912
                        final int height = getClientHeight();
1913
                        final int scrollY = getScrollY();
1914
                        final ItemInfo ii = infoForCurrentScrollPosition();
1915
                        final int currentPage = ii.position;
1916
                        final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
1917
                        final int activePointerIndex =
1918
                                MotionEventCompat.findPointerIndex(ev, mActivePointerId);
1919
                        final float y = MotionEventCompat.getY(ev, activePointerIndex);
1920
                        final int totalDelta = (int) (y - mInitialMotionY);
1921
                        int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
1922
                                totalDelta);
1923
                        setCurrentItemInternal(nextPage, true, true, initialVelocity);
1924
1925
                        mActivePointerId = INVALID_POINTER;
1926
                        endDrag();
1927
                        needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
1928
                    }
1929
                    break;
1930
                case MotionEvent.ACTION_CANCEL:
1931
                    if (mIsBeingDragged) {
1932
                        scrollToItem(mCurItem, true, 0, false);
1933
                        mActivePointerId = INVALID_POINTER;
1934
                        endDrag();
1935
                        needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
1936
                    }
1937
                    break;
1938
                case MotionEventCompat.ACTION_POINTER_DOWN: {
1939
                    final int index = MotionEventCompat.getActionIndex(ev);
1940
                    final float y = MotionEventCompat.getY(ev, index);
1941
                    mLastMotionY = y;
1942
                    mActivePointerId = MotionEventCompat.getPointerId(ev, index);
1943
                    break;
1890 1944
                }
1891
                // Not else! Note that mIsBeingDragged can be set above.
1892
                if (mIsBeingDragged) {
1893
                    // Scroll to follow the motion event
1894
                    final int activePointerIndex = MotionEventCompat.findPointerIndex(
1895
                            ev, mActivePointerId);
1896
                    final float y = MotionEventCompat.getY(ev, activePointerIndex);
1897
                    needsInvalidate |= performDrag(y);
1898
                }
1899
                break;
1900
            case MotionEvent.ACTION_UP:
1901
                if (mIsBeingDragged) {
1902
                    final VelocityTracker velocityTracker = mVelocityTracker;
1903
                    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
1904
                    int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
1905
                            velocityTracker, mActivePointerId);
1906
                    mPopulatePending = true;
1907
                    final int height = getClientHeight();
1908
                    final int scrollY = getScrollY();
1909
                    final ItemInfo ii = infoForCurrentScrollPosition();
1910
                    final int currentPage = ii.position;
1911
                    final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
1912
                    final int activePointerIndex =
1913
                            MotionEventCompat.findPointerIndex(ev, mActivePointerId);
1914
                    final float y = MotionEventCompat.getY(ev, activePointerIndex);
1915
                    final int totalDelta = (int) (y - mInitialMotionY);
1916
                    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
1917
                            totalDelta);
1918
                    setCurrentItemInternal(nextPage, true, true, initialVelocity);
1919
1920
                    mActivePointerId = INVALID_POINTER;
1921
                    endDrag();
1922
                    needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
1923
                }
1924
                break;
1925
            case MotionEvent.ACTION_CANCEL:
1926
                if (mIsBeingDragged) {
1927
                    scrollToItem(mCurItem, true, 0, false);
1928
                    mActivePointerId = INVALID_POINTER;
1929
                    endDrag();
1930
                    needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
1931
                }
1932
                break;
1933
            case MotionEventCompat.ACTION_POINTER_DOWN: {
1934
                final int index = MotionEventCompat.getActionIndex(ev);
1935
                final float y = MotionEventCompat.getY(ev, index);
1936
                mLastMotionY = y;
1937
                mActivePointerId = MotionEventCompat.getPointerId(ev, index);
1938
                break;
1945
                case MotionEventCompat.ACTION_POINTER_UP:
1946
                    onSecondaryPointerUp(ev);
1947
                    mLastMotionY = MotionEventCompat.getY(ev,
1948
                            MotionEventCompat.findPointerIndex(ev, mActivePointerId));
1949
                    break;
1939 1950
            }
1940
            case MotionEventCompat.ACTION_POINTER_UP:
1941
                onSecondaryPointerUp(ev);
1942
                mLastMotionY = MotionEventCompat.getY(ev,
1943
                        MotionEventCompat.findPointerIndex(ev, mActivePointerId));
1944
                break;
1945
        }
1946
        if (needsInvalidate) {
1947
            ViewCompat.postInvalidateOnAnimation(this);
1951
            if (needsInvalidate) {
1952
                ViewCompat.postInvalidateOnAnimation(this);
1953
            }
1954
        } catch (IllegalArgumentException ex) {
1955
            ex.printStackTrace();
1948 1956
        }
1957
1949 1958
        return true;
1950 1959
    }
1951 1960