forked from aadityamp01/Androapps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db2b0a5
commit b6f0a48
Showing
44 changed files
with
1,140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
compileSdk 32 | ||
|
||
defaultConfig { | ||
applicationId "com.rahulsoni0.image2text" | ||
minSdk 21 | ||
targetSdk 32 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
buildFeatures { | ||
viewBinding true | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.appcompat:appcompat:1.5.1' | ||
implementation 'com.google.android.material:material:1.6.1' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
|
||
//ml kit | ||
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:18.0.2' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
...mage2Text/app/src/androidTest/java/com/rahulsoni0/image2text/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.rahulsoni0.image2text; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.rahulsoni0.image2text", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.rahulsoni0.image2text"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"></uses-permission> | ||
<uses-permission android:name="android.permission.CAMERA"></uses-permission> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Image2Text" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".tools.ScannerActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
36 changes: 36 additions & 0 deletions
36
Image2Text/Image2Text/app/src/main/java/com/rahulsoni0/image2text/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.rahulsoni0.image2text; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.app.ActionBar; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.WindowManager; | ||
|
||
import com.rahulsoni0.image2text.databinding.ActivityMainBinding; | ||
import com.rahulsoni0.image2text.tools.ScannerActivity; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
private ActivityMainBinding binding;// viewBinding | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
binding = ActivityMainBinding.inflate(getLayoutInflater()); | ||
setContentView(binding.getRoot()); | ||
if (getSupportActionBar() != null) { | ||
getSupportActionBar().hide(); | ||
} | ||
|
||
binding.btnCapture.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent i = new Intent(MainActivity.this, ScannerActivity.class); | ||
startActivity(i); | ||
} | ||
}); | ||
|
||
|
||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
Image2Text/Image2Text/app/src/main/java/com/rahulsoni0/image2text/tools/ScannerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package com.rahulsoni0.image2text.tools; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.Manifest; | ||
import android.app.ActionBar; | ||
import android.app.Activity; | ||
import android.content.ClipData; | ||
import android.content.ClipboardManager; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Point; | ||
import android.graphics.Rect; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.provider.MediaStore; | ||
import android.view.ContextMenu; | ||
import android.view.View; | ||
import android.view.WindowManager; | ||
import android.widget.Toast; | ||
|
||
import com.google.android.gms.tasks.OnFailureListener; | ||
import com.google.android.gms.tasks.OnSuccessListener; | ||
import com.google.android.gms.tasks.Task; | ||
import com.google.mlkit.vision.common.InputImage; | ||
import com.google.mlkit.vision.text.Text; | ||
import com.google.mlkit.vision.text.TextRecognition; | ||
import com.google.mlkit.vision.text.TextRecognizer; | ||
import com.google.mlkit.vision.text.latin.TextRecognizerOptions; | ||
import com.rahulsoni0.image2text.R; | ||
import com.rahulsoni0.image2text.databinding.ActivityScannerBinding; | ||
|
||
public class ScannerActivity extends AppCompatActivity { | ||
private Bitmap imageBitmap; | ||
private static final int CAMERA_REQUEST = 1888; | ||
private static final int MY_CAMERA_PERMISSION_CODE = 100; | ||
private ActivityScannerBinding binding; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
binding = ActivityScannerBinding.inflate(getLayoutInflater()); | ||
setContentView(binding.getRoot()); | ||
if (getSupportActionBar() != null) { | ||
getSupportActionBar().hide(); | ||
} | ||
binding.btnSnap.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { | ||
requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_CAMERA_PERMISSION_CODE); | ||
} else { | ||
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | ||
startActivityForResult(cameraIntent, CAMERA_REQUEST); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
binding.btnScntext.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
|
||
detectText(); | ||
} | ||
}); | ||
|
||
registerForContextMenu(binding.tvResult); | ||
|
||
|
||
} | ||
|
||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
if (requestCode == MY_CAMERA_PERMISSION_CODE) { | ||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show(); | ||
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); | ||
startActivityForResult(cameraIntent, CAMERA_REQUEST); | ||
} else { | ||
Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) { | ||
Bitmap photo = (Bitmap) data.getExtras().get("data"); | ||
binding.ivResult.setImageBitmap(photo); | ||
imageBitmap = photo; | ||
} | ||
} | ||
|
||
private void detectText() { | ||
|
||
InputImage image = InputImage.fromBitmap(imageBitmap, 0); | ||
TextRecognizer recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS); | ||
Task<Text> result = recognizer.process(image).addOnSuccessListener(new OnSuccessListener<Text>() { | ||
@Override | ||
public void onSuccess(Text text) { | ||
|
||
StringBuilder result = new StringBuilder(); | ||
for (Text.TextBlock block : text.getTextBlocks()) { | ||
String blockText = block.getText(); | ||
Point[] blockCornerpoint = block.getCornerPoints(); | ||
Rect blockFrame = block.getBoundingBox(); | ||
for (Text.Line line : block.getLines()) { | ||
String lineText = line.getText(); | ||
Point[] lineCornerPoint = line.getCornerPoints(); | ||
Rect lineRect = line.getBoundingBox(); | ||
for (Text.Element element : line.getElements()) { | ||
String elementText = element.getText(); | ||
result.append(elementText + " "); | ||
} | ||
//Toast.makeText(getApplicationContext(), result.toString()+" hello", Toast.LENGTH_SHORT).show(); | ||
binding.tvResult.setText(result.toString()); | ||
} | ||
|
||
} | ||
} | ||
}).addOnFailureListener(new OnFailureListener() { | ||
@Override | ||
public void onFailure(@NonNull Exception e) { | ||
Toast.makeText(getApplicationContext(), "Failed to detect text From image ....!" + e.getMessage(), Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onCreateContextMenu(ContextMenu menu, View v, | ||
ContextMenu.ContextMenuInfo menuInfo) { | ||
|
||
menu.add(0, v.getId(), 0, "Copy"); | ||
menu.setHeaderTitle("Copy text"); //setting header title for menu | ||
ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); | ||
ClipData clipData = ClipData.newPlainText("text", binding.tvResult.getText()); | ||
manager.setPrimaryClip(clipData); | ||
Toast.makeText(ScannerActivity.this, "Text Copied to clipboard", Toast.LENGTH_SHORT).show(); | ||
} | ||
} |
Oops, something went wrong.