List of usage examples for android.widget ImageView setImageResource
@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync") public void setImageResource(@DrawableRes int resId)
From source file:com.example.android.saddacampus.MainActivity.java
public void initSearchView() { final SearchView searchView = (SearchView) search_menu.findItem(R.id.action_filter_search).getActionView(); // Enable/Disable Submit button in the keyboard searchView.setSubmitButtonEnabled(false); // Change search close button image ImageView closeButton = (ImageView) searchView.findViewById(R.id.search_close_btn); closeButton.setImageResource(R.drawable.ic_action_search); // set hint and the text colors EditText txtSearch = ((EditText) searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text)); txtSearch.setHint("Search.."); txtSearch.setHintTextColor(Color.DKGRAY); txtSearch.setTextColor(getResources().getColor(R.color.primary_color)); // set the cursor AutoCompleteTextView searchTextView = (AutoCompleteTextView) searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text); try {/*from w w w. j a v a 2 s.c om*/ Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); mCursorDrawableRes.setAccessible(true); mCursorDrawableRes.set(searchTextView, R.drawable.ic_action_search); //This sets the cursor resource ID to 0 or @null which will make it visible on white background } catch (Exception e) { e.printStackTrace(); } searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { callSearch(query); searchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { callSearch(newText); return true; } public void callSearch(String query) { //Do searching Log.i("query", "" + query); } }); }
From source file:com.mifos.mifosxdroid.online.DashboardActivity.java
/** * downloads the logged in user's username * sets dummy profile picture as no profile picture attribute available *///ww w. ja v a2 s . c o m private void loadClientDetails() { // download logged in user final User loggedInUser = PrefManager.getUser(); TextView textViewUsername = ButterKnife.findById(mNavigationHeader, R.id.tv_user_name); textViewUsername.setText(loggedInUser.getUsername()); // no profile picture credential, using dummy profile picture ImageView imageViewUserPicture = ButterKnife.findById(mNavigationHeader, R.id.iv_user_picture); imageViewUserPicture.setImageResource(R.drawable.ic_dp_placeholder); }
From source file:com.example.kyle.weatherforecast.WeatherFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_layout, container, false); Bundle args = getArguments();/*ww w . j a v a2s .c o m*/ int i = args.getInt("day"); TextView textOutlook = ((TextView) rootView.findViewById(R.id.text_outlook)); ImageView symbolView = ((ImageView) rootView.findViewById(R.id.image_symbol)); TextView tempsView = ((TextView) rootView.findViewById(R.id.text_temp)); TextView windView = ((TextView) rootView.findViewById(R.id.text_min)); TextView realFeelView = ((TextView) rootView.findViewById(R.id.text_real_feel)); textOutlook.setText(WeatherData.outlookArray[i]); symbolView.setImageResource(WeatherData.symbolArray[i]); tempsView.setText(WeatherData.tempsArray[i] + "c"); windView.setText(("Min " + WeatherData.minArray[i] + "c")); realFeelView.setText("Real feel " + WeatherData.realFeelArray[i] + "c"); return rootView; }
From source file:cn.dev4mob.app.ui.animationsdemo.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 ww w .j a v a 2 s . c o m * * <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> * * @param thumbView The thumbnail view to zoom in. * @param imageResId The high-resolution version of the image represented by the thumbnail. */ 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. 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. 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); Timber.d("thumbview startBounds = %s", startBounds); findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); Timber.d("thumbview finalBoundst = %s", finalBounds); Timber.d("thumbview globalOffset = %s", globalOffset); startBounds.offset(-globalOffset.x, -globalOffset.y); 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). 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(); Timber.d("startSCale = %f", startScale); 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.linkedin.android.eventsapp.EventFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final String eventNameArg = getArguments().getString(EXTRA_EVENT_NAME); final long eventDateArg = getArguments().getLong(EXTRA_EVENT_DATE); final String eventLocationArg = getArguments().getString(EXTRA_EVENT_LOCATION); int pictureIdArg = getArguments().getInt(EXTRA_PICTURE_ID); boolean isAttendingArg = getArguments().getBoolean(EXTRA_EVENT_ATTENDING); Person[] attendeesArg = (Person[]) getArguments().getParcelableArray(EXTRA_EVENT_ATTENDEES); SimpleDateFormat dateFormat = new SimpleDateFormat("E dd MMM yyyy 'at' hh:00 a"); final String dateString = dateFormat.format(new Date(eventDateArg)); View v = inflater.inflate(R.layout.layout_event_fragment, container, false); boolean accessTokenValid = LISessionManager.getInstance(getActivity()).getSession().isValid(); if (!accessTokenValid) { ViewStub linkedinLogin = (ViewStub) v.findViewById(R.id.connectWithLinkedInStub); linkedinLogin.inflate();/*ww w. j av a 2 s . c om*/ Button loginButton = (Button) v.findViewById(R.id.connectWithLinkedInButton); loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked login button"); LISessionManager.getInstance(getActivity()).init(getActivity(), Constants.scope, new AuthListener() { @Override public void onAuthSuccess() { Intent intent = new Intent(getActivity(), MainActivity.class); startActivity(intent); getActivity().finish(); } @Override public void onAuthError(LIAuthError error) { } }, false); } }); } TextView eventNameView = (TextView) v.findViewById(R.id.eventName); eventNameView.setText(eventNameArg); TextView eventLocationAndDateView = (TextView) v.findViewById(R.id.eventLocationAndDate); eventLocationAndDateView.setText(eventLocationArg + " " + dateString); TextView eventAttendeeCount = (TextView) v.findViewById(R.id.attendeeCount); eventAttendeeCount.setText("Other Attendees (" + attendeesArg.length + ")"); ImageView eventImageView = (ImageView) v.findViewById(R.id.eventImage); eventImageView.setImageResource(pictureIdArg); final Button attendButton = (Button) v.findViewById(R.id.attendButton); final Button declineButton = (Button) v.findViewById(R.id.declineButton); if (isAttendingArg) { attendButton.setText("Attending"); attendButton.setEnabled(false); declineButton.setText("Decline"); declineButton.setEnabled(true); } attendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((Button) v).setText("Attending"); v.setEnabled(false); declineButton.setText("Decline"); declineButton.setEnabled(true); if (LISessionManager.getInstance(getActivity()).getSession().isValid()) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setTitle("Share on LinkedIn?"); alertDialogBuilder.setCancelable(true) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { JSONObject shareObject = new JSONObject(); try { JSONObject visibilityCode = new JSONObject(); visibilityCode.put("code", "anyone"); shareObject.put("visibility", visibilityCode); shareObject.put("comment", "I am attending " + eventNameArg + " in " + eventLocationArg + " on " + dateString); } catch (JSONException e) { } APIHelper.getInstance(getActivity()).postRequest(getActivity(), Constants.shareBaseUrl, shareObject, new ApiListener() { @Override public void onApiSuccess(ApiResponse apiResponse) { Toast.makeText(getActivity(), "Your share was successful!", Toast.LENGTH_LONG); } @Override public void onApiError(LIApiError apiError) { Log.e(TAG, apiError.toString()); Toast.makeText(getActivity(), "Your share was unsuccessful. Try again later!", Toast.LENGTH_LONG); } }); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }); declineButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((Button) v).setText("Declined"); v.setEnabled(false); attendButton.setText("Attend"); attendButton.setEnabled(true); } }); ListView attendeesListView = (ListView) v.findViewById(R.id.attendeesList); AttendeeAdapter adapter = new AttendeeAdapter(getActivity(), R.layout.attendee_list_item, attendeesArg, accessTokenValid); attendeesListView.setAdapter(adapter); attendeesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ArrayAdapter adapter = (ArrayAdapter) parent.getAdapter(); Person person = (Person) adapter.getItem(position); Intent intent = new Intent(getActivity(), ProfileActivity.class); Bundle extras = new Bundle(); extras.putParcelable("person", person); intent.putExtras(extras); startActivity(intent); } }); return v; }
From source file:com.dm.material.dashboard.candybar.fragments.IconsSearchFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.menu_icons_search, menu); MenuItem search = menu.findItem(R.id.menu_search); mSearchView = (SearchView) MenuItemCompat.getActionView(search); mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_SEARCH); mSearchView.setQueryHint(getActivity().getResources().getString(R.string.search_icon)); mSearchView.setMaxWidth(Integer.MAX_VALUE); MenuItemCompat.expandActionView(search); mSearchView.setIconifiedByDefault(false); mSearchView.clearFocus();//from w w w . j a va 2 s .co m int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon); ViewHelper.changeSearchViewTextColor(mSearchView, color, ColorHelper.setColorAlpha(color, 0.6f)); View view = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_plate); if (view != null) view.setBackgroundColor(Color.TRANSPARENT); ImageView closeIcon = (ImageView) mSearchView .findViewById(android.support.v7.appcompat.R.id.search_close_btn); if (closeIcon != null) closeIcon.setImageResource(R.drawable.ic_toolbar_close); ImageView searchIcon = (ImageView) mSearchView .findViewById(android.support.v7.appcompat.R.id.search_mag_icon); ViewHelper.removeSearchViewSearchIcon(searchIcon); mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String string) { filterSearch(string); return true; } @Override public boolean onQueryTextSubmit(String string) { mSearchView.clearFocus(); return true; } }); }
From source file:com.example.android.tourguide.ObjectAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { // Check if an existing view is being reused, otherwise inflate the view View listItemView = convertView; if (listItemView == null) { listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false); }/*from w w w. j ava 2 s. c om*/ // Get the {@link Object} object located at this position in the list final Object currentObject = getItem(position); // Find the TextView in the list_item.xml layout with the ID name_text_view. TextView objectNameTV = (TextView) listItemView.findViewById(R.id.name_text_view); objectNameTV.setSelected(true); objectNameTV.setText(currentObject.getObjectName()); // Find the TextView in the list_item.xml layout with the ID address_text_view. TextView addressTV = (TextView) listItemView.findViewById(R.id.address_text_view); addressTV.setSelected(true); addressTV.setText(currentObject.getObjectAddress()); // Find the TextView in the list_item.xml layout with the ID description_text_view. TextView objectDescription = (TextView) listItemView.findViewById(R.id.description_text_view); objectDescription.setText(currentObject.getObjectDescription()); // Find the ImageView in the list_item.xml layout with the ID image. final ImageView imageView = (ImageView) listItemView.findViewById(R.id.image); // Check if an image is provided for this word or not if (currentObject.hasImage()) { // If an image is available, display the provided image based on the resource ID imageView.setImageResource(currentObject.getImageResourceId()); // Make sure the view is visible imageView.setVisibility(View.VISIBLE); } else { // Otherwise hide the ImageView (set visibility to GONE) imageView.setVisibility(View.GONE); } LinearLayout textContainer = (LinearLayout) listItemView.findViewById(R.id.text_container); int color = ContextCompat.getColor(getContext(), mColorResourceId); textContainer.setBackgroundColor(color); textContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (currentObject.hasImage()) { if (imageView.getVisibility() == View.GONE) { imageView.setVisibility(View.VISIBLE); } else { imageView.setVisibility(View.GONE); } } } }); // Return the whole list item layout (containing 2 TextViews) so that it can be shown in // the ListView. return listItemView; }
From source file:com.hacktx.android.activities.EventDetailActivity.java
private void setupEventDetails() { int eventIconId; switch (event.getType()) { case TALK:// ww w .j av a 2 s .c om eventIconId = R.drawable.ic_event_talk; break; case EDUCATION: eventIconId = R.drawable.ic_event_education; break; case BUS: eventIconId = R.drawable.ic_event_bus; break; case FOOD: eventIconId = R.drawable.ic_event_food; break; case DEV: eventIconId = R.drawable.ic_event_dev; break; default: eventIconId = R.drawable.ic_event_default; break; } ImageView eventIcon = (ImageView) findViewById(R.id.eventIcon); eventIcon.setImageResource(eventIconId); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); Calendar start = Calendar.getInstance(); try { start.setTime(formatter.parse(event.getStartDate())); } catch (ParseException e) { e.printStackTrace(); } ((TextView) findViewById(R.id.eventLocation)).setText(event.getLocation().getLocationDetails()); ((TextView) findViewById(R.id.eventDateTime)) .setText(start.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()) + " " + start.get(Calendar.DAY_OF_MONTH) + " | " + event.getEventTimes()); }
From source file:com.common.android.lib.controls.view.indicator.IconPageIndicator.java
public void notifyDataSetChanged() { mIconsLayout.removeAllViews();/*from w ww . j a va 2 s . c o m*/ IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter(); int count = iconAdapter.getCount(); for (int i = 0; i < count; i++) { ImageView view = new ImageView(getContext()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(15, 0, 0, 0); view.setImageResource(iconAdapter.getIconResId(i)); view.setLayoutParams(lp); mIconsLayout.addView(view); } if (mSelectedIndex > count) { mSelectedIndex = count - 1; } setCurrentItem(mSelectedIndex); requestLayout(); }
From source file:com.idevity.card.read.ShowCHUID.java
/** * Method onCreateView.//ww w.jav a 2 s . c o m * * @param inflater * LayoutInflater * @param container * ViewGroup * @param savedInstanceState * Bundle * @return View */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Globals g = Globals.getInstance(); String issuer = new String(); String subject = new String(); String validfrom = new String(); String validto = new String(); boolean certvalid = true; boolean sigvalid = false; CMSSignedDataObject chuidSig = null; X509Certificate pcs = null; View chuidLayout = inflater.inflate(R.layout.activity_show_chuid, container, false); // get card data byte[] _data = g.getCard(); CardData80073 carddata = new CardData80073(_data); // get chuid PIVCardHolderUniqueID chuid = null; PIVDataTempl chuidInDataTempl = carddata.getPIVCardHolderUniqueID(); if (chuidInDataTempl != null) { byte[] chuidData = chuidInDataTempl.getData(); if (chuidData == null) { chuidData = chuidInDataTempl.getEncoded(); } chuid = new PIVCardHolderUniqueID(chuidData); } if (chuid != null) { try { // get chuid signature object chuidSig = new CMSSignedDataObject(chuid.getSignatureBytes(), chuid.getSignatureDataBytes()); chuidSig.setProviderName("OpenSSLFIPSProvider"); // validate the signature, don't do PDVAL sigvalid = chuidSig.verifySignature(false); } catch (SignatureException e) { Log.e(TAG, "Error: " + e.getMessage()); } // get x509 cert if (chuidSig != null) { pcs = chuidSig.getSigner(); } // get values from x509 if (pcs != null) { issuer = pcs.getIssuerDN().getName(); subject = pcs.getSubjectDN().getName(); validfrom = pcs.getNotBefore().toString(); validto = pcs.getNotAfter().toString(); } } ImageView sigthumbs = (ImageView) chuidLayout.findViewById(R.id.chuidindicator1); TextView sigtext = (TextView) chuidLayout.findViewById(R.id.chuid1); if (sigvalid) { sigthumbs.setImageResource(R.drawable.cert_good); } else { sigthumbs.setImageResource(R.drawable.cert_bad); sigtext.setTextColor(getResources().getColor(R.color.idredmain)); } /* * Note to self. I am not thrilled how Java almost forces you to assume * a certificate if valid unless an exception is thrown! */ TextView vfText = (TextView) chuidLayout.findViewById(R.id.chuid4); TextView vtText = (TextView) chuidLayout.findViewById(R.id.chuid5); try { if (pcs != null) { pcs.checkValidity(); } } catch (CertificateNotYetValidException e) { certvalid = false; vfText.setTextColor(getResources().getColor(R.color.idredmain)); if (debug) { Log.d(TAG, "Error: Authentication Certificate Not Vaid Yet!"); } } catch (CertificateExpiredException e) { certvalid = false; vtText.setTextColor(getResources().getColor(R.color.idredmain)); if (debug) { Log.d(TAG, "Error: Card Authentication Certificate Expired!"); } } ImageView certthumbs = (ImageView) chuidLayout.findViewById(R.id.chuidindicator2); TextView certtext = (TextView) chuidLayout.findViewById(R.id.chuid2); if (certvalid && pcs != null) { certthumbs.setImageResource(R.drawable.cert_good); } else { certthumbs.setImageResource(R.drawable.cert_bad); certtext.setTextColor(getResources().getColor(R.color.idredmain)); } // setting all values in activity TextView editChuidSubject = (TextView) chuidLayout.findViewById(R.id.chuid_subject); editChuidSubject.setText(subject); TextView editValidFrom = (TextView) chuidLayout.findViewById(R.id.chuid_date); editValidFrom.setText(validfrom); TextView editValidTo = (TextView) chuidLayout.findViewById(R.id.chuid_expiry); editValidTo.setText(validto); TextView editIssuer = (TextView) chuidLayout.findViewById(R.id.chuid_issuer); editIssuer.setText(issuer); return chuidLayout; }