Commit 34c4b7cd1c298beca5d57442b20348f99b000d75
1 parent
324693cab8
Exists in
master
BUG修改
Showing
6 changed files
with
157 additions
and
58 deletions
Show diff stats
app/src/main/java/com/hjx/parent/AddSuccessActivity.java
| 1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
| 2 | 2 | ||
| 3 | import android.content.Intent; | 3 | import android.content.Intent; |
| 4 | import android.graphics.Bitmap; | 4 | import android.graphics.Bitmap; |
| 5 | import android.graphics.BitmapFactory; | 5 | import android.graphics.BitmapFactory; |
| 6 | import android.net.Uri; | 6 | import android.net.Uri; |
| 7 | import android.os.Bundle; | 7 | import android.os.Bundle; |
| 8 | import android.provider.MediaStore; | 8 | import android.provider.MediaStore; |
| 9 | import android.text.TextUtils; | 9 | import android.text.TextUtils; |
| 10 | import android.util.Log; | 10 | import android.util.Log; |
| 11 | import android.view.LayoutInflater; | 11 | import android.view.LayoutInflater; |
| 12 | import android.view.View; | 12 | import android.view.View; |
| 13 | 13 | ||
| 14 | import androidx.annotation.Nullable; | 14 | import androidx.annotation.Nullable; |
| 15 | import androidx.core.content.FileProvider; | 15 | import androidx.core.content.FileProvider; |
| 16 | 16 | ||
| 17 | import com.hjx.parent.databinding.ActivityAddSuccessBinding; | 17 | import com.hjx.parent.databinding.ActivityAddSuccessBinding; |
| 18 | import com.prws.common.utils.BitmapUtils; | 18 | import com.prws.common.utils.BitmapUtils; |
| 19 | import com.prws.common.utils.CommonUtil; | 19 | import com.prws.common.utils.CommonUtil; |
| 20 | import com.prws.common.utils.dialog.MyButtomDialog; | 20 | import com.prws.common.utils.dialog.MyButtomDialog; |
| 21 | import com.zhangteng.imagepicker.bean.ImageInfo; | 21 | import com.zhangteng.imagepicker.bean.ImageInfo; |
| 22 | import com.zhangteng.imagepicker.config.ImagePickerConfig; | 22 | import com.zhangteng.imagepicker.config.ImagePickerConfig; |
| 23 | import com.zhangteng.imagepicker.config.ImagePickerEnum; | 23 | import com.zhangteng.imagepicker.config.ImagePickerEnum; |
| 24 | import com.zhangteng.imagepicker.config.ImagePickerOpen; | 24 | import com.zhangteng.imagepicker.config.ImagePickerOpen; |
| 25 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; | 25 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; |
| 26 | import com.zhangteng.utils.IHandlerCallBack; | 26 | import com.zhangteng.utils.IHandlerCallBack; |
| 27 | 27 | ||
| 28 | import java.io.File; | 28 | import java.io.File; |
| 29 | import java.util.ArrayList; | 29 | import java.util.ArrayList; |
| 30 | import java.util.List; | 30 | import java.util.List; |
| 31 | 31 | ||
| 32 | public class AddSuccessActivity extends BaseActivity<ActivityAddSuccessBinding> { | 32 | public class AddSuccessActivity extends BaseActivity<ActivityAddSuccessBinding> { |
| 33 | private int REQUEST_CODE_IMAGE = 123; | 33 | private int REQUEST_CODE_IMAGE = 123; |
| 34 | private String filePath; | 34 | private String filePath; |
| 35 | 35 | ||
| 36 | @Override | 36 | @Override |
| 37 | public void initView(Bundle savedInstanceState) { | 37 | public void initView(Bundle savedInstanceState) { |
| 38 | binding.ivBack.setOnClickListener(new View.OnClickListener() { | 38 | binding.ivBack.setOnClickListener(new View.OnClickListener() { |
| 39 | @Override | 39 | @Override |
| 40 | public void onClick(View v) { | 40 | public void onClick(View v) { |
| 41 | finish(); | 41 | finish(); |
| 42 | } | 42 | } |
| 43 | }); | 43 | }); |
| 44 | binding.tvAdd.setOnClickListener(new View.OnClickListener() { | 44 | binding.tvAdd.setOnClickListener(new View.OnClickListener() { |
| 45 | @Override | 45 | @Override |
| 46 | public void onClick(View v) { | 46 | public void onClick(View v) { |
| 47 | MyButtomDialog dialog = new MyButtomDialog(context, R.style.BottomSheetDialog); | 47 | MyButtomDialog dialog = new MyButtomDialog(context, R.style.BottomSheetDialog); |
| 48 | View bottomView = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_layout, null); | 48 | View bottomView = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_layout, null); |
| 49 | dialog.setContentView(bottomView); | 49 | dialog.setContentView(bottomView); |
| 50 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 50 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
| 51 | @Override | 51 | @Override |
| 52 | public void onClick(View view) { | 52 | public void onClick(View view) { |
| 53 | dialog.dismiss(); | 53 | dialog.dismiss(); |
| 54 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 54 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| 55 | //确保有相机来处理Intent | 55 | //确保有相机来处理Intent |
| 56 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 56 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 57 | File photoFile = new File(filePath); | 57 | File photoFile = new File(filePath); |
| 58 | if (photoFile != null) { | 58 | if (photoFile != null) { |
| 59 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | 59 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri |
| 60 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); | 60 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); |
| 61 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 61 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| 62 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | 62 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); |
| 63 | activity.startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE); | 63 | activity.startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE); |
| 64 | } | 64 | } |
| 65 | } | 65 | } |
| 66 | }); | 66 | }); |
| 67 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 67 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
| 68 | @Override | 68 | @Override |
| 69 | public void onClick(View view) { | 69 | public void onClick(View view) { |
| 70 | dialog.dismiss(); | 70 | dialog.dismiss(); |
| 71 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 | 71 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 |
| 72 | .iHandlerCallBack(new HandlerCallBack()) //图片选择器生命周期监听(直接打开摄像头时无效) | 72 | .iHandlerCallBack(new HandlerCallBack()) //图片选择器生命周期监听(直接打开摄像头时无效) |
| 73 | .multiSelect(true) //是否多选 | 73 | .multiSelect(true) //是否多选 |
| 74 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false | 74 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false |
| 75 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 | 75 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 |
| 76 | .maxImageSelectable(9) //图片可选择数 | 76 | .maxImageSelectable(9) //图片可选择数 |
| 77 | .maxHeight(1920) //图片最大高度 | 77 | .maxHeight(1920) //图片最大高度 |
| 78 | .maxWidth(1920) //图片最大宽度 | 78 | .maxWidth(1920) //图片最大宽度 |
| 79 | .maxImageSize(10) //图片最大大小Mb | 79 | .maxImageSize(10) //图片最大大小Mb |
| 80 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); | 80 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); |
| 81 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(AddSuccessActivity.this); | 81 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(AddSuccessActivity.this); |
| 82 | 82 | ||
| 83 | } | 83 | } |
| 84 | }); | 84 | }); |
| 85 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 85 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
| 86 | @Override | 86 | @Override |
| 87 | public void onClick(View view) { | 87 | public void onClick(View view) { |
| 88 | dialog.dismiss(); | 88 | dialog.dismiss(); |
| 89 | } | 89 | } |
| 90 | }); | 90 | }); |
| 91 | dialog.show(); | 91 | dialog.show(); |
| 92 | } | 92 | } |
| 93 | }); | 93 | }); |
| 94 | binding.tvBook.setOnClickListener(new View.OnClickListener() { | ||
| 95 | @Override | ||
| 96 | public void onClick(View v) { | ||
| 97 | startActivity(new Intent(context, ErrorListActivity.class)); | ||
| 98 | } | ||
| 99 | }); | ||
| 94 | } | 100 | } |
| 95 | 101 | ||
| 96 | @Override | 102 | @Override |
| 97 | protected ActivityAddSuccessBinding getViewBinding() { | 103 | protected ActivityAddSuccessBinding getViewBinding() { |
| 98 | return ActivityAddSuccessBinding.inflate(getLayoutInflater()); | 104 | return ActivityAddSuccessBinding.inflate(getLayoutInflater()); |
| 99 | } | 105 | } |
| 100 | 106 | ||
| 101 | @Override | 107 | @Override |
| 102 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 108 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 103 | super.onActivityResult(requestCode, resultCode, data); | 109 | super.onActivityResult(requestCode, resultCode, data); |
| 104 | if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { | 110 | if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { |
| 105 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); | 111 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
| 106 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 112 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 107 | CommonUtil.saveBitmapToUri(b, path); | 113 | CommonUtil.saveBitmapToUri(b, path); |
| 108 | List<String> strings = new ArrayList<>(); | 114 | List<String> strings = new ArrayList<>(); |
| 109 | Intent intent = new Intent(context, ImageActivity.class); | 115 | Intent intent = new Intent(context, ImageActivity.class); |
| 110 | strings.add(path); | 116 | strings.add(path); |
| 111 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); | 117 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); |
| 112 | startActivity(intent); | 118 | startActivity(intent); |
| 113 | finish(); | 119 | finish(); |
| 114 | } | 120 | } |
| 115 | } | 121 | } |
| 116 | 122 | ||
| 117 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { | 123 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { |
| 118 | private String TAG = "---ImagePicker---"; | 124 | private String TAG = "---ImagePicker---"; |
| 119 | List<ImageInfo> photoList = new ArrayList<>(); | 125 | List<ImageInfo> photoList = new ArrayList<>(); |
| 120 | 126 | ||
| 121 | @Override | 127 | @Override |
| 122 | public void onStart() { | 128 | public void onStart() { |
| 123 | Log.i(TAG, "onStart: 开启"); | 129 | Log.i(TAG, "onStart: 开启"); |
| 124 | } | 130 | } |
| 125 | 131 | ||
| 126 | @Override | 132 | @Override |
| 127 | public void onSuccess(List<ImageInfo> photoList) { | 133 | public void onSuccess(List<ImageInfo> photoList) { |
| 128 | this.photoList = photoList; | 134 | this.photoList = photoList; |
| 129 | Log.i(TAG, "onSuccess: 返回数据"); | 135 | Log.i(TAG, "onSuccess: 返回数据"); |
| 130 | } | 136 | } |
| 131 | 137 | ||
| 132 | @Override | 138 | @Override |
| 133 | public void onCancel() { | 139 | public void onCancel() { |
| 134 | Log.i(TAG, "onCancel: 取消"); | 140 | Log.i(TAG, "onCancel: 取消"); |
| 135 | } | 141 | } |
| 136 | 142 | ||
| 137 | @Override | 143 | @Override |
| 138 | public void onFinish(List<ImageInfo> selectImage) { | 144 | public void onFinish(List<ImageInfo> selectImage) { |
| 139 | if (selectImage.size() == photoList.size()) { | 145 | if (selectImage.size() == photoList.size()) { |
| 140 | List<String> strings = new ArrayList<>(); | 146 | List<String> strings = new ArrayList<>(); |
| 141 | Intent intent = new Intent(context, ImageActivity.class); | 147 | Intent intent = new Intent(context, ImageActivity.class); |
| 142 | for (ImageInfo imageInfo : selectImage) { | 148 | for (ImageInfo imageInfo : selectImage) { |
| 143 | strings.add(imageInfo.getPath()); | 149 | strings.add(imageInfo.getPath()); |
| 144 | } | 150 | } |
| 145 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); | 151 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); |
| 146 | startActivity(intent); | 152 | startActivity(intent); |
| 147 | finish(); | 153 | finish(); |
| 148 | } | 154 | } |
| 149 | } | 155 | } |
| 150 | 156 | ||
| 151 | @Override | 157 | @Override |
| 152 | public void onError() { | 158 | public void onError() { |
| 153 | Log.i(TAG, "onError: 出错"); | 159 | Log.i(TAG, "onError: 出错"); |
| 154 | } | 160 | } |
| 155 | } | 161 | } |
| 156 | } | 162 | } |
| 157 | 163 |
app/src/main/java/com/hjx/parent/BaseActivity.java
| 1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import static com.xiasuhuei321.loadingdialog.view.LoadingDialog.Speed.SPEED_TWO; | 4 | import static com.xiasuhuei321.loadingdialog.view.LoadingDialog.Speed.SPEED_TWO; |
| 5 | 5 | ||
| 6 | import android.content.Context; | 6 | import android.content.Context; |
| 7 | import android.graphics.Color; | 7 | import android.graphics.Color; |
| 8 | import android.os.Bundle; | 8 | import android.os.Bundle; |
| 9 | import android.view.View; | 9 | import android.view.View; |
| 10 | import android.view.Window; | 10 | import android.view.Window; |
| 11 | import android.view.WindowManager; | 11 | import android.view.WindowManager; |
| 12 | import android.widget.Toast; | 12 | import android.widget.Toast; |
| 13 | 13 | ||
| 14 | import androidx.annotation.Nullable; | 14 | import androidx.annotation.Nullable; |
| 15 | import androidx.appcompat.app.AppCompatActivity; | 15 | import androidx.appcompat.app.AppCompatActivity; |
| 16 | import androidx.viewbinding.ViewBinding; | 16 | import androidx.viewbinding.ViewBinding; |
| 17 | 17 | ||
| 18 | import com.hjx.parent.dialog.TipDialog; | 18 | import com.hjx.parent.dialog.TipDialog; |
| 19 | import com.xiasuhuei321.loadingdialog.view.LoadingDialog; | 19 | import com.xiasuhuei321.loadingdialog.view.LoadingDialog; |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | public abstract class BaseActivity<VB extends ViewBinding> extends AppCompatActivity { | 22 | public abstract class BaseActivity<VB extends ViewBinding> extends AppCompatActivity { |
| 23 | protected Context context; | 23 | protected Context context; |
| 24 | protected AppCompatActivity activity; | 24 | protected AppCompatActivity activity; |
| 25 | protected VB binding; | 25 | protected VB binding; |
| 26 | private LoadingDialog dialog; | 26 | private LoadingDialog dialog; |
| 27 | private TipDialog tipDialog; | 27 | private TipDialog tipDialog; |
| 28 | 28 | ||
| 29 | @Override | 29 | @Override |
| 30 | protected void onCreate(@Nullable Bundle savedInstanceState) { | 30 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 31 | super.onCreate(savedInstanceState); | 31 | super.onCreate(savedInstanceState); |
| 32 | binding = getViewBinding(); | 32 | binding = getViewBinding(); |
| 33 | setContentView(binding.getRoot()); | 33 | setContentView(binding.getRoot()); |
| 34 | showWhiteStatus(); | 34 | showWhiteStatus(); |
| 35 | context = this; | 35 | context = this; |
| 36 | activity = this; | 36 | activity = this; |
| 37 | initView(savedInstanceState); | 37 | initView(savedInstanceState); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | public void showLoadingDialog(String text) { | 41 | public void showLoadingDialog(String text) { |
| 42 | dialog = new LoadingDialog(this); | 42 | dialog = new LoadingDialog(this); |
| 43 | dialog.setLoadingText(text) | 43 | dialog.setLoadingText(text) |
| 44 | .setSuccessText("成功")//显示加载成功时的文字 | 44 | .setSuccessText("成功")//显示加载成功时的文字 |
| 45 | .setFailedText("失败") | 45 | .setFailedText("失败") |
| 46 | .setLoadSpeed(SPEED_TWO) | 46 | .setLoadSpeed(SPEED_TWO) |
| 47 | .show(); | 47 | .show(); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | public void showLoadingDialog(String text, LoadingDialog.DismissListener listener) { | ||
| 51 | if (dialog != null) | ||
| 52 | dialog.close(); | ||
| 53 | dialog = new LoadingDialog(this); | ||
| 54 | dialog.setLoadingText(text) | ||
| 55 | .setSuccessText("成功")//显示加载成功时的文字 | ||
| 56 | .setFailedText("失败") | ||
| 57 | .setLoadSpeed(SPEED_TWO) | ||
| 58 | .show(); | ||
| 59 | dialog.setDimissListener(listener); | ||
| 60 | } | ||
| 61 | |||
| 50 | public void loadFail(String text) { | 62 | public void loadFail(String text) { |
| 51 | dialog.setFailedText(text); | 63 | dialog.setFailedText(text); |
| 52 | dialog.loadFailed(); | 64 | dialog.loadFailed(); |
| 53 | } | 65 | } |
| 54 | 66 | ||
| 55 | public void cancelLoadingDialog() { | 67 | public void cancelLoadingDialog() { |
| 56 | dialog.loadSuccess(); | 68 | dialog.loadSuccess(); |
| 57 | } | 69 | } |
| 58 | 70 | ||
| 59 | public void showWhiteStatus() { | 71 | public void showWhiteStatus() { |
| 60 | Window window = getWindow(); | 72 | Window window = getWindow(); |
| 61 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | 73 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
| 62 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | 74 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
| 63 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | 75 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
| 64 | window.setStatusBarColor(Color.TRANSPARENT); | 76 | window.setStatusBarColor(Color.TRANSPARENT); |
| 65 | } | 77 | } |
| 66 | 78 | ||
| 67 | 79 | ||
| 68 | protected void hideBottomUIMenu() { | 80 | protected void hideBottomUIMenu() { |
| 69 | Window window = getWindow(); | 81 | Window window = getWindow(); |
| 70 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | 82 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
| 71 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | 83 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 72 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | 84 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
| 73 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | 85 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
| 74 | window.setStatusBarColor(Color.TRANSPARENT); | 86 | window.setStatusBarColor(Color.TRANSPARENT); |
| 75 | } | 87 | } |
| 76 | 88 | ||
| 77 | public void showToast(String text) { | 89 | public void showToast(String text) { |
| 78 | Toast.makeText(App.getInstance().getApplicationContext(), text, Toast.LENGTH_SHORT).show(); | 90 | Toast.makeText(App.getInstance().getApplicationContext(), text, Toast.LENGTH_SHORT).show(); |
| 79 | } | 91 | } |
| 80 | 92 | ||
| 81 | public void showTipDialog(String title, String content, String cancel, String confirm, TipDialog.TipDialogInterface tipDialogInterface) { | 93 | public void showTipDialog(String title, String content, String cancel, String confirm, TipDialog.TipDialogInterface tipDialogInterface) { |
| 82 | tipDialog = new TipDialog(context, title, content, confirm, cancel, tipDialogInterface); | 94 | tipDialog = new TipDialog(context, title, content, confirm, cancel, tipDialogInterface); |
| 83 | tipDialog.show(); | 95 | tipDialog.show(); |
| 84 | } | 96 | } |
| 85 | 97 | ||
| 86 | public abstract void initView(Bundle savedInstanceState); | 98 | public abstract void initView(Bundle savedInstanceState); |
| 87 | 99 | ||
| 88 | protected abstract VB getViewBinding(); | 100 | protected abstract VB getViewBinding(); |
| 89 | 101 | ||
| 90 | } | 102 | } |
| 91 | 103 |
app/src/main/java/com/hjx/parent/ErrorListActivity.java
| 1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
| 2 | 2 | ||
| 3 | import android.app.Dialog; | 3 | import android.app.Dialog; |
| 4 | import android.content.DialogInterface; | 4 | import android.content.DialogInterface; |
| 5 | import android.content.Intent; | 5 | import android.content.Intent; |
| 6 | import android.graphics.Bitmap; | 6 | import android.graphics.Bitmap; |
| 7 | import android.graphics.BitmapFactory; | 7 | import android.graphics.BitmapFactory; |
| 8 | import android.graphics.Color; | 8 | import android.graphics.Color; |
| 9 | import android.graphics.drawable.Drawable; | 9 | import android.graphics.drawable.Drawable; |
| 10 | import android.net.Uri; | 10 | import android.net.Uri; |
| 11 | import android.os.Bundle; | 11 | import android.os.Bundle; |
| 12 | import android.provider.MediaStore; | 12 | import android.provider.MediaStore; |
| 13 | import android.text.TextUtils; | 13 | import android.text.TextUtils; |
| 14 | import android.util.Log; | 14 | import android.util.Log; |
| 15 | import android.view.KeyEvent; | 15 | import android.view.KeyEvent; |
| 16 | import android.view.LayoutInflater; | 16 | import android.view.LayoutInflater; |
| 17 | import android.view.View; | 17 | import android.view.View; |
| 18 | import android.widget.CompoundButton; | 18 | import android.widget.CompoundButton; |
| 19 | import android.widget.RadioButton; | 19 | import android.widget.RadioButton; |
| 20 | import android.widget.RadioGroup; | 20 | import android.widget.RadioGroup; |
| 21 | import android.widget.TextView; | 21 | import android.widget.TextView; |
| 22 | import android.widget.Toast; | ||
| 22 | 23 | ||
| 23 | import androidx.annotation.Nullable; | 24 | import androidx.annotation.Nullable; |
| 24 | import androidx.core.content.FileProvider; | 25 | import androidx.core.content.FileProvider; |
| 25 | import androidx.recyclerview.widget.GridLayoutManager; | 26 | import androidx.recyclerview.widget.GridLayoutManager; |
| 26 | import androidx.recyclerview.widget.LinearLayoutManager; | 27 | import androidx.recyclerview.widget.LinearLayoutManager; |
| 27 | import androidx.recyclerview.widget.RecyclerView; | 28 | import androidx.recyclerview.widget.RecyclerView; |
| 28 | 29 | ||
| 29 | import com.google.gson.Gson; | 30 | import com.google.gson.Gson; |
| 31 | import com.hjq.permissions.OnPermissionCallback; | ||
| 32 | import com.hjq.permissions.Permission; | ||
| 33 | import com.hjq.permissions.XXPermissions; | ||
| 30 | import com.hjx.parent.adapter.ErrorAdapter; | 34 | import com.hjx.parent.adapter.ErrorAdapter; |
| 31 | import com.hjx.parent.adapter.FilterAdapter; | 35 | import com.hjx.parent.adapter.FilterAdapter; |
| 32 | import com.hjx.parent.adapter.LoadMoreOnScrollListener; | 36 | import com.hjx.parent.adapter.LoadMoreOnScrollListener; |
| 33 | import com.hjx.parent.bean.StudentBean; | 37 | import com.hjx.parent.bean.StudentBean; |
| 34 | import com.hjx.parent.databinding.ActivityErrorListBinding; | 38 | import com.hjx.parent.databinding.ActivityErrorListBinding; |
| 35 | import com.hjx.parent.dialog.ErrorEditDialog; | 39 | import com.hjx.parent.dialog.ErrorEditDialog; |
| 36 | import com.hjx.parent.dialog.TipDialog; | 40 | import com.hjx.parent.dialog.TipDialog; |
| 37 | import com.prws.common.bean.GradeAndSubject; | 41 | import com.prws.common.bean.GradeAndSubject; |
| 38 | import com.prws.common.bean.PageInfo; | 42 | import com.prws.common.bean.PageInfo; |
| 39 | import com.prws.common.bean.ResponseResult; | 43 | import com.prws.common.bean.ResponseResult; |
| 40 | import com.prws.common.bean.Subject; | 44 | import com.prws.common.bean.Subject; |
| 41 | import com.prws.common.bean.TopicBean; | 45 | import com.prws.common.bean.TopicBean; |
| 42 | import com.prws.common.net.NetWorks; | 46 | import com.prws.common.net.NetWorks; |
| 43 | import com.prws.common.utils.BitmapUtils; | 47 | import com.prws.common.utils.BitmapUtils; |
| 44 | import com.prws.common.utils.CommonUtil; | 48 | import com.prws.common.utils.CommonUtil; |
| 45 | import com.prws.common.utils.SharedPreferencesUtil; | 49 | import com.prws.common.utils.SharedPreferencesUtil; |
| 46 | import com.prws.common.utils.dialog.MyButtomDialog; | 50 | import com.prws.common.utils.dialog.MyButtomDialog; |
| 47 | import com.zhangteng.imagepicker.bean.ImageInfo; | 51 | import com.zhangteng.imagepicker.bean.ImageInfo; |
| 48 | import com.zhangteng.imagepicker.config.ImagePickerConfig; | 52 | import com.zhangteng.imagepicker.config.ImagePickerConfig; |
| 49 | import com.zhangteng.imagepicker.config.ImagePickerEnum; | 53 | import com.zhangteng.imagepicker.config.ImagePickerEnum; |
| 50 | import com.zhangteng.imagepicker.config.ImagePickerOpen; | 54 | import com.zhangteng.imagepicker.config.ImagePickerOpen; |
| 51 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; | 55 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; |
| 52 | import com.zhangteng.utils.IHandlerCallBack; | 56 | import com.zhangteng.utils.IHandlerCallBack; |
| 53 | 57 | ||
| 54 | import java.io.File; | 58 | import java.io.File; |
| 55 | import java.util.ArrayList; | 59 | import java.util.ArrayList; |
| 56 | import java.util.HashMap; | 60 | import java.util.HashMap; |
| 57 | import java.util.List; | 61 | import java.util.List; |
| 58 | import java.util.Map; | 62 | import java.util.Map; |
| 59 | 63 | ||
| 60 | import io.reactivex.Observer; | 64 | import io.reactivex.Observer; |
| 61 | import io.reactivex.disposables.Disposable; | 65 | import io.reactivex.disposables.Disposable; |
| 62 | 66 | ||
| 63 | public class ErrorListActivity extends BaseActivity<ActivityErrorListBinding> implements View.OnClickListener { | 67 | public class ErrorListActivity extends BaseActivity<ActivityErrorListBinding> implements View.OnClickListener { |
| 64 | private TextView last; | 68 | private TextView last; |
| 65 | private String subject; | 69 | private String subject; |
| 66 | private String grade; | 70 | private String grade; |
| 67 | private String manger; | 71 | private String manger; |
| 68 | private String type = "全部"; | 72 | private String type = "全部"; |
| 69 | private String time = "全部"; | 73 | private String time = "全部"; |
| 70 | private FilterAdapter filterAdapter; | 74 | private FilterAdapter filterAdapter; |
| 71 | StudentBean studentBean; | 75 | StudentBean studentBean; |
| 72 | private int page = 1; | 76 | private int page = 1; |
| 73 | private ErrorAdapter adapter; | 77 | private ErrorAdapter adapter; |
| 74 | private int total; | 78 | private int total; |
| 75 | private int REQUEST_CODE_IMAGE = 123; | 79 | private int REQUEST_CODE_IMAGE = 123; |
| 76 | private String filePath; | 80 | private String filePath; |
| 77 | 81 | ||
| 78 | @Override | 82 | @Override |
| 79 | public void initView(Bundle savedInstanceState) { | 83 | public void initView(Bundle savedInstanceState) { |
| 80 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 84 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
| 81 | try { | 85 | try { |
| 82 | studentBean = new Gson().fromJson(student, StudentBean.class); | 86 | studentBean = new Gson().fromJson(student, StudentBean.class); |
| 83 | } catch (Exception e) { | 87 | } catch (Exception e) { |
| 84 | 88 | ||
| 85 | } | 89 | } |
| 86 | binding.ivBack.setOnClickListener(this); | 90 | binding.ivBack.setOnClickListener(this); |
| 87 | binding.tvFilterGrade.setOnClickListener(this); | 91 | binding.tvFilterGrade.setOnClickListener(this); |
| 88 | binding.tvFilterSubject.setOnClickListener(this); | 92 | binding.tvFilterSubject.setOnClickListener(this); |
| 89 | binding.tvFilterMore.setOnClickListener(this); | 93 | binding.tvFilterMore.setOnClickListener(this); |
| 90 | binding.tvFilterManage.setOnClickListener(this); | 94 | binding.tvFilterManage.setOnClickListener(this); |
| 91 | binding.tvEdit.setOnClickListener(this); | 95 | binding.tvEdit.setOnClickListener(this); |
| 92 | binding.tvAdd.setOnClickListener(this); | 96 | binding.tvAdd.setOnClickListener(this); |
| 93 | binding.llDelete.setOnClickListener(this); | 97 | binding.llDelete.setOnClickListener(this); |
| 94 | binding.tvSave.setOnClickListener(this); | 98 | binding.tvSave.setOnClickListener(this); |
| 95 | binding.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | 99 | binding.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
| 96 | @Override | 100 | @Override |
| 97 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | 101 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 98 | adapter.checkAll(isChecked); | 102 | adapter.checkAll(isChecked); |
| 99 | } | 103 | } |
| 100 | }); | 104 | }); |
| 101 | RadioButton timeButton = (RadioButton) binding.groupTime.getChildAt(3); | 105 | RadioButton timeButton = (RadioButton) binding.groupTime.getChildAt(3); |
| 102 | timeButton.setChecked(true); | 106 | timeButton.setChecked(true); |
| 103 | binding.groupTime.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { | 107 | binding.groupTime.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { |
| 104 | @Override | 108 | @Override |
| 105 | public void onCheckedChanged(RadioGroup group, int checkedId) { | 109 | public void onCheckedChanged(RadioGroup group, int checkedId) { |
| 106 | RadioButton rcheck = (RadioButton) findViewById(checkedId); | 110 | RadioButton rcheck = (RadioButton) findViewById(checkedId); |
| 107 | time = rcheck.getText().toString(); | 111 | time = rcheck.getText().toString(); |
| 108 | refreshError(); | 112 | refreshError(); |
| 109 | } | 113 | } |
| 110 | }); | 114 | }); |
| 111 | 115 | ||
| 112 | RadioButton typeButton = (RadioButton) binding.groupType.getChildAt(2); | 116 | RadioButton typeButton = (RadioButton) binding.groupType.getChildAt(2); |
| 113 | typeButton.setChecked(true); | 117 | typeButton.setChecked(true); |
| 114 | binding.groupType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { | 118 | binding.groupType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { |
| 115 | @Override | 119 | @Override |
| 116 | public void onCheckedChanged(RadioGroup group, int checkedId) { | 120 | public void onCheckedChanged(RadioGroup group, int checkedId) { |
| 117 | RadioButton rcheck = (RadioButton) findViewById(checkedId); | 121 | RadioButton rcheck = (RadioButton) findViewById(checkedId); |
| 118 | type = rcheck.getText().toString(); | 122 | type = rcheck.getText().toString(); |
| 119 | refreshError(); | 123 | refreshError(); |
| 120 | } | 124 | } |
| 121 | }); | 125 | }); |
| 122 | refreshError(); | 126 | refreshError(); |
| 123 | } | 127 | } |
| 124 | 128 | ||
| 125 | @Override | 129 | @Override |
| 126 | protected ActivityErrorListBinding getViewBinding() { | 130 | protected ActivityErrorListBinding getViewBinding() { |
| 127 | return ActivityErrorListBinding.inflate(getLayoutInflater()); | 131 | return ActivityErrorListBinding.inflate(getLayoutInflater()); |
| 128 | } | 132 | } |
| 129 | 133 | ||
| 130 | @Override | 134 | @Override |
| 131 | public void onClick(View v) { | 135 | public void onClick(View v) { |
| 132 | switch (v.getId()) { | 136 | switch (v.getId()) { |
| 133 | case R.id.iv_back: | 137 | case R.id.iv_back: |
| 134 | finish(); | 138 | finish(); |
| 135 | break; | 139 | break; |
| 136 | case R.id.tv_filter_grade: | 140 | case R.id.tv_filter_grade: |
| 137 | List<String> grades = new ArrayList<>(); | 141 | List<String> grades = new ArrayList<>(); |
| 138 | for (GradeAndSubject gradeAndSubject : App.getInstance().getGradeAndSubjects()) { | 142 | for (GradeAndSubject gradeAndSubject : App.getInstance().getGradeAndSubjects()) { |
| 139 | grades.add(gradeAndSubject.getGrade().getGrade()); | 143 | grades.add(gradeAndSubject.getGrade().getGrade()); |
| 140 | } | 144 | } |
| 141 | grades.add("全部"); | 145 | grades.add("全部"); |
| 142 | setFilterAdapter(grades, binding.tvFilterGrade, grade); | 146 | setFilterAdapter(grades, binding.tvFilterGrade, grade); |
| 143 | break; | 147 | break; |
| 144 | case R.id.tv_filter_subject: | 148 | case R.id.tv_filter_subject: |
| 145 | List<String> subjects = new ArrayList<>(); | 149 | List<String> subjects = new ArrayList<>(); |
| 146 | for (GradeAndSubject gradeAndSubject : App.getInstance().getGradeAndSubjects()) { | 150 | for (GradeAndSubject gradeAndSubject : App.getInstance().getGradeAndSubjects()) { |
| 147 | for (Subject subject : gradeAndSubject.getSubjects()) { | 151 | for (Subject subject : gradeAndSubject.getSubjects()) { |
| 148 | if (!subjects.contains(subject.getSubject())) { | 152 | if (!subjects.contains(subject.getSubject())) { |
| 149 | subjects.add(subject.getSubject()); | 153 | subjects.add(subject.getSubject()); |
| 150 | } | 154 | } |
| 151 | } | 155 | } |
| 152 | } | 156 | } |
| 153 | subjects.add("全部"); | 157 | subjects.add("全部"); |
| 154 | setFilterAdapter(subjects, binding.tvFilterSubject, subject); | 158 | setFilterAdapter(subjects, binding.tvFilterSubject, subject); |
| 155 | break; | 159 | break; |
| 156 | case R.id.tv_filter_manage: | 160 | case R.id.tv_filter_manage: |
| 157 | List<String> manages = new ArrayList<>(); | 161 | List<String> manages = new ArrayList<>(); |
| 158 | manages.add("已掌握"); | 162 | manages.add("已掌握"); |
| 159 | manages.add("未掌握"); | 163 | manages.add("未掌握"); |
| 160 | manages.add("全部"); | 164 | manages.add("全部"); |
| 161 | setFilterAdapter(manages, binding.tvFilterManage, manger); | 165 | setFilterAdapter(manages, binding.tvFilterManage, manger); |
| 162 | break; | 166 | break; |
| 163 | case R.id.tv_filter_more: | 167 | case R.id.tv_filter_more: |
| 164 | showFilterMore(); | 168 | showFilterMore(); |
| 165 | break; | 169 | break; |
| 166 | case R.id.tv_edit: | 170 | case R.id.tv_edit: |
| 167 | if (adapter.edit) { | 171 | if (adapter.edit) { |
| 168 | adapter.setEdit(false); | 172 | adapter.setEdit(false); |
| 169 | binding.tvSave.setVisibility(View.GONE); | 173 | binding.tvSave.setVisibility(View.GONE); |
| 170 | binding.tvAdd.setVisibility(View.VISIBLE); | 174 | binding.tvAdd.setVisibility(View.VISIBLE); |
| 171 | binding.checkbox.setVisibility(View.GONE); | 175 | binding.checkbox.setVisibility(View.GONE); |
| 172 | binding.llDelete.setVisibility(View.GONE); | 176 | binding.llDelete.setVisibility(View.GONE); |
| 173 | binding.ivBack.setVisibility(View.VISIBLE); | 177 | binding.ivBack.setVisibility(View.VISIBLE); |
| 174 | binding.tvEdit.setText("编辑"); | 178 | binding.tvEdit.setText("编辑"); |
| 175 | } else { | 179 | } else { |
| 176 | adapter.setEdit(true); | 180 | adapter.setEdit(true); |
| 177 | binding.tvSave.setVisibility(View.VISIBLE); | 181 | binding.tvSave.setVisibility(View.VISIBLE); |
| 178 | binding.tvAdd.setVisibility(View.GONE); | 182 | binding.tvAdd.setVisibility(View.GONE); |
| 179 | binding.llDelete.setVisibility(View.VISIBLE); | 183 | binding.llDelete.setVisibility(View.VISIBLE); |
| 180 | binding.checkbox.setVisibility(View.VISIBLE); | 184 | binding.checkbox.setVisibility(View.VISIBLE); |
| 181 | binding.ivBack.setVisibility(View.GONE); | 185 | binding.ivBack.setVisibility(View.GONE); |
| 182 | binding.tvEdit.setText("取消"); | 186 | binding.tvEdit.setText("取消"); |
| 183 | } | 187 | } |
| 184 | adapter.notifyDataSetChanged(); | 188 | adapter.notifyDataSetChanged(); |
| 185 | break; | 189 | break; |
| 186 | case R.id.ll_delete: | 190 | case R.id.ll_delete: |
| 187 | showTipDialog("温馨提示", "确认删除已勾选的错题?", "取消", "确认", new TipDialog.TipDialogInterface() { | 191 | showTipDialog("温馨提示", "确认删除已勾选的错题?", "取消", "确认", new TipDialog.TipDialogInterface() { |
| 188 | @Override | 192 | @Override |
| 189 | public void onConfirm(Dialog dialog) { | 193 | public void onConfirm(Dialog dialog) { |
| 190 | deleteError(adapter.getChecKList()); | 194 | deleteError(adapter.getChecKList()); |
| 191 | dialog.dismiss(); | 195 | dialog.dismiss(); |
| 192 | } | 196 | } |
| 193 | 197 | ||
| 194 | @Override | 198 | @Override |
| 195 | public void onCancel(Dialog dialog) { | 199 | public void onCancel(Dialog dialog) { |
| 196 | dialog.dismiss(); | 200 | dialog.dismiss(); |
| 197 | } | 201 | } |
| 198 | }); | 202 | }); |
| 199 | break; | 203 | break; |
| 200 | case R.id.tv_add: | 204 | case R.id.tv_add: |
| 201 | MyButtomDialog dialog = new MyButtomDialog(context, R.style.BottomSheetDialog); | 205 | if (!XXPermissions.isGranted(context, Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { |
| 202 | View bottomView = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_layout, null); | 206 | XXPermissions.with(context) |
| 203 | dialog.setContentView(bottomView); | 207 | // 申请多个权限 |
| 204 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 208 | .permission(Permission.CAMERA) |
| 205 | @Override | 209 | .request(new OnPermissionCallback() { |
| 206 | public void onClick(View view) { | 210 | @Override |
| 207 | dialog.dismiss(); | 211 | public void onGranted(List<String> permissions, boolean all) { |
| 208 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 212 | if (all) { |
| 209 | //确保有相机来处理Intent | 213 | //开启扫码界面 |
| 210 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 214 | showButtonDialog(); |
| 211 | File photoFile = new File(filePath); | 215 | } else { |
| 212 | if (photoFile != null) { | 216 | Toast.makeText(context, "需要权限", Toast.LENGTH_SHORT).show(); |
| 213 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | 217 | } |
| 214 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); | 218 | } |
| 215 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | ||
| 216 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | ||
| 217 | activity.startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE); | ||
| 218 | } | ||
| 219 | } | ||
| 220 | }); | ||
| 221 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | ||
| 222 | @Override | ||
| 223 | public void onClick(View view) { | ||
| 224 | dialog.dismiss(); | ||
| 225 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 | ||
| 226 | .iHandlerCallBack(new HandlerCallBack()) //图片选择器生命周期监听(直接打开摄像头时无效) | ||
| 227 | .multiSelect(true) //是否多选 | ||
| 228 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false | ||
| 229 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 | ||
| 230 | .maxImageSelectable(9) //图片可选择数 | ||
| 231 | .maxHeight(1920) //图片最大高度 | ||
| 232 | .maxWidth(1920) //图片最大宽度 | ||
| 233 | .maxImageSize(10) //图片最大大小Mb | ||
| 234 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); | ||
| 235 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(ErrorListActivity.this); | ||
| 236 | 219 | ||
| 237 | } | 220 | @Override |
| 238 | }); | 221 | public void onDenied(List<String> permissions, boolean never) { |
| 239 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 222 | XXPermissions.startPermissionActivity(context, permissions); |
| 240 | @Override | 223 | } |
| 241 | public void onClick(View view) { | 224 | }); |
| 242 | dialog.dismiss(); | 225 | } else { |
| 243 | } | 226 | showButtonDialog(); |
| 244 | }); | 227 | } |
| 245 | dialog.show(); | ||
| 246 | break; | 228 | break; |
| 247 | case R.id.tv_save: | 229 | case R.id.tv_save: |
| 248 | if (adapter.getChecKList().size() > 0) { | 230 | if (adapter.getChecKList().size() > 0) { |
| 249 | ErrorEditDialog errorEditDialog = new ErrorEditDialog(context, adapter.getChecKList(), new ErrorEditDialog.EditInterface() { | 231 | ErrorEditDialog errorEditDialog = new ErrorEditDialog(context, adapter.getChecKList(), new ErrorEditDialog.EditInterface() { |
| 250 | @Override | 232 | @Override |
| 251 | public void edit(String s, int i) { | 233 | public void edit(String s, int i) { |
| 252 | adapter.setEdit(false); | 234 | adapter.setEdit(false); |
| 253 | binding.tvSave.setVisibility(View.GONE); | 235 | binding.tvSave.setVisibility(View.GONE); |
| 254 | binding.tvAdd.setVisibility(View.VISIBLE); | 236 | binding.tvAdd.setVisibility(View.VISIBLE); |
| 255 | binding.checkbox.setVisibility(View.GONE); | 237 | binding.checkbox.setVisibility(View.GONE); |
| 256 | binding.llDelete.setVisibility(View.GONE); | 238 | binding.llDelete.setVisibility(View.GONE); |
| 257 | binding.ivBack.setVisibility(View.VISIBLE); | 239 | binding.ivBack.setVisibility(View.VISIBLE); |
| 258 | binding.tvEdit.setText("编辑"); | 240 | binding.tvEdit.setText("编辑"); |
| 259 | page = 1; | 241 | page = 1; |
| 260 | refreshError(); | 242 | refreshError(); |
| 261 | } | 243 | } |
| 262 | }); | 244 | }); |
| 263 | errorEditDialog.show(); | 245 | errorEditDialog.show(); |
| 264 | } | 246 | } |
| 265 | break; | 247 | break; |
| 266 | } | 248 | } |
| 267 | } | 249 | } |
| 268 | 250 | ||
| 251 | private void showButtonDialog() { | ||
| 252 | MyButtomDialog dialog = new MyButtomDialog(context, R.style.BottomSheetDialog); | ||
| 253 | View bottomView = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_layout, null); | ||
| 254 | dialog.setContentView(bottomView); | ||
| 255 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | ||
| 256 | @Override | ||
| 257 | public void onClick(View view) { | ||
| 258 | dialog.dismiss(); | ||
| 259 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | ||
| 260 | //确保有相机来处理Intent | ||
| 261 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | ||
| 262 | File photoFile = new File(filePath); | ||
| 263 | if (photoFile != null) { | ||
| 264 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | ||
| 265 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); | ||
| 266 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | ||
| 267 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | ||
| 268 | activity.startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE); | ||
| 269 | } | ||
| 270 | } | ||
| 271 | }); | ||
| 272 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | ||
| 273 | @Override | ||
| 274 | public void onClick(View view) { | ||
| 275 | dialog.dismiss(); | ||
| 276 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 | ||
| 277 | .iHandlerCallBack(new HandlerCallBack()) //图片选择器生命周期监听(直接打开摄像头时无效) | ||
| 278 | .multiSelect(true) //是否多选 | ||
| 279 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false | ||
| 280 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 | ||
| 281 | .maxImageSelectable(9) //图片可选择数 | ||
| 282 | .maxHeight(1920) //图片最大高度 | ||
| 283 | .maxWidth(1920) //图片最大宽度 | ||
| 284 | .maxImageSize(10) //图片最大大小Mb | ||
| 285 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); | ||
| 286 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(ErrorListActivity.this); | ||
| 287 | |||
| 288 | } | ||
| 289 | }); | ||
| 290 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | ||
| 291 | @Override | ||
| 292 | public void onClick(View view) { | ||
| 293 | dialog.dismiss(); | ||
| 294 | } | ||
| 295 | }); | ||
| 296 | dialog.show(); | ||
| 297 | } | ||
| 298 | |||
| 269 | private void deleteError(List<TopicBean> topicBeans) { | 299 | private void deleteError(List<TopicBean> topicBeans) { |
| 270 | List<String> list = new ArrayList<>(); | 300 | List<String> list = new ArrayList<>(); |
| 271 | for (int i = 0; i < topicBeans.size(); i++) { | 301 | for (int i = 0; i < topicBeans.size(); i++) { |
| 272 | list.add(topicBeans.get(i).getId()); | 302 | list.add(topicBeans.get(i).getId()); |
| 273 | } | 303 | } |
| 274 | NetWorks.deleteError(list, new Observer<ResponseResult>() { | 304 | NetWorks.deleteError(list, new Observer<ResponseResult>() { |
| 275 | @Override | 305 | @Override |
| 276 | public void onSubscribe(Disposable d) { | 306 | public void onSubscribe(Disposable d) { |
| 277 | 307 | ||
| 278 | } | 308 | } |
| 279 | 309 | ||
| 280 | @Override | 310 | @Override |
| 281 | public void onNext(ResponseResult responseResult) { | 311 | public void onNext(ResponseResult responseResult) { |
| 282 | if (responseResult.getCode() == 200) { | 312 | if (responseResult.getCode() == 200) { |
| 283 | adapter.setEdit(false); | 313 | adapter.setEdit(false); |
| 284 | binding.tvSave.setVisibility(View.GONE); | 314 | binding.tvSave.setVisibility(View.GONE); |
| 285 | binding.tvAdd.setVisibility(View.VISIBLE); | 315 | binding.tvAdd.setVisibility(View.VISIBLE); |
| 286 | binding.checkbox.setVisibility(View.GONE); | 316 | binding.checkbox.setVisibility(View.GONE); |
| 287 | binding.llDelete.setVisibility(View.GONE); | 317 | binding.llDelete.setVisibility(View.GONE); |
| 288 | binding.ivBack.setVisibility(View.VISIBLE); | 318 | binding.ivBack.setVisibility(View.VISIBLE); |
| 289 | binding.tvEdit.setText("编辑"); | 319 | binding.tvEdit.setText("编辑"); |
| 290 | page = 1; | 320 | page = 1; |
| 291 | refreshError(); | 321 | refreshError(); |
| 292 | } | 322 | } |
| 293 | } | 323 | } |
| 294 | 324 | ||
| 295 | @Override | 325 | @Override |
| 296 | public void onError(Throwable e) { | 326 | public void onError(Throwable e) { |
| 297 | 327 | ||
| 298 | } | 328 | } |
| 299 | 329 | ||
| 300 | @Override | 330 | @Override |
| 301 | public void onComplete() { | 331 | public void onComplete() { |
| 302 | 332 | ||
| 303 | } | 333 | } |
| 304 | }); | 334 | }); |
| 305 | } | 335 | } |
| 306 | 336 | ||
| 307 | private void showFilterMore() { | 337 | private void showFilterMore() { |
| 308 | binding.recycleFilter.setVisibility(View.GONE); | 338 | binding.recycleFilter.setVisibility(View.GONE); |
| 309 | if (binding.llFilterMore.getVisibility() == View.VISIBLE) { | 339 | if (binding.llFilterMore.getVisibility() == View.VISIBLE) { |
| 310 | binding.llFilterMore.setVisibility(View.GONE); | 340 | binding.llFilterMore.setVisibility(View.GONE); |
| 311 | } else { | 341 | } else { |
| 312 | binding.llFilterMore.setVisibility(View.VISIBLE); | 342 | binding.llFilterMore.setVisibility(View.VISIBLE); |
| 313 | last.setTextColor(getColor(R.color.text_title)); | 343 | if (last != null) { |
| 314 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); | 344 | last.setTextColor(getColor(R.color.text_title)); |
| 315 | // 这一步必须要做,否则不会显示. | 345 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); |
| 316 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 346 | // 这一步必须要做,否则不会显示. |
| 317 | last.setCompoundDrawables(null, null, drawable, null); | 347 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
| 348 | last.setCompoundDrawables(null, null, drawable, null); | ||
| 349 | } | ||
| 318 | binding.tvFilterMore.setTextColor(Color.parseColor("#1C90F3")); | 350 | binding.tvFilterMore.setTextColor(Color.parseColor("#1C90F3")); |
| 319 | Drawable drawable1 = getResources().getDrawable(R.drawable.ic_filter_blue); | 351 | Drawable drawable1 = getResources().getDrawable(R.drawable.ic_filter_blue); |
| 320 | // 这一步必须要做,否则不会显示. | 352 | // 这一步必须要做,否则不会显示. |
| 321 | drawable1.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 353 | drawable1.setBounds(0, 0, drawable1.getMinimumWidth(), drawable1.getMinimumHeight()); |
| 322 | binding.tvFilterMore.setCompoundDrawables(null, null, drawable1, null); | 354 | binding.tvFilterMore.setCompoundDrawables(null, null, drawable1, null); |
| 323 | last = binding.tvFilterMore; | 355 | last = binding.tvFilterMore; |
| 324 | } | 356 | } |
| 325 | } | 357 | } |
| 326 | 358 | ||
| 327 | private void setFilterAdapter(List<String> list, TextView textView, String select) { | 359 | private void setFilterAdapter(List<String> list, TextView textView, String select) { |
| 328 | if (TextUtils.isEmpty(select)) { | 360 | if (TextUtils.isEmpty(select)) { |
| 329 | select = "全部"; | 361 | select = "全部"; |
| 330 | } | 362 | } |
| 331 | binding.llFilterMore.setVisibility(View.GONE); | 363 | binding.llFilterMore.setVisibility(View.GONE); |
| 332 | if (last != null && last.getId() == R.id.tv_filter_more) { | 364 | if (last != null && last.getId() == R.id.tv_filter_more) { |
| 333 | last.setTextColor(getColor(R.color.text_title)); | 365 | last.setTextColor(getColor(R.color.text_title)); |
| 334 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); | 366 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); |
| 335 | // 这一步必须要做,否则不会显示. | 367 | // 这一步必须要做,否则不会显示. |
| 336 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 368 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
| 337 | last.setCompoundDrawables(null, null, drawable, null); | 369 | last.setCompoundDrawables(null, null, drawable, null); |
| 338 | } | 370 | } |
| 339 | if (binding.recycleFilter.getVisibility() == View.GONE) { | 371 | if (binding.recycleFilter.getVisibility() == View.GONE) { |
| 340 | if (filterAdapter != null) { | 372 | if (filterAdapter != null) { |
| 341 | filterAdapter.refresh(list, textView, select); | 373 | filterAdapter.refresh(list, textView, select); |
| 342 | } else { | 374 | } else { |
| 343 | filterAdapter = new FilterAdapter(context, new FilterAdapter.Filter() { | 375 | filterAdapter = new FilterAdapter(context, new FilterAdapter.Filter() { |
| 344 | @Override | 376 | @Override |
| 345 | public void onSelect(TextView type, String select) { | 377 | public void onSelect(TextView type, String select) { |
| 346 | switch (type.getId()) { | 378 | switch (type.getId()) { |
| 347 | case R.id.tv_filter_grade: | 379 | case R.id.tv_filter_grade: |
| 348 | grade = select; | 380 | grade = select; |
| 349 | break; | 381 | break; |
| 350 | case R.id.tv_filter_subject: | 382 | case R.id.tv_filter_subject: |
| 351 | subject = select; | 383 | subject = select; |
| 352 | break; | 384 | break; |
| 353 | case R.id.tv_filter_manage: | 385 | case R.id.tv_filter_manage: |
| 354 | manger = select; | 386 | manger = select; |
| 355 | break; | 387 | break; |
| 356 | } | 388 | } |
| 357 | page = 1; | 389 | page = 1; |
| 358 | filterAdapter.refresh(select); | 390 | filterAdapter.refresh(select); |
| 359 | refreshError(); | 391 | refreshError(); |
| 360 | } | 392 | } |
| 361 | }, list, textView, select); | 393 | }, list, textView, select); |
| 362 | binding.recycleFilter.setLayoutManager(new GridLayoutManager(context, 4, LinearLayoutManager.VERTICAL, false)); | 394 | binding.recycleFilter.setLayoutManager(new GridLayoutManager(context, 4, LinearLayoutManager.VERTICAL, false)); |
| 363 | binding.recycleFilter.setAdapter(filterAdapter); | 395 | binding.recycleFilter.setAdapter(filterAdapter); |
| 364 | } | 396 | } |
| 365 | binding.recycleFilter.setVisibility(View.VISIBLE); | 397 | binding.recycleFilter.setVisibility(View.VISIBLE); |
| 366 | textView.setTextColor(Color.parseColor("#1C90F3")); | 398 | textView.setTextColor(Color.parseColor("#1C90F3")); |
| 367 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_blue); | 399 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_blue); |
| 368 | // 这一步必须要做,否则不会显示. | 400 | // 这一步必须要做,否则不会显示. |
| 369 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 401 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
| 370 | textView.setCompoundDrawables(null, null, drawable, null); | 402 | textView.setCompoundDrawables(null, null, drawable, null); |
| 371 | last = textView; | 403 | last = textView; |
| 372 | } else { | 404 | } else { |
| 373 | if (textView.getId() == last.getId()) { | 405 | if (textView.getId() == last.getId()) { |
| 374 | binding.recycleFilter.setVisibility(View.GONE); | 406 | binding.recycleFilter.setVisibility(View.GONE); |
| 375 | textView.setTextColor(getColor(R.color.text_title)); | 407 | textView.setTextColor(getColor(R.color.text_title)); |
| 376 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); | 408 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); |
| 377 | // 这一步必须要做,否则不会显示. | 409 | // 这一步必须要做,否则不会显示. |
| 378 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 410 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
| 379 | textView.setCompoundDrawables(null, null, drawable, null); | 411 | textView.setCompoundDrawables(null, null, drawable, null); |
| 380 | } else { | 412 | } else { |
| 381 | filterAdapter.refresh(list, textView, select); | 413 | filterAdapter.refresh(list, textView, select); |
| 382 | last.setTextColor(getColor(R.color.text_title)); | 414 | last.setTextColor(getColor(R.color.text_title)); |
| 383 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); | 415 | Drawable drawable = getResources().getDrawable(R.drawable.ic_filter_gray); |
| 384 | // 这一步必须要做,否则不会显示. | 416 | // 这一步必须要做,否则不会显示. |
| 385 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 417 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
| 386 | last.setCompoundDrawables(null, null, drawable, null); | 418 | last.setCompoundDrawables(null, null, drawable, null); |
| 387 | textView.setTextColor(Color.parseColor("#1C90F3")); | 419 | textView.setTextColor(Color.parseColor("#1C90F3")); |
| 388 | Drawable drawable1 = getResources().getDrawable(R.drawable.ic_filter_blue); | 420 | Drawable drawable1 = getResources().getDrawable(R.drawable.ic_filter_blue); |
| 389 | // 这一步必须要做,否则不会显示. | 421 | // 这一步必须要做,否则不会显示. |
| 390 | drawable1.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); | 422 | drawable1.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
| 391 | textView.setCompoundDrawables(null, null, drawable1, null); | 423 | textView.setCompoundDrawables(null, null, drawable1, null); |
| 392 | last = textView; | 424 | last = textView; |
| 393 | } | 425 | } |
| 394 | } | 426 | } |
| 395 | } | 427 | } |
| 396 | 428 | ||
| 397 | private void refreshError() { | 429 | private void refreshError() { |
| 398 | Map map = new HashMap(); | 430 | Map map = new HashMap(); |
| 399 | if (!TextUtils.isEmpty(subject) && !"全部".equals(subject)) { | 431 | if (!TextUtils.isEmpty(subject) && !"全部".equals(subject)) { |
| 400 | map.put("subject", subject); | 432 | map.put("subject", subject); |
| 401 | } | 433 | } |
| 402 | if (!TextUtils.isEmpty(grade) && !"全部".equals(grade)) { | 434 | if (!TextUtils.isEmpty(grade) && !"全部".equals(grade)) { |
| 403 | map.put("grade", grade); | 435 | map.put("grade", grade); |
| 404 | } | 436 | } |
| 405 | if (!TextUtils.isEmpty(time) && !"全部".equals(time)) { | 437 | if (!TextUtils.isEmpty(time) && !"全部".equals(time)) { |
| 406 | if ("一周内".equals(time)) { | 438 | if ("一周内".equals(time)) { |
| 407 | map.put("time", 6); | 439 | map.put("time", 6); |
| 408 | } else if ("一个月内".equals(time)) { | 440 | } else if ("一个月内".equals(time)) { |
| 409 | map.put("time", 30); | 441 | map.put("time", 30); |
| 410 | } else if ("三个月内".equals(time)) { | 442 | } else if ("三个月内".equals(time)) { |
| 411 | map.put("time", 90); | 443 | map.put("time", 90); |
| 412 | } | 444 | } |
| 413 | } | 445 | } |
| 414 | if (!TextUtils.isEmpty(type) && !"全部".equals(type)) { | 446 | if (!TextUtils.isEmpty(type) && !"全部".equals(type)) { |
| 415 | map.put("type", "课内".equals(type) ? 0 : 1); | 447 | map.put("type", "课内".equals(type) ? 0 : 1); |
| 416 | } | 448 | } |
| 417 | if (!TextUtils.isEmpty(manger) && !"全部".equals(manger)) { | 449 | if (!TextUtils.isEmpty(manger) && !"全部".equals(manger)) { |
| 418 | map.put("controlFlag", "已掌握".equals(manger) ? 0 : 1); | 450 | map.put("controlFlag", "已掌握".equals(manger) ? 0 : 1); |
| 419 | } | 451 | } |
| 420 | map.put("stuId", studentBean.getStuId()); | 452 | map.put("stuId", studentBean.getStuId()); |
| 421 | map.put("pageSize", 10); | 453 | map.put("pageSize", 10); |
| 422 | map.put("pageNum", page); | 454 | map.put("pageNum", page); |
| 423 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { | 455 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { |
| 424 | @Override | 456 | @Override |
| 425 | public void onSubscribe(Disposable d) { | 457 | public void onSubscribe(Disposable d) { |
| 426 | 458 | ||
| 427 | } | 459 | } |
| 428 | 460 | ||
| 429 | @Override | 461 | @Override |
| 430 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { | 462 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { |
| 431 | if (result.getData() != null && result.getCode() == 200) { | 463 | if (result.getData() != null && result.getCode() == 200) { |
| 432 | total = result.getData().getTotal(); | 464 | total = result.getData().getTotal(); |
| 433 | List<TopicBean> topicBeans = result.getData().getList(); | 465 | List<TopicBean> topicBeans = result.getData().getList(); |
| 434 | loadError(topicBeans); | 466 | loadError(topicBeans); |
| 435 | } | 467 | } |
| 436 | } | 468 | } |
| 437 | 469 | ||
| 438 | @Override | 470 | @Override |
| 439 | public void onError(Throwable e) { | 471 | public void onError(Throwable e) { |
| 440 | e.toString(); | 472 | e.toString(); |
| 441 | } | 473 | } |
| 442 | 474 | ||
| 443 | @Override | 475 | @Override |
| 444 | public void onComplete() { | 476 | public void onComplete() { |
| 445 | 477 | ||
| 446 | } | 478 | } |
| 447 | }); | 479 | }); |
| 448 | } | 480 | } |
| 449 | 481 | ||
| 450 | private void loadError(List<TopicBean> list) { | 482 | private void loadError(List<TopicBean> list) { |
| 451 | if (list.size() > 0) { | 483 | if (list.size() > 0) { |
| 452 | binding.recycle.setVisibility(View.VISIBLE); | 484 | binding.recycle.setVisibility(View.VISIBLE); |
| 453 | binding.llEmpty.setVisibility(View.GONE); | 485 | binding.llEmpty.setVisibility(View.GONE); |
| 454 | if (adapter != null) { | 486 | if (adapter != null) { |
| 455 | if (page > 1) { | 487 | if (page > 1) { |
| 456 | adapter.addData(list); | 488 | adapter.addData(list); |
| 457 | } else { | 489 | } else { |
| 458 | adapter.refresh(list); | 490 | adapter.refresh(list); |
| 459 | } | 491 | } |
| 460 | } else { | 492 | } else { |
| 461 | adapter = new ErrorAdapter(context, list, false, new ErrorAdapter.CheckInterface() { | 493 | adapter = new ErrorAdapter(context, list, false, new ErrorAdapter.CheckInterface() { |
| 462 | @Override | 494 | @Override |
| 463 | public void onErrorCheck() { | 495 | public void onErrorCheck() { |
| 464 | if (adapter.getChecKList().size() > 0) { | 496 | if (adapter.getChecKList().size() > 0) { |
| 465 | binding.tvSave.setText("批量修改标签" + "(" + adapter.getChecKList().size() + ")"); | 497 | binding.tvSave.setText("批量修改标签" + "(" + adapter.getChecKList().size() + ")"); |
| 466 | } else { | 498 | } else { |
| 467 | binding.tvSave.setText("批量修改标签"); | 499 | binding.tvSave.setText("批量修改标签"); |
| 468 | } | 500 | } |
| 469 | } | 501 | } |
| 470 | }); | 502 | }); |
| 471 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false); | 503 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false); |
| 472 | binding.recycle.setLayoutManager(linearLayoutManager); | 504 | binding.recycle.setLayoutManager(linearLayoutManager); |
| 473 | binding.recycle.setAdapter(adapter); | 505 | binding.recycle.setAdapter(adapter); |
| 474 | binding.recycle.addOnScrollListener(new LoadMoreOnScrollListener(linearLayoutManager) { | 506 | binding.recycle.addOnScrollListener(new LoadMoreOnScrollListener(linearLayoutManager) { |
| 475 | @Override | 507 | @Override |
| 476 | public void onLoadMore(int currentPage) { | 508 | public void onLoadMore(int currentPage) { |
| 477 | if (currentPage > page) { | 509 | if (currentPage > page) { |
| 478 | new Thread(new Runnable() { | 510 | new Thread(new Runnable() { |
| 479 | @Override | 511 | @Override |
| 480 | public void run() { | 512 | public void run() { |
| 481 | try { | 513 | try { |
| 482 | runOnUiThread(new Runnable() { | 514 | runOnUiThread(new Runnable() { |
| 483 | @Override | 515 | @Override |
| 484 | public void run() { | 516 | public void run() { |
| 485 | if (page * 10 < total) { | 517 | if (page * 10 < total) { |
| 486 | page++; | 518 | page++; |
| 487 | refreshError(); | 519 | refreshError(); |
| 488 | } | 520 | } |
| 489 | } | 521 | } |
| 490 | }); | 522 | }); |
| 491 | } catch (Exception e) { | 523 | } catch (Exception e) { |
| 492 | e.printStackTrace(); | 524 | e.printStackTrace(); |
| 493 | } | 525 | } |
| 494 | } | 526 | } |
| 495 | }).start(); | 527 | }).start(); |
| 496 | } | 528 | } |
| 497 | } | 529 | } |
| 498 | }); | 530 | }); |
| 499 | } | 531 | } |
| 500 | } else { | 532 | } else { |
| 501 | if (page == 1) { | 533 | if (page == 1) { |
| 502 | binding.recycle.setVisibility(View.GONE); | 534 | binding.recycle.setVisibility(View.GONE); |
| 503 | binding.llEmpty.setVisibility(View.VISIBLE); | 535 | binding.llEmpty.setVisibility(View.VISIBLE); |
| 504 | } | 536 | } |
| 505 | } | 537 | } |
| 506 | } | 538 | } |
| 507 | 539 | ||
| 508 | @Override | 540 | @Override |
| 509 | public boolean onKeyDown(int keyCode, KeyEvent event) { | 541 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 510 | if (keyCode == KeyEvent.KEYCODE_BACK) { | 542 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
| 511 | if (adapter != null && adapter.edit) { | 543 | if (adapter != null && adapter.edit) { |
| 512 | adapter.setEdit(false); | 544 | adapter.setEdit(false); |
| 513 | binding.tvSave.setVisibility(View.GONE); | 545 | binding.tvSave.setVisibility(View.GONE); |
| 514 | binding.tvAdd.setVisibility(View.VISIBLE); | 546 | binding.tvAdd.setVisibility(View.VISIBLE); |
| 515 | binding.checkbox.setVisibility(View.GONE); | 547 | binding.checkbox.setVisibility(View.GONE); |
| 516 | binding.llDelete.setVisibility(View.GONE); | 548 | binding.llDelete.setVisibility(View.GONE); |
| 517 | binding.ivBack.setVisibility(View.VISIBLE); | 549 | binding.ivBack.setVisibility(View.VISIBLE); |
| 518 | binding.tvEdit.setText("编辑"); | 550 | binding.tvEdit.setText("编辑"); |
| 519 | adapter.notifyDataSetChanged(); | 551 | adapter.notifyDataSetChanged(); |
| 520 | } else { | 552 | } else { |
| 521 | finish(); | 553 | finish(); |
| 522 | } | 554 | } |
| 523 | return true; | 555 | return true; |
| 524 | } | 556 | } |
| 525 | return super.onKeyDown(keyCode, event); | 557 | return super.onKeyDown(keyCode, event); |
| 526 | } | 558 | } |
| 527 | 559 | ||
| 528 | @Override | 560 | @Override |
| 529 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 561 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 530 | super.onActivityResult(requestCode, resultCode, data); | 562 | super.onActivityResult(requestCode, resultCode, data); |
| 531 | if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { | 563 | if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { |
| 532 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); | 564 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
| 533 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 565 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 534 | CommonUtil.saveBitmapToUri(b, path); | 566 | CommonUtil.saveBitmapToUri(b, path); |
| 535 | List<String> strings = new ArrayList<>(); | 567 | List<String> strings = new ArrayList<>(); |
| 536 | Intent intent = new Intent(context, ImageActivity.class); | 568 | Intent intent = new Intent(context, ImageActivity.class); |
| 537 | strings.add(path); | 569 | strings.add(path); |
| 538 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); | 570 | intent.putStringArrayListExtra("images", (ArrayList<String>) strings); |
| 539 | startActivity(intent); | 571 | startActivity(intent); |
| 540 | } | 572 | } |
| 541 | } | 573 | } |
| 542 | 574 | ||
| 543 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { | 575 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { |
| 544 | private String TAG = "---ImagePicker---"; | 576 | private String TAG = "---ImagePicker---"; |
| 545 | List<ImageInfo> photoList = new ArrayList<>(); | 577 | List<ImageInfo> photoList = new ArrayList<>(); |
| 546 | 578 | ||
| 547 | @Override | 579 | @Override |
| 548 | public void onStart() { | 580 | public void onStart() { |
| 549 | Log.i(TAG, "onStart: 开启"); | 581 | Log.i(TAG, "onStart: 开启"); |
| 550 | } | 582 | } |
| 551 | 583 | ||
| 552 | @Override | 584 | @Override |
| 553 | public void onSuccess(List<ImageInfo> photoList) { | 585 | public void onSuccess(List<ImageInfo> photoList) { |
| 554 | this.photoList = photoList; | 586 | this.photoList = photoList; |
| 555 | Log.i(TAG, "onSuccess: 返回数据"); | 587 | Log.i(TAG, "onSuccess: 返回数据"); |
| 556 | } | 588 | } |
| 557 | 589 | ||
| 558 | @Override | 590 | @Override |
| 559 | public void onCancel() { | 591 | public void onCancel() { |
| 560 | Log.i(TAG, "onCancel: 取消"); | 592 | Log.i(TAG, "onCancel: 取消"); |
| 561 | } | 593 | } |
| 562 | 594 | ||
| 563 | @Override | 595 | @Override |
| 564 | public void onFinish(List<ImageInfo> selectImage) { | 596 | public void onFinish(List<ImageInfo> selectImage) { |
| 565 | if (selectImage.size() == photoList.size()) { | 597 | if (selectImage.size() == photoList.size()) { |
| 566 | List<String> strings = new ArrayList<>(); | 598 | List<String> strings = new ArrayList<>(); |
app/src/main/java/com/hjx/parent/ImageActivity.java
| 1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
| 2 | 2 | ||
| 3 | import android.app.Dialog; | 3 | import android.app.Dialog; |
| 4 | import android.content.Intent; | 4 | import android.content.Intent; |
| 5 | import android.graphics.Bitmap; | 5 | import android.graphics.Bitmap; |
| 6 | import android.graphics.BitmapFactory; | 6 | import android.graphics.BitmapFactory; |
| 7 | import android.graphics.Rect; | 7 | import android.graphics.Rect; |
| 8 | import android.net.Uri; | 8 | import android.net.Uri; |
| 9 | import android.os.Bundle; | 9 | import android.os.Bundle; |
| 10 | import android.os.Handler; | 10 | import android.os.Handler; |
| 11 | import android.provider.MediaStore; | 11 | import android.provider.MediaStore; |
| 12 | import android.text.TextUtils; | 12 | import android.text.TextUtils; |
| 13 | import android.util.Log; | 13 | import android.util.Log; |
| 14 | import android.view.KeyEvent; | 14 | import android.view.KeyEvent; |
| 15 | import android.view.View; | 15 | import android.view.View; |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | import androidx.annotation.Nullable; | 18 | import androidx.annotation.Nullable; |
| 19 | import androidx.core.content.FileProvider; | 19 | import androidx.core.content.FileProvider; |
| 20 | import androidx.viewpager2.widget.ViewPager2; | 20 | import androidx.viewpager2.widget.ViewPager2; |
| 21 | 21 | ||
| 22 | import com.google.gson.Gson; | 22 | import com.google.gson.Gson; |
| 23 | import com.google.gson.JsonObject; | 23 | import com.google.gson.JsonObject; |
| 24 | import com.hjx.parent.adapter.ImageAdapter; | 24 | import com.hjx.parent.adapter.ImageAdapter; |
| 25 | import com.hjx.parent.databinding.ActivityImageBinding; | 25 | import com.hjx.parent.databinding.ActivityImageBinding; |
| 26 | import com.hjx.parent.dialog.ErrorInputDialog; | 26 | import com.hjx.parent.dialog.ErrorInputDialog; |
| 27 | import com.hjx.parent.dialog.TipDialog; | 27 | import com.hjx.parent.dialog.TipDialog; |
| 28 | import com.prws.common.bean.CutPicBean; | 28 | import com.prws.common.bean.CutPicBean; |
| 29 | import com.prws.common.bean.ImageBean; | 29 | import com.prws.common.bean.ImageBean; |
| 30 | import com.prws.common.bean.TopicBean; | 30 | import com.prws.common.bean.TopicBean; |
| 31 | import com.prws.common.net.NetWorks; | 31 | import com.prws.common.net.NetWorks; |
| 32 | import com.prws.common.utils.BitmapUtils; | 32 | import com.prws.common.utils.BitmapUtils; |
| 33 | import com.prws.common.utils.CommonUtil; | 33 | import com.prws.common.utils.CommonUtil; |
| 34 | import com.xiasuhuei321.loadingdialog.view.LoadingDialog; | ||
| 34 | 35 | ||
| 35 | import java.io.File; | 36 | import java.io.File; |
| 36 | import java.util.ArrayList; | 37 | import java.util.ArrayList; |
| 37 | import java.util.List; | 38 | import java.util.List; |
| 38 | 39 | ||
| 39 | import io.reactivex.Observer; | 40 | import io.reactivex.Observer; |
| 40 | import io.reactivex.disposables.Disposable; | 41 | import io.reactivex.disposables.Disposable; |
| 41 | import retrofit2.Call; | 42 | import retrofit2.Call; |
| 42 | import retrofit2.Callback; | 43 | import retrofit2.Callback; |
| 43 | import retrofit2.Response; | 44 | import retrofit2.Response; |
| 44 | 45 | ||
| 45 | public class ImageActivity extends BaseActivity<ActivityImageBinding> implements View.OnClickListener { | 46 | public class ImageActivity extends BaseActivity<ActivityImageBinding> implements View.OnClickListener { |
| 46 | 47 | ||
| 47 | private List<String> images = new ArrayList<>(); | 48 | private List<String> images = new ArrayList<>(); |
| 48 | private ImageAdapter imageAdapter; | 49 | private ImageAdapter imageAdapter; |
| 49 | private List<ImageBean> list = new ArrayList<>(); | 50 | private List<ImageBean> list = new ArrayList<>(); |
| 50 | private String filePath; | 51 | private String filePath; |
| 51 | 52 | ||
| 52 | @Override | 53 | @Override |
| 53 | public void initView(Bundle savedInstanceState) { | 54 | public void initView(Bundle savedInstanceState) { |
| 54 | images = getIntent().getStringArrayListExtra("images"); | 55 | images = getIntent().getStringArrayListExtra("images"); |
| 55 | for (String s : images) { | 56 | for (String s : images) { |
| 56 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 57 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 57 | ImageBean imageBean = new ImageBean(); | 58 | ImageBean imageBean = new ImageBean(); |
| 58 | Bitmap bitmap = BitmapUtils.getimage(s); | 59 | Bitmap bitmap = BitmapUtils.getimage(s); |
| 59 | CommonUtil.saveBitmapToUri(bitmap, filepath); | 60 | CommonUtil.saveBitmapToUri(bitmap, filepath); |
| 60 | imageBean.setPath(filepath); | 61 | imageBean.setPath(filepath); |
| 61 | list.add(imageBean); | 62 | list.add(imageBean); |
| 62 | } | 63 | } |
| 63 | imageAdapter = new ImageAdapter(this, list); | 64 | imageAdapter = new ImageAdapter(this, list); |
| 64 | binding.viewPager.setAdapter(imageAdapter); | 65 | binding.viewPager.setAdapter(imageAdapter); |
| 65 | binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { | 66 | binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { |
| 66 | @Override | 67 | @Override |
| 67 | public void onPageSelected(int position) { | 68 | public void onPageSelected(int position) { |
| 69 | if (list.get(position).getCuts() == null) { | ||
| 70 | binding.ivPrevious.setEnabled(false); | ||
| 71 | binding.ivNext.setEnabled(false); | ||
| 72 | clearText(); | ||
| 73 | } | ||
| 68 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); | 74 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); |
| 69 | if (position == 0) { | 75 | if (position == 0) { |
| 70 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous_gray); | 76 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous_gray); |
| 71 | binding.ivPrevious.setEnabled(false); | ||
| 72 | } else { | 77 | } else { |
| 73 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous); | 78 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous); |
| 74 | binding.ivPrevious.setEnabled(true); | ||
| 75 | } | 79 | } |
| 76 | if (position == list.size() - 1) { | 80 | if (position == list.size() - 1) { |
| 77 | binding.ivNext.setImageResource(R.mipmap.ic_next_gray); | 81 | binding.ivNext.setImageResource(R.mipmap.ic_next_gray); |
| 78 | binding.ivNext.setEnabled(false); | ||
| 79 | } else { | 82 | } else { |
| 80 | binding.ivNext.setImageResource(R.mipmap.ic_next); | 83 | binding.ivNext.setImageResource(R.mipmap.ic_next); |
| 81 | binding.ivNext.setEnabled(true); | ||
| 82 | } | ||
| 83 | if (list.get(position).getCuts() == null) { | ||
| 84 | clearText(); | ||
| 85 | } | 84 | } |
| 86 | super.onPageSelected(position); | 85 | super.onPageSelected(position); |
| 87 | } | 86 | } |
| 88 | }); | 87 | }); |
| 89 | binding.ivNext.setOnClickListener(this); | 88 | binding.ivNext.setOnClickListener(this); |
| 90 | binding.ivPrevious.setOnClickListener(this); | 89 | binding.ivPrevious.setOnClickListener(this); |
| 91 | binding.ivBack.setOnClickListener(this); | 90 | binding.ivBack.setOnClickListener(this); |
| 92 | binding.tvPhoto.setOnClickListener(this); | 91 | binding.tvPhoto.setOnClickListener(this); |
| 93 | binding.tvAdd.setOnClickListener(this); | 92 | binding.tvAdd.setOnClickListener(this); |
| 94 | binding.llEdit.setOnClickListener(this); | 93 | binding.llEdit.setOnClickListener(this); |
| 95 | binding.tvSave.setOnClickListener(this); | 94 | binding.tvSave.setOnClickListener(this); |
| 96 | } | 95 | } |
| 97 | 96 | ||
| 98 | public void clearText() { | 97 | public void clearText() { |
| 99 | int index = binding.viewPager.getCurrentItem(); | 98 | int index = binding.viewPager.getCurrentItem(); |
| 100 | showLoadingDialog(getString(R.string.loading_text)); | 99 | showLoadingDialog(getString(R.string.loading_text), new LoadingDialog.DismissListener() { |
| 100 | @Override | ||
| 101 | public void dimiss() { | ||
| 102 | binding.ivPrevious.setEnabled(index != 0); | ||
| 103 | binding.ivNext.setEnabled(index != list.size() - 1); | ||
| 104 | } | ||
| 105 | }); | ||
| 101 | Log.i("clearText", list.get(index).getPath()); | 106 | Log.i("clearText", list.get(index).getPath()); |
| 102 | String base64 = BitmapUtils.imageToBase64(list.get(index).getPath()); | 107 | String base64 = BitmapUtils.imageToBase64(list.get(index).getPath()); |
| 103 | NetWorks.removeWriting(base64, new Observer<JsonObject>() { | 108 | NetWorks.removeWriting(base64, new Observer<JsonObject>() { |
| 104 | @Override | 109 | @Override |
| 105 | public void onSubscribe(Disposable d) { | 110 | public void onSubscribe(Disposable d) { |
| 106 | 111 | ||
| 107 | } | 112 | } |
| 108 | 113 | ||
| 109 | @Override | 114 | @Override |
| 110 | public void onNext(JsonObject jsonObject) { | 115 | public void onNext(JsonObject jsonObject) { |
| 111 | if (jsonObject != null && jsonObject.get("image_processed") != null) { | 116 | if (jsonObject != null && jsonObject.get("image_processed") != null) { |
| 112 | String image = jsonObject.get("image_processed").getAsString(); | 117 | String image = jsonObject.get("image_processed").getAsString(); |
| 113 | if (image != null) { | 118 | if (image != null) { |
| 114 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 119 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 115 | CommonUtil.saveBitmapToUri(BitmapUtils.stringToBitmap(image), filepath); | 120 | CommonUtil.saveBitmapToUri(BitmapUtils.stringToBitmap(image), filepath); |
| 116 | list.get(index).setPath(filepath); | 121 | list.get(index).setPath(filepath); |
| 117 | imageAdapter.notifyItemChanged(index); | 122 | imageAdapter.notifyItemChanged(index); |
| 118 | cut(filepath); | 123 | cut(filepath); |
| 119 | } else { | 124 | } else { |
| 120 | loadFail("去除字迹失败"); | 125 | loadFail("去除字迹失败"); |
| 121 | } | 126 | } |
| 122 | } else { | 127 | } else { |
| 123 | loadFail("去除字迹失败"); | 128 | loadFail("去除字迹失败"); |
| 124 | } | 129 | } |
| 125 | } | 130 | } |
| 126 | 131 | ||
| 127 | @Override | 132 | @Override |
| 128 | public void onError(Throwable e) { | 133 | public void onError(Throwable e) { |
| 129 | loadFail("去除字迹失败"); | 134 | loadFail("去除字迹失败"); |
| 130 | } | 135 | } |
| 131 | 136 | ||
| 132 | @Override | 137 | @Override |
| 133 | public void onComplete() { | 138 | public void onComplete() { |
| 134 | 139 | ||
| 135 | } | 140 | } |
| 136 | }); | 141 | }); |
| 137 | } | 142 | } |
| 138 | 143 | ||
| 139 | public void cut(String path) { | 144 | public void cut(String path) { |
| 140 | String base64 = BitmapUtils.imageToBase64(path); | 145 | String base64 = BitmapUtils.imageToBase64(path); |
| 141 | Log.i("figLoaction", path); | 146 | Log.i("figLoaction", path); |
| 142 | NetWorks.cut(base64, new Observer<CutPicBean>() { | 147 | NetWorks.cut(base64, new Observer<CutPicBean>() { |
| 143 | @Override | 148 | @Override |
| 144 | public void onSubscribe(Disposable d) { | 149 | public void onSubscribe(Disposable d) { |
| 145 | 150 | ||
| 146 | } | 151 | } |
| 147 | 152 | ||
| 148 | @Override | 153 | @Override |
| 149 | public void onNext(CutPicBean cutPicBean) { | 154 | public void onNext(CutPicBean cutPicBean) { |
| 150 | if (cutPicBean != null) { | 155 | if (cutPicBean != null) { |
| 151 | if (cutPicBean.getDirection() != 0) { | 156 | if (cutPicBean.getDirection() != 0) { |
| 152 | rotatingImage(cutPicBean); | 157 | rotatingImage(cutPicBean); |
| 153 | } else { | 158 | } else { |
| 154 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { | 159 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { |
| 155 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); | 160 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); |
| 156 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { | 161 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { |
| 157 | figLoactions.add(cutLocation.getFig_location()); | 162 | figLoactions.add(cutLocation.getFig_location()); |
| 158 | } | 163 | } |
| 159 | new Handler().postDelayed(new Runnable() { | 164 | new Handler().postDelayed(new Runnable() { |
| 160 | @Override | 165 | @Override |
| 161 | public void run() { | 166 | public void run() { |
| 162 | getRects(figLoactions); | 167 | getRects(figLoactions); |
| 163 | } | 168 | } |
| 164 | }, 1000); | 169 | }, 1000); |
| 165 | } else { | 170 | } else { |
| 166 | cancelLoadingDialog(); | 171 | cancelLoadingDialog(); |
| 167 | } | 172 | } |
| 168 | } | 173 | } |
| 169 | } else { | 174 | } else { |
| 170 | loadFail("自动切题失败"); | 175 | loadFail("自动切题失败"); |
| 171 | } | 176 | } |
| 172 | } | 177 | } |
| 173 | 178 | ||
| 174 | @Override | 179 | @Override |
| 175 | public void onError(Throwable e) { | 180 | public void onError(Throwable e) { |
| 176 | loadFail("自动切题失败"); | 181 | loadFail("自动切题失败"); |
| 177 | } | 182 | } |
| 178 | 183 | ||
| 179 | @Override | 184 | @Override |
| 180 | public void onComplete() { | 185 | public void onComplete() { |
| 181 | 186 | ||
| 182 | } | 187 | } |
| 183 | }); | 188 | }); |
| 184 | } | 189 | } |
| 185 | 190 | ||
| 186 | private void getRects(List<CutPicBean.FigLoaction> figLoactions) { | 191 | private void getRects(List<CutPicBean.FigLoaction> figLoactions) { |
| 187 | Log.i("figLoaction", new Gson().toJson(figLoactions)); | 192 | Log.i("figLoaction", new Gson().toJson(figLoactions)); |
| 188 | int index = binding.viewPager.getCurrentItem(); | 193 | int index = binding.viewPager.getCurrentItem(); |
| 189 | List<ImageBean.Cut> cuts = new ArrayList<>(); | 194 | List<ImageBean.Cut> cuts = new ArrayList<>(); |
| 190 | for (CutPicBean.FigLoaction figLoaction : figLoactions) { | 195 | for (CutPicBean.FigLoaction figLoaction : figLoactions) { |
| 191 | ImageBean.Cut cut = new ImageBean.Cut(); | 196 | ImageBean.Cut cut = new ImageBean.Cut(); |
| 192 | cut.setRect(figLoaction); | 197 | cut.setRect(figLoaction); |
| 193 | cut.setSelect(false); | 198 | cut.setSelect(false); |
| 194 | cuts.add(cut); | 199 | cuts.add(cut); |
| 195 | } | 200 | } |
| 196 | list.get(index).setCuts(cuts); | 201 | list.get(index).setCuts(cuts); |
| 197 | imageAdapter.notifyItemChanged(index); | 202 | imageAdapter.notifyItemChanged(index); |
| 198 | cancelLoadingDialog(); | 203 | cancelLoadingDialog(); |
| 199 | } | 204 | } |
| 200 | 205 | ||
| 201 | private void rotatingImage(CutPicBean cutPicBean) { | 206 | private void rotatingImage(CutPicBean cutPicBean) { |
| 202 | int index = binding.viewPager.getCurrentItem(); | 207 | int index = binding.viewPager.getCurrentItem(); |
| 203 | Bitmap bitmap = BitmapFactory.decodeFile(list.get(index).getPath()); | 208 | Bitmap bitmap = BitmapFactory.decodeFile(list.get(index).getPath()); |
| 204 | int angle = 0; | 209 | int angle = 0; |
| 205 | switch (cutPicBean.getDirection()) { | 210 | switch (cutPicBean.getDirection()) { |
| 206 | case 1: | 211 | case 1: |
| 207 | angle = 90; | 212 | angle = 90; |
| 208 | break; | 213 | break; |
| 209 | case 2: | 214 | case 2: |
| 210 | angle = 180; | 215 | angle = 180; |
| 211 | break; | 216 | break; |
| 212 | case 3: | 217 | case 3: |
| 213 | angle = 270; | 218 | angle = 270; |
| 214 | break; | 219 | break; |
| 215 | } | 220 | } |
| 216 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { | 221 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { |
| 217 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); | 222 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); |
| 218 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { | 223 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { |
| 219 | figLoactions.add(cutLocation.getFig_location()); | 224 | figLoactions.add(cutLocation.getFig_location()); |
| 220 | } | 225 | } |
| 221 | figLoactions = CommonUtil.rotaingLocation(angle, figLoactions, bitmap.getWidth(), bitmap.getHeight()); | 226 | figLoactions = CommonUtil.rotaingLocation(angle, figLoactions, bitmap.getWidth(), bitmap.getHeight()); |
| 222 | bitmap = CommonUtil.rotaingImageView(angle, bitmap); | 227 | bitmap = CommonUtil.rotaingImageView(angle, bitmap); |
| 223 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 228 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 224 | CommonUtil.saveBitmapToUri(bitmap, filepath); | 229 | CommonUtil.saveBitmapToUri(bitmap, filepath); |
| 225 | list.get(index).setPath(filepath); | 230 | list.get(index).setPath(filepath); |
| 226 | imageAdapter.notifyItemChanged(index); | 231 | imageAdapter.notifyItemChanged(index); |
| 227 | List<CutPicBean.FigLoaction> finalFigLoactions = figLoactions; | 232 | List<CutPicBean.FigLoaction> finalFigLoactions = figLoactions; |
| 228 | new Handler().postDelayed(new Runnable() { | 233 | new Handler().postDelayed(new Runnable() { |
| 229 | @Override | 234 | @Override |
| 230 | public void run() { | 235 | public void run() { |
| 231 | getRects(finalFigLoactions); | 236 | getRects(finalFigLoactions); |
| 232 | } | 237 | } |
| 233 | }, 500); | 238 | }, 500); |
| 234 | } else { | 239 | } else { |
| 235 | cancelLoadingDialog(); | 240 | cancelLoadingDialog(); |
| 236 | } | 241 | } |
| 237 | } | 242 | } |
| 238 | 243 | ||
| 239 | @Override | 244 | @Override |
| 240 | protected ActivityImageBinding getViewBinding() { | 245 | protected ActivityImageBinding getViewBinding() { |
| 241 | return ActivityImageBinding.inflate(getLayoutInflater()); | 246 | return ActivityImageBinding.inflate(getLayoutInflater()); |
| 242 | } | 247 | } |
| 243 | 248 | ||
| 244 | public void refreshNum() { | 249 | public void refreshNum() { |
| 245 | int num = 0; | 250 | int num = 0; |
| 246 | for (ImageBean imageBean : list) { | 251 | for (ImageBean imageBean : list) { |
| 247 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { | 252 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { |
| 248 | for (ImageBean.Cut cut : imageBean.getCuts()) { | 253 | for (ImageBean.Cut cut : imageBean.getCuts()) { |
| 249 | if (cut.isSelect()) { | 254 | if (cut.isSelect()) { |
| 250 | num++; | 255 | num++; |
| 251 | } | 256 | } |
| 252 | } | 257 | } |
| 253 | } | 258 | } |
| 254 | } | 259 | } |
| 255 | if (num > 0) { | 260 | if (num > 0) { |
| 256 | binding.tvSave.setEnabled(true); | 261 | binding.tvSave.setEnabled(true); |
| 257 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_5); | 262 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_5); |
| 258 | binding.tvSave.setText("保留错题(" + num + ")"); | 263 | binding.tvSave.setText("保留错题(" + num + ")"); |
| 259 | } else { | 264 | } else { |
| 260 | binding.tvSave.setEnabled(false); | 265 | binding.tvSave.setEnabled(false); |
| 261 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_light_5); | 266 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_light_5); |
| 262 | binding.tvSave.setText("保留错题"); | 267 | binding.tvSave.setText("保留错题"); |
| 263 | } | 268 | } |
| 264 | } | 269 | } |
| 265 | 270 | ||
| 266 | @Override | 271 | @Override |
| 267 | public void onClick(View v) { | 272 | public void onClick(View v) { |
| 268 | switch (v.getId()) { | 273 | switch (v.getId()) { |
| 269 | case R.id.iv_back: | 274 | case R.id.iv_back: |
| 270 | back(); | 275 | back(); |
| 271 | break; | 276 | break; |
| 272 | case R.id.iv_next: | 277 | case R.id.iv_next: |
| 273 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() + 1); | 278 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() + 1); |
| 274 | break; | 279 | break; |
| 275 | case R.id.iv_previous: | 280 | case R.id.iv_previous: |
| 276 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() - 1); | 281 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() - 1); |
| 277 | break; | 282 | break; |
| 278 | case R.id.ll_edit: | 283 | case R.id.ll_edit: |
| 279 | Intent intent = new Intent(context, ImageEditActivity.class); | 284 | Intent intent = new Intent(context, ImageEditActivity.class); |
| 280 | intent.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); | 285 | intent.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); |
| 281 | startActivityForResult(intent, 1001); | 286 | startActivityForResult(intent, 1001); |
| 282 | break; | 287 | break; |
| 283 | case R.id.tv_photo: | 288 | case R.id.tv_photo: |
| 284 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 289 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| 285 | //确保有相机来处理Intent | 290 | //确保有相机来处理Intent |
| 286 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 291 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 287 | File photoFile = new File(filePath); | 292 | File photoFile = new File(filePath); |
| 288 | if (photoFile != null) { | 293 | if (photoFile != null) { |
| 289 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | 294 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri |
| 290 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); | 295 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); |
| 291 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 296 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| 292 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | 297 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); |
| 293 | activity.startActivityForResult(takePictureIntent, 1002); | 298 | activity.startActivityForResult(takePictureIntent, 1002); |
| 294 | } | 299 | } |
| 295 | break; | 300 | break; |
| 296 | case R.id.tv_add: | 301 | case R.id.tv_add: |
| 297 | Intent intent1 = new Intent(context, ImageSelectActivity.class); | 302 | Intent intent1 = new Intent(context, ImageSelectActivity.class); |
| 298 | intent1.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); | 303 | intent1.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); |
| 299 | startActivityForResult(intent1, 1001); | 304 | startActivityForResult(intent1, 1001); |
| 300 | break; | 305 | break; |
| 301 | case R.id.tv_save: | 306 | case R.id.tv_save: |
| 302 | List<TopicBean> topicBeans = new ArrayList<>(); | 307 | List<TopicBean> topicBeans = new ArrayList<>(); |
| 303 | for (ImageBean imageBean : list) { | 308 | for (ImageBean imageBean : list) { |
| 304 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { | 309 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { |
| 305 | for (ImageBean.Cut cut : imageBean.getCuts()) { | 310 | for (ImageBean.Cut cut : imageBean.getCuts()) { |
| 306 | if (cut.isSelect()) { | 311 | if (cut.isSelect()) { |
| 307 | TopicBean bean = new TopicBean(); | 312 | TopicBean bean = new TopicBean(); |
| 308 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 313 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 309 | BitmapUtils.saveBitmap(cut.getBitmap(), path); | 314 | BitmapUtils.saveBitmap(cut.getBitmap(), path); |
| 310 | bean.setPath(path); | 315 | bean.setPath(path); |
| 311 | topicBeans.add(bean); | 316 | topicBeans.add(bean); |
| 312 | } | 317 | } |
| 313 | } | 318 | } |
| 314 | } | 319 | } |
| 315 | } | 320 | } |
| 316 | ErrorInputDialog dialog = new ErrorInputDialog(this, topicBeans); | 321 | ErrorInputDialog dialog = new ErrorInputDialog(this, topicBeans); |
| 317 | dialog.show(); | 322 | dialog.show(); |
| 318 | break; | 323 | break; |
| 319 | } | 324 | } |
| 320 | } | 325 | } |
| 321 | 326 | ||
| 322 | @Override | 327 | @Override |
| 323 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 328 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 324 | super.onActivityResult(requestCode, resultCode, data); | 329 | super.onActivityResult(requestCode, resultCode, data); |
| 325 | if (requestCode == 1001) { | 330 | if (requestCode == 1001) { |
| 326 | if (resultCode == 1002) { | 331 | if (resultCode == 1002) { |
| 327 | if (list.size() > 1) { | 332 | if (list.size() > 1) { |
| 328 | list.remove(binding.viewPager.getCurrentItem()); | 333 | list.remove(binding.viewPager.getCurrentItem()); |
| 329 | imageAdapter.notifyItemRemoved(binding.viewPager.getCurrentItem()); | 334 | imageAdapter.notifyItemRemoved(binding.viewPager.getCurrentItem()); |
| 330 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); | 335 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); |
| 331 | refreshNum(); | 336 | refreshNum(); |
| 332 | } else { | 337 | } else { |
| 333 | finish(); | 338 | finish(); |
| 334 | } | 339 | } |
| 335 | } else if (resultCode == 1003) { | 340 | } else if (resultCode == 1003) { |
| 336 | int position = binding.viewPager.getCurrentItem(); | 341 | int position = binding.viewPager.getCurrentItem(); |
| 337 | list.remove(position); | 342 | list.remove(position); |
| 338 | String path = data.getStringExtra("path"); | 343 | String path = data.getStringExtra("path"); |
| 339 | ImageBean imageBean = new ImageBean(); | 344 | ImageBean imageBean = new ImageBean(); |
| 340 | imageBean.setPath(path); | 345 | imageBean.setPath(path); |
| 341 | list.add(position, imageBean); | 346 | list.add(position, imageBean); |
| 342 | imageAdapter.notifyItemChanged(position); | 347 | imageAdapter.notifyItemChanged(position); |
| 343 | clearText(); | 348 | clearText(); |
| 344 | refreshNum(); | 349 | refreshNum(); |
| 345 | } else if (resultCode == 1004) { | 350 | } else if (resultCode == 1004) { |
| 346 | Rect rect = data.getParcelableExtra("cut"); | 351 | Rect rect = data.getParcelableExtra("cut"); |
| 347 | if (rect != null) { | 352 | if (rect != null) { |
| 348 | int position = binding.viewPager.getCurrentItem(); | 353 | int position = binding.viewPager.getCurrentItem(); |
| 349 | ImageBean.Cut cut = new ImageBean.Cut(); | 354 | ImageBean.Cut cut = new ImageBean.Cut(); |
| 350 | cut.setRect1(rect); | 355 | cut.setRect1(rect); |
| 351 | cut.setSelect(false); | 356 | cut.setSelect(false); |
| 352 | list.get(position).getCuts().add(cut); | 357 | list.get(position).getCuts().add(cut); |
| 353 | imageAdapter.notifyItemChanged(position); | 358 | imageAdapter.notifyItemChanged(position); |
| 354 | refreshNum(); | 359 | refreshNum(); |
| 355 | } | 360 | } |
| 356 | } else if (resultCode == 1005) { | 361 | } else if (resultCode == 1005) { |
| 357 | int i = data.getIntExtra("position", 0); | 362 | int i = data.getIntExtra("position", 0); |
| 358 | int position = binding.viewPager.getCurrentItem(); | 363 | int position = binding.viewPager.getCurrentItem(); |
| 359 | Rect rect = data.getParcelableExtra("cut"); | 364 | Rect rect = data.getParcelableExtra("cut"); |
| 360 | if (rect != null) { | 365 | if (rect != null) { |
| 361 | ImageBean.Cut cut = new ImageBean.Cut(); | 366 | ImageBean.Cut cut = new ImageBean.Cut(); |
| 362 | cut.setRect1(rect); | 367 | cut.setRect1(rect); |
| 363 | cut.setSelect(false); | 368 | cut.setSelect(false); |
| 364 | list.get(position).getCuts().remove(i); | 369 | list.get(position).getCuts().remove(i); |
| 365 | list.get(position).getCuts().add(i, cut); | 370 | list.get(position).getCuts().add(i, cut); |
| 366 | imageAdapter.notifyItemChanged(position); | 371 | imageAdapter.notifyItemChanged(position); |
| 367 | refreshNum(); | 372 | refreshNum(); |
| 368 | } else { | 373 | } else { |
| 369 | list.get(position).getCuts().remove(i); | 374 | list.get(position).getCuts().remove(i); |
| 370 | imageAdapter.notifyItemChanged(position); | 375 | imageAdapter.notifyItemChanged(position); |
| 371 | refreshNum(); | 376 | refreshNum(); |
| 372 | } | 377 | } |
| 373 | } | 378 | } |
| 374 | } else if (requestCode == 1002 && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { | 379 | } else if (requestCode == 1002 && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { |
| 375 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); | 380 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
| 376 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 381 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 377 | CommonUtil.saveBitmapToUri(b, path); | 382 | CommonUtil.saveBitmapToUri(b, path); |
| 378 | int position = binding.viewPager.getCurrentItem(); | 383 | int position = binding.viewPager.getCurrentItem(); |
| 379 | list.remove(position); | 384 | list.remove(position); |
| 380 | ImageBean imageBean = new ImageBean(); | 385 | ImageBean imageBean = new ImageBean(); |
| 381 | imageBean.setPath(path); | 386 | imageBean.setPath(path); |
| 382 | list.add(position, imageBean); | 387 | list.add(position, imageBean); |
| 383 | imageAdapter.notifyItemChanged(position); | 388 | imageAdapter.notifyItemChanged(position); |
| 384 | clearText(); | 389 | clearText(); |
| 385 | refreshNum(); | 390 | refreshNum(); |
| 386 | } | 391 | } |
| 387 | } | 392 | } |
| 388 | 393 | ||
| 389 | private void back() { | 394 | private void back() { |
| 390 | showTipDialog("温馨提示", "是否确认退出?", "取消", "确定", new TipDialog.TipDialogInterface() { | 395 | showTipDialog("温馨提示", "是否确认退出?", "取消", "确定", new TipDialog.TipDialogInterface() { |
| 391 | @Override | 396 | @Override |
| 392 | public void onConfirm(Dialog dialog) { | 397 | public void onConfirm(Dialog dialog) { |
| 393 | dialog.dismiss(); | 398 | dialog.dismiss(); |
| 394 | finish(); | 399 | finish(); |
| 395 | } | 400 | } |
| 396 | 401 | ||
| 397 | @Override | 402 | @Override |
| 398 | public void onCancel(Dialog dialog) { | 403 | public void onCancel(Dialog dialog) { |
| 399 | dialog.dismiss(); | 404 | dialog.dismiss(); |
| 400 | } | 405 | } |
| 401 | }); | 406 | }); |
| 402 | } | 407 | } |
| 403 | 408 | ||
| 404 | @Override | 409 | @Override |
| 405 | public boolean onKeyDown(int keyCode, KeyEvent event) { | 410 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 406 | if (keyCode == KeyEvent.KEYCODE_BACK) { | 411 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
app/src/main/java/com/hjx/parent/ImageSelectActivity.java
| 1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
| 2 | 2 | ||
| 3 | import android.app.Dialog; | ||
| 3 | import android.content.Intent; | 4 | import android.content.Intent; |
| 4 | import android.graphics.Bitmap; | 5 | import android.graphics.Bitmap; |
| 5 | import android.graphics.BitmapFactory; | 6 | import android.graphics.BitmapFactory; |
| 6 | import android.graphics.Canvas; | 7 | import android.graphics.Canvas; |
| 7 | import android.graphics.Paint; | 8 | import android.graphics.Paint; |
| 8 | import android.graphics.Rect; | 9 | import android.graphics.Rect; |
| 9 | import android.os.Bundle; | 10 | import android.os.Bundle; |
| 10 | import android.os.SystemClock; | 11 | import android.os.SystemClock; |
| 11 | import android.util.Log; | 12 | import android.util.Log; |
| 13 | import android.view.KeyEvent; | ||
| 12 | import android.view.MotionEvent; | 14 | import android.view.MotionEvent; |
| 13 | import android.view.View; | 15 | import android.view.View; |
| 14 | import android.widget.RelativeLayout; | 16 | import android.widget.RelativeLayout; |
| 15 | 17 | ||
| 16 | import com.hjx.parent.databinding.ActivityImageSelectBinding; | 18 | import com.hjx.parent.databinding.ActivityImageSelectBinding; |
| 19 | import com.hjx.parent.dialog.TipDialog; | ||
| 17 | import com.prws.common.bean.CutPicBean; | 20 | import com.prws.common.bean.CutPicBean; |
| 18 | import com.prws.common.bean.ImageBean; | 21 | import com.prws.common.bean.ImageBean; |
| 19 | import com.prws.common.utils.BitmapUtils; | 22 | import com.prws.common.utils.BitmapUtils; |
| 20 | import com.prws.common.utils.CommonUtil; | 23 | import com.prws.common.utils.CommonUtil; |
| 21 | import com.prws.common.widget.MarkSizeView; | 24 | import com.prws.common.widget.MarkSizeView; |
| 22 | 25 | ||
| 23 | public class ImageSelectActivity extends BaseActivity<ActivityImageSelectBinding> { | 26 | public class ImageSelectActivity extends BaseActivity<ActivityImageSelectBinding> { |
| 24 | private Bitmap bitmap; | 27 | private Bitmap bitmap; |
| 25 | Rect rect; | 28 | Rect rect; |
| 26 | private double widthFold, heightFold; | 29 | private double widthFold, heightFold; |
| 27 | private Bitmap backGroundBitmap; | 30 | private Bitmap backGroundBitmap; |
| 28 | private int bitmapWidth, bitmapHeight; | 31 | private int bitmapWidth, bitmapHeight; |
| 29 | private Rect select; | 32 | private Rect select; |
| 33 | private boolean isSelect = false; | ||
| 30 | 34 | ||
| 31 | @Override | 35 | @Override |
| 32 | public void initView(Bundle savedInstanceState) { | 36 | public void initView(Bundle savedInstanceState) { |
| 33 | String path = getIntent().getStringExtra("path"); | 37 | String path = getIntent().getStringExtra("path"); |
| 34 | bitmap = BitmapFactory.decodeFile(path); | 38 | bitmap = BitmapFactory.decodeFile(path); |
| 35 | showImage(); | 39 | showImage(); |
| 36 | binding.markView.setmOnClickListener(new MarkSizeView.onClickListener() { | 40 | binding.markView.setmOnClickListener(new MarkSizeView.onClickListener() { |
| 37 | @Override | 41 | @Override |
| 38 | public void onConfirm(Rect markedArea) { | 42 | public void onConfirm(Rect markedArea) { |
| 43 | if (isSelect) { | ||
| 44 | binding.markView.setBackGroundBitmap(backGroundBitmap); | ||
| 45 | isSelect = false; | ||
| 46 | } | ||
| 39 | int markSizeViewWidth = binding.markView.getWidth(); | 47 | int markSizeViewWidth = binding.markView.getWidth(); |
| 40 | int markSizeHeight = binding.markView.getHeight(); | 48 | int markSizeHeight = binding.markView.getHeight(); |
| 41 | backGroundBitmap = binding.markView.getBackGroundBitmap(); | 49 | backGroundBitmap = binding.markView.getBackGroundBitmap(); |
| 42 | bitmapWidth = backGroundBitmap.getWidth(); | 50 | bitmapWidth = backGroundBitmap.getWidth(); |
| 43 | bitmapHeight = backGroundBitmap.getHeight(); | 51 | bitmapHeight = backGroundBitmap.getHeight(); |
| 44 | widthFold = CommonUtil.div(bitmapWidth, markSizeViewWidth, 2); | 52 | widthFold = CommonUtil.div(bitmapWidth, markSizeViewWidth, 2); |
| 45 | heightFold = CommonUtil.div(bitmapHeight, markSizeHeight, 2); | 53 | heightFold = CommonUtil.div(bitmapHeight, markSizeHeight, 2); |
| 46 | Log.d(toString(), markedArea.toString()); | 54 | Log.d(toString(), markedArea.toString()); |
| 47 | drawRectangles(markedArea); | 55 | drawRectangles(markedArea); |
| 48 | binding.markView.reset(); | 56 | binding.markView.reset(); |
| 49 | } | 57 | } |
| 50 | 58 | ||
| 51 | @Override | 59 | @Override |
| 52 | public void onCancel() { | 60 | public void onCancel() { |
| 53 | rect = null; | 61 | rect = null; |
| 54 | } | 62 | } |
| 55 | 63 | ||
| 56 | @Override | 64 | @Override |
| 57 | public void onTouch() { | 65 | public void onTouch() { |
| 58 | 66 | ||
| 59 | } | 67 | } |
| 60 | }); | 68 | }); |
| 61 | binding.tvSave.setOnClickListener(new View.OnClickListener() { | 69 | binding.tvSave.setOnClickListener(new View.OnClickListener() { |
| 62 | @Override | 70 | @Override |
| 63 | public void onClick(View v) { | 71 | public void onClick(View v) { |
| 64 | if (rect != null) { | 72 | if (rect != null) { |
| 65 | if (select == null) { | 73 | if (select == null) { |
| 66 | Intent intent = new Intent(); | 74 | Intent intent = new Intent(); |
| 67 | intent.putExtra("cut", rect); | 75 | intent.putExtra("cut", rect); |
| 68 | setResult(1004, intent); | 76 | setResult(1004, intent); |
| 69 | finish(); | 77 | finish(); |
| 70 | } else { | 78 | } else { |
| 71 | Intent intent = new Intent(); | 79 | Intent intent = new Intent(); |
| 72 | intent.putExtra("cut", rect); | 80 | intent.putExtra("cut", rect); |
| 73 | intent.putExtra("position", getIntent().getIntExtra("position", 0)); | 81 | intent.putExtra("position", getIntent().getIntExtra("position", 0)); |
| 74 | setResult(1005, intent); | 82 | setResult(1005, intent); |
| 75 | finish(); | 83 | finish(); |
| 76 | } | 84 | } |
| 77 | } else { | 85 | } else { |
| 78 | showToast("未选择框题区域"); | 86 | showToast("未选择框题区域"); |
| 79 | } | 87 | } |
| 80 | } | 88 | } |
| 81 | }); | 89 | }); |
| 82 | binding.llDelete.setOnClickListener(new View.OnClickListener() { | 90 | binding.llDelete.setOnClickListener(new View.OnClickListener() { |
| 83 | @Override | 91 | @Override |
| 84 | public void onClick(View v) { | 92 | public void onClick(View v) { |
| 85 | if (select == null) { | 93 | if (select == null) { |
| 86 | finish(); | 94 | finish(); |
| 87 | } else { | 95 | } else { |
| 88 | rect = null; | 96 | rect = null; |
| 89 | Intent intent = new Intent(); | 97 | Intent intent = new Intent(); |
| 90 | intent.putExtra("cut", rect); | 98 | intent.putExtra("cut", rect); |
| 91 | intent.putExtra("position", getIntent().getIntExtra("position", 0)); | 99 | intent.putExtra("position", getIntent().getIntExtra("position", 0)); |
| 92 | setResult(1005, intent); | 100 | setResult(1005, intent); |
| 93 | finish(); | 101 | finish(); |
| 94 | } | 102 | } |
| 95 | } | 103 | } |
| 96 | }); | 104 | }); |
| 105 | binding.ivBack.setOnClickListener(new View.OnClickListener() { | ||
| 106 | @Override | ||
| 107 | public void onClick(View v) { | ||
| 108 | back(); | ||
| 109 | } | ||
| 110 | }); | ||
| 111 | } | ||
| 112 | |||
| 113 | private void back() { | ||
| 114 | showTipDialog("温馨提示", "是否确认放弃当前的编辑?", "取消", "确定", new TipDialog.TipDialogInterface() { | ||
| 115 | @Override | ||
| 116 | public void onConfirm(Dialog dialog) { | ||
| 117 | dialog.dismiss(); | ||
| 118 | finish(); | ||
| 119 | } | ||
| 120 | |||
| 121 | @Override | ||
| 122 | public void onCancel(Dialog dialog) { | ||
| 123 | dialog.dismiss(); | ||
| 124 | } | ||
| 125 | }); | ||
| 97 | } | 126 | } |
| 98 | 127 | ||
| 99 | private void simulateClick(int x1, int x2, int y1, int y2) { | 128 | private void simulateClick(int x1, int x2, int y1, int y2) { |
| 100 | long downTime = SystemClock.uptimeMillis(); | 129 | long downTime = SystemClock.uptimeMillis(); |
| 101 | final MotionEvent downEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x1, y1, 0); | 130 | final MotionEvent downEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x1, y1, 0); |
| 102 | downTime += 1000; | 131 | downTime += 1000; |
| 103 | final MotionEvent moveEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, x2, y2, 0); | 132 | final MotionEvent moveEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, x2, y2, 0); |
| 104 | final MotionEvent upEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_UP, x2, y2, 0); | 133 | final MotionEvent upEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_UP, x2, y2, 0); |
| 105 | binding.markView.onTouchEvent(downEvent); | 134 | binding.markView.onTouchEvent(downEvent); |
| 106 | binding.markView.onTouchEvent(moveEvent); | 135 | binding.markView.onTouchEvent(moveEvent); |
| 107 | binding.markView.onTouchEvent(upEvent); | 136 | binding.markView.onTouchEvent(upEvent); |
| 108 | downEvent.recycle(); | 137 | downEvent.recycle(); |
| 109 | moveEvent.recycle(); | 138 | moveEvent.recycle(); |
| 110 | upEvent.recycle(); | 139 | upEvent.recycle(); |
| 111 | } | 140 | } |
| 112 | 141 | ||
| 113 | private void drawRectangles(Rect ints) { | 142 | private void drawRectangles(Rect ints) { |
| 143 | isSelect = true; | ||
| 114 | rect = new Rect(ints.left, ints.top, ints.right, ints.bottom); | 144 | rect = new Rect(ints.left, ints.top, ints.right, ints.bottom); |
| 115 | Log.d(toString(), ints.toString()); | 145 | Log.d(toString(), ints.toString()); |
| 116 | Rect rect = new Rect(CommonUtil.mulForInt(ints.left, widthFold), CommonUtil.mulForInt(ints.top, heightFold), CommonUtil.mulForInt(ints.right, widthFold), CommonUtil.mulForInt(ints.bottom, heightFold)); | 146 | Rect rect = new Rect(CommonUtil.mulForInt(ints.left, widthFold), CommonUtil.mulForInt(ints.top, heightFold), CommonUtil.mulForInt(ints.right, widthFold), CommonUtil.mulForInt(ints.bottom, heightFold)); |
| 117 | // Log.d(toString(),rect.toString()); | 147 | // Log.d(toString(),rect.toString()); |
| 118 | Bitmap mutableBitmap = backGroundBitmap.copy(Bitmap.Config.ARGB_8888, true); | 148 | Bitmap mutableBitmap = backGroundBitmap.copy(Bitmap.Config.ARGB_8888, true); |
| 119 | Canvas canvas = new Canvas(mutableBitmap); | 149 | Canvas canvas = new Canvas(mutableBitmap); |
| 120 | //画矩形框 | 150 | //画矩形框 |
| 121 | Paint paint = new Paint(); | 151 | Paint paint = new Paint(); |
| 122 | paint.setAntiAlias(true); | 152 | paint.setAntiAlias(true); |
| 123 | paint.setStyle(Paint.Style.FILL);//填充 | 153 | paint.setStyle(Paint.Style.FILL);//填充 |
| 124 | paint.setStrokeWidth(CommonUtil.dpToPx(this, 1)); //线的宽度 | 154 | paint.setStrokeWidth(CommonUtil.dpToPx(this, 1)); //线的宽度 |
| 125 | paint.setColor(getColor(R.color.select_fill)); | 155 | paint.setColor(getColor(R.color.select_fill)); |
| 126 | canvas.drawRect(rect, paint); | 156 | canvas.drawRect(rect, paint); |
| 127 | paint.setStyle(Paint.Style.STROKE);//不填充 | 157 | paint.setStyle(Paint.Style.STROKE);//不填充 |
| 128 | paint.setColor(getColor(R.color.select_border)); | 158 | paint.setColor(getColor(R.color.select_border)); |
| 129 | canvas.drawRect(rect, paint); | 159 | canvas.drawRect(rect, paint); |
| 130 | binding.markView.setBackGroundBitmap(mutableBitmap); | 160 | binding.markView.setBackGroundBitmap(mutableBitmap); |
| 131 | } | 161 | } |
| 132 | 162 | ||
| 133 | private void showImage() { | 163 | private void showImage() { |
| 134 | float imageHeight = bitmap.getHeight(); | 164 | float imageHeight = bitmap.getHeight(); |
| 135 | float imageWidth = bitmap.getWidth(); | 165 | float imageWidth = bitmap.getWidth(); |
| 136 | float viewHeight = CommonUtil.getScreenHeight(context) - CommonUtil.dpToPx(context, 250); | 166 | float viewHeight = CommonUtil.getScreenHeight(context) - CommonUtil.dpToPx(context, 250); |
| 137 | float viewWidth = CommonUtil.getScreenWidth(context) - CommonUtil.dpToPx(context, 60); | 167 | float viewWidth = CommonUtil.getScreenWidth(context) - CommonUtil.dpToPx(context, 60); |
| 138 | binding.markView.post(new Runnable() { | 168 | binding.markView.post(new Runnable() { |
| 139 | @Override | 169 | @Override |
| 140 | public void run() { | 170 | public void run() { |
| 141 | binding.markView.reset(); | 171 | binding.markView.reset(); |
| 142 | RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(binding.markView.getLayoutParams()); | 172 | RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(binding.markView.getLayoutParams()); |
| 143 | if (imageHeight / imageWidth > viewHeight / viewWidth) { | 173 | if (imageHeight / imageWidth > viewHeight / viewWidth) { |
| 144 | if (viewHeight > imageHeight) { | 174 | if (viewHeight > imageHeight) { |
| 145 | layoutParams.height = (int) imageHeight; | 175 | layoutParams.height = (int) imageHeight; |
| 146 | layoutParams.width = (int) imageWidth; | 176 | layoutParams.width = (int) imageWidth; |
| 147 | } else { | 177 | } else { |
| 148 | layoutParams.height = (int) viewHeight; | 178 | layoutParams.height = (int) viewHeight; |
| 149 | layoutParams.width = (int) ((float) (imageWidth / imageHeight) * viewHeight); | 179 | layoutParams.width = (int) ((float) (imageWidth / imageHeight) * viewHeight); |
| 150 | } | 180 | } |
| 151 | } else { | 181 | } else { |
| 152 | if (viewWidth > imageWidth) { | 182 | if (viewWidth > imageWidth) { |
| 153 | layoutParams.height = (int) imageHeight; | 183 | layoutParams.height = (int) imageHeight; |
| 154 | layoutParams.width = (int) imageWidth; | 184 | layoutParams.width = (int) imageWidth; |
| 155 | } else { | 185 | } else { |
| 156 | layoutParams.height = (int) ((float) (imageHeight / imageWidth) * viewWidth); | 186 | layoutParams.height = (int) ((float) (imageHeight / imageWidth) * viewWidth); |
| 157 | layoutParams.width = (int) viewWidth; | 187 | layoutParams.width = (int) viewWidth; |
| 158 | } | 188 | } |
| 159 | } | 189 | } |
| 160 | layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); | 190 | layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); |
| 161 | binding.markView.setLayoutParams(layoutParams); | 191 | binding.markView.setLayoutParams(layoutParams); |
| 162 | binding.markView.setBackGroundBitmap(bitmap); | 192 | binding.markView.setBackGroundBitmap(bitmap); |
| 163 | binding.markView.reset(); | 193 | binding.markView.reset(); |
| 164 | select = getIntent().getParcelableExtra("rect"); | 194 | select = getIntent().getParcelableExtra("rect"); |
| 165 | if (select != null) { | 195 | if (select != null) { |
| 166 | simulateClick(select.left, select.right, select.top, select.bottom); | 196 | simulateClick(select.left, select.right, select.top, select.bottom); |
| 167 | } | 197 | } |
| 168 | } | 198 | } |
| 169 | }); | 199 | }); |
| 170 | } | 200 | } |
| 171 | 201 | ||
| 172 | @Override | 202 | @Override |
| 173 | protected void onDestroy() { | 203 | protected void onDestroy() { |
| 174 | if (backGroundBitmap != null) { | 204 | if (backGroundBitmap != null) { |
| 175 | backGroundBitmap.recycle(); | 205 | backGroundBitmap.recycle(); |
| 176 | backGroundBitmap = null; | 206 | backGroundBitmap = null; |
| 177 | } | 207 | } |
| 178 | if (bitmap != null) { | 208 | if (bitmap != null) { |
| 179 | bitmap.recycle(); | 209 | bitmap.recycle(); |
| 180 | bitmap = null; | 210 | bitmap = null; |
| 181 | } | 211 | } |
| 182 | super.onDestroy(); | 212 | super.onDestroy(); |
| 183 | } | 213 | } |
| 184 | 214 | ||
| 185 | @Override | 215 | @Override |
| 216 | public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
| 217 | if (keyCode == KeyEvent.KEYCODE_BACK) { | ||
| 218 | back(); | ||
| 219 | return true; | ||
| 220 | } | ||
| 221 | return super.onKeyDown(keyCode, event); | ||
| 222 | } | ||
| 223 | |||
| 224 | @Override | ||
| 186 | protected ActivityImageSelectBinding getViewBinding() { | 225 | protected ActivityImageSelectBinding getViewBinding() { |
| 187 | return ActivityImageSelectBinding.inflate(getLayoutInflater()); | 226 | return ActivityImageSelectBinding.inflate(getLayoutInflater()); |
| 188 | } | 227 | } |
| 189 | } | 228 | } |
| 190 | 229 |
app/src/main/java/com/hjx/parent/fragment/HomeFragment.java
| 1 | package com.hjx.parent.fragment; | 1 | package com.hjx.parent.fragment; |
| 2 | 2 | ||
| 3 | import android.content.Intent; | 3 | import android.content.Intent; |
| 4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
| 5 | import android.text.TextUtils; | 5 | import android.text.TextUtils; |
| 6 | import android.view.LayoutInflater; | 6 | import android.view.LayoutInflater; |
| 7 | import android.view.View; | 7 | import android.view.View; |
| 8 | import android.widget.ImageView; | 8 | import android.widget.ImageView; |
| 9 | import android.widget.LinearLayout; | 9 | import android.widget.LinearLayout; |
| 10 | import android.widget.TextView; | 10 | import android.widget.TextView; |
| 11 | import android.widget.Toast; | 11 | import android.widget.Toast; |
| 12 | 12 | ||
| 13 | import androidx.annotation.NonNull; | 13 | import androidx.annotation.NonNull; |
| 14 | import androidx.annotation.Nullable; | 14 | import androidx.annotation.Nullable; |
| 15 | import androidx.recyclerview.widget.LinearLayoutManager; | 15 | import androidx.recyclerview.widget.LinearLayoutManager; |
| 16 | import androidx.recyclerview.widget.RecyclerView; | 16 | import androidx.recyclerview.widget.RecyclerView; |
| 17 | 17 | ||
| 18 | import com.bumptech.glide.Glide; | 18 | import com.bumptech.glide.Glide; |
| 19 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 19 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
| 20 | import com.bumptech.glide.request.RequestOptions; | 20 | import com.bumptech.glide.request.RequestOptions; |
| 21 | import com.chad.library.adapter.base.BaseQuickAdapter; | 21 | import com.chad.library.adapter.base.BaseQuickAdapter; |
| 22 | import com.chad.library.adapter.base.BaseViewHolder; | 22 | import com.chad.library.adapter.base.BaseViewHolder; |
| 23 | import com.google.gson.Gson; | 23 | import com.google.gson.Gson; |
| 24 | import com.hjq.permissions.OnPermissionCallback; | 24 | import com.hjq.permissions.OnPermissionCallback; |
| 25 | import com.hjq.permissions.Permission; | 25 | import com.hjq.permissions.Permission; |
| 26 | import com.hjq.permissions.XXPermissions; | 26 | import com.hjq.permissions.XXPermissions; |
| 27 | import com.hjx.parent.ChooseActivity; | 27 | import com.hjx.parent.ChooseActivity; |
| 28 | import com.hjx.parent.ErrorBookActivity; | 28 | import com.hjx.parent.ErrorBookActivity; |
| 29 | import com.hjx.parent.QRActivity; | 29 | import com.hjx.parent.QRActivity; |
| 30 | import com.hjx.parent.R; | 30 | import com.hjx.parent.R; |
| 31 | import com.hjx.parent.bean.StudentBean; | 31 | import com.hjx.parent.bean.StudentBean; |
| 32 | import com.prws.common.base.BaseFragment; | 32 | import com.prws.common.base.BaseFragment; |
| 33 | import com.prws.common.bean.ResponseResult; | 33 | import com.prws.common.bean.ResponseResult; |
| 34 | import com.prws.common.bean.ScheduleBean; | 34 | import com.prws.common.bean.ScheduleBean; |
| 35 | import com.prws.common.bean.Video; | 35 | import com.prws.common.bean.Video; |
| 36 | import com.prws.common.net.NetWorks; | 36 | import com.prws.common.net.NetWorks; |
| 37 | import com.prws.common.utils.ScreenUtils; | 37 | import com.prws.common.utils.ScreenUtils; |
| 38 | import com.prws.common.utils.SharedPreferencesUtil; | 38 | import com.prws.common.utils.SharedPreferencesUtil; |
| 39 | import com.uuzuche.lib_zxing.activity.CaptureActivity; | 39 | import com.uuzuche.lib_zxing.activity.CaptureActivity; |
| 40 | import com.uuzuche.lib_zxing.activity.CodeUtils; | 40 | import com.uuzuche.lib_zxing.activity.CodeUtils; |
| 41 | 41 | ||
| 42 | import java.text.SimpleDateFormat; | 42 | import java.text.SimpleDateFormat; |
| 43 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
| 44 | import java.util.List; | 44 | import java.util.List; |
| 45 | 45 | ||
| 46 | import butterknife.BindView; | 46 | import butterknife.BindView; |
| 47 | import butterknife.OnClick; | 47 | import butterknife.OnClick; |
| 48 | import io.reactivex.Observer; | 48 | import io.reactivex.Observer; |
| 49 | import io.reactivex.disposables.Disposable; | 49 | import io.reactivex.disposables.Disposable; |
| 50 | 50 | ||
| 51 | public class HomeFragment extends BaseFragment { | 51 | public class HomeFragment extends BaseFragment { |
| 52 | @Override | 52 | @Override |
| 53 | protected int getLayoutRes() { | 53 | protected int getLayoutRes() { |
| 54 | return R.layout.fragment_home; | 54 | return R.layout.fragment_home; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | ImageView iv_sapmiao; | 57 | ImageView iv_sapmiao; |
| 58 | TextView tv_name; | 58 | TextView tv_name; |
| 59 | StudentBean studentBean; | 59 | StudentBean studentBean; |
| 60 | ImageView iv_2; | 60 | ImageView iv_2; |
| 61 | @BindView(R.id.recycle) | 61 | @BindView(R.id.recycle) |
| 62 | RecyclerView recyclerView; | 62 | RecyclerView recyclerView; |
| 63 | @BindView(R.id.tv_empty) | 63 | @BindView(R.id.tv_empty) |
| 64 | TextView tv_empty; | 64 | TextView tv_empty; |
| 65 | @BindView(R.id.iv_empty) | 65 | @BindView(R.id.iv_empty) |
| 66 | ImageView iv_empty; | 66 | ImageView iv_empty; |
| 67 | 67 | ||
| 68 | @Override | 68 | @Override |
| 69 | protected void initDatas() { | 69 | protected void initDatas() { |
| 70 | super.initDatas(); | 70 | super.initDatas(); |
| 71 | iv_2 = mRootView.findViewById(R.id.iv_2); | 71 | iv_2 = mRootView.findViewById(R.id.iv_2); |
| 72 | iv_sapmiao = mRootView.findViewById(R.id.iv_sapmiao); | 72 | iv_sapmiao = mRootView.findViewById(R.id.iv_sapmiao); |
| 73 | tv_name = mRootView.findViewById(R.id.tv_name); | 73 | tv_name = mRootView.findViewById(R.id.tv_name); |
| 74 | iv_sapmiao.setOnClickListener(view -> { | 74 | iv_sapmiao.setOnClickListener(view -> { |
| 75 | if (!XXPermissions.isGranted(getActivity(), Permission.CAMERA)) { | 75 | if (!XXPermissions.isGranted(getActivity(), Permission.CAMERA)) { |
| 76 | XXPermissions.with(getActivity()) | 76 | XXPermissions.with(getActivity()) |
| 77 | // 申请多个权限 | 77 | // 申请多个权限 |
| 78 | .permission(Permission.CAMERA) | 78 | .permission(Permission.CAMERA) |
| 79 | .request(new OnPermissionCallback() { | 79 | .request(new OnPermissionCallback() { |
| 80 | @Override | 80 | @Override |
| 81 | public void onGranted(List<String> permissions, boolean all) { | 81 | public void onGranted(List<String> permissions, boolean all) { |
| 82 | if (all) { | 82 | if (all) { |
| 83 | //开启扫码界面 | 83 | //开启扫码界面 |
| 84 | startQRView(); | 84 | startQRView(); |
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | } else { | 87 | } else { |
| 88 | Toast.makeText(getActivity(), "需要相机权限", Toast.LENGTH_SHORT).show(); | 88 | Toast.makeText(getActivity(), "需要相机权限", Toast.LENGTH_SHORT).show(); |
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | @Override | 92 | @Override |
| 93 | public void onDenied(List<String> permissions, boolean never) { | 93 | public void onDenied(List<String> permissions, boolean never) { |
| 94 | XXPermissions.startPermissionActivity(getActivity(), permissions); | 94 | XXPermissions.startPermissionActivity(getActivity(), permissions); |
| 95 | } | 95 | } |
| 96 | }); | 96 | }); |
| 97 | } else { | 97 | } else { |
| 98 | startQRView(); | 98 | startQRView(); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | }); | 101 | }); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | @OnClick(R.id.ll_error) | 104 | @OnClick(R.id.ll_error) |
| 105 | public void goError(View view) { | 105 | public void goError(View view) { |
| 106 | Intent intent = new Intent(getActivity(), ErrorBookActivity.class); | 106 | Intent intent = new Intent(getActivity(), ErrorBookActivity.class); |
| 107 | startActivity(intent); | 107 | startActivity(intent); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | @Override | 110 | @Override |
| 111 | public void onResume() { | 111 | public void onResume() { |
| 112 | super.onResume(); | 112 | super.onResume(); |
| 113 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 113 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
| 114 | try { | 114 | try { |
| 115 | studentBean = new Gson().fromJson(student, StudentBean.class); | 115 | studentBean = new Gson().fromJson(student, StudentBean.class); |
| 116 | tv_name.setText(studentBean.getNickName()); | 116 | tv_name.setText(studentBean.getNickName()); |
| 117 | if (TextUtils.isEmpty(studentBean.getPhoto())) { | 117 | if (TextUtils.isEmpty(studentBean.getPhoto())) { |
| 118 | iv_2.setImageResource(studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 118 | iv_2.setImageResource(studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
| 119 | } else { | 119 | } else { |
| 120 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 20)); | 120 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 20)); |
| 121 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 121 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
| 122 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into(iv_2); | 122 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into(iv_2); |
| 123 | } | 123 | } |
| 124 | getWeekPlan(studentBean.getStuId()); | 124 | getWeekPlan(studentBean.getStuId()); |
| 125 | } catch (Exception e) { | 125 | } catch (Exception e) { |
| 126 | 126 | ||
| 127 | } | 127 | } |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | public void getWeekPlan(String id) { | 130 | public void getWeekPlan(String id) { |
| 131 | NetWorks.getWeekPlan(id, new Observer<ResponseResult<ScheduleBean>>() { | 131 | NetWorks.getWeekPlan(id, new Observer<ResponseResult<ScheduleBean>>() { |
| 132 | @Override | 132 | @Override |
| 133 | public void onSubscribe(Disposable d) { | 133 | public void onSubscribe(Disposable d) { |
| 134 | 134 | ||
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | @Override | 137 | @Override |
| 138 | public void onNext(ResponseResult<ScheduleBean> result) { | 138 | public void onNext(ResponseResult<ScheduleBean> result) { |
| 139 | if (result != null && result.getCode() == 200) { | 139 | if (result != null && result.getCode() == 200) { |
| 140 | showWeekPlan(result.getData().getList()); | 140 | showWeekPlan(result.getData().getList()); |
| 141 | } | 141 | } |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | @Override | 144 | @Override |
| 145 | public void onError(Throwable e) { | 145 | public void onError(Throwable e) { |
| 146 | 146 | ||
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | @Override | 149 | @Override |
| 150 | public void onComplete() { | 150 | public void onComplete() { |
| 151 | 151 | ||
| 152 | } | 152 | } |
| 153 | }); | 153 | }); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | public void startQRView() { | 156 | public void startQRView() { |
| 157 | startActivityForResult(new Intent(getActivity(), QRActivity.class), 101); | 157 | startActivityForResult(new Intent(getActivity(), QRActivity.class), 101); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | @Override | 160 | @Override |
| 161 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 161 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 162 | super.onActivityResult(requestCode, resultCode, data); | 162 | super.onActivityResult(requestCode, resultCode, data); |
| 163 | if (requestCode == 101) { | 163 | if (requestCode == 101) { |
| 164 | if (null != data) { | 164 | if (null != data) { |
| 165 | Bundle bundle = data.getExtras(); | 165 | Bundle bundle = data.getExtras(); |
| 166 | if (bundle == null) { | 166 | if (bundle == null) { |
| 167 | return; | 167 | return; |
| 168 | } | 168 | } |
| 169 | if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) { | 169 | if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) { |
| 170 | String result = bundle.getString(CodeUtils.RESULT_STRING); | 170 | String result = bundle.getString(CodeUtils.RESULT_STRING); |
| 171 | Toast.makeText(getActivity(), "解析结果:" + result, Toast.LENGTH_LONG).show(); | 171 | Toast.makeText(getActivity(), "解析结果:" + result, Toast.LENGTH_LONG).show(); |
| 172 | } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) { | 172 | } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) { |
| 173 | Toast.makeText(getActivity(), "解析二维码失败", Toast.LENGTH_LONG).show(); | 173 | Toast.makeText(getActivity(), "解析二维码失败", Toast.LENGTH_LONG).show(); |
| 174 | } | 174 | } |
| 175 | } | 175 | } |
| 176 | } | 176 | } |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | @OnClick({R.id.iv_2, R.id.tv_name}) | 179 | @OnClick({R.id.iv_2, R.id.tv_name}) |
| 180 | public void choose(View view) { | 180 | public void choose(View view) { |
| 181 | Intent intent = new Intent(getActivity(), ChooseActivity.class); | 181 | Intent intent = new Intent(getActivity(), ChooseActivity.class); |
| 182 | startActivity(intent); | 182 | startActivity(intent); |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | @OnClick(R.id.iv_1) | 185 | @OnClick(R.id.iv_1) |
| 186 | public void exit(View view) { | 186 | public void exit(View view) { |
| 187 | getActivity().finish(); | 187 | getActivity().finish(); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | private void showWeekPlan(List<Video> list) { | 190 | private void showWeekPlan(List<Video> list) { |
| 191 | iv_empty.setVisibility(list.size() > 0 ? View.GONE : View.VISIBLE); | 191 | iv_empty.setVisibility(list.size() > 0 ? View.GONE : View.VISIBLE); |
| 192 | tv_empty.setVisibility(list.size() > 0 ? View.GONE : View.VISIBLE); | 192 | tv_empty.setVisibility(list.size() > 0 ? View.GONE : View.VISIBLE); |
| 193 | List<Schedule> schedules = new ArrayList<>(); | 193 | List<Schedule> schedules = new ArrayList<>(); |
| 194 | for (int i = 0; i < list.size(); i++) { | 194 | for (int i = 0; i < list.size(); i++) { |
| 195 | String date = new SimpleDateFormat("yyyy.MM.dd").format(list.get(i).getStudyTime()); | 195 | String date = new SimpleDateFormat("yyyy.MM.dd").format(list.get(i).getStudyTime()); |
| 196 | if (schedules.size() > 0 && schedules.get(schedules.size() - 1).getDate().equals(date)) { | 196 | if (schedules.size() > 0 && schedules.get(schedules.size() - 1).getDate().equals(date)) { |
| 197 | schedules.get(schedules.size() - 1).getStrings().add(list.get(i).getSectionChildName()); | 197 | schedules.get(schedules.size() - 1).getStrings().add(list.get(i).getSectionChildName()); |
| 198 | } else { | 198 | } else { |
| 199 | List<String> stringList = new ArrayList<>(); | 199 | List<String> stringList = new ArrayList<>(); |
| 200 | Schedule schedule = new Schedule(); | 200 | Schedule schedule = new Schedule(); |
| 201 | schedule.setDate(date); | 201 | schedule.setDate(date); |
| 202 | stringList.add(list.get(i).getSectionChildName()); | 202 | stringList.add(list.get(i).getSectionChildName()); |
| 203 | schedule.setStrings(stringList); | 203 | schedule.setStrings(stringList); |
| 204 | schedules.add(schedule); | 204 | schedules.add(schedule); |
| 205 | } | 205 | } |
| 206 | } | 206 | } |
| 207 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_schedule, schedules) { | 207 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_schedule, schedules) { |
| 208 | @Override | 208 | @Override |
| 209 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | ||
| 210 | |||
| 211 | } | ||
| 212 | |||
| 213 | @Override | ||
| 209 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 214 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
| 210 | Schedule schedule = schedules.get(item.getAdapterPosition()); | 215 | Schedule schedule = schedules.get(item.getAdapterPosition()); |
| 211 | item.setText(R.id.tv_date, schedule.getDate()); | 216 | item.setText(R.id.tv_date, schedule.getDate()); |
| 212 | LinearLayout layout = item.getView(R.id.ll_schedule); | 217 | LinearLayout layout = item.getView(R.id.ll_schedule); |
| 213 | for (int i = 0; i < schedule.getStrings().size(); i++) { | 218 | for (int i = 0; i < schedule.getStrings().size(); i++) { |
| 214 | View view = LayoutInflater.from(getContext()).inflate(R.layout.item_video, null); | 219 | View view = LayoutInflater.from(getContext()).inflate(R.layout.item_video, null); |
| 215 | TextView textView = view.findViewById(R.id.tv_name); | 220 | TextView textView = view.findViewById(R.id.tv_name); |
| 216 | textView.setText(schedule.getStrings().get(i)); | 221 | textView.setText(schedule.getStrings().get(i)); |
| 217 | layout.addView(view); | 222 | layout.addView(view); |
| 218 | } | 223 | } |
| 219 | } | 224 | } |
| 220 | }; | 225 | }; |
| 221 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false)); | 226 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false)); |
| 222 | recyclerView.setAdapter(adapter); | 227 | recyclerView.setAdapter(adapter); |
| 223 | } | 228 | } |
| 224 | 229 | ||
| 225 | class Schedule { | 230 | class Schedule { |
| 226 | String date; | 231 | String date; |
| 227 | List<String> strings; | 232 | List<String> strings; |
| 228 | 233 | ||
| 229 | public void setDate(String date) { | 234 | public void setDate(String date) { |
| 230 | this.date = date; | 235 | this.date = date; |
| 231 | } | 236 | } |
| 232 | 237 | ||
| 233 | public void setStrings(List<String> strings) { | 238 | public void setStrings(List<String> strings) { |
| 234 | this.strings = strings; | 239 | this.strings = strings; |
| 235 | } | 240 | } |
| 236 | 241 | ||
| 237 | public String getDate() { | 242 | public String getDate() { |
| 238 | return date; | 243 | return date; |
| 239 | } | 244 | } |
| 240 | 245 | ||
| 241 | public List<String> getStrings() { | 246 | public List<String> getStrings() { |
| 242 | return strings; | 247 | return strings; |
| 243 | } | 248 | } |
| 244 | } | 249 | } |
| 245 | } | 250 | } |
| 246 | 251 |