From 3e6e77d015eb26daf6221725c82f17d2571132af Mon Sep 17 00:00:00 2001 From: chenyanan Date: Thu, 3 Aug 2017 14:28:25 +0800 Subject: [PATCH] 2.2.0 finish --- chatapp/src/main/AndroidManifest.xml | 3 - .../activity/BrowserViewPagerActivity.java | 70 ++- .../chat/controller/ActivityController.java | 1 + .../chat/controller/ChatItemController.java | 29 +- .../PreviewImageFromLocalActivity.java | 398 ------------------ .../ImagePagerAdapterInImageSwitch.java | 85 ---- .../chat/pickerimage/utils/StorageUtil.java | 13 +- .../jiguang/chat/utils/DialogCreator.java | 16 + .../res/layout/jmui_dialog_delete_conv.xml | 1 + .../preview_image_from_local_activity.xml | 63 --- chatapp/src/main/res/values/strings.xml | 3 + 11 files changed, 99 insertions(+), 583 deletions(-) delete mode 100644 chatapp/src/main/java/jiguang/chat/pickerimage/PreviewImageFromLocalActivity.java delete mode 100644 chatapp/src/main/java/jiguang/chat/pickerimage/adapter/ImagePagerAdapterInImageSwitch.java delete mode 100644 chatapp/src/main/res/layout/preview_image_from_local_activity.xml diff --git a/chatapp/src/main/AndroidManifest.xml b/chatapp/src/main/AndroidManifest.xml index 0ed1e8d2..cd2ef44b 100644 --- a/chatapp/src/main/AndroidManifest.xml +++ b/chatapp/src/main/AndroidManifest.xml @@ -199,9 +199,6 @@ - diff --git a/chatapp/src/main/java/jiguang/chat/activity/BrowserViewPagerActivity.java b/chatapp/src/main/java/jiguang/chat/activity/BrowserViewPagerActivity.java index 7f30a51a..4244357e 100644 --- a/chatapp/src/main/java/jiguang/chat/activity/BrowserViewPagerActivity.java +++ b/chatapp/src/main/java/jiguang/chat/activity/BrowserViewPagerActivity.java @@ -1,6 +1,8 @@ package jiguang.chat.activity; +import android.app.Dialog; import android.app.ProgressDialog; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; @@ -9,6 +11,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; +import android.provider.MediaStore; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.text.TextUtils; @@ -18,6 +21,7 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; +import android.view.WindowManager; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -43,7 +47,10 @@ import cn.jpush.im.android.api.model.Message; import jiguang.chat.R; import jiguang.chat.application.JGApplication; +import jiguang.chat.pickerimage.utils.AttachmentStore; +import jiguang.chat.pickerimage.utils.StorageUtil; import jiguang.chat.utils.BitmapLoader; +import jiguang.chat.utils.DialogCreator; import jiguang.chat.utils.NativeImageLoader; import jiguang.chat.view.ImgBrowserViewPager; import jiguang.chat.view.PhotoView; @@ -57,7 +64,7 @@ public class BrowserViewPagerActivity extends BaseActivity { private ImgBrowserViewPager mViewPager; private ProgressDialog mProgressDialog; //存放所有图片的路径 - private List mPathList = new ArrayList (); + private List mPathList = new ArrayList(); //存放图片消息的ID private List mMsgIdList = new ArrayList(); private TextView mNumberTv; @@ -90,6 +97,8 @@ public class BrowserViewPagerActivity extends BaseActivity { private final static int INIT_ADAPTER = 0x2001; private final static int GET_NEXT_PAGE_OF_PICTURE = 0x2002; private final static int SET_CURRENT_POSITION = 0x2003; + private Dialog mDialog; + /** * 用来存储图片的选中情况 @@ -229,6 +238,8 @@ public View instantiateItem(ViewGroup container, int position) { photoView.setImageResource(R.drawable.jmui_picture_not_found); } container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + //图片长按保存到手机 + onImageViewFound(photoView, path); return photoView; } @@ -255,6 +266,51 @@ public boolean isViewFromObject(View view, Object object) { }; + private void onImageViewFound(PhotoView photoView, final String path) { + photoView.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + + View.OnClickListener listener = new OnClickListener() { + @Override + public void onClick(View v) { + savePicture(path, mDialog); + } + }; + mDialog = DialogCreator.createSavePictureDialog(mContext, listener); + mDialog.show(); + mDialog.getWindow().setLayout((int) (0.8 * mWidth), WindowManager.LayoutParams.WRAP_CONTENT); + return false; + } + }); + } + + // 保存图片 + public void savePicture(String path, Dialog dialog) { + if (TextUtils.isEmpty(path)) { + return; + } + + String picPath = StorageUtil.getSystemImagePath(); + String dstPath = picPath + path; + if (AttachmentStore.copy(path, dstPath) != -1) { + try { + ContentValues values = new ContentValues(2); + values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); + values.put(MediaStore.Images.Media.DATA, dstPath); + getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); + Toast.makeText(mContext, getString(R.string.picture_save_to), Toast.LENGTH_LONG).show(); + dialog.dismiss(); + } catch (Exception e) { + dialog.dismiss(); + Toast.makeText(mContext, getString(R.string.picture_save_fail), Toast.LENGTH_LONG).show(); + } + } else { + dialog.dismiss(); + Toast.makeText(mContext, getString(R.string.picture_save_fail), Toast.LENGTH_LONG).show(); + } + } + private void setLoadBtnText(ImageContent ic) { NumberFormat ddf1 = NumberFormat.getNumberInstance(); //保留小数点后两位 @@ -295,7 +351,6 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { /** * 点击发送原图CheckBox,触发事件 - * */ private void checkOriginPictureSelected() { mOriginPictureCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @@ -314,7 +369,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { private void showTotalSize() { if (mSelectMap.size() > 0) { List pathList = new ArrayList(); - for (int i=0; i < mSelectMap.size(); i++) { + for (int i = 0; i < mSelectMap.size(); i++) { pathList.add(mPathList.get(mSelectMap.keyAt(i))); } String totalSize = BitmapLoader.getPictureSize(pathList); @@ -572,7 +627,8 @@ private void getThumbnailPictures(int position) { /** * 根据图片路径生成ImageContent - * @param path 图片路径 + * + * @param path 图片路径 * @param isOriginal 是否发送原图 */ private void createImageContent(String path, final boolean isOriginal) { @@ -584,7 +640,7 @@ private void createImageContent(String path, final boolean isOriginal) { public void gotResult(int status, String desc, ImageContent imageContent) { if (status == 0) { if (isOriginal) { - imageContent.setBooleanExtra("originalPicture" , true); + imageContent.setBooleanExtra("originalPicture", true); } Message msg = mConv.createSendMessage(imageContent); mMsgIds[mIndex] = msg.getId(); @@ -700,10 +756,10 @@ public void onComplete(int status, String desc, File file) { } } - private static class UIHandler extends Handler{ + private static class UIHandler extends Handler { private final WeakReference mActivity; - public UIHandler(BrowserViewPagerActivity activity){ + public UIHandler(BrowserViewPagerActivity activity) { mActivity = new WeakReference(activity); } diff --git a/chatapp/src/main/java/jiguang/chat/controller/ActivityController.java b/chatapp/src/main/java/jiguang/chat/controller/ActivityController.java index 760c99a9..9f8e1efd 100644 --- a/chatapp/src/main/java/jiguang/chat/controller/ActivityController.java +++ b/chatapp/src/main/java/jiguang/chat/controller/ActivityController.java @@ -18,6 +18,7 @@ public static void addActivity(Activity activity) { public static void removeActivity(Activity activity) { activities.remove(activity); + activity.finish(); } public static void finishAll() { diff --git a/chatapp/src/main/java/jiguang/chat/controller/ChatItemController.java b/chatapp/src/main/java/jiguang/chat/controller/ChatItemController.java index 59a4a454..b5e5b3b8 100644 --- a/chatapp/src/main/java/jiguang/chat/controller/ChatItemController.java +++ b/chatapp/src/main/java/jiguang/chat/controller/ChatItemController.java @@ -1138,23 +1138,20 @@ private ImageView setPictureScale(String extra, Message message, String path, fi private ImageView setDensity(String extra, Message message, double imageWidth, double imageHeight, ImageView imageView) { - if (extra == null) { - imageWidth = 90; - imageHeight = 1320; + if (extra != null) { + imageWidth = 200; + imageHeight = 200; } else { - imageWidth = 90; - imageHeight = 100; - } - - if (imageWidth > 150 * mDensity || imageHeight > 200 * mDensity) { - imageHeight = 150 * mDensity; - imageWidth = 100 * mDensity; - } else if (imageHeight == imageWidth) { - imageHeight = 150 * mDensity; - imageWidth = 100 * mDensity; - } else { - imageHeight = imageHeight * (100 * mDensity / imageWidth); - imageWidth = 100 * mDensity; + if (imageWidth > 300) { + imageWidth = 450; + imageHeight = 300; + } else if (imageHeight > 450) { + imageWidth = 300; + imageHeight = 450; + } else { + imageWidth = 300; + imageHeight = 450; + } } ViewGroup.LayoutParams params = imageView.getLayoutParams(); params.width = (int) imageWidth; diff --git a/chatapp/src/main/java/jiguang/chat/pickerimage/PreviewImageFromLocalActivity.java b/chatapp/src/main/java/jiguang/chat/pickerimage/PreviewImageFromLocalActivity.java deleted file mode 100644 index df2638b7..00000000 --- a/chatapp/src/main/java/jiguang/chat/pickerimage/PreviewImageFromLocalActivity.java +++ /dev/null @@ -1,398 +0,0 @@ -package jiguang.chat.pickerimage; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Intent; -import android.graphics.Bitmap; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.Handler; -import android.support.v4.view.ViewPager; -import android.support.v4.view.ViewPager.OnPageChangeListener; -import android.text.TextUtils; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.ImageButton; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import java.io.File; -import java.util.ArrayList; - -import jiguang.chat.R; -import jiguang.chat.pickerimage.adapter.ImagePagerAdapterInImageSwitch; -import jiguang.chat.pickerimage.utils.AttachmentStore; -import jiguang.chat.pickerimage.utils.BitmapDecoder; -import jiguang.chat.pickerimage.utils.EasyAlertDialog; -import jiguang.chat.pickerimage.utils.Extras; -import jiguang.chat.pickerimage.utils.FileUtil; -import jiguang.chat.pickerimage.utils.ImageUtil; -import jiguang.chat.pickerimage.utils.RequestCode; -import jiguang.chat.pickerimage.utils.StorageType; -import jiguang.chat.pickerimage.utils.StorageUtil; -import jiguang.chat.pickerimage.view.BaseZoomableImageView; -import jiguang.chat.pickerimage.view.UIView; - -public class PreviewImageFromLocalActivity extends UIView { - - private boolean needShowSendOriginal = false; - - private ImageButton originalImage; - - private boolean isSendOriginalImage; - - private TextView originalImageSizeTip; - - private File imageFile; - - private ArrayList selectImageList; - - private ArrayList origImageList; - - protected ViewPager imageViewPager; - - private ImagePagerAdapterInImageSwitch imageViewPagerAdapter; - - protected BaseZoomableImageView currentImageView; - - protected int currentPostion = -1; - - private int tempIndex = -1; - - private View sendButton; - - public static Intent initPreviewImageIntent( - ArrayList thumbnailImageList, - ArrayList orignialImageList, - boolean isOrignial - ) { - Intent intent = new Intent(); - intent.putStringArrayListExtra(Extras.EXTRA_SCALED_IMAGE_LIST, thumbnailImageList); - intent.putStringArrayListExtra(Extras.EXTRA_ORIG_IMAGE_LIST, orignialImageList); - intent.putExtra(Extras.EXTRA_IS_ORIGINAL, isOrignial); - return intent; - } - - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.preview_image_from_local_activity); - - originalImageSizeTip = (TextView) findViewById(R.id.picker_image_preview_orignal_image_tip); - originalImage = (ImageButton) findViewById(R.id.picker_image_preview_orignal_image); - originalImage.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - isSendOriginalImage = !isSendOriginalImage; - updateOriImageSizeTip(isSendOriginalImage); - } - }); - - needShowSendOriginal = getIntent().getBooleanExtra(Extras.EXTRA_NEED_SHOW_SEND_ORIGINAL, false); - if (needShowSendOriginal) { - originalImage.setVisibility(View.VISIBLE); - originalImageSizeTip.setVisibility(View.VISIBLE); - } else { - originalImage.setVisibility(View.INVISIBLE); - originalImageSizeTip.setVisibility(View.INVISIBLE); - } - - sendButton = findViewById(R.id.buttonSend); - sendButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - //发送原图还是缩略图 - if (isSendOriginalImage) { - sendOrigImage(); - } else { - sendSelectedImage(false); - } - } - }); - - initViewPager(); - } - - private void restoreList() { - if (tempIndex != -1) { - imageViewPager.setAdapter(imageViewPagerAdapter); - setTitleIndex(tempIndex); - imageViewPager.setCurrentItem(tempIndex); - tempIndex = -1; - } - } - - private void setTitleIndex(int index) { - if (selectImageList.size() <= 0) { - setTitle(""); - } - else { - index++; - setTitle(index + "/" + selectImageList.size()); - } - } - - private void sendSelectedImage(boolean isOrig) { - Intent intent = initPreviewImageIntent(selectImageList, origImageList, isOrig); - intent.setClass(PreviewImageFromLocalActivity.this, getIntent().getClass()); - setResult(RESULT_OK, intent); - PreviewImageFromLocalActivity.this.finish(); - } - - @SuppressLint("NewApi") - private void sendOrigImage() { - final UIView activity = PreviewImageFromLocalActivity.this; - final EasyAlertDialog allAlertDialog = new EasyAlertDialog(activity); - allAlertDialog.setTitle(getString(R.string.picker_image_preview_original)); - - long fileSize = 0; - for (String filepath : origImageList) { - fileSize += AttachmentStore.getFileLength(filepath); - } - - if (origImageList.size() == 1) { - allAlertDialog.setMessage(getString(R.string.image_compressed_size, FileUtil.formatFileSize(fileSize)) - + getString(R.string.is_send_image)); - } else { - allAlertDialog.setMessage(getString(R.string.multi_image_compressed_size, - FileUtil.formatFileSize(fileSize)) - + getString(R.string.is_send_multi_image)); - } - - allAlertDialog.addPositiveButton(getString(R.string.ok), EasyAlertDialog.NO_TEXT_COLOR, EasyAlertDialog.NO_TEXT_SIZE, - new OnClickListener() { - @Override - public void onClick(View view) { - sendSelectedImage(true); - } - }); - allAlertDialog.addNegativeButton(getString(R.string.cancel), EasyAlertDialog.NO_TEXT_COLOR, - EasyAlertDialog.NO_TEXT_SIZE, new OnClickListener() { - @Override - public void onClick(View view) { - allAlertDialog.dismiss(); - } - }); - if (!activity.isDestroyedCompatible()) { - allAlertDialog.show(); - } - } - - private void updateOriImageSizeTip(boolean isOrig){ - if(origImageList == null) - return; - if(isOrig){ - long totalSize = 0; - - for (String filepath : origImageList) { - totalSize += AttachmentStore.getFileLength(filepath); - } - originalImageSizeTip.setText(String.format(this.getResources().getString( - R.string.picker_image_preview_original_select), FileUtil.formatFileSize(totalSize))); - originalImage.setImageResource(R.drawable.picker_orignal_checked); - }else{ - originalImageSizeTip.setText(R.string.picker_image_preview_original); - originalImage.setImageResource(R.drawable.picker_orignal_normal); - } - } - - /** - * 初始化图片查看 - */ - private void initViewPager() { - imageViewPager = (ViewPager) findViewById(R.id.viewPagerImage); - imageViewPager.setOnPageChangeListener(new OnPageChangeListener() { - @Override - public void onPageScrollStateChanged(int arg0) { - } - - @Override - public void onPageScrolled(int arg0, float arg1, int arg2) { - } - - @Override - public void onPageSelected(int arg0) { - setTitleIndex(arg0); - } - }); - imageViewPager.setOffscreenPageLimit(2); - - String imageFilePath = getIntent().getExtras().getString("ImageFilePath"); - String origImageFilePath = getIntent().getExtras().getString("OrigImageFilePath"); - - imageFile = new File(imageFilePath); - - selectImageList = new ArrayList(); - selectImageList.add(imageFilePath); - - origImageList = new ArrayList(); - origImageList.add(origImageFilePath); - - imageViewPagerAdapter = new ImagePagerAdapterInImageSwitch(this, selectImageList, getLayoutInflater(), - imageViewPager.getLayoutParams().width, imageViewPager.getLayoutParams().height, this); - imageViewPager.setAdapter(imageViewPagerAdapter); - } - - @Override - public void onBackPressed() { - deleteTempFiles(); - - Intent intent = new Intent(); - intent.setClass(PreviewImageFromLocalActivity.this, getIntent().getClass()); - setResult(RESULT_CANCELED, intent); - PreviewImageFromLocalActivity.this.finish(); - } - - @Override - public void onResume() { - // restore the data source - restoreList(); - - super.onResume(); - } - - @Override - public void onPause() { - // recycleBitmap(previewImageView); - - // save the data source and recycle all bitmaps - imageViewPager.setAdapter(null); - tempIndex = currentPostion; - currentPostion = -1; - - super.onPause(); - } - - /** - * 获取本地图片 - */ - protected void choosePictureFromLocal() { - if (!StorageUtil.hasEnoughSpaceForWrite(PreviewImageFromLocalActivity.this, StorageType.TYPE_IMAGE, true)) { - return; - } - - new AsyncTask() { - @Override - protected void onPreExecute() { - Toast.makeText(PreviewImageFromLocalActivity.this, R.string.waitfor_image_local, Toast.LENGTH_LONG).show(); - } - - @Override - protected Boolean doInBackground(String... params) { - return true; - } - - @Override - protected void onPostExecute(Boolean result) { - int from = PickImageActivity.FROM_LOCAL; - Activity thiz = PreviewImageFromLocalActivity.this; - PickImageActivity.start(thiz, RequestCode.GET_LOCAL_IMAGE, from, ""); - } - }.execute(); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode != RESULT_CANCELED) { - if (requestCode == RequestCode.GET_LOCAL_IMAGE) { - onGetLocalPictureResult(requestCode, resultCode, data); - } - } else { - if (selectImageList.size() == 0) { - sendButton.setEnabled(false); - } - } - } - - public void onGetLocalPictureResult(int requestCode, int resultCode, final Intent data) { - if (data == null) { - return; - } - final String photoPath = data.getStringExtra(Extras.EXTRA_FILE_PATH); - if (TextUtils.isEmpty(photoPath)) { - return; - } - - imageFile = new File(photoPath); - String mimeType = FileUtil.getExtensionName(photoPath); - imageFile = ImageUtil.getScaledImageFileWithMD5(imageFile, mimeType); - if (imageFile == null) { - Toast.makeText(this, R.string.picker_image_error, Toast.LENGTH_LONG).show(); - return; - } else { - ImageUtil.makeThumbnail(PreviewImageFromLocalActivity.this, - imageFile); - } - - origImageList.add(photoPath); - selectImageList.add(imageFile.getAbsolutePath()); - imageViewPagerAdapter.notifyDataSetChanged(); - - final Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - imageViewPager.setCurrentItem(selectImageList.size() - 1); - } - }, 100); - //有可用的图片 - if(selectImageList.size() >= 1){ - sendButton.setEnabled(true); - } - } - - public void updateCurrentImageView(final int position) { - if (selectImageList == null - || (position > 0 - && position >= selectImageList.size())) - return; - - if (currentPostion == position) { - return; - } else { - currentPostion = position; - } - setTitleIndex(position); - - // LinearLayout currentLayout = (LinearLayout) - // imageViewPager.getChildAt(position); - LinearLayout currentLayout = (LinearLayout) imageViewPager.findViewWithTag(position); - - if (currentLayout == null) { - Handler mHandler = new Handler(); - mHandler.postDelayed(new Runnable() { - @Override - public void run() { - updateCurrentImageView(position); - } - }, 300); - return; - } - currentImageView = (BaseZoomableImageView) currentLayout.findViewById(R.id.imageView); - currentImageView.setViewPager(imageViewPager); - - setImageView(selectImageList.get(position)); - } - - public void setImageView(String imageFilePath) { - if (imageFilePath == null) { - return; - } - - Bitmap bitmap = BitmapDecoder.decodeSampledForDisplay(imageFilePath); - if (bitmap == null) { - currentImageView.setImageBitmap(ImageUtil.getDefaultBitmapWhenGetFail()); - Toast.makeText(this, R.string.picker_image_error, Toast.LENGTH_LONG).show(); - } else { - currentImageView.setImageBitmap(bitmap); - } - } - - private void deleteTempFiles() { - for (String file : selectImageList) { - new File(file).delete(); - } - } -} diff --git a/chatapp/src/main/java/jiguang/chat/pickerimage/adapter/ImagePagerAdapterInImageSwitch.java b/chatapp/src/main/java/jiguang/chat/pickerimage/adapter/ImagePagerAdapterInImageSwitch.java deleted file mode 100644 index 1d3e9612..00000000 --- a/chatapp/src/main/java/jiguang/chat/pickerimage/adapter/ImagePagerAdapterInImageSwitch.java +++ /dev/null @@ -1,85 +0,0 @@ -package jiguang.chat.pickerimage.adapter; - -import android.content.Context; -import android.os.Build; -import android.support.v4.view.PagerAdapter; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import java.util.List; - -import jiguang.chat.R; -import jiguang.chat.pickerimage.PreviewImageFromLocalActivity; -import jiguang.chat.pickerimage.utils.ScreenUtil; -import jiguang.chat.pickerimage.view.BaseZoomableImageView; -import jiguang.chat.pickerimage.view.UIView; - -public class ImagePagerAdapterInImageSwitch extends PagerAdapter { - private Context mContext; - private List mList; - private LayoutInflater mInflater; - private int viewPagerWidth, viewPagerHeight; - private UIView mActivity; - - public ImagePagerAdapterInImageSwitch(Context cx, List list, LayoutInflater inflater, int width, int height, UIView activity) { - mContext = cx; - mList = list; - mInflater = inflater; - viewPagerHeight = height; - viewPagerWidth = width; - mActivity = activity; - } - - @Override - public void destroyItem (ViewGroup container, int position, Object object) { - View layout = (View)object; - BaseZoomableImageView iv = (BaseZoomableImageView)layout.findViewById(R.id.imageView); - iv.clear(); - container.removeView(layout); - } - - @Override - public int getCount() { - return mList == null ? 0 : mList.size(); - } - - @Override - public boolean isViewFromObject(View arg0, Object arg1) { - // TODO Auto-generated method stub - return (arg0 == arg1); - } - - @Override - public Object instantiateItem (ViewGroup container, int position) { -// ImageView iv = new ImageView(mContext); - View layout = null; - -// if( Build.VERSION.SDK_INT >= 17 ) - if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ) - { - layout = mInflater.inflate(R.layout.preview_image_layout_multi_touch, null); - } - else - { - layout = mInflater.inflate(R.layout.preview_image_layout_zoom_control, null); - } - - container.addView(layout); - layout.setTag(position); - viewPagerWidth = ScreenUtil.screenWidth; - viewPagerHeight = ScreenUtil.screenHeight; - - return layout; - } - - @Override - public int getItemPosition(Object object) { - return POSITION_NONE; - } - - @Override - public void setPrimaryItem (View container, int position, Object object) { - ((PreviewImageFromLocalActivity) mActivity).updateCurrentImageView(position); - } -} diff --git a/chatapp/src/main/java/jiguang/chat/pickerimage/utils/StorageUtil.java b/chatapp/src/main/java/jiguang/chat/pickerimage/utils/StorageUtil.java index 368085a7..4db65b82 100644 --- a/chatapp/src/main/java/jiguang/chat/pickerimage/utils/StorageUtil.java +++ b/chatapp/src/main/java/jiguang/chat/pickerimage/utils/StorageUtil.java @@ -103,22 +103,13 @@ public static String getWritePath(Context context, String fileName, StorageType return getWritePath(context, fileName, fileType, true); } - public static String getDirectoryByDirType(StorageType fileType) { - return ExternalStorage.getInstance().getDirectoryByDirType(fileType); - } - public static String getSystemImagePath() { if (Build.VERSION.SDK_INT > 7) { String picturePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath(); - return picturePath + "/nim/"; + return picturePath + "/im/"; } else { String picturePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath(); - return picturePath + "/nim/"; + return picturePath + "/im/"; } } - - public static boolean isInvalidVideoFile(String filePath) { - return filePath.toLowerCase().endsWith(".3gp") - || filePath.toLowerCase().endsWith(".mp4"); - } } diff --git a/chatapp/src/main/java/jiguang/chat/utils/DialogCreator.java b/chatapp/src/main/java/jiguang/chat/utils/DialogCreator.java index 373ea472..d323c7b3 100644 --- a/chatapp/src/main/java/jiguang/chat/utils/DialogCreator.java +++ b/chatapp/src/main/java/jiguang/chat/utils/DialogCreator.java @@ -109,6 +109,22 @@ public static Dialog createDelConversationDialog(Context context, dialog.setCanceledOnTouchOutside(true); return dialog; } + public static Dialog createSavePictureDialog(Context context, + View.OnClickListener listener) { + Dialog dialog = new Dialog(context, IdHelper.getStyle(context, "jmui_default_dialog_style")); + View v = LayoutInflater.from(context).inflate( + IdHelper.getLayout(context, "jmui_dialog_delete_conv"), null); + dialog.setContentView(v); + final LinearLayout deleteLl = (LinearLayout) v.findViewById(IdHelper + .getViewID(context, "jmui_delete_conv_ll")); + TextView textView = (TextView) v.findViewById(IdHelper.getViewID(context, "tv_dialogText")); + textView.setText("保存到手机"); + + deleteLl.setOnClickListener(listener); + dialog.setCancelable(true); + dialog.setCanceledOnTouchOutside(true); + return dialog; + } public static Dialog createDelRecommendDialog(Context context, View.OnClickListener listener) { Dialog dialog = new Dialog(context, IdHelper.getStyle(context, "jmui_default_dialog_style")); diff --git a/chatapp/src/main/res/layout/jmui_dialog_delete_conv.xml b/chatapp/src/main/res/layout/jmui_dialog_delete_conv.xml index 4d2a3537..5a1b14ac 100644 --- a/chatapp/src/main/res/layout/jmui_dialog_delete_conv.xml +++ b/chatapp/src/main/res/layout/jmui_dialog_delete_conv.xml @@ -33,6 +33,7 @@ android:background="@drawable/white_btn_selector"> - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/chatapp/src/main/res/values/strings.xml b/chatapp/src/main/res/values/strings.xml index 920db80a..5b163cc1 100644 --- a/chatapp/src/main/res/values/strings.xml +++ b/chatapp/src/main/res/values/strings.xml @@ -65,6 +65,9 @@ 转发 已复制 删除 + 保存到手机 + 图片保存失败 + 图片已保存到手机 删除该聊天 创建文件失败 按住 说话