充电桩app代码

ZhanCommentActivity.java 50KB

    package com.electric.chargingpile.activity; import android.Manifest; import android.app.Activity; import android.app.ProgressDialog; import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.provider.MediaStore; import android.text.Editable; import android.text.TextWatcher; import android.util.Base64; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.GridView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import com.blankj.utilcode.util.CacheUtils; import com.electric.chargingpile.R; import com.electric.chargingpile.application.MainApplication; import com.electric.chargingpile.data.CommentsBean; import com.electric.chargingpile.data.MyOtto; import com.electric.chargingpile.data.RObject; import com.electric.chargingpile.util.BarColorUtil; import com.electric.chargingpile.util.Bimp; import com.electric.chargingpile.util.DES3; import com.electric.chargingpile.util.FileUtils; import com.electric.chargingpile.util.ImageItem; import com.electric.chargingpile.util.ImageUtils; import com.electric.chargingpile.util.JsonUtils; import com.electric.chargingpile.util.LoadingDialog; import com.electric.chargingpile.util.Md5Util; import com.electric.chargingpile.util.PublicWayONE; import com.electric.chargingpile.util.Res; import com.electric.chargingpile.util.ScreenUtils; import com.electric.chargingpile.util.StatusConstants; import com.electric.chargingpile.util.ToastUtil; import com.electric.chargingpile.util.UploadUtil; import com.electric.chargingpile.view.REditText; import com.electric.chargingpile.view.RatingBarView; import com.zhihu.matisse.Matisse; import com.zhihu.matisse.MimeType; import com.zhihu.matisse.engine.impl.GlideEngine; import com.zhihu.matisse.internal.entity.CaptureStrategy; import com.zhy.http.okhttp.OkHttpUtils; import com.zhy.http.okhttp.callback.StringCallback; import com.zhy.view.flowlayout.FlowLayout; import com.zhy.view.flowlayout.TagAdapter; import com.zhy.view.flowlayout.TagFlowLayout; import org.json.JSONException; import org.json.JSONObject; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import io.reactivex.Observable; import io.reactivex.ObservableEmitter; import io.reactivex.ObservableOnSubscribe; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import okhttp3.Call; import pub.devrel.easypermissions.AfterPermissionGranted; import pub.devrel.easypermissions.EasyPermissions; public class ZhanCommentActivity extends Activity implements View.OnClickListener, EasyPermissions.PermissionCallbacks { private static final String TAG = "ZhanCommentActivity"; private static final int PIC_NUM = 1; private ProgressDialog insertDialog; public static CommentsBean commentsBean; private IntentFilter intentFilter; private NetworkChangeReceiver networkChangeReceiver; public static int commentType = 1; Bitmap bm = null; String zhan_id; public static REditText et_pinglun; private TextView tv_make_sure, tv_huodong; private String star_level = ""; private String show_txt = ""; private RelativeLayout rl_huodong, rl_point; private RatingBarView ratingBarView; private ImageView iv_back; private LoadingDialog dialog; private String[] stringArr; private String[] mValss = new String[]{MainApplication.huodonglabel}; private TagFlowLayout mFlowLayout, mFlowLayoutTwo; List<String> list; private String select_s = ""; private String select_ss = ""; private TextView tv_grade, tv_point; private File tempFile; private static String PHOTO_FILE_NAME = ""; private static final String PHOTO_FILE_PATH = getPath(Environment.getExternalStorageDirectory() + "/" + "cdz"); public static Bitmap bimap; private PopupWindow pop = null; private LinearLayout ll_popup; private GridView noScrollgridview; private GridAdapter adapter; private static final int PHOTO_REQUEST_CAMERA = 1; private static final int PHOTO_REQUEST_GALLERY = 2; private static final int PHOTO_REQUEST_CUT = 3; public static android.view.animation.Animation animation; public static TextView textView; public static RelativeLayout relativeLayout; public static ImageView point; private InputMethodManager imm = null; private static final int RC_ALBUM_PERM = 123; public static final int REQUEST_CODE_CHOOSE = 336; Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 2: try { JSONObject jsonObject = new JSONObject(msg.obj.toString()); Log.e("111111", msg.obj.toString()); String code = jsonObject.getString("code"); if (code.equals("200")) { Log.e("200==", "图片成功"); String fileUrl = jsonObject.getString("fileUrl"); String thumUrl = jsonObject.getString("thumUrl"); try { addComment(fileUrl, thumUrl); } catch (Exception e) { e.printStackTrace(); } } else { Toast.makeText(ZhanCommentActivity.this, "评论失败", Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); } break; case StatusConstants.REQUEST_WHAT_SUCCESS: break; } super.handleMessage(msg); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zhan_comment); dialog = new LoadingDialog(this); dialog.setCanceledOnTouchOutside(false); intentFilter = new IntentFilter(); intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE"); networkChangeReceiver = new NetworkChangeReceiver(); registerReceiver(networkChangeReceiver, intentFilter); long appTime1 = System.currentTimeMillis() / 1000; PHOTO_FILE_NAME = "android" + appTime1 + ".jpg"; tempFile = getFile(PHOTO_FILE_PATH + "/" + PHOTO_FILE_NAME); MyOtto.getInstance().unregister(this); Res.init(this); bimap = BitmapFactory.decodeResource( getResources(), R.drawable.addpic65); PublicWayONE.activityList.add(this); if (null == imm) { imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); } BarColorUtil.initStatusBarColor(ZhanCommentActivity.this); initViews(); getDatas(); Init(); } private void initViews() { insertDialog = new ProgressDialog(this); insertDialog.setMessage("正在插入图片..."); insertDialog.setCanceledOnTouchOutside(false); rl_point = (RelativeLayout) findViewById(R.id.rl_point); tv_point = (TextView) findViewById(R.id.tv_point); animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.nn); relativeLayout = (RelativeLayout) findViewById(R.id.activity_zhan_comment); relativeLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); rl_huodong = (RelativeLayout) findViewById(R.id.rl_huodong); tv_grade = (TextView) findViewById(R.id.tv_grade); tv_huodong = (TextView) findViewById(R.id.tv_huodong); if (MainApplication.level_one.equals("")) { String levellabel = getResources().getString(R.string.app_level_label); CacheUtils.getInstance().put("levellabel", levellabel); MainApplication.level_one = JsonUtils.getKeyResult(levellabel, "1"); MainApplication.level_two = JsonUtils.getKeyResult(levellabel, "2"); MainApplication.level_three = JsonUtils.getKeyResult(levellabel, "3"); MainApplication.level_four = JsonUtils.getKeyResult(levellabel, "4"); MainApplication.level_five = JsonUtils.getKeyResult(levellabel, "5"); } if (MainApplication.huodonglabel.equals("")) { tv_huodong.setVisibility(View.GONE); } et_pinglun = (REditText) findViewById(R.id.et_pinglun); et_pinglun.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (et_pinglun.getText().toString().equals("") && NewZhanDetailsActivity.replaceBlank(et_pinglun.getText().toString()).equals("")) { if (!star_level.equals("") && !select_s.equals("")) { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } else { tv_make_sure.setTextColor(getResources().getColor(R.color.huise)); tv_make_sure.setEnabled(false); } } else { Log.e("edit===", et_pinglun.getText().toString()); if (et_pinglun.getText().toString().equals("#" + MainApplication.huodonglabel + "# ")) { if (!star_level.equals("") && !select_s.equals("")) { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } else { tv_make_sure.setTextColor(getResources().getColor(R.color.huise)); tv_make_sure.setEnabled(false); } } else { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } } if (!et_pinglun.getText().toString().contains("#" + MainApplication.huodonglabel + "#")) { final LayoutInflater mInflater = LayoutInflater.from(getApplicationContext()); mFlowLayoutTwo.setAdapter(new TagAdapter<String>(mValss) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv, mFlowLayoutTwo, false); tv.setText(s); return tv; } }); } } }); tv_make_sure = (TextView) findViewById(R.id.tv_make_sure); tv_make_sure.setOnClickListener(this); tv_make_sure.setTextColor(getResources().getColor(R.color.huise)); tv_make_sure.setEnabled(false); ratingBarView = (RatingBarView) findViewById(R.id.custom_ratingbar); ratingBarView.setOnRatingListener(new RatingBarView.OnRatingListener() { @Override public void onRating(Object bindObject, int RatingScore) { star_level = String.valueOf(RatingScore); mFlowLayout.setVisibility(View.VISIBLE); select_s = ""; if (et_pinglun.getText().toString().equals("") && NewZhanDetailsActivity.replaceBlank(et_pinglun.getText().toString()).equals("")) { if (!star_level.equals("") && !select_s.equals("")) { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } else { tv_make_sure.setTextColor(getResources().getColor(R.color.huise)); tv_make_sure.setEnabled(false); } } else { if (et_pinglun.getText().toString().equals("#" + MainApplication.huodonglabel + "# ")) { if (!star_level.equals("") && !select_s.equals("")) { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } else { tv_make_sure.setTextColor(getResources().getColor(R.color.huise)); tv_make_sure.setEnabled(false); } } else { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } } switch (RatingScore) { case 1: if (!MainApplication.level_one.equals("")) { getLevelData(MainApplication.level_one); } tv_grade.setText(RatingScore + ".0"); break; case 2: if (!MainApplication.level_two.equals("")) { getLevelData(MainApplication.level_two); } tv_grade.setText(RatingScore + ".0"); break; case 3: if (!MainApplication.level_three.equals("")) { getLevelData(MainApplication.level_three); } tv_grade.setText(RatingScore + ".0"); break; case 4: if (!MainApplication.level_four.equals("")) { getLevelData(MainApplication.level_four); } tv_grade.setText(RatingScore + ".0"); break; case 5: if (!MainApplication.level_five.equals("")) { getLevelData(MainApplication.level_five); } tv_grade.setText(RatingScore + ".0"); break; } } }); iv_back = (ImageView) findViewById(R.id.iv_back); iv_back.setOnClickListener(this); final LayoutInflater mInflater = LayoutInflater.from(this); mFlowLayout = (TagFlowLayout) findViewById(R.id.id_flowlayout); mFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener() { @Override public void onSelected(Set<Integer> selectPosSet) { } }); mFlowLayoutTwo = (TagFlowLayout) findViewById(R.id.id_flowlayout_activity); if (MainApplication.huodonglabel.equals("")) { mFlowLayoutTwo.setVisibility(View.GONE); rl_huodong.setVisibility(View.GONE); } else { mFlowLayoutTwo.setVisibility(View.VISIBLE); rl_huodong.setVisibility(View.VISIBLE); } mFlowLayoutTwo.setAdapter(new TagAdapter<String>(mValss) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv_comment1, mFlowLayoutTwo, false); tv.setText(s); return tv; } }); mFlowLayoutTwo.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() { @Override public boolean onTagClick(View view, int position, FlowLayout parent) { if (select_ss.equals(MainApplication.huodonglabel)) { select_ss = ""; String s = et_pinglun.getText().toString(); String del_s = s.replace("#" + MainApplication.huodonglabel + "# ", ""); et_pinglun.setText(del_s); } else { select_ss = MainApplication.huodonglabel; setTopic(); } if (et_pinglun.getText().toString().equals("") && NewZhanDetailsActivity.replaceBlank(et_pinglun.getText().toString()).equals("")) { if (!star_level.equals("") && !select_s.equals("")) { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } else { tv_make_sure.setTextColor(getResources().getColor(R.color.huise)); tv_make_sure.setEnabled(false); } } else { if (et_pinglun.getText().toString().equals("#" + MainApplication.huodonglabel + "# ")) { // tv_make_sure.setBackgroundResource(R.color.huise); // tv_make_sure.setEnabled(false); if (!star_level.equals("") && !select_s.equals("")) { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } else { tv_make_sure.setTextColor(getResources().getColor(R.color.huise)); tv_make_sure.setEnabled(false); } } else { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } } // Toast.makeText(getApplicationContext(), mVals[position], Toast.LENGTH_SHORT).show(); return true; } }); mFlowLayoutTwo.setOnSelectListener(new TagFlowLayout.OnSelectListener() { @Override public void onSelected(Set<Integer> selectPosSet) { // Toast.makeText(getApplicationContext(), "choose:" + selectPosSet.toString(), Toast.LENGTH_SHORT).show(); } }); } public void Init() { pop = new PopupWindow(ZhanCommentActivity.this); View view = getLayoutInflater().inflate(R.layout.item_popupwindows, null); ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup); pop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); pop.setBackgroundDrawable(new BitmapDrawable()); pop.setFocusable(true); pop.setOutsideTouchable(true); pop.setContentView(view); final RelativeLayout parent = (RelativeLayout) view.findViewById(R.id.parent); Button bt1 = (Button) view.findViewById(R.id.item_popupwindows_camera); Button bt2 = (Button) view.findViewById(R.id.item_popupwindows_Photo); Button bt3 = (Button) view.findViewById(R.id.item_popupwindows_cancel); parent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub pop.dismiss(); ll_popup.clearAnimation(); } }); bt1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { photo(); pop.dismiss(); ll_popup.clearAnimation(); } }); bt2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ZhanCommentActivity.this, AlbumActivityComment.class); startActivity(intent); overridePendingTransition(R.anim.activity_translate_in, R.anim.activity_translate_out); pop.dismiss(); ll_popup.clearAnimation(); } }); bt3.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { pop.dismiss(); ll_popup.clearAnimation(); } }); noScrollgridview = (GridView) findViewById(R.id.noScrollgridview); noScrollgridview.setSelector(new ColorDrawable(Color.TRANSPARENT)); adapter = new GridAdapter(this); adapter.update(); noScrollgridview.setAdapter(adapter); noScrollgridview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { imm.hideSoftInputFromWindow(arg1.getWindowToken(), 0); if (arg2 == Bimp.tempSelectBitmap.size()) { permissionTask(); } else { Intent intent = new Intent(ZhanCommentActivity.this, GalleryActivityComment.class); intent.putExtra("position", "1"); intent.putExtra("ID", arg2); startActivity(intent); } } }); } /** * 调用图库选择 */ private void callGallery() { Matisse.from(ZhanCommentActivity.this) .choose(MimeType.of(MimeType.JPEG, MimeType.PNG, MimeType.GIF)) .showSingleMediaType(true) .countable(true) .maxSelectable(PIC_NUM - Bimp.tempSelectBitmap.size()) .capture(true) .captureStrategy(new CaptureStrategy(true, "com.electric.chargingpile.provider")) .imageEngine(new GlideEngine()) .forResult(REQUEST_CODE_CHOOSE); } @Override protected void onActivityResult(int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (data != null) { if (requestCode == 1) { //处理调用系统图库 } else if (requestCode == REQUEST_CODE_CHOOSE) { //异步方式插入图片 insertImagesSync(data); } } } } /** * 异步方式插入图片 * * @param data */ private void insertImagesSync(final Intent data) { insertDialog.show(); Observable.create(new ObservableOnSubscribe<String>() { @Override public void subscribe(ObservableEmitter<String> subscriber) throws Exception { try { List<Uri> uriList = Matisse.obtainResult(data); for (Uri uri : uriList) { Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); File file = FileUtils.from(ZhanCommentActivity.this, uri); bitmap = FileUtils.rotateIfRequired(file, bitmap); bitmap = imageZoom(bitmap); ImageItem takePhoto = new ImageItem(); takePhoto.setBitmap(bitmap); Bimp.tempSelectBitmap.add(takePhoto); subscriber.onNext(""); } subscriber.onComplete(); } catch (Exception e) { e.printStackTrace(); subscriber.onError(e); } } }) .subscribeOn(Schedulers.io())//生产事件在io .observeOn(AndroidSchedulers.mainThread())//消费事件在UI线程 .subscribe(new Observer<String>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(String s) { } @Override public void onError(Throwable e) { insertDialog.dismiss(); Log.e(TAG, "onError: " + "图片插入失败:" + e.getMessage()); ToastUtil.showToast(getApplicationContext(), "图片插入失败", Toast.LENGTH_SHORT); } @Override public void onComplete() { Log.e(TAG, "onCompleted: -------------"); insertDialog.dismiss(); adapter.update(); } }); } public void shite(String s) throws Exception { Map<String, String> par = new HashMap<String, String>(); String file; long appTime1 = System.currentTimeMillis() / 1000; Log.i("appTime(long)---", appTime1 + ""); long updatetime = appTime1 - MainMapActivity.cha - 1; Log.i("updatetime(long)---", updatetime + ""); Log.i("cha---", MainMapActivity.cha + ""); for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) { try { bm = imageZoom(Bimp.tempSelectBitmap.get(i).getBitmap()); file = bitmapToBase64(bm); par.put("file", file); Log.i("file--------" + (i + 1), file); par.put("filename", "androidapp.jpg"); } catch (Exception e) { e.printStackTrace(); } } try { String u = UploadUtil.post(MainApplication.url + "/zhannew/basic/web/index.php/fileupload/upload", par, null); System.err.println(u); // submit(u); Message msg = new Message(); msg.obj = u; msg.what = 2; handler.sendMessage(msg); } catch (IOException e) { e.printStackTrace(); } } private void setTopic() { MyTopic topic = new MyTopic(); int id = (int) (Math.random() * 100); topic.setId("No." + id); topic.setObjectText(MainApplication.huodonglabel);// 必须设置 switch (2) { case 0: topic.setObjectRule("*");// 开发者设置,默认# break; case 1: topic.setObjectRule("$");// 开发者设置,默认# break; case 2: topic.setObjectRule("#");// 开发者设置,默认# break; } et_pinglun.setObject(topic); } private void getLevelData(final String level_data) { final LayoutInflater mInflater = LayoutInflater.from(this); stringArr = level_data.split(","); mFlowLayout.setAdapter(new TagAdapter<String>(stringArr) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv_comment, mFlowLayout, false); tv.setText(s); return tv; } }); mFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() { @Override public boolean onTagClick(View view, int position, FlowLayout parent) { if (select_s.contains(stringArr[position])) { String s = stringArr[position] + ","; select_s = select_s.replaceAll(s, ""); } else { select_s += stringArr[position] + ","; } Log.e("select===", select_s); if (et_pinglun.getText().toString().equals("") && NewZhanDetailsActivity.replaceBlank(et_pinglun.getText().toString()).equals("")) { if (!star_level.equals("") && !select_s.equals("")) { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } else { tv_make_sure.setTextColor(getResources().getColor(R.color.huise)); tv_make_sure.setEnabled(false); } } else { if (et_pinglun.getText().toString().equals("#" + MainApplication.huodonglabel + "# ")) { if (!star_level.equals("") && !select_s.equals("")) { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } else { tv_make_sure.setTextColor(getResources().getColor(R.color.huise)); tv_make_sure.setEnabled(false); } } else { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } } return true; } }); } private void getDatas() { zhan_id = getIntent().getStringExtra("zhan_id"); show_txt = getIntent().getStringExtra("show_txt"); et_pinglun.setHint(show_txt); } private void addComment(String fileUrl, String thumUrl) throws Exception { long appTime1 = System.currentTimeMillis() / 1000; long updatetime = appTime1 - MainMapActivity.cha - 2; String token = String.valueOf(updatetime); String childCommentUrl = ""; if (commentsBean != null) { childCommentUrl = "&parentid=" + commentsBean.getId() + "&puserid=" + commentsBean.getUserid(); } String url = ""; if (commentType == 1) { url = MainApplication.url + "/zhannew/basic/web/index.php/tpappcomments/add?userid=" + MainApplication.userId + "&zhanid=" + zhan_id + "&comment=" + URLEncoder.encode(et_pinglun.getText().toString()) + "&tel=" + MainApplication.userPhone + "&token=" + URLEncoder.encode(DES3.encode(token)) + "&fileUrl=" + fileUrl + "&thumUrl=" + thumUrl; Log.d("url!!!", url); } else if (commentType == 2) { url = MainApplication.url + "/zhannew/basic/web/index.php/tpappcomments/add?userid=" + MainApplication.userId + "&zhanid=" + zhan_id + "&comment=" + URLEncoder.encode(et_pinglun.getText().toString()) + "&tel=" + MainApplication.userPhone + "&token=" + URLEncoder.encode(DES3.encode(token)) + childCommentUrl; // url = "http://59.110.68.162/zhannew/basic/web/index.php/tpappcomments/add?userid=" + MainApplication.userId + "&zhanid=" + zhan_id + "&comment=" + URLEncoder.encode(et_pinglun.getText().toString()) + "&tel=" + MainApplication.userPhone + "&token=" + URLEncoder.encode(DES3.encode(token)) + childCommentUrl; Log.d("url###", url); } Log.d("url++++", url); OkHttpUtils.get() .url(url) .build() .execute(new StringCallback() { @Override public void onError(Call call, Exception e) { } @Override public void onResponse(String response) { Log.e("comment", response); String rtnCode = JsonUtils.getKeyResult(response, "rtnCode"); String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg"); dialog.cancel(); if (rtnCode.equals("01")) { final String data = JsonUtils.getKeyResult(response, "data"); String plusScore = JsonUtils.getKeyResult(response, "plusScore"); submitPF(data); if (!plusScore.equals("")) { tv_point.setText(plusScore); rl_point.setVisibility(View.VISIBLE); rl_point.startAnimation(animation); new Handler().postDelayed(new Runnable() { public void run() { rl_point.setVisibility(View.GONE); } }, 1000); new Handler().postDelayed(new Runnable() { public void run() { finish(); } }, 1500); } else { ToastUtil.showToast(getApplicationContext(), "评论成功", Toast.LENGTH_SHORT); new Handler().postDelayed(new Runnable() { public void run() { finish(); } }, 1500); } NewZhanDetailsActivity.reFreshUi(); } else { ToastUtil.showToast(getApplicationContext(), rtnMsg, Toast.LENGTH_SHORT); } } }); } private void submitPF(String data) { long appTime1 = System.currentTimeMillis() / 1000; long updatetime = appTime1 - MainMapActivity.cha - 3; String token = String.valueOf(updatetime); if (!star_level.equals("")) { if (Integer.parseInt(star_level) > 5) { star_level = String.valueOf(5); } } if (!select_s.equals("")) { select_s = select_s.substring(0, select_s.length() - 1); } String url = MainApplication.url + "/zhannew/basic/web/index.php/zhanstar/staradd" + "?commit_id=" + data + "&star_level=" + star_level + "&supplier=星星充电&tag=" + select_s + "&timer=" + token + "&user_id=" + MainApplication.userId + "&ver=1.0&zhan_id=" + zhan_id + "&sign=" + Md5Util.md5("commit_id=" + data + "&star_level=" + star_level + "&supplier=星星充电&tag=" + select_s + "&timer=" + token + "&user_id=" + MainApplication.userId + "&zhan_id=" + zhan_id + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a"); Log.e("PF_url", url); OkHttpUtils.get() .url(url) .build() .execute(new StringCallback() { @Override public void onError(Call call, Exception e) { } @Override public void onResponse(String response) { Log.e("PF=====", response); } }); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.tv_make_sure: if (imm.isActive()) { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); //强制隐藏键盘 } if (MainApplication.isLogin()) { try { if (Bimp.tempSelectBitmap.size() > 0) { dialog.show(); new Thread(new Runnable() { @Override public void run() { try { shite(""); } catch (Exception e) { e.printStackTrace(); } } }).start(); } else { if (containsEmoji(et_pinglun.getText().toString())) { ToastUtil.showToast(MainApplication.context, "不支持输入表情", Toast.LENGTH_SHORT); } else { dialog.show(); addComment("", ""); } } } catch (Exception e) { e.printStackTrace(); } } else { Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show(); startActivity(new Intent(getApplication(), LoginActivity.class)); } break; case R.id.iv_back: finish(); break; } } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); } @Override public void onPermissionsGranted(int requestCode, List<String> perms) { } @Override public void onPermissionsDenied(int requestCode, List<String> perms) { } @AfterPermissionGranted(RC_ALBUM_PERM) public void permissionTask() { if (isPermissionOK()) { callGallery(); } else { // Ask for one permission EasyPermissions.requestPermissions( this, "充电桩想要获取您的图片读取权限,是否允许?", RC_ALBUM_PERM, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA); } } private boolean isPermissionOK() { return EasyPermissions.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA ); } public class MyTopic extends RObject { private String id; // 其他属性... public String getId() { return id; } public void setId(String id) { this.id = id; } } private File getFile(String path) { File f = new File(path); if (!f.exists()) { try { f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } return f; } private static String getPath(String path) { File f = new File(path); if (!f.exists()) { f.mkdirs(); } return f.getAbsolutePath(); } public class GridAdapter extends BaseAdapter { private LayoutInflater inflater; private int selectedPosition = -1; private boolean shape; public boolean isShape() { return shape; } public void setShape(boolean shape) { this.shape = shape; } public GridAdapter(Context context) { inflater = LayoutInflater.from(context); } public void update() { loading(); } public int getCount() { if (Bimp.tempSelectBitmap.size() == 1) { return 1; } return (Bimp.tempSelectBitmap.size() + 1); } public Object getItem(int arg0) { return null; } public long getItemId(int arg0) { return 0; } public void setSelectedPosition(int position) { selectedPosition = position; } public int getSelectedPosition() { return selectedPosition; } public View getView(int position, View convertView, ViewGroup parent) { GridAdapter.ViewHolder holder = null; if (convertView == null) { convertView = inflater.inflate(R.layout.item_published_grida, parent, false); holder = new GridAdapter.ViewHolder(); holder.image = (ImageView) convertView .findViewById(R.id.item_grida_image); convertView.setTag(holder); } else { holder = (GridAdapter.ViewHolder) convertView.getTag(); } if (position == Bimp.tempSelectBitmap.size()) { holder.image.setImageBitmap(BitmapFactory.decodeResource( getResources(), R.drawable.icon_comment_upload)); if (position == 1) { holder.image.setVisibility(View.GONE); } } else { holder.image.setImageBitmap(Bimp.tempSelectBitmap.get(position).getBitmap()); } return convertView; } public class ViewHolder { public ImageView image; } Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 1: adapter.notifyDataSetChanged(); break; } super.handleMessage(msg); } }; public void loading() { new Thread(new Runnable() { public void run() { while (true) { if (Bimp.max == Bimp.tempSelectBitmap.size()) { Message message = new Message(); message.what = 1; handler.sendMessage(message); break; } else { Bimp.max += 1; Message message = new Message(); message.what = 1; handler.sendMessage(message); } } } }).start(); } } public void photo() { if (hasSdcard()) { int currentapiVersion = Build.VERSION.SDK_INT; Log.e("currentapiVersion", "currentapiVersion====>" + currentapiVersion); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//��������� intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); startActivityForResult(intent, PHOTO_REQUEST_CAMERA); } } private boolean hasSdcard() { if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { return true; } else { return false; } } private void crop(Uri uri, Uri cutImgUri) { // �ü�ͼƬ��ͼ Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(getImageContentUri(this, tempFile), "image/*"); intent.putExtra("crop", "true"); // �ü���ı�����1��1 // intent.putExtra("aspectX", 16); // intent.putExtra("aspectY", 9); // // �ü������ͼƬ�ijߴ��С // intent.putExtra("outputX", 900); // intent.putExtra("outputY", 540); // intent.putExtra("scale", false); // ͼƬ��ʽ intent.putExtra("outputFormat", "JPEG"); intent.putExtra("noFaceDetection", true);// ȡ������ʶ�� intent.putExtra("return-data", false);// true:������uri��false������uri intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));//д���ȡ��ͼƬ startActivityForResult(intent, PHOTO_REQUEST_CUT); } public static Uri getImageContentUri(Context context, File imageFile) { String filePath = imageFile.getAbsolutePath(); Cursor cursor = context.getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Images.Media._ID}, MediaStore.Images.Media.DATA + "=? ", new String[]{filePath}, null); if (cursor != null && cursor.moveToFirst()) { int id = cursor.getInt(cursor .getColumnIndex(MediaStore.MediaColumns._ID)); Uri baseUri = Uri.parse("content://media/external/images/media"); return Uri.withAppendedPath(baseUri, "" + id); } else { if (imageFile.exists()) { ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.DATA, filePath); return context.getContentResolver().insert( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } else { return null; } } } public Bitmap decodeUriAsBitmap(Uri uri) { Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri)); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } return bitmap; } protected void onRestart() { adapter.update(); super.onRestart(); } @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(networkChangeReceiver); MyOtto.getInstance().unregister(this); Bimp.tempSelectBitmap.clear(); Bimp.max = 0; } private String bitmapToBase64(Bitmap bitmap) { String result = null; ByteArrayOutputStream baos = null; try { if (bitmap != null) { baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); baos.flush(); baos.close(); byte[] bitmapBytes = baos.toByteArray(); result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (baos != null) { baos.flush(); baos.close(); } } catch (IOException e) { e.printStackTrace(); } } return result; } private Bitmap imageZoom(Bitmap bm) { // 图片允许最大空间 单位:KB double maxSize = 200.00; // 将bitmap放至数组中,意在bitmap的大小(与实际读取的原文件要大) ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); // 将字节换成KB double mid = b.length / 1024; // 判断bitmap占用空间是否大于允许最大空间 如果大于则压缩 小于则不压缩 if (mid > maxSize) { // 获取bitmap大小 是允许最大大小的多少倍 double i = mid / maxSize; // 开始压缩 此处用到平方根 将宽带和高度压缩掉对应的平方根倍 // (1.保持刻度和高度和原bitmap比率一致,压缩后也达到了最大大小占用空间的大小) bm = zoomImage(bm, bm.getWidth() / Math.sqrt(i), bm.getHeight() / Math.sqrt(i)); } return bm; } public Bitmap zoomImage(Bitmap bgimage, double newWidth, double newHeight) { // 获取这个图片的宽和高 float width = bgimage.getWidth(); float height = bgimage.getHeight(); // 创建操作图片用的matrix对象 Matrix matrix = new Matrix(); // 计算宽高缩放率 float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // 缩放图片动作 matrix.postScale(scaleWidth, scaleHeight); Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width, (int) height, matrix, true); // iv_2.setImageBitmap(bitmap); // tv_2.setText(bitmap.getRowBytes() * bitmap.getHeight() + ""); return bitmap; } class NetworkChangeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (Bimp.tempSelectBitmap.size() > 0) { new Thread(new Runnable() { @Override public void run() { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } }).start(); } } } @Override protected void onResume() { super.onResume(); if (Bimp.tempSelectBitmap.size() > 0) { tv_make_sure.setTextColor(getResources().getColor(R.color.lvse)); tv_make_sure.setEnabled(true); } } /** * 检测是否有emoji表情 * * @param source * @return */ public static boolean containsEmoji(String source) { int len = source.length(); for (int i = 0; i < len; i++) { char codePoint = source.charAt(i); if (!isEmojiCharacter(codePoint)) { //如果不能匹配,则该字符是Emoji表情 return true; } } return false; } /** * 判断是否是Emoji * * @param codePoint 比较的单个字符 * @return */ private static boolean isEmojiCharacter(char codePoint) { return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF)); } }