-
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
Showing
65 changed files
with
2,184 additions
and
3 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.
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,47 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.example.ai_background_eraser' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.example.ai_background_eraser" | ||
minSdk 24 | ||
targetSdk 33 | ||
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 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.9.0' | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.8.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
implementation project(path: ':autobackgroundremover') | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
//gestureView | ||
implementation 'com.alexvasilkov:gesture-views:2.8.3' | ||
} |
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,22 @@ | ||
# 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 | ||
|
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/example/ai_background_eraser/ExampleInstrumentedTest.kt
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,24 @@ | ||
package com.example.ai_background_eraser | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.example.ai_background_eraser", appContext.packageName) | ||
} | ||
} |
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,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<uses-permission android:name="android.permission.CAMERA" /> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<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:supportsRtl="true" | ||
android:theme="@style/Theme.AIBackgroundEraser" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:screenOrientation="portrait" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<!-- <activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"--> | ||
<!-- android:theme="@style/Base.Theme.AppCompat"/>--> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions
61
app/src/main/java/com/example/ai_background_eraser/BitmapUtility.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,61 @@ | ||
package com.example.ai_background_eraser; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.graphics.Matrix; | ||
import android.graphics.Paint; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.PorterDuffColorFilter; | ||
|
||
public class BitmapUtility { | ||
|
||
static Bitmap getResizedBitmap(Bitmap bitmap, int width, int height) { | ||
Bitmap background = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); | ||
|
||
float originalWidth = bitmap.getWidth(); | ||
float originalHeight = bitmap.getHeight(); | ||
|
||
Canvas canvas = new Canvas(background); | ||
|
||
float scale = width / originalWidth; | ||
|
||
float xTranslation = 0.0f; | ||
float yTranslation = (height - originalHeight * scale) / 2.0f; | ||
|
||
Matrix transformation = new Matrix(); | ||
transformation.postTranslate(xTranslation, yTranslation); | ||
transformation.preScale(scale, scale); | ||
|
||
Paint paint = new Paint(); | ||
paint.setFilterBitmap(true); | ||
|
||
canvas.drawBitmap(bitmap, transformation, paint); | ||
|
||
return background; | ||
} | ||
|
||
static Bitmap getBorderedBitmap(Bitmap image, int borderColor, int borderSize) { | ||
|
||
// Creating a canvas with an empty bitmap, this is the bitmap that gonna store the final canvas changes | ||
Bitmap finalImage = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888); | ||
Canvas canvas = new Canvas(finalImage); | ||
|
||
// Make a smaller copy of the image to draw on top of original | ||
Bitmap imageCopy = Bitmap.createScaledBitmap(image, image.getWidth() - borderSize, image.getHeight() - borderSize, true); | ||
|
||
// Let's draw the bigger image using a white paint brush | ||
Paint paint = new Paint(); | ||
paint.setColorFilter(new PorterDuffColorFilter(borderColor, PorterDuff.Mode.SRC_ATOP)); | ||
canvas.drawBitmap(image, 0, 0, paint); | ||
|
||
int width = image.getWidth(); | ||
int height = image.getHeight(); | ||
float centerX = (width - imageCopy.getWidth()) * 0.5f; | ||
float centerY = (height - imageCopy.getHeight()) * 0.5f; | ||
// Now let's draw the original image on top of the white image, passing a null paint because we want to keep it original | ||
canvas.drawBitmap(imageCopy, centerX, centerY, null); | ||
|
||
// Returning the image with the final results | ||
return finalImage; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
app/src/main/java/com/example/ai_background_eraser/CheckerboardDrawable.kt
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,88 @@ | ||
package com.example.ai_background_eraser | ||
|
||
import android.graphics.* | ||
import android.graphics.drawable.Drawable | ||
|
||
//import android.support.annotation.NonNull; | ||
//import android.support.annotation.Nullable; | ||
|
||
|
||
class CheckerboardDrawable private constructor(builder: Builder) : | ||
Drawable() { | ||
private val paint = Paint(Paint.ANTI_ALIAS_FLAG) | ||
private val size: Int | ||
private val colorOdd: Int | ||
private val colorEven: Int | ||
|
||
init { | ||
size = builder.size | ||
colorOdd = builder.colorOdd | ||
colorEven = builder.colorEven | ||
configurePaint() | ||
} | ||
|
||
private fun configurePaint() { | ||
val bitmap = Bitmap.createBitmap(size * 2, size * 2, Bitmap.Config.ARGB_8888) | ||
val bitmapPaint = Paint(Paint.ANTI_ALIAS_FLAG) | ||
bitmapPaint.style = Paint.Style.FILL | ||
val canvas = Canvas(bitmap) | ||
val rect = Rect(0, 0, size, size) | ||
bitmapPaint.color = colorOdd | ||
canvas.drawRect(rect, bitmapPaint) | ||
rect.offset(size, size) | ||
canvas.drawRect(rect, bitmapPaint) | ||
bitmapPaint.color = colorEven | ||
rect.offset(-size, 0) | ||
canvas.drawRect(rect, bitmapPaint) | ||
rect.offset(size, -size) | ||
canvas.drawRect(rect, bitmapPaint) | ||
paint.shader = | ||
BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT) | ||
} | ||
|
||
override fun draw(canvas: Canvas) { | ||
canvas.drawPaint(paint) | ||
} | ||
|
||
override fun setAlpha(alpha: Int) { | ||
paint.alpha = alpha | ||
} | ||
|
||
override fun setColorFilter(colorFilter: ColorFilter?) { | ||
paint.colorFilter = colorFilter | ||
} | ||
|
||
override fun getOpacity(): Int { | ||
return PixelFormat.OPAQUE | ||
} | ||
|
||
class Builder { | ||
var size = 40 | ||
var colorOdd = -0x3d3d3e | ||
var colorEven = -0xc0c0d | ||
fun size(size: Int): Builder { | ||
this.size = size | ||
return this | ||
} | ||
|
||
fun colorOdd(color: Int): Builder { | ||
colorOdd = color | ||
return this | ||
} | ||
|
||
fun colorEven(color: Int): Builder { | ||
colorEven = color | ||
return this | ||
} | ||
|
||
fun build(): CheckerboardDrawable { | ||
return CheckerboardDrawable(this) | ||
} | ||
} | ||
|
||
companion object { | ||
fun create(): CheckerboardDrawable { | ||
return CheckerboardDrawable(Builder()) | ||
} | ||
} | ||
} |
Oops, something went wrong.