1124 lines
34 KiB
Java
1124 lines
34 KiB
Java
package cn.shangyu.gdxzExpert.activity;
|
|
|
|
import android.Manifest;
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Environment;
|
|
import android.os.Handler;
|
|
import android.os.IBinder;
|
|
import android.os.Message;
|
|
import android.provider.MediaStore;
|
|
import android.text.TextUtils;
|
|
import android.view.Gravity;
|
|
import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.view.View.OnClickListener;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup.LayoutParams;
|
|
import android.view.inputmethod.InputMethodManager;
|
|
import android.widget.AdapterView;
|
|
import android.widget.AdapterView.OnItemClickListener;
|
|
import android.widget.BaseAdapter;
|
|
import android.widget.Button;
|
|
import android.widget.CheckBox;
|
|
import android.widget.CompoundButton;
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
import android.widget.EditText;
|
|
import android.widget.GridView;
|
|
import android.widget.ImageView;
|
|
import android.widget.PopupWindow;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.core.content.FileProvider;
|
|
import androidx.viewpager.widget.PagerAdapter;
|
|
import androidx.viewpager.widget.ViewPager;
|
|
|
|
import com.github.dfqin.grantor.PermissionListener;
|
|
import com.github.dfqin.grantor.PermissionsUtil;
|
|
import com.gyf.immersionbar.ImmersionBar;
|
|
import com.hjq.window.EasyWindow;
|
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import cn.shangyu.gdxzExpert.R;
|
|
import cn.shangyu.gdxzExpert.base.BaseActivity;
|
|
import cn.shangyu.gdxzExpert.bean.AddBitmaps;
|
|
import cn.shangyu.gdxzExpert.bean.PhotoItem;
|
|
import cn.shangyu.gdxzExpert.http.HttpHelper;
|
|
import cn.shangyu.gdxzExpert.http.HttpHelper.HttpResult;
|
|
import cn.shangyu.gdxzExpert.http.OnCallBackFromNet;
|
|
import cn.shangyu.gdxzExpert.ui.CustomProgressDialog;
|
|
import cn.shangyu.gdxzExpert.utils.Base64Util;
|
|
import cn.shangyu.gdxzExpert.utils.Constant;
|
|
import cn.shangyu.gdxzExpert.utils.SharePrefUtil;
|
|
import cn.shangyu.gdxzExpert.utils.StringUtil;
|
|
import cn.shangyu.gdxzExpert.utils.ToastUtil;
|
|
import cn.shangyu.gdxzExpert.utils.UIUtils;
|
|
import cn.shangyu.gdxzExpert.utils.Url;
|
|
import cn.shangyu.gdxzExpert.view.PhotoView;
|
|
import cn.shangyu.gdxzExpert.widget.ECAlertDialog;
|
|
import cn.shangyu.gdxzExpert.widget.LoadingPage.ResultState;
|
|
|
|
public class WriteTopicActivity extends BaseActivity implements OnClickListener,OnCallBackFromNet{
|
|
|
|
private EditText et_house_topic;
|
|
private CheckBox cb_hous_01, cb_hous_02, cb_hous_03, cb_hous_04,
|
|
cb_hous_05, cb_hous_06, cb_hous_07, cb_hous_08;
|
|
private ArrayList<CheckBox> checkBoxs;
|
|
private ArrayList<CheckBox> checked;
|
|
public static int isTopic = 0;
|
|
private Button btn_pop;
|
|
private String tag1;
|
|
private String tag2;
|
|
private String tag3;
|
|
private String tag4;
|
|
private String tag5;
|
|
private String tag6;
|
|
private String tag7;
|
|
private TextView top_title, top_right_text;
|
|
private GridView gv_View;
|
|
private Bitmap bmp;// 添加按钮图片
|
|
private AddTopicAdapter gv_adapter;
|
|
private List<AddBitmaps> mBitmaps;
|
|
private AddBitmaps addBipmap;
|
|
private View mView;
|
|
private RelativeLayout back;
|
|
private ViewPager mPager;
|
|
private Handler handler1 = new Handler() {
|
|
public void handleMessage(Message msg) {
|
|
if (msg.what == 88) {
|
|
|
|
if (mBitmaps.size() < 3) {
|
|
mBitmaps.add(addBipmap);
|
|
}
|
|
gv_adapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (msg.what == 11) {
|
|
if (pd.isShowing()) {
|
|
pd.dismiss();
|
|
}
|
|
Map<String, String> param = new HashMap<>();
|
|
param.put("score_type","3");
|
|
sendJsonPostParamtoNetSignMD5(Url.addBonusPoints, param, 1, WriteTopicActivity.this);
|
|
ToastUtil.showMessage("发布成功");
|
|
Intent intent = new Intent();
|
|
WriteTopicActivity.this
|
|
.setResult(GanDanHouseActivity.GET_ADD_FOR_RESULT);
|
|
SharePrefUtil.saveString(WriteTopicActivity.this,"WriteTopicActivity","");
|
|
hideSoftKeyboard();
|
|
WriteTopicActivity.this.finish();
|
|
}
|
|
};
|
|
};
|
|
private RelativeLayout mRl_bigPhoto;
|
|
private View mToolbar1;
|
|
|
|
/**
|
|
* hide inputMethod
|
|
*/
|
|
public void hideSoftKeyboard() {
|
|
InputMethodManager inputMethodManager = (InputMethodManager)
|
|
getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
if (inputMethodManager != null) {
|
|
View localView = getCurrentFocus();
|
|
if (localView != null && localView.getWindowToken() != null) {
|
|
IBinder windowToken = localView.getWindowToken();
|
|
inputMethodManager.hideSoftInputFromWindow(windowToken, 0);
|
|
}
|
|
}
|
|
}
|
|
private ECAlertDialog dilaog2;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
// TODO Auto-generated method stub
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.topic_activity);
|
|
mToolbar1=findViewById(R.id.toolbar);
|
|
ImmersionBar.with(this).keyboardEnable(true).statusBarDarkFont(true).titleBar(mToolbar1).init();
|
|
back = (RelativeLayout) findViewById(R.id.top_back_layout);
|
|
back.setOnClickListener(this);
|
|
initView();
|
|
String context = SharePrefUtil.getString(WriteTopicActivity.this, "WriteTopicActivity", "");
|
|
if (!context.isEmpty()){
|
|
et_house_topic.setText(context);
|
|
}
|
|
}
|
|
|
|
private void initView() {
|
|
isTopic = 1;
|
|
// TODO Auto-generated method stub
|
|
et_house_topic = (EditText) findViewById(R.id.et_house_topic);
|
|
mRl_bigPhoto = findViewById(R.id.rl_addcase_bigphoto);
|
|
mPager = findViewById(R.id.pager);
|
|
cb_hous_01 = (CheckBox) findViewById(R.id.cb_hous_01);
|
|
cb_hous_02 = (CheckBox) findViewById(R.id.cb_hous_02);
|
|
cb_hous_03 = (CheckBox) findViewById(R.id.cb_hous_03);
|
|
cb_hous_04 = (CheckBox) findViewById(R.id.cb_hous_04);
|
|
cb_hous_05 = (CheckBox) findViewById(R.id.cb_hous_05);
|
|
cb_hous_06 = (CheckBox) findViewById(R.id.cb_hous_06);
|
|
cb_hous_07 = (CheckBox) findViewById(R.id.cb_hous_07);
|
|
cb_hous_08 = (CheckBox) findViewById(R.id.cb_hous_08);
|
|
checkBoxs = new ArrayList<>();
|
|
checked = new ArrayList<>();
|
|
checkBoxs.add(cb_hous_01);
|
|
checkBoxs.add(cb_hous_02);
|
|
checkBoxs.add(cb_hous_03);
|
|
checkBoxs.add(cb_hous_04);
|
|
checkBoxs.add(cb_hous_05);
|
|
checkBoxs.add(cb_hous_06);
|
|
checkBoxs.add(cb_hous_07);
|
|
checkBoxs.add(cb_hous_08);
|
|
pd = new CustomProgressDialog(this, "请稍候");
|
|
// for (int i = 0; i < checkBoxs.size(); i++) {
|
|
// //if(checkBoxs.get(i).isChecked()){
|
|
// // c
|
|
// //}
|
|
// }
|
|
btn_pop = (Button) findViewById(R.id.btn_pop);
|
|
setListener();
|
|
top_title = (TextView) findViewById(R.id.top_title);
|
|
top_title.setText("发布新话题");
|
|
top_right_text = (TextView) findViewById(R.id.top_right_text);
|
|
top_right_text.setVisibility(View.VISIBLE);
|
|
top_right_text.setText("发送");
|
|
top_right_text.setOnClickListener(this);
|
|
gv_View = (GridView) findViewById(R.id.gv_add_topic);
|
|
//
|
|
bmp = BitmapFactory.decodeResource(getResources(),
|
|
R.drawable.new_selected);
|
|
addBipmap = new AddBitmaps(true, bmp, null);
|
|
mBitmaps = new ArrayList<>();
|
|
mBitmaps.add(addBipmap);
|
|
gv_adapter = new AddTopicAdapter();
|
|
gv_View.setAdapter(gv_adapter);
|
|
// ToastUtil.showMessage(mBitmaps.size()+'"');
|
|
gv_View.setOnItemClickListener(new OnItemClickListener() {
|
|
|
|
@Override
|
|
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
|
|
long arg3) {
|
|
hideSoftKeyboard();
|
|
// TODO Auto-generated method stub
|
|
if (mBitmaps.get(arg2).isAdd()) {
|
|
// initSelectedHeadPopupwindow();
|
|
// selectedPhoto();
|
|
selectedPhotoView = UIUtils
|
|
.inflate(R.layout.activity_selected_photo2);
|
|
ll_selected_carmera = (TextView) selectedPhotoView
|
|
.findViewById(R.id.btn_camera);
|
|
ll_selected_photo = (TextView) selectedPhotoView
|
|
.findViewById(R.id.btn_img);
|
|
tv_cancel = (TextView) selectedPhotoView
|
|
.findViewById(R.id.btn_cancle);
|
|
ImageView imageView = (ImageView) selectedPhotoView
|
|
.findViewById(R.id.imageView);
|
|
// imageView.setVisibility(View.GONE);
|
|
imageView.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
// TODO Auto-generated method stub
|
|
if (mPopupWindowDialog != null
|
|
&& mPopupWindowDialog.isShowing()) {
|
|
mPopupWindowDialog.dismiss();
|
|
}
|
|
}
|
|
});
|
|
initSelectedHeadPopupwindow();
|
|
if (mPopupWindowDialog != null) {
|
|
mPopupWindowDialog.showAtLocation(btn_pop,
|
|
Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0,
|
|
0);
|
|
}
|
|
|
|
selectedPhoto();
|
|
}
|
|
else
|
|
{
|
|
mRl_bigPhoto.setVisibility(View.VISIBLE);
|
|
PagerSetAdapter(arg2);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
public void PagerSetAdapter(int p) {
|
|
mToolbar1.setVisibility(View.INVISIBLE);
|
|
mPager.setPageMargin((int) (getResources().getDisplayMetrics().density * 15));
|
|
mPager.setAdapter(new PagerAdapter() {
|
|
@Override
|
|
public int getCount() {
|
|
for (int i = 0; i < mBitmaps.size(); i++) {
|
|
if (mBitmaps.get(i).isAdd()) {
|
|
return mBitmaps.size() - 1;
|
|
}
|
|
}
|
|
return mBitmaps.size();
|
|
}
|
|
|
|
@Override
|
|
public boolean isViewFromObject(View view, Object object) {
|
|
return view == object;
|
|
}
|
|
|
|
@Override
|
|
public Object instantiateItem(ViewGroup container, int position) {
|
|
PhotoView view = new PhotoView(WriteTopicActivity.this);
|
|
view.enable();
|
|
view.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
|
if (!mBitmaps.get(position).isAdd()) {
|
|
view.setImageBitmap(mBitmaps.get(position).getBitmap());
|
|
}
|
|
view.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
// TODO Auto-generated method stub
|
|
mToolbar1.setVisibility(View.VISIBLE);
|
|
mRl_bigPhoto.setVisibility(View.GONE);
|
|
|
|
|
|
}
|
|
});
|
|
container.addView(view);
|
|
return view;
|
|
}
|
|
|
|
@Override
|
|
public void destroyItem(ViewGroup container, int position,
|
|
Object object) {
|
|
container.removeView((View) object);
|
|
}
|
|
});
|
|
mPager.setCurrentItem(p);
|
|
}
|
|
private void setListener() {
|
|
// TODO Auto-generated method stub
|
|
cb_hous_01.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
boolean isChecked) {
|
|
// TODO Auto-generated method stub
|
|
|
|
if (isChecked) {
|
|
checked.add(cb_hous_01);
|
|
if (checked.size() > 3) {
|
|
ToastUtil.showMessage("最多选择三个标签");
|
|
cb_hous_01.setChecked(false);
|
|
checked.remove(cb_hous_01);
|
|
return;
|
|
}
|
|
// ToastUtil.showMessage(checked.get(0).getText().toString());
|
|
} else {
|
|
checked.remove(cb_hous_01);
|
|
cb_hous_01.setEnabled(true);
|
|
}
|
|
|
|
}
|
|
});
|
|
cb_hous_02.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
boolean isChecked) {
|
|
// TODO Auto-generated method stub
|
|
|
|
if (isChecked) {
|
|
|
|
checked.add(cb_hous_02);
|
|
if (checked.size() > 3) {
|
|
ToastUtil.showMessage("最多选择三个标签");
|
|
cb_hous_02.setChecked(false);
|
|
checked.remove(cb_hous_02);
|
|
return;
|
|
}
|
|
} else {
|
|
checked.remove(cb_hous_02);
|
|
cb_hous_01.setEnabled(true);
|
|
}
|
|
|
|
}
|
|
});
|
|
cb_hous_03.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
boolean isChecked) {
|
|
// TODO Auto-generated method stub
|
|
|
|
if (isChecked) {
|
|
|
|
checked.add(cb_hous_03);
|
|
} else {
|
|
checked.remove(cb_hous_03);
|
|
cb_hous_01.setEnabled(true);
|
|
}
|
|
if (checked.size() > 3) {
|
|
ToastUtil.showMessage("最多选择三个标签");
|
|
cb_hous_03.setChecked(false);
|
|
checked.remove(cb_hous_03);
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
cb_hous_04.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
boolean isChecked) {
|
|
// TODO Auto-generated method stub
|
|
|
|
if (isChecked) {
|
|
|
|
checked.add(cb_hous_04);
|
|
} else {
|
|
checked.remove(cb_hous_04);
|
|
cb_hous_01.setEnabled(true);
|
|
}
|
|
if (checked.size() > 3) {
|
|
ToastUtil.showMessage("最多选择三个标签");
|
|
cb_hous_04.setChecked(false);
|
|
checked.remove(cb_hous_04);
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
cb_hous_05.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
boolean isChecked) {
|
|
// TODO Auto-generated method stub
|
|
|
|
if (isChecked) {
|
|
checked.add(cb_hous_05);
|
|
} else {
|
|
checked.remove(cb_hous_05);
|
|
cb_hous_01.setEnabled(true);
|
|
}
|
|
if (checked.size() > 3) {
|
|
ToastUtil.showMessage("最多选择三个标签");
|
|
cb_hous_05.setChecked(false);
|
|
checked.remove(cb_hous_05);
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
cb_hous_06.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
boolean isChecked) {
|
|
// TODO Auto-generated method stub
|
|
|
|
if (isChecked) {
|
|
|
|
checked.add(cb_hous_06);
|
|
} else {
|
|
checked.remove(cb_hous_06);
|
|
cb_hous_01.setEnabled(true);
|
|
}
|
|
if (checked.size() > 3) {
|
|
ToastUtil.showMessage("最多选择三个标签");
|
|
cb_hous_06.setChecked(false);
|
|
checked.remove(cb_hous_06);
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
cb_hous_07.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
boolean isChecked) {
|
|
// TODO Auto-generated method stub
|
|
|
|
if (isChecked) {
|
|
|
|
checked.add(cb_hous_07);
|
|
} else {
|
|
checked.remove(cb_hous_07);
|
|
cb_hous_01.setEnabled(true);
|
|
}
|
|
if (checked.size() > 3) {
|
|
ToastUtil.showMessage("最多选择三个标签");
|
|
cb_hous_07.setChecked(false);
|
|
checked.remove(cb_hous_07);
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
cb_hous_08.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
boolean isChecked) {
|
|
// TODO Auto-generated method stub
|
|
|
|
if (isChecked) {
|
|
|
|
checked.add(cb_hous_08);
|
|
} else {
|
|
checked.remove(cb_hous_08);
|
|
cb_hous_01.setEnabled(true);
|
|
}
|
|
if (checked.size() > 3) {
|
|
ToastUtil.showMessage("最多选择三个标签");
|
|
cb_hous_08.setChecked(false);
|
|
checked.remove(cb_hous_08);
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
// TODO Auto-generated method stub
|
|
super.onDestroy();
|
|
isTopic = 0;
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
// TODO Auto-generated method stub
|
|
switch (v.getId()) {
|
|
case R.id.top_right_text:
|
|
|
|
if (TextUtils.isEmpty(et_house_topic.getText().toString())) {
|
|
ToastUtil.showMessage("话题内容不能为空!");
|
|
return;
|
|
}
|
|
StringUtil.IS_PUBLISH_TOPIC = true;
|
|
pd.show();
|
|
uploadInfo();
|
|
|
|
break;
|
|
case R.id.top_back_layout:
|
|
|
|
if (TextUtils.isEmpty(et_house_topic.getText().toString())) {
|
|
hideSoftKeyboard();
|
|
finish();
|
|
}else {
|
|
dilaog2 = ECAlertDialog.buildAlert(WriteTopicActivity.this,
|
|
"您有未发布的内容,是否保存?", "取消", "保存", new DialogInterface.OnClickListener() {
|
|
@Override
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
dilaog2.dismiss();
|
|
SharePrefUtil.saveString(WriteTopicActivity.this,"WriteTopicActivity","");
|
|
hideSoftKeyboard();
|
|
finish();
|
|
}
|
|
}, new DialogInterface.OnClickListener() {
|
|
@Override
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
dilaog2.dismiss();
|
|
SharePrefUtil.saveString(WriteTopicActivity.this,"WriteTopicActivity",et_house_topic.getText().toString());
|
|
hideSoftKeyboard();
|
|
finish();
|
|
}
|
|
});
|
|
// dilaog2.setTitle("温馨提示");
|
|
dilaog2.setCancelable(false);
|
|
dilaog2.getWindow();
|
|
dilaog2.show();
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
if(keyCode == event.KEYCODE_BACK){
|
|
if (TextUtils.isEmpty(et_house_topic.getText().toString())) {
|
|
hideSoftKeyboard();
|
|
finish();
|
|
}else {
|
|
dilaog2 = ECAlertDialog.buildAlert(WriteTopicActivity.this,
|
|
"您有未发布的内容,是否保存?", "取消", "保存", new DialogInterface.OnClickListener() {
|
|
@Override
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
dilaog2.dismiss();
|
|
SharePrefUtil.saveString(WriteTopicActivity.this,"WriteTopicActivity","");
|
|
hideSoftKeyboard();
|
|
finish();
|
|
}
|
|
}, new DialogInterface.OnClickListener() {
|
|
@Override
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
dilaog2.dismiss();
|
|
SharePrefUtil.saveString(WriteTopicActivity.this,"WriteTopicActivity",et_house_topic.getText().toString());
|
|
hideSoftKeyboard();
|
|
finish();
|
|
}
|
|
});
|
|
// dilaog2.setTitle("温馨提示");
|
|
dilaog2.setCancelable(false);
|
|
dilaog2.getWindow();
|
|
dilaog2.show();
|
|
}
|
|
|
|
}
|
|
return super.onKeyDown(keyCode, event);
|
|
}
|
|
|
|
List<BasicNameValuePair> parameters;
|
|
private StringBuffer buffer;
|
|
private String code;
|
|
|
|
// 提交信息
|
|
private void uploadInfo() {
|
|
buffer = new StringBuffer();
|
|
for (int i = 0; i < checked.size(); i++) {
|
|
if (i == (checked.size() - 1)) {
|
|
buffer.append(checked.get(i).getText());
|
|
} else {
|
|
buffer.append(checked.get(i).getText() + ",");
|
|
}
|
|
}
|
|
|
|
new Thread() {
|
|
public void run() {
|
|
parameters = new ArrayList<BasicNameValuePair>();
|
|
BasicNameValuePair value01 = new BasicNameValuePair(
|
|
"expert_uuid", SharePrefUtil.getString(
|
|
WriteTopicActivity.this, "uuid", ""));
|
|
BasicNameValuePair value02 = new BasicNameValuePair("content",
|
|
et_house_topic.getText().toString());
|
|
if (TextUtils.isEmpty(buffer.toString())) {
|
|
BasicNameValuePair value03 = new BasicNameValuePair("tags",
|
|
"");
|
|
parameters.add(value03);
|
|
} else {
|
|
BasicNameValuePair value03 = new BasicNameValuePair("tags",
|
|
buffer.toString());
|
|
parameters.add(value03);
|
|
}
|
|
|
|
parameters.add(value01);
|
|
parameters.add(value02);
|
|
|
|
for (int i = 0; i < mBitmaps.size(); i++) {
|
|
int num = i + 1;
|
|
if (!mBitmaps.get(i).isAdd()) {
|
|
BasicNameValuePair value = new BasicNameValuePair("img"
|
|
+ num, Base64Util.BitmaptoBase64(mBitmaps
|
|
.get(i).getBitmap()));
|
|
parameters.add(value);
|
|
}
|
|
}
|
|
/*
|
|
* else {
|
|
*
|
|
* BasicNameValuePair value = new BasicNameValuePair("img" +
|
|
* "1", ""); parameters.add(value);
|
|
*
|
|
* }
|
|
*/
|
|
|
|
HttpResult httpResult = HttpHelper.post(Url.getAddInteraction,
|
|
parameters);
|
|
// 请求网络,添加病例
|
|
String result = httpResult.getString();// str为服务器返回的json串
|
|
|
|
if (!StringUtil.isEmpty(result)) {
|
|
handler1.sendEmptyMessage(11);
|
|
}
|
|
};
|
|
}.start();
|
|
|
|
}
|
|
|
|
private View selectedPhotoView;
|
|
private TextView ll_selected_carmera;// 从照相机
|
|
private TextView ll_selected_photo;// 从相册
|
|
private TextView tv_cancel;// 取消
|
|
private File temp;
|
|
private PopupWindow mPopupWindowDialog;
|
|
private Uri photoUri;// 图片路径
|
|
private CustomProgressDialog pd;
|
|
|
|
/**
|
|
* 初始化头像选择pop
|
|
*/
|
|
private void initSelectedHeadPopupwindow() {
|
|
// TODO Auto-generated method stub
|
|
mPopupWindowDialog = new PopupWindow(selectedPhotoView,
|
|
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
mPopupWindowDialog.setFocusable(true);
|
|
mPopupWindowDialog.update();
|
|
mPopupWindowDialog.setBackgroundDrawable(new BitmapDrawable(
|
|
getResources(), (Bitmap) null));
|
|
mPopupWindowDialog.setOutsideTouchable(true);
|
|
}
|
|
|
|
/**
|
|
* 选择图片
|
|
*/
|
|
private void selectedPhoto() {
|
|
// TODO Auto-generated method stub
|
|
|
|
ll_selected_carmera.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
// 拍照获取照片
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
// Android 13+ (API 33+) 拍照主要需要 CAMERA 权限
|
|
boolean hasPermission;
|
|
String[] permissionsToRequest;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
// Android 13+ 拍照主要需要 CAMERA 权限
|
|
hasPermission = PermissionsUtil.hasPermission(WriteTopicActivity.this, Manifest.permission.CAMERA);
|
|
permissionsToRequest = new String[]{Manifest.permission.CAMERA};
|
|
} else {
|
|
// Android 12及以下需要 CAMERA 和存储权限
|
|
hasPermission = PermissionsUtil.hasPermission(WriteTopicActivity.this, Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
permissionsToRequest = new String[]{Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
|
}
|
|
|
|
if (hasPermission) {
|
|
//有访问摄像头的权限
|
|
takePhoto11();
|
|
} else {
|
|
EasyWindow.with(WriteTopicActivity.this).setGravity(Gravity.TOP).setYOffset(200).setWidth(1000)
|
|
|
|
.setContentView(R.layout.float_top_dialog_new).show();
|
|
PermissionsUtil.requestPermission(WriteTopicActivity.this, new PermissionListener() {
|
|
@Override
|
|
public void permissionGranted(@NonNull String[] permissions) {
|
|
EasyWindow.cancelAll();
|
|
//用户授予了访问摄像头的权限
|
|
takePhoto11();
|
|
}
|
|
@Override
|
|
public void permissionDenied(@NonNull String[] permissions) {
|
|
EasyWindow.cancelAll();
|
|
//用户拒绝了访问摄像头的申请
|
|
|
|
}
|
|
|
|
}, permissionsToRequest);
|
|
}
|
|
|
|
}else {
|
|
takePhoto();
|
|
}
|
|
|
|
|
|
if (mPopupWindowDialog != null
|
|
&& mPopupWindowDialog.isShowing()) {
|
|
mPopupWindowDialog.dismiss();// 消失
|
|
}
|
|
}
|
|
});
|
|
|
|
ll_selected_photo.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
// 从相册获取
|
|
pickPhoto();
|
|
if (mPopupWindowDialog != null
|
|
&& mPopupWindowDialog.isShowing()) {
|
|
mPopupWindowDialog.dismiss();// 消失
|
|
}
|
|
}
|
|
});
|
|
tv_cancel.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
// TODO Auto-generated method stub
|
|
if (mPopupWindowDialog != null
|
|
&& mPopupWindowDialog.isShowing()) {
|
|
mPopupWindowDialog.dismiss();// 消失
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
* 拍照获取图片
|
|
*/
|
|
private void takePhoto() {
|
|
String fileName = null;
|
|
// 执行拍照前,应该先判断SD卡是否存在
|
|
String SDState = Environment.getExternalStorageState();
|
|
if (SDState.equals(Environment.MEDIA_MOUNTED)) {
|
|
|
|
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);// "android.media.action.IMAGE_CAPTURE"调用系统的相机
|
|
fileName = String.valueOf(System.currentTimeMillis()) + ".jpg";
|
|
photoUri = Uri.fromFile(new File(Environment
|
|
.getExternalStorageDirectory(), fileName));
|
|
// 指定照片保存路径(SD卡),image.jpg为一个临时文件,每次拍照后这个图片都会被替换
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
|
|
SharePrefUtil.saveString(WriteTopicActivity.this,
|
|
"startConsultPhotoUri", photoUri + "");
|
|
startActivityForResult(intent, SELECT_PIC_BY_TACK_PHOTO);
|
|
} else {
|
|
Toast.makeText(this, "内存卡不存在", Toast.LENGTH_LONG).show();
|
|
}
|
|
}
|
|
private void takePhoto11() {
|
|
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);// 设置打开相机
|
|
|
|
File photoFile = null;
|
|
try {
|
|
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); // 保存到公共共享空间内,可以在资源管理器中找到,其他应用也可以直接访问
|
|
// File storageDir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES); 将图片放到应用专属空间内,其他的应用无法访问,也无法查看。随app的卸载而删除
|
|
String imageFileName = "fileName";
|
|
photoFile = File.createTempFile(imageFileName, ".jpg", storageDir);
|
|
// String filePath = photoFile.getAbsolutePath(); 获取到图片的路径,可以在onActivityResult中根据这个路径去获取图片
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
if (photoFile != null) {
|
|
photoUri = FileProvider.getUriForFile(this,getPackageName() + ".fileprovider",
|
|
photoFile);
|
|
SharePrefUtil.saveString(this, "startConsultPhotoUri",
|
|
photoUri + "");
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT,
|
|
FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".fileprovider", photoFile));
|
|
|
|
startActivityForResult(intent, SELECT_PIC_BY_TACK_PHOTO);
|
|
}
|
|
}
|
|
/***
|
|
* 从相册中取图片
|
|
*/
|
|
public static final int SELECT_PIC_BY_TACK_PHOTO = 1; // 使用照相机拍照获取图片
|
|
public static final int SELECT_PIC_BY_PICK_PHOTO = 2; // 使用相册中的图片
|
|
/**
|
|
* 执行返回结果
|
|
*/
|
|
private ArrayList<PhotoItem> paths;
|
|
|
|
private void pickPhoto() {
|
|
|
|
|
|
|
|
// Android 6.0 ~ 12 使用旧的存储权限
|
|
boolean hasPermission;
|
|
String[] permissionsToRequest;
|
|
|
|
hasPermission = PermissionsUtil.hasPermission(WriteTopicActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
permissionsToRequest = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
|
|
|
if (hasPermission) {
|
|
isTopic = 1;
|
|
Intent intent = new Intent(WriteTopicActivity.this,
|
|
AllPhotosActivity.class);
|
|
intent.putExtra("photonum", "" + (mBitmaps.size() - 1));
|
|
intent.putExtra("isTopic", "isTopic");
|
|
startActivityForResult(intent, SELECT_PIC_BY_PICK_PHOTO);
|
|
} else {
|
|
EasyWindow.with(WriteTopicActivity.this).setGravity(Gravity.TOP).setYOffset(200).setWidth(1000)
|
|
|
|
.setContentView(R.layout.float_top_dialog_photo).show();
|
|
PermissionsUtil.requestPermission(WriteTopicActivity.this, new PermissionListener() {
|
|
@Override
|
|
public void permissionGranted(@NonNull String[] permissions) {
|
|
EasyWindow.cancelAll();
|
|
isTopic = 1;
|
|
Intent intent = new Intent(WriteTopicActivity.this,
|
|
AllPhotosActivity.class);
|
|
intent.putExtra("photonum", "" + (mBitmaps.size() - 1));
|
|
intent.putExtra("isTopic", "isTopic");
|
|
startActivityForResult(intent, SELECT_PIC_BY_PICK_PHOTO);
|
|
|
|
}
|
|
@Override
|
|
public void permissionDenied(@NonNull String[] permissions) {
|
|
EasyWindow.cancelAll();
|
|
//用户拒绝了访问相册的申请
|
|
}
|
|
|
|
}, permissionsToRequest);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
// this.data = data;
|
|
|
|
if (resultCode == 102) {
|
|
if (data == null) {
|
|
return;
|
|
}
|
|
|
|
paths = (ArrayList<PhotoItem>) data.getSerializableExtra("photos");
|
|
|
|
mBitmaps.remove(addBipmap);
|
|
new Thread() {
|
|
|
|
public void run() {
|
|
for (int i = 0; i < paths.size(); i++) {
|
|
InputStream is;
|
|
try {
|
|
is = new FileInputStream(paths.get(i).getPath());
|
|
BitmapFactory.Options opts = new BitmapFactory.Options();
|
|
opts.inTempStorage = new byte[100 * 1024];
|
|
opts.inPreferredConfig = Bitmap.Config.RGB_565;
|
|
opts.inPurgeable = true;
|
|
BitmapFactory.decodeFile(paths.get(i).getPath(),
|
|
opts);
|
|
opts.inSampleSize = calculateInSampleSize(opts,
|
|
720, 1280);
|
|
opts.inInputShareable = true;
|
|
Bitmap bitmap = BitmapFactory.decodeStream(is,
|
|
null, opts);
|
|
// String picPath =
|
|
// Base64Util.BitmaptoBase64(bitmap);
|
|
mBitmaps.add(new AddBitmaps(false, bitmap, null));
|
|
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
handler1.sendEmptyMessage(88);
|
|
};
|
|
}.start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
doPhoto(requestCode, data);
|
|
}
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
}
|
|
|
|
public static int calculateInSampleSize(BitmapFactory.Options options,
|
|
int reqWidth, int reqHeight) {
|
|
|
|
final int height = options.outHeight;
|
|
|
|
final int width = options.outWidth;
|
|
|
|
int inSampleSize = 1;
|
|
|
|
if (height > reqHeight || width > reqWidth) {
|
|
|
|
final int heightRatio = Math.round((float) height
|
|
/ (float) reqHeight);
|
|
|
|
final int widthRatio = Math.round((float) width / (float) reqWidth);
|
|
|
|
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
|
|
|
|
}
|
|
|
|
return inSampleSize;
|
|
|
|
}
|
|
|
|
private void doPhoto(int requestCode, Intent data) {
|
|
if (requestCode == SELECT_PIC_BY_PICK_PHOTO) // 从相册取图片,有些手机有异常情况,请注意
|
|
{
|
|
if (data == null) {
|
|
Toast.makeText(this, " ", Toast.LENGTH_LONG).show();
|
|
return;
|
|
}
|
|
photoUri = data.getData();
|
|
if (photoUri == null) {
|
|
Toast.makeText(this, "选择图片文件出错", Toast.LENGTH_LONG).show();
|
|
return;
|
|
}
|
|
cropImg(photoUri);
|
|
}
|
|
if (requestCode == SELECT_PIC_BY_TACK_PHOTO) {
|
|
// pd = new CustomProgressDialog(AddCaseActivity.this, "请稍候");
|
|
// pd.show();
|
|
photoUri = Uri.parse(SharePrefUtil.getString(
|
|
WriteTopicActivity.this, "startConsultPhotoUri", ""));
|
|
// LogUtils.e("photoUri" + photoUri);
|
|
if (photoUri == null) {
|
|
Toast.makeText(this, "选择图片文件出错", Toast.LENGTH_LONG).show();
|
|
return;
|
|
}
|
|
cropImg(photoUri);
|
|
gv_View.setAdapter(gv_adapter);
|
|
// pd.dismiss();
|
|
}
|
|
|
|
}
|
|
|
|
private void cropImg(Uri photoUri) {
|
|
// TODO Auto-generated method stub
|
|
ImageLoader.getInstance().loadImage(photoUri + "",
|
|
new SimpleImageLoadingListener() {
|
|
@Override
|
|
public void onLoadingComplete(String imageUri, View view,
|
|
Bitmap loadedImage) {
|
|
|
|
// TODO Auto-generated method stub
|
|
super.onLoadingComplete(imageUri, view, loadedImage);
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
loadedImage.compress(Bitmap.CompressFormat.JPEG, 100,
|
|
baos);
|
|
String aaa = baos.toByteArray().length + "";
|
|
String name = "picPath" + mPhotos.size();
|
|
name = Base64Util.BitmaptoBase64(loadedImage);// 路径
|
|
|
|
mBitmaps.add(mBitmaps.size() - 1, new AddBitmaps(false,
|
|
loadedImage, name));
|
|
if (mBitmaps.size() > 3) {
|
|
mBitmaps.remove(addBipmap);
|
|
}
|
|
gv_adapter.notifyDataSetChanged();
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private List<AddBitmaps> mPhotos = new ArrayList<>();// 存gridview的照片的集合
|
|
|
|
class AddTopicAdapter extends BaseAdapter {
|
|
|
|
@Override
|
|
public int getCount() {
|
|
// TODO Auto-generated method stub
|
|
return mBitmaps.size();
|
|
}
|
|
|
|
@Override
|
|
public Object getItem(int position) {
|
|
// TODO Auto-generated method stub
|
|
return mBitmaps.get(position);
|
|
}
|
|
|
|
@Override
|
|
public long getItemId(int position) {
|
|
// TODO Auto-generated method stub
|
|
return position;
|
|
}
|
|
|
|
@Override
|
|
public View getView(final int position, View convertView,
|
|
ViewGroup parent) {
|
|
View view = UIUtils.inflate(R.layout.item_gv_case_record);
|
|
ImageView iv_photo = (ImageView) view
|
|
.findViewById(R.id.iv_item_gv_case_photo);
|
|
ImageView iv_delete = (ImageView) view
|
|
.findViewById(R.id.iv_item_gv_case_delete);
|
|
if (mBitmaps.get(position).isAdd()) {
|
|
iv_delete.setVisibility(View.GONE);
|
|
}
|
|
if (mBitmaps.get(position).getBitmap() != null) {
|
|
iv_photo.setImageBitmap(mBitmaps.get(position).getBitmap());
|
|
}
|
|
iv_delete.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
// TODO Auto-generated method stub
|
|
mBitmaps.remove(position);
|
|
if (!mBitmaps.contains(addBipmap)) {
|
|
mBitmaps.add(addBipmap);
|
|
}
|
|
notifyDataSetChanged();
|
|
}
|
|
});
|
|
return view;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCallbackFromThread(String resultJson) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onCallBackFromThread(String resultJson, int resultCode) {
|
|
// TODO Auto-generated method stub
|
|
switch (resultCode) {
|
|
case 1:
|
|
JSONObject jsonObject;
|
|
try {
|
|
jsonObject = new JSONObject(resultJson);
|
|
String optString = jsonObject.optString("code");
|
|
if ("200".equals(optString)) {
|
|
Constant.isRefreshpoint = true;//个人中心界面刷新
|
|
ToastUtil.showMessage(jsonObject.optString("message"));
|
|
}
|
|
} catch (JSONException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setTitle() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public View onCreateSuccessedView() {
|
|
// TODO Auto-generated method stub
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public ResultState onLoad() {
|
|
// TODO Auto-generated method stub
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
protected void processClick(View v) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
}
|