|
|
@@ -0,0 +1,240 @@
|
|
|
+package com.xzjmyk.pm.activity.ui.erp.activity.oa;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.BaseAdapter;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.andreabaccega.widget.FormEditText;
|
|
|
+import com.lidroid.xutils.ViewUtils;
|
|
|
+import com.lidroid.xutils.view.annotation.ViewInject;
|
|
|
+import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
+import com.xzjmyk.pm.activity.AppConstant;
|
|
|
+import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.tool.MultiImagePreviewActivity;
|
|
|
+import com.xzjmyk.pm.activity.util.CameraUtil;
|
|
|
+import com.xzjmyk.pm.activity.util.ToastUtil;
|
|
|
+import com.xzjmyk.pm.activity.view.MyGridView;
|
|
|
+import com.xzjmyk.pm.activity.view.SquareCenterImageView;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by FANGlh on 2017/6/9.
|
|
|
+ * function:
|
|
|
+ */
|
|
|
+
|
|
|
+public class ExpenseReimbursementActivity extends BaseActivity implements View.OnClickListener{
|
|
|
+ @ViewInject(R.id.reimbursement_title_fet)
|
|
|
+ private FormEditText reimbursement_title_fet;
|
|
|
+ @ViewInject(R.id.reimbursement_type_fet)
|
|
|
+ private FormEditText reimbursement_type_fet;
|
|
|
+ @ViewInject(R.id.reimbursement_currency_fet)
|
|
|
+ private FormEditText reimbursement_currency_fet;
|
|
|
+ @ViewInject(R.id.btn_save)
|
|
|
+ private Button btn_save;
|
|
|
+ @ViewInject(R.id.select_img_layout)
|
|
|
+ private View mSelectImgLayout;
|
|
|
+ private MyGridView mGridView;
|
|
|
+ private GridViewAdapter mAdapter;
|
|
|
+ private ArrayList<String> mPhotoList;
|
|
|
+ private Uri mNewPhotoUri;// 拍照和图库 获得图片的URI
|
|
|
+ private static final int REQUEST_CODE_CAPTURE_PHOTO = 1;// 拍照
|
|
|
+ private static final int REQUEST_CODE_PICK_PHOTO = 2;// 图库
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_expense_reimbursement);
|
|
|
+ ViewUtils.inject(this);
|
|
|
+ iniView();
|
|
|
+ initPicturesEvent();
|
|
|
+ }
|
|
|
+ private void iniView() {
|
|
|
+ reimbursement_title_fet.setOnClickListener(this);
|
|
|
+
|
|
|
+ reimbursement_type_fet.setKeyListener(null);
|
|
|
+ reimbursement_type_fet.setFocusable(false);
|
|
|
+ reimbursement_type_fet.setOnClickListener(this);
|
|
|
+
|
|
|
+ reimbursement_currency_fet.setOnClickListener(this);
|
|
|
+ btn_save.setOnClickListener(this);
|
|
|
+
|
|
|
+ mGridView = (MyGridView) findViewById(R.id.grid_view);
|
|
|
+ mPhotoList = new ArrayList<String>();
|
|
|
+ mAdapter = new GridViewAdapter();
|
|
|
+ mGridView.setAdapter(mAdapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ switch (v.getId()){
|
|
|
+ case R.id.reimbursement_title_fet:
|
|
|
+ break;
|
|
|
+ case R.id.reimbursement_type_fet:
|
|
|
+ break;
|
|
|
+ case R.id.reimbursement_currency_fet:
|
|
|
+ break;
|
|
|
+ case R.id.btn_save:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initPicturesEvent() {
|
|
|
+ mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ int viewType = mAdapter.getItemViewType(position);
|
|
|
+
|
|
|
+ if (viewType == 1) {
|
|
|
+ showSelectPictureDialog();//第一个
|
|
|
+ //TODO 选择图片页面
|
|
|
+// startActivityForResult(new Intent(ct, PhoneSelectActivity.class), 222);
|
|
|
+ } else {
|
|
|
+ showPictureActionDialog(position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (requestCode == REQUEST_CODE_CAPTURE_PHOTO) {// 拍照返回
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (mNewPhotoUri != null) {
|
|
|
+ mPhotoList.add(mNewPhotoUri.getPath());
|
|
|
+ mAdapter.notifyDataSetInvalidated();
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_take_picture_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if (requestCode == REQUEST_CODE_PICK_PHOTO) {// 选择一张图片,然后立即调用裁减
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (data != null && data.getData() != null) {
|
|
|
+ String path = CameraUtil.getImagePathFromUri(this, data.getData());
|
|
|
+ mPhotoList.add(path);
|
|
|
+ mAdapter.notifyDataSetInvalidated();
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_photo_album_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showSelectPictureDialog() {
|
|
|
+ String[] items = new String[]{getString(R.string.c_take_picture), getString(R.string.c_photo_album)};
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this).setSingleChoiceItems(items, 0,
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ if (which == 0) {
|
|
|
+ takePhoto();
|
|
|
+ } else {
|
|
|
+ selectPhoto();
|
|
|
+ }
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.show();
|
|
|
+ }
|
|
|
+ private void showPictureActionDialog(final int position) {
|
|
|
+ String[] items = new String[]{getString(R.string.look_over), getString(R.string.common_delete)};
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.pictures)
|
|
|
+ .setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ if (which == 0) {// 查看
|
|
|
+ Intent intent = new Intent(ct, MultiImagePreviewActivity.class);
|
|
|
+ intent.putExtra(AppConstant.EXTRA_IMAGES, mPhotoList);
|
|
|
+ intent.putExtra(AppConstant.EXTRA_POSITION, position);
|
|
|
+ intent.putExtra(AppConstant.EXTRA_CHANGE_SELECTED, false);
|
|
|
+ startActivity(intent);
|
|
|
+ } else {// 删除
|
|
|
+ deletePhoto(position);
|
|
|
+ }
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.show();
|
|
|
+ }
|
|
|
+ private void deletePhoto(final int position) {
|
|
|
+ mPhotoList.remove(position);
|
|
|
+ mAdapter.notifyDataSetInvalidated();
|
|
|
+ }
|
|
|
+ private void takePhoto() {
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(this, CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ CameraUtil.captureImage(this, mNewPhotoUri, REQUEST_CODE_CAPTURE_PHOTO);
|
|
|
+ }
|
|
|
+ private void selectPhoto() {
|
|
|
+ CameraUtil.pickImageSimple(this, REQUEST_CODE_PICK_PHOTO);
|
|
|
+ }
|
|
|
+ private class GridViewAdapter extends BaseAdapter {
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ if (mPhotoList.size() >= 9) {return 9;}
|
|
|
+ return mPhotoList.size() + 1;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public Object getItem(int position) {
|
|
|
+ return position;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public long getItemId(int position) {
|
|
|
+ return position;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public int getViewTypeCount() {
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public int getItemViewType(int position) {
|
|
|
+ if (mPhotoList.size() == 0) {
|
|
|
+ return 1;// View Type 1代表添加更多的视图
|
|
|
+ } else if (mPhotoList.size() < 9) {
|
|
|
+ if (position < mPhotoList.size()) {
|
|
|
+ return 0;// View Type 0代表普通的ImageView视图
|
|
|
+ } else {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getView(final int position, View convertView, ViewGroup parent) {
|
|
|
+ if (getItemViewType(position) == 0) {// 普通的视图
|
|
|
+ SquareCenterImageView imageView = new SquareCenterImageView(ct);
|
|
|
+ imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
+ String url = mPhotoList.get(position);
|
|
|
+ if (url == null) {
|
|
|
+ url = "";
|
|
|
+ }
|
|
|
+ ImageLoader.getInstance().displayImage(Uri.fromFile(new File(url)).toString(), imageView);
|
|
|
+ return imageView;
|
|
|
+ } else {
|
|
|
+ View view = LayoutInflater.from(ct).inflate(R.layout.layout_circle_add_more_item,
|
|
|
+ parent, false);
|
|
|
+ ImageView iconImageView = (ImageView) view.findViewById(R.id.icon_image_view);
|
|
|
+ TextView voiceTextTv = (TextView) view.findViewById(R.id.text_tv);
|
|
|
+ iconImageView.setBackgroundResource(R.drawable.add_picture);
|
|
|
+ voiceTextTv.setText(R.string.qzone_add_picture);
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|