/** * Method that returns a drawable reference of a FileSystemObject. * * @param iconView View to load the drawable into * @param fso The FileSystemObject reference * @param defaultIcon Drawable to be used in case no specific one could be found * @return Drawable The drawable reference */ public void loadDrawable(ImageView iconView, final String fso, Drawable defaultIcon) { if (!mUseThumbs) { return; } // Is cached? final String filePath = fso; if (this.mAppIcons.containsKey(filePath)) { iconView.setImageBitmap(this.mAppIcons.get(filePath)); return; } mRequests.put(iconView, fso); new Thread( new Runnable() { @Override public void run() { mHandler.removeMessages(MSG_DESTROY); if (mWorkerThread == null || mWorkerHandler == null) { mWorkerThread = new HandlerThread("IconHolderLoader"); mWorkerThread.start(); mWorkerHandler = new WorkerHandler(mWorkerThread.getLooper()); } Message msg = mWorkerHandler.obtainMessage(MSG_LOAD, fso); msg.sendToTarget(); } }) .start(); }
private void processResult(LoadResult result) { // Cache the new drawable final String filePath = (result.fso); mAppIcons.put(filePath, result.result); // find the request for it for (Map.Entry<ImageView, String> entry : mRequests.entrySet()) { final ImageView imageView = entry.getKey(); final String fso = entry.getValue(); if (fso == result.fso) { imageView.setImageBitmap(result.result); mRequests.remove(imageView); break; } } }
@Override public void onTick(long millisUntilFinished) { switch (iconCount) { case 0: drawable = getResources().getDrawable(R.drawable.loading); break; case 1: drawable = getResources().getDrawable(R.drawable.loading_1); break; case 2: drawable = getResources().getDrawable(R.drawable.loading_2); break; case 3: drawable = getResources().getDrawable(R.drawable.loading_3); break; case 4: drawable = getResources().getDrawable(R.drawable.loading_4); break; case 5: drawable = getResources().getDrawable(R.drawable.loading_5); break; case 6: drawable = getResources().getDrawable(R.drawable.loading_6); break; } iconCount++; loadingIconLayout.setImageDrawable(drawable); }