Reputation: 363
I have an app that should deploy for few different costumers. For each costumer I want to allow different coloring and resources.
Are there any ways to enable the app to load resources and configurations from the internet on startup, and then using them on the app.
I know I can use Google Tag Manager for loading configuration values from the internet. Is there some platform I can use for doing something similar for Drawable resources?
Upvotes: 2
Views: 227
Reputation: 2691
You'll need to download the remote resources to the SD card. Then you can create drawables on the fly with:
Drawable d = Drawable.createFromPath(new File(Environment.getExternalStorageDirectory(), "yourDownloadedBackground.png").getAbsolutePath());
and then set the layout background with setBackGroundDrawable() or setBackGround(), the latter only if you're targetting API 16 or more.
The other way, is to put webviews instead of the images in your layout. This will allow you to load remote images, local files and HTML snippets. Put a webview in your layout and try this:
android.webkit.WebView v = (android.webkit.WebView) findViewById(R.id.webView1);
v.loadUrl("http://developer.android.com/assets/images/dac_logo.png");
Upvotes: 2
Reputation: 372
Consider the implications of this: if you start this application on a non-internet connected device, it will still need a local cache of drawables. If your customers want a tight user experience, do you really want to be dependent upon a remote source to load the UI of your application?
Perhaps your best (though less extensible) solution would be to create multiple APKs, one for each customer. For "a few different customers", this is probably simpler than hosting UI components. For large numbers of customers, then you might start thinking about more creative solutions.
EDIT: please take a look at this answer for some productive ideas on how to efficiently manage multiple packages.
Upvotes: 0
Reputation: 1549
You can use color filters, see this Modifying the color of an android drawable http://blog.syedgakbar.com/2012/07/changing-color-of-the-drawable-or-imageview-at-runtime-in-android/
int color=Color.rgb(colorR, colorG, colorB);
public static BitmapDrawable changeColor(Bitmap bitmap, Context context, int color){
Bitmap bitmapCopy = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas c = new Canvas(bitmapCopy);
Paint p = new Paint();
p.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
c.drawBitmap(bitmap, 0, 0, p);
return new BitmapDrawable(context.getResources(),bitmapCopy);
}
Just be sure thats the filter you want
Upvotes: 0