-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Release v0.0.1
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# architecture-classifier | ||
# Architecture classifier |
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
namespace 'com.architecture.app' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.architecture.app" | ||
minSdk 29 | ||
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 | ||
} | ||
|
||
aaptOptions { | ||
noCompress "tflite" | ||
} | ||
buildFeatures { | ||
mlModelBinding true | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.8.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
implementation 'androidx.camera:camera-core:1.2.2' | ||
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0' | ||
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
} |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.architecture.app; | ||
|
||
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.architecture.app", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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-feature android:name="android.hardware.camera" /> | ||
|
||
<uses-permission android:name="android.permission.CAMERA" /> | ||
<uses-permission android:name="android.permission.READ_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.App" | ||
tools:targetApi="31"> | ||
<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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Ancient Egyptian architecture | ||
Deconstructivism | ||
Greek Revival architecture |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.architecture.app; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.graphics.Bitmap; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.provider.MediaStore; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RequiresApi; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.core.app.ActivityCompat; | ||
|
||
import com.architecture.app.image.AbstractImageLoader; | ||
import com.architecture.app.image.ImageLoaderFactory; | ||
import com.architecture.app.image.RequestCodes; | ||
import com.architecture.app.model.ModelLoader; | ||
import com.architecture.app.permission.Permissions; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
private Button _cameraButton; | ||
private Button _galleryButton; | ||
private TextView _label; | ||
private ImageView _image; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU) | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
setContentView(R.layout.activity_main); | ||
initializeUI(); | ||
grantPermissions(); | ||
|
||
_cameraButton.setOnClickListener( | ||
view -> { | ||
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | ||
startActivityForResult(intent, RequestCodes.CAMERA); | ||
} | ||
); | ||
_galleryButton.setOnClickListener( | ||
view -> { | ||
Intent intent = new Intent().setType("image/*").setAction(Intent.ACTION_GET_CONTENT); | ||
startActivityForResult(Intent.createChooser(intent, "Select picture"), RequestCodes.GALLERY); | ||
} | ||
); | ||
} | ||
|
||
@SuppressLint("SetTextI18n") | ||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
if(resultCode != Activity.RESULT_OK) { | ||
return; | ||
} | ||
|
||
try { | ||
AbstractImageLoader imageLoader = new ImageLoaderFactory().create(requestCode, getApplicationContext()); | ||
setImage(imageLoader.load(data)); | ||
} catch(Exception exception) { | ||
_label.setText(exception.getMessage()); | ||
} | ||
|
||
super.onActivityResult(requestCode, resultCode, data); | ||
} | ||
|
||
private void setImage(Bitmap image) { | ||
_image.setImageBitmap(image); | ||
|
||
ModelLoader modelLoader = new ModelLoader(getApplicationContext()); | ||
_label.setText(modelLoader.classifyImage(image)); | ||
} | ||
|
||
private void grantPermissions() { | ||
boolean hasCameraAccess = checkSelfPermission(Permissions.CAMERA) == PackageManager.PERMISSION_GRANTED; | ||
boolean hasStorageAccess = checkSelfPermission(Permissions.READ_STORAGE) == PackageManager.PERMISSION_GRANTED; | ||
|
||
if(!hasCameraAccess) { | ||
ActivityCompat.requestPermissions( | ||
MainActivity.this, | ||
new String[] {Permissions.CAMERA}, | ||
Permissions.CAMERA_REQUEST_CODE | ||
); | ||
} | ||
|
||
if(!hasStorageAccess) { | ||
ActivityCompat.requestPermissions( | ||
MainActivity.this, | ||
new String[] {Permissions.READ_STORAGE}, | ||
Permissions.STORAGE_REQUEST_CODE | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||
for(int grantResult : grantResults) { | ||
if (grantResult != PackageManager.PERMISSION_GRANTED) { | ||
grantPermissions(); | ||
} | ||
} | ||
|
||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
} | ||
|
||
private void initializeUI() { | ||
_cameraButton = findViewById(R.id.cameraButton); | ||
_galleryButton = findViewById(R.id.galleryButton); | ||
_image = findViewById(R.id.image); | ||
_label = findViewById(R.id.textView); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.architecture.app.image; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import java.io.FileNotFoundException; | ||
|
||
public abstract class AbstractImageLoader { | ||
private final Context _context; | ||
|
||
public AbstractImageLoader(Context context) { | ||
_context = context; | ||
} | ||
|
||
public Context getContext() { | ||
return _context; | ||
} | ||
|
||
@Nullable | ||
public abstract Bitmap load(Intent intent) throws FileNotFoundException; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.architecture.app.image; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
|
||
public class CameraImageLoader extends AbstractImageLoader { | ||
public CameraImageLoader(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public Bitmap load(Intent data) { | ||
return (Bitmap) data.getExtras().get("data"); | ||
} | ||
} |