Skip to content

Instantly share code, notes, and snippets.

Avatar

Flavius Popescu FlaviusPopescu

View GitHub Profile
View FrameAnimationView.java
/**
* A helper view class useful in playing animation in a more memory efficient way, since Bitmaps
* are preloaded on a background handlerThread and reused, while the main thread "plays" the frames.
* To specify which animation frames should be played you need to provide an implementation of
* FramesDataSource.
*/
public class FrameAnimationView extends FrameLayout {
private static final String TAG = FrameAnimationView.class.getSimpleName();
private final ImageView imageView;
private final Handler animationHandler;
@FlaviusPopescu
FlaviusPopescu / ImageUtil.java
Created Apr 28, 2016
Internet and Background Threads
View ImageUtil.java
public class ImageUtil {
private static final String TAG = "ImageUtil";
public static Bitmap getImage(String urlSpec) {
Bitmap result = null;
try {
byte[] posterBytes = getBytes(urlSpec);
result = BitmapFactory.decodeByteArray(posterBytes, 0, posterBytes.length);
} catch (IOException e) {
Log.e(TAG, "getImage: ", e);
@FlaviusPopescu
FlaviusPopescu / MainActivity.java
Created Apr 28, 2016
Internet and Background Tasks
View MainActivity.java
public class MainActivity extends AppCompatActivity {
final String IMAGE_URL = "https://pixabay.com/static/uploads/photo/2014/12/22/00/05/spindle-576757_960_720.png";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView imageView = (ImageView) findViewById(R.id.headerimage);
new ImageDownloaderTask(new ImageDownloaderTask.OnImageDownloadedListener() {
@FlaviusPopescu
FlaviusPopescu / ImageDownloaderTask.java
Last active Apr 28, 2016
Internet and Background Threads
View ImageDownloaderTask.java
public class ImageDownloaderTask extends AsyncTask<String, Void, Bitmap> {
private static final String TAG = "ImageDownloaderTask";
private final OnImageDownloadedListener mListener;
public ImageDownloaderTask(OnImageDownloadedListener listener) {
mListener = listener;
}
@Override
protected Bitmap doInBackground(String... params) {
You can’t perform that action at this time.