Skip to content

Instantly share code, notes, and snippets.

@prakashpun
prakashpun / MainActivity.java
Created January 7, 2018 08:53
Google Mobile Ads SDK initialization
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize the Mobile Ads SDK.
MobileAds.initialize(this,getString(R.string.admob_app_id));
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
...
}
@prakashpun
prakashpun / strings.xml
Created January 7, 2018 08:48
Add test AdMob app ID and ad unit IDs which has to be replaced later with live production ads for Admob account
<resources>
...
<string name="admob_app_id">ca-app-pub-3940256099942544~3347511713</string>
<string name="ad_unit_id">ca-app-pub-3940256099942544/5224354917</string>
...
</resources>
@prakashpun
prakashpun / build.gradle
Created January 7, 2018 08:29
build.gradle for adding dependency for firebase ads
dependencies {
...
compile 'com.google.firebase:firebase-ads:11.8.0'
...
}
//Dont forget to apply the plugin below
apply plugin: 'com.google.gms.google-services'
@prakashpun
prakashpun / build.gradle
Last active January 7, 2018 08:42
build.gradle for the project
buildscript {
repositories {
jcenter()
}
dependencies {
...
classpath 'com.google.gms:google-services:3.0.0'
}
}
@prakashpun
prakashpun / MainActivity.java
Last active December 30, 2017 16:10
Set the TextRecognizer's Processor.
textRecognizer.setProcessor(new Detector.Processor<TextBlock>() {
@Override
public void release() {
}
/**
* Detect all the text from camera using TextBlock and the save values into a stringBuilder
* which will then be set to the textView.
* */
@Override
@prakashpun
prakashpun / MainActivity.java
Created December 30, 2017 15:40
Initialize mCameraSource
mCameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1280, 1024)
.setAutoFocusEnabled(true)
.setRequestedFps(2.0f)
.build();
@prakashpun
prakashpun / MainActivity.java
Last active April 8, 2020 10:59
Initialize TextRecognizer and CameraSource
private void startCameraSource() {
//Create the TextRecognizer
final TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
if (!textRecognizer.isOperational()) {
Log.w(TAG, "Detector dependencies not loaded yet");
} else {
//Initialize camerasource to use high resolution and set Autofocus on.
@prakashpun
prakashpun / activity_main.xml
Created December 30, 2017 15:02
Layout file for activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5"
tools:context="com.tuts.prakash.simpleocr.MainActivity">
<SurfaceView
android:id="@+id/surfaceView"
@prakashpun
prakashpun / AndroidManifest.xml
Created December 30, 2017 14:59
AndroidManifest.xml for OCR
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tuts.prakash.simpleocr">
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
@prakashpun
prakashpun / build.gradle
Last active December 30, 2017 14:56
dependency for Google Mobile Vision library
dependencies {
...
compile 'com.google.android.gms:play-services-vision:11.0.4'
...
}