|
|
@@ -1,9 +1,14 @@
|
|
|
package com.xzjmyk.pm.activity.ui.circle;
|
|
|
|
|
|
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.os.Environment;
|
|
|
import android.text.TextUtils;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
|
@@ -24,6 +29,7 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
import com.nostra13.universalimageloader.core.assist.PauseOnScrollListener;
|
|
|
import com.xzjmyk.pm.activity.AppConfig;
|
|
|
import com.xzjmyk.pm.activity.db.dao.MyPhotoDao;
|
|
|
+import com.xzjmyk.pm.activity.util.CameraUtil;
|
|
|
import com.xzjmyk.pm.activity.volley.StringJsonArrayRequest;
|
|
|
import com.xzjmyk.pm.activity.AppConstant;
|
|
|
import com.xzjmyk.pm.activity.MyApplication;
|
|
|
@@ -48,6 +54,7 @@ import com.xzjmyk.pm.activity.volley.ObjectResult;
|
|
|
import com.xzjmyk.pm.activity.volley.Result;
|
|
|
import com.xzjmyk.pm.activity.volley.StringJsonObjectRequest;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -67,7 +74,6 @@ public class BusinessCircleActivity extends BaseActivity implements showCEView {
|
|
|
private PullToRefreshListView mPullToRefreshListView;//
|
|
|
/* 封面视图 */
|
|
|
private View mMyCoverView;// 封面root view
|
|
|
- private CarouselImageView mCoverImg;// 封面图片ImageView
|
|
|
private ImageView imgHead;// 封面图片ImageView
|
|
|
private Button mInviteBtn;// 面试邀请按钮
|
|
|
private ImageView mAvatarImg;// 用户头像
|
|
|
@@ -278,7 +284,7 @@ public class BusinessCircleActivity extends BaseActivity implements showCEView {
|
|
|
|
|
|
private void initCoverView() {
|
|
|
mMyCoverView = LayoutInflater.from(this).inflate(R.layout.space_cover_view, null);
|
|
|
- mCoverImg = (CarouselImageView) mMyCoverView.findViewById(R.id.cover_img);
|
|
|
+ imgHead = (ImageView) mMyCoverView.findViewById(R.id.cover_img);
|
|
|
mInviteBtn = (Button) mMyCoverView.findViewById(R.id.invite_btn);
|
|
|
mAvatarImg = (ImageView) mMyCoverView.findViewById(R.id.avatar_img);
|
|
|
// 邀请按钮
|
|
|
@@ -302,30 +308,71 @@ public class BusinessCircleActivity extends BaseActivity implements showCEView {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- if (isMyBusiness() || isMySpace()) {
|
|
|
- mCoverImg.setUserId(mLoginUserId);
|
|
|
- } else {
|
|
|
- mCoverImg.setUserId(mUserId);
|
|
|
- }
|
|
|
+// if (isMyBusiness() || isMySpace()) {
|
|
|
+// mCoverImg.setUserId(mLoginUserId);
|
|
|
+// } else {
|
|
|
+// mCoverImg.setUserId(mUserId);
|
|
|
+// }
|
|
|
|
|
|
- mCoverImg.setOnClickListener(new View.OnClickListener() {
|
|
|
+ imgHead.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- if (mPhotos == null || mPhotos.size() <= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- ArrayList<String> images = new ArrayList<String>();
|
|
|
- for (int i = 0; i < mPhotos.size(); i++) {
|
|
|
- images.add(mPhotos.get(i).getOriginalUrl());
|
|
|
- }
|
|
|
- Intent intent = new Intent(BusinessCircleActivity.this, MultiImagePreviewActivity.class);
|
|
|
- intent.putExtra(AppConstant.EXTRA_IMAGES, images);
|
|
|
- startActivity(intent);
|
|
|
+// if (mPhotos == null || mPhotos.size() <= 0) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// ArrayList<String> images = new ArrayList<String>();
|
|
|
+// for (int i = 0; i < mPhotos.size(); i++) {
|
|
|
+// images.add(mPhotos.get(i).getOriginalUrl());
|
|
|
+// }
|
|
|
+// Intent intent = new Intent(BusinessCircleActivity.this, MultiImagePreviewActivity.class);
|
|
|
+// intent.putExtra(AppConstant.EXTRA_IMAGES, images);
|
|
|
+// startActivity(intent);
|
|
|
+ showSelectAvatarDialog();
|
|
|
}
|
|
|
});
|
|
|
- loadPhotos();
|
|
|
+ // loadPhotos();
|
|
|
+ String url = PreferenceUtils.getString(this, HEAD_PHONE, "o");
|
|
|
+ if (url != null && !url.equals("o")) {
|
|
|
+ if (new File(url).isFile())
|
|
|
+ ImageLoader.getInstance().displayImage(url, imgHead);
|
|
|
+ else
|
|
|
+ imgHead.setImageResource(R.drawable.qzone_phone);
|
|
|
+ } else {
|
|
|
+ imgHead.setImageResource(R.drawable.qzone_phone);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showSelectAvatarDialog() {
|
|
|
+ String[] items = new String[]{getString(R.string.c_take_picture), getString(R.string.c_photo_album)};
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.select_avatar).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 static final int REQUEST_CODE_CAPTURE_CROP_PHOTO = 2;
|
|
|
+ private static final int REQUEST_CODE_PICK_CROP_PHOTO = 4;
|
|
|
+ private Uri mNewPhotoUri;
|
|
|
+
|
|
|
+ private void takePhoto() {
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(this, CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ CameraUtil.captureImage(this, mNewPhotoUri, REQUEST_CODE_CAPTURE_CROP_PHOTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void selectPhoto() {
|
|
|
+ CameraUtil.pickImageSimple(this, REQUEST_CODE_PICK_CROP_PHOTO);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void loadPhotos() {
|
|
|
if (isMyBusiness() || isMySpace()) {// 自己的,那么就直接从数据库加载我的相册
|
|
|
mPhotos = MyPhotoDao.getInstance().getPhotos(mLoginUserId);
|
|
|
@@ -355,11 +402,7 @@ public class BusinessCircleActivity extends BaseActivity implements showCEView {
|
|
|
}
|
|
|
|
|
|
private void setCoverPhotos(List<MyPhoto> photos) {
|
|
|
- String[] coverPhotos2 = {"http://img0.bdstatic.com/img/image/shouye/xiaoxiao/%E6%91%84%E5%BD%B11.jpg",
|
|
|
- "http://c.hiphotos.baidu.com/image/h%3D200/sign=7b991b465eee3d6d3dc680cb73176d41/96dda144ad3459829813ed730bf431adcaef84b1.jpg",
|
|
|
- "http://img0.bdstatic.com/img/image/shouye/xiaoxiao/%E5%88%98%E8%AF%97%E8%AF%97.jpg",
|
|
|
- "http://img0.bdstatic.com/img/image/shouye/xiaoxiao/%E5%8A%A8%E6%BC%AB2.jpg"
|
|
|
- };
|
|
|
+
|
|
|
|
|
|
if (photos == null || photos.size() <= 0) {
|
|
|
return;
|
|
|
@@ -368,7 +411,7 @@ public class BusinessCircleActivity extends BaseActivity implements showCEView {
|
|
|
for (int i = 0; i < photos.size(); i++) {
|
|
|
coverPhotos[i] = photos.get(i).getOriginalUrl();
|
|
|
}
|
|
|
- mCoverImg.setImages(coverPhotos2);
|
|
|
+// mCoverImg.setImages(coverPhotos);
|
|
|
}
|
|
|
|
|
|
private List<MyPhoto> mPhotos = null;
|
|
|
@@ -389,17 +432,17 @@ public class BusinessCircleActivity extends BaseActivity implements showCEView {
|
|
|
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
- if (mCoverImg != null) {
|
|
|
- mCoverImg.onResume();
|
|
|
- }
|
|
|
+// if (mCoverImg != null) {
|
|
|
+// mCoverImg.onResume();
|
|
|
+// }
|
|
|
super.onResume();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onStop() {
|
|
|
- if (mCoverImg != null) {
|
|
|
- mCoverImg.onStop();
|
|
|
- }
|
|
|
+// if (mCoverImg != null) {
|
|
|
+// mCoverImg.onStop();
|
|
|
+// }
|
|
|
if (listener != null) {
|
|
|
listener.ideChange();
|
|
|
}
|
|
|
@@ -420,6 +463,9 @@ public class BusinessCircleActivity extends BaseActivity implements showCEView {
|
|
|
void ideChange();
|
|
|
}
|
|
|
|
|
|
+ private File mCurrentFile;
|
|
|
+ private static final int REQUEST_CODE_CROP_PHOTO = 3;
|
|
|
+
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
if (requestCode == REQUEST_CODE_SEND_MSG) {
|
|
|
@@ -428,11 +474,45 @@ public class BusinessCircleActivity extends BaseActivity implements showCEView {
|
|
|
CircleMessageDao.getInstance().addMessage(mLoginUserId, messageId);
|
|
|
requestData(true);
|
|
|
}
|
|
|
+ } else if (requestCode == REQUEST_CODE_CAPTURE_CROP_PHOTO) {// 拍照返回再去裁减
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (mNewPhotoUri != null) {
|
|
|
+ Uri o = mNewPhotoUri;
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(this, CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ mCurrentFile = new File(mNewPhotoUri.getPath());
|
|
|
+ CameraUtil.cropImage(this, o, mNewPhotoUri, REQUEST_CODE_CROP_PHOTO, 1, 1, 300, 300);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_photo_album_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (requestCode == REQUEST_CODE_PICK_CROP_PHOTO) {// 选择一张图片,然后立即调用裁减
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (data != null && data.getData() != null) {
|
|
|
+ String path = CameraUtil.getImagePathFromUri(this, data.getData());
|
|
|
+ Uri o = Uri.fromFile(new File(path));
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(this, CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ mCurrentFile = new File(mNewPhotoUri.getPath());
|
|
|
+ CameraUtil.cropImage(this, o, mNewPhotoUri, REQUEST_CODE_CROP_PHOTO, 1, 1, 300, 300);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_photo_album_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (requestCode == REQUEST_CODE_CROP_PHOTO) {
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (mNewPhotoUri != null) {
|
|
|
+ mCurrentFile = new File(mNewPhotoUri.getPath());
|
|
|
+ ImageLoader.getInstance().displayImage(mNewPhotoUri.toString(), imgHead);
|
|
|
+ PreferenceUtils.putString(this, HEAD_PHONE, mNewPhotoUri.toString());
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, mNewPhotoUri.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static String HEAD_PHONE = "head_phone";
|
|
|
/********** 公共消息的数据请求部分 *********/
|
|
|
-
|
|
|
/**
|
|
|
* 请求公共消息
|
|
|
*
|
|
|
@@ -613,7 +693,6 @@ public class BusinessCircleActivity extends BaseActivity implements showCEView {
|
|
|
ToastUtil.showErrorNet(BusinessCircleActivity.this);
|
|
|
}
|
|
|
}, new StringJsonObjectRequest.Listener<String>() {
|
|
|
-
|
|
|
@Override
|
|
|
public void onResponse(ObjectResult<String> result) {
|
|
|
boolean success = Result.defaultParser(BusinessCircleActivity.this, result, true);
|