List of usage examples for android.widget ImageView setImageResource
@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync") public void setImageResource(@DrawableRes int resId)
From source file:com.inc.playground.playground.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); globalVariables = ((GlobalVariables) getApplication()); // Set up the action bar. final ActionBar actionBar = getActionBar(); setPlayGroundActionBar();/* www. j a va 2 s .c om*/ //set actionBar color actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor))); actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor))); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent. //actionBar.setHomeButtonEnabled(false); actionBar.setDisplayShowHomeEnabled(false); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab(actionBar.newTab().setTabListener(this)); } actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view); actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view); actionBar.getTabAt(2).setIcon(R.drawable.pg_calendar_view); //NavigationDrawer handling (e.g the list from leftside): mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); getActionBar().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getActionBar().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.closeDrawers(); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // all linear layout from slider menu /*Home button */ LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home); ll_Home.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); /*Login button */ LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login); ll_Login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes LinearLayout ll_Login = (LinearLayout) v; TextView loginTxt = (TextView) findViewById(R.id.login_txt); if (loginTxt.getText().equals("Login")) { Intent iv = new Intent(MainActivity.this, Login.class); startActivity(iv); finish(); } else if (loginTxt.getText().equals("Logout")) { final Dialog alertDialog = new Dialog(MainActivity.this); alertDialog.setContentView(R.layout.logout_dilaog); alertDialog.setTitle("Logout"); alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.clear(); editor.commit(); ImageView loginImg = (ImageView) findViewById(R.id.login_img); TextView loginTxt = (TextView) findViewById(R.id.login_txt); loginTxt.setText("Login"); loginImg.setImageResource(R.drawable.pg_action_lock_open); globalVariables = ((GlobalVariables) getApplication()); globalVariables.SetCurrentUser(null); globalVariables.SetUserPictureBitMap(null); globalVariables.SetUsersList(null); globalVariables.SetUsersImagesMap(null); Util.clearCookies(getApplicationContext()); Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.show(); //<-- See This! } } }); /*Setting button*/ LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings); ll_Setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, com.inc.playground.playground.upLeft3StripesButton.SettingsActivity.class); startActivity(iv); finish(); } }); /*My profile button*/ LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile); ll_my_profile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // new changes globalVariables = ((GlobalVariables) getApplication()); User currentUser = globalVariables.GetCurrentUser(); if (currentUser == null) { Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show(); } else { Intent iv = new Intent(MainActivity.this, com.inc.playground.playground.upLeft3StripesButton.MyProfile.class); //for my profile iv.putExtra("name", currentUser.getName()); iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents()); //pass events iv.putExtra("events", currentUser.getEvents()); iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval()); iv.putExtra("events_decline", currentUser.getEvents_decline()); iv.putExtra("photoUrl", currentUser.getPhotoUrl()); startActivity(iv); // } } }); LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about); ll_aboutUs.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, AboutUs.class); startActivity(iv); finish(); } }); }
From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java
public void addResultListItem(String title, String value, LinearLayout netLayout) { final float scale = activity.getResources().getDisplayMetrics().density; final int leftRightDiv = Helperfunctions.dpToPx(0, scale); final int topBottomDiv = Helperfunctions.dpToPx(0, scale); final int heightDiv = Helperfunctions.dpToPx(1, scale); LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View measurementItemView = inflater.inflate(R.layout.classification_list_item, netLayout, false); final TextView itemTitle = (TextView) measurementItemView.findViewById(R.id.classification_item_title); itemTitle.setText(title);/*from ww w. j a va 2s .c o m*/ final ImageView itemClassification = (ImageView) measurementItemView .findViewById(R.id.classification_item_color); itemClassification.setImageResource(Helperfunctions.getClassificationColor(-1)); itemClassification.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { activity.showHelp(R.string.url_help_result, false); } }); final TextView itemValue = (TextView) measurementItemView.findViewById(R.id.classification_item_value); itemValue.setText(value); netLayout.addView(measurementItemView); final View divider = new View(activity); divider.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv, 1)); divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); netLayout.addView(divider); netLayout.invalidate(); }
From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java
public void showDialog() throws NameNotFoundException { final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.about_dialog); dialog.setTitle("About Repeater.MY " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName); dialog.setCancelable(true);/*from w ww . j ava 2 s . c o m*/ // text TextView text = (TextView) dialog.findViewById(R.id.tvAbout); text.setText(R.string.txtLicense); // icon image ImageView img = (ImageView) dialog.findViewById(R.id.ivAbout); img.setImageResource(R.drawable.ic_launcher); dialog.show(); }
From source file:com.adkdevelopment.earthquakesurvival.ui.PagerActivity.java
/** * Method to set tab images and highlights on tab switching *///from w w w.j a va 2s .c o m private void setTabImages() { if (mTab != null) { int[] iconSet = { R.drawable.error_grey, R.drawable.map_grey, R.drawable.newspaper_grey, R.drawable.lightbulb_grey, R.drawable.error_blue, R.drawable.map_blue, R.drawable.newspaper_blue, R.drawable.lightbulb_blue }; // Set custom layouts for each Tab for (int i = 0, n = mTab.getTabCount(); i < n; i++) { TabLayout.Tab tabLayout = mTab.getTabAt(i); if (tabLayout != null) { tabLayout.setCustomView(R.layout.pager_tab_layout); View customView = tabLayout.getCustomView(); if (customView != null) { ImageView imageView = ButterKnife.findById(customView, R.id.tab_item_image); TextView textView = ButterKnife.findById(customView, R.id.tab_item_text); textView.setText(tabLayout.getText()); if (i == 0) { textView.setTextColor(mColorSelected); imageView.setImageResource(iconSet[i + iconSet.length / 2]); } else { textView.setTextColor(mColorUnselected); imageView.setImageResource(iconSet[i]); } } } } // Highlight image and text on selection mTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { setTitle(); View customView = tab.getCustomView(); if (customView != null) { ImageView imageView = ButterKnife.findById(customView, R.id.tab_item_image); imageView.setImageResource(iconSet[tab.getPosition() + iconSet.length / 2]); TextView textView = ButterKnife.findById(customView, R.id.tab_item_text); textView.setTextColor(mColorSelected); } mViewPager.setCurrentItem(tab.getPosition()); Fragment fragment = mPagerAdapter.getRegisteredFragment(tab.getPosition()); if (fragment instanceof SurvivalFragment) { ((SurvivalFragment) fragment).animateViewsIn(); } else if (fragment instanceof NewsFragment) { ((NewsFragment) fragment).animateViewsIn(); } else if (fragment instanceof RecentFragment) { ((RecentFragment) fragment).animateViewsIn(); } } @Override public void onTabUnselected(TabLayout.Tab tab) { View customView = tab.getCustomView(); if (customView != null) { ImageView imageView = ButterKnife.findById(customView, R.id.tab_item_image); imageView.setImageResource(iconSet[tab.getPosition()]); TextView textView = ButterKnife.findById(customView, R.id.tab_item_text); textView.setTextColor(mColorUnselected); } } @Override public void onTabReselected(TabLayout.Tab tab) { Fragment fragment = mPagerAdapter.getRegisteredFragment(tab.getPosition()); if (fragment instanceof RecentFragment) { ((RecentFragment) fragment).scrollToTop(); } else if (fragment instanceof NewsFragment) { ((NewsFragment) fragment).scrollToTop(); } } }); } }
From source file:com.frostwire.android.gui.adapters.PeerListAdapter.java
@Override protected void populateView(View view, Peer peer) { TextView title = findView(view, R.id.view_peer_list_item_title); title.setText(peer.isLocalHost() ? view.getResources().getString(R.string.my_files) : peer.getNickname()); TextView version = findView(view, R.id.view_peer_list_item_version); version.setText("v. " + peer.getClientVersion()); version.setTextColor(0xffcccccc);//from w ww . j av a 2s. co m ImageView icon = findView(view, R.id.view_peer_list_item_icon); populateIcon(icon, peer); ImageView howtoShareButton = findView(view, R.id.view_peer_list_item_button_how_to_share); howtoShareButton.setOnClickListener(howtoShareClickListener); if (!peer.isLocalHost()) { howtoShareButton.setVisibility(View.INVISIBLE); title.setTextColor(0xff3b3b3b); } else { title.setTextColor(0xff54afe4); // show my version in red If I'm old to encourage user to update. if (SoftwareUpdater.instance().isOldVersion()) { version.setTextColor(Color.RED); version.setText(getContext().getString(R.string.please_update_to_v, SoftwareUpdater.instance().getLatestVersion())); } howtoShareButton.setVisibility(View.VISIBLE); howtoShareButton.setImageResource(R.drawable.share_howto); } TextView summary = findView(view, R.id.view_peer_list_item_summary); summary.setText(getContext().getString(R.string.summary_files_shared, peer.getNumSharedFiles())); }
From source file:com.corporatetaxi.TaxiOntheWay_Activity.java
public void caceldialog() { AlertDialog.Builder builder = new AlertDialog.Builder(TaxiOntheWay_Activity.this); //builder.setTitle(getString(R.string.cancel_trip)); //builder.setIcon(R.drawable.ic_launcher); LayoutInflater inflater = getLayoutInflater(); View header = inflater.inflate(R.layout.dialog_heading, null); TextView textView = (TextView) header.findViewById(R.id.text); ImageView icon = (ImageView) header.findViewById(R.id.icon); icon.setImageResource(R.drawable.ic_launcher); textView.setText("Taxi On The Way"); builder.setCustomTitle(header);/*from w ww . ja v a 2 s . co m*/ builder.setCancelable(false); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // AppPreferences.setTripId(DrawerMainActivity.this, ""); // AppPreferences.setDriverId(DrawerMainActivity.this, ""); dialog.dismiss(); } }); builder.show(); }
From source file:edu.ucdavis.glass.sepsis.support.OverviewActivity.java
private void loadView() { Patient p = Global.recentPatients.peek(); // retrieve data fields TextView pNameView = (TextView) findViewById(R.id.patientName); TextView pIdView = (TextView) findViewById(R.id.patientId); TextView pDOBView = (TextView) findViewById(R.id.overviewDOBField); TextView pGenderView = (TextView) findViewById(R.id.overviewGenderField); TextView pHospAdmView = (TextView) findViewById(R.id.overviewHospAdmField); TextView pStateView = (TextView) findViewById(R.id.overviewCurentStateField); TextView sumBACView = (TextView) findViewById(R.id.summaryBACField); TextView sumRRView = (TextView) findViewById(R.id.summaryRRField); TextView sumMAPView = (TextView) findViewById(R.id.summaryMAPField); TextView sumSBPView = (TextView) findViewById(R.id.summarySBPField); TextView sumWBCView = (TextView) findViewById(R.id.summaryWBCField); ImageView c = (ImageView) findViewById(R.id.picture); // set data/*from ww w . j a v a 2s . c o m*/ pNameView.setText(p.name); pIdView.setText(p.id); pDOBView.setText(p.dob); pGenderView.setText(p.gender); pHospAdmView.setText(p.admissionTimestamp); pStateView.setText(p.currentState); sumBACView.setText(p.bacteriaInBlood); sumRRView.setText(p.vitals.get(p.vitals.size() - 1).respiratoryRate); sumMAPView.setText(p.vitals.get(p.vitals.size() - 1).MAP); sumSBPView.setText(p.vitals.get(p.vitals.size() - 1).SBP); sumWBCView.setText(p.vitals.get(p.vitals.size() - 1).WBC); if (p.id.equals("1")) { c.setImageResource(R.drawable.patient_1); } else if (p.id.equals("2")) { c.setImageResource(R.drawable.patient_2); } else if (p.id.equals("3")) { c.setImageResource(R.drawable.patient_3); } else if (p.id.equals("4")) { c.setImageResource(R.drawable.patient_4); } else { c.setImageResource(R.drawable.default_user); } }
From source file:com.android.ex.chips.RecipientAlternatesAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { int position = cursor.getPosition(); TextView display = (TextView) view.findViewById(android.R.id.title); ImageView imageView = (ImageView) view.findViewById(android.R.id.icon); RecipientEntry entry = getRecipientEntry(position); if (position == 0) { display.setText(cursor.getString(Queries.Query.NAME)); display.setVisibility(View.VISIBLE); byte[] photoBytes = mPhotoCacheMap.get(entry.getPhotoThumbnailUri()); if (photoBytes != null && imageView != null) { Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length); imageView.setImageBitmap(photo); } else {/* w ww . ja v a 2 s . co m*/ imageView.setImageResource(R.drawable.ic_contact_picture); if (entry.getPhotoThumbnailUri() != null) fetchPhotoAsync(entry, entry.getPhotoThumbnailUri()); } imageView.setVisibility(View.VISIBLE); } else { display.setVisibility(View.GONE); imageView.setVisibility(View.GONE); } TextView destination = (TextView) view.findViewById(android.R.id.text1); destination.setText(cursor.getString(Queries.Query.DESTINATION)); TextView destinationType = (TextView) view.findViewById(android.R.id.text2); if (destinationType != null) { destinationType.setText( mQuery.getTypeLabel(context.getResources(), cursor.getInt(Queries.Query.DESTINATION_TYPE), cursor.getString(Queries.Query.DESTINATION_LABEL)).toString().toUpperCase()); } }
From source file:ch.bfh.instacircle.MessageCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { // extracting the labels of the layout TextView content = (TextView) view.findViewById(R.id.content); TextView description = (TextView) view.findViewById(R.id.description); ImageView icon = (ImageView) view.findViewById(R.id.icon); // setting the content label content.setText(cursor.getString(cursor.getColumnIndex("message"))); SimpleDateFormat sdf = new SimpleDateFormat(); // create a readable date from the timestamp Date date = new Date(cursor.getLong(cursor.getColumnIndex("timestamp"))); int messageType = cursor.getInt(cursor.getColumnIndex("message_type")); // setting the icon according to the message type switch (messageType) { case Message.MSG_CONTENT: if (cursor.getInt(cursor.getColumnIndex("sequence_number")) == -1) { description.setText("Unicast message received from " + cursor.getString(cursor.getColumnIndex("identification")) + ",\n" + sdf.format(date)); icon.setImageResource(R.drawable.glyphicons_120_message_full); icon.setBackgroundColor(context.getResources().getColor(android.R.color.holo_purple)); } else {/*w w w. j ava2 s . co m*/ description.setText("Broadcast message received from " + cursor.getString(cursor.getColumnIndex("identification")) + ",\n" + sdf.format(date)); icon.setImageResource(R.drawable.glyphicons_120_message_full); icon.setBackgroundColor(context.getResources().getColor(android.R.color.holo_blue_light)); } break; case Message.MSG_MSGJOIN: description.setText("Participant joined,\n" + sdf.format(date)); icon.setImageResource(R.drawable.glyphicons_006_user_add); break; case Message.MSG_MSGLEAVE: description.setText("Participant left,\n" + sdf.format(date)); icon.setImageResource(R.drawable.glyphicons_007_user_remove); break; } }
From source file:com.brq.wallet.activity.modern.ModernMain.java
public void setRefreshAnimation() { if (refreshItem != null) { if (_mbwManager.getWalletManager(false).getState() == WalletManager.State.SYNCHRONIZING) { MenuItem menuItem = MenuItemCompat.setActionView(refreshItem, R.layout.actionbar_indeterminate_progress); ImageView ivTorIcon = (ImageView) menuItem.getActionView().findViewById(R.id.ivTorIcon); if (_mbwManager.getTorMode() == ServerEndpointType.Types.ONLY_TOR && _mbwManager.getTorManager() != null) { ivTorIcon.setVisibility(View.VISIBLE); if (_mbwManager.getTorManager().getInitState() == 100) { ivTorIcon.setImageResource(R.drawable.tor); } else { ivTorIcon.setImageResource(R.drawable.tor_gray); }/*from w w w . j a v a2 s . com*/ } else { ivTorIcon.setVisibility(View.GONE); } } else { MenuItemCompat.setActionView(refreshItem, null); } } }