Skip to content

Instantly share code, notes, and snippets.

View doomSDey's full-sized avatar
:electron:
Holding everything together with try and catch

Sudipta Dey doomSDey

:electron:
Holding everything together with try and catch
View GitHub Profile
@doomSDey
doomSDey / index.html
Created March 28, 2020 11:09
Sticky Notes
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Sticky Notes board</title>
<meta name="description" content="Sticky Notes by Edmond Ko">
<meta name="author" content="Edmond Ko">
<link href='https://fonts.googleapis.com/css?family=Gloria+Hallelujah' rel='stylesheet' type='text/css'>
</head>
<body>
android{
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
// Add CameraX dependencies
implementation "androidx.camera:camera-core:1.0.0-beta05"
<SurfaceView
android:id="@+id/overlay"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.camera.view.PreviewView
PreviewView mCameraView;
SurfaceHolder holder;
SurfaceView surfaceView;
Canvas canvas;
Paint paint;
int cameraHeight, cameraWidth, xOffset, yOffset, boxWidth, boxHeight;
private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;
private ExecutorService executor = Executors.newSingleThreadExecutor();
...
//Image Analysis Function
//Set static size according to your device or write a dynamic function for it
ImageAnalysis imageAnalysis =
new ImageAnalysis.Builder()
.setTargetResolution(new Size(720, 1488))
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.build();
private int degreesToFirebaseRotation(int degrees) {
switch (degrees) {
case 0:
return FirebaseVisionImageMetadata.ROTATION_0;
case 90:
return FirebaseVisionImageMetadata.ROTATION_90;
case 180:
return FirebaseVisionImageMetadata.ROTATION_180;
case 270:
return FirebaseVisionImageMetadata.ROTATION_270;
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback {
TextView textView;
PreviewView mCameraView;
SurfaceHolder holder;
SurfaceView surfaceView;
Canvas canvas;
Paint paint;
int cameraHeight, cameraWidth, xOffset, yOffset, boxWidth, boxHeight;
private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;
dependencies {
// ... implementation 'com.google.firebase:firebase-ml-vision:24.0.3'
}
<application ...>
...
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="ocr" />
</application>
<uses-permission android:name="android.permission.CAMERA"/>