dxh 5 years ago
parent
commit
f093399452

+ 4 - 4
app/src/main/AndroidManifest.xml

@ -853,10 +853,10 @@
853 853
        <activity
854 854
            android:name=".activity.TLDLoadingActivity"
855 855
            android:screenOrientation="portrait" />
856
        <activity
857
            android:name=".activity.MyCaptureActivity"
858
            android:launchMode="singleTask"
859
            android:screenOrientation="portrait" />
856
        <!--<activity-->
857
            <!--android:name=".activity.MyCaptureActivity"-->
858
            <!--android:launchMode="singleTask"-->
859
            <!--android:screenOrientation="portrait" />-->
860 860
        <activity
861 861
            android:name=".activity.MemberCoinRecordActivity"
862 862
            android:screenOrientation="portrait" />

+ 3 - 1
app/src/main/java/com/electric/chargingpile/activity/ImageDetailFragment.java

@ -48,7 +48,9 @@ public class ImageDetailFragment extends Fragment {
48 48
49 49
            @Override
50 50
            public void onPhotoTap(View arg0, float arg1, float arg2) {
51
                getActivity().finish();
51
                if (getActivity() != null) {
52
                    getActivity().finish();
53
                }
52 54
            }
53 55
        });
54 56

+ 950 - 947
app/src/main/java/com/electric/chargingpile/activity/MyCaptureActivity.java

@ -1,948 +1,951 @@
1
package com.electric.chargingpile.activity;
2
3
import android.app.Activity;
4
import android.content.Intent;
5
import android.content.SharedPreferences;
6
import android.content.pm.ActivityInfo;
7
import android.graphics.Rect;
8
import android.hardware.Camera;
9
import android.hardware.Camera.AutoFocusCallback;
10
import android.hardware.Camera.PreviewCallback;
11
import android.hardware.Camera.Size;
12
import android.os.Bundle;
13
import android.os.Handler;
14
import android.text.TextUtils;
15
import android.util.Log;
16
import android.view.KeyEvent;
17
import android.view.View;
18
import android.view.View.OnClickListener;
19
import android.view.animation.Animation;
20
import android.view.animation.TranslateAnimation;
21
import android.widget.Button;
22
import android.widget.FrameLayout;
23
import android.widget.ImageView;
24
import android.widget.RelativeLayout;
25
import android.widget.TextView;
26
import android.widget.Toast;
27
28
import com.electric.chargingpile.R;
29
import com.electric.chargingpile.application.MainApplication;
30
import com.electric.chargingpile.camera.CameraManager;
31
import com.electric.chargingpile.camera.CameraPreview;
32
import com.electric.chargingpile.manager.ProfileManager;
33
import com.electric.chargingpile.util.DES3;
34
import com.electric.chargingpile.util.JsonUtils;
35
import com.electric.chargingpile.util.LoadingDialog;
36
import com.electric.chargingpile.util.Md5Util;
37
import com.electric.chargingpile.util.ToastUtil;
38
import com.zhy.http.okhttp.OkHttpUtils;
39
import com.zhy.http.okhttp.callback.StringCallback;
40
41
import net.sourceforge.zbar.Config;
42
import net.sourceforge.zbar.Image;
43
import net.sourceforge.zbar.ImageScanner;
44
import net.sourceforge.zbar.Symbol;
45
import net.sourceforge.zbar.SymbolSet;
46
47
import java.io.IOException;
48
import java.lang.reflect.Field;
49
import java.net.URLEncoder;
50
51
import okhttp3.Call;
52
53
public class MyCaptureActivity extends Activity implements OnClickListener {
54
    private static final String TAG = "MyCaptureActivity";
55
    private Camera mCamera;
56
    private CameraPreview mPreview;
57
    private Handler autoFocusHandler;
58
    private CameraManager mCameraManager;
59
60
    private TextView scanResult, capture_flashlight, tv_input_code;
61
    private FrameLayout scanPreview;
62
    private Button scanRestart;
63
    private RelativeLayout scanContainer;
64
    private RelativeLayout scanCropView;
65
    private ImageView scanLine;
66
67
    private Rect mCropRect = null;
68
    private boolean barcodeScanned = false;
69
    private boolean previewing = true;
70
    private ImageScanner mImageScanner = null;
71
    private boolean flag = true;
72
    private LoadingDialog dialog;
73
    private String stubGroupId;
74
    private String password = "";
75
    private ImageView iv_back;
76
77
    static {
78
        System.loadLibrary("iconv");
79
    }
80
81
    public void onCreate(Bundle savedInstanceState) {
82
        super.onCreate(savedInstanceState);
83
        setContentView(R.layout.activity_my_capture);
84
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
85
        dialog = new LoadingDialog(this);
86
        dialog.setCanceledOnTouchOutside(false);
87
        findViewById();
88
        addEvents();
89
        initViews();
90
91
    }
92
93
    private void findViewById() {
94
        scanPreview = (FrameLayout) findViewById(R.id.capture_preview);
95
        scanResult = (TextView) findViewById(R.id.capture_scan_result);
96
        scanRestart = (Button) findViewById(R.id.capture_restart_scan);
97
        scanContainer = (RelativeLayout) findViewById(R.id.capture_container);
98
        scanCropView = (RelativeLayout) findViewById(R.id.capture_crop_view);
99
        scanLine = (ImageView) findViewById(R.id.capture_scan_line);
100
        capture_flashlight = (TextView) findViewById(R.id.capture_flashlight);
101
        capture_flashlight.setOnClickListener(this);
102
        tv_input_code = (TextView) findViewById(R.id.tv_input_code);
103
        tv_input_code.setOnClickListener(this);
104
        iv_back = (ImageView) findViewById(R.id.iv_back);
105
        iv_back.setOnClickListener(this);
106
    }
107
108
    private void addEvents() {
109
        scanRestart.setOnClickListener(new OnClickListener() {
110
            public void onClick(View v) {
111
112
            }
113
        });
114
    }
115
116
    private void scanRestart() {
117
        if (barcodeScanned) {
118
            barcodeScanned = false;
119
            if (null == mCamera) {
120
                mCamera = mCameraManager.getCamera();
121
            }
122
            mCamera.setPreviewCallback(previewCb);
123
            mCamera.startPreview();
124
            previewing = true;
125
            mCamera.autoFocus(autoFocusCB);
126
        }
127
    }
128
129
    public void light() {
130
        if (this.flag) {
131
            mCameraManager.openLight();
132
            this.flag = false;
133
            this.capture_flashlight.setText("关灯");
134
            return;
135
        }
136
        mCameraManager.offLight();
137
        this.flag = true;
138
        this.capture_flashlight.setText("开灯");
139
    }
140
141
    private void initViews() {
142
        mImageScanner = new ImageScanner();
143
        mImageScanner.setConfig(0, Config.X_DENSITY, 3);
144
        mImageScanner.setConfig(0, Config.Y_DENSITY, 3);
145
146
        autoFocusHandler = new Handler();
147
        mCameraManager = new CameraManager(this);
148
        try {
149
            mCameraManager.openDriver();
150
        } catch (IOException e) {
151
            e.printStackTrace();
152
        }
153
154
        mCamera = mCameraManager.getCamera();
155
        mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
156
        scanPreview.addView(mPreview);
157
158
        TranslateAnimation animation = new TranslateAnimation(
159
                Animation.RELATIVE_TO_PARENT, 0.0f,
160
                Animation.RELATIVE_TO_PARENT, 0.0f,
161
                Animation.RELATIVE_TO_PARENT, 0.0f,
162
                Animation.RELATIVE_TO_PARENT, 0.85f);
163
        animation.setDuration(3000);
164
        animation.setRepeatCount(-1);
165
        animation.setRepeatMode(Animation.REVERSE);
166
        scanLine.startAnimation(animation);
167
    }
168
169
    public void onPause() {
170
        Log.e(TAG, "onPause: 11");
171
        super.onPause();
172
//		scanRestart();
1
//package com.electric.chargingpile.activity;
2
//
3
//import android.app.Activity;
4
//import com.electric.chargingpile.view.AlertDialog;
5
//import android.content.Intent;
6
//import android.content.SharedPreferences;
7
//import android.content.pm.ActivityInfo;
8
//import android.graphics.Rect;
9
//import android.hardware.Camera;
10
//import android.hardware.Camera.AutoFocusCallback;
11
//import android.hardware.Camera.PreviewCallback;
12
//import android.hardware.Camera.Size;
13
//import android.os.Bundle;
14
//import android.os.Handler;
15
//import android.text.TextUtils;
16
//import android.util.Log;
17
//import android.view.KeyEvent;
18
//import android.view.View;
19
//import android.view.View.OnClickListener;
20
//import android.view.animation.Animation;
21
//import android.view.animation.TranslateAnimation;
22
//import android.widget.Button;
23
//import android.widget.FrameLayout;
24
//import android.widget.ImageView;
25
//import android.widget.RelativeLayout;
26
//import android.widget.TextView;
27
//import android.widget.Toast;
28
//
29
//import com.electric.chargingpile.R;
30
//import com.electric.chargingpile.application.MainApplication;
31
//import com.electric.chargingpile.camera.CameraManager;
32
//import com.electric.chargingpile.camera.CameraPreview;
33
//import com.electric.chargingpile.manager.ProfileManager;
34
//import com.electric.chargingpile.util.DES3;
35
//import com.electric.chargingpile.util.JsonUtils;
36
//import com.electric.chargingpile.util.LoadingDialog;
37
//import com.electric.chargingpile.util.Md5Util;
38
//import com.electric.chargingpile.util.ToastUtil;
39
//import com.zhy.http.okhttp.OkHttpUtils;
40
//import com.zhy.http.okhttp.callback.StringCallback;
41
//
42
//import net.sourceforge.zbar.Config;
43
//import net.sourceforge.zbar.Image;
44
//import net.sourceforge.zbar.ImageScanner;
45
//import net.sourceforge.zbar.Symbol;
46
//import net.sourceforge.zbar.SymbolSet;
47
//
48
//import java.io.IOException;
49
//import java.lang.reflect.Field;
50
//import java.net.URLEncoder;
51
//
52
//import okhttp3.Call;
53
//
54
//public class MyCaptureActivity extends Activity implements OnClickListener {
55
//    private static final String TAG = "MyCaptureActivity";
56
//    private Camera mCamera;
57
//    private CameraPreview mPreview;
58
//    private Handler autoFocusHandler;
59
//    private CameraManager mCameraManager;
60
//
61
//    private TextView scanResult, capture_flashlight, tv_input_code;
62
//    private FrameLayout scanPreview;
63
//    private Button scanRestart;
64
//    private RelativeLayout scanContainer;
65
//    private RelativeLayout scanCropView;
66
//    private ImageView scanLine;
67
//
68
//    private Rect mCropRect = null;
69
//    private boolean barcodeScanned = false;
70
//    private boolean previewing = true;
71
//    private ImageScanner mImageScanner = null;
72
//    private boolean flag = true;
73
//    private LoadingDialog dialog;
74
//    private String stubGroupId;
75
//    private String password = "";
76
//    private ImageView iv_back;
77
//
78
//    static {
79
//        System.loadLibrary("iconv");
80
//    }
81
//
82
//    @Override
83
//    public void onCreate(Bundle savedInstanceState) {
84
//        super.onCreate(savedInstanceState);
85
//        setContentView(R.layout.activity_my_capture);
86
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
87
//        dialog = new LoadingDialog(this);
88
//        dialog.setCanceledOnTouchOutside(false);
89
//        findViewById();
90
//        addEvents();
91
//        initViews();
92
//
93
//    }
94
//
95
//    private void findViewById() {
96
//        scanPreview = (FrameLayout) findViewById(R.id.capture_preview);
97
//        scanResult = (TextView) findViewById(R.id.capture_scan_result);
98
//        scanRestart = (Button) findViewById(R.id.capture_restart_scan);
99
//        scanContainer = (RelativeLayout) findViewById(R.id.capture_container);
100
//        scanCropView = (RelativeLayout) findViewById(R.id.capture_crop_view);
101
//        scanLine = (ImageView) findViewById(R.id.capture_scan_line);
102
//        capture_flashlight = (TextView) findViewById(R.id.capture_flashlight);
103
//        capture_flashlight.setOnClickListener(this);
104
//        tv_input_code = (TextView) findViewById(R.id.tv_input_code);
105
//        tv_input_code.setOnClickListener(this);
106
//        iv_back = (ImageView) findViewById(R.id.iv_back);
107
//        iv_back.setOnClickListener(this);
108
//    }
109
//
110
//    private void addEvents() {
111
//        scanRestart.setOnClickListener(new OnClickListener() {
112
//            public void onClick(View v) {
113
//
114
//            }
115
//        });
116
//    }
117
//
118
//    private void scanRestart() {
119
//        if (barcodeScanned) {
120
//            barcodeScanned = false;
121
//            if (null == mCamera) {
122
//                mCamera = mCameraManager.getCamera();
123
//            }
124
//            mCamera.setPreviewCallback(previewCb);
125
//            mCamera.startPreview();
126
//            previewing = true;
127
//            mCamera.autoFocus(autoFocusCB);
128
//        }
129
//    }
130
//
131
//    public void light() {
132
//        if (this.flag) {
133
//            mCameraManager.openLight();
134
//            this.flag = false;
135
//            this.capture_flashlight.setText("关灯");
136
//            return;
137
//        }
138
//        mCameraManager.offLight();
139
//        this.flag = true;
140
//        this.capture_flashlight.setText("开灯");
141
//    }
142
//
143
//    private void initViews() {
144
//        mImageScanner = new ImageScanner();
145
//        mImageScanner.setConfig(0, Config.X_DENSITY, 3);
146
//        mImageScanner.setConfig(0, Config.Y_DENSITY, 3);
147
//
148
//        autoFocusHandler = new Handler();
149
//        mCameraManager = new CameraManager(this);
150
//        try {
151
//            mCameraManager.openDriver();
152
//        } catch (IOException e) {
153
//            e.printStackTrace();
154
//        }
155
//
156
//        mCamera = mCameraManager.getCamera();
157
//        mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
158
//        scanPreview.addView(mPreview);
159
//
160
//        TranslateAnimation animation = new TranslateAnimation(
161
//                Animation.RELATIVE_TO_PARENT, 0.0f,
162
//                Animation.RELATIVE_TO_PARENT, 0.0f,
163
//                Animation.RELATIVE_TO_PARENT, 0.0f,
164
//                Animation.RELATIVE_TO_PARENT, 0.85f);
165
//        animation.setDuration(3000);
166
//        animation.setRepeatCount(-1);
167
//        animation.setRepeatMode(Animation.REVERSE);
168
//        scanLine.startAnimation(animation);
169
//    }
170
//
171
//    @Override
172
//    public void onPause() {
173
//        Log.e(TAG, "onPause: 11");
174
//        super.onPause();
175
////		scanRestart();
176
////        releaseCamera();
177
//    }
178
//
179
//    @Override
180
//    protected void onDestroy() {
181
//        super.onDestroy();
173 182
//        releaseCamera();
174
    }
175
176
    @Override
177
    protected void onDestroy() {
178
        super.onDestroy();
179
        releaseCamera();
180
    }
181
182
    @Override
183
    public boolean onKeyDown(int keyCode, KeyEvent event) {
184
        System.out.println("Page01 -->onKeyDown: keyCode: " + keyCode);
185
        if (KeyEvent.KEYCODE_HOME == keyCode) {
186
            System.out.println("HOME has been pressed yet ...");
187
            // android.os.Process.killProcess(android.os.Process.myPid());
188
            Toast.makeText(getApplicationContext(), "HOME 键已被禁用...",
189
                    Toast.LENGTH_LONG).show();
190
            return true;
191
        }
192
        return super.onKeyDown(keyCode, event); // 不会回到 home 页面
193
    }
194
195
    @Override
196
    protected void onResume() {
197
        super.onResume();
198
        scanRestart();
199
    }
200
201
    private void releaseCamera() {
202
        if (mCamera != null) {
203
            previewing = false;
204
            mCamera.setPreviewCallback(null);
205
            mCamera.release();
206
            mCamera = null;
207
        }
208
    }
209
210
    private Runnable doAutoFocus = new Runnable() {
211
        public void run() {
212
            if (previewing)
213
214
                mCamera.autoFocus(autoFocusCB);
215
        }
216
    };
217
218
    PreviewCallback previewCb = new PreviewCallback() {
219
        public void onPreviewFrame(byte[] data, Camera camera) {
220
            try {
221
                Size size = camera.getParameters().getPreviewSize();
222
223
                // 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据
224
                byte[] rotatedData = new byte[data.length];
225
                for (int y = 0; y < size.height; y++) {
226
                    for (int x = 0; x < size.width; x++)
227
                        rotatedData[x * size.height + size.height - y - 1] = data[x
228
                                + y * size.width];
229
                }
230
231
                // 宽高也要调整
232
                int tmp = size.width;
233
                size.width = size.height;
234
                size.height = tmp;
235
236
                initCrop();
237
238
                Image barcode = new Image(size.width, size.height, "Y800");
239
                barcode.setData(rotatedData);
240
                barcode.setCrop(mCropRect.left, mCropRect.top, mCropRect.width(),
241
                        mCropRect.height());
242
243
                int result = mImageScanner.scanImage(barcode);
244
                String resultStr = null;
245
246
                if (result != 0) {
247
                    SymbolSet syms = mImageScanner.getResults();
248
                    for (Symbol sym : syms) {
249
                        resultStr = sym.getData();
250
                    }
251
                }
252
253
                if (!TextUtils.isEmpty(resultStr)) {
254
                    previewing = false;
255
                    mCamera.setPreviewCallback(null);
256
                    mCamera.stopPreview();
257
258
                    barcodeScanned = true;
259
//                ToastUtil.showToast(getApplicationContext(),resultStr,Toast.LENGTH_SHORT);
260
//                Log.e(TAG, "onPreviewFrame: result="+resultStr );
261
262
                    getChargingPile(resultStr);
263
264
                }
265
266
            } catch (Exception e) {
267
                e.printStackTrace();
268
            }
269
        }
270
     };
271
272
    // Mimic continuous auto-focusing
273
    AutoFocusCallback autoFocusCB = new AutoFocusCallback() {
274
        public void onAutoFocus(boolean success, Camera camera) {
275
            autoFocusHandler.postDelayed(doAutoFocus, 1000);
276
        }
277
    };
278
279
    /**
280
     * 初始化截取的矩形区域
281
     */
282
    private void initCrop() {
283
        int cameraWidth = mCameraManager.getCameraResolution().y;
284
        int cameraHeight = mCameraManager.getCameraResolution().x;
285
286
        /** 获取布局中扫描框的位置信息 */
287
        int[] location = new int[2];
288
        scanCropView.getLocationInWindow(location);
289
290
        int cropLeft = location[0];
291
        int cropTop = location[1] - getStatusBarHeight();
292
293
        int cropWidth = scanCropView.getWidth();
294
        int cropHeight = scanCropView.getHeight();
295
296
        /** 获取布局容器的宽高 */
297
        int containerWidth = scanContainer.getWidth();
298
        int containerHeight = scanContainer.getHeight();
299
300
        /** 计算最终截取的矩形的左上角顶点x坐标 */
301
        int x = cropLeft * cameraWidth / containerWidth;
302
        /** 计算最终截取的矩形的左上角顶点y坐标 */
303
        int y = cropTop * cameraHeight / containerHeight;
304
305
        /** 计算最终截取的矩形的宽度 */
306
        int width = cropWidth * cameraWidth / containerWidth;
307
        /** 计算最终截取的矩形的高度 */
308
        int height = cropHeight * cameraHeight / containerHeight;
309
310
        /** 生成最终的截取的矩形 */
311
        mCropRect = new Rect(x, y, width + x, height + y);
312
    }
313
314
    private int getStatusBarHeight() {
315
        try {
316
            Class<?> c = Class.forName("com.android.internal.R$dimen");
317
            Object obj = c.newInstance();
318
            Field field = c.getField("status_bar_height");
319
            int x = Integer.parseInt(field.get(obj).toString());
320
            return getResources().getDimensionPixelSize(x);
321
        } catch (Exception e) {
322
            e.printStackTrace();
323
        }
324
        return 0;
325
    }
326
327
    @Override
328
    public void onClick(View v) {
329
        switch (v.getId()) {
330
            case R.id.capture_flashlight:
331
                light();
332
                break;
333
            case R.id.tv_input_code:
334
                startActivity(new Intent(getApplication(), InputCodeActivity.class));
335
                finish();
336
                break;
337
            case R.id.iv_back:
338
                finish();
339
                break;
340
        }
341
    }
342
343
    private void checkJd(final String chargingCode) {
344
        String url = MainApplication.url + "/zhannew/basic/web/index.php/polyelectric/info?pile_code=" + chargingCode;
345
        Log.e("jd_url===", url);
346
        OkHttpUtils.get()
347
                .url(url)
348
                .build()
349
                .execute(new StringCallback() {
350
                    @Override
351
                    public void onError(Call call, Exception e) {
352
353
                    }
354
355
                    @Override
356
                    public void onResponse(String response) {
357
                        dialog.cancel();
358
                        String code = JsonUtils.getKeyResult(response, "code");
359
                        if (code.equals("200")) {
360
                            String group_id = JsonUtils.getKeyResult(response, "group_id");
361
                            startJdCharging(group_id, chargingCode);
362
                        } else {
363
                            String error_messge = JsonUtils.getKeyResult(response, "error_message");
364
                            if (!error_messge.equals("")) {
365
                                ToastUtil.showToast(getApplicationContext(), error_messge, Toast.LENGTH_SHORT);
366
                                new Handler().postDelayed(new Runnable() {
367
                                    public void run() {
368
                                        scanRestart();
369
                                    }
370
                                }, 1500);
371
372
                            }
373
                        }
374
                    }
375
                });
376
    }
377
378
    private void startJdCharging(String zhan_id, String zhuang_id) {
379
        dialog.show();
380
        long appTime1 = System.currentTimeMillis() / 1000;
381
        long updatetime = appTime1 - MainMapActivity.cha - 3;
382
        String token = String.valueOf(updatetime);
383
        String s = "group_id=" + zhan_id + "&pile_code=" + zhuang_id + "&timer=" + token + "&user_id=" + MainApplication.userId + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a";
384
        Log.e("s_url==", s);
385
        final String url = MainApplication.url + "/zhannew/basic/web/index.php/polyelectric/start?ver=1.0&sign=" + Md5Util.md5(s) + "&timer=" + token + "&group_id=" + zhan_id + "&user_id=" + MainApplication.userId + "&pile_code=" + zhuang_id;
386
        Log.e("jd_url==", url);
387
        OkHttpUtils.get()
388
                .url(url)
389
                .build()
390
                .execute(new StringCallback() {
391
                    @Override
392
                    public void onError(Call call, Exception e) {
393
394
                    }
395
396
                    @Override
397
                    public void onResponse(String response) {
398
                        Log.e("start===", response);
399
                        dialog.cancel();
400
                        String code = JsonUtils.getKeyResult(response, "code");
401
                        if (code != null) {
402
                            if (code.equals("400")) {
403
                                String error_message = JsonUtils.getKeyResult(response, "error_message");
404
                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
405
                                OkHttpUtils.post()
406
                                        .url(urll)
407
                                        .addParams("url", url)
408
                                        .addParams("code", code)
409
                                        .addParams("message", error_message)
410
                                        .addParams("type", "android")
411
                                        .build()
412
                                        .execute(new StringCallback() {
413
                                            @Override
414
                                            public void onError(Call call, Exception e) {
415
416
                                            }
417
418
                                            @Override
419
                                            public void onResponse(String response) {
420
421
                                            }
422
                                        });
423
                                new com.electric.chargingpile.view.AlertDialog(MyCaptureActivity.this).builder()
424
                                        .setMsg(error_message)
425
                                        .setNegativeButton("确定", new View.OnClickListener() {
426
                                            @Override
427
                                            public void onClick(View v) {
428
                                                if (mCamera != null) {
429
                                                    scanRestart();
430
                                                }
431
//                                        startActivity(new Intent(getApplication(),ChargingStatusActivity.class));
432
433
//                                                startCharging();
434
                                            }
435
                                        }).show();
436
437
438
                            } else if (code.equals("200")) {
439
                                Intent intent = new Intent(getApplication(), ChargingStatusActivity.class);
440
//									intent.putExtra("stubId",zhuang_num);
441
//									intent.putExtra("stubGroupId",stubGroupId);
442
                                intent.putExtra("type", "jd");
443
                                startActivity(intent);
444
                                if (mCamera != null) {
445
                                    scanRestart();
446
                                }
447
                                finish();
448
                            } else if (code.equals("104")) {
449
                                String error_message = JsonUtils.getKeyResult(response, "error_message");
450
                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
451
                                OkHttpUtils.post()
452
                                        .url(urll)
453
                                        .addParams("url", url)
454
                                        .addParams("code", code)
455
                                        .addParams("message", error_message)
456
                                        .addParams("type", "android")
457
                                        .build()
458
                                        .execute(new StringCallback() {
459
                                            @Override
460
                                            public void onError(Call call, Exception e) {
461
462
                                            }
463
464
                                            @Override
465
                                            public void onResponse(String response) {
466
467
                                            }
468
                                        });
469
                                new com.electric.chargingpile.view.AlertDialog(MyCaptureActivity.this).builder()
470
                                        .setMsg("您的余额不足1元,可能无法满\n足您此次充电")
471
                                        .setPositiveButton("去充值", new View.OnClickListener() {
472
                                            @Override
473
                                            public void onClick(View v) {
474
                                                startActivity(new Intent(getApplication(), AccountRechargeActivity.class));
475
                                            }
476
                                        }).setNegativeButton("取消", new View.OnClickListener() {
477
                                    @Override
478
                                    public void onClick(View v) {
479
                                        if (mCamera != null) {
480
                                            scanRestart();
481
                                        }
482
//                                        startActivity(new Intent(getApplication(),ChargingStatusActivity.class));
483
                                    }
484
                                }).show();
485
                            } else if (code.equals("0")) {
486
                                if (mCamera != null) {
487
                                    scanRestart();
488
                                }
489
                                ToastUtil.showToast(getApplicationContext(), "该桩正在充电中,请移步到附近充电桩", Toast.LENGTH_SHORT);
490
                            } else if (code.equals("40000")) {
491
                                if (mCamera != null) {
492
                                    scanRestart();
493
                                }
494
                                ToastUtil.showToast(getApplicationContext(), "未插充电枪或该桩已离线", Toast.LENGTH_SHORT);
495
                            } else if (code.equals("600")) {
496
                                if (mCamera != null) {
497
                                    scanRestart();
498
                                }
499
                                ToastUtil.showToast(getApplicationContext(), "由于网络原因,您有一笔订单未结算,请稍候再试", Toast.LENGTH_SHORT);
500
                            } else {
501
                                if (mCamera != null) {
502
                                    scanRestart();
503
                                }
504
                                String error_message = JsonUtils.getKeyResult(response, "error_message");
505
                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
506
                                OkHttpUtils.post()
507
                                        .url(urll)
508
                                        .addParams("url", url)
509
                                        .addParams("code", code)
510
                                        .addParams("message", error_message)
511
                                        .addParams("type", "android")
512
                                        .build()
513
                                        .execute(new StringCallback() {
514
                                            @Override
515
                                            public void onError(Call call, Exception e) {
516
517
                                            }
518
519
                                            @Override
520
                                            public void onResponse(String response) {
521
522
                                            }
523
                                        });
524
                                ToastUtil.showToast(getApplicationContext(), error_message, Toast.LENGTH_SHORT);
525
                            }
526
                        }
527
                    }
528
                });
529
    }
530
531
    private void checkoutInfo(final String zhuang_num) {
532
        long appTime1 = System.currentTimeMillis() / 1000;
533
        Log.i("appTime(long)---", appTime1 + "");
534
        long updatetime = appTime1 - MainMapActivity.cha - 3;
535
        Log.i("updatetime(long)---", updatetime + "");
536
        Log.i("cha---", MainMapActivity.cha + "");
537
        String token = String.valueOf(updatetime);
538
        final String url = MainApplication.url + "/zhannew/basic/web/index.php/xxapi/info" +
539
                "?stubId=" + zhuang_num + "&supplier=星星充电&timer=" + token + "&user_id=" + MainApplication.userId + "&ver=1.0&sign="
540
                + Md5Util.md5("stubId=" + zhuang_num + "&supplier=星星充电&timer=" + token + "&user_id=" + MainApplication.userId + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a");
541
542
        Log.e("url", url);
543
        OkHttpUtils
544
                .get()
545
                .url(url)
546
                .build()
547
                .connTimeOut(20000)
548
                .readTimeOut(20000)
549
                .execute(new StringCallback() {
550
                    @Override
551
                    public void onError(Call call, Exception e) {
552
                        Toast.makeText(getApplicationContext(), "网络不给力", Toast.LENGTH_SHORT).show();
553
                        dialog.cancel();
554
                    }
555
556
                    @Override
557
                    public void onResponse(String response) {
558
                        Log.e("response====", response);
559
                        String error_message = JsonUtils.getKeyResult(response, "error_message");
560
                        String code = JsonUtils.getKeyResult(response, "code");
561
                        dialog.cancel();
562
                        if (code != null) {
563
                            if (code.equals("104")) {
564
                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
565
                                OkHttpUtils.post()
566
                                        .url(urll)
567
                                        .addParams("url", url)
568
                                        .addParams("code", code)
569
                                        .addParams("message", error_message)
570
                                        .addParams("type", "android")
571
                                        .build()
572
                                        .execute(new StringCallback() {
573
                                            @Override
574
                                            public void onError(Call call, Exception e) {
575
576
                                            }
577
578
                                            @Override
579
                                            public void onResponse(String response) {
580
581
                                            }
582
                                        });
583
                                new com.electric.chargingpile.view.AlertDialog(MyCaptureActivity.this).builder()
584
                                        .setMsg("您的余额不足1元,可能无法满\n足您此次充电")
585
                                        .setPositiveButton("去充值", new View.OnClickListener() {
586
                                            @Override
587
                                            public void onClick(View v) {
588
                                                startActivity(new Intent(getApplication(), AccountRechargeActivity.class));
589
                                            }
590
                                        }).setNegativeButton("取消", new View.OnClickListener() {
591
                                    @Override
592
                                    public void onClick(View v) {
593
                                        if (mCamera != null) {
594
                                            scanRestart();
595
                                        }
596
                                    }
597
                                }).show();
598
                            } else if (code.equals("106")) {
599
                                if (mCamera != null) {
600
                                    scanRestart();
601
                                }
602
                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
603
                                OkHttpUtils.post()
604
                                        .url(urll)
605
                                        .addParams("url", url)
606
                                        .addParams("code", code)
607
                                        .addParams("message", error_message)
608
                                        .addParams("type", "android")
609
                                        .build()
610
                                        .execute(new StringCallback() {
611
                                            @Override
612
                                            public void onError(Call call, Exception e) {
613
614
                                            }
615
616
                                            @Override
617
                                            public void onResponse(String response) {
618
619
                                            }
620
                                        });
621
                                ToastUtil.showToast(getApplicationContext(), "无此电桩,请重新扫码", Toast.LENGTH_SHORT);
622
                            } else if (code.equals("301")) {
623
                                if (mCamera != null) {
624
                                    scanRestart();
625
                                }
626
                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
627
                                OkHttpUtils.post()
628
                                        .url(urll)
629
                                        .addParams("url", url)
630
                                        .addParams("code", code)
631
                                        .addParams("message", error_message)
632
                                        .addParams("type", "android")
633
                                        .build()
634
                                        .execute(new StringCallback() {
635
                                            @Override
636
                                            public void onError(Call call, Exception e) {
637
638
                                            }
639
640
                                            @Override
641
                                            public void onResponse(String response) {
642
643
                                            }
644
                                        });
645
                                ToastUtil.showToast(getApplicationContext(), "终端系统错误", Toast.LENGTH_SHORT);
646
                            } else if (code.equals("200")) {
647
//                            00:空闲,01:充电中,02:故障,03:车位占用,04:维护中,
648
//                            05:离线,06:在建中,07:升级中,99:删除
649
650
                                String data = JsonUtils.getKeyResult(response, "data");
651
                                Log.e("data===", data);
652
                                String status = JsonUtils.getKeyResult(data, "status");
653
                                if (status.equals("00")) {
654
                                    stubGroupId = JsonUtils.getKeyResult(data, "stubGroupId");
655
                                    try {
656
                                        startCharging(zhuang_num);
657
                                    } catch (Exception e) {
658
                                        e.printStackTrace();
659
                                    }
660
661
662
                                } else if (status.equals("01")) {
663
                                    new com.electric.chargingpile.view.AlertDialog(MyCaptureActivity.this).builder()
664
                                            .setMsg("充电中")
665
                                            .setNegativeButton("确定", new View.OnClickListener() {
666
                                                @Override
667
                                                public void onClick(View v) {
668
                                                    scanRestart();
669
//                                        startActivity(new Intent(getApplication(),ChargingStatusActivity.class));
670
                                                }
671
                                            }).show();
672
                                } else if (status.equals("02")) {
673
                                    scanRestart();
674
                                    ToastUtil.showToast(getApplicationContext(), "故障", Toast.LENGTH_SHORT);
675
                                } else if (status.equals("03")) {
676
                                    scanRestart();
677
                                    ToastUtil.showToast(getApplicationContext(), "车位占用", Toast.LENGTH_SHORT);
678
                                } else if (status.equals("04")) {
679
                                    scanRestart();
680
                                    ToastUtil.showToast(getApplicationContext(), "维护中", Toast.LENGTH_SHORT);
681
                                } else if (status.equals("05")) {
682
                                    scanRestart();
683
                                    ToastUtil.showToast(getApplicationContext(), "离线", Toast.LENGTH_SHORT);
684
                                } else if (status.equals("06")) {
685
                                    scanRestart();
686
                                    ToastUtil.showToast(getApplicationContext(), "在建中", Toast.LENGTH_SHORT);
687
                                } else if (status.equals("07")) {
688
                                    scanRestart();
689
                                    ToastUtil.showToast(getApplicationContext(), "升级中", Toast.LENGTH_SHORT);
690
                                } else if (status.equals("99")) {
691
                                    scanRestart();
692
                                    ToastUtil.showToast(getApplicationContext(), "删除", Toast.LENGTH_SHORT);
693
                                }
694
                            } else if (code.equals("600")) {
695
                                scanRestart();
696
                                ToastUtil.showToast(getApplicationContext(), "由于网络原因,您有一笔订单未结算,请稍候再试", Toast.LENGTH_SHORT);
697
                            } else {
698
                                ToastUtil.showToast(getApplicationContext(), "无此电桩,请重新扫码", Toast.LENGTH_SHORT);
699
                                scanRestart();
700
                            }
701
                        } else {
702
                            ToastUtil.showToast(getApplicationContext(), "code为空", Toast.LENGTH_SHORT);
703
                        }
704
                    }
705
                });
706
    }
707
708
    private void sp() {
709
        SharedPreferences sharedPreferences = getApplication().getSharedPreferences("userInfo",
710
                Activity.MODE_PRIVATE);
711
        password = sharedPreferences.getString("password", "");
712
    }
713
714
    private void startCharging(final String zhuang_num) throws Exception {
715
        sp();
716
        dialog.show();
717
        long appTime1 = System.currentTimeMillis() / 1000;
718
        long updatetime = appTime1 - MainMapActivity.cha - 3;
719
        String token = String.valueOf(updatetime);
720
        String s = "password=" + DES3.encode(password) + "&stubGroupId=" + stubGroupId + "&stubId=" + zhuang_num + "&supplier=" + "星星充电&timer=" + token + "&user_id=" + MainApplication.userId + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a";
721
        final String url = MainApplication.url + "/zhannew/basic/web/index.php/charge/start" +
722
                "?password=" + URLEncoder.encode(DES3.encode(password)) + "&stubGroupId=" + stubGroupId + "&stubId=" + zhuang_num + "&supplier=" + URLEncoder.encode("星星充电") + "&timer=" + token + "&user_id=" + MainApplication.userId + "&ver=1.0&sign="
723
                + Md5Util.md5(s);
724
        Log.e("urlstart===", URLEncoder.encode(url));
725
        OkHttpUtils.get()
726
                .url(url)
727
                .build()
728
                .connTimeOut(10000)
729
                .readTimeOut(10000)
730
                .execute(new StringCallback() {
731
                    @Override
732
                    public void onError(Call call, Exception e) {
733
                        Toast.makeText(getApplicationContext(), "网络不给力", Toast.LENGTH_SHORT).show();
734
                        dialog.cancel();
735
                    }
736
737
                    @Override
738
                    public void onResponse(String response) {
739
                        Log.e("start===", response);
740
                        dialog.cancel();
741
                        String code = JsonUtils.getKeyResult(response, "code");
742
                        if (code != null) {
743
                            if (code.equals("400")) {
744
                                String error_message = JsonUtils.getKeyResult(response, "error_message");
745
                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
746
                                OkHttpUtils.post()
747
                                        .url(urll)
748
                                        .addParams("url", url)
749
                                        .addParams("code", code)
750
                                        .addParams("message", error_message)
751
                                        .addParams("type", "android")
752
                                        .build()
753
                                        .execute(new StringCallback() {
754
                                            @Override
755
                                            public void onError(Call call, Exception e) {
756
757
                                            }
758
759
                                            @Override
760
                                            public void onResponse(String response) {
761
762
                                            }
763
                                        });
764
                                new com.electric.chargingpile.view.AlertDialog(MyCaptureActivity.this).builder()
765
                                        .setMsg(error_message)
766
                                        .setNegativeButton("确定", new View.OnClickListener() {
767
                                            @Override
768
                                            public void onClick(View v) {
769
                                                if (mCamera != null) {
770
                                                    scanRestart();
771
                                                }
772
//                                        startActivity(new Intent(getApplication(),ChargingStatusActivity.class));
773
774
//                                                startCharging();
775
                                            }
776
                                        }).show();
777
778
779
                            } else if (code.equals("200")) {
780
                                Intent intent = new Intent(getApplication(), ChargingStatusActivity.class);
781
//								intent.putExtra("stubId",zhuang_num);
782
//								intent.putExtra("stubGroupId",stubGroupId);
783
                                intent.putExtra("type", "xx");
784
                                startActivity(intent);
785
                                if (mCamera != null) {
786
                                    scanRestart();
787
                                }
788
                                finish();
789
                            } else {
790
                                if (mCamera != null) {
791
                                    scanRestart();
792
                                }
793
                                String error_message = JsonUtils.getKeyResult(response, "error_message");
794
                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
795
                                OkHttpUtils.post()
796
                                        .url(urll)
797
                                        .addParams("url", url)
798
                                        .addParams("code", code)
799
                                        .addParams("message", error_message)
800
                                        .addParams("type", "android")
801
                                        .build()
802
                                        .execute(new StringCallback() {
803
                                            @Override
804
                                            public void onError(Call call, Exception e) {
805
806
                                            }
807
808
                                            @Override
809
                                            public void onResponse(String response) {
810
811
                                            }
812
                                        });
813
814
                                ToastUtil.showToast(getApplicationContext(), error_message, Toast.LENGTH_SHORT);
815
                            }
816
                        }
817
                    }
818
                });
819
    }
820
821
    private void checkTlD(final String chargingCode) {
822
        final String url = MainApplication.url + "/zhannew/basic/web/index.php/special/info?pile_id=" + chargingCode + "&user_id=" + MainApplication.userId;
823
        Log.e("checkTlD_url===", url);
824
        dialog.show();
825
        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
826
            @Override
827
            public void onError(Call call, Exception e) {
828
829
            }
830
831
            @Override
832
            public void onResponse(String response) {
833
                dialog.cancel();
834
                Log.e("checkTlD_response", response);
835
                String code = JsonUtils.getKeyResult(response, "code");
836
                if (code.equals("200")) {
837
                    String group_id = JsonUtils.getKeyResult(response, "group_id");
838
                    String eletype = JsonUtils.getKeyResult(response, "eletype");
839
                    Intent intent = new Intent(getApplicationContext(), TLDLoadingActivity.class);
840
                    intent.putExtra("eletype", eletype);
841
                    intent.putExtra("chargingCode", chargingCode);
842
                    intent.putExtra("group_id", group_id);
843
                    startActivity(intent);
844
                    finish();
845
846
//                    startTLD(chargingCode,group_id);
847
                } else {
848
                    String error_messge = JsonUtils.getKeyResult(response, "error_message");
849
                    Toast.makeText(getApplicationContext(), error_messge, Toast.LENGTH_SHORT).show();
850
                    new Handler().postDelayed(new Runnable() {
851
                        public void run() {
852
                            if (mCamera != null) {
853
                                scanRestart();
854
                            }
855
                        }
856
                    }, 1500);
857
                }
858
            }
859
        });
860
    }
861
862
    private void getChargingPile(final String result) {
863
        String url = MainApplication.url + "/zhannew/basic/web/index.php/interface/info?flag=1&user_id=" + MainApplication.userId + "&url=" + result;
864
        Log.e(TAG, "getChargingPile: url=" + url);
865
        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
866
            @Override
867
            public void onError(Call call, Exception e) {
868
869
            }
870
871
            @Override
872
            public void onResponse(String response) {
873
                Log.e(TAG, "onResponse: getChargingPile11=" + response);
874
                String code = JsonUtils.getKeyResult(response, "code");
875
                if (code.equals("200")) {
876
                    String group_id = JsonUtils.getKeyResult(response, "group_id");
877
                    String eletype = JsonUtils.getKeyResult(response, "eletype");
878
                    String type = JsonUtils.getKeyResult(response, "type");
879
                    String pile_code = JsonUtils.getKeyResult(response, "pile_code");
880
                    if (type.equals("jd")) {
881
                        startHssy(pile_code, group_id, type);
882
                    } else {
883
                        Intent intent = new Intent(getApplicationContext(), TLDLoadingActivity.class);
884
                        intent.putExtra("type", type);
885
                        intent.putExtra("eletype", eletype);
886
                        intent.putExtra("chargingCode", pile_code);
887
                        intent.putExtra("group_id", group_id);
888
                        startActivity(intent);
889
                        finish();
890
                    }
891
892
                } else {
893
                    String error_message = JsonUtils.getKeyResult(response, "error_message");
894
                    ToastUtil.showToast(getApplicationContext(), error_message, Toast.LENGTH_SHORT);
895
                    new Handler().postDelayed(new Runnable() {
896
                        public void run() {
897
                            if (mCamera != null) {
898
                                scanRestart();
899
                            }
900
901
                        }
902
                    }, 1500);
903
                }
904
            }
905
        });
906
    }
907
908
    private void startHssy(String pile_code, String group_id, String type) {
909
        long appTime1 = System.currentTimeMillis() / 1000;
910
        long updatetime = appTime1 - MainMapActivity.cha - 3;
911
        String token = String.valueOf(updatetime);
912
        String s = "group_id=" + group_id + "&password=" + MainApplication.userPassword + "&pile_code=" + pile_code + "&timer=" + token + "&type=" + type + "&user_id=" + MainApplication.userId + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a";
913
        String url = MainApplication.url + "/zhannew/basic/web/index.php/interface/start_v2?" +
914
                "ver=1.0&type=" + type + "&timer=" + token + "&user_id=" + MainApplication.userId + "&pile_code="
915
                + pile_code + "&group_id=" + group_id + "&password=" + MainApplication.userPassword + "&sign=" + Md5Util.md5(s);
916
        Log.e(TAG, "startHssy: url=" + url);
917
        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
918
            @Override
919
            public void onError(Call call, Exception e) {
920
921
            }
922
923
            @Override
924
            public void onResponse(String response) {
925
                Log.e(TAG, "onResponse: startHssy=" + response);
926
                String code = JsonUtils.getKeyResult(response, "code");
927
                if (code.equals("200")) {
928
                    MainApplication.isAppStart = true;
929
                    ProfileManager.getInstance().setAppStart(getApplicationContext(), MainApplication.isAppStart);
930
                    startActivity(new Intent(getApplicationContext(), ChargingStatusActivity.class));
931
                    finish();
932
                } else {
933
                    String error_message = JsonUtils.getKeyResult(response, "error_message");
934
                    ToastUtil.showToast(getApplicationContext(), error_message, Toast.LENGTH_SHORT);
935
                    new Handler().postDelayed(new Runnable() {
936
                        public void run() {
937
                            if (mCamera != null) {
938
                                scanRestart();
939
                            }
940
                        }
941
                    }, 1500);
942
                }
943
            }
944
        });
945
    }
946
947
948
}
183
//    }
184
//
185
//    @Override
186
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
187
//        System.out.println("Page01 -->onKeyDown: keyCode: " + keyCode);
188
//        if (KeyEvent.KEYCODE_HOME == keyCode) {
189
//            System.out.println("HOME has been pressed yet ...");
190
//            // android.os.Process.killProcess(android.os.Process.myPid());
191
//            Toast.makeText(getApplicationContext(), "HOME 键已被禁用...",
192
//                    Toast.LENGTH_LONG).show();
193
//            return true;
194
//        }
195
//        return super.onKeyDown(keyCode, event); // 不会回到 home 页面
196
//    }
197
//
198
//    @Override
199
//    protected void onResume() {
200
//        super.onResume();
201
//        scanRestart();
202
//    }
203
//
204
//    private void releaseCamera() {
205
//        if (mCamera != null) {
206
//            previewing = false;
207
//            mCamera.setPreviewCallback(null);
208
//            mCamera.release();
209
//            mCamera = null;
210
//        }
211
//    }
212
//
213
//    private Runnable doAutoFocus = new Runnable() {
214
//        public void run() {
215
//            if (previewing)
216
//
217
//                mCamera.autoFocus(autoFocusCB);
218
//        }
219
//    };
220
//
221
//    PreviewCallback previewCb = new PreviewCallback() {
222
//        public void onPreviewFrame(byte[] data, Camera camera) {
223
//            try {
224
//                Size size = camera.getParameters().getPreviewSize();
225
//
226
//                // 这里需要将获取的data翻转一下,因为相机默认拿的的横屏的数据
227
//                byte[] rotatedData = new byte[data.length];
228
//                for (int y = 0; y < size.height; y++) {
229
//                    for (int x = 0; x < size.width; x++)
230
//                        rotatedData[x * size.height + size.height - y - 1] = data[x
231
//                                + y * size.width];
232
//                }
233
//
234
//                // 宽高也要调整
235
//                int tmp = size.width;
236
//                size.width = size.height;
237
//                size.height = tmp;
238
//
239
//                initCrop();
240
//
241
//                Image barcode = new Image(size.width, size.height, "Y800");
242
//                barcode.setData(rotatedData);
243
//                barcode.setCrop(mCropRect.left, mCropRect.top, mCropRect.width(),
244
//                        mCropRect.height());
245
//
246
//                int result = mImageScanner.scanImage(barcode);
247
//                String resultStr = null;
248
//
249
//                if (result != 0) {
250
//                    SymbolSet syms = mImageScanner.getResults();
251
//                    for (Symbol sym : syms) {
252
//                        resultStr = sym.getData();
253
//                    }
254
//                }
255
//
256
//                if (!TextUtils.isEmpty(resultStr)) {
257
//                    previewing = false;
258
//                    mCamera.setPreviewCallback(null);
259
//                    mCamera.stopPreview();
260
//
261
//                    barcodeScanned = true;
262
////                ToastUtil.showToast(getApplicationContext(),resultStr,Toast.LENGTH_SHORT);
263
////                Log.e(TAG, "onPreviewFrame: result="+resultStr );
264
//
265
//                    getChargingPile(resultStr);
266
//
267
//                }
268
//
269
//            } catch (Exception e) {
270
//                e.printStackTrace();
271
//            }
272
//        }
273
//    };
274
//
275
//    // Mimic continuous auto-focusing
276
//    AutoFocusCallback autoFocusCB = new AutoFocusCallback() {
277
//        public void onAutoFocus(boolean success, Camera camera) {
278
//            autoFocusHandler.postDelayed(doAutoFocus, 1000);
279
//         }
280
//    };
281
//
282
//    /**
283
//     * 初始化截取的矩形区域
284
//     */
285
//    private void initCrop() {
286
//        int cameraWidth = mCameraManager.getCameraResolution().y;
287
//        int cameraHeight = mCameraManager.getCameraResolution().x;
288
//
289
//        /** 获取布局中扫描框的位置信息 */
290
//        int[] location = new int[2];
291
//        scanCropView.getLocationInWindow(location);
292
//
293
//        int cropLeft = location[0];
294
//        int cropTop = location[1] - getStatusBarHeight();
295
//
296
//        int cropWidth = scanCropView.getWidth();
297
//        int cropHeight = scanCropView.getHeight();
298
//
299
//        /** 获取布局容器的宽高 */
300
//        int containerWidth = scanContainer.getWidth();
301
//        int containerHeight = scanContainer.getHeight();
302
//
303
//        /** 计算最终截取的矩形的左上角顶点x坐标 */
304
//        int x = cropLeft * cameraWidth / containerWidth;
305
//        /** 计算最终截取的矩形的左上角顶点y坐标 */
306
//        int y = cropTop * cameraHeight / containerHeight;
307
//
308
//        /** 计算最终截取的矩形的宽度 */
309
//        int width = cropWidth * cameraWidth / containerWidth;
310
//        /** 计算最终截取的矩形的高度 */
311
//        int height = cropHeight * cameraHeight / containerHeight;
312
//
313
//        /** 生成最终的截取的矩形 */
314
//        mCropRect = new Rect(x, y, width + x, height + y);
315
//    }
316
//
317
//    private int getStatusBarHeight() {
318
//        try {
319
//            Class<?> c = Class.forName("com.android.internal.R$dimen");
320
//            Object obj = c.newInstance();
321
//            Field field = c.getField("status_bar_height");
322
//            int x = Integer.parseInt(field.get(obj).toString());
323
//            return getResources().getDimensionPixelSize(x);
324
//        } catch (Exception e) {
325
//            e.printStackTrace();
326
//        }
327
//        return 0;
328
//    }
329
//
330
//    @Override
331
//    public void onClick(View v) {
332
//        switch (v.getId()) {
333
//            case R.id.capture_flashlight:
334
//                light();
335
//                break;
336
//            case R.id.tv_input_code:
337
//                startActivity(new Intent(getApplication(), InputCodeActivity.class));
338
//                finish();
339
//                break;
340
//            case R.id.iv_back:
341
//                finish();
342
//                break;
343
//        }
344
//    }
345
//
346
//    private void checkJd(final String chargingCode) {
347
//        String url = MainApplication.url + "/zhannew/basic/web/index.php/polyelectric/info?pile_code=" + chargingCode;
348
//        Log.e("jd_url===", url);
349
//        OkHttpUtils.get()
350
//                .url(url)
351
//                .build()
352
//                .execute(new StringCallback() {
353
//                    @Override
354
//                    public void onError(Call call, Exception e) {
355
//
356
//                    }
357
//
358
//                    @Override
359
//                    public void onResponse(String response) {
360
//                        dialog.cancel();
361
//                        String code = JsonUtils.getKeyResult(response, "code");
362
//                        if (code.equals("200")) {
363
//                            String group_id = JsonUtils.getKeyResult(response, "group_id");
364
//                            startJdCharging(group_id, chargingCode);
365
//                        } else {
366
//                            String error_messge = JsonUtils.getKeyResult(response, "error_message");
367
//                            if (!error_messge.equals("")) {
368
//                                ToastUtil.showToast(getApplicationContext(), error_messge, Toast.LENGTH_SHORT);
369
//                                new Handler().postDelayed(new Runnable() {
370
//                                    public void run() {
371
//                                        scanRestart();
372
//                                    }
373
//                                }, 1500);
374
//
375
//                            }
376
//                        }
377
//                    }
378
//                });
379
//    }
380
//
381
//    private void startJdCharging(String zhan_id, String zhuang_id) {
382
//        dialog.show();
383
//        long appTime1 = System.currentTimeMillis() / 1000;
384
//        long updatetime = appTime1 - MainMapActivity.cha - 3;
385
//        String token = String.valueOf(updatetime);
386
//        String s = "group_id=" + zhan_id + "&pile_code=" + zhuang_id + "&timer=" + token + "&user_id=" + MainApplication.userId + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a";
387
//        Log.e("s_url==", s);
388
//        final String url = MainApplication.url + "/zhannew/basic/web/index.php/polyelectric/start?ver=1.0&sign=" + Md5Util.md5(s) + "&timer=" + token + "&group_id=" + zhan_id + "&user_id=" + MainApplication.userId + "&pile_code=" + zhuang_id;
389
//        Log.e("jd_url==", url);
390
//        OkHttpUtils.get()
391
//                .url(url)
392
//                .build()
393
//                .execute(new StringCallback() {
394
//                    @Override
395
//                    public void onError(Call call, Exception e) {
396
//
397
//                    }
398
//
399
//                    @Override
400
//                    public void onResponse(String response) {
401
//                        Log.e("start===", response);
402
//                        dialog.cancel();
403
//                        String code = JsonUtils.getKeyResult(response, "code");
404
//                        if (code != null) {
405
//                            if (code.equals("400")) {
406
//                                String error_message = JsonUtils.getKeyResult(response, "error_message");
407
//                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
408
//                                OkHttpUtils.post()
409
//                                        .url(urll)
410
//                                        .addParams("url", url)
411
//                                        .addParams("code", code)
412
//                                        .addParams("message", error_message)
413
//                                        .addParams("type", "android")
414
//                                        .build()
415
//                                        .execute(new StringCallback() {
416
//                                            @Override
417
//                                            public void onError(Call call, Exception e) {
418
//
419
//                                            }
420
//
421
//                                            @Override
422
//                                            public void onResponse(String response) {
423
//
424
//                                            }
425
//                                        });
426
//                                new AlertDialog(MyCaptureActivity.this).builder()
427
//                                        .setMsg(error_message)
428
//                                        .setNegativeButton("确定", new View.OnClickListener() {
429
//                                            @Override
430
//                                            public void onClick(View v) {
431
//                                                if (mCamera != null) {
432
//                                                    scanRestart();
433
//                                                }
434
////                                        startActivity(new Intent(getApplication(),ChargingStatusActivity.class));
435
//
436
////                                                startCharging();
437
//                                            }
438
//                                        }).show();
439
//
440
//
441
//                            } else if (code.equals("200")) {
442
//                                Intent intent = new Intent(getApplication(), ChargingStatusActivity.class);
443
////									intent.putExtra("stubId",zhuang_num);
444
////									intent.putExtra("stubGroupId",stubGroupId);
445
//                                intent.putExtra("type", "jd");
446
//                                startActivity(intent);
447
//                                if (mCamera != null) {
448
//                                    scanRestart();
449
//                                }
450
//                                finish();
451
//                            } else if (code.equals("104")) {
452
//                                String error_message = JsonUtils.getKeyResult(response, "error_message");
453
//                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
454
//                                OkHttpUtils.post()
455
//                                        .url(urll)
456
//                                        .addParams("url", url)
457
//                                        .addParams("code", code)
458
//                                        .addParams("message", error_message)
459
//                                        .addParams("type", "android")
460
//                                        .build()
461
//                                        .execute(new StringCallback() {
462
//                                            @Override
463
//                                            public void onError(Call call, Exception e) {
464
//
465
//                                            }
466
//
467
//                                            @Override
468
//                                            public void onResponse(String response) {
469
//
470
//                                            }
471
//                                        });
472
//                                new AlertDialog(MyCaptureActivity.this).builder()
473
//                                        .setMsg("您的余额不足1元,可能无法满\n足您此次充电")
474
//                                        .setPositiveButton("去充值", new View.OnClickListener() {
475
//                                            @Override
476
//                                            public void onClick(View v) {
477
//                                                startActivity(new Intent(getApplication(), AccountRechargeActivity.class));
478
//                                            }
479
//                                        }).setNegativeButton("取消", new View.OnClickListener() {
480
//                                    @Override
481
//                                    public void onClick(View v) {
482
//                                        if (mCamera != null) {
483
//                                            scanRestart();
484
//                                        }
485
////                                        startActivity(new Intent(getApplication(),ChargingStatusActivity.class));
486
//                                    }
487
//                                }).show();
488
//                            } else if (code.equals("0")) {
489
//                                if (mCamera != null) {
490
//                                    scanRestart();
491
//                                }
492
//                                ToastUtil.showToast(getApplicationContext(), "该桩正在充电中,请移步到附近充电桩", Toast.LENGTH_SHORT);
493
//                            } else if (code.equals("40000")) {
494
//                                if (mCamera != null) {
495
//                                    scanRestart();
496
//                                }
497
//                                ToastUtil.showToast(getApplicationContext(), "未插充电枪或该桩已离线", Toast.LENGTH_SHORT);
498
//                            } else if (code.equals("600")) {
499
//                                if (mCamera != null) {
500
//                                    scanRestart();
501
//                                }
502
//                                ToastUtil.showToast(getApplicationContext(), "由于网络原因,您有一笔订单未结算,请稍候再试", Toast.LENGTH_SHORT);
503
//                            } else {
504
//                                if (mCamera != null) {
505
//                                    scanRestart();
506
//                                }
507
//                                String error_message = JsonUtils.getKeyResult(response, "error_message");
508
//                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
509
//                                OkHttpUtils.post()
510
//                                        .url(urll)
511
//                                        .addParams("url", url)
512
//                                        .addParams("code", code)
513
//                                        .addParams("message", error_message)
514
//                                        .addParams("type", "android")
515
//                                        .build()
516
//                                        .execute(new StringCallback() {
517
//                                            @Override
518
//                                            public void onError(Call call, Exception e) {
519
//
520
//                                            }
521
//
522
//                                            @Override
523
//                                            public void onResponse(String response) {
524
//
525
//                                            }
526
//                                        });
527
//                                ToastUtil.showToast(getApplicationContext(), error_message, Toast.LENGTH_SHORT);
528
//                            }
529
//                        }
530
//                    }
531
//                });
532
//    }
533
//
534
//    private void checkoutInfo(final String zhuang_num) {
535
//        long appTime1 = System.currentTimeMillis() / 1000;
536
//        Log.i("appTime(long)---", appTime1 + "");
537
//        long updatetime = appTime1 - MainMapActivity.cha - 3;
538
//        Log.i("updatetime(long)---", updatetime + "");
539
//        Log.i("cha---", MainMapActivity.cha + "");
540
//        String token = String.valueOf(updatetime);
541
//        final String url = MainApplication.url + "/zhannew/basic/web/index.php/xxapi/info" +
542
//                "?stubId=" + zhuang_num + "&supplier=星星充电&timer=" + token + "&user_id=" + MainApplication.userId + "&ver=1.0&sign="
543
//                + Md5Util.md5("stubId=" + zhuang_num + "&supplier=星星充电&timer=" + token + "&user_id=" + MainApplication.userId + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a");
544
//
545
//        Log.e("url", url);
546
//        OkHttpUtils
547
//                .get()
548
//                .url(url)
549
//                .build()
550
//                .connTimeOut(20000)
551
//                .readTimeOut(20000)
552
//                .execute(new StringCallback() {
553
//                    @Override
554
//                    public void onError(Call call, Exception e) {
555
//                        Toast.makeText(getApplicationContext(), "网络不给力", Toast.LENGTH_SHORT).show();
556
//                        dialog.cancel();
557
//                    }
558
//
559
//                    @Override
560
//                    public void onResponse(String response) {
561
//                        Log.e("response====", response);
562
//                        String error_message = JsonUtils.getKeyResult(response, "error_message");
563
//                        String code = JsonUtils.getKeyResult(response, "code");
564
//                        dialog.cancel();
565
//                        if (code != null) {
566
//                            if (code.equals("104")) {
567
//                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
568
//                                OkHttpUtils.post()
569
//                                        .url(urll)
570
//                                        .addParams("url", url)
571
//                                        .addParams("code", code)
572
//                                        .addParams("message", error_message)
573
//                                        .addParams("type", "android")
574
//                                        .build()
575
//                                        .execute(new StringCallback() {
576
//                                            @Override
577
//                                            public void onError(Call call, Exception e) {
578
//
579
//                                            }
580
//
581
//                                            @Override
582
//                                            public void onResponse(String response) {
583
//
584
//                                            }
585
//                                        });
586
//                                new AlertDialog(MyCaptureActivity.this).builder()
587
//                                        .setMsg("您的余额不足1元,可能无法满\n足您此次充电")
588
//                                        .setPositiveButton("去充值", new View.OnClickListener() {
589
//                                            @Override
590
//                                            public void onClick(View v) {
591
//                                                startActivity(new Intent(getApplication(), AccountRechargeActivity.class));
592
//                                            }
593
//                                        }).setNegativeButton("取消", new View.OnClickListener() {
594
//                                    @Override
595
//                                    public void onClick(View v) {
596
//                                        if (mCamera != null) {
597
//                                            scanRestart();
598
//                                        }
599
//                                    }
600
//                                }).show();
601
//                            } else if (code.equals("106")) {
602
//                                if (mCamera != null) {
603
//                                    scanRestart();
604
//                                }
605
//                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
606
//                                OkHttpUtils.post()
607
//                                        .url(urll)
608
//                                        .addParams("url", url)
609
//                                        .addParams("code", code)
610
//                                        .addParams("message", error_message)
611
//                                        .addParams("type", "android")
612
//                                        .build()
613
//                                        .execute(new StringCallback() {
614
//                                            @Override
615
//                                            public void onError(Call call, Exception e) {
616
//
617
//                                            }
618
//
619
//                                            @Override
620
//                                            public void onResponse(String response) {
621
//
622
//                                            }
623
//                                        });
624
//                                ToastUtil.showToast(getApplicationContext(), "无此电桩,请重新扫码", Toast.LENGTH_SHORT);
625
//                            } else if (code.equals("301")) {
626
//                                if (mCamera != null) {
627
//                                    scanRestart();
628
//                                }
629
//                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
630
//                                OkHttpUtils.post()
631
//                                        .url(urll)
632
//                                        .addParams("url", url)
633
//                                        .addParams("code", code)
634
//                                        .addParams("message", error_message)
635
//                                        .addParams("type", "android")
636
//                                        .build()
637
//                                        .execute(new StringCallback() {
638
//                                            @Override
639
//                                            public void onError(Call call, Exception e) {
640
//
641
//                                            }
642
//
643
//                                            @Override
644
//                                            public void onResponse(String response) {
645
//
646
//                                            }
647
//                                        });
648
//                                ToastUtil.showToast(getApplicationContext(), "终端系统错误", Toast.LENGTH_SHORT);
649
//                            } else if (code.equals("200")) {
650
////                            00:空闲,01:充电中,02:故障,03:车位占用,04:维护中,
651
////                            05:离线,06:在建中,07:升级中,99:删除
652
//
653
//                                String data = JsonUtils.getKeyResult(response, "data");
654
//                                Log.e("data===", data);
655
//                                String status = JsonUtils.getKeyResult(data, "status");
656
//                                if (status.equals("00")) {
657
//                                    stubGroupId = JsonUtils.getKeyResult(data, "stubGroupId");
658
//                                    try {
659
//                                        startCharging(zhuang_num);
660
//                                    } catch (Exception e) {
661
//                                        e.printStackTrace();
662
//                                    }
663
//
664
//
665
//                                } else if (status.equals("01")) {
666
//                                    new AlertDialog(MyCaptureActivity.this).builder()
667
//                                            .setMsg("充电中")
668
//                                            .setNegativeButton("确定", new View.OnClickListener() {
669
//                                                @Override
670
//                                                public void onClick(View v) {
671
//                                                    scanRestart();
672
////                                        startActivity(new Intent(getApplication(),ChargingStatusActivity.class));
673
//                                                }
674
//                                            }).show();
675
//                                } else if (status.equals("02")) {
676
//                                    scanRestart();
677
//                                    ToastUtil.showToast(getApplicationContext(), "故障", Toast.LENGTH_SHORT);
678
//                                } else if (status.equals("03")) {
679
//                                    scanRestart();
680
//                                    ToastUtil.showToast(getApplicationContext(), "车位占用", Toast.LENGTH_SHORT);
681
//                                } else if (status.equals("04")) {
682
//                                    scanRestart();
683
//                                    ToastUtil.showToast(getApplicationContext(), "维护中", Toast.LENGTH_SHORT);
684
//                                } else if (status.equals("05")) {
685
//                                    scanRestart();
686
//                                    ToastUtil.showToast(getApplicationContext(), "离线", Toast.LENGTH_SHORT);
687
//                                } else if (status.equals("06")) {
688
//                                    scanRestart();
689
//                                    ToastUtil.showToast(getApplicationContext(), "在建中", Toast.LENGTH_SHORT);
690
//                                } else if (status.equals("07")) {
691
//                                    scanRestart();
692
//                                    ToastUtil.showToast(getApplicationContext(), "升级中", Toast.LENGTH_SHORT);
693
//                                } else if (status.equals("99")) {
694
//                                    scanRestart();
695
//                                    ToastUtil.showToast(getApplicationContext(), "删除", Toast.LENGTH_SHORT);
696
//                                }
697
//                            } else if (code.equals("600")) {
698
//                                scanRestart();
699
//                                ToastUtil.showToast(getApplicationContext(), "由于网络原因,您有一笔订单未结算,请稍候再试", Toast.LENGTH_SHORT);
700
//                            } else {
701
//                                ToastUtil.showToast(getApplicationContext(), "无此电桩,请重新扫码", Toast.LENGTH_SHORT);
702
//                                scanRestart();
703
//                            }
704
//                        } else {
705
//                            ToastUtil.showToast(getApplicationContext(), "code为空", Toast.LENGTH_SHORT);
706
//                        }
707
//                    }
708
//                });
709
//    }
710
//
711
//    private void sp() {
712
//        SharedPreferences sharedPreferences = getApplication().getSharedPreferences("userInfo",
713
//                Activity.MODE_PRIVATE);
714
//        password = sharedPreferences.getString("password", "");
715
//    }
716
//
717
//    private void startCharging(final String zhuang_num) throws Exception {
718
//        sp();
719
//        dialog.show();
720
//        long appTime1 = System.currentTimeMillis() / 1000;
721
//        long updatetime = appTime1 - MainMapActivity.cha - 3;
722
//        String token = String.valueOf(updatetime);
723
//        String s = "password=" + DES3.encode(password) + "&stubGroupId=" + stubGroupId + "&stubId=" + zhuang_num + "&supplier=" + "星星充电&timer=" + token + "&user_id=" + MainApplication.userId + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a";
724
//        final String url = MainApplication.url + "/zhannew/basic/web/index.php/charge/start" +
725
//                "?password=" + URLEncoder.encode(DES3.encode(password)) + "&stubGroupId=" + stubGroupId + "&stubId=" + zhuang_num + "&supplier=" + URLEncoder.encode("星星充电") + "&timer=" + token + "&user_id=" + MainApplication.userId + "&ver=1.0&sign="
726
//                + Md5Util.md5(s);
727
//        Log.e("urlstart===", URLEncoder.encode(url));
728
//        OkHttpUtils.get()
729
//                .url(url)
730
//                .build()
731
//                .connTimeOut(10000)
732
//                .readTimeOut(10000)
733
//                .execute(new StringCallback() {
734
//                    @Override
735
//                    public void onError(Call call, Exception e) {
736
//                        Toast.makeText(getApplicationContext(), "网络不给力", Toast.LENGTH_SHORT).show();
737
//                        dialog.cancel();
738
//                    }
739
//
740
//                    @Override
741
//                    public void onResponse(String response) {
742
//                        Log.e("start===", response);
743
//                        dialog.cancel();
744
//                        String code = JsonUtils.getKeyResult(response, "code");
745
//                        if (code != null) {
746
//                            if (code.equals("400")) {
747
//                                String error_message = JsonUtils.getKeyResult(response, "error_message");
748
//                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
749
//                                OkHttpUtils.post()
750
//                                        .url(urll)
751
//                                        .addParams("url", url)
752
//                                        .addParams("code", code)
753
//                                        .addParams("message", error_message)
754
//                                        .addParams("type", "android")
755
//                                        .build()
756
//                                        .execute(new StringCallback() {
757
//                                            @Override
758
//                                            public void onError(Call call, Exception e) {
759
//
760
//                                            }
761
//
762
//                                            @Override
763
//                                            public void onResponse(String response) {
764
//
765
//                                            }
766
//                                        });
767
//                                new AlertDialog(MyCaptureActivity.this).builder()
768
//                                        .setMsg(error_message)
769
//                                        .setNegativeButton("确定", new View.OnClickListener() {
770
//                                            @Override
771
//                                            public void onClick(View v) {
772
//                                                if (mCamera != null) {
773
//                                                    scanRestart();
774
//                                                }
775
////                                        startActivity(new Intent(getApplication(),ChargingStatusActivity.class));
776
//
777
////                                                startCharging();
778
//                                            }
779
//                                        }).show();
780
//
781
//
782
//                            } else if (code.equals("200")) {
783
//                                Intent intent = new Intent(getApplication(), ChargingStatusActivity.class);
784
////								intent.putExtra("stubId",zhuang_num);
785
////								intent.putExtra("stubGroupId",stubGroupId);
786
//                                intent.putExtra("type", "xx");
787
//                                startActivity(intent);
788
//                                if (mCamera != null) {
789
//                                    scanRestart();
790
//                                }
791
//                                finish();
792
//                            } else {
793
//                                if (mCamera != null) {
794
//                                    scanRestart();
795
//                                }
796
//                                String error_message = JsonUtils.getKeyResult(response, "error_message");
797
//                                String urll = "http://123.57.6.131/zhannew/basic/web/index.php/log/write";
798
//                                OkHttpUtils.post()
799
//                                        .url(urll)
800
//                                        .addParams("url", url)
801
//                                        .addParams("code", code)
802
//                                        .addParams("message", error_message)
803
//                                        .addParams("type", "android")
804
//                                        .build()
805
//                                        .execute(new StringCallback() {
806
//                                            @Override
807
//                                            public void onError(Call call, Exception e) {
808
//
809
//                                            }
810
//
811
//                                            @Override
812
//                                            public void onResponse(String response) {
813
//
814
//                                            }
815
//                                        });
816
//
817
//                                ToastUtil.showToast(getApplicationContext(), error_message, Toast.LENGTH_SHORT);
818
//                            }
819
//                        }
820
//                    }
821
//                });
822
//    }
823
//
824
//    private void checkTlD(final String chargingCode) {
825
//        final String url = MainApplication.url + "/zhannew/basic/web/index.php/special/info?pile_id=" + chargingCode + "&user_id=" + MainApplication.userId;
826
//        Log.e("checkTlD_url===", url);
827
//        dialog.show();
828
//        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
829
//            @Override
830
//            public void onError(Call call, Exception e) {
831
//
832
//            }
833
//
834
//            @Override
835
//            public void onResponse(String response) {
836
//                dialog.cancel();
837
//                Log.e("checkTlD_response", response);
838
//                String code = JsonUtils.getKeyResult(response, "code");
839
//                if (code.equals("200")) {
840
//                    String group_id = JsonUtils.getKeyResult(response, "group_id");
841
//                    String eletype = JsonUtils.getKeyResult(response, "eletype");
842
//                    Intent intent = new Intent(getApplicationContext(), TLDLoadingActivity.class);
843
//                    intent.putExtra("eletype", eletype);
844
//                    intent.putExtra("chargingCode", chargingCode);
845
//                    intent.putExtra("group_id", group_id);
846
//                    startActivity(intent);
847
//                    finish();
848
//
849
////                    startTLD(chargingCode,group_id);
850
//                } else {
851
//                    String error_messge = JsonUtils.getKeyResult(response, "error_message");
852
//                    Toast.makeText(getApplicationContext(), error_messge, Toast.LENGTH_SHORT).show();
853
//                    new Handler().postDelayed(new Runnable() {
854
//                        public void run() {
855
//                            if (mCamera != null) {
856
//                                scanRestart();
857
//                            }
858
//                        }
859
//                    }, 1500);
860
//                }
861
//            }
862
//        });
863
//    }
864
//
865
//    private void getChargingPile(final String result) {
866
//        String url = MainApplication.url + "/zhannew/basic/web/index.php/interface/info?flag=1&user_id=" + MainApplication.userId + "&url=" + result;
867
//        Log.e(TAG, "getChargingPile: url=" + url);
868
//        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
869
//            @Override
870
//            public void onError(Call call, Exception e) {
871
//
872
//            }
873
//
874
//            @Override
875
//            public void onResponse(String response) {
876
//                Log.e(TAG, "onResponse: getChargingPile11=" + response);
877
//                String code = JsonUtils.getKeyResult(response, "code");
878
//                if (code.equals("200")) {
879
//                    String group_id = JsonUtils.getKeyResult(response, "group_id");
880
//                    String eletype = JsonUtils.getKeyResult(response, "eletype");
881
//                    String type = JsonUtils.getKeyResult(response, "type");
882
//                    String pile_code = JsonUtils.getKeyResult(response, "pile_code");
883
//                    if (type.equals("jd")) {
884
//                        startHssy(pile_code, group_id, type);
885
//                    } else {
886
//                        Intent intent = new Intent(getApplicationContext(), TLDLoadingActivity.class);
887
//                        intent.putExtra("type", type);
888
//                        intent.putExtra("eletype", eletype);
889
//                        intent.putExtra("chargingCode", pile_code);
890
//                        intent.putExtra("group_id", group_id);
891
//                        startActivity(intent);
892
//                        finish();
893
//                    }
894
//
895
//                } else {
896
//                    String error_message = JsonUtils.getKeyResult(response, "error_message");
897
//                    ToastUtil.showToast(getApplicationContext(), error_message, Toast.LENGTH_SHORT);
898
//                    new Handler().postDelayed(new Runnable() {
899
//                        public void run() {
900
//                            if (mCamera != null) {
901
//                                scanRestart();
902
//                            }
903
//
904
//                        }
905
//                    }, 1500);
906
//                }
907
//            }
908
//        });
909
//    }
910
//
911
//    private void startHssy(String pile_code, String group_id, String type) {
912
//        long appTime1 = System.currentTimeMillis() / 1000;
913
//        long updatetime = appTime1 - MainMapActivity.cha - 3;
914
//        String token = String.valueOf(updatetime);
915
//        String s = "group_id=" + group_id + "&password=" + MainApplication.userPassword + "&pile_code=" + pile_code + "&timer=" + token + "&type=" + type + "&user_id=" + MainApplication.userId + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a";
916
//        String url = MainApplication.url + "/zhannew/basic/web/index.php/interface/start_v2?" +
917
//                "ver=1.0&type=" + type + "&timer=" + token + "&user_id=" + MainApplication.userId + "&pile_code="
918
//                + pile_code + "&group_id=" + group_id + "&password=" + MainApplication.userPassword + "&sign=" + Md5Util.md5(s);
919
//        Log.e(TAG, "startHssy: url=" + url);
920
//        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
921
//            @Override
922
//            public void onError(Call call, Exception e) {
923
//
924
//            }
925
//
926
//            @Override
927
//            public void onResponse(String response) {
928
//                Log.e(TAG, "onResponse: startHssy=" + response);
929
//                String code = JsonUtils.getKeyResult(response, "code");
930
//                if (code.equals("200")) {
931
//                    MainApplication.isAppStart = true;
932
//                    ProfileManager.getInstance().setAppStart(getApplicationContext(), MainApplication.isAppStart);
933
//                    startActivity(new Intent(getApplicationContext(), ChargingStatusActivity.class));
934
//                    finish();
935
//                } else {
936
//                    String error_message = JsonUtils.getKeyResult(response, "error_message");
937
//                    ToastUtil.showToast(getApplicationContext(), error_message, Toast.LENGTH_SHORT);
938
//                    new Handler().postDelayed(new Runnable() {
939
//                        public void run() {
940
//                            if (mCamera != null) {
941
//                                scanRestart();
942
//                            }
943
//                        }
944
//                    }, 1500);
945
//                }
946
//            }
947
//        });
948
//    }
949
//
950
//
951
//}

+ 8 - 25
app/src/main/java/com/electric/chargingpile/fragment/SvVideoShowView.java

@ -5,6 +5,7 @@ import android.content.Intent;
5 5
import android.support.v4.view.PagerAdapter;
6 6
import android.support.v4.view.ViewPager;
7 7
import android.text.TextUtils;
8
import android.util.Log;
8 9
import android.view.LayoutInflater;
9 10
import android.view.MotionEvent;
10 11
import android.view.View;
@ -172,33 +173,15 @@ public class SvVideoShowView implements View.OnClickListener {
172 173
        } else {
173 174
            // sv_show_like_img  not like
174 175
        }
175
        sv_show_tvcon.post(
176
                new Runnable() {
177
                    @Override
178
                    public void run() {
179
                        int lineCount = sv_show_tvcon.getLineCount();
180
                        if (lineCount > 3) {
181
                            isMaxline = true;
182
                            sv_show_tvcon.setMaxLines(3);
183
                            sv_show_tvcon.setEllipsize(TextUtils.TruncateAt.END);
184
                            sv_show_tvcon_more.setVisibility(View.VISIBLE);
185
                        } else {
186
                            if (!isMaxline) {
187
                                sv_show_tvcon.setMaxLines(lineCount);
188
                                sv_show_tvcon_more.setVisibility(View.GONE);
189
                            }
190
                        }
191
                    }
192
                }
193
        );
194
//        if (sv_show_tvcon.getLineCount() > 3) {
195
//            sv_show_tvcon_more.setVisibility(View.VISIBLE);
196
//        } else {
197
//            sv_show_tvcon_more.setVisibility(View.GONE);
198
//        }
176
        int length = sv_show_tvcon.length();
177
        Log.e("length", "setData: length: "+length);
178
        if (sv_show_tvcon.getLineCount() >= 3 && sv_show_tvcon.getText().length()> 100) {
179
            sv_show_tvcon_more.setVisibility(View.VISIBLE);
180
        } else {
181
            sv_show_tvcon_more.setVisibility(View.GONE);
182
        }
199 183
    }
200 184
201
    boolean isMaxline = false;
202 185
203 186
    private void likeRequest(final int likeFlag) {
204 187
        String url = MainApplication.urlNew + "/article/like";

+ 3 - 2
app/src/main/java/com/electric/chargingpile/view/VideoPubilshDialog.java

@ -52,8 +52,9 @@ public class VideoPubilshDialog extends Dialog implements View.OnClickListener {
52 52
53 53
54 54
        videoPublishTopicCon.setText(talkRecommendBean.topicName);
55
        videoPublishCon.setText(talkRecommendBean.title);
56
55
        if(!TextUtils.isEmpty(talkRecommendBean.title)) {
56
            videoPublishCon.setText(talkRecommendBean.title);
57
        }
57 58
        if (TextUtils.isEmpty(talkRecommendBean.headImgUrl)) {
58 59
            Picasso.with(context)
59 60
                    .load(R.drawable.icon_face2_0)

+ 2 - 2
app/src/main/res/layout/sv_video_publish_info.xml

@ -22,7 +22,6 @@
22 22
        android:layout_marginStart="15dp"
23 23
        android:layout_marginTop="15dp"
24 24
        android:layout_marginEnd="40dp"
25
        android:layout_marginBottom="10dp"
26 25
        android:background="@drawable/bg_topic"
27 26
        android:gravity="center_vertical"
28 27
        android:minHeight="30dp">
@ -50,13 +49,14 @@
50 49
        android:layout_height="20dp"
51 50
        android:layout_below="@+id/video_publish_topic"
52 51
        android:layout_marginStart="15dp"
52
        android:layout_marginTop="10dp"
53 53
        android:gravity="center_vertical"
54 54
        android:orientation="horizontal">
55 55
56 56
        <ImageView
57 57
            android:id="@+id/video_publish_user_avatar"
58 58
            android:layout_width="20dp"
59
            android:layout_height="20dp"  />
59
            android:layout_height="20dp" />
60 60
61 61
        <TextView
62 62
            android:id="@+id/video_publish_user_name"

+ 2 - 0
app/src/main/res/layout/view_show_bottom.xml

@ -123,6 +123,8 @@
123 123
        android:layout_marginRight="39dp"
124 124
        android:layout_marginBottom="23dp"
125 125
        android:textColor="#E2E2E2"
126
        android:ellipsize="end"
127
        android:maxLines="3"
126 128
        android:textSize="14sp" />
127 129
128 130
    <ImageView