@Override public void onStateChange(UrlImageView v, UrlImageView.State newState, String url) { if (newState.isLoaded()) { TextView lFontName = (TextView) v.getTag(R.id.TAG_fontName); lFontName.setVisibility(View.GONE); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { View res = convertView != null ? convertView : getLayoutInflater().inflate(R.layout.item_font_download, null); UrlImageView imgPreview = V.get(res, R.id.imgPreview); TextView lFontName = V.get(res, R.id.lFontName); View bDownload = V.get(res, R.id.bDownload); View bDelete = V.get(res, R.id.bDelete); ProgressBar progressbar = V.get(res, R.id.progressbar); TextView lErrorMsg = V.get(res, R.id.lErrorMsg); FontItem item = getItem(position); String dlkey = getFontDownloadKey(item.name); lFontName.setText(item.name); lFontName.setVisibility(View.VISIBLE); imgPreview.setTag(R.id.TAG_fontName, lFontName); imgPreview.setOnStateChangeListener(imgPreview_stateChange); imgPreview.setUrl(String.format(URL_fontPreview, item.name)); bDownload.setTag(R.id.TAG_fontItem, item); bDownload.setOnClickListener(bDownload_click); bDelete.setTag(R.id.TAG_fontItem, item); bDelete.setOnClickListener(bDelete_click); if (FontManager.isInstalled(item.name)) { progressbar.setIndeterminate(false); progressbar.setMax(100); progressbar.setProgress(100); bDownload.setVisibility(View.GONE); bDelete.setVisibility(View.VISIBLE); lErrorMsg.setVisibility(View.GONE); } else { DownloadEntry entry = dls.getEntry(dlkey); if (entry == null) { progressbar.setIndeterminate(false); progressbar.setMax(100); progressbar.setProgress(0); bDownload.setVisibility(View.VISIBLE); bDownload.setEnabled(true); bDelete.setVisibility(View.GONE); lErrorMsg.setVisibility(View.GONE); } else { if (entry.state == DownloadService.State.created) { progressbar.setIndeterminate(true); bDownload.setVisibility(View.VISIBLE); bDownload.setEnabled(false); bDelete.setVisibility(View.GONE); lErrorMsg.setVisibility(View.GONE); } else if (entry.state == DownloadService.State.downloading) { if (entry.length == -1) { progressbar.setIndeterminate(true); } else { progressbar.setIndeterminate(false); progressbar.setMax((int) entry.length); progressbar.setProgress((int) entry.progress); } bDownload.setVisibility(View.VISIBLE); bDownload.setEnabled(false); bDelete.setVisibility(View.GONE); lErrorMsg.setVisibility(View.GONE); } else if (entry.state == DownloadService.State.finished) { progressbar.setIndeterminate(false); progressbar.setMax(100); // consider full progressbar.setProgress(100); // consider full bDownload.setVisibility(View.GONE); bDelete.setVisibility(View.VISIBLE); lErrorMsg.setVisibility(View.GONE); } else if (entry.state == DownloadService.State.failed) { progressbar.setIndeterminate(false); progressbar.setMax(100); progressbar.setProgress(0); bDownload.setVisibility(View.VISIBLE); bDownload.setEnabled(true); bDelete.setVisibility(View.GONE); lErrorMsg.setVisibility(View.VISIBLE); lErrorMsg.setText(entry.errorMsg); } } } return res; }