Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
罗孟伟 committed Mar 28, 2018
1 parent 956d82c commit d1fb94b
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.widget.Toast;

import com.luck.picture.lib.compress.Luban;
import com.luck.picture.lib.compress.OnCompressListener;
Expand Down Expand Up @@ -149,10 +148,6 @@ protected void startActivity(Class clz, Bundle bundle, int requestCode) {
}
}

protected void showToast(String msg) {
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}

/**
* loading dialog
*/
Expand Down Expand Up @@ -278,7 +273,7 @@ private void handleCompressCallBack(List<LocalMedia> images, List<File> files) {
}
}
RxBus.getDefault().post(new EventEntity(PictureConfig.CLOSE_PREVIEW_FLAG));
//onResult(images);
onResult(images);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.luck.picture.lib.photoview.PhotoView;
import com.luck.picture.lib.tools.PictureFileUtils;
import com.luck.picture.lib.tools.ScreenUtils;
import com.luck.picture.lib.tools.ToastManage;
import com.luck.picture.lib.widget.PreviewViewPager;
import com.luck.picture.lib.widget.longimage.ImageSource;
import com.luck.picture.lib.widget.longimage.ImageViewState;
Expand Down Expand Up @@ -245,7 +246,7 @@ public void onNext(Boolean aBoolean) {
if (aBoolean) {
showDownLoadDialog(path);
} else {
showToast(getString(R.string.picture_jurisdiction));
ToastManage.s(mContext, getString(R.string.picture_jurisdiction));
}
}

Expand Down Expand Up @@ -316,10 +317,10 @@ public void onClick(View view) {
String dirPath = PictureFileUtils.createDir(PictureExternalPreviewActivity.this,
System.currentTimeMillis() + ".png", directory_path);
PictureFileUtils.copyFile(path, dirPath);
showToast(getString(R.string.picture_save_success) + "\n" + dirPath);
ToastManage.s(mContext, getString(R.string.picture_save_success) + "\n" + dirPath);
dismissDialog();
} catch (IOException e) {
showToast(getString(R.string.picture_save_error) + "\n" + e.getMessage());
ToastManage.s(mContext, getString(R.string.picture_save_error) + "\n" + e.getMessage());
dismissDialog();
e.printStackTrace();
}
Expand All @@ -340,6 +341,7 @@ public loadDataThread(String path) {
this.path = path;
}

@Override
public void run() {
try {
showLoadingImage(path);
Expand Down Expand Up @@ -375,7 +377,7 @@ public void showLoadingImage(String urlPath) {
message.obj = path;
handler.sendMessage(message);
} catch (IOException e) {
showToast(getString(R.string.picture_save_error) + "\n" + e.getMessage());
ToastManage.s(mContext, getString(R.string.picture_save_error) + "\n" + e.getMessage());
e.printStackTrace();
}
}
Expand All @@ -388,7 +390,7 @@ public void handleMessage(Message msg) {
switch (msg.what) {
case 200:
String path = (String) msg.obj;
showToast(getString(R.string.picture_save_success) + "\n" + path);
ToastManage.s(mContext, getString(R.string.picture_save_success) + "\n" + path);
dismissDialog();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.luck.picture.lib.rxbus2.Subscribe;
import com.luck.picture.lib.rxbus2.ThreadMode;
import com.luck.picture.lib.tools.ScreenUtils;
import com.luck.picture.lib.tools.ToastManage;
import com.luck.picture.lib.tools.VoiceUtils;
import com.luck.picture.lib.widget.PreviewViewPager;
import com.yalantis.ucrop.UCrop;
Expand Down Expand Up @@ -130,7 +131,7 @@ public void onClick(View view) {
boolean toEqual = PictureMimeType.
mimeToEqual(pictureType, image.getPictureType());
if (!toEqual) {
showToast(getString(R.string.picture_rule));
ToastManage.s(mContext,getString(R.string.picture_rule));
return;
}
}
Expand All @@ -145,7 +146,7 @@ public void onClick(View view) {
check.setSelected(false);
}
if (selectImages.size() >= config.maxSelectNum && isChecked) {
showToast(getString(R.string.picture_message_max_num, config.maxSelectNum));
ToastManage.s(mContext, getString(R.string.picture_message_max_num, config.maxSelectNum));
check.setSelected(false);
return;
}
Expand Down Expand Up @@ -401,7 +402,7 @@ public void onClick(View view) {
boolean eqImg = pictureType.startsWith(PictureConfig.IMAGE);
String str = eqImg ? getString(R.string.picture_min_img_num, config.minSelectNum)
: getString(R.string.picture_min_video_num, config.minSelectNum);
showToast(str);
ToastManage.s(mContext,str);
return;
}
}
Expand Down Expand Up @@ -453,7 +454,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
} else if (resultCode == UCrop.RESULT_ERROR) {
Throwable throwable = (Throwable) data.getSerializableExtra(UCrop.EXTRA_ERROR);
showToast(throwable.getMessage());
ToastManage.s(mContext,throwable.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.luck.picture.lib.tools.PictureFileUtils;
import com.luck.picture.lib.tools.ScreenUtils;
import com.luck.picture.lib.tools.StringUtils;
import com.luck.picture.lib.tools.ToastManage;
import com.luck.picture.lib.widget.FolderPopWindow;
import com.luck.picture.lib.widget.PhotoPopupWindow;
import com.yalantis.ucrop.UCrop;
Expand Down Expand Up @@ -160,7 +161,7 @@ public void onNext(Boolean aBoolean) {
if (aBoolean) {
onTakePhoto();
} else {
showToast(getString(R.string.picture_camera));
ToastManage.s(mContext, getString(R.string.picture_camera));
closeActivity();
}
}
Expand Down Expand Up @@ -244,7 +245,7 @@ public void onNext(Boolean aBoolean) {
mHandler.sendEmptyMessage(SHOW_DIALOG);
readLocalMedia();
} else {
showToast(getString(R.string.picture_jurisdiction));
ToastManage.s(mContext, getString(R.string.picture_jurisdiction));
}
}

Expand Down Expand Up @@ -421,7 +422,7 @@ public void onNext(Boolean aBoolean) {
startActivityForResult(cameraIntent, PictureConfig.REQUEST_CAMERA);
}
} else {
showToast(getString(R.string.picture_audio));
ToastManage.s(mContext, getString(R.string.picture_audio));
}
}

Expand Down Expand Up @@ -503,7 +504,7 @@ public void onClick(View v) {
if (size < config.minSelectNum) {
String str = eqImg ? getString(R.string.picture_min_img_num, config.minSelectNum)
: getString(R.string.picture_min_video_num, config.minSelectNum);
showToast(str);
ToastManage.s(mContext,str);
return;
}
}
Expand Down Expand Up @@ -757,7 +758,7 @@ public void onNext(Boolean aBoolean) {
if (aBoolean) {
startCamera();
} else {
showToast(getString(R.string.picture_camera));
ToastManage.s(mContext,getString(R.string.picture_camera));
if (config.camera) {
closeActivity();
}
Expand Down Expand Up @@ -1030,7 +1031,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
} else if (resultCode == UCrop.RESULT_ERROR) {
Throwable throwable = (Throwable) data.getSerializableExtra(UCrop.EXTRA_ERROR);
showToast(throwable.getMessage());
ToastManage.s(mContext, throwable.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
Expand All @@ -28,6 +27,7 @@
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.tools.DateUtils;
import com.luck.picture.lib.tools.StringUtils;
import com.luck.picture.lib.tools.ToastManage;
import com.luck.picture.lib.tools.VoiceUtils;

import java.io.File;
Expand Down Expand Up @@ -166,6 +166,7 @@ public void onClick(View v) {

final int mediaMimeType = PictureMimeType.isPictureType(pictureType);
boolean gif = PictureMimeType.isGif(pictureType);

contentHolder.tv_isGif.setVisibility(gif ? View.VISIBLE : View.GONE);
if (mimeType == PictureMimeType.ofAudio()) {
contentHolder.tv_duration.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -205,9 +206,7 @@ public void onClick(View v) {
public void onClick(View v) {
// 如原图路径不存在或者路径存在但文件不存在
if (!new File(path).exists()) {
Toast.makeText(context.getApplicationContext(),
context.getString(R.string.picture_error), Toast.LENGTH_LONG)
.show();
ToastManage.s(context, PictureMimeType.s(context, mediaMimeType));
return;
}
changeCheckboxState(contentHolder, image);
Expand All @@ -219,9 +218,7 @@ public void onClick(View v) {
public void onClick(View v) {
// 如原图路径不存在或者路径存在但文件不存在
if (!new File(path).exists()) {
Toast.makeText(context.getApplicationContext(),
context.getString(R.string.picture_error), Toast.LENGTH_LONG)
.show();
ToastManage.s(context, PictureMimeType.s(context, mediaMimeType));
return;
}
int index = showCamera ? position - 1 : position;
Expand Down Expand Up @@ -317,16 +314,15 @@ private void changeCheckboxState(ViewHolder contentHolder, LocalMedia image) {
if (!TextUtils.isEmpty(pictureType)) {
boolean toEqual = PictureMimeType.mimeToEqual(pictureType, image.getPictureType());
if (!toEqual) {
Toast.makeText(context.getApplicationContext(), context.getString(R.string.picture_rule), Toast.LENGTH_LONG)
.show();
ToastManage.s(context, context.getString(R.string.picture_rule));
return;
}
}
if (selectImages.size() >= maxSelectNum && !isChecked) {
boolean eqImg = pictureType.startsWith(PictureConfig.IMAGE);
String str = eqImg ? context.getString(R.string.picture_message_max_num, maxSelectNum)
: context.getString(R.string.picture_message_video_max_num, maxSelectNum);
Toast.makeText(context.getApplicationContext(), str, Toast.LENGTH_LONG).show();
ToastManage.s(context, str);
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.luck.picture.lib.config;


import android.content.Context;
import android.media.MediaMetadataRetriever;
import android.text.TextUtils;

import com.luck.picture.lib.R;
import com.luck.picture.lib.entity.LocalMedia;

import java.io.File;
Expand Down Expand Up @@ -298,6 +300,26 @@ public static String getLastImgType(String path) {
}
}

/**
* 根据不同的类型,返回不同的错误提示
*
* @param mediaMimeType
* @return
*/
public static String s(Context context, int mediaMimeType) {
Context ctx = context.getApplicationContext();
switch (mediaMimeType) {
case PictureConfig.TYPE_IMAGE:
return ctx.getString(R.string.picture_error);
case PictureConfig.TYPE_VIDEO:
return ctx.getString(R.string.picture_video_error);
case PictureConfig.TYPE_AUDIO:
return ctx.getString(R.string.picture_audio_error);
default:
return ctx.getString(R.string.picture_error);
}
}

public final static String JPEG = ".JPEG";

public final static String PNG = ".png";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.luck.picture.lib.tools;

import android.content.Context;
import android.widget.Toast;

/**
* @author:luck
* @data:2018/3/28 下午4:10
* @描述: Toast工具类
*/

public final class ToastManage {

public static void s(Context mContext, String s) {
Toast.makeText(mContext.getApplicationContext(), s, Toast.LENGTH_LONG)
.show();
}
}
2 changes: 2 additions & 0 deletions picture_library/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
<string name="picture_quit_audio">Quit</string>
<string name="picture_pause_audio">Pause</string>
<string name="picture_error">The picture is corrupted</string>
<string name="picture_video_error">The video is corrupted</string>
<string name="picture_audio_error">The audio is corrupted</string>
<string name="picture_confirm">Cancel</string>
</resources>
2 changes: 2 additions & 0 deletions picture_library/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@
<string name="picture_quit_audio">退出</string>
<string name="picture_pause_audio">暂停</string>
<string name="picture_error">图片已损坏</string>
<string name="picture_video_error">视频已损坏</string>
<string name="picture_audio_error">音频已损坏</string>
<string name="picture_confirm">确定</string>
</resources>
2 changes: 2 additions & 0 deletions picture_library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@
<string name="picture_quit_audio">退出</string>
<string name="picture_pause_audio">暂停</string>
<string name="picture_error">图片已损坏</string>
<string name="picture_video_error">视频已损坏</string>
<string name="picture_audio_error">音频已损坏</string>
<string name="picture_confirm">确定</string>
</resources>

0 comments on commit d1fb94b

Please sign in to comment.