Skip to content

Commit cf4bac1

Browse files
authored
Merge pull request #201 from Channingss/android_clc
add lite/android sdk&demo
2 parents 92d9a59 + f8ba640 commit cf4bac1

File tree

60 files changed

+3710
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3710
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import java.security.MessageDigest
2+
3+
apply plugin: 'com.android.application'
4+
5+
android {
6+
compileSdkVersion 28
7+
defaultConfig {
8+
applicationId "com.baidu.paddlex.lite.demo"
9+
minSdkVersion 15
10+
targetSdkVersion 28
11+
versionCode 1
12+
versionName "1.0"
13+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
implementation fileTree(include: ['*.aar'], dir: 'libs')
25+
implementation 'com.android.support:appcompat-v7:28.0.0'
26+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
27+
implementation 'com.android.support:design:28.0.0'
28+
testImplementation 'junit:junit:4.12'
29+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
30+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
31+
}
32+
33+
34+
def paddlexAndroidSdk = 'https://bj.bcebos.com/paddlex/deploy/lite/paddlex_lite_11cbd50e.tar.gz'
35+
36+
task downloadAndExtractPaddleXAndroidSdk(type: DefaultTask) {
37+
doFirst {
38+
println "Downloading and extracting PaddleX Android SDK"}
39+
doLast {
40+
// Prepare cache folder for sdk
41+
if (!file("cache").exists()) {
42+
mkdir "cache"
43+
}
44+
// Generate cache name for sdk
45+
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
46+
messageDigest.update(paddlexAndroidSdk.bytes)
47+
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
48+
// Download sdk
49+
if (!file("cache/${cacheName}.tar.gz").exists()) {
50+
ant.get(src: paddlexAndroidSdk, dest: file("cache/${cacheName}.tar.gz"))
51+
}
52+
// Unpack sdk
53+
copy {
54+
from tarTree("cache/${cacheName}.tar.gz")
55+
into "cache/${cacheName}"
56+
}
57+
// Copy sdk
58+
if (!file("libs/paddlex.aar").exists()) {
59+
copy {
60+
from "cache/${cacheName}/paddlex.aar"
61+
into "libs"
62+
}
63+
}
64+
}
65+
}
66+
67+
preBuild.dependsOn downloadAndExtractPaddleXAndroidSdk
68+
69+
def paddleXLiteModel = 'https://bj.bcebos.com/paddlex/deploy/lite/mobilenetv2_imagenet_lite2.6.1.tar.gz'
70+
task downloadAndExtractPaddleXLiteModel(type: DefaultTask) {
71+
doFirst {
72+
println "Downloading and extracting PaddleX Android SDK"}
73+
74+
doLast {
75+
// Prepare cache folder for model
76+
if (!file("cache").exists()) {
77+
mkdir "cache"
78+
}
79+
// Generate cache name for model
80+
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
81+
messageDigest.update(paddleXLiteModel.bytes)
82+
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
83+
// Download sdk
84+
if (!file("cache/${cacheName}.tar.gz").exists()) {
85+
ant.get(src: paddleXLiteModel, dest: file("cache/${cacheName}.tar.gz"))
86+
}
87+
88+
// Unpack model
89+
copy {
90+
from tarTree("cache/${cacheName}.tar.gz")
91+
into "cache/${cacheName}"
92+
}
93+
94+
// Copy model.nb
95+
if (!file("src/main/assets/model/model.nb").exists()) {
96+
copy {
97+
from "cache/${cacheName}/model.nb"
98+
into "src/main/assets/model/"
99+
}
100+
}
101+
// Copy config file model.yml
102+
if (!file("src/main/assets/config/model.yml").exists()) {
103+
copy {
104+
from "cache/${cacheName}/model.yml"
105+
into "src/main/assets/config/"
106+
}
107+
}
108+
// Copy config file model.yml
109+
if (!file("src/main/assets/images/test.jpg").exists()) {
110+
copy {
111+
from "cache/${cacheName}/test.jpg"
112+
into "src/main/assets/images/"
113+
}
114+
}
115+
}
116+
117+
}
118+
119+
preBuild.dependsOn downloadAndExtractPaddleXLiteModel
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baidu.paddlex.lite.demo;
2+
3+
import android.content.Context;
4+
import android.content.res.AssetManager;
5+
import android.support.test.InstrumentationRegistry;
6+
import android.support.test.runner.AndroidJUnit4;
7+
8+
import com.baidu.paddlex.config.ConfigParser;
9+
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
13+
import java.io.IOException;
14+
import java.io.InputStream;
15+
16+
import static org.junit.Assert.assertEquals;
17+
18+
/**
19+
* Instrumented test, which will execute on an Android device.
20+
*
21+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
22+
*/
23+
@RunWith(AndroidJUnit4.class)
24+
public class ExampleInstrumentedTest {
25+
@Test
26+
public void useAppContext() throws IOException {
27+
// Context of the app under test.
28+
Context appContext = InstrumentationRegistry.getTargetContext();
29+
AssetManager ass = appContext.getAssets();
30+
assertEquals("com.baidu.paddlex.lite.demo", appContext.getPackageName());
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.baidu.paddlex.lite.demo">
4+
5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
6+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
7+
<uses-permission android:name="android.permission.CAMERA" />
8+
9+
<application
10+
android:allowBackup="true"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:largeHeap="true"
16+
android:theme="@style/AppTheme">
17+
<activity android:name="com.baidu.paddlex.lite.demo.MainActivity">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
<activity
24+
android:name="com.baidu.paddlex.lite.demo.SettingsActivity"
25+
android:label="Settings"></activity>
26+
</application>
27+
28+
</manifest>
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.baidu.paddlex.lite.demo;
16+
17+
import android.content.res.Configuration;
18+
import android.os.Bundle;
19+
import android.preference.PreferenceActivity;
20+
import android.support.annotation.LayoutRes;
21+
import android.support.annotation.Nullable;
22+
import android.support.v7.app.ActionBar;
23+
import android.support.v7.app.AppCompatDelegate;
24+
import android.support.v7.widget.Toolbar;
25+
import android.view.MenuInflater;
26+
import android.view.View;
27+
import android.view.ViewGroup;
28+
29+
/**
30+
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
31+
* to be used with AppCompat.
32+
* <p>
33+
* This technique can be used with an {@link android.app.Activity} class, not just
34+
* {@link android.preference.PreferenceActivity}.
35+
*/
36+
37+
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
38+
private AppCompatDelegate mDelegate;
39+
40+
@Override
41+
protected void onCreate(Bundle savedInstanceState) {
42+
getDelegate().installViewFactory();
43+
getDelegate().onCreate(savedInstanceState);
44+
super.onCreate(savedInstanceState);
45+
}
46+
47+
@Override
48+
protected void onPostCreate(Bundle savedInstanceState) {
49+
super.onPostCreate(savedInstanceState);
50+
getDelegate().onPostCreate(savedInstanceState);
51+
}
52+
53+
public ActionBar getSupportActionBar() {
54+
return getDelegate().getSupportActionBar();
55+
}
56+
57+
public void setSupportActionBar(@Nullable Toolbar toolbar) {
58+
getDelegate().setSupportActionBar(toolbar);
59+
}
60+
61+
@Override
62+
public MenuInflater getMenuInflater() {
63+
return getDelegate().getMenuInflater();
64+
}
65+
66+
@Override
67+
public void setContentView(@LayoutRes int layoutResID) {
68+
getDelegate().setContentView(layoutResID);
69+
}
70+
71+
@Override
72+
public void setContentView(View view) {
73+
getDelegate().setContentView(view);
74+
}
75+
76+
@Override
77+
public void setContentView(View view, ViewGroup.LayoutParams params) {
78+
getDelegate().setContentView(view, params);
79+
}
80+
81+
@Override
82+
public void addContentView(View view, ViewGroup.LayoutParams params) {
83+
getDelegate().addContentView(view, params);
84+
}
85+
86+
@Override
87+
protected void onPostResume() {
88+
super.onPostResume();
89+
getDelegate().onPostResume();
90+
}
91+
92+
@Override
93+
protected void onTitleChanged(CharSequence title, int color) {
94+
super.onTitleChanged(title, color);
95+
getDelegate().setTitle(title);
96+
}
97+
98+
@Override
99+
public void onConfigurationChanged(Configuration newConfig) {
100+
super.onConfigurationChanged(newConfig);
101+
getDelegate().onConfigurationChanged(newConfig);
102+
}
103+
104+
@Override
105+
protected void onStop() {
106+
super.onStop();
107+
getDelegate().onStop();
108+
}
109+
110+
@Override
111+
protected void onDestroy() {
112+
super.onDestroy();
113+
getDelegate().onDestroy();
114+
}
115+
116+
public void invalidateOptionsMenu() {
117+
getDelegate().invalidateOptionsMenu();
118+
}
119+
120+
private AppCompatDelegate getDelegate() {
121+
if (mDelegate == null) {
122+
mDelegate = AppCompatDelegate.create(this, null);
123+
}
124+
return mDelegate;
125+
}
126+
}

0 commit comments

Comments
 (0)