詹子聪 hace 5 años
padre
commit
13acb4dcf0

+ 12 - 14
app/src/main/java/com/miekir/ocr/ui/OperationActivity.java

@@ -248,14 +248,6 @@ public class OperationActivity extends CameraActivity implements CropView.onLoca
             dialog.cancel();
         });
 
-        if (result == null) {
-            return;
-        }
-
-        TextView tv_postal = dialog.findViewById(R.id.tv_postal);
-        TextView tv_address = dialog.findViewById(R.id.tv_address);
-        TextView tv_name = dialog.findViewById(R.id.tv_name);
-
         LinearLayout ll_postal = dialog.findViewById(R.id.ll_postal);
         LinearLayout ll_address = dialog.findViewById(R.id.ll_address);
         LinearLayout ll_name = dialog.findViewById(R.id.ll_name);
@@ -278,22 +270,28 @@ public class OperationActivity extends CameraActivity implements CropView.onLoca
             ll_address.setVisibility(View.GONE);
         }
 
+        TextView tv_postal = dialog.findViewById(R.id.tv_postal);
+        TextView tv_address = dialog.findViewById(R.id.tv_address);
+        TextView tv_name = dialog.findViewById(R.id.tv_name);
+        tv_postal.setText("");
+        tv_address.setText("");
+        tv_name.setText("");
+
+
+        if (result == null) {
+            return;
+        }
+
         if (result.postcode != null) {
             tv_postal.setText(result.postcode.getText());
-        } else {
-            tv_postal.setText("");
         }
 
         if (result.address != null) {
             tv_address.setText(result.address.getText());
-        } else {
-            tv_address.setText("");
         }
 
         if (result.name != null) {
             tv_name.setText(result.name.getText());
-        } else {
-            tv_name.setText("");
         }
     }
 

+ 6 - 4
app/src/main/java/com/miekir/ocr/ui/OperationPresenter.java

@@ -182,7 +182,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
 //                    }
 //                });
 //    }
-    public void startOcrFromFile(Context context, byte[] rawPhotoBytes, int[] rectData, File file, String scene, boolean isLandscape) {
+    public void startOcrFromFile(Context context, byte[] rawPhotoBytes, int[] rectData, File file, String scene, boolean isScreenLandscape) {
         getView().showLoading(context.getResources().getString(R.string.loading));
         int mLeft = rectData[0];
         int mTop = rectData[1];
@@ -204,6 +204,8 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                 int realWidth;
                 int realHeight;
 
+                boolean isLandscape = mBottom-mTop > mRight-mLeft;
+
                 // 图片宽度与屏幕宽度的比
                 float widthD = 1.0f * normalWidth / SizeTool.SCREEN_WIDTH;
                 // 图片高度与屏幕高度的比
@@ -256,13 +258,13 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                     rotatedBitmap = croppedBmp;
                 }
 
-                if (!file.getParentFile().exists()) {
+                if (file.getParentFile() == null || !file.getParentFile().exists()) {
                     file.mkdirs();
                 }
                 int max = rotatedBitmap.getWidth() > rotatedBitmap.getHeight() ? rotatedBitmap.getWidth() : rotatedBitmap.getHeight();
                 int multi = 1;
                 if (max > 1000) {
-                    multi = max / 1000;
+                    multi = max / 1000 + 1;
                 }
 
                 // 压缩图片
@@ -273,7 +275,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                 rotatedBitmap.recycle();
                 if (saveCropSuccess) {
                     File compressedFile = new Compressor(context.getApplicationContext())
-                            .setQuality(92)
+                            .setQuality(90)
                             .setDestinationDirectoryPath(file.getParentFile().getAbsolutePath())
                             .compressToFile(file, "cp_" + file.getName());
 

+ 138 - 125
app/src/main/res/layout/dialog_result.xml

@@ -1,148 +1,161 @@
 <?xml version="1.0" encoding="utf-8"?>
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content">
-    <LinearLayout
+    android:layout_height="wrap_content"
+    android:background="@drawable/shape_result_bg"
+    android:orientation="vertical">
+
+    <TextView
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical"
-        android:background="@drawable/shape_result_bg">
+        android:layout_height="56dp"
+        android:gravity="center_vertical"
+        android:paddingStart="@dimen/margin_default"
+        android:paddingEnd="@dimen/margin_default"
+        android:text="@string/result"
+        android:textColor="@color/black_press"
+        android:textSize="@dimen/size_text_title_p" />
 
-        <TextView
-            android:layout_width="match_parent"
-            android:layout_height="56dp"
-            android:gravity="center_vertical"
-            android:textColor="@color/black_press"
-            android:text="@string/result"
-            android:textSize="@dimen/size_text_title_p"
-            android:paddingStart="@dimen/margin_default"
-            android:paddingEnd="@dimen/margin_default"/>
-
-        <View
-            android:layout_width="match_parent"
-            android:layout_height="2dp"
-            android:background="@color/divider"/>
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="2dp"
+        android:background="@color/divider" />
+
+    <ScrollView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
 
         <LinearLayout
-            android:id="@+id/ll_postal"
-            android:layout_width="wrap_content"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:orientation="horizontal"
-            android:gravity="center_vertical"
-            android:paddingStart="@dimen/margin_default"
-            android:paddingEnd="@dimen/margin_default"
-            android:layout_marginTop="@dimen/margin_default">
-            <TextView
+            android:orientation="vertical">
+
+            <LinearLayout
+                android:id="@+id/ll_postal"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:textSize="@dimen/size_text_title"
-                android:textColor="@color/black_press"
-                android:text="@string/postal_code_title"/>
+                android:layout_marginTop="@dimen/margin_default"
+                android:gravity="center_vertical"
+                android:orientation="horizontal"
+                android:paddingStart="@dimen/margin_default"
+                android:paddingEnd="@dimen/margin_default">
 
-            <TextView
-                android:id="@+id/tv_postal"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:textSize="@dimen/size_text_title"
-                android:textColor="@color/gray_text" />
-        </LinearLayout>
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="@string/postal_code_title"
+                    android:textColor="@color/black_press"
+                    android:textSize="@dimen/size_text_title" />
 
-        <LinearLayout
-            android:id="@+id/ll_address"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal"
-            android:gravity="center_vertical"
-            android:paddingStart="@dimen/margin_default"
-            android:paddingEnd="@dimen/margin_default"
-            android:layout_marginTop="@dimen/margin_default">
-            <TextView
+                <TextView
+                    android:id="@+id/tv_postal"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textColor="@color/gray_text"
+                    android:textSize="@dimen/size_text_title" />
+            </LinearLayout>
+
+            <LinearLayout
+                android:id="@+id/ll_address"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:textSize="@dimen/size_text_title"
-                android:textColor="@color/black_press"
-                android:text="@string/address_title"/>
+                android:layout_marginTop="@dimen/margin_default"
+                android:gravity="center_vertical"
+                android:orientation="horizontal"
+                android:paddingStart="@dimen/margin_default"
+                android:paddingEnd="@dimen/margin_default">
 
-            <TextView
-                android:id="@+id/tv_address"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:textSize="@dimen/size_text_title"
-                android:textColor="@color/gray_text" />
-        </LinearLayout>
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="@string/address_title"
+                    android:textColor="@color/black_press"
+                    android:textSize="@dimen/size_text_title" />
 
+                <TextView
+                    android:id="@+id/tv_address"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textColor="@color/gray_text"
+                    android:textSize="@dimen/size_text_title" />
+            </LinearLayout>
 
-        <LinearLayout
-            android:id="@+id/ll_name"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal"
-            android:gravity="center_vertical"
-            android:paddingStart="@dimen/margin_default"
-            android:paddingEnd="@dimen/margin_default"
-            android:layout_marginTop="@dimen/margin_default">
-            <TextView
+            <LinearLayout
+                android:id="@+id/ll_name"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:textSize="@dimen/size_text_title"
-                android:textColor="@color/black_press"
-                android:text="@string/name_title"/>
+                android:layout_marginTop="@dimen/margin_default"
+                android:gravity="center_vertical"
+                android:orientation="horizontal"
+                android:paddingStart="@dimen/margin_default"
+                android:paddingEnd="@dimen/margin_default">
 
-            <TextView
-                android:id="@+id/tv_name"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:textSize="@dimen/size_text_title"
-                android:textColor="@color/gray_text"/>
-        </LinearLayout>
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="@string/name_title"
+                    android:textColor="@color/black_press"
+                    android:textSize="@dimen/size_text_title" />
 
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal"
-            android:gravity="center"
-            android:paddingStart="@dimen/margin_default"
-            android:paddingEnd="@dimen/margin_default"
-            android:layout_marginTop="64dp"
-            android:layout_marginBottom="32dp">
-
-            <TextView
-                android:id="@+id/tv_copy"
-                android:layout_width="wrap_content"
-                android:minWidth="114dp"
-                android:layout_height="wrap_content"
-                android:singleLine="true"
-                android:ellipsize="end"
-                android:gravity="center"
-                android:textSize="11.5sp"
-                android:textColor="@color/white"
-                android:paddingStart="@dimen/margin_s"
-                android:paddingEnd="@dimen/margin_s"
-                android:paddingTop="@dimen/margin_button"
-                android:paddingBottom="@dimen/margin_button"
-                android:background="@drawable/selector_copy"
-                android:text="@string/copy"/>
-
-            <Space
-                android:layout_width="@dimen/margin_default"
-                android:layout_height="wrap_content"/>
-
-            <TextView
-                android:id="@+id/tv_cancel"
-                android:layout_width="wrap_content"
-                android:minWidth="114dp"
+                <TextView
+                    android:id="@+id/tv_name"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textColor="@color/gray_text"
+                    android:textSize="@dimen/size_text_title" />
+            </LinearLayout>
+
+            <LinearLayout
+                android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:singleLine="true"
-                android:ellipsize="end"
-                android:textColor="@color/black_press"
+                android:layout_marginTop="64dp"
+                android:layout_marginBottom="32dp"
                 android:gravity="center"
-                android:textSize="11.8sp"
-                android:paddingStart="@dimen/margin_s"
-                android:paddingEnd="@dimen/margin_s"
-                android:paddingTop="@dimen/margin_button"
-                android:paddingBottom="@dimen/margin_button"
-                android:background="@drawable/selector_cancel"
-                android:text="@string/cancel"/>
+                android:orientation="horizontal"
+                android:paddingStart="@dimen/margin_default"
+                android:paddingEnd="@dimen/margin_default">
+
+                <TextView
+                    android:id="@+id/tv_copy"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:background="@drawable/selector_copy"
+                    android:ellipsize="end"
+                    android:gravity="center"
+                    android:minWidth="114dp"
+                    android:paddingStart="@dimen/margin_s"
+                    android:paddingTop="@dimen/margin_button"
+                    android:paddingEnd="@dimen/margin_s"
+                    android:paddingBottom="@dimen/margin_button"
+                    android:singleLine="true"
+                    android:text="@string/copy"
+                    android:textColor="@color/white"
+                    android:textSize="11.5sp" />
+
+                <Space
+                    android:layout_width="@dimen/margin_default"
+                    android:layout_height="wrap_content" />
+
+                <TextView
+                    android:id="@+id/tv_cancel"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:background="@drawable/selector_cancel"
+                    android:ellipsize="end"
+                    android:gravity="center"
+                    android:minWidth="114dp"
+                    android:paddingStart="@dimen/margin_s"
+                    android:paddingTop="@dimen/margin_button"
+                    android:paddingEnd="@dimen/margin_s"
+                    android:paddingBottom="@dimen/margin_button"
+                    android:singleLine="true"
+                    android:text="@string/cancel"
+                    android:textColor="@color/black_press"
+                    android:textSize="11.8sp" />
+            </LinearLayout>
         </LinearLayout>
-    </LinearLayout>
-</ScrollView>
+    </ScrollView>
+
+
+
+</LinearLayout>