forked from pytorch/android-demo-app
-
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
5b9777a
commit d9ca4b1
Showing
101 changed files
with
3,747 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,7 @@ | ||
.DS_Store | ||
local.properties | ||
**/*.iml | ||
.gradle | ||
.idea/ | ||
.externalNativeBuild | ||
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,7 @@ | ||
.DS_Store | ||
local.properties | ||
**/*.iml | ||
.gradle | ||
.idea/ | ||
.externalNativeBuild | ||
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 @@ | ||
/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,39 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
repositories { | ||
maven { | ||
url "https://oss.sonatype.org/content/repositories/snapshots" | ||
} | ||
} | ||
|
||
android { | ||
compileOptions { | ||
sourceCompatibility 1.8 | ||
targetCompatibility 1.8 | ||
} | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "org.pytorch.demo" | ||
minSdkVersion 21 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'androidx.appcompat:appcompat:1.0.0-beta01' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
implementation "androidx.camera:camera-core:1.0.0-alpha05" | ||
implementation 'com.google.android.material:material:1.0.0-beta01' | ||
|
||
implementation 'org.pytorch:pytorch_android:0.0.8-SNAPSHOT' | ||
implementation 'org.pytorch:pytorch_android_torchvision:0.0.8-SNAPSHOT' | ||
} |
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" | ||
package="org.pytorch.demo"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme.NoActionBar"> | ||
<activity | ||
android:name=".WelcomeActivity" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity android:name=".MainActivity"></activity> | ||
<activity android:name=".vision.VisionListActivity" /> | ||
<activity android:name=".nlp.NLPListActivity" /> | ||
<activity | ||
android:name=".vision.ImageClassificationActivity" | ||
android:label="@string/image_classification_title"></activity> | ||
<activity android:name=".nlp.TextClassificationActivity" /> | ||
|
||
</application> | ||
|
||
<uses-permission android:name="android.permission.CAMERA" /> | ||
|
||
</manifest> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions
23
PyTorchDemoApp/app/src/main/java/org/pytorch/demo/AbstractListActivity.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,23 @@ | ||
package org.pytorch.demo; | ||
|
||
import android.os.Bundle; | ||
import android.view.ViewStub; | ||
|
||
import androidx.annotation.LayoutRes; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
public abstract class AbstractListActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_list_stub); | ||
findViewById(R.id.list_back).setOnClickListener(v -> finish()); | ||
final ViewStub listContentStub = findViewById(R.id.list_content_stub); | ||
listContentStub.setLayoutResource(getListContentLayoutRes()); | ||
listContentStub.inflate(); | ||
} | ||
|
||
protected abstract @LayoutRes | ||
int getListContentLayoutRes(); | ||
} |
103 changes: 103 additions & 0 deletions
103
PyTorchDemoApp/app/src/main/java/org/pytorch/demo/BaseModuleActivity.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,103 @@ | ||
package org.pytorch.demo; | ||
|
||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.HandlerThread; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.annotation.UiThread; | ||
import androidx.appcompat.app.AlertDialog; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.appcompat.widget.Toolbar; | ||
|
||
public class BaseModuleActivity extends AppCompatActivity { | ||
private static final int UNSET = 0; | ||
|
||
protected HandlerThread mBackgroundThread; | ||
protected Handler mBackgroundHandler; | ||
protected Handler mUIHandler; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
mUIHandler = new Handler(getMainLooper()); | ||
} | ||
|
||
@Override | ||
protected void onPostCreate(@Nullable Bundle savedInstanceState) { | ||
super.onPostCreate(savedInstanceState); | ||
final Toolbar toolbar = findViewById(R.id.toolbar); | ||
if (toolbar != null) { | ||
setSupportActionBar(toolbar); | ||
} | ||
startBackgroundThread(); | ||
} | ||
|
||
protected void startBackgroundThread() { | ||
mBackgroundThread = new HandlerThread("ModuleActivity"); | ||
mBackgroundThread.start(); | ||
mBackgroundHandler = new Handler(mBackgroundThread.getLooper()); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
stopBackgroundThread(); | ||
super.onDestroy(); | ||
} | ||
|
||
protected void stopBackgroundThread() { | ||
mBackgroundThread.quitSafely(); | ||
try { | ||
mBackgroundThread.join(); | ||
mBackgroundThread = null; | ||
mBackgroundHandler = null; | ||
} catch (InterruptedException e) { | ||
Log.e(Constants.TAG, "Error on stopping background thread", e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.menu_model, menu); | ||
menu.findItem(R.id.action_info).setVisible(getInfoViewCode() != UNSET); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
if (item.getItemId() == R.id.action_info) { | ||
onMenuItemInfoSelected(); | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
protected int getInfoViewCode() { | ||
return UNSET; | ||
} | ||
|
||
protected String getInfoViewAdditionalText() { | ||
return null; | ||
} | ||
|
||
private void onMenuItemInfoSelected() { | ||
final AlertDialog.Builder builder = new AlertDialog.Builder(this) | ||
.setCancelable(true) | ||
.setView(InfoViewFactory.newInfoView(this, getInfoViewCode(), getInfoViewAdditionalText())); | ||
|
||
builder.show(); | ||
} | ||
|
||
@UiThread | ||
protected void showErrorDialog(View.OnClickListener clickListener) { | ||
final View view = InfoViewFactory.newErrorDialogView(this); | ||
view.setOnClickListener(clickListener); | ||
final AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.CustomDialog) | ||
.setCancelable(false) | ||
.setView(view); | ||
builder.show(); | ||
} | ||
} |
Oops, something went wrong.