Commit f536f83fe340c6b8f6f60e36f386113a3684d35c
1 parent
36364a3420
Exists in
master
修改统一baidu key, 图片增强代替字迹擦除, 提前压缩图片
Showing
6 changed files
with
65 additions
and
22 deletions
Show diff stats
.idea/inspectionProfiles/Project_Default.xml
| 1 | <component name="InspectionProjectProfileManager"> | 1 | <component name="InspectionProjectProfileManager"> |
| 2 | <profile version="1.0"> | 2 | <profile version="1.0"> |
| 3 | <option name="myName" value="Project Default" /> | 3 | <option name="myName" value="Project Default" /> |
| 4 | <inspection_tool class="Deprecation" enabled="false" level="WARNING" enabled_by_default="false" /> | 4 | <inspection_tool class="Deprecation" enabled="false" level="WARNING" enabled_by_default="false" /> |
| 5 | <inspection_tool class="IgnoreResultOfCall" enabled="false" level="WARNING" enabled_by_default="false"> | 5 | <inspection_tool class="IgnoreResultOfCall" enabled="false" level="WARNING" enabled_by_default="false"> |
| 6 | <option name="m_reportAllNonLibraryCalls" value="false" /> | 6 | <option name="m_reportAllNonLibraryCalls" value="false" /> |
| 7 | <option name="callCheckString" value="java.io.File,.*,java.io.InputStream,read|skip|available|markSupported,java.io.Reader,read|skip|ready|markSupported,java.lang.AbstractStringBuilder,capacity|codePointAt|codePointBefore|codePointCount|indexOf|lastIndexOf|offsetByCodePoints|substring|subSequence,java.lang.Boolean,.*,java.lang.Byte,.*,java.lang.Character,.*,java.lang.Double,.*,java.lang.Float,.*,java.lang.Integer,.*,java.lang.Long,.*,java.lang.Math,.*,java.lang.Object,equals|hashCode|toString,java.lang.Short,.*,java.lang.StrictMath,.*,java.lang.String,.*,java.lang.Thread,interrupted,java.math.BigDecimal,.*,java.math.BigInteger,.*,java.net.InetAddress,.*,java.net.URI,.*,java.nio.channels.AsynchronousChannelGroup,.*,java.nio.channels.Channel,isOpen,java.nio.channels.FileChannel,open|map|lock|tryLock|write,java.nio.channels.ScatteringByteChannel,read,java.nio.channels.SocketChannel,open|socket|isConnected|isConnectionPending,java.util.Arrays,.*,java.util.Collections,(?!addAll).*,java.util.List,of,java.util.Map,of|ofEntries|entry,java.util.Set,of,java.util.UUID,.*,java.util.concurrent.BlockingQueue,offer|remove,java.util.concurrent.CountDownLatch,await|getCount,java.util.concurrent.ExecutorService,awaitTermination|isShutdown|isTerminated,java.util.concurrent.ForkJoinPool,awaitQuiescence,java.util.concurrent.Semaphore,tryAcquire|availablePermits|isFair|hasQueuedThreads|getQueueLength|getQueuedThreads,java.util.concurrent.locks.Condition,await|awaitNanos|awaitUntil,java.util.concurrent.locks.Lock,tryLock|newCondition,java.util.regex.Matcher,pattern|toMatchResult|start|end|group|groupCount|matches|find|lookingAt|quoteReplacement|replaceAll|replaceFirst|regionStart|regionEnd|hasTransparentBounds|hasAnchoringBounds|hitEnd|requireEnd,java.util.regex.Pattern,.*,java.util.stream.BaseStream,.*,java.util.stream.DoubleStream,.*,java.util.stream.IntStream,.*,java.util.stream.LongStream,.*,java.util.stream.Stream,.*" /> | 7 | <option name="callCheckString" value="java.io.File,.*,java.io.InputStream,read|skip|available|markSupported,java.io.Reader,read|skip|ready|markSupported,java.lang.AbstractStringBuilder,capacity|codePointAt|codePointBefore|codePointCount|indexOf|lastIndexOf|offsetByCodePoints|substring|subSequence,java.lang.Boolean,.*,java.lang.Byte,.*,java.lang.Character,.*,java.lang.Double,.*,java.lang.Float,.*,java.lang.Integer,.*,java.lang.Long,.*,java.lang.Math,.*,java.lang.Object,equals|hashCode|toString,java.lang.Short,.*,java.lang.StrictMath,.*,java.lang.String,.*,java.lang.Thread,interrupted,java.math.BigDecimal,.*,java.math.BigInteger,.*,java.net.InetAddress,.*,java.net.URI,.*,java.nio.channels.AsynchronousChannelGroup,.*,java.nio.channels.Channel,isOpen,java.nio.channels.FileChannel,open|map|lock|tryLock|write,java.nio.channels.ScatteringByteChannel,read,java.nio.channels.SocketChannel,open|socket|isConnected|isConnectionPending,java.util.Arrays,.*,java.util.Collections,(?!addAll).*,java.util.List,of,java.util.Map,of|ofEntries|entry,java.util.Set,of,java.util.UUID,.*,java.util.concurrent.BlockingQueue,offer|remove,java.util.concurrent.CountDownLatch,await|getCount,java.util.concurrent.ExecutorService,awaitTermination|isShutdown|isTerminated,java.util.concurrent.ForkJoinPool,awaitQuiescence,java.util.concurrent.Semaphore,tryAcquire|availablePermits|isFair|hasQueuedThreads|getQueueLength|getQueuedThreads,java.util.concurrent.locks.Condition,await|awaitNanos|awaitUntil,java.util.concurrent.locks.Lock,tryLock|newCondition,java.util.regex.Matcher,pattern|toMatchResult|start|end|group|groupCount|matches|find|lookingAt|quoteReplacement|replaceAll|replaceFirst|regionStart|regionEnd|hasTransparentBounds|hasAnchoringBounds|hitEnd|requireEnd,java.util.regex.Pattern,.*,java.util.stream.BaseStream,.*,java.util.stream.DoubleStream,.*,java.util.stream.IntStream,.*,java.util.stream.LongStream,.*,java.util.stream.Stream,.*" /> |
| 8 | </inspection_tool> | 8 | </inspection_tool> |
| 9 | <inspection_tool class="SameReturnValue" enabled="false" level="WARNING" enabled_by_default="false" /> | ||
| 9 | <inspection_tool class="UnnecessaryLocalVariable" enabled="false" level="WARNING" enabled_by_default="false"> | 10 | <inspection_tool class="UnnecessaryLocalVariable" enabled="false" level="WARNING" enabled_by_default="false"> |
| 10 | <option name="m_ignoreImmediatelyReturnedVariables" value="false" /> | 11 | <option name="m_ignoreImmediatelyReturnedVariables" value="false" /> |
| 11 | <option name="m_ignoreAnnotatedVariables" value="false" /> | 12 | <option name="m_ignoreAnnotatedVariables" value="false" /> |
| 12 | </inspection_tool> | 13 | </inspection_tool> |
| 13 | </profile> | 14 | </profile> |
| 14 | </component> | 15 | </component> |
app/src/main/java/com/hjx/parent/ImageActivity.java
| 1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
| 2 | 2 | ||
| 3 | import android.annotation.SuppressLint; | 3 | import android.annotation.SuppressLint; |
| 4 | import android.app.Dialog; | 4 | import android.app.Dialog; |
| 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.Rect; | 8 | import android.graphics.Rect; |
| 9 | import android.net.Uri; | 9 | import android.net.Uri; |
| 10 | import android.os.Bundle; | 10 | import android.os.Bundle; |
| 11 | import android.os.Handler; | 11 | import android.os.Handler; |
| 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.View; | 16 | import android.view.View; |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | import androidx.annotation.Nullable; | 19 | import androidx.annotation.Nullable; |
| 20 | import androidx.core.content.FileProvider; | 20 | import androidx.core.content.FileProvider; |
| 21 | import androidx.viewpager2.widget.ViewPager2; | 21 | import androidx.viewpager2.widget.ViewPager2; |
| 22 | 22 | ||
| 23 | import com.google.gson.Gson; | 23 | import com.google.gson.Gson; |
| 24 | import com.google.gson.JsonObject; | 24 | import com.google.gson.JsonObject; |
| 25 | import com.hjx.parent.adapter.ImageAdapter; | 25 | import com.hjx.parent.adapter.ImageAdapter; |
| 26 | import com.hjx.parent.databinding.ActivityImageBinding; | 26 | import com.hjx.parent.databinding.ActivityImageBinding; |
| 27 | import com.hjx.parent.databinding.ItemImageBinding; | 27 | import com.hjx.parent.databinding.ItemImageBinding; |
| 28 | import com.hjx.parent.dialog.AddHomeworkDialog; | 28 | import com.hjx.parent.dialog.AddHomeworkDialog; |
| 29 | import com.hjx.parent.dialog.ErrorInputDialog; | 29 | import com.hjx.parent.dialog.ErrorInputDialog; |
| 30 | import com.hjx.parent.dialog.PhotoViewDialog; | 30 | import com.hjx.parent.dialog.PhotoViewDialog; |
| 31 | import com.hjx.parent.dialog.TipDialog; | 31 | import com.hjx.parent.dialog.TipDialog; |
| 32 | import com.hjx.parent.rx.BaseRxActivity; | 32 | import com.hjx.parent.rx.BaseRxActivity; |
| 33 | import com.hjx.parent.utils.CutUtil; | 33 | import com.hjx.parent.utils.CutUtil; |
| 34 | import com.prws.common.bean.CutPicBean; | 34 | import com.prws.common.bean.CutPicBean; |
| 35 | import com.prws.common.bean.ImageBean; | 35 | import com.prws.common.bean.ImageBean; |
| 36 | import com.prws.common.bean.TopicBean; | 36 | import com.prws.common.bean.TopicBean; |
| 37 | import com.prws.common.net.NetWorks; | 37 | import com.prws.common.net.NetWorks; |
| 38 | import com.prws.common.utils.BitmapUtils; | 38 | import com.prws.common.utils.BitmapUtils; |
| 39 | import com.prws.common.utils.CommonUtil; | 39 | import com.prws.common.utils.CommonUtil; |
| 40 | import com.xiasuhuei321.loadingdialog.view.LoadingDialog; | 40 | import com.xiasuhuei321.loadingdialog.view.LoadingDialog; |
| 41 | 41 | ||
| 42 | import java.io.File; | 42 | import java.io.File; |
| 43 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
| 44 | import java.util.List; | 44 | import java.util.List; |
| 45 | import java.util.stream.Collectors; | ||
| 45 | 46 | ||
| 46 | import io.reactivex.Observer; | 47 | import io.reactivex.Observer; |
| 48 | import io.reactivex.Single; | ||
| 47 | import io.reactivex.disposables.Disposable; | 49 | import io.reactivex.disposables.Disposable; |
| 48 | import retrofit2.Call; | ||
| 49 | import retrofit2.Callback; | ||
| 50 | import retrofit2.Response; | ||
| 51 | 50 | ||
| 52 | public class ImageActivity extends BaseRxActivity<ActivityImageBinding> implements View.OnClickListener { | 51 | public class ImageActivity extends BaseRxActivity<ActivityImageBinding> implements View.OnClickListener { |
| 53 | 52 | ||
| 54 | private List<String> images = new ArrayList<>(); | 53 | private final List<String> images = new ArrayList<>(); |
| 55 | private ImageAdapter imageAdapter; | 54 | private ImageAdapter imageAdapter; |
| 56 | private List<ImageBean> list = new ArrayList<>(); | 55 | private List<ImageBean> list = new ArrayList<>(); |
| 57 | private String filePath; | 56 | private String filePath; |
| 58 | 57 | ||
| 59 | private int type = 0; | 58 | private int type = 0; |
| 60 | private AddHomeworkDialog addHomeworkDialog; | 59 | private AddHomeworkDialog addHomeworkDialog; |
| 61 | 60 | ||
| 61 | @SuppressLint("CheckResult") | ||
| 62 | @Override | 62 | @Override |
| 63 | public void initView(Bundle savedInstanceState) { | 63 | public void initView(Bundle savedInstanceState) { |
| 64 | type = getIntent().getIntExtra("type", 0); | 64 | type = getIntent().getIntExtra("type", 0); |
| 65 | binding.tvSave.setText(type == 0 ? "保存错题" : "录入题目"); | 65 | binding.tvSave.setText(type == 0 ? "保存错题" : "录入题目"); |
| 66 | 66 | ||
| 67 | images = getIntent().getStringArrayListExtra("images"); | 67 | List<String> originList = getIntent().getStringArrayListExtra("images"); |
| 68 | List<String> originListFinal = originList == null ? new ArrayList<>() : originList; | ||
| 69 | Single.fromCallable(() -> CutUtil.compressAllSync(this, originListFinal, 200)) | ||
| 70 | .map(it -> it.stream().map(File::getAbsolutePath).collect(Collectors.toList())) | ||
| 71 | .compose(transformSingle()) | ||
| 72 | .subscribe((it, throwable) -> { | ||
| 73 | if (throwable != null) Log.e(getClass().getName(), "", throwable); | ||
| 74 | images.clear(); | ||
| 75 | if (it == null) { | ||
| 76 | images.addAll(originListFinal); | ||
| 77 | } else { | ||
| 78 | images.addAll(it); | ||
| 79 | } | ||
| 80 | start(); | ||
| 81 | }); | ||
| 82 | } | ||
| 83 | |||
| 84 | private void start() { | ||
| 68 | if (images == null || images.size() <= 1) { | 85 | if (images == null || images.size() <= 1) { |
| 69 | binding.rlPrevious.setVisibility(View.GONE); | 86 | binding.rlPrevious.setVisibility(View.GONE); |
| 70 | binding.rlNext.setVisibility(View.GONE); | 87 | binding.rlNext.setVisibility(View.GONE); |
| 71 | } | 88 | } |
| 72 | for (String s : images) { | 89 | for (String s : images) { |
| 73 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; | 90 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; |
| 74 | ImageBean imageBean = new ImageBean(); | 91 | ImageBean imageBean = new ImageBean(); |
| 75 | Bitmap bitmap = BitmapUtils.getimage(s); | 92 | Bitmap bitmap = BitmapUtils.getimage(s); |
| 76 | CommonUtil.saveBitmapToUri(bitmap, filepath); | 93 | CommonUtil.saveBitmapToUri(bitmap, filepath); |
| 77 | imageBean.setPath(filepath); | 94 | imageBean.setPath(filepath); |
| 78 | imageBean.source = filepath; | 95 | imageBean.source = filepath; |
| 79 | list.add(imageBean); | 96 | list.add(imageBean); |
| 80 | } | 97 | } |
| 81 | imageAdapter = new ImageAdapter(this, list); | 98 | imageAdapter = new ImageAdapter(this, list); |
| 82 | binding.viewPager.setAdapter(imageAdapter); | 99 | binding.viewPager.setAdapter(imageAdapter); |
| 83 | binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { | 100 | binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { |
| 84 | @Override | 101 | @Override |
| 85 | public void onPageSelected(int position) { | 102 | public void onPageSelected(int position) { |
| 86 | if (list.get(position).getCuts() == null) { | 103 | if (list.get(position).getCuts() == null) { |
| 87 | // binding.ivPrevious.setEnabled(false); | ||
| 88 | // binding.ivNext.setEnabled(false); | ||
| 89 | clearText(); | 104 | clearText(); |
| 90 | } | 105 | } |
| 91 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); | 106 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); |
| 92 | if (position == 0) { | 107 | if (position == 0) { |
| 93 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous_gray); | 108 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous_gray); |
| 94 | // binding.ivPrevious.setEnabled(true); | ||
| 95 | } else { | 109 | } else { |
| 96 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous); | 110 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous); |
| 97 | // binding.ivPrevious.setEnabled(false); | ||
| 98 | } | 111 | } |
| 99 | if (position == list.size() - 1) { | 112 | if (position == list.size() - 1) { |
| 100 | binding.ivNext.setImageResource(R.mipmap.ic_next_gray); | 113 | binding.ivNext.setImageResource(R.mipmap.ic_next_gray); |
| 101 | // binding.ivNext.setEnabled(true); | ||
| 102 | } else { | 114 | } else { |
| 103 | binding.ivNext.setImageResource(R.mipmap.ic_next); | 115 | binding.ivNext.setImageResource(R.mipmap.ic_next); |
| 104 | // binding.ivNext.setEnabled(false); | ||
| 105 | } | 116 | } |
| 106 | super.onPageSelected(position); | 117 | super.onPageSelected(position); |
| 107 | } | 118 | } |
| 108 | }); | 119 | }); |
| 109 | binding.rlNext.setOnClickListener(this); | 120 | binding.rlNext.setOnClickListener(this); |
| 110 | binding.rlPrevious.setOnClickListener(this); | 121 | binding.rlPrevious.setOnClickListener(this); |
| 111 | binding.ivBack.setOnClickListener(this); | 122 | binding.ivBack.setOnClickListener(this); |
| 112 | binding.tvPhoto.setOnClickListener(this); | 123 | binding.tvPhoto.setOnClickListener(this); |
| 113 | binding.tvAdd.setOnClickListener(this); | 124 | binding.tvAdd.setOnClickListener(this); |
| 114 | binding.llEdit.setOnClickListener(this); | 125 | binding.llEdit.setOnClickListener(this); |
| 115 | binding.tvSave.setOnClickListener(this); | 126 | binding.tvSave.setOnClickListener(this); |
| 116 | binding.btnShowSource.setOnClickListener(v -> { | 127 | binding.btnShowSource.setOnClickListener(v -> { |
| 117 | if (list.isEmpty()) return; | 128 | if (list.isEmpty()) return; |
| 118 | ImageBean data = list.get(binding.viewPager.getCurrentItem()); | 129 | ImageBean data = list.get(binding.viewPager.getCurrentItem()); |
| 119 | new PhotoViewDialog(this).show(data.source); | 130 | new PhotoViewDialog(this).show(data.source); |
| 120 | }); | 131 | }); |
| 121 | 132 | ||
| 122 | binding.btnJudge.setVisibility(type == 0 ? View.VISIBLE : View.GONE); | 133 | binding.btnJudge.setVisibility(type == 0 ? View.VISIBLE : View.GONE); |
| 123 | binding.btnJudge.setOnClickListener(v -> { | 134 | binding.btnJudge.setOnClickListener(v -> { |
| 124 | goJudge(); | 135 | goJudge(); |
| 125 | }); | 136 | }); |
| 126 | } | 137 | } |
| 127 | 138 | ||
| 128 | private void goJudge() { | 139 | private void goJudge() { |
| 129 | if (list.isEmpty()) return; | 140 | if (list.isEmpty()) return; |
| 130 | int position = binding.viewPager.getCurrentItem(); | 141 | int position = binding.viewPager.getCurrentItem(); |
| 131 | ImageBean imageBean = list.get(position); | 142 | ImageBean imageBean = list.get(position); |
| 132 | Bitmap bitmap = BitmapFactory.decodeFile(imageBean.getPath()); | 143 | Bitmap bitmap = BitmapFactory.decodeFile(imageBean.getPath()); |
| 133 | if (bitmap == null || imageBean.getCuts() == null) { | 144 | if (bitmap == null || imageBean.getCuts() == null) { |
| 134 | showToast("请先框选题目"); | 145 | showToast("请先框选题目"); |
| 135 | return; | 146 | return; |
| 136 | } | 147 | } |
| 137 | ItemImageBinding ib = imageAdapter.viewArray.get(position); | 148 | ItemImageBinding ib = imageAdapter.viewArray.get(position); |
| 138 | if (ib == null) { | 149 | if (ib == null) { |
| 139 | showToast("出错"); | 150 | showToast("出错"); |
| 140 | return; | 151 | return; |
| 141 | } | 152 | } |
| 142 | View view = ib.ivPic; | 153 | View view = ib.ivPic; |
| 143 | float[] size = CutUtil.measureBitmap(view, bitmap); | 154 | float[] size = CutUtil.measureBitmap(view, bitmap); |
| 144 | 155 | ||
| 145 | ArrayList<Rect> rects = new ArrayList<>(); | 156 | ArrayList<Rect> rects = new ArrayList<>(); |
| 146 | for (ImageBean.Cut cut: imageBean.getCuts()) { | 157 | for (ImageBean.Cut cut: imageBean.getCuts()) { |
| 147 | if (cut.getRect1() == null) continue; | 158 | if (cut.getRect1() == null) continue; |
| 148 | Rect rectV = cut.getRect1(); | 159 | Rect rectV = cut.getRect1(); |
| 149 | rects.add(getRectB(rectV, bitmap, size)); | 160 | rects.add(getRectB(rectV, bitmap, size)); |
| 150 | } | 161 | } |
| 151 | if (list.isEmpty()) { | 162 | if (list.isEmpty()) { |
| 152 | showToast("请先框选题目"); | 163 | showToast("请先框选题目"); |
| 153 | return; | 164 | return; |
| 154 | } | 165 | } |
| 155 | 166 | ||
| 156 | Intent intent = new Intent(this, JudgeActivity.class); | 167 | Intent intent = new Intent(this, JudgeActivity.class); |
| 157 | intent.putExtra("path", imageBean.getPath()); | 168 | intent.putExtra("path", imageBean.getPath()); |
| 158 | intent.putParcelableArrayListExtra("rects", rects); | 169 | intent.putParcelableArrayListExtra("rects", rects); |
| 159 | 170 | ||
| 160 | startActivity(intent); | 171 | startActivity(intent); |
| 161 | } | 172 | } |
| 162 | 173 | ||
| 163 | private Rect getRectB(Rect rectV, Bitmap bitmap, float[] measuredSize) { | 174 | private Rect getRectB(Rect rectV, Bitmap bitmap, float[] measuredSize) { |
| 164 | float realW = measuredSize[0]; | 175 | float realW = measuredSize[0]; |
| 165 | float realH = measuredSize[1]; | 176 | float realH = measuredSize[1]; |
| 166 | float offsetX = measuredSize[2]; | 177 | float offsetX = measuredSize[2]; |
| 167 | float offsetY = measuredSize[3]; | 178 | float offsetY = measuredSize[3]; |
| 168 | float percentX = bitmap.getWidth() / realW; | 179 | float percentX = bitmap.getWidth() / realW; |
| 169 | float percentY = bitmap.getHeight() / realH; | 180 | float percentY = bitmap.getHeight() / realH; |
| 170 | 181 | ||
| 171 | float left = (rectV.left - offsetX) * percentX; | 182 | float left = (rectV.left - offsetX) * percentX; |
| 172 | float right = (rectV.right - offsetX) * percentX; | 183 | float right = (rectV.right - offsetX) * percentX; |
| 173 | float top = (rectV.top - offsetY) * percentY; | 184 | float top = (rectV.top - offsetY) * percentY; |
| 174 | float bottom = (rectV.bottom - offsetY) * percentY; | 185 | float bottom = (rectV.bottom - offsetY) * percentY; |
| 175 | Rect rectB = new Rect((int) left, (int) top, (int) right, (int) bottom); | 186 | Rect rectB = new Rect((int) left, (int) top, (int) right, (int) bottom); |
| 176 | return rectB; | 187 | return rectB; |
| 177 | } | 188 | } |
| 178 | 189 | ||
| 179 | public void clearText() { | 190 | public void clearText() { |
| 180 | int index = binding.viewPager.getCurrentItem(); | 191 | int index = binding.viewPager.getCurrentItem(); |
| 181 | showLoadingDialog(getString(R.string.loading_text), new LoadingDialog.DismissListener() { | 192 | showLoadingDialog(getString(R.string.loading_text), new LoadingDialog.DismissListener() { |
| 182 | @Override | 193 | @Override |
| 183 | public void dimiss() { | 194 | public void dimiss() { |
| 184 | // binding.ivPrevious.setEnabled(index != 0); | 195 | // binding.ivPrevious.setEnabled(index != 0); |
| 185 | // binding.ivNext.setEnabled(index != list.size() - 1); | 196 | // binding.ivNext.setEnabled(index != list.size() - 1); |
| 186 | } | 197 | } |
| 187 | }); | 198 | }); |
| 188 | Log.i("clearText", list.get(index).getPath()); | 199 | Log.i("clearText", list.get(index).getPath()); |
| 189 | String base64 = BitmapUtils.imageToBase64(list.get(index).getPath()); | 200 | String base64 = BitmapUtils.imageToBase64(list.get(index).getPath(), false); |
| 190 | NetWorks.removeWriting(base64, new Observer<JsonObject>() { | 201 | NetWorks.baiduEnhance(base64, new Observer<JsonObject>() { |
| 191 | @Override | 202 | @Override |
| 192 | public void onSubscribe(Disposable d) { | 203 | public void onSubscribe(Disposable d) { |
| 193 | 204 | ||
| 194 | } | 205 | } |
| 195 | 206 | ||
| 196 | @Override | 207 | @Override |
| 197 | public void onNext(JsonObject jsonObject) { | 208 | public void onNext(JsonObject jsonObject) { |
| 198 | if (jsonObject != null && jsonObject.get("image_processed") != null) { | 209 | if (jsonObject != null && jsonObject.get("image_processed") != null) { |
| 199 | String image = jsonObject.get("image_processed").getAsString(); | 210 | String image = jsonObject.get("image_processed").getAsString(); |
| 200 | if (image != null) { | 211 | if (image != null) { |
| 201 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 212 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 202 | CommonUtil.saveBitmapToUri(BitmapUtils.stringToBitmap(image), filepath); | 213 | CommonUtil.saveBitmapToUri(BitmapUtils.stringToBitmap(image), filepath); |
| 203 | list.get(index).setPath(filepath); | 214 | list.get(index).setPath(filepath); |
| 204 | if (list.get(index).getCuts() == null) { | 215 | if (list.get(index).getCuts() == null) { |
| 205 | list.get(index).setCuts(new ArrayList<>()); | 216 | list.get(index).setCuts(new ArrayList<>()); |
| 206 | } | 217 | } |
| 207 | imageAdapter.notifyItemChanged(index); | 218 | imageAdapter.notifyItemChanged(index); |
| 208 | cut(filepath); | 219 | cut(filepath); |
| 209 | } else { | 220 | } else { |
| 210 | loadFail("去除字迹失败"); | 221 | loadFail("去除字迹失败"); |
| 211 | } | 222 | } |
| 212 | } else { | 223 | } else { |
| 213 | loadFail("去除字迹失败"); | 224 | loadFail("去除字迹失败"); |
| 214 | } | 225 | } |
| 215 | } | 226 | } |
| 216 | 227 | ||
| 217 | @Override | 228 | @Override |
| 218 | public void onError(Throwable e) { | 229 | public void onError(Throwable e) { |
| 219 | e.printStackTrace(); | 230 | e.printStackTrace(); |
| 220 | loadFail("去除字迹失败"); | 231 | loadFail("去除字迹失败"); |
| 221 | } | 232 | } |
| 222 | 233 | ||
| 223 | @Override | 234 | @Override |
| 224 | public void onComplete() { | 235 | public void onComplete() { |
| 225 | 236 | ||
| 226 | } | 237 | } |
| 227 | }); | 238 | }); |
| 228 | } | 239 | } |
| 229 | 240 | ||
| 230 | public void cut(String path) { | 241 | public void cut(String path) { |
| 231 | String base64 = BitmapUtils.imageToBase64(path); | 242 | String base64 = BitmapUtils.imageToBase64WithUrlEncode(path); |
| 232 | Log.i("figLoaction", path); | 243 | Log.i("figLoaction", path); |
| 233 | NetWorks.cut(base64, new Observer<CutPicBean>() { | 244 | NetWorks.cut(base64, new Observer<CutPicBean>() { |
| 234 | @Override | 245 | @Override |
| 235 | public void onSubscribe(Disposable d) { | 246 | public void onSubscribe(Disposable d) { |
| 236 | 247 | ||
| 237 | } | 248 | } |
| 238 | 249 | ||
| 239 | @Override | 250 | @Override |
| 240 | public void onNext(CutPicBean cutPicBean) { | 251 | public void onNext(CutPicBean cutPicBean) { |
| 241 | if (cutPicBean != null) { | 252 | if (cutPicBean != null) { |
| 242 | if (cutPicBean.getDirection() != 0) { | 253 | if (cutPicBean.getDirection() != 0) { |
| 243 | rotatingImage(cutPicBean); | 254 | rotatingImage(cutPicBean); |
| 244 | } else { | 255 | } else { |
| 245 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { | 256 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { |
| 246 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); | 257 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); |
| 247 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { | 258 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { |
| 248 | figLoactions.add(cutLocation.getFig_location()); | 259 | figLoactions.add(cutLocation.getFig_location()); |
| 249 | } | 260 | } |
| 250 | new Handler().postDelayed(new Runnable() { | 261 | new Handler().postDelayed(new Runnable() { |
| 251 | @Override | 262 | @Override |
| 252 | public void run() { | 263 | public void run() { |
| 253 | getRects(figLoactions); | 264 | getRects(figLoactions); |
| 254 | } | 265 | } |
| 255 | }, 1000); | 266 | }, 1000); |
| 256 | } else { | 267 | } else { |
| 257 | cancelLoadingDialog(); | 268 | cancelLoadingDialog(); |
| 258 | } | 269 | } |
| 259 | } | 270 | } |
| 260 | } else { | 271 | } else { |
| 261 | loadFail("自动切题失败"); | 272 | loadFail("自动切题失败"); |
| 262 | } | 273 | } |
| 263 | } | 274 | } |
| 264 | 275 | ||
| 265 | @Override | 276 | @Override |
| 266 | public void onError(Throwable e) { | 277 | public void onError(Throwable e) { |
| 267 | loadFail("自动切题失败"); | 278 | loadFail("自动切题失败"); |
| 268 | } | 279 | } |
| 269 | 280 | ||
| 270 | @Override | 281 | @Override |
| 271 | public void onComplete() { | 282 | public void onComplete() { |
| 272 | 283 | ||
| 273 | } | 284 | } |
| 274 | }); | 285 | }); |
| 275 | } | 286 | } |
| 276 | 287 | ||
| 277 | private void getRects(List<CutPicBean.FigLoaction> figLoactions) { | 288 | private void getRects(List<CutPicBean.FigLoaction> figLoactions) { |
| 278 | Log.i("figLoaction", new Gson().toJson(figLoactions)); | 289 | Log.i("figLoaction", new Gson().toJson(figLoactions)); |
| 279 | int index = binding.viewPager.getCurrentItem(); | 290 | int index = binding.viewPager.getCurrentItem(); |
| 280 | List<ImageBean.Cut> cuts = new ArrayList<>(); | 291 | List<ImageBean.Cut> cuts = new ArrayList<>(); |
| 281 | for (CutPicBean.FigLoaction figLoaction : figLoactions) { | 292 | for (CutPicBean.FigLoaction figLoaction : figLoactions) { |
| 282 | ImageBean.Cut cut = new ImageBean.Cut(); | 293 | ImageBean.Cut cut = new ImageBean.Cut(); |
| 283 | cut.setRect(figLoaction); | 294 | cut.setRect(figLoaction); |
| 284 | cut.setSelect(false); | 295 | cut.setSelect(false); |
| 285 | cuts.add(cut); | 296 | cuts.add(cut); |
| 286 | } | 297 | } |
| 287 | list.get(index).setCuts(cuts); | 298 | list.get(index).setCuts(cuts); |
| 288 | imageAdapter.notifyItemChanged(index); | 299 | imageAdapter.notifyItemChanged(index); |
| 289 | cancelLoadingDialog(); | 300 | cancelLoadingDialog(); |
| 290 | } | 301 | } |
| 291 | 302 | ||
| 292 | private void rotatingImage(CutPicBean cutPicBean) { | 303 | private void rotatingImage(CutPicBean cutPicBean) { |
| 293 | int index = binding.viewPager.getCurrentItem(); | 304 | int index = binding.viewPager.getCurrentItem(); |
| 294 | Bitmap bitmap = BitmapFactory.decodeFile(list.get(index).getPath()); | 305 | Bitmap bitmap = BitmapFactory.decodeFile(list.get(index).getPath()); |
| 295 | int angle = 0; | 306 | int angle = 0; |
| 296 | switch (cutPicBean.getDirection()) { | 307 | switch (cutPicBean.getDirection()) { |
| 297 | case 1: | 308 | case 1: |
| 298 | angle = 90; | 309 | angle = 90; |
| 299 | break; | 310 | break; |
| 300 | case 2: | 311 | case 2: |
| 301 | angle = 180; | 312 | angle = 180; |
| 302 | break; | 313 | break; |
| 303 | case 3: | 314 | case 3: |
| 304 | angle = 270; | 315 | angle = 270; |
| 305 | break; | 316 | break; |
| 306 | } | 317 | } |
| 307 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { | 318 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { |
| 308 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); | 319 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); |
| 309 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { | 320 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { |
| 310 | figLoactions.add(cutLocation.getFig_location()); | 321 | figLoactions.add(cutLocation.getFig_location()); |
| 311 | } | 322 | } |
| 312 | figLoactions = CommonUtil.rotaingLocation(angle, figLoactions, bitmap.getWidth(), bitmap.getHeight()); | 323 | figLoactions = CommonUtil.rotaingLocation(angle, figLoactions, bitmap.getWidth(), bitmap.getHeight()); |
| 313 | bitmap = CommonUtil.rotaingImageView(angle, bitmap); | 324 | bitmap = CommonUtil.rotaingImageView(angle, bitmap); |
| 314 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 325 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 315 | CommonUtil.saveBitmapToUri(bitmap, filepath); | 326 | CommonUtil.saveBitmapToUri(bitmap, filepath); |
| 316 | list.get(index).setPath(filepath); | 327 | list.get(index).setPath(filepath); |
| 317 | imageAdapter.notifyItemChanged(index); | 328 | imageAdapter.notifyItemChanged(index); |
| 318 | List<CutPicBean.FigLoaction> finalFigLoactions = figLoactions; | 329 | List<CutPicBean.FigLoaction> finalFigLoactions = figLoactions; |
| 319 | new Handler().postDelayed(new Runnable() { | 330 | new Handler().postDelayed(new Runnable() { |
| 320 | @Override | 331 | @Override |
| 321 | public void run() { | 332 | public void run() { |
| 322 | getRects(finalFigLoactions); | 333 | getRects(finalFigLoactions); |
| 323 | } | 334 | } |
| 324 | }, 500); | 335 | }, 500); |
| 325 | } else { | 336 | } else { |
| 326 | cancelLoadingDialog(); | 337 | cancelLoadingDialog(); |
| 327 | } | 338 | } |
| 328 | } | 339 | } |
| 329 | 340 | ||
| 330 | @Override | 341 | @Override |
| 331 | protected ActivityImageBinding getViewBinding() { | 342 | protected ActivityImageBinding getViewBinding() { |
| 332 | return ActivityImageBinding.inflate(getLayoutInflater()); | 343 | return ActivityImageBinding.inflate(getLayoutInflater()); |
| 333 | } | 344 | } |
| 334 | 345 | ||
| 335 | @SuppressLint("SetTextI18n") | 346 | @SuppressLint("SetTextI18n") |
| 336 | public void refreshNum() { | 347 | public void refreshNum() { |
| 337 | int num = 0; | 348 | int num = 0; |
| 338 | for (ImageBean imageBean : list) { | 349 | for (ImageBean imageBean : list) { |
| 339 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { | 350 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { |
| 340 | for (ImageBean.Cut cut : imageBean.getCuts()) { | 351 | for (ImageBean.Cut cut : imageBean.getCuts()) { |
| 341 | if (cut.isSelect()) { | 352 | if (cut.isSelect()) { |
| 342 | num++; | 353 | num++; |
| 343 | } | 354 | } |
| 344 | } | 355 | } |
| 345 | } | 356 | } |
| 346 | } | 357 | } |
| 347 | String btnText = type == 0 ? "保存错题" : "录入题目"; | 358 | String btnText = type == 0 ? "保存错题" : "录入题目"; |
| 348 | if (num > 0) { | 359 | if (num > 0) { |
| 349 | binding.tvSave.setEnabled(true); | 360 | binding.tvSave.setEnabled(true); |
| 350 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_5); | 361 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_5); |
| 351 | binding.tvSave.setText(btnText + "(" + num + ")"); | 362 | binding.tvSave.setText(btnText + "(" + num + ")"); |
| 352 | } else { | 363 | } else { |
| 353 | binding.tvSave.setEnabled(false); | 364 | binding.tvSave.setEnabled(false); |
| 354 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_light_5); | 365 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_light_5); |
| 355 | binding.tvSave.setText(btnText); | 366 | binding.tvSave.setText(btnText); |
| 356 | } | 367 | } |
| 357 | } | 368 | } |
| 358 | 369 | ||
| 359 | @Override | 370 | @Override |
| 360 | public void onClick(View v) { | 371 | public void onClick(View v) { |
| 361 | switch (v.getId()) { | 372 | switch (v.getId()) { |
| 362 | case R.id.iv_back: | 373 | case R.id.iv_back: |
| 363 | back(); | 374 | back(); |
| 364 | break; | 375 | break; |
| 365 | case R.id.rl_next: | 376 | case R.id.rl_next: |
| 366 | if (binding.viewPager.getCurrentItem() + 1 < list.size()) { | 377 | if (binding.viewPager.getCurrentItem() + 1 < list.size()) { |
| 367 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() + 1); | 378 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() + 1); |
| 368 | } | 379 | } |
| 369 | break; | 380 | break; |
| 370 | case R.id.rl_previous: | 381 | case R.id.rl_previous: |
| 371 | if (binding.viewPager.getCurrentItem() != 0) { | 382 | if (binding.viewPager.getCurrentItem() != 0) { |
| 372 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() - 1); | 383 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() - 1); |
| 373 | } | 384 | } |
| 374 | break; | 385 | break; |
| 375 | case R.id.ll_edit: | 386 | case R.id.ll_edit: |
| 376 | Intent intent = new Intent(context, ImageEditActivity.class); | 387 | Intent intent = new Intent(context, ImageEditActivity.class); |
| 377 | intent.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); | 388 | intent.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); |
| 378 | startActivityForResult(intent, 1001); | 389 | startActivityForResult(intent, 1001); |
| 379 | break; | 390 | break; |
| 380 | case R.id.tv_photo: | 391 | case R.id.tv_photo: |
| 381 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 392 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| 382 | //确保有相机来处理Intent | 393 | //确保有相机来处理Intent |
| 383 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 394 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 384 | File photoFile = new File(filePath); | 395 | File photoFile = new File(filePath); |
| 385 | if (photoFile != null) { | 396 | if (photoFile != null) { |
| 386 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | 397 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri |
| 387 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); | 398 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); |
| 388 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 399 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| 389 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | 400 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); |
| 390 | activity.startActivityForResult(takePictureIntent, 1002); | 401 | activity.startActivityForResult(takePictureIntent, 1002); |
| 391 | } | 402 | } |
| 392 | break; | 403 | break; |
| 393 | case R.id.tv_add: | 404 | case R.id.tv_add: |
| 394 | Intent intent1 = new Intent(context, ImageSelectActivity.class); | 405 | Intent intent1 = new Intent(context, ImageSelectActivity.class); |
| 395 | intent1.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); | 406 | intent1.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); |
| 396 | intent1.putExtra("source", list.get(binding.viewPager.getCurrentItem()).source); | 407 | intent1.putExtra("source", list.get(binding.viewPager.getCurrentItem()).source); |
| 397 | startActivityForResult(intent1, 1001); | 408 | startActivityForResult(intent1, 1001); |
| 398 | break; | 409 | break; |
| 399 | case R.id.tv_save: | 410 | case R.id.tv_save: |
| 400 | List<TopicBean> topicBeans = new ArrayList<>(); | 411 | List<TopicBean> topicBeans = new ArrayList<>(); |
| 401 | for (ImageBean imageBean : list) { | 412 | for (ImageBean imageBean : list) { |
| 402 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { | 413 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { |
| 403 | for (ImageBean.Cut cut : imageBean.getCuts()) { | 414 | for (ImageBean.Cut cut : imageBean.getCuts()) { |
| 404 | if (cut.isSelect()) { | 415 | if (cut.isSelect()) { |
| 405 | TopicBean bean = new TopicBean(); | 416 | TopicBean bean = new TopicBean(); |
| 406 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 417 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 407 | BitmapUtils.saveBitmap(cut.getBitmap(), path); | 418 | BitmapUtils.saveBitmap(cut.getBitmap(), path); |
| 408 | bean.setPath(path); | 419 | bean.setPath(path); |
| 409 | topicBeans.add(bean); | 420 | topicBeans.add(bean); |
| 410 | } | 421 | } |
| 411 | } | 422 | } |
| 412 | } | 423 | } |
| 413 | } | 424 | } |
| 414 | save(topicBeans); | 425 | save(topicBeans); |
| 415 | break; | 426 | break; |
| 416 | } | 427 | } |
| 417 | } | 428 | } |
| 418 | 429 | ||
| 419 | private void save(List<TopicBean> topicBeans) { | 430 | private void save(List<TopicBean> topicBeans) { |
| 420 | if (type == 0) { | 431 | if (type == 0) { |
| 421 | ErrorInputDialog dialog = new ErrorInputDialog(this, topicBeans); | 432 | ErrorInputDialog dialog = new ErrorInputDialog(this, topicBeans); |
| 422 | dialog.show(); | 433 | dialog.show(); |
| 423 | } else { | 434 | } else { |
| 424 | List<String> paths = new ArrayList<>(); | 435 | List<String> paths = new ArrayList<>(); |
| 425 | for (TopicBean it: topicBeans) { | 436 | for (TopicBean it: topicBeans) { |
| 426 | paths.add(it.getPath()); | 437 | paths.add(it.getPath()); |
| 427 | } | 438 | } |
| 428 | if (addHomeworkDialog == null) { | 439 | if (addHomeworkDialog == null) { |
| 429 | addHomeworkDialog = new AddHomeworkDialog(this); | 440 | addHomeworkDialog = new AddHomeworkDialog(this); |
| 430 | } | 441 | } |
| 431 | addHomeworkDialog.show(paths, student -> { | 442 | addHomeworkDialog.show(paths, student -> { |
| 432 | Intent intent = new Intent(context, AddSuccessActivity.class); | 443 | Intent intent = new Intent(context, AddSuccessActivity.class); |
| 433 | intent.putExtra("type", type); | 444 | intent.putExtra("type", type); |
| 434 | intent.putExtra("studentJson", new Gson().toJson(student)); | 445 | intent.putExtra("studentJson", new Gson().toJson(student)); |
| 435 | startActivity(intent); | 446 | startActivity(intent); |
| 436 | finish(); | 447 | finish(); |
| 437 | }); | 448 | }); |
| 438 | } | 449 | } |
| 439 | } | 450 | } |
| 440 | 451 | ||
| 441 | @Override | 452 | @Override |
| 442 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 453 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 443 | super.onActivityResult(requestCode, resultCode, data); | 454 | super.onActivityResult(requestCode, resultCode, data); |
| 444 | if (requestCode == 1001) { | 455 | if (requestCode == 1001) { |
| 445 | if (resultCode == 1002) { | 456 | if (resultCode == 1002) { |
| 446 | if (list.size() > 1) { | 457 | if (list.size() > 1) { |
| 447 | list.remove(binding.viewPager.getCurrentItem()); | 458 | list.remove(binding.viewPager.getCurrentItem()); |
| 448 | if (list.size() <= 1) { | 459 | if (list.size() <= 1) { |
| 449 | binding.rlPrevious.setVisibility(View.GONE); | 460 | binding.rlPrevious.setVisibility(View.GONE); |
| 450 | binding.rlNext.setVisibility(View.GONE); | 461 | binding.rlNext.setVisibility(View.GONE); |
| 451 | } | 462 | } |
| 452 | imageAdapter.notifyItemRemoved(binding.viewPager.getCurrentItem()); | 463 | imageAdapter.notifyItemRemoved(binding.viewPager.getCurrentItem()); |
| 453 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); | 464 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); |
| 454 | refreshNum(); | 465 | refreshNum(); |
| 455 | } else { | 466 | } else { |
| 456 | finish(); | 467 | finish(); |
| 457 | } | 468 | } |
| 458 | } else if (resultCode == 1003) { | 469 | } else if (resultCode == 1003) { |
| 459 | int position = binding.viewPager.getCurrentItem(); | 470 | int position = binding.viewPager.getCurrentItem(); |
| 460 | String src = list.get(position).source; | 471 | String src = list.get(position).source; |
| 461 | list.remove(position); | 472 | list.remove(position); |
| 462 | String path = data.getStringExtra("path"); | 473 | String path = data.getStringExtra("path"); |
| 463 | ImageBean imageBean = new ImageBean(); | 474 | ImageBean imageBean = new ImageBean(); |
| 464 | imageBean.setPath(path); | 475 | imageBean.setPath(path); |
| 465 | imageBean.source = src; | 476 | imageBean.source = src; |
| 466 | list.add(position, imageBean); | 477 | list.add(position, imageBean); |
| 467 | imageAdapter.notifyItemChanged(position); | 478 | imageAdapter.notifyItemChanged(position); |
| 468 | clearText(); | 479 | clearText(); |
| 469 | refreshNum(); | 480 | refreshNum(); |
| 470 | } else if (resultCode == 1004) { | 481 | } else if (resultCode == 1004) { |
| 471 | Rect rect = data.getParcelableExtra("cut"); | 482 | Rect rect = data.getParcelableExtra("cut"); |
| 472 | if (rect != null) { | 483 | if (rect != null) { |
| 473 | int position = binding.viewPager.getCurrentItem(); | 484 | int position = binding.viewPager.getCurrentItem(); |
| 474 | ImageBean.Cut cut = new ImageBean.Cut(); | 485 | ImageBean.Cut cut = new ImageBean.Cut(); |
| 475 | cut.setRect1(rect); | 486 | cut.setRect1(rect); |
| 476 | cut.setSelect(false); | 487 | cut.setSelect(false); |
| 477 | if (list.get(position).getCuts() != null) { | 488 | if (list.get(position).getCuts() != null) { |
| 478 | list.get(position).getCuts().add(cut); | 489 | list.get(position).getCuts().add(cut); |
| 479 | } else { | 490 | } else { |
| 480 | List<ImageBean.Cut> cuts =new ArrayList<>(); | 491 | List<ImageBean.Cut> cuts =new ArrayList<>(); |
| 481 | cuts.add(cut); | 492 | cuts.add(cut); |
| 482 | list.get(position).setCuts(cuts); | 493 | list.get(position).setCuts(cuts); |
| 483 | } | 494 | } |
| 484 | imageAdapter.notifyItemChanged(position); | 495 | imageAdapter.notifyItemChanged(position); |
| 485 | refreshNum(); | 496 | refreshNum(); |
| 486 | } | 497 | } |
| 487 | } else if (resultCode == 1005) { | 498 | } else if (resultCode == 1005) { |
| 488 | int i = data.getIntExtra("position", 0); | 499 | int i = data.getIntExtra("position", 0); |
| 489 | int position = binding.viewPager.getCurrentItem(); | 500 | int position = binding.viewPager.getCurrentItem(); |
| 490 | Rect rect = data.getParcelableExtra("cut"); | 501 | Rect rect = data.getParcelableExtra("cut"); |
| 491 | if (rect != null) { | 502 | if (rect != null) { |
| 492 | ImageBean.Cut cut = new ImageBean.Cut(); | 503 | ImageBean.Cut cut = new ImageBean.Cut(); |
| 493 | cut.setRect1(rect); | 504 | cut.setRect1(rect); |
| 494 | cut.setSelect(false); | 505 | cut.setSelect(false); |
| 495 | list.get(position).getCuts().remove(i); | 506 | list.get(position).getCuts().remove(i); |
| 496 | list.get(position).getCuts().add(i, cut); | 507 | list.get(position).getCuts().add(i, cut); |
| 497 | imageAdapter.notifyItemChanged(position); | 508 | imageAdapter.notifyItemChanged(position); |
| 498 | refreshNum(); | 509 | refreshNum(); |
| 499 | } else { | 510 | } else { |
| 500 | list.get(position).getCuts().remove(i); | 511 | list.get(position).getCuts().remove(i); |
| 501 | imageAdapter.notifyItemChanged(position); | 512 | imageAdapter.notifyItemChanged(position); |
| 502 | refreshNum(); | 513 | refreshNum(); |
| 503 | } | 514 | } |
| 504 | } | 515 | } |
| 505 | } else if (requestCode == 1002 && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { | 516 | } else if (requestCode == 1002 && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { |
| 506 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); | 517 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
| 507 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 518 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 508 | CommonUtil.saveBitmapToUri(b, path); | 519 | CommonUtil.saveBitmapToUri(b, path); |
| 509 | int position = binding.viewPager.getCurrentItem(); | 520 | int position = binding.viewPager.getCurrentItem(); |
| 510 | list.remove(position); | 521 | list.remove(position); |
| 511 | ImageBean imageBean = new ImageBean(); | 522 | ImageBean imageBean = new ImageBean(); |
| 512 | imageBean.setPath(path); | 523 | imageBean.setPath(path); |
| 513 | imageBean.source = path; | 524 | imageBean.source = path; |
| 514 | list.add(position, imageBean); | 525 | list.add(position, imageBean); |
| 515 | imageAdapter.notifyItemChanged(position); | 526 | imageAdapter.notifyItemChanged(position); |
| 516 | clearText(); | 527 | clearText(); |
| 517 | refreshNum(); | 528 | refreshNum(); |
| 518 | } | 529 | } |
| 519 | } | 530 | } |
| 520 | 531 | ||
| 521 | private void back() { | 532 | private void back() { |
| 522 | showTipDialog("温馨提示", "是否确认退出?", "取消", "确定", new TipDialog.TipDialogInterface() { | 533 | showTipDialog("温馨提示", "是否确认退出?", "取消", "确定", new TipDialog.TipDialogInterface() { |
| 523 | @Override | 534 | @Override |
| 524 | public void onConfirm(Dialog dialog) { | 535 | public void onConfirm(Dialog dialog) { |
| 525 | dialog.dismiss(); | 536 | dialog.dismiss(); |
| 526 | finish(); | 537 | finish(); |
| 527 | } | 538 | } |
| 528 | 539 | ||
| 529 | @Override | 540 | @Override |
| 530 | public void onCancel(Dialog dialog) { | 541 | public void onCancel(Dialog dialog) { |
| 531 | dialog.dismiss(); | 542 | dialog.dismiss(); |
| 532 | } | 543 | } |
| 533 | }); | 544 | }); |
| 534 | } | 545 | } |
| 535 | 546 | ||
| 536 | @Override | 547 | @Override |
app/src/main/java/com/hjx/parent/utils/CutUtil.java
| 1 | package com.hjx.parent.utils; | 1 | package com.hjx.parent.utils; |
| 2 | 2 | ||
| 3 | import android.content.Context; | 3 | import android.content.Context; |
| 4 | import android.graphics.Bitmap; | 4 | import android.graphics.Bitmap; |
| 5 | import android.graphics.Canvas; | 5 | import android.graphics.Canvas; |
| 6 | import android.graphics.Color; | 6 | import android.graphics.Color; |
| 7 | import android.graphics.Paint; | 7 | import android.graphics.Paint; |
| 8 | import android.util.Base64; | 8 | import android.util.Base64; |
| 9 | import android.view.View; | 9 | import android.view.View; |
| 10 | import android.view.ViewTreeObserver; | 10 | import android.view.ViewTreeObserver; |
| 11 | 11 | ||
| 12 | import com.bumptech.glide.Glide; | 12 | import com.bumptech.glide.Glide; |
| 13 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; | 13 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; |
| 14 | import com.hjx.parent.function.Function1; | 14 | import com.hjx.parent.function.Function1; |
| 15 | 15 | ||
| 16 | import java.io.ByteArrayOutputStream; | 16 | import java.io.ByteArrayOutputStream; |
| 17 | import java.io.File; | ||
| 18 | import java.io.IOException; | ||
| 19 | import java.util.List; | ||
| 20 | |||
| 21 | import top.zibin.luban.Luban; | ||
| 17 | 22 | ||
| 18 | public class CutUtil { | 23 | public class CutUtil { |
| 19 | 24 | ||
| 20 | public static float[] measureBitmap(View view, Bitmap bitmap) { | 25 | public static float[] measureBitmap(View view, Bitmap bitmap) { |
| 21 | float realW; | 26 | float realW; |
| 22 | float realH; | 27 | float realH; |
| 23 | float offsetX; | 28 | float offsetX; |
| 24 | float offsetY; | 29 | float offsetY; |
| 25 | 30 | ||
| 26 | float vp = 1f * view.getWidth() / view.getHeight(); | 31 | float vp = 1f * view.getWidth() / view.getHeight(); |
| 27 | float bp = 1f * bitmap.getWidth() / bitmap.getHeight(); | 32 | float bp = 1f * bitmap.getWidth() / bitmap.getHeight(); |
| 28 | 33 | ||
| 29 | if (vp > bp) { | 34 | if (vp > bp) { |
| 30 | realW = view.getHeight() * bp; | 35 | realW = view.getHeight() * bp; |
| 31 | realH = (float) view.getHeight(); | 36 | realH = (float) view.getHeight(); |
| 32 | offsetY = 0f; | 37 | offsetY = 0f; |
| 33 | offsetX = (view.getWidth() - realW) * 0.5f; | 38 | offsetX = (view.getWidth() - realW) * 0.5f; |
| 34 | } else if (vp < bp) { | 39 | } else if (vp < bp) { |
| 35 | realW = (float) view.getWidth(); | 40 | realW = (float) view.getWidth(); |
| 36 | realH = view.getWidth() * (1f / bp); | 41 | realH = view.getWidth() * (1f / bp); |
| 37 | offsetX = 0f; | 42 | offsetX = 0f; |
| 38 | offsetY = (view.getHeight() - realH) * 0.5f; | 43 | offsetY = (view.getHeight() - realH) * 0.5f; |
| 39 | } else { | 44 | } else { |
| 40 | realW = (float) view.getWidth(); | 45 | realW = (float) view.getWidth(); |
| 41 | realH = (float) view.getHeight(); | 46 | realH = (float) view.getHeight(); |
| 42 | offsetX = 0f; | 47 | offsetX = 0f; |
| 43 | offsetY = 0f; | 48 | offsetY = 0f; |
| 44 | } | 49 | } |
| 45 | 50 | ||
| 46 | return new float[]{realW, realH, offsetX, offsetY}; | 51 | return new float[]{realW, realH, offsetX, offsetY}; |
| 47 | } | 52 | } |
| 48 | 53 | ||
| 49 | public static Bitmap cut(Bitmap source, float x, float y, int w, int h, Context context) { | 54 | public static Bitmap cut(Bitmap source, float x, float y, int w, int h, Context context) { |
| 50 | // 获取 Glide 的 BitmapPool | 55 | // 获取 Glide 的 BitmapPool |
| 51 | BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); | 56 | BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); |
| 52 | 57 | ||
| 53 | // 从 BitmapPool 中获取可复用的 Bitmap | 58 | // 从 BitmapPool 中获取可复用的 Bitmap |
| 54 | Bitmap result = bitmapPool.get(w, h, source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888); | 59 | Bitmap result = bitmapPool.get(w, h, source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888); |
| 55 | 60 | ||
| 56 | // 填充白色背景 | 61 | // 填充白色背景 |
| 57 | result.eraseColor(Color.WHITE); | 62 | result.eraseColor(Color.WHITE); |
| 58 | 63 | ||
| 59 | // 创建画布并绘制 | 64 | // 创建画布并绘制 |
| 60 | Canvas canvas = new Canvas(result); | 65 | Canvas canvas = new Canvas(result); |
| 61 | Paint paint = new Paint(); | 66 | Paint paint = new Paint(); |
| 62 | canvas.drawBitmap(source, -x, -y, paint); | 67 | canvas.drawBitmap(source, -x, -y, paint); |
| 63 | 68 | ||
| 64 | return result; | 69 | return result; |
| 65 | } | 70 | } |
| 66 | 71 | ||
| 67 | public static void onLayoutReady(final View view, final Function1<View> action) { | 72 | public static void onLayoutReady(final View view, final Function1<View> action) { |
| 68 | view.getViewTreeObserver().addOnGlobalLayoutListener( | 73 | view.getViewTreeObserver().addOnGlobalLayoutListener( |
| 69 | new ViewTreeObserver.OnGlobalLayoutListener() { | 74 | new ViewTreeObserver.OnGlobalLayoutListener() { |
| 70 | @Override | 75 | @Override |
| 71 | public void onGlobalLayout() { | 76 | public void onGlobalLayout() { |
| 72 | view.getViewTreeObserver().removeOnGlobalLayoutListener(this); | 77 | view.getViewTreeObserver().removeOnGlobalLayoutListener(this); |
| 73 | action.invoke(view); | 78 | action.invoke(view); |
| 74 | } | 79 | } |
| 75 | } | 80 | } |
| 76 | ); | 81 | ); |
| 77 | } | 82 | } |
| 78 | 83 | ||
| 79 | public static byte[] bitmapToByteArray(Bitmap bitmap) { | 84 | public static byte[] bitmapToByteArray(Bitmap bitmap) { |
| 80 | ByteArrayOutputStream output = new ByteArrayOutputStream(); | 85 | ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| 81 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output); | 86 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output); |
| 82 | return output.toByteArray(); | 87 | return output.toByteArray(); |
| 83 | } | 88 | } |
| 84 | 89 | ||
| 85 | public static String bitmapToBase64(Bitmap bitmap, Boolean usePrefix) { | 90 | public static String bitmapToBase64(Bitmap bitmap, Boolean usePrefix) { |
| 86 | String base64 = Base64.encodeToString(bitmapToByteArray(bitmap), Base64.NO_WRAP); | 91 | String base64 = Base64.encodeToString(bitmapToByteArray(bitmap), Base64.NO_WRAP); |
| 87 | if (usePrefix) return "data:image/jpeg;base64," + base64; | 92 | if (usePrefix) return "data:image/jpeg;base64," + base64; |
| 88 | else return base64; | 93 | else return base64; |
| 89 | } | 94 | } |
| 95 | |||
| 96 | public static List<File> compressAllSync(Context context, List<String> originList, int ignore) throws IOException { | ||
| 97 | return Luban.with(context).ignoreBy(ignore) | ||
| 98 | .setTargetDir(context.getExternalCacheDir().getAbsolutePath()) | ||
| 99 | .load(originList) | ||
| 100 | .get(); | ||
| 101 | } | ||
| 90 | } | 102 | } |
| 91 | 103 |
libs/common/build.gradle
| 1 | apply plugin: 'com.android.library' | 1 | apply plugin: 'com.android.library' |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | def androidId = rootProject.ext.androidId | 4 | def androidId = rootProject.ext.androidId |
| 5 | def support = rootProject.ext.dependencies | 5 | def support = rootProject.ext.dependencies |
| 6 | def url = rootProject.ext.url | 6 | def url = rootProject.ext.url |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | android { | 9 | android { |
| 10 | compileSdkVersion androidId.compileSdkVersion | 10 | compileSdkVersion androidId.compileSdkVersion |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | defaultConfig { | 13 | defaultConfig { |
| 14 | minSdkVersion androidId.minSdkVersion | 14 | minSdkVersion androidId.minSdkVersion |
| 15 | targetSdkVersion androidId.targetSdkVersion | 15 | targetSdkVersion androidId.targetSdkVersion |
| 16 | versionCode androidId.versionCode | 16 | versionCode androidId.versionCode |
| 17 | versionName androidId.versionName | 17 | versionName androidId.versionName |
| 18 | 18 | ||
| 19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | 19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 20 | 20 | ||
| 21 | buildConfigField("String", "APIKey1", "\"eCa3YzEjTBBiNjlXcNnjnldP\"") | 21 | buildConfigField("String", "APIKey", "\"oj9XT8AOeTeLkdqaEX7RJA0N\"") |
| 22 | buildConfigField("String", "SecretKey1", "\"KnZPmjF0ZzmxWV964mzmm6yuDljnETLt\"") | 22 | buildConfigField("String", "SecretKey", "\"AfUFmACkfbd0RMuk11qbw1TW5LtxtJHK\"") |
| 23 | buildConfigField("String", "APIKey1", "\"oj9XT8AOeTeLkdqaEX7RJA0N\"") | ||
| 24 | buildConfigField("String", "SecretKey1", "\"AfUFmACkfbd0RMuk11qbw1TW5LtxtJHK\"") | ||
| 23 | } | 25 | } |
| 24 | 26 | ||
| 25 | buildTypes { | 27 | buildTypes { |
| 26 | debug { | 28 | debug { |
| 27 | minifyEnabled false | 29 | minifyEnabled false |
| 28 | buildConfigField("String", "SERVER_URL", "\"${url.server_url}\"") | 30 | buildConfigField("String", "SERVER_URL", "\"${url.server_url}\"") |
| 29 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") | ||
| 30 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") | ||
| 31 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 31 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 32 | } | 32 | } |
| 33 | release { | 33 | release { |
| 34 | minifyEnabled false | 34 | minifyEnabled false |
| 35 | buildConfigField("String", "SERVER_URL", "\"${url.server_url_online}\"") | 35 | buildConfigField("String", "SERVER_URL", "\"${url.server_url_online}\"") |
| 36 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") | ||
| 37 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") | ||
| 38 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 36 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 39 | } | 37 | } |
| 40 | } | 38 | } |
| 41 | 39 | ||
| 42 | compileOptions { | 40 | compileOptions { |
| 43 | sourceCompatibility JavaVersion.VERSION_1_8 | 41 | sourceCompatibility JavaVersion.VERSION_1_8 |
| 44 | targetCompatibility JavaVersion.VERSION_1_8 | 42 | targetCompatibility JavaVersion.VERSION_1_8 |
| 45 | } | 43 | } |
| 46 | } | 44 | } |
| 47 | 45 | ||
| 48 | dependencies { | 46 | dependencies { |
| 49 | implementation fileTree(include: ['*.jar'], dir: 'libs') | 47 | implementation fileTree(include: ['*.jar'], dir: 'libs') |
| 50 | 48 | ||
| 51 | 49 | ||
| 52 | support.each { k, v -> implementation v } | 50 | support.each { k, v -> implementation v } |
| 53 | 51 | ||
| 54 | // 抓包, OkHttp拦截 | 52 | // 抓包, OkHttp拦截 |
| 55 | def chuckerVersion = "3.5.2" | 53 | def chuckerVersion = "3.5.2" |
| 56 | debugImplementation("com.github.chuckerteam.chucker:library:$chuckerVersion") { | 54 | debugImplementation("com.github.chuckerteam.chucker:library:$chuckerVersion") { |
| 57 | exclude module: 'lifecycle-viewmodel-ktx' | 55 | exclude module: 'lifecycle-viewmodel-ktx' |
| 58 | } | 56 | } |
| 59 | releaseImplementation("com.github.chuckerteam.chucker:library-no-op:$chuckerVersion") { | 57 | releaseImplementation("com.github.chuckerteam.chucker:library-no-op:$chuckerVersion") { |
| 60 | exclude module: 'lifecycle-viewmodel-ktx' | 58 | exclude module: 'lifecycle-viewmodel-ktx' |
| 61 | } | 59 | } |
| 62 | 60 | ||
| 63 | implementation 'com.jakewharton:butterknife:10.2.3' | 61 | implementation 'com.jakewharton:butterknife:10.2.3' |
libs/common/src/main/java/com/prws/common/net/NetWorks.java
| 1 | package com.prws.common.net; | 1 | package com.prws.common.net; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import com.google.gson.Gson; | 4 | import com.google.gson.Gson; |
| 5 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
| 6 | import com.prws.common.BuildConfig; | 6 | import com.prws.common.BuildConfig; |
| 7 | import com.prws.common.bean.CutPicBean; | 7 | import com.prws.common.bean.CutPicBean; |
| 8 | import com.prws.common.bean.GradeAndSubject; | 8 | import com.prws.common.bean.GradeAndSubject; |
| 9 | import com.prws.common.bean.PageInfo; | 9 | import com.prws.common.bean.PageInfo; |
| 10 | import com.prws.common.bean.ResponseResult; | 10 | import com.prws.common.bean.ResponseResult; |
| 11 | import com.prws.common.bean.ScheduleBean; | 11 | import com.prws.common.bean.ScheduleBean; |
| 12 | import com.prws.common.bean.Student; | 12 | import com.prws.common.bean.Student; |
| 13 | import com.prws.common.bean.Teacher; | 13 | import com.prws.common.bean.Teacher; |
| 14 | import com.prws.common.bean.TopicBean; | 14 | import com.prws.common.bean.TopicBean; |
| 15 | import com.prws.common.bean.UpdateBean; | 15 | import com.prws.common.bean.UpdateBean; |
| 16 | import com.prws.common.bean.User; | 16 | import com.prws.common.bean.User; |
| 17 | import com.prws.common.bean.baidu.BaiduInput; | 17 | import com.prws.common.bean.baidu.BaiduInput; |
| 18 | import com.prws.common.bean.homework.HomeWork; | 18 | import com.prws.common.bean.homework.HomeWork; |
| 19 | import com.prws.common.bean.homework.HomeworkDetail; | 19 | import com.prws.common.bean.homework.HomeworkDetail; |
| 20 | import com.prws.common.bean.homework.HomeworkList; | 20 | import com.prws.common.bean.homework.HomeworkList; |
| 21 | import com.prws.common.bean.homework.StDetail; | 21 | import com.prws.common.bean.homework.StDetail; |
| 22 | import com.prws.common.utils.BitmapUtils; | 22 | import com.prws.common.utils.BitmapUtils; |
| 23 | import com.prws.common.utils.SharedPreferencesUtil; | 23 | import com.prws.common.utils.SharedPreferencesUtil; |
| 24 | 24 | ||
| 25 | import java.io.File; | 25 | import java.io.File; |
| 26 | import java.util.HashMap; | 26 | import java.util.HashMap; |
| 27 | import java.util.LinkedHashMap; | ||
| 27 | import java.util.List; | 28 | import java.util.List; |
| 28 | import java.util.Map; | 29 | import java.util.Map; |
| 29 | 30 | ||
| 30 | import io.reactivex.Observable; | 31 | import io.reactivex.Observable; |
| 31 | import io.reactivex.Observer; | 32 | import io.reactivex.Observer; |
| 32 | import io.reactivex.Single; | 33 | import io.reactivex.Single; |
| 33 | import io.reactivex.android.schedulers.AndroidSchedulers; | 34 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 34 | import io.reactivex.schedulers.Schedulers; | 35 | import io.reactivex.schedulers.Schedulers; |
| 35 | import okhttp3.MediaType; | 36 | import okhttp3.MediaType; |
| 36 | import okhttp3.MultipartBody; | 37 | import okhttp3.MultipartBody; |
| 37 | import okhttp3.RequestBody; | 38 | import okhttp3.RequestBody; |
| 38 | import okhttp3.ResponseBody; | 39 | import okhttp3.ResponseBody; |
| 39 | import retrofit2.Call; | 40 | import retrofit2.Call; |
| 40 | import retrofit2.Callback; | 41 | import retrofit2.Callback; |
| 41 | import retrofit2.Retrofit; | 42 | import retrofit2.Retrofit; |
| 42 | import retrofit2.http.Body; | 43 | import retrofit2.http.Body; |
| 43 | import retrofit2.http.GET; | 44 | import retrofit2.http.GET; |
| 44 | import retrofit2.http.Header; | 45 | import retrofit2.http.Header; |
| 45 | import retrofit2.http.Headers; | 46 | import retrofit2.http.Headers; |
| 46 | import retrofit2.http.Multipart; | 47 | import retrofit2.http.Multipart; |
| 47 | import retrofit2.http.POST; | 48 | import retrofit2.http.POST; |
| 48 | import retrofit2.http.PUT; | 49 | import retrofit2.http.PUT; |
| 49 | import retrofit2.http.Part; | 50 | import retrofit2.http.Part; |
| 50 | import retrofit2.http.PartMap; | 51 | import retrofit2.http.PartMap; |
| 51 | import retrofit2.http.Query; | 52 | import retrofit2.http.Query; |
| 52 | import retrofit2.http.Url; | 53 | import retrofit2.http.Url; |
| 53 | 54 | ||
| 54 | /** | 55 | /** |
| 55 | * 类名称:NetWorks | 56 | * 类名称:NetWorks |
| 56 | * 创建人: | 57 | * 创建人: |
| 57 | * <p> | 58 | * <p> |
| 58 | * 类描述:网络请求的操作类 | 59 | * 类描述:网络请求的操作类 |
| 59 | */ | 60 | */ |
| 60 | public class NetWorks extends RetrofitUtils { | 61 | public class NetWorks extends RetrofitUtils { |
| 61 | //服务器路径 | 62 | //服务器路径 |
| 62 | public static final Retrofit retrofit = getMachineRetrofit(BuildConfig.SERVER_URL); | 63 | public static final Retrofit retrofit = getMachineRetrofit(BuildConfig.SERVER_URL); |
| 63 | public static final NetService service_url = retrofit.create(NetService.class); | 64 | public static final NetService service_url = retrofit.create(NetService.class); |
| 64 | 65 | ||
| 65 | //设缓存有效期为1天 | 66 | //设缓存有效期为1天 |
| 66 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; | 67 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; |
| 67 | //查询缓存的Cache-Control设置,使用缓存 | 68 | //查询缓存的Cache-Control设置,使用缓存 |
| 68 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; | 69 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; |
| 69 | //查询网络的Cache-Control设置。不使用缓存 | 70 | //查询网络的Cache-Control设置。不使用缓存 |
| 70 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; | 71 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; |
| 71 | 72 | ||
| 72 | 73 | ||
| 73 | public interface NetService { | 74 | public interface NetService { |
| 74 | 75 | ||
| 75 | 76 | ||
| 76 | @GET("/api/v1/user/logout") | 77 | @GET("/api/v1/user/logout") |
| 77 | Observable<ResponseBody> logout(); | 78 | Observable<ResponseBody> logout(); |
| 78 | 79 | ||
| 79 | @Multipart | 80 | @Multipart |
| 80 | @POST("/api/v1/user/upLoadAvatar") | 81 | @POST("/api/v1/user/upLoadAvatar") |
| 81 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); | 82 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); |
| 82 | 83 | ||
| 83 | 84 | ||
| 84 | @Headers("Content-Type: application/json") | 85 | @Headers("Content-Type: application/json") |
| 85 | @POST("/api/v1/user/editUser") | 86 | @POST("/api/v1/user/editUser") |
| 86 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); | 87 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); |
| 87 | 88 | ||
| 88 | @Headers("Content-Type: application/json") | 89 | @Headers("Content-Type: application/json") |
| 89 | @POST("/api/v1/user/changePassword") | 90 | @POST("/api/v1/user/changePassword") |
| 90 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); | 91 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); |
| 91 | 92 | ||
| 92 | 93 | ||
| 93 | @GET("/api/v1/user/searchById") | 94 | @GET("/api/v1/user/searchById") |
| 94 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); | 95 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); |
| 95 | 96 | ||
| 96 | 97 | ||
| 97 | @Headers("Content-Type: application/json") | 98 | @Headers("Content-Type: application/json") |
| 98 | @POST("/api/v1/login/userLogin") | 99 | @POST("/api/v1/login/userLogin") |
| 99 | Observable<ResponseBody> login(@Body RequestBody body); | 100 | Observable<ResponseBody> login(@Body RequestBody body); |
| 100 | 101 | ||
| 101 | @GET("/api/v1/resource/listGradeAndSubject") | 102 | @GET("/api/v1/resource/listGradeAndSubject") |
| 102 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); | 103 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); |
| 103 | 104 | ||
| 104 | 105 | ||
| 105 | @GET("/api/v1/manager/generalQrCode") | 106 | @GET("/api/v1/manager/generalQrCode") |
| 106 | Observable<ResponseBody> generalQrCode(); | 107 | Observable<ResponseBody> generalQrCode(); |
| 107 | 108 | ||
| 108 | @GET("/api/v1/parent/scanAndLogin") | 109 | @GET("/api/v1/parent/scanAndLogin") |
| 109 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); | 110 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); |
| 110 | 111 | ||
| 111 | @GET("/api/v1/parent/getChildrenList") | 112 | @GET("/api/v1/parent/getChildrenList") |
| 112 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); | 113 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); |
| 113 | 114 | ||
| 114 | 115 | ||
| 115 | @Headers("Content-Type: application/json") | 116 | @Headers("Content-Type: application/json") |
| 116 | @POST("/api/v1/parent/registerParent") | 117 | @POST("/api/v1/parent/registerParent") |
| 117 | Observable<ResponseBody> registerParent(@Body RequestBody body); | 118 | Observable<ResponseBody> registerParent(@Body RequestBody body); |
| 118 | 119 | ||
| 119 | 120 | ||
| 120 | @GET("/api/v1/parent/listChildren") | 121 | @GET("/api/v1/parent/listChildren") |
| 121 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); | 122 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); |
| 122 | 123 | ||
| 123 | 124 | ||
| 124 | @Headers("Content-Type: application/json") | 125 | @Headers("Content-Type: application/json") |
| 125 | @POST("/api/v1/parent/registerStudent") | 126 | @POST("/api/v1/parent/registerStudent") |
| 126 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); | 127 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); |
| 127 | 128 | ||
| 128 | @Headers("Content-Type: application/json") | 129 | @Headers("Content-Type: application/json") |
| 129 | @POST("/api/v1/parent/bindTeacher") | 130 | @POST("/api/v1/parent/bindTeacher") |
| 130 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); | 131 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); |
| 131 | 132 | ||
| 132 | @Multipart | 133 | @Multipart |
| 133 | @POST("/api/v1/user/upLoadAvatar") | 134 | @POST("/api/v1/user/upLoadAvatar") |
| 134 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); | 135 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); |
| 135 | 136 | ||
| 136 | 137 | ||
| 137 | @Multipart | 138 | @Multipart |
| 138 | @POST("/api/v1/student/editStudentAvatar") | 139 | @POST("/api/v1/student/editStudentAvatar") |
| 139 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 140 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
| 140 | 141 | ||
| 141 | @Headers("Content-Type: application/json") | 142 | @Headers("Content-Type: application/json") |
| 142 | @POST("/api/v1/parent/editChild") | 143 | @POST("/api/v1/parent/editChild") |
| 143 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); | 144 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); |
| 144 | 145 | ||
| 145 | @GET("/api/v1/student/getStudyPlanForThisWeek") | 146 | @GET("/api/v1/student/getStudyPlanForThisWeek") |
| 146 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); | 147 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); |
| 147 | 148 | ||
| 148 | @GET("api/v1/parent/searchTeacher") | 149 | @GET("api/v1/parent/searchTeacher") |
| 149 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); | 150 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); |
| 150 | 151 | ||
| 151 | @POST("api/v1/question/listErrorBook") | 152 | @POST("api/v1/question/listErrorBook") |
| 152 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); | 153 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); |
| 153 | 154 | ||
| 154 | @POST | 155 | @POST |
| 155 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); | 156 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); |
| 156 | 157 | ||
| 158 | @POST("https://aip.baidubce.com/rest/2.0/ocr/v1/doc_crop_enhance") | ||
| 159 | Observable<JsonObject> baiduEnhance( | ||
| 160 | @Query("access_token") String token, | ||
| 161 | @Body Object any | ||
| 162 | ); | ||
| 163 | |||
| 157 | @POST | 164 | @POST |
| 158 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); | 165 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); |
| 159 | 166 | ||
| 160 | @POST | 167 | @POST |
| 161 | Observable<JsonObject> getBaiduToken(@Url String url); | 168 | Observable<JsonObject> getBaiduToken(@Url String url); |
| 162 | 169 | ||
| 163 | @Multipart | 170 | @Multipart |
| 164 | @POST("api/v1/pad/addErrorBook") | 171 | @POST("api/v1/pad/addErrorBook") |
| 165 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 172 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
| 166 | 173 | ||
| 167 | @POST("api/v1/pad/deleteStuErrorBook") | 174 | @POST("api/v1/pad/deleteStuErrorBook") |
| 168 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); | 175 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); |
| 169 | 176 | ||
| 170 | @PUT("api/v1/pad/updateStuErrorBookInfo") | 177 | @PUT("api/v1/pad/updateStuErrorBookInfo") |
| 171 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); | 178 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); |
| 172 | 179 | ||
| 173 | @POST("api/v1/question/editErrorBook") | 180 | @POST("api/v1/question/editErrorBook") |
| 174 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); | 181 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); |
| 175 | 182 | ||
| 176 | @GET("api/v1/resource/checkUpdate") | 183 | @GET("api/v1/resource/checkUpdate") |
| 177 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); | 184 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); |
| 178 | 185 | ||
| 179 | @GET("api/v1/teacher/getStudentList") | 186 | @GET("api/v1/teacher/getStudentList") |
| 180 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); | 187 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); |
| 181 | 188 | ||
| 182 | @GET("api/v1/teacher/getStudentList") | 189 | @GET("api/v1/teacher/getStudentList") |
| 183 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); | 190 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); |
| 184 | 191 | ||
| 185 | @GET("api/v1/answer/listRecordForTeacher") | 192 | @GET("api/v1/answer/listRecordForTeacher") |
| 186 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); | 193 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); |
| 187 | 194 | ||
| 188 | @GET("api/v1/homework/listHomeworkByStuId") | 195 | @GET("api/v1/homework/listHomeworkByStuId") |
| 189 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); | 196 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); |
| 190 | 197 | ||
| 191 | @POST | 198 | @POST |
| 192 | Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); | 199 | Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); |
| 193 | 200 | ||
| 194 | @Multipart | 201 | @Multipart |
| 195 | @POST("api/v1/homework/uploadHomework") | 202 | @POST("api/v1/homework/uploadHomework") |
| 196 | Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); | 203 | Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); |
| 197 | 204 | ||
| 198 | @POST("api/v1/homework/uploadHomeworkAction") | 205 | @POST("api/v1/homework/uploadHomeworkAction") |
| 199 | Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); | 206 | Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); |
| 200 | 207 | ||
| 201 | @GET("api/v1/homework/removeHomework") | 208 | @GET("api/v1/homework/removeHomework") |
| 202 | Single<ResponseResult<Boolean>> deleteHomework( | 209 | Single<ResponseResult<Boolean>> deleteHomework( |
| 203 | @Header("Authorization") String token, | 210 | @Header("Authorization") String token, |
| 204 | @Query("homeworkId") String homeworkId | 211 | @Query("homeworkId") String homeworkId |
| 205 | ); | 212 | ); |
| 206 | 213 | ||
| 207 | @GET("api/v1/homework/listHomeworkById") | 214 | @GET("api/v1/homework/listHomeworkById") |
| 208 | Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId); | 215 | Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId); |
| 209 | 216 | ||
| 210 | @POST("api/v1/homework/uploadHomeworkFeedback") | 217 | @POST("api/v1/homework/uploadHomeworkFeedback") |
| 211 | Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); | 218 | Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); |
| 212 | 219 | ||
| 213 | @POST("api/v1/homework/editHomeworkInfo") | 220 | @POST("api/v1/homework/editHomeworkInfo") |
| 214 | Single<ResponseResult<Boolean>> editHomework( | 221 | Single<ResponseResult<Boolean>> editHomework( |
| 215 | @Header("Authorization") String token, | 222 | @Header("Authorization") String token, |
| 216 | @Body Object body | 223 | @Body Object body |
| 217 | ); | 224 | ); |
| 218 | 225 | ||
| 219 | @GET("api/v1/homework/listHomeworkDetailByStuId") | 226 | @GET("api/v1/homework/listHomeworkDetailByStuId") |
| 220 | Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail( | 227 | Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail( |
| 221 | @Header("Authorization") String token, | 228 | @Header("Authorization") String token, |
| 222 | @Query("stuId") String stuId, | 229 | @Query("stuId") String stuId, |
| 223 | @Query("homeworkId") String homeworkId, | 230 | @Query("homeworkId") String homeworkId, |
| 224 | // type 固定传true | 231 | // type 固定传true |
| 225 | @Query("type") boolean type | 232 | @Query("type") boolean type |
| 226 | ); | 233 | ); |
| 227 | 234 | ||
| 228 | @GET("api/v1/homework/listHomeworkStatistics") | 235 | @GET("api/v1/homework/listHomeworkStatistics") |
| 229 | Single<ResponseResult<List<StDetail>>> getHuyouList( | 236 | Single<ResponseResult<List<StDetail>>> getHuyouList( |
| 230 | @Header("Authorization") String token, | 237 | @Header("Authorization") String token, |
| 231 | @Query("stuId") String stuId, | 238 | @Query("stuId") String stuId, |
| 232 | @Query("type") int type //0: 周报, 1:阶段总结 | 239 | @Query("type") int type //0: 周报, 1:阶段总结 |
| 233 | ); | 240 | ); |
| 234 | 241 | ||
| 235 | @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent") | 242 | @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent") |
| 236 | Single<ResponseResult<StDetail>> getHuyouDetail( | 243 | Single<ResponseResult<StDetail>> getHuyouDetail( |
| 237 | @Header("Authorization") String token, | 244 | @Header("Authorization") String token, |
| 238 | @Query("homeworkStatisticsId") String homeworkId | 245 | @Query("homeworkStatisticsId") String homeworkId |
| 239 | ); | 246 | ); |
| 240 | 247 | ||
| 241 | @GET("api/v1/demo/generalStatisticsHomework") | 248 | @GET("api/v1/demo/generalStatisticsHomework") |
| 242 | Single<ResponseResult<Object>> generalHuyou(); | 249 | Single<ResponseResult<Object>> generalHuyou(); |
| 243 | 250 | ||
| 244 | @POST("api/v1/homework/generalHomeworkStageStatistics") | 251 | @POST("api/v1/homework/generalHomeworkStageStatistics") |
| 245 | Single<ResponseResult<Boolean>> generalStageHuyou( | 252 | Single<ResponseResult<Boolean>> generalStageHuyou( |
| 246 | @Header("Authorization") String token, | 253 | @Header("Authorization") String token, |
| 247 | @Body Object body | 254 | @Body Object body |
| 248 | ); | 255 | ); |
| 249 | 256 | ||
| 250 | @GET("api/v1/homework/removeHomeworkStatistics") | 257 | @GET("api/v1/homework/removeHomeworkStatistics") |
| 251 | Single<ResponseResult<Boolean>> deleteHuyou( | 258 | Single<ResponseResult<Boolean>> deleteHuyou( |
| 252 | @Header("Authorization") String token, | 259 | @Header("Authorization") String token, |
| 253 | @Query("homeworkStatisticsId") String homeworkId | 260 | @Query("homeworkStatisticsId") String homeworkId |
| 254 | ); | 261 | ); |
| 255 | 262 | ||
| 256 | @GET("api/v1/login/smsCode") | 263 | @GET("api/v1/login/smsCode") |
| 257 | Single<ResponseResult<String>> smsCode(@Query("mobile") String mobile); | 264 | Single<ResponseResult<String>> smsCode(@Query("mobile") String mobile); |
| 258 | 265 | ||
| 259 | @POST("api/v1/login/smsLogin") | 266 | @POST("api/v1/login/smsLogin") |
| 260 | Single<ResponseResult<User>> smsLogin(@Body Object body); | 267 | Single<ResponseResult<User>> smsLogin(@Body Object body); |
| 261 | 268 | ||
| 262 | } | 269 | } |
| 263 | 270 | ||
| 264 | public static String getUserId() { | 271 | public static String getUserId() { |
| 265 | return (String) SharedPreferencesUtil.getData("userId", ""); | 272 | return (String) SharedPreferencesUtil.getData("userId", ""); |
| 266 | } | 273 | } |
| 267 | 274 | ||
| 268 | public static String getHeader() { | 275 | public static String getHeader() { |
| 269 | return (String) SharedPreferencesUtil.getData("token", ""); | 276 | return (String) SharedPreferencesUtil.getData("token", ""); |
| 270 | } | 277 | } |
| 271 | 278 | ||
| 272 | public static String getBaiduToken() { | 279 | public static String getBaiduToken() { |
| 273 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); | 280 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); |
| 274 | } | 281 | } |
| 275 | 282 | ||
| 276 | public static Single<BaiduInput> inputImage(String filePath, String id) { | 283 | public static Single<BaiduInput> inputImage(String filePath, String id) { |
| 277 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 284 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 278 | String base64 = BitmapUtils.fileToBase64(filePath); | 285 | String base64 = BitmapUtils.fileToBase64(filePath); |
| 279 | File file = new File(filePath); | 286 | File file = new File(filePath); |
| 280 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); | 287 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); |
| 281 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) | 288 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) |
| 282 | .flatMap(token -> { | 289 | .flatMap(token -> { |
| 283 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); | 290 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); |
| 284 | }); | 291 | }); |
| 285 | } | 292 | } |
| 286 | 293 | ||
| 287 | public static Single<ResponseResult> uploadImage(String path, String id) { | 294 | public static Single<ResponseResult> uploadImage(String path, String id) { |
| 288 | File file = new File(path); | 295 | File file = new File(path); |
| 289 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 296 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
| 290 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 297 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 291 | return service_url.uploadImage(getHeader(), part, id); | 298 | return service_url.uploadImage(getHeader(), part, id); |
| 292 | } | 299 | } |
| 293 | 300 | ||
| 294 | 301 | ||
| 295 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { | 302 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { |
| 296 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); | 303 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); |
| 297 | } | 304 | } |
| 298 | 305 | ||
| 299 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { | 306 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { |
| 300 | File file = new File(path); | 307 | File file = new File(path); |
| 301 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 308 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
| 302 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 309 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 303 | Map<String, Object> map = new HashMap<>(); | 310 | Map<String, Object> map = new HashMap<>(); |
| 304 | map.put("condition", param); | 311 | map.put("condition", param); |
| 305 | setSubscribe(service_url.addError(part, map), observer); | 312 | setSubscribe(service_url.addError(part, map), observer); |
| 306 | } | 313 | } |
| 307 | 314 | ||
| 308 | 315 | ||
| 309 | public static void cut(String base64, Observer<CutPicBean> observer) { | 316 | public static void cut(String base64, Observer<CutPicBean> observer) { |
| 310 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 317 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 311 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); | 318 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); |
| 312 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); | 319 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); |
| 313 | } | 320 | } |
| 314 | 321 | ||
| 315 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { | 322 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { |
| 316 | setSubscribe(service_url.editError(getHeader(), map), observer); | 323 | setSubscribe(service_url.editError(getHeader(), map), observer); |
| 317 | } | 324 | } |
| 318 | 325 | ||
| 319 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { | 326 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { |
| 320 | setSubscribe(service_url.updateError(getHeader(), map), observer); | 327 | setSubscribe(service_url.updateError(getHeader(), map), observer); |
| 321 | } | 328 | } |
| 322 | 329 | ||
| 323 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { | 330 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { |
| 324 | setSubscribe(service_url.deleteError(getHeader(), map), observer); | 331 | setSubscribe(service_url.deleteError(getHeader(), map), observer); |
| 325 | } | 332 | } |
| 326 | 333 | ||
| 327 | public static void getBaiduToken(Observer<JsonObject> observer) { | 334 | public static void getBaiduToken(Observer<JsonObject> observer) { |
| 328 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); | 335 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); |
| 329 | } | 336 | } |
| 330 | 337 | ||
| 331 | public static Single<JsonObject> getBaiduTokenOcr() { | 338 | public static Single<JsonObject> getBaiduTokenOcr() { |
| 332 | return service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey1 + "&client_secret=" + BuildConfig.SecretKey1).firstOrError(); | 339 | return service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey1 + "&client_secret=" + BuildConfig.SecretKey1).firstOrError(); |
| 333 | } | 340 | } |
| 334 | 341 | ||
| 335 | public static void removeWriting(String base64, Observer<JsonObject> observer) { | 342 | public static void removeWriting(String base64, Observer<JsonObject> observer) { |
| 336 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 343 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 337 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); | 344 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); |
| 338 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); | 345 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); |
| 339 | } | 346 | } |
| 340 | 347 | ||
| 348 | public static void baiduEnhance(String base64, Observer<JsonObject> observer) { | ||
| 349 | Map<String, Object> body = new LinkedHashMap<>(); | ||
| 350 | body.put("image", base64); | ||
| 351 | body.put("scan_type", 3); | ||
| 352 | body.put("enhance_type", 3); | ||
| 353 | setSubscribe(service_url.baiduEnhance(getBaiduToken(), body), observer); | ||
| 354 | } | ||
| 355 | |||
| 341 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { | 356 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { |
| 342 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); | 357 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); |
| 343 | } | 358 | } |
| 344 | 359 | ||
| 345 | public static void logout(Observer<ResponseBody> observer) { | 360 | public static void logout(Observer<ResponseBody> observer) { |
| 346 | setSubscribe(service_url.logout(), observer); | 361 | setSubscribe(service_url.logout(), observer); |
| 347 | } | 362 | } |
| 348 | 363 | ||
| 349 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { | 364 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { |
| 350 | setSubscribe(service_url.editStudent(getHeader(), body), observable); | 365 | setSubscribe(service_url.editStudent(getHeader(), body), observable); |
| 351 | } | 366 | } |
| 352 | 367 | ||
| 353 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { | 368 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { |
| 354 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); | 369 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); |
| 355 | } | 370 | } |
| 356 | 371 | ||
| 357 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { | 372 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { |
| 358 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 373 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 359 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 374 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 360 | Map<String, Object> map = new HashMap<>(); | 375 | Map<String, Object> map = new HashMap<>(); |
| 361 | map.put("stuId", stuId); | 376 | map.put("stuId", stuId); |
| 362 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); | 377 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); |
| 363 | } | 378 | } |
| 364 | 379 | ||
| 365 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { | 380 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { |
| 366 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 381 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 367 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 382 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 368 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); | 383 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); |
| 369 | } | 384 | } |
| 370 | 385 | ||
| 371 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { | 386 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { |
| 372 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); | 387 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); |
| 373 | } | 388 | } |
| 374 | 389 | ||
| 375 | 390 | ||
| 376 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { | 391 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { |
| 377 | setSubscribe(service_url.editUser(getHeader(), body), observer); | 392 | setSubscribe(service_url.editUser(getHeader(), body), observer); |
| 378 | } | 393 | } |
| 379 | 394 | ||
| 380 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { | 395 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { |
| 381 | setSubscribe(service_url.changePassword(getHeader(), body), observer); | 396 | setSubscribe(service_url.changePassword(getHeader(), body), observer); |
| 382 | } | 397 | } |
| 383 | 398 | ||
| 384 | 399 | ||
| 385 | public static void searchById(String userId, Observer<ResponseBody> observer) { | 400 | public static void searchById(String userId, Observer<ResponseBody> observer) { |
| 386 | setSubscribe(service_url.searchById(getHeader(), userId), observer); | 401 | setSubscribe(service_url.searchById(getHeader(), userId), observer); |
| 387 | } | 402 | } |
| 388 | 403 | ||
| 389 | 404 | ||
| 390 | public static void login(RequestBody body, Observer<ResponseBody> observer) { | 405 | public static void login(RequestBody body, Observer<ResponseBody> observer) { |
| 391 | setSubscribe(service_url.login(body), observer); | 406 | setSubscribe(service_url.login(body), observer); |
| 392 | } | 407 | } |
| 393 | 408 | ||
| 394 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { | 409 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { |
| 395 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); | 410 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); |
| 396 | } | 411 | } |
| 397 | 412 | ||
| 398 | 413 | ||
| 399 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { | 414 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { |
| 400 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); | 415 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); |
| 401 | } | 416 | } |
| 402 | 417 | ||
| 403 | public static void getChildrenList(Observer<ResponseBody> observer) { | 418 | public static void getChildrenList(Observer<ResponseBody> observer) { |
| 404 | setSubscribe(service_url.getChildrenList(getHeader()), observer); | 419 | setSubscribe(service_url.getChildrenList(getHeader()), observer); |
| 405 | } | 420 | } |
| 406 | 421 | ||
| 407 | 422 | ||
| 408 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { | 423 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { |
| 409 | setSubscribe(service_url.registerParent(body), observer); | 424 | setSubscribe(service_url.registerParent(body), observer); |
| 410 | } | 425 | } |
| 411 | 426 | ||
| 412 | 427 | ||
| 413 | public static void listChildren(Observer<ResponseBody> observer) { | 428 | public static void listChildren(Observer<ResponseBody> observer) { |
| 414 | setSubscribe(service_url.listChildren(getHeader()), observer); | 429 | setSubscribe(service_url.listChildren(getHeader()), observer); |
| 415 | } | 430 | } |
| 416 | 431 | ||
| 417 | public static void listStudent(Observer<ResponseBody> observer) { | 432 | public static void listStudent(Observer<ResponseBody> observer) { |
| 418 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 433 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 419 | } | 434 | } |
| 420 | 435 | ||
| 421 | public static Single<ResponseResult<List<Student>>> listStudent() { | 436 | public static Single<ResponseResult<List<Student>>> listStudent() { |
| 422 | return service_url.getStudentList2(getHeader(), getUserId()); | 437 | return service_url.getStudentList2(getHeader(), getUserId()); |
| 423 | } | 438 | } |
| 424 | 439 | ||
| 425 | public static void listRecord(Observer<ResponseBody> observer) { | 440 | public static void listRecord(Observer<ResponseBody> observer) { |
| 426 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 441 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 427 | } | 442 | } |
| 428 | 443 | ||
| 429 | 444 | ||
| 430 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { | 445 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { |
| 431 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); | 446 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); |
| 432 | } | 447 | } |
| 433 | 448 | ||
| 434 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { | 449 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { |
| 435 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); | 450 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); |
| 436 | } | 451 | } |
| 437 | 452 | ||
| 438 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { | 453 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { |
| 439 | setSubscribe(service_url.getError(getHeader(), map), observer); | 454 | setSubscribe(service_url.getError(getHeader(), map), observer); |
| 440 | } | 455 | } |
| 441 | 456 | ||
| 442 | 457 | ||
| 443 | public static RequestBody getMapRequestBody(Map map) { | 458 | public static RequestBody getMapRequestBody(Map map) { |
| 444 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); | 459 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); |
| 445 | } | 460 | } |
| 446 | 461 | ||
| 447 | 462 | ||
| 448 | public static RequestBody getArrayRequestBody(List list) { | 463 | public static RequestBody getArrayRequestBody(List list) { |
| 449 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); | 464 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); |
| 450 | } | 465 | } |
| 451 | 466 | ||
| 452 | public static RequestBody getFileRequestBody(File file) { | 467 | public static RequestBody getFileRequestBody(File file) { |
| 453 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); | 468 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); |
| 454 | } | 469 | } |
| 455 | 470 | ||
| 456 | public static RequestBody getFileRequestBody(byte[] bytes) { | 471 | public static RequestBody getFileRequestBody(byte[] bytes) { |
| 457 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); | 472 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); |
| 458 | } | 473 | } |
| 459 | 474 | ||
| 460 | public static RequestBody getObjectRequestBody(Object obj) { | 475 | public static RequestBody getObjectRequestBody(Object obj) { |
| 461 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); | 476 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); |
| 462 | } | 477 | } |
| 463 | 478 | ||
| 464 | public static RequestBody getStringRequestBody(String str) { | 479 | public static RequestBody getStringRequestBody(String str) { |
| 465 | return RequestBody.create(MediaType.parse("text/plain"), str); | 480 | return RequestBody.create(MediaType.parse("text/plain"), str); |
| 466 | } | 481 | } |
| 467 | 482 | ||
| 468 | 483 | ||
| 469 | /** | 484 | /** |
| 470 | * 插入观察者 | 485 | * 插入观察者 |
| 471 | * | 486 | * |
| 472 | * @param observable | 487 | * @param observable |
| 473 | * @param observer | 488 | * @param observer |
| 474 | * @param <T> | 489 | * @param <T> |
| 475 | */ | 490 | */ |
| 476 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { | 491 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { |
| 477 | observable.subscribeOn(Schedulers.io())//子线程访问网络 | 492 | observable.subscribeOn(Schedulers.io())//子线程访问网络 |
| 478 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 | 493 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 |
| 479 | .subscribe(observer); | 494 | .subscribe(observer); |
| 480 | } | 495 | } |
| 481 | 496 | ||
| 482 | } | 497 | } |
| 483 | 498 |
libs/common/src/main/java/com/prws/common/utils/BitmapUtils.java
| 1 | package com.prws.common.utils; | 1 | package com.prws.common.utils; |
| 2 | 2 | ||
| 3 | import android.graphics.Bitmap; | 3 | import android.graphics.Bitmap; |
| 4 | import android.graphics.BitmapFactory; | 4 | import android.graphics.BitmapFactory; |
| 5 | import android.graphics.Canvas; | 5 | import android.graphics.Canvas; |
| 6 | import android.graphics.Matrix; | 6 | import android.graphics.Matrix; |
| 7 | import android.hardware.Camera; | 7 | import android.hardware.Camera; |
| 8 | import android.text.TextUtils; | 8 | import android.text.TextUtils; |
| 9 | import android.util.Base64; | 9 | import android.util.Base64; |
| 10 | import android.view.View; | 10 | import android.view.View; |
| 11 | 11 | ||
| 12 | import java.io.ByteArrayInputStream; | 12 | import java.io.ByteArrayInputStream; |
| 13 | import java.io.ByteArrayOutputStream; | 13 | import java.io.ByteArrayOutputStream; |
| 14 | import java.io.File; | 14 | import java.io.File; |
| 15 | import java.io.FileInputStream; | 15 | import java.io.FileInputStream; |
| 16 | import java.io.FileNotFoundException; | 16 | import java.io.FileNotFoundException; |
| 17 | import java.io.FileOutputStream; | 17 | import java.io.FileOutputStream; |
| 18 | import java.io.IOException; | 18 | import java.io.IOException; |
| 19 | import java.io.InputStream; | 19 | import java.io.InputStream; |
| 20 | import java.net.URLEncoder; | 20 | import java.net.URLEncoder; |
| 21 | 21 | ||
| 22 | public class BitmapUtils { | 22 | public class BitmapUtils { |
| 23 | 23 | ||
| 24 | public static Bitmap compress(Bitmap image) { | 24 | public static Bitmap compress(Bitmap image) { |
| 25 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); | 25 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 26 | image.compress(Bitmap.CompressFormat.JPEG, 100, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 | 26 | image.compress(Bitmap.CompressFormat.JPEG, 100, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 |
| 27 | int options = 100; | 27 | int options = 100; |
| 28 | while (baos.toByteArray().length / 1024 > 2000) { //循环判断如果压缩后图片是否大于100kb,大于继续压缩 | 28 | while (baos.toByteArray().length / 1024 > 2000) { //循环判断如果压缩后图片是否大于100kb,大于继续压缩 |
| 29 | baos.reset();//重置baos即清空baos | 29 | baos.reset();//重置baos即清空baos |
| 30 | image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中 | 30 | image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中 |
| 31 | options -= 10;//每次都减少10 | 31 | options -= 10;//每次都减少10 |
| 32 | } | 32 | } |
| 33 | ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//把压缩后的数据baos存放到ByteArrayInputStream中 | 33 | ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//把压缩后的数据baos存放到ByteArrayInputStream中 |
| 34 | Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//把ByteArrayInputStream数据生成图片 | 34 | Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//把ByteArrayInputStream数据生成图片 |
| 35 | return bitmap; | 35 | return bitmap; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | public static Bitmap getimage(String srcPath) { | 38 | public static Bitmap getimage(String srcPath) { |
| 39 | BitmapFactory.Options newOpts = new BitmapFactory.Options(); | 39 | BitmapFactory.Options newOpts = new BitmapFactory.Options(); |
| 40 | //开始读入图片,此时把options.inJustDecodeBounds 设回true了 | 40 | //开始读入图片,此时把options.inJustDecodeBounds 设回true了 |
| 41 | newOpts.inJustDecodeBounds = true; | 41 | newOpts.inJustDecodeBounds = true; |
| 42 | Bitmap bitmap = BitmapFactory.decodeFile(srcPath, newOpts);//此时返回bm为空 | 42 | Bitmap bitmap = BitmapFactory.decodeFile(srcPath, newOpts);//此时返回bm为空 |
| 43 | 43 | ||
| 44 | newOpts.inJustDecodeBounds = false; | 44 | newOpts.inJustDecodeBounds = false; |
| 45 | int w = newOpts.outWidth; | 45 | int w = newOpts.outWidth; |
| 46 | int h = newOpts.outHeight; | 46 | int h = newOpts.outHeight; |
| 47 | float hh = 2000f;//这里设置高度为800f | 47 | float hh = 2000f;//这里设置高度为800f |
| 48 | float ww = 2000f;//这里设置宽度为480f | 48 | float ww = 2000f;//这里设置宽度为480f |
| 49 | //缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 | 49 | //缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 |
| 50 | int be = 1;//be=1表示不缩放 | 50 | int be = 1;//be=1表示不缩放 |
| 51 | if (w > h && w > ww) {//如果宽度大的话根据宽度固定大小缩放 | 51 | if (w > h && w > ww) {//如果宽度大的话根据宽度固定大小缩放 |
| 52 | be = (int) (newOpts.outWidth / ww); | 52 | be = (int) (newOpts.outWidth / ww); |
| 53 | } else if (w < h && h > hh) {//如果高度高的话根据宽度固定大小缩放 | 53 | } else if (w < h && h > hh) {//如果高度高的话根据宽度固定大小缩放 |
| 54 | be = (int) (newOpts.outHeight / hh); | 54 | be = (int) (newOpts.outHeight / hh); |
| 55 | } | 55 | } |
| 56 | if (be <= 0) | 56 | if (be <= 0) |
| 57 | be = 1; | 57 | be = 1; |
| 58 | newOpts.inSampleSize = be;//设置缩放比例 | 58 | newOpts.inSampleSize = be;//设置缩放比例 |
| 59 | //重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 | 59 | //重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 |
| 60 | bitmap = BitmapFactory.decodeFile(srcPath, newOpts); | 60 | bitmap = BitmapFactory.decodeFile(srcPath, newOpts); |
| 61 | return compress(bitmap);//压缩好比例大小后再进行质量压缩 | 61 | return compress(bitmap);//压缩好比例大小后再进行质量压缩 |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | /** | 65 | /** |
| 66 | * 注释:设置拍照图片正确方向 | 66 | * 注释:设置拍照图片正确方向 |
| 67 | * | 67 | * |
| 68 | * @param id | 68 | * @param id |
| 69 | * @param bitmap | 69 | * @param bitmap |
| 70 | * @return | 70 | * @return |
| 71 | */ | 71 | */ |
| 72 | public static Bitmap setTakePicktrueOrientation(int id, Bitmap bitmap) { | 72 | public static Bitmap setTakePicktrueOrientation(int id, Bitmap bitmap) { |
| 73 | //如果返回的图片宽度小于高度,说明FrameWork层已经做过处理直接返回即可 | 73 | //如果返回的图片宽度小于高度,说明FrameWork层已经做过处理直接返回即可 |
| 74 | try { | 74 | try { |
| 75 | if (bitmap.getWidth() < bitmap.getHeight()) { | 75 | if (bitmap.getWidth() < bitmap.getHeight()) { |
| 76 | return bitmap; | 76 | return bitmap; |
| 77 | } | 77 | } |
| 78 | Camera.CameraInfo info = new Camera.CameraInfo(); | 78 | Camera.CameraInfo info = new Camera.CameraInfo(); |
| 79 | Camera.getCameraInfo(id, info); | 79 | Camera.getCameraInfo(id, info); |
| 80 | bitmap = rotaingImageView(id, info.orientation, bitmap); | 80 | bitmap = rotaingImageView(id, info.orientation, bitmap); |
| 81 | } catch (Exception e) { | 81 | } catch (Exception e) { |
| 82 | 82 | ||
| 83 | } | 83 | } |
| 84 | return bitmap; | 84 | return bitmap; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | /** | 87 | /** |
| 88 | * 把相机拍照返回照片转正 | 88 | * 把相机拍照返回照片转正 |
| 89 | * | 89 | * |
| 90 | * @param angle 旋转角度 | 90 | * @param angle 旋转角度 |
| 91 | * @return bitmap 图片 | 91 | * @return bitmap 图片 |
| 92 | */ | 92 | */ |
| 93 | private static Bitmap rotaingImageView(int id, int angle, Bitmap bitmap) { | 93 | private static Bitmap rotaingImageView(int id, int angle, Bitmap bitmap) { |
| 94 | //矩阵 | 94 | //矩阵 |
| 95 | Matrix matrix = new Matrix(); | 95 | Matrix matrix = new Matrix(); |
| 96 | matrix.postRotate(angle); | 96 | matrix.postRotate(angle); |
| 97 | //加入翻转 把相机拍照返回照片转正 | 97 | //加入翻转 把相机拍照返回照片转正 |
| 98 | if (id == 1) { | 98 | if (id == 1) { |
| 99 | matrix.postScale(-1, 1); | 99 | matrix.postScale(-1, 1); |
| 100 | } | 100 | } |
| 101 | // 创建新的图片 | 101 | // 创建新的图片 |
| 102 | Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, | 102 | Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, |
| 103 | bitmap.getWidth(), bitmap.getHeight(), matrix, true); | 103 | bitmap.getWidth(), bitmap.getHeight(), matrix, true); |
| 104 | return resizedBitmap; | 104 | return resizedBitmap; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | /** | 107 | /** |
| 108 | * 注释:保存图片 | 108 | * 注释:保存图片 |
| 109 | * | 109 | * |
| 110 | * @param bitmap | 110 | * @param bitmap |
| 111 | * @param path | 111 | * @param path |
| 112 | * @return | 112 | * @return |
| 113 | */ | 113 | */ |
| 114 | public static boolean saveBitmap(Bitmap bitmap, String path) { | 114 | public static boolean saveBitmap(Bitmap bitmap, String path) { |
| 115 | 115 | ||
| 116 | try { | 116 | try { |
| 117 | File file = new File(path); | 117 | File file = new File(path); |
| 118 | File parent = file.getParentFile(); | 118 | File parent = file.getParentFile(); |
| 119 | if (!parent.exists()) { | 119 | if (!parent.exists()) { |
| 120 | parent.mkdirs(); | 120 | parent.mkdirs(); |
| 121 | } | 121 | } |
| 122 | FileOutputStream fos = new FileOutputStream(file); | 122 | FileOutputStream fos = new FileOutputStream(file); |
| 123 | boolean b = bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); | 123 | boolean b = bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); |
| 124 | fos.flush(); | 124 | fos.flush(); |
| 125 | fos.close(); | 125 | fos.close(); |
| 126 | return b; | 126 | return b; |
| 127 | } catch (Exception e) { | 127 | } catch (Exception e) { |
| 128 | e.printStackTrace(); | 128 | e.printStackTrace(); |
| 129 | } | 129 | } |
| 130 | return false; | 130 | return false; |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | public static Bitmap routeBitmap(Bitmap bitmap) { | 133 | public static Bitmap routeBitmap(Bitmap bitmap) { |
| 134 | Matrix matrix = new Matrix(); | 134 | Matrix matrix = new Matrix(); |
| 135 | matrix.preRotate(90f); | 135 | matrix.preRotate(90f); |
| 136 | Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); | 136 | Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); |
| 137 | return bitmap1; | 137 | return bitmap1; |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | public static String fileToBase64(String path) { | 140 | public static String fileToBase64(String path) { |
| 141 | File file = new File(path); | 141 | File file = new File(path); |
| 142 | String base64 = null; | 142 | String base64 = null; |
| 143 | InputStream in = null; | 143 | InputStream in = null; |
| 144 | try { | 144 | try { |
| 145 | in = new FileInputStream(file); | 145 | in = new FileInputStream(file); |
| 146 | byte[] bytes = new byte[in.available()]; | 146 | byte[] bytes = new byte[in.available()]; |
| 147 | int length = in.read(bytes); | 147 | int length = in.read(bytes); |
| 148 | base64 = Base64.encodeToString(bytes, 0, length, Base64.DEFAULT); | 148 | base64 = Base64.encodeToString(bytes, 0, length, Base64.DEFAULT); |
| 149 | } catch (FileNotFoundException e) { | 149 | } catch (FileNotFoundException e) { |
| 150 | e.printStackTrace(); | 150 | e.printStackTrace(); |
| 151 | } catch (IOException e) { | 151 | } catch (IOException e) { |
| 152 | e.printStackTrace(); | 152 | e.printStackTrace(); |
| 153 | } finally { | 153 | } finally { |
| 154 | try { | 154 | try { |
| 155 | if (in != null) { | 155 | if (in != null) { |
| 156 | in.close(); | 156 | in.close(); |
| 157 | } | 157 | } |
| 158 | } catch (IOException e) { | 158 | } catch (IOException e) { |
| 159 | e.printStackTrace(); | 159 | e.printStackTrace(); |
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | return toURLEncoded(base64); | 162 | return toURLEncoded(base64); |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | 165 | ||
| 166 | /** | 166 | /** |
| 167 | * 将图片转换成Base64编码的字符串 | 167 | * 将图片转换成Base64编码的字符串 |
| 168 | */ | 168 | */ |
| 169 | public static String imageToBase64(String path) { | 169 | public static String imageToBase64WithUrlEncode(String path) { |
| 170 | return imageToBase64(path, true); | ||
| 171 | } | ||
| 172 | |||
| 173 | public static String imageToBase64(String path, boolean urlEncode) { | ||
| 174 | |||
| 170 | if (TextUtils.isEmpty(path)) { | 175 | if (TextUtils.isEmpty(path)) { |
| 171 | return null; | 176 | return null; |
| 172 | } | 177 | } |
| 173 | InputStream is = null; | 178 | InputStream is = null; |
| 174 | byte[] data = null; | 179 | byte[] data = null; |
| 175 | String result = null; | 180 | String result = null; |
| 176 | try { | 181 | try { |
| 177 | is = new FileInputStream(path); | 182 | is = new FileInputStream(path); |
| 178 | //创建一个字符流大小的数组。 | 183 | //创建一个字符流大小的数组。 |
| 179 | data = new byte[is.available()]; | 184 | data = new byte[is.available()]; |
| 180 | //写入数组 | 185 | //写入数组 |
| 181 | is.read(data); | 186 | is.read(data); |
| 182 | //用默认的编码格式进行编码 | 187 | //用默认的编码格式进行编码 |
| 183 | result = Base64.encodeToString(data, Base64.NO_CLOSE); | 188 | result = Base64.encodeToString(data, Base64.NO_CLOSE); |
| 184 | } catch (Exception e) { | 189 | } catch (Exception e) { |
| 185 | e.printStackTrace(); | 190 | e.printStackTrace(); |
| 186 | } finally { | 191 | } finally { |
| 187 | if (null != is) { | 192 | if (null != is) { |
| 188 | try { | 193 | try { |
| 189 | is.close(); | 194 | is.close(); |
| 190 | } catch (IOException e) { | 195 | } catch (IOException e) { |
| 191 | e.printStackTrace(); | 196 | e.printStackTrace(); |
| 192 | } | 197 | } |
| 193 | } | 198 | } |
| 194 | 199 | ||
| 195 | } | 200 | } |
| 196 | return toURLEncoded(result); | 201 | if (urlEncode) return toURLEncoded(result); |
| 202 | else return result; | ||
| 197 | } | 203 | } |
| 198 | 204 | ||
| 199 | 205 | ||
| 200 | public static String toURLEncoded(String paramString) { | 206 | public static String toURLEncoded(String paramString) { |
| 201 | if (paramString == null || paramString.equals("")) { | 207 | if (paramString == null || paramString.equals("")) { |
| 202 | return ""; | 208 | return ""; |
| 203 | } | 209 | } |
| 204 | try { | 210 | try { |
| 205 | String str = new String(paramString.getBytes(), "UTF-8"); | 211 | String str = new String(paramString.getBytes(), "UTF-8"); |
| 206 | str = URLEncoder.encode(str, "UTF-8"); | 212 | str = URLEncoder.encode(str, "UTF-8"); |
| 207 | return str; | 213 | return str; |
| 208 | } catch (Exception localException) { | 214 | } catch (Exception localException) { |
| 209 | } | 215 | } |
| 210 | return ""; | 216 | return ""; |
| 211 | } | 217 | } |
| 212 | 218 | ||
| 213 | public static Bitmap stringToBitmap(String string) { | 219 | public static Bitmap stringToBitmap(String string) { |
| 214 | Bitmap bitmap = null; | 220 | Bitmap bitmap = null; |
| 215 | try { | 221 | try { |
| 216 | byte[] bitmapArray = Base64.decode(string, Base64.DEFAULT); | 222 | byte[] bitmapArray = Base64.decode(string, Base64.DEFAULT); |
| 217 | bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); | 223 | bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); |
| 218 | } catch (Exception e) { | 224 | } catch (Exception e) { |
| 219 | e.printStackTrace(); | 225 | e.printStackTrace(); |
| 220 | } | 226 | } |
| 221 | return bitmap; | 227 | return bitmap; |
| 222 | } | 228 | } |
| 223 | 229 | ||
| 224 | /** | 230 | /** |
| 225 | * 将图片转成byte数组 | 231 | * 将图片转成byte数组 |
| 226 | * | 232 | * |
| 227 | * @param bitmap 图片 | 233 | * @param bitmap 图片 |
| 228 | * @return 图片的字节数组 | 234 | * @return 图片的字节数组 |
| 229 | */ | 235 | */ |
| 230 | public static String bitmap2Byte(Bitmap bitmap) { | 236 | public static String bitmap2Byte(Bitmap bitmap) { |
| 231 | if (null == bitmap) throw new NullPointerException(); | 237 | if (null == bitmap) throw new NullPointerException(); |
| 232 | // if (null == bitmap) return null; | 238 | // if (null == bitmap) return null; |
| 233 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | 239 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| 234 | //把bitmap100%高质量压缩 到 output对象里 | 240 | //把bitmap100%高质量压缩 到 output对象里 |
| 235 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); | 241 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); |
| 236 | return byte2Base64(outputStream.toByteArray()); | 242 | return byte2Base64(outputStream.toByteArray()); |
| 237 | } | 243 | } |
| 238 | 244 | ||
| 239 | /** | 245 | /** |
| 240 | * 将图片转成byte数组 | 246 | * 将图片转成byte数组 |
| 241 | * | 247 | * |
| 242 | * @param imageByte 图片 | 248 | * @param imageByte 图片 |
| 243 | * @return Base64 String | 249 | * @return Base64 String |
| 244 | */ | 250 | */ |
| 245 | public static String byte2Base64(byte[] imageByte) { | 251 | public static String byte2Base64(byte[] imageByte) { |
| 246 | if (null == imageByte) return null; | 252 | if (null == imageByte) return null; |
| 247 | return Base64.encodeToString(imageByte, Base64.DEFAULT); | 253 | return Base64.encodeToString(imageByte, Base64.DEFAULT); |
| 248 | } | 254 | } |
| 249 | 255 | ||
| 250 | public static Bitmap shotView(View v) { | 256 | public static Bitmap shotView(View v) { |
| 251 | Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.RGB_565); | 257 | Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.RGB_565); |
| 252 | Canvas canvas = new Canvas(bitmap); | 258 | Canvas canvas = new Canvas(bitmap); |
| 253 | v.draw(canvas); | 259 | v.draw(canvas); |
| 254 | return bitmap; | 260 | return bitmap; |
| 255 | } | 261 | } |
| 256 | 262 | ||
| 257 | 263 | ||
| 258 | } | 264 | } |
| 259 | 265 |