Pārlūkot izejas kodu

add video topic

1145873331@qq.com 6 gadi atpakaļ
vecāks
revīzija
b14c9d588a

+ 1 - 3
app/build.gradle

@ -263,8 +263,6 @@ dependencies {
263 263
    compile 'me.iwf.photopicker:PhotoPicker:0.9.12@aar'
264 264
    compile 'top.zibin:Luban:1.1.2'
265 265
    compile 'com.ms-square:expandableTextView:0.1.4'
266
//    compile 'io.reactivex:rxjava:1.1.0'
267
//    compile 'io.reactivex:rxandroid:1.1.0'
268 266
269 267
    compile 'io.reactivex.rxjava2:rxjava:2.0.5'
270 268
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
@ -282,5 +280,5 @@ dependencies {
282 280
    compile 'com.github.Aspsine:IRecyclerView:0.0.7'
283 281
    compile project(':ijkplayer-java')
284 282
    compile 'com.upyun:upyun-android-sdk:+'
285
   compile project(':videolibrary:picture_library')
283
    compile project(':videolibrary:picture_library')
286 284
}

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

@ -4,11 +4,9 @@ import android.Manifest;
4 4
import android.annotation.SuppressLint;
5 5
import android.app.Activity;
6 6
import android.app.ProgressDialog;
7
import android.content.ContentValues;
8 7
import android.content.Context;
9 8
import android.content.Intent;
10 9
import android.content.pm.PackageManager;
11
import android.database.Cursor;
12 10
import android.graphics.Bitmap;
13 11
import android.graphics.BitmapFactory;
14 12
import android.graphics.Color;
@ -27,7 +25,6 @@ import android.telephony.TelephonyManager;
27 25
import android.text.Editable;
28 26
import android.text.TextUtils;
29 27
import android.text.TextWatcher;
30
import android.util.Base64;
31 28
import android.util.Log;
32 29
import android.view.LayoutInflater;
33 30
import android.view.View;
@ -61,19 +58,16 @@ import com.electric.chargingpile.util.PublicWay;
61 58
import com.electric.chargingpile.util.Res;
62 59
import com.electric.chargingpile.util.SystemTypeUtil;
63 60
import com.electric.chargingpile.util.ToastUtil;
64
import com.electric.chargingpile.util.UploadUtil;
65 61
import com.umeng.analytics.MobclickAgent;
66 62
import com.upyun.library.common.ParallelUploader;
67 63
import com.upyun.library.common.UploadEngine;
68 64
import com.upyun.library.listener.UpCompleteListener;
69 65
import com.upyun.library.listener.UpProgressListener;
70
import com.upyun.library.utils.UpYunUtils;
71 66
import com.zhy.http.okhttp.OkHttpUtils;
72 67
import com.zhy.http.okhttp.callback.StringCallback;
73 68
74 69
import java.io.ByteArrayOutputStream;
75 70
import java.io.File;
76
import java.io.FileNotFoundException;
77 71
import java.io.IOException;
78 72
import java.util.ArrayList;
79 73
import java.util.HashMap;
@ -323,18 +317,19 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
323 317
                    ArrayList<AuthSignBean> signBeans = (ArrayList<AuthSignBean>) JsonUtils.parseToObjectList(rtnMsg, AuthSignBean.class);
324 318
325 319
                    if (null != signBeans && signBeans.size() > 0) {
326
                        File tempFile = new File(Bimp.tempSelectBitmap.get(0).getImagePath().trim());
327
                        String fileName = tempFile.getName();
328
                        //生产policy传的参数
329
                        Map<String, Object> map = new HashMap<>();
330
                        map.put("bucket", "d1evcom01-fs");
331
                        map.put("expiration", (System.currentTimeMillis() + 1800) + "");
332
                        map.put("save-key", picSavePath + "/" + tempFile.getName());
333
                        policy = UpYunUtils.getPolicy(map);
320
//                        File tempFile = new File(Bimp.tempSelectBitmap.get(0).getImagePath().trim());
321
//                        String fileName = tempFile.getName();
322
//                        //生产policy传的参数
323
//                        Map<String, Object> map = new HashMap<>();
324
//                        map.put("bucket", SPACE);
325
//                        map.put("expiration", (System.currentTimeMillis() + 1800) + "");
326
//                        map.put("save-key", picSavePath + "/" + tempFile.getName());
327
//                        policy = UpYunUtils.getPolicy(map);
334 328
                        String sign = signBeans.get(0).sign;
335 329
336
                        formUpload(Bimp.tempSelectBitmap.get(0).getImagePath(), sign,
337
                                signBeans.get(0).fname, signBeans.get(0).policy);
330
                        formUpload(Bimp.tempSelectBitmap.get(0).getImagePath(), sign, signBeans.get(0).policy);
331
332
338 333
                    }
339 334
                }
340 335
            }
@ -568,8 +563,6 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
568 563
                        takePhoto.setBitmap(bitmap);
569 564
                        takePhoto.setImagePath(imagePath);
570 565
                        Bimp.tempSelectBitmap.add(takePhoto);
571
//
572
//                        Log.e(TAG, "call: "+imagePath );
573 566
                        subscriber.onNext(imagePath);
574 567
                    }
575 568
                    subscriber.onComplete();
@ -725,43 +718,7 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
725 718
        }
726 719
    }
727 720
728
    public static Uri getImageContentUri(Context context, File imageFile) {
729
        String filePath = imageFile.getAbsolutePath();
730
        Cursor cursor = context.getContentResolver().query(
731
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
732
                new String[]{MediaStore.Images.Media._ID},
733
                MediaStore.Images.Media.DATA + "=? ",
734
                new String[]{filePath}, null);
735
736
        if (cursor != null && cursor.moveToFirst()) {
737
            int id = cursor.getInt(cursor
738
                    .getColumnIndex(MediaStore.MediaColumns._ID));
739
            Uri baseUri = Uri.parse("content://media/external/images/media");
740
            return Uri.withAppendedPath(baseUri, "" + id);
741
        } else {
742
            if (imageFile.exists()) {
743
                ContentValues values = new ContentValues();
744
                values.put(MediaStore.Images.Media.DATA, filePath);
745
                return context.getContentResolver().insert(
746
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
747
            } else {
748
                return null;
749
            }
750
        }
751
    }
752
753
    public Bitmap decodeUriAsBitmap(Uri uri) {
754
        Bitmap bitmap = null;
755
        try {
756
            bitmap = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri));
757
        } catch (FileNotFoundException e) {
758
            e.printStackTrace();
759
            return null;
760
        }
761
        return bitmap;
762
    }
763
764
721
    @Override
765 722
    protected void onRestart() {
766 723
        adapter.update();
767 724
        super.onRestart();
@ -774,66 +731,6 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
774 731
        Bimp.max = 0;
775 732
    }
776 733
777
    private void uploadFeedbackPic() {
778
        Map<String, String> par = new HashMap<String, String>();
779
        String file;
780
        for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) {
781
            try {
782
                bm = imageZoom(Bimp.tempSelectBitmap.get(i).getBitmap());
783
                file = bitmapToBase64(bm);
784
                par.put("file" + (i + 1), file);
785
                Log.i("file--------" + (i + 1), file);
786
                par.put("filename" + (i + 1), "androidapp.jpg");
787
            } catch (Exception e) {
788
                e.printStackTrace();
789
            }
790
791
        }
792
        try {
793
            String u = UploadUtil.postTopicPicture(
794
                    MainApplication.urlNew + "/topic/sign.do",
795
//                    "http://123.57.6.131/zhannew/basic/web/index.php/zhanlist/add",
796
//					"http://59.110.68.162"+"/zhannew/fileupload/multi-upload",
797
                    par, null);
798
            System.err.println(u);
799
            // submit(u);
800
            Message msg = new Message();
801
            msg.obj = u;
802
            msg.what = 2;
803
            handler.sendMessage(msg);
804
        } catch (IOException e) {
805
            e.printStackTrace();
806
        }
807
    }
808
809
    private String bitmapToBase64(Bitmap bitmap) {
810
811
        String result = null;
812
        ByteArrayOutputStream baos = null;
813
        try {
814
            if (bitmap != null) {
815
                baos = new ByteArrayOutputStream();
816
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
817
                baos.flush();
818
                baos.close();
819
                byte[] bitmapBytes = baos.toByteArray();
820
                result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
821
            }
822
        } catch (IOException e) {
823
            e.printStackTrace();
824
        } finally {
825
            try {
826
                if (baos != null) {
827
                    baos.flush();
828
                    baos.close();
829
                }
830
            } catch (IOException e) {
831
                e.printStackTrace();
832
            }
833
        }
834
        return result;
835
    }
836
837 734
    private Bitmap imageZoom(Bitmap bm) {
838 735
        // 图片允许最大空间 单位:KB
839 736
        double maxSize = 200.00;
@ -879,13 +776,6 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
879 776
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
880 777
        final String imem;
881 778
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
882
            // TODO: Consider calling
883
            //    ActivityCompat#requestPermissions
884
            // here to request the missing permissions, and then overriding
885
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
886
            //                                          int[] grantResults)
887
            // to handle the case where the user grants the permission. See the documentation
888
            // for ActivityCompat#requestPermissions for more details.
889 779
            imem = "";
890 780
        } else {
891 781
            imem = telephonyManager.getDeviceId();
@ -1015,25 +905,12 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
1015 905
    /**
1016 906
     * 表单上传
1017 907
     *
908
     * @param SAMPLE_PIC_FILE
1018 909
     * @param sign
1019
     * @param saveName
910
     * @param policyServer
1020 911
     */
1021
    private void formUpload(String SAMPLE_PIC_FILE, String sign, String saveName, String policyServer) {
912
    private void formUpload(String SAMPLE_PIC_FILE, String sign, String policyServer) {
1022 913
        File temp = new File(SAMPLE_PIC_FILE);
1023
//
1024
//        final Map<String, Object> paramsMap = new HashMap<>();
1025
//        //上传空间
1026
//        paramsMap.put(Params.BUCKET, SPACE);
1027
//        //保存路径,任选其中一个
1028
//        paramsMap.put(Params.SAVE_KEY, picSavePath);
1029
//        //添加 CONTENT_LENGTH 参数使用大文件表单上传
1030
//        paramsMap.put(Params.CONTENT_LENGTH, temp.length());
1031
//
1032
//
1033
//        paramsMap.put(Params.CONTENT_MD5, UpYunUtils.md5Hex(temp));
1034
////        paramsMap.put(Params.PATH, savePath);
1035
//        //可选参数(详情见api文档介绍)
1036
//        paramsMap.put(Params.RETURN_URL, "httpbin.org/post");
1037 914
//        //进度回调,可为空
1038 915
        UpProgressListener progressListener = new UpProgressListener() {
1039 916
            @Override
@ -1053,8 +930,10 @@ public class PublishPicTopicActivity extends Activity implements OnClickListener
1053 930
                Log.e(TAG, isSuccess + ":" + result);
1054 931
            }
1055 932
        };
933
1056 934
        //表单上传(服务器签名方式)
1057
        UploadEngine.getInstance().formUpload(temp, policyServer, OPERATER, sign, completeListener, progressListener);
935
        UploadEngine.getInstance().formUpload(temp, policyServer, OPERATER, sign, completeListener,
936
                progressListener);
1058 937
1059 938
    }
1060 939

+ 49 - 9
app/src/main/java/com/electric/chargingpile/activity/PublishTopicActivity.java

@ -3,8 +3,11 @@ package com.electric.chargingpile.activity;
3 3
import android.app.Activity;
4 4
import android.content.Context;
5 5
import android.content.Intent;
6
import android.graphics.drawable.Drawable;
7
import android.net.Uri;
6 8
import android.os.Bundle;
7 9
import android.os.Environment;
10
import android.support.annotation.Nullable;
8 11
import android.text.Editable;
9 12
import android.text.Html;
10 13
import android.text.TextUtils;
@ -14,8 +17,14 @@ import android.view.View;
14 17
import android.view.View.OnClickListener;
15 18
import android.widget.EditText;
16 19
import android.widget.ImageView;
20
import android.widget.RelativeLayout;
17 21
import android.widget.TextView;
18 22

23
import com.bumptech.glide.Glide;
24
import com.bumptech.glide.load.DataSource;
25
import com.bumptech.glide.load.engine.GlideException;
26
import com.bumptech.glide.request.RequestListener;
27
import com.bumptech.glide.request.target.Target;
19 28
import com.electric.chargingpile.R;
20 29
import com.electric.chargingpile.data.TalkRecommendBean;
21 30
import com.electric.chargingpile.util.BarColorUtil;
@ -30,11 +39,7 @@ import java.io.File;
30 39
import java.util.List;
31 40

32 41
public class PublishTopicActivity extends Activity implements OnClickListener {
33
    private ImageView ivBack, icon_scan;
34
    private TextView tvVersion, tv_banquan, tv_call, android;
35
    private String app_version;
36 42
    Context mContext;
37
    private static final int RC_CALL_PERM = 123;
38 43
    private ImageView mPublishtopicBack;
39 44
    private TextView mPublishtopicPublish;
40 45
    private EditText mPublishtopicCon;
@ -43,6 +48,12 @@ public class PublishTopicActivity extends Activity implements OnClickListener {
43 48
    private TextView mPublishtopicChoosePreview;
44 49
    private TextView mPublishtopicWordNum;
45 50
    private ImageView mPublishTopicDe;
51

52
    private RelativeLayout mItemVideoLl;
53
    private ImageView mItemVideo;
54
    private View mItemVideoDelete;
55

56

46 57
    public static final String CACHE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath() + "/cdz";
47 58

48 59

@ -68,6 +79,11 @@ public class PublishTopicActivity extends Activity implements OnClickListener {
68 79
        mPublishtopicWordNum = (TextView) findViewById(R.id.publishtopic_word_num);
69 80
        mPublishTopicDe = (ImageView) findViewById(R.id.publishtopic_choose_topic_de);
70 81

82
        mItemVideoLl = (RelativeLayout) findViewById(R.id.item_video_ll);
83
        mItemVideo = (ImageView) findViewById(R.id.item_video);
84
        mItemVideoDelete = (View) findViewById(R.id.item_video_delete);
85

86

71 87
        mPublishtopicCon.addTextChangedListener(new TextWatcher() {
72 88
            @Override
73 89
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
@ -97,6 +113,7 @@ public class PublishTopicActivity extends Activity implements OnClickListener {
97 113
        mPublishtopicChoosePreview.setOnClickListener(this);
98 114
        mPublishtopicChooseTopic.setOnClickListener(this);
99 115
        mPublishTopicDe.setOnClickListener(this);
116
        mItemVideoDelete.setOnClickListener(this);
100 117
        mPublishtopicGv.setOnClickListener(this);
101 118
    }
102 119

@ -146,6 +163,10 @@ public class PublishTopicActivity extends Activity implements OnClickListener {
146 163
                        .recordVideoSecond(15)//录制视频秒数 默认60秒
147 164
                        .forResult(PictureConfig.CHOOSE_REQUEST);
148 165
                break;
166
            case R.id.item_video_delete:
167
                mItemVideoLl.setVisibility(View.GONE);
168
                mPublishtopicGv.setVisibility(View.VISIBLE);
169
                break;
149 170
            default:
150 171
                break;
151 172
        }
@ -171,21 +192,40 @@ public class PublishTopicActivity extends Activity implements OnClickListener {
171 192
                    return;
172 193
                }
173 194
                if (!fileIsExists(media.getPath())) {
174
                    Log.e("yopic","文件可能不存在了~");
195
                    Log.e("yopic", "文件可能不存在了~");
175 196
                    return;
176 197
                }
177
                Log.e("yopic","TEST===> video path = " + media.getPath()
198

199
                Glide.with(this).load(Uri.fromFile(new File(media.getPath())))
200
                        .listener(new RequestListener<Drawable>() {
201
                            @Override
202
                            public boolean onLoadFailed(@Nullable GlideException e, Object model,
203
                                                        Target<Drawable> target, boolean isFirstResource) {
204
                                return false;
205
                            }
206

207
                            @Override
208
                            public boolean onResourceReady(Drawable resource, Object model,
209
                                                           Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
210
                                return false;
211
                            }
212
                        })
213
                        .into(mItemVideo);
214
                mItemVideoLl.setVisibility(View.VISIBLE);
215
                mPublishtopicGv.setVisibility(View.GONE);
216
                Log.e("yopic", "TEST===> video path = " + media.getPath()
178 217
                        + ",  compressPath = " + media.getCompressPath()
179 218
                        + ", height = " + media.getHeight()
180 219
                        + ", width = " + media.getWidth());
181 220
            }
182 221

183

184 222
        }
185 223
    }
186
    public static boolean fileIsExists(String strFile) {
187
        if (TextUtils.isEmpty(strFile)) return false;
188 224

225
    public static boolean fileIsExists(String strFile) {
226
        if (TextUtils.isEmpty(strFile)) {
227
            return false;
228
        }
189 229
        try {
190 230
            File f = new File(strFile);
191 231
            if (!f.exists()) {

+ 28 - 0
app/src/main/res/layout/activity_publishtopic.xml

@ -68,6 +68,34 @@
68 68
                android:layout_height="108dp"
69 69
                android:background="@drawable/icon_feedback_upload"
70 70
                android:scaleType="centerCrop" />
71
72
            <RelativeLayout
73
                android:id="@+id/item_video_ll"
74
                android:visibility="gone"
75
                android:layout_width="wrap_content"
76
                android:layout_height="wrap_content">
77
78
                <ImageView
79
                    android:id="@+id/item_video"
80
                    android:layout_width="wrap_content"
81
                    android:layout_height="wrap_content"
82
                    android:background="@drawable/icon_feedback_upload"
83
                    android:scaleType="centerCrop" />
84
85
                <View
86
                    android:layout_width="40dp"
87
                    android:layout_height="40dp"
88
                    android:layout_centerInParent="true"
89
                    android:background="@drawable/app_talk_video_icon" />
90
91
                <View
92
                    android:id="@+id/item_video_delete"
93
                    android:layout_width="16dp"
94
                    android:layout_height="16dp"
95
                    android:layout_alignEnd="@+id/item_video"
96
                    android:layout_margin="12dp"
97
                    android:background="@drawable/icon_tuijian_close" />
98
            </RelativeLayout>
71 99
        </LinearLayout>
72 100
    </ScrollView>
73 101

+ 1 - 1
videolibrary/picture_library/build.gradle

@ -21,7 +21,7 @@ android {
21 21
dependencies {
22 22
    compile 'com.android.support:appcompat-v7:26.1.0'
23 23
    compile 'com.android.support:recyclerview-v7:26.1.0'
24
    compile 'com.github.bumptech.glide:glide:4.0.0-RC1'
24
    compile 'com.github.bumptech.glide:glide:4.1.1'
25 25
    compile 'com.github.chrisbanes:PhotoView:1.3.0'
26 26
    compile 'io.reactivex.rxjava2:rxjava:2.0.5'
27 27
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'