diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd45b12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea/caches/build_file_checksums.ser +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml new file mode 100644 index 0000000..bf74c20 --- /dev/null +++ b/.idea/assetWizardSettings.xml @@ -0,0 +1,52 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e0d5b93 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Procfile b/Procfile deleted file mode 100644 index 9df3bff..0000000 --- a/Procfile +++ /dev/null @@ -1,3 +0,0 @@ -web: gunicorn cat_or_not -heroku ps:scale web=1 -export GOOGLE_APPLICATION_CREDENTIALS="authentication.json" diff --git a/README.md b/README.md index dbce2c3..feacf6d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Cat or Not - artifact repository -# First prototype +# Version 0.9 (UI not completed) ### Monday 15:30 group ## How to use this repository? @@ -14,5 +14,5 @@ Application prototype is located in the **app** branch. ## Version Control Document It is located in a [repository's wiki](https://git.wmi.amu.edu.pl/s434650/CatOrNot/wiki/Version+History+Document). It will be updated with each accepted artifact. -## Heroku application -https://lit-wildwood-10245.herokuapp.com/ +## APK for System Administrator +APK is located in path /app/release/app-release.apk diff --git a/__pycache__/cat_or_not.cpython-36.pyc b/__pycache__/cat_or_not.cpython-36.pyc deleted file mode 100644 index 63f3e4d..0000000 Binary files a/__pycache__/cat_or_not.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/cat_recognition.cpython-36.pyc b/__pycache__/cat_recognition.cpython-36.pyc deleted file mode 100644 index 5f0382d..0000000 Binary files a/__pycache__/cat_recognition.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/config.cpython-36.pyc b/__pycache__/config.cpython-36.pyc deleted file mode 100644 index 442ed48..0000000 Binary files a/__pycache__/config.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/forms.cpython-36.pyc b/__pycache__/forms.cpython-36.pyc deleted file mode 100644 index 18070b2..0000000 Binary files a/__pycache__/forms.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/hello.cpython-36.pyc b/__pycache__/hello.cpython-36.pyc deleted file mode 100644 index 47f8c9f..0000000 Binary files a/__pycache__/hello.cpython-36.pyc and /dev/null differ diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/__init__.py b/app/__init__.py deleted file mode 100644 index f5b34f4..0000000 --- a/app/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask import Flask -from config import Config - -app = Flask(__name__) -app.config.from_object(Config) - -from app import routes diff --git a/app/__pycache__/__init__.cpython-36.pyc b/app/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 10c727a..0000000 Binary files a/app/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/app/__pycache__/cat_recognition.cpython-36.pyc b/app/__pycache__/cat_recognition.cpython-36.pyc deleted file mode 100644 index 9289b2a..0000000 Binary files a/app/__pycache__/cat_recognition.cpython-36.pyc and /dev/null differ diff --git a/app/__pycache__/forms.cpython-36.pyc b/app/__pycache__/forms.cpython-36.pyc deleted file mode 100644 index 8e14a92..0000000 Binary files a/app/__pycache__/forms.cpython-36.pyc and /dev/null differ diff --git a/app/__pycache__/picture_downloader.cpython-36.pyc b/app/__pycache__/picture_downloader.cpython-36.pyc deleted file mode 100644 index 1fd1e52..0000000 Binary files a/app/__pycache__/picture_downloader.cpython-36.pyc and /dev/null differ diff --git a/app/__pycache__/routes.cpython-36.pyc b/app/__pycache__/routes.cpython-36.pyc deleted file mode 100644 index 32d5883..0000000 Binary files a/app/__pycache__/routes.cpython-36.pyc and /dev/null differ diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..9701fa0 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.example.se.catornot" + minSdkVersion 15 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} diff --git a/app/cat_recognition.py b/app/cat_recognition.py deleted file mode 100644 index b65d418..0000000 --- a/app/cat_recognition.py +++ /dev/null @@ -1,20 +0,0 @@ -# Imports the Google Cloud client library -from google.cloud import vision -from google.cloud.vision import types - -def is_cat(content): - labels = fetch_data(content) - if labels[0].description == "cat": - return True - else: - return False - -def fetch_data(content): - # Instantiates a client - client = vision.ImageAnnotatorClient() - # Tell Google Vision that our content is of type Image - image = types.Image(content=content) - # Performs label detection on the image file - response = client.label_detection(image=image) - # Return array of labels - return response.label_annotations diff --git a/app/forms.py b/app/forms.py deleted file mode 100644 index ab65d4c..0000000 --- a/app/forms.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask_wtf import FlaskForm -from wtforms import StringField, PasswordField, BooleanField, SubmitField -from wtforms.validators import DataRequired - -class UploadForm(FlaskForm): - url = StringField('Link', validators=[DataRequired()]) - submit = SubmitField('Cat or not?') diff --git a/app/picture_downloader.py b/app/picture_downloader.py deleted file mode 100644 index 3304f35..0000000 --- a/app/picture_downloader.py +++ /dev/null @@ -1,10 +0,0 @@ -import requests - -def get_image_from_url(url): - f = open('pic.jpg','wb') - f.write(requests.get(url).content) - f.close() - f = open('pic.jpg','rb') - file = f.read() - f.close() - return file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -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 diff --git a/app/release/app-release.apk b/app/release/app-release.apk new file mode 100644 index 0000000..220762c Binary files /dev/null and b/app/release/app-release.apk differ diff --git a/app/release/output.json b/app/release/output.json new file mode 100644 index 0000000..9f0c959 --- /dev/null +++ b/app/release/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file diff --git a/app/routes.py b/app/routes.py deleted file mode 100644 index feedcbd..0000000 --- a/app/routes.py +++ /dev/null @@ -1,18 +0,0 @@ -from flask import Flask -from flask import render_template -from app.forms import UploadForm -from app import app -from app import cat_recognition as cat -from app import picture_downloader as downloader - -@app.route('/', methods=['GET', 'POST']) -def index(): - form = UploadForm() - if form.validate_on_submit(): - content = downloader.get_image_from_url(form.url.data) - if cat.is_cat(content): - return "Cat!" - else: - return "Not!" - - return render_template('index.html', form=form) diff --git a/app/src/androidTest/java/com/example/se/catornot/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/se/catornot/ExampleInstrumentedTest.java new file mode 100644 index 0000000..bbe7715 --- /dev/null +++ b/app/src/androidTest/java/com/example/se/catornot/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.se.catornot; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.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 Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.example.se.catornot", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0be7c2a --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/se/catornot/MainActivity.java b/app/src/main/java/com/example/se/catornot/MainActivity.java new file mode 100644 index 0000000..78fda01 --- /dev/null +++ b/app/src/main/java/com/example/se/catornot/MainActivity.java @@ -0,0 +1,120 @@ +package com.example.se.catornot; + +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Environment; +import android.provider.MediaStore; +import android.support.v4.content.FileProvider; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Random; + +import static android.graphics.Color.GREEN; +import static android.graphics.Color.RED; + +public class MainActivity extends AppCompatActivity { + + static final int REQUEST_IMAGE_CAPTURE = 1; + ImageView mImageView; + Button mButton; + TextView mTextView; + String mCurrentPhotoPath; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + mImageView = this.findViewById(R.id.img1); + mTextView = this.findViewById(R.id.textView); + mButton = this.findViewById(R.id.button); + } + + public void takePicture(View view) { + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + // Ensure that there's a camera activity to handle the intent + if (takePictureIntent.resolveActivity(getPackageManager()) != null) { + // Create the File where the photo should go + File photoFile = null; + try { + photoFile = createImageFile(); + } catch (IOException ex) { + // Error occured while creating the File + } + // Continue only if the File was successfully created + if (photoFile != null) { + Uri photoUri = FileProvider.getUriForFile(this, + "com.example.android.fileprovider", + photoFile); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); + startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); + } + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { + File file = new File(mCurrentPhotoPath); + Bitmap imageBitmap = null; + try { + imageBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), Uri.fromFile(file)); + } catch (IOException e) { + e.printStackTrace(); + } + + mImageView.setImageBitmap(imageBitmap); + + String decision = makeDecision(); + mTextView.setText(decision); + mTextView.setVisibility(View.VISIBLE); + if (decision == "Cat!") { + mTextView.setTextColor(GREEN); + } + else { + mTextView.setTextColor(RED); + } + + mButton.setText("Take another picture!"); + + // Delete the cached image + file.delete(); + } + } + + // Create temporary image file to provide picture in high quality + private File createImageFile() throws IOException { + // Create an image file name + String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); + String imageFileName = "JPEG_" + timeStamp + "_"; + File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); + File image = File.createTempFile( + imageFileName, /* prefix */ + ".jpg", /* suffix */ + storageDir /* directory */ + ); + + // Save a file: path for use with ACTION_VIEW intents + mCurrentPhotoPath = image.getAbsolutePath(); + return image; + } + + // Randomly choose if cat or not + private String makeDecision() { + Random r = new Random(); + int flip = r.nextInt(2); + if (flip == 0) + return "Cat!"; + else + return "Not!"; + } +} diff --git a/app/src/main/res/drawable-hdpi/cat.png b/app/src/main/res/drawable-hdpi/cat.png new file mode 100644 index 0000000..bd32e2a Binary files /dev/null and b/app/src/main/res/drawable-hdpi/cat.png differ diff --git a/app/src/main/res/drawable-mdpi/cat.png b/app/src/main/res/drawable-mdpi/cat.png new file mode 100644 index 0000000..bd32e2a Binary files /dev/null and b/app/src/main/res/drawable-mdpi/cat.png differ diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable-xhdpi/cat.png b/app/src/main/res/drawable-xhdpi/cat.png new file mode 100644 index 0000000..bd32e2a Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/cat.png differ diff --git a/app/src/main/res/drawable-xxhdpi/cat.png b/app/src/main/res/drawable-xxhdpi/cat.png new file mode 100644 index 0000000..bd32e2a Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/cat.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/cat.png b/app/src/main/res/drawable-xxxhdpi/cat.png new file mode 100644 index 0000000..bd32e2a Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/cat.png differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..efc1382 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,91 @@ + + + + + +