Skip to content

Commit 7dec652

Browse files
author
Vincent Gachet
committed
Version 1.0.26
0 parents  commit 7dec652

File tree

87 files changed

+4478
-0
lines changed

Some content is hidden

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

87 files changed

+4478
-0
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#built application files
2+
*.apk
3+
*.ap_
4+
5+
# files for the dex VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# generated files
12+
bin/
13+
gen/
14+
15+
# Local configuration file (sdk path, etc)
16+
local.properties
17+
18+
# Windows thumbnail db
19+
Thumbs.db
20+
21+
# OSX files
22+
.DS_Store
23+
24+
# Eclipse project files
25+
.classpath
26+
.project
27+
28+
# Android Studio
29+
*.iml
30+
.idea
31+
.gradle
32+
build/
33+
34+
import-summary.txt

README.md

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
# SMAAssetManager
2+
3+
This library is linked to the following dependencies :
4+
5+
:::javascript
6+
compile 'fr.smartapps.smartguide:downloader_library:0.3.1'
7+
compile 'fr.smartapps.smartguide:googleplayservices_lib:0.3.1'
8+
compile 'fr.smartapps.smartguide:play_licensing:0.3.1'
9+
compile 'fr.smartapps.smartguide:zip_file:0.3.1'
10+
compile 'commons-io:commons-io:2.4'
11+
compile 'com.github.bumptech.glide:glide:3.7.0'
12+
13+
This library has been created to help you manage easily every image, audio, video, ... from any places :
14+
15+
- to get assets from assets folder : "assets://filename.png"
16+
- to get assets from expansion file : "obb://filename.png"
17+
- to get assets from external public phone directory : "external://filename.png"
18+
- to get assets from external private phone directory : "external_private://filename.png"
19+
20+
To use OBB you must have those permissions in your manifest :
21+
22+
:::xml
23+
<!-- OBB PERMISSION -->
24+
<uses-permission android:name="com.android.vending.CHECK_LICENSE"/>
25+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
26+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
27+
<uses-permission android:name="android.permission.INTERNET"/>
28+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
29+
<uses-permission android:name="android.permission.WAKE_LOCK"/>
30+
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
31+
32+
If you don't use OBB, you need this permission to write and read in external storage :
33+
34+
:::xml
35+
<!-- EXTERNAL STORAGE PERMISSION -->
36+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
37+
38+
# Import
39+
40+
:::javascript
41+
// project gradle
42+
allprojects {
43+
repositories {
44+
jcenter()
45+
maven { url 'https://dl.bintray.com/smartapps/maven' }
46+
}
47+
}
48+
49+
// module gradle
50+
compile 'fr.smartapps.library:lib_smaassetmanager:1.0.16'
51+
52+
# Implement
53+
54+
## Initialize
55+
56+
Initialize **SMAAssetManager** first
57+
58+
assetManager = new SMAAssetManager(this);
59+
60+
If you wanna use Expansion file (APK over 100MB), you have to configure it with :
61+
62+
assetManager.initMainOBB(version, size);
63+
64+
If no suffix has been set, you can set a default folder where you will take every file (if none of these line are set, assets folder is the default one) :
65+
66+
:::java
67+
assetManager.setDefaultStorageType(SMAAssetManager.STORAGE_TYPE_ASSETS);
68+
// or
69+
assetManager.setDefaultStorageType(SMAAssetManager.STORAGE_TYPE_OBB);
70+
// or
71+
assetManager.setDefaultStorageType(SMAAssetManager.STORAGE_TYPE_EXTERNAL);
72+
// or
73+
assetManager.setDefaultStorageType(SMAAssetManager.STORAGE_TYPE_EXTERNAL_PRIVATE);
74+
75+
// by default when you are searching file depending on DEFAULT_STORAGE : it will add this extension right before your file name
76+
assetManager.setExtensionDirectory("package_name/");
77+
78+
## Drawable
79+
80+
![](/screen_drawable.png)
81+
82+
:::java
83+
imageView1.setBackground(assetManager.getDrawable("obb://pikachu.png"));
84+
imageView2.setBackground(assetManager.getDrawable("external_private://pikachu.png"));
85+
imageView3.setBackground(assetManager.getDrawable("external://pikachu.png"));
86+
87+
## Custom drawable
88+
89+
![Alt text](/screen_image.png)
90+
91+
:::java
92+
imageView1.setBackground(assetManager.getDrawable("assets://tinder.png"));
93+
imageView2.setBackground(assetManager.getDrawable("assets://tinder.png").filter("#000000"));
94+
imageView3.setBackground(assetManager.getDrawable("assets://tinder.png").alpha(100));
95+
96+
## Button
97+
98+
![Alt text](/screen_button.png)
99+
100+
:::java
101+
buttonView.setBackground(assetManager.getStateListDrawable()
102+
.focused("assets://tinder_selected.png")
103+
.pressed("assets://tinder_selected.png")
104+
.inverse("assets://tinder.png"));
105+
106+
// always finish with inverse state : it is the default state
107+
108+
toggleButtonView.setBackground(assetManager.getStateListDrawable()
109+
.checked("assets://tinder_selected.png")
110+
.inverse("assets://tinder.png"));
111+
112+
// known bug : you cannot put modified drawable (drawable.filter(), drawable.alpha(), ...) in StateListDrawable before Lollipop
113+
114+
## TextView
115+
116+
![Alt text](/screen_textview.png)
117+
118+
:::java
119+
textView1.setTypeface(assetManager.getTypeFace("assets://font_assets.ttf"));
120+
textView2.setTypeface(assetManager.getTypeFace("external://font_external.ttf"));
121+
textView3.setTypeface(assetManager.getTypeFace("external_private://font_external_private.ttf"));
122+
textView4.setTypeface(assetManager.getTypeFace("obb://font_obb.ttf"));
123+
textView5.setTextColor(assetManager.getStateListColor().focused("#abcdef").pressed("#abcdef").inverse("#abcabc"));
124+
125+
## Audio
126+
127+
![Alt text](/screen_audio.png)
128+
129+
:::java
130+
SMAAudioPlayer audioPlayer = assetManager.getAudioPlayer(url, new SMAAudioPlayerListener() {
131+
@Override
132+
public void onSongProgress(int progress, int totalProgress) {
133+
// callback as long as the song is playing
134+
}
135+
136+
@Override
137+
public void onSongFinish(int totalProgress) {
138+
// callback when the song is finished
139+
}
140+
});
141+
142+
Also customize your SeekBar :
143+
144+
:::java
145+
seekBar.setProgressDrawable(assetManager.getLayerDrawable()
146+
.backgroundProgressColor("#cccccc")
147+
.progressColor("#abcdef")
148+
.getLayer());
149+
SMADrawable thumb = assetManager.getDrawable("assets://scrubber_control.png").filter("#abcdef").density(5);
150+
seekBar.setThumb(thumb);
151+
152+
## Webview
153+
154+
Load web content from url path :
155+
156+
:::java
157+
SMAWebView webView = (SMAWebView) findViewById(R.id.webview);
158+
assetManager.setDefaultStorageType(SMAAssetManager.STORAGE_TYPE_ASSETS);
159+
webView.loadPath("html/index.html", assetManager, new SMAWebViewListener() {
160+
@Override
161+
public void onUrlLoadProgress(int progress, int totalProgress) {
162+
// only use when loading from http url. SMAWebview starts invisible
163+
// and became progressively visible when web content are loaded
164+
}
165+
166+
@Override
167+
public void onUrlCall(String url) {
168+
// callback called everytime your content redirect to another url
169+
}
170+
});
171+
172+
Load content from template & base directory :
173+
174+
:::java
175+
// baseDirectory is a folder inside "default storage" and then inside "extension directory"
176+
// templateHTML is a full html string
177+
webview.loadTemplate(baseDirectory, templateHTML, assetManager, webViewListener);
178+
// or
179+
webview.loadTemplate(templateHTML, assetManager, webViewListener);
180+
181+
## NEW ! Asynchronous loading with glide (recommended by Google)
182+
183+
![](/glide.gif)
184+
185+
:::java
186+
ImageView imageAssets = (ImageView) findViewById(R.id.image_1);
187+
Glide.with(this).load(new SMAFile("assets://pikachu.png", assetManager)).into(imageAssets);
188+
189+
ImageView imageExternal = (ImageView) findViewById(R.id.image_2);
190+
Glide.with(this).load(new SMAFile("external_private://pikachu.png", assetManager)).into(imageExternal);
191+
192+
ImageView imageExternalPrivate = (ImageView) findViewById(R.id.image_3);
193+
Glide.with(this).load(new SMAFile("external://pikachu.png", assetManager)).into(imageExternalPrivate);
194+
195+
ImageView imageOBB = (ImageView) findViewById(R.id.image_4);
196+
Glide.with(this).load(new SMAFile("obb://pikachu.png", assetManager)).into(imageOBB);
197+
198+
## Find much more power in the sample !
199+
200+
## TODO
201+
202+
* Gérer téléchargement OBB depuis le store si non présent
203+
* Gérer OutOfMemoryError, drawable vs bitmap

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 24
5+
buildToolsVersion "24.0.1"
6+
7+
defaultConfig {
8+
applicationId "fr.smartapps.smaassetmanager"
9+
minSdkVersion 16
10+
targetSdkVersion 22
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile 'com.android.support:appcompat-v7:24.+'
24+
compile project(':lib_smaassetmanager')
25+
compile 'com.android.support:percent:24.+'
26+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/vincentchann/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

app/src/main/AndroidManifest.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="fr.smartapps.smaassetmanager">
4+
5+
6+
<!-- OBB PERMISSION -->
7+
<uses-permission android:name="com.android.vending.CHECK_LICENSE"/>
8+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
9+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
10+
<uses-permission android:name="android.permission.INTERNET"/>
11+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
12+
<uses-permission android:name="android.permission.WAKE_LOCK"/>
13+
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
14+
15+
<application
16+
android:allowBackup="true"
17+
android:icon="@mipmap/ic_launcher"
18+
android:label="@string/app_name"
19+
android:supportsRtl="true"
20+
android:theme="@style/AppTheme">
21+
22+
<activity android:name=".MainActivity">
23+
<intent-filter>
24+
<action android:name="android.intent.action.MAIN" />
25+
<category android:name="android.intent.category.LAUNCHER" />
26+
</intent-filter>
27+
</activity>
28+
29+
<activity android:name=".AudioActivity"/>
30+
<activity android:name=".ImageActivity"/>
31+
<activity android:name=".DrawableActivity"/>
32+
<activity android:name=".ButtonActivity"/>
33+
<activity android:name=".TextActivity"/>
34+
<activity android:name=".WebActivity"/>
35+
<activity android:name=".GlideActivity"/>
36+
37+
</application>
38+
39+
</manifest>

app/src/main/assets/font_assets.ttf

15.9 KB
Binary file not shown.

app/src/main/assets/font_external.ttf

49.2 KB
Binary file not shown.
40.1 KB
Binary file not shown.

app/src/main/assets/font_obb.ttf

39.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)