|
| 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 | + |
| 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 | + |
| 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 | + |
| 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 | + |
| 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 | + |
| 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 | + |
| 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 |
0 commit comments