/*
* Copyright (c) 2012 Daniel Huckaby
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.handlerexploit.prime.drawable;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.StateListDrawable;
import com.handlerexploit.prime.utils.ImageManager;
/**
* This is a very expensive way to create a StateListDrawable from a remote
* image set. <b>I do not recommend this ever</b>. Although, if you have to do
* it then this is going to be the best way to do it.</br></br> The basic api
* for adding a remote image is
* {@link RemoteStateListDrawable#addRemoteState(int[], String)}.
*/
public class RemoteStateListDrawable extends StateListDrawable {
private ImageManager mImageManager;
public RemoteStateListDrawable(Context context) {
mImageManager = ImageManager.getInstance(context);
}
/**
* Add a new image/string ID to the set of images.
*
* </br></br>Make sure to call this off the UI Thread, because it is
* synchronously receiving the image.
*
* @param stateSet
* An array of resource Ids to associate with the image. Switch
* to this image by calling setState().
* @param source
* The URL of a remote image
*/
public void addRemoteState(int[] stateSet, String source) {
addState(stateSet, new BitmapDrawable(mImageManager.get(source)));
}
}