List of usage examples for android.widget ImageView setImageResource
@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync") public void setImageResource(@DrawableRes int resId)
From source file:com.google.android.gcm.demo.ui.NetworkSchedulerFragment.java
@Override public void refresh() { FrameLayout tasksView = (FrameLayout) getActivity().findViewById(R.id.scheduler_tasks); // the view might have been destroyed, in which case we don't do anything if (tasksView != null) { float density = getActivity().getResources().getDisplayMetrics().density; SimpleArrayMap<String, TaskTracker> tasks = mTasks.getTasks(); LinearLayout tasksList = new LinearLayout(getActivity()); tasksList.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < tasks.size(); i++) { final TaskTracker task = tasks.valueAt(i); CardView taskCard = (CardView) getActivity().getLayoutInflater().inflate(R.layout.widget_task, tasksList, false);/*from www . j a v a2s. co m*/ ImageView taskIcon = (ImageView) taskCard.findViewById(R.id.task_icon); taskIcon.setImageResource(R.drawable.check_circle_grey600); taskIcon.setPadding(0, 0, (int) (8 * density), 0); TextView taskLabel = (TextView) taskCard.findViewById(R.id.task_title); TextView taskParams = (TextView) taskCard.findViewById(R.id.task_params); if (task.period == 0) { taskLabel.setText(getString(R.string.scheduler_oneoff, task.tag)); taskParams.setText(getString(R.string.scheduler_oneoff_params, task.windowStartElapsedSecs, task.windowStopElapsedSecs)); } else { taskLabel.setText(getString(R.string.scheduler_periodic, task.tag)); taskParams.setText(getString(R.string.scheduler_periodic_params, task.period, task.flex)); } TextView taskCreatedAt = (TextView) taskCard.findViewById(R.id.task_created_at); taskCreatedAt.setText(getString(R.string.scheduler_secs_ago, DateUtils .formatElapsedTime(SystemClock.elapsedRealtime() / 1000 - task.createdAtElapsedSecs))); TextView lastExecuted = (TextView) taskCard.findViewById(R.id.task_last_exec); if (task.executionTimes.isEmpty()) { lastExecuted.setText(getString(R.string.scheduler_na)); } else { long lastExecTime = task.executionTimes.get(task.executionTimes.size() - 1); lastExecuted.setText(getString(R.string.scheduler_secs_ago, DateUtils.formatElapsedTime(SystemClock.elapsedRealtime() / 1000 - lastExecTime))); } TextView state = (TextView) taskCard.findViewById(R.id.task_state); if (task.isCancelled()) { state.setText(getString(R.string.scheduler_cancelled)); } else if (task.isExecuted()) { state.setText(getString(R.string.scheduler_executed)); } else { state.setText(getString(R.string.scheduler_pending)); } Button cancel = (Button) taskCard.findViewById(R.id.task_cancel); cancel.setVisibility(View.VISIBLE); cancel.setText(R.string.scheduler_cancel); Button delete = (Button) taskCard.findViewById(R.id.task_delete); delete.setVisibility(View.VISIBLE); delete.setText(R.string.scheduler_delete); if (!task.isCancelled() && (!task.isExecuted() || task.period != 0)) { cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { cancelTask(task.tag); refresh(); } }); cancel.setEnabled(true); delete.setEnabled(false); } else { cancel.setEnabled(false); delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mTasks.deleteTask(task.tag); refresh(); } }); delete.setEnabled(true); } tasksList.addView(taskCard); } tasksView.removeAllViews(); tasksView.addView(tasksList); } }
From source file:com.msn.support.gallery.ZoomActivity.java
/** * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in" * image view and animating its bounds to fit the entire activity content area. More * specifically:/*from w w w . j a v a 2 s .c om*/ * <ol> * <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li> * <li>Calculate the starting and ending bounds for the expanded view.</li> * <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y) * simultaneously, from the starting bounds to the ending bounds.</li> * <li>Zoom back out by running the reverse animation on click.</li> * </ol> * ??ImageView? * Activity * <ol> * <li>???ImageView</li> * <li>?ImageView?</li> * <li>??ImageView?/?X, Y, SCALE_X, SCALE_Y * ??</li> * <li>???</li> * @param thumbView The thumbnail view to zoom in. * @param imageResId The high-resolution version of the image represented by the thumbnail. * */ @TargetApi(11) private void zoomImageFromThumb(final View thumbView, int imageResId) { // If there's an animation in progress, cancel it immediately and proceed with this one. // ? if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Load the high-resolution "zoomed-in" image.?ImageView final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image); expandedImageView.setImageResource(imageResId); // Calculate the starting and ending bounds for the zoomed-in image. This step // involves lots of math. Yay, math. //?ImageView?? final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); // The start bounds are the global visible rectangle of the thumbnail, and the // final bounds are the global visible rectangle of the container view. Also // set the container view's offset as the origin for the bounds, since that's // the origin for the positioning animation properties (X, Y). // ????? // ???? thumbView.getGlobalVisibleRect(startBounds); findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); Log.e("Test", "globalOffset.x=" + globalOffset.x + " globalOffset.y=" + globalOffset.y); Log.e("Test", "startBounds.top=" + startBounds.top + " startBounds.left=" + startBounds.left); startBounds.offset(-globalOffset.x, -globalOffset.y); Log.e("Test", "startBounds2.top=" + startBounds.top + " startBounds2.left=" + startBounds.left); finalBounds.offset(-globalOffset.x, -globalOffset.y); // Adjust the start bounds to be the same aspect ratio as the final bounds using the // "center crop" technique. This prevents undesirable stretching during the animation. // Also calculate the start scaling factor (the end scaling factor is always 1.0). // ??"center crop"??? // ????1.0 float startScale; if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) { // Extend start bounds horizontally ? startScale = (float) startBounds.height() / finalBounds.height(); float startWidth = startScale * finalBounds.width(); float deltaWidth = (startWidth - startBounds.width()) / 2; startBounds.left -= deltaWidth; startBounds.right += deltaWidth; } else { // Extend start bounds vertically ? startScale = (float) startBounds.width() / finalBounds.width(); float startHeight = startScale * finalBounds.height(); float deltaHeight = (startHeight - startBounds.height()) / 2; startBounds.top -= deltaHeight; startBounds.bottom += deltaHeight; } // Hide the thumbnail and show the zoomed-in view. When the animation begins, // it will position the zoomed-in view in the place of the thumbnail. //thumbView.setAlpha(0f); expandedImageView.setVisibility(View.VISIBLE); // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of // the zoomed-in view (the default is the center of the view). expandedImageView.setPivotX(0f); expandedImageView.setPivotY(0f); // Construct and run the parallel animation of the four translation and scale properties // (X, Y, SCALE_X, and SCALE_Y). AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; // Upon clicking the zoomed-in image, it should zoom back down to the original bounds // and show the thumbnail instead of the expanded image. final float startScaleFinal = startScale; expandedImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Animate the four positioning/sizing properties in parallel, back to their // original values. AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; } }); }
From source file:com.ibuildapp.romanblack.CouponPlugin.CouponAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { try {//ErrorLogging View row;//from w w w . j a v a 2 s.c o m if (null == convertView) { } else { row = convertView; } if (items.get(position).hasImage()) { row = layoutInflater.inflate(R.layout.romanblack_coupon_feed_item_image, null); ImageView imageView = (ImageView) row.findViewById(R.id.romanblack_coupon_image); imageView.setImageResource(R.drawable.romanblack_coupon_no_image); } else { row = layoutInflater.inflate(R.layout.romanblack_coupon_feed_item, null); } // change arrow color depending of background color ImageView arrow = (ImageView) row.findViewById(R.id.romanblack_coupon_feed_item_arrow); if (Utils.isChemeDark(Statics.color1)) { arrow.setImageResource(R.drawable.romanblack_coupon_arrow_light); } else { arrow.setImageResource(R.drawable.romanblack_coupon_arrow); } TextView title = (TextView) row.findViewById(R.id.romanblack_coupon_title); title.setTextColor(Statics.color3); TextView description = (TextView) row.findViewById(R.id.romanblack_coupon_description); description.setTextColor(Statics.color4); title.setText(items.get(position).getTitle()); description.setText(items.get(position).getAnounce(75)); if (items.get(position).hasImage()) { ImageView imageView = (ImageView) row.findViewById(R.id.romanblack_coupon_image); if (imageView != null) { if (items.get(position).getImagePath().length() > 0) { Bitmap bitmap = null; Integer key = new Integer(position); if (bitmaps.containsValue(key)) { bitmap = bitmaps.get(key); } else { try { bitmap = decodeImageFile(items.get(position).getImagePath()); bitmaps.put(key, bitmap); } catch (Exception e) { Log.w("NEWS ADAPTER", e); } } if (bitmap != null) { imageView.setImageBitmap(bitmap); } } } } return row; } catch (Exception e) { return null; } }
From source file:cn.wander.Utils.views.pageindicator.TabPageIndicator.java
private void addTab(int index, CharSequence text, int iconResId) { RelativeLayout tablayout = (RelativeLayout) View.inflate(getContext(), R.layout.tab_item_layout, null); final TextView tabView = (TextView) tablayout.findViewById(R.id.tab_item_title); tabView.setTag(index);//from w ww . j a v a 2s . c o m tabView.setFocusable(true); tabView.setOnClickListener(mTabClickListener); tabView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 19); tabView.setText(text); tabView.setTextColor(getResources().getColor(R.color.kw_common_cl_white)); if (iconResId != 0) { // tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0); ImageView iconView = (ImageView) tablayout.findViewById(R.id.tab_item_icon); iconView.setImageResource(iconResId); iconView.setVisibility(View.VISIBLE); } mTabLayout.addView(tablayout, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1)); }
From source file:com.jaspersoft.android.jaspermobile.activities.profile.fragment.ServersFragment.java
@Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == cursor.getColumnIndex(ServerProfilesTable._ID)) { ImageView imageView = (ImageView) view; if (mServerProfile == null) { imageView.setImageResource(R.drawable.ic_composed_server); } else {//w w w . j a v a 2 s .c om long entryId = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID)); imageView.setImageResource((mServerProfileId == entryId) ? R.drawable.ic_composed_active_server : R.drawable.ic_composed_server); } return true; } if (columnIndex == cursor.getColumnIndex(ServerProfilesTable.ALIAS)) { TextView textView = (TextView) view; String alias = cursor.getString(columnIndex); if (mServerProfile == null) { textView.setText(alias); } else { long entryId = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID)); boolean isItemActive = (mServerProfileId == entryId); textView.setText(isItemActive ? getString(R.string.sp_active_item, alias) : alias); } return true; } return false; }
From source file:com.markupartist.sthlmtraveling.ui.view.TripView.java
public void updateViews() { this.setOrientation(VERTICAL); float scale = getResources().getDisplayMetrics().density; this.setPadding(getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding), getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding)); LinearLayout timeStartEndLayout = new LinearLayout(getContext()); TextView timeStartEndText = new TextView(getContext()); timeStartEndText.setText(DateTimeUtil.routeToTimeDisplay(getContext(), trip)); timeStartEndText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); timeStartEndText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); ViewCompat.setPaddingRelative(timeStartEndText, 0, 0, 0, (int) (2 * scale)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { timeStartEndText.setTextDirection(View.TEXT_DIRECTION_RTL); }/* w ww .ja v a 2 s .c o m*/ } // Check if we have Realtime for start and or end. boolean hasRealtime = false; Pair<Date, RealTimeState> transitTime = trip.departsAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } else { transitTime = trip.arrivesAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } } // if (hasRealtime) { // ImageView liveDrawable = new ImageView(getContext()); // liveDrawable.setImageResource(R.drawable.ic_live); // ViewCompat.setPaddingRelative(liveDrawable, 0, (int) (2 * scale), (int) (4 * scale), 0); // timeStartEndLayout.addView(liveDrawable); // // AlphaAnimation animation1 = new AlphaAnimation(0.4f, 1.0f); // animation1.setDuration(600); // animation1.setRepeatMode(Animation.REVERSE); // animation1.setRepeatCount(Animation.INFINITE); // // liveDrawable.startAnimation(animation1); // } timeStartEndLayout.addView(timeStartEndText); LinearLayout startAndEndPointLayout = new LinearLayout(getContext()); TextView startAndEndPoint = new TextView(getContext()); BidiFormatter bidiFormatter = BidiFormatter.getInstance(RtlUtils.isRtl(Locale.getDefault())); startAndEndPoint.setText(String.format("%s %s", bidiFormatter.unicodeWrap(trip.fromStop().getName()), bidiFormatter.unicodeWrap(trip.toStop().getName()))); startAndEndPoint.setTextColor(getResources().getColor(R.color.body_text_1)); // Dark gray startAndEndPoint.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { startAndEndPoint.setTextDirection(View.TEXT_DIRECTION_RTL); } } ViewCompat.setPaddingRelative(startAndEndPoint, 0, (int) (4 * scale), 0, (int) (4 * scale)); startAndEndPointLayout.addView(startAndEndPoint); RelativeLayout timeLayout = new RelativeLayout(getContext()); LinearLayout routeChanges = new LinearLayout(getContext()); routeChanges.setGravity(Gravity.CENTER_VERTICAL); LinearLayout.LayoutParams changesLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); changesLayoutParams.gravity = Gravity.CENTER_VERTICAL; if (trip.hasAlertsOrNotes()) { ImageView warning = new ImageView(getContext()); warning.setImageResource(R.drawable.ic_trip_deviation); ViewCompat.setPaddingRelative(warning, 0, (int) (2 * scale), (int) (4 * scale), 0); routeChanges.addView(warning); } int currentTransportCount = 1; int transportCount = trip.getLegs().size(); for (Leg leg : trip.getLegs()) { if (!leg.isTransit() && transportCount > 3) { if (leg.getDistance() < 150) { continue; } } if (currentTransportCount > 1 && transportCount >= currentTransportCount) { ImageView separator = new ImageView(getContext()); separator.setImageResource(R.drawable.transport_separator); ViewCompat.setPaddingRelative(separator, 0, 0, (int) (2 * scale), 0); separator.setLayoutParams(changesLayoutParams); routeChanges.addView(separator); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(separator, -1f); } } ImageView changeImageView = new ImageView(getContext()); Drawable transportDrawable = LegUtil.getTransportDrawable(getContext(), leg); changeImageView.setImageDrawable(transportDrawable); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(changeImageView, -1f); } ViewCompat.setPaddingRelative(changeImageView, 0, 0, 0, 0); changeImageView.setLayoutParams(changesLayoutParams); routeChanges.addView(changeImageView); if (currentTransportCount <= 3) { String lineName = leg.getRouteShortName(); if (!TextUtils.isEmpty(lineName)) { TextView lineNumberView = new TextView(getContext()); lineNumberView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13); RoundedBackgroundSpan roundedBackgroundSpan = new RoundedBackgroundSpan( LegUtil.getColor(getContext(), leg), Color.WHITE, ViewHelper.dipsToPix(getContext().getResources(), 4)); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(lineName); sb.append(' '); sb.setSpan(roundedBackgroundSpan, 0, lineName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); lineNumberView.setText(sb); ViewCompat.setPaddingRelative(lineNumberView, (int) (5 * scale), (int) (1 * scale), (int) (2 * scale), 0); lineNumberView.setLayoutParams(changesLayoutParams); routeChanges.addView(lineNumberView); } } currentTransportCount++; } TextView durationText = new TextView(getContext()); durationText.setText(DateTimeUtil.formatDetailedDuration(getResources(), trip.getDuration() * 1000)); durationText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); durationText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); durationText.setTypeface(Typeface.DEFAULT_BOLD); timeLayout.addView(routeChanges); timeLayout.addView(durationText); RelativeLayout.LayoutParams durationTextParams = (RelativeLayout.LayoutParams) durationText .getLayoutParams(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_END); } else { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } durationText.setLayoutParams(durationTextParams); View divider = new View(getContext()); ViewGroup.LayoutParams dividerParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); divider.setLayoutParams(dividerParams); this.addView(timeLayout); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) routeChanges.getLayoutParams(); params.height = LayoutParams.MATCH_PARENT; params.addRule(RelativeLayout.CENTER_VERTICAL); routeChanges.setLayoutParams(params); this.addView(startAndEndPointLayout); this.addView(timeStartEndLayout); if (mShowDivider) { this.addView(divider); } }
From source file:com.amanmehara.programming.android.activities.ProgramActivity.java
private void setLanguageDatails() { TextView name = (TextView) findViewById(R.id.language_name); name.setText(languageName);/*from ww w .jav a 2s . com*/ ImageView image = (ImageView) findViewById(R.id.language_image); if (Objects.nonNull(logoBlob)) { int imageBlobLength = logoBlob.length; Bitmap logo = BitmapFactory.decodeByteArray(logoBlob, 0, imageBlobLength); image.setImageBitmap(logo); } else { image.setImageResource(R.drawable.ic_circle_logo); } }
From source file:com.coinblesk.client.TransactionDetailActivity.java
private void updateTransactionDetails() { final TransactionWrapper txWrapper = walletServiceBinder.getTransaction(transactionHash); final Transaction transaction = txWrapper.getTransaction(); try {/*from www. j a v a 2s . co m*/ // No one liner because of color filter, sorry View v; ImageView statusIcon; if ((statusIcon = (ImageView) findViewById(R.id.txdetail_status_icon)) != null) { statusIcon.setImageResource(ClientUtils.isConfidenceReached(txWrapper) ? R.drawable.ic_checkbox_marked_circle_outline_white_18dp : R.drawable.ic_clock_white_18dp); statusIcon.setColorFilter(UIUtils.getStatusColorFilter(txWrapper)); } TextView txt; if ((txt = ((TextView) findViewById(R.id.txdetail_amount_content))) != null) { // TODO: should we respect user setting (micro/milli coin?) txt.setText(UIUtils.toFriendlyAmountString(getApplicationContext(), txWrapper)); } if ((txt = ((TextView) findViewById(R.id.txdetail_status_content))) != null) { txt.setText(transaction.getConfidence().toString()); } if ((txt = ((TextView) findViewById(R.id.txdetail_instant_content))) != null) { txt.setText(txWrapper.isInstant() ? R.string.yes : R.string.no); } if ((txt = ((TextView) findViewById(R.id.txdetail_date_content))) != null) { txt.setText(transaction.getUpdateTime().toString()); } if ((txt = ((TextView) findViewById(R.id.txdetail_txhash_content))) != null) { txt.setText(transactionHash); } if ((txt = (TextView) findViewById(R.id.txdetail_fee_content)) != null) { // for incoming tx, fee is null because inputs not known. if (transaction.getFee() != null) { // TODO: should we respect user setting (micro/milli coin?) txt.setText(UIUtils.toFriendlyFeeString(this, transaction)); } else if ((v = findViewById(R.id.txfee)) != null) { v.setVisibility(View.GONE); } } String addressSentTo = sentToAddressOfTx(txWrapper); if ((txt = (TextView) findViewById(R.id.txdetail_address_to_content)) != null) { if (addressSentTo != null) { txt.setText(addressSentTo); } else if ((v = findViewById(R.id.txdetail_address_to)) != null) { v.setVisibility(View.GONE); } } } catch (Exception e) { Log.w(TAG, "updateTransactionDetails exception: ", e); } }
From source file:com.eggwall.SoundSleep.SleepActivity.java
/** * Sets the icons from the current AudioService state. * @param state an integer: {@link AudioService#MUSIC}, {@link AudioService#WHITE_NOISE}, or * {@link AudioService#SILENCE} which determines what the {@link AudioService} is currently doing. *//*from w w w. j av a 2 s . c o m*/ private void setIconFromState(int state) { final ImageView cloud = (ImageView) findViewById(R.id.cloud); final ImageView note = (ImageView) findViewById(R.id.note); switch (state) { case AudioService.MUSIC: cloud.setImageResource(R.drawable.rain); note.setImageResource(R.drawable.pause); break; case AudioService.WHITE_NOISE: note.setImageResource(R.drawable.music); cloud.setImageResource(R.drawable.pause); break; case AudioService.SILENCE: cloud.setImageResource(R.drawable.rain); note.setImageResource(R.drawable.music); break; } }
From source file:com.google.android.gcm.demo.ui.GroupsFragment.java
@Override public void refresh() { float density = getActivity().getResources().getDisplayMetrics().density; SimpleArrayMap<String, Sender> senders = mSenders.getSenders(); LinearLayout sendersList = new LinearLayout(getActivity()); sendersList.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < senders.size(); i++) { Sender sender = senders.valueAt(i); if (sender.groups.size() > 0) { LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater() .inflate(R.layout.widget_icon_text_button_row, sendersList, false); ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon); TextView senderText = (TextView) senderRow.findViewById(R.id.widget_itbr_text); senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE); senderIcon.setImageResource(R.drawable.cloud_googblue); senderIcon.setPadding(0, 0, (int) (8 * density), 0); senderText.setText(getString(R.string.groups_sender_id, sender.senderId)); sendersList.addView(senderRow); for (DeviceGroup deviceGroup : sender.groups.values()) { LinearLayout row = (LinearLayout) getActivity().getLayoutInflater() .inflate(R.layout.widget_icon_text_button_row, sendersList, false); ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon); TextView label = (TextView) row.findViewById(R.id.widget_itbr_text); Button button = (Button) row.findViewById(R.id.widget_itbr_button); icon.setImageResource(R.drawable.group_grey600); label.setText(deviceGroup.notificationKeyName); label.setBackgroundResource(selectableBackgroundResource); label.setTag(R.id.tag_action, ACTION_OPEN_GROUP); label.setTag(R.id.tag_senderid, sender.senderId); label.setTag(R.id.tag_group, deviceGroup.notificationKeyName); label.setOnClickListener(this); button.setText(R.string.groups_delete); button.setTag(R.id.tag_action, ACTION_DELETE_GROUP); button.setTag(R.id.tag_senderid, sender.senderId); button.setTag(R.id.tag_group, deviceGroup.notificationKeyName); button.setOnClickListener(this); row.setPadding((int) (16 * density), 0, 0, 0); sendersList.addView(row); }//from ww w. jav a2 s .co m } } if (sendersList.getChildCount() == 0) { TextView noTokens = new TextView(getActivity()); noTokens.setText(getString(R.string.groups_no_groups_available)); noTokens.setTypeface(null, Typeface.ITALIC); sendersList.addView(noTokens); } FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.groups_list_wrapper); topicsView.removeAllViews(); topicsView.addView(sendersList); }