List of usage examples for android.widget ImageView setImageResource
@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync") public void setImageResource(@DrawableRes int resId)
From source file:com.facebook.android.friendsmash.GameFragment.java
void setLives(int lives) { this.lives = lives; if (getActivity() != null) { // Update the livesContainer livesContainer.removeAllViews(); for (int i = 0; i < lives; i++) { ImageView heartImageView = new ImageView(getActivity()); heartImageView.setImageResource(R.drawable.heart_red); livesContainer.addView(heartImageView); }// w w w. ja v a2 s .c o m if (lives <= 0) { // User has no lives left, so end the game, passing back the score Bundle bundle = new Bundle(); bundle.putInt("score", getScore()); Intent i = new Intent(); i.putExtras(bundle); getActivity().setResult(Activity.RESULT_OK, i); getActivity().finish(); } } }
From source file:co.mrktplaces.android.ui.views.smarttablayout.SmartTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.//from w w w. ja va2 s .co m */ protected ImageView createDefaultTabView(int resource) { ImageView imageView = new ImageView(getContext()); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1)); imageView.setImageResource(resource); if (tabViewBackgroundResId != NO_ID) { imageView.setBackgroundResource(tabViewBackgroundResId); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); imageView.setBackgroundResource(outValue.resourceId); } imageView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { imageView.setMinimumWidth(tabViewTextMinWidth); } return imageView; }
From source file:com.accia77.mockey.adapters.ManageEntriesCustomCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final Entry entry = EntriesDataSource.cursorToEntry(cursor); TextView txtDesc = (TextView) view.findViewById(R.id.desc); // holder.txtTitle = (TextView) // convertView.findViewById(R.id.title); ImageView imageView = (ImageView) view.findViewById(R.id.icon); txtDesc.setText(entry.getUserEditedEntry()); //iconId defaults to ic_action_edit int iconId = R.drawable.ic_action_edit; // if(entry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_PURE_TEXT) // iconId = R.drawable.ic_action_edit; if (entry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_AUDIO) iconId = R.drawable.ic_action_microphone; //NOTE: PHOTO and VIDEO not supported yet if (entry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_PHOTO) iconId = R.drawable.ic_action_photo; if (entry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_VIDEO) iconId = R.drawable.ic_action_video; imageView.setImageResource(iconId); imageView.setOnClickListener(new OnClickListener() { @Override//from w ww . j av a 2 s . c om public void onClick(View v) { //No playback if the sdcard is not mounted if (MyApplication.getInstance().isSdCardMounted(false)) { MyApplication.getInstance().playSelection(entry); } } }); }
From source file:com.cerema.cloud2.ui.fragment.ShareFileFragment.java
/** * {@inheritDoc}/*from w ww. jav a2 s . co m*/ */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log_OC.d(TAG, "onCreateView"); // Inflate the layout for this fragment View view = inflater.inflate(R.layout.share_file_layout, container, false); // Setup layout // Image ImageView icon = (ImageView) view.findViewById(R.id.shareFileIcon); icon.setImageResource(MimetypeIconUtil.getFileTypeIconId(mFile.getMimetype(), mFile.getFileName())); if (mFile.isImage()) { String remoteId = String.valueOf(mFile.getRemoteId()); Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(remoteId); if (thumbnail != null) { icon.setImageBitmap(thumbnail); } } // Name TextView fileNameHeader = (TextView) view.findViewById(R.id.shareFileName); fileNameHeader.setText(getResources().getString(R.string.share_file, mFile.getFileName())); // Size TextView size = (TextView) view.findViewById(R.id.shareFileSize); if (mFile.isFolder()) { size.setVisibility(View.GONE); } else { size.setText(DisplayUtils.bytesToHumanReadable(mFile.getFileLength())); } // Add User Button Button addUserGroupButton = (Button) view.findViewById(R.id.addUserButton); addUserGroupButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean shareWithUsersEnable = AccountUtils.hasSearchUsersSupport(mAccount); if (shareWithUsersEnable) { // Show Search Fragment mListener.showSearchUsersAndGroups(); } else { String message = getString(R.string.share_sharee_unavailable); Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show(); } } }); // Set listener for user actions on switch for sharing/unsharing via link initShareViaLinkListener(view); // Set listener for user actions on expiration date initExpirationListener(view); // Set listener for user actions on password initPasswordListener(view); // Set listener for user actions on edit permission initEditPermissionListener(view); return view; }
From source file:com.android.deskclock.timer.TimerFragment.java
/** * Updates the state of the page indicators so they reflect the selected page in the context of * all pages./*w w w .j a va 2 s . c o m*/ */ private void updatePageIndicators() { final int page = mViewPager.getCurrentItem(); final int pageIndicatorCount = mPageIndicators.length; final int pageCount = mAdapter.getCount(); final int[] states = computePageIndicatorStates(page, pageIndicatorCount, pageCount); for (int i = 0; i < states.length; i++) { final int state = states[i]; final ImageView pageIndicator = mPageIndicators[i]; if (state == 0) { pageIndicator.setVisibility(GONE); } else { pageIndicator.setVisibility(VISIBLE); pageIndicator.setImageResource(state); } } }
From source file:com.benefit.buy.library.viewpagerindicator.PagerSlidingTabStrip.java
private void addIconTab(final int position, String title, int iconResId, int iconResclickId, int count) { // TextView tab = new TextView(getContext()); LayoutInflater inflater = LayoutInflater.from(getContext()); View tabView = inflater.inflate(R.layout.item_tab, null); ImageView clickImg = (ImageView) tabView.findViewById(R.id.img_click); ImageView outImg = (ImageView) tabView.findViewById(R.id.img_out); TextView text = (TextView) tabView.findViewById(R.id.tab_name); TextView textHint = (TextView) tabView.findViewById(R.id.tab_hint_number); text.setText(title);//from w w w . j av a 2 s. co m outImg.setImageResource(iconResId); clickImg.setImageResource(iconResclickId); // tab.setGravity(Gravity.CENTER); // tab.setSingleLine(); // if (iconResId != 0) { // tab.setCompoundDrawablesWithIntrinsicBounds(0, iconResId, 0, 0); // tab.setBackgroundResource(iconResId); // } if (count <= 0) { textHint.setVisibility(View.GONE); } else { textHint.setVisibility(View.VISIBLE); textHint.setText(count + ""); } addTab(position, tabView); }
From source file:com.guerinet.materialtabs.TabLayout.java
/** * Adds the tabs based on a list of Strings to use as tab titles * * @param listener The {@link TabClickListener} to use when a tab is clicked * @param initialTab The initial tab to show * @param titles The titles for the tabs *//*w ww. j av a 2s .co m*/ private void addTabs(TabClickListener listener, int initialTab, List<String> titles) { //Clear any existing tabs clear(); //Reset the current position mCurrentPosition = -1; View initialTabView = null; //Go through the titles for (int i = 0; i < titles.size(); i++) { View tabView; TextView tabTitleView = null; //If there is a custom tab view layout id set, try and inflate it if (mTabViewLayoutId != 0) { tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); //Set the default selector if we should use the default selector if (mDefaultSelector) { tabView.setBackgroundResource(getTabBackground()); } tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); prepareTextView(tabTitleView); //Set up the icon if needed if (mTabViewIconId != null) { ImageView iconView = (ImageView) tabView.findViewById(mTabViewIconId); //Wrap through the icons iconView.setImageResource(mIconIds[i % mIconIds.length]); } } else { //If not, just use the default tab view tabView = createDefaultTabView(); } //If there is no tab title and the tab view is a TextView, use that if (tabTitleView == null) { if (!TextView.class.isInstance(tabView)) { //If there is no tab title, throw an exception throw new IllegalStateException("Could not find the title TextView"); } tabTitleView = (TextView) tabView; } //Set equal weights if we are to distribute these tabs evenly if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } //Set the text and the listener tabTitleView.setText(titles.get(i)); tabView.setOnClickListener(listener); //Set the content description if there is one String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } //Add it to the strip mTabStrip.addView(tabView); //If we found the initial tab, store it if (i == initialTab) { initialTabView = tabView; } } //Click on the first tab if there is one. This will set the initial position if (initialTabView != null) { initialTabView.performClick(); } }
From source file:com.android.inputmethod.keyboard.EmojiPalettesView.java
private void addTab(final TabHost host, final int categoryId) { final String tabId = mEmojiCategory.getCategoryName(categoryId, 0 /* categoryPageId */); final TabHost.TabSpec tspec = host.newTabSpec(tabId); tspec.setContent(R.id.emoji_keyboard_dummy); if (mEmojiCategory.getCategoryIcon(categoryId) != 0) { final ImageView iconView = (ImageView) LayoutInflater.from(getContext()) .inflate(R.layout.emoji_keyboard_tab_icon, null); iconView.setImageResource(mEmojiCategory.getCategoryIcon(categoryId)); tspec.setIndicator(iconView);//w ww . ja v a 2 s . c o m } if (mEmojiCategory.getCategoryLabel(categoryId) != null) { final TextView textView = (TextView) LayoutInflater.from(getContext()) .inflate(R.layout.emoji_keyboard_tab_label, null); textView.setText(mEmojiCategory.getCategoryLabel(categoryId)); textView.setTextColor(mTabLabelColor); tspec.setIndicator(textView); } host.addTab(tspec); }
From source file:net.idlesoft.android.apps.github.activities.SingleIssue.java
private void loadIssueItemBox() { final TextView date = (TextView) mHeader.findViewById(R.id.tv_issue_list_item_updated_date); final ImageView icon = (ImageView) mHeader.findViewById(R.id.iv_issue_list_item_icon); final TextView title = (TextView) mHeader.findViewById(R.id.tv_issue_list_item_title); final TextView number = (TextView) mHeader.findViewById(R.id.tv_issue_list_item_number); final TextView topbar = (TextView) findViewById(R.id.tv_page_title); try {//from w ww . j a v a 2 s. c om date.setText(getTimeSince(mJson.getString("updated_at"))); if (mJson.getString("state").equalsIgnoreCase("open")) { icon.setImageResource(R.drawable.issues_open); } else { icon.setImageResource(R.drawable.issues_closed); } number.setText("#" + mJson.getString("number")); title.setText(mJson.getString("title")); topbar.setText("Issue " + number.getText().toString()); } catch (final Exception e) { e.printStackTrace(); } }