-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScanActivity.java
128 lines (110 loc) · 4.88 KB
/
ScanActivity.java
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
package com.scanlibrary;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.content.ComponentCallbacks2;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
/**
* Created by jhansi on 28/03/15.
*/
public class ScanActivity extends Activity implements IScanner, ComponentCallbacks2 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scan_layout);
init();
}
private void init() {
PickImageFragment fragment = new PickImageFragment();
Bundle bundle = new Bundle();
bundle.putInt(ScanConstants.OPEN_INTENT_PREFERENCE, getPreferenceContent());
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");
}
}