-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathScanActivity.java
More file actions
175 lines (150 loc) · 6.42 KB
/
ScanActivity.java
File metadata and controls
175 lines (150 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.scanlibrary;
import android.Manifest;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.ComponentCallbacks2;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jhansi on 28/03/15.
*/
public class ScanActivity extends Activity implements IScanner, ComponentCallbacks2 {
String[] permissions = new String[2];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= 33) {
permissions[0] = Manifest.permission.READ_MEDIA_IMAGES;
} else {
permissions[0] = Manifest.permission.READ_EXTERNAL_STORAGE;
}
permissions[1] = Manifest.permission.CAMERA;
setContentView(R.layout.scan_layout);
if(getActionBar() != null){
getActionBar().hide();
}
checkPermissions();
}
private void checkPermissions() {
List<String> listPermissionsNeeded = new ArrayList<>();
for (String p : permissions) {
int result = ContextCompat.checkSelfPermission(this, p);
if (result != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(p);
}
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), 100);
return;
}
init();
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 100) {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
init();
}
}
}
private void init() {
PickImageFragment fragment = new PickImageFragment();
Bundle bundle = new Bundle();
bundle.putInt(ScanConstants.OPEN_INTENT_PREFERENCE, getPreferenceContent());
bundle.putInt("quality", getIntent().getIntExtra("quality", 1));
fragment.setArguments(bundle);
android.app.FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.content, fragment);
fragmentTransaction.commit();
}
protected int getPreferenceContent() {
return getIntent().getIntExtra(ScanConstants.OPEN_INTENT_PREFERENCE, 0);
}
@Override
public void onBitmapSelect(Uri uri) {
ScanFragment fragment = new ScanFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ScanConstants.SELECTED_BITMAP, uri);
fragment.setArguments(bundle);
android.app.FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.content, fragment);
fragmentTransaction.addToBackStack(ScanFragment.class.toString());
fragmentTransaction.commit();
}
@Override
public void onScanFinish(Uri uri) {
ResultFragment fragment = new ResultFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ScanConstants.SCANNED_RESULT, uri);
fragment.setArguments(bundle);
android.app.FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.content, fragment);
fragmentTransaction.addToBackStack(ResultFragment.class.toString());
fragmentTransaction.commit();
}
@Override
public void onTrimMemory(int level) {
switch (level) {
case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
/*
Release any UI objects that currently hold memory.
The user interface has moved to the background.
*/
break;
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
/*
Release any memory that your app doesn't need to run.
The device is running low on memory while the app is running.
The event raised indicates the severity of the memory-related event.
If the event is TRIM_MEMORY_RUNNING_CRITICAL, then the system will
begin killing background processes.
*/
break;
case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
/*
Release as much memory as the process can.
The app is on the LRU list and the system is running low on memory.
The event raised indicates where the app sits within the LRU list.
If the event is TRIM_MEMORY_COMPLETE, the process will be one of
the first to be terminated.
*/
// new AlertDialog.Builder(this)
// .setTitle(R.string.low_memory)
// .setMessage(R.string.low_memory_message)
// .create()
// .show();
break;
default:
/*
Release any non-critical data structures.
The app received an unrecognized memory level value
from the system. Treat this as a generic low-memory message.
*/
break;
}
}
public native Bitmap getScannedBitmap(Bitmap bitmap, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
public native Bitmap getGrayBitmap(Bitmap bitmap);
public native Bitmap getMagicColorBitmap(Bitmap bitmap);
public native Bitmap getBWBitmap(Bitmap bitmap);
public native float[] getPoints(Bitmap bitmap);
static {
System.loadLibrary("opencv_java3");
System.loadLibrary("Scanner");
}
}