List of usage examples for android.widget ViewSwitcher setVisibility
@RemotableViewMethod public void setVisibility(@Visibility int visibility)
From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java
@SuppressLint("NewApi") private static View createMessageDialogContentsView(Activity activity, MessageDescription messageDescription) { Context context = activity;/*from w ww . j a v a2 s . c om*/ final AlertDialog.Builder builder; // Workaround for dialog theme problems if (android.os.Build.VERSION.SDK_INT > 10) { builder = new AlertDialog.Builder(context); context = builder.getContext(); } else { context = new ContextThemeWrapper(context, android.R.style.Theme_Dialog); builder = new AlertDialog.Builder(context); } builder.setTitle("Send feedback"); final LayoutInflater inflater = LayoutInflater.from(context); final View dialogContentsView = inflater.inflate(R.layout.updater_dialog_message, null, false); final TextView textView = (TextView) dialogContentsView.findViewById(R.id.dialog_update_message_text); final ImageView imageView = (ImageView) dialogContentsView.findViewById(R.id.dialog_update_message_image); final ViewSwitcher switcher = (ViewSwitcher) dialogContentsView .findViewById(R.id.dialog_update_message_switcher); String messageText = null; String imageUrl = null; if (messageDescription != null) { messageText = messageDescription.get(MessageDescription.KEY_MESSAGE); imageUrl = messageDescription.get(MessageDescription.KEY_IMAGE_URL); } if (Utilities.isNullOrEmpty(messageText)) { textView.setVisibility(View.GONE); } else { textView.setText(messageText); } if (Utilities.isNullOrEmpty(imageUrl)) { switcher.setVisibility(View.GONE); } else { URI uri; try { uri = new URI(imageUrl); } catch (URISyntaxException e) { uri = null; } if (uri != null) { DownloadRequest request = new DownloadRequest(); request.setUri(uri); request.setDownloadHandler(new DownloadHandler() { @Override public void onSuccess(byte[] result) { // Load image from byte array final Bitmap bitmap = BitmapFactory.decodeByteArray(result, 0, result.length); imageView.setImageBitmap(bitmap); // Hide progress bar and display image if (switcher != null) { switcher.setDisplayedChild(1); } } @Override public void onProgress(Integer percent) { } @Override public void onFail(Exception ex) { Log.e("Message image couldn't be loaded", ex); } @Override public void onCancelled() { } }); HttpClient client = Utilities.createClient("Turkcell Updater/1.0 ", false); try { request.executeAsync(client); } catch (Exception e) { Log.e("Message image couldn't be loaded", e); } } else { switcher.setVisibility(View.GONE); } } return dialogContentsView; }