List of usage examples for android.widget ImageView setImageResource
@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync") public void setImageResource(@DrawableRes int resId)
From source file:com.parse.favourama.ACTLoginSelf.java
public void checkAvail(View view) { String uname = username.getText().toString().trim(); if (uname.isEmpty()) return;//from w w w . j a va2 s . co m final Context c = this; final ImageView imgView = (ImageView) findViewById(R.id.ava_state_img); final TextView textView = (TextView) findViewById(R.id.ava_state_text); final ProgressBar progressBar = (ProgressBar) findViewById(R.id.ava_state_prog); /*final Handler mHandler = new Handler(); new Thread(new Runnable() { public void run() { mHandler.post(new Runnable() { public void run() { progressBar.setProgress(100); } }); } }).start();*/ ParseQuery<ParseUser> userQuery = ParseUser.getQuery(); userQuery.whereEqualTo("username", uname); progressBar.setVisibility(View.VISIBLE); userQuery.getFirstInBackground(new GetCallback<ParseUser>() { @Override public void done(ParseUser parseUser, ParseException e) { progressBar.setVisibility(View.GONE); if (e != null && e.getCode() != 101) { Toast.makeText(c, "An error has occured: " + e.getMessage() + " Sorry, please try again!", Toast.LENGTH_SHORT).show(); return; } if (parseUser == null) { /*The name is available*/ imgView.setImageResource(R.drawable.ic_check_black_24dp); textView.setText("It's available!"); } else { imgView.setImageResource(R.drawable.ic_close_black_24dp); textView.setText("Sorry, It's taken."); } } }); }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
private View makeView(boolean icon, boolean watcher, boolean closeable, float density) { int size = (int) (48f * density); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setGravity(Gravity.CENTER_VERTICAL); ImageView iconView = null;//w ww . j a v a 2 s. c o m if (icon) { iconView = new ImageView(context); iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); linearLayout.addView(iconView, (int) (24f * density), size); } TextView textView = makeCommonTextView(false); linearLayout.addView(textView, new LinearLayout.LayoutParams(0, size, 1)); WatcherView watcherView = null; if (watcher) { watcherView = new WatcherView(context); linearLayout.addView(watcherView, size, size); } ImageView closeView = null; if (!watcher && closeable) { closeView = new ImageView(context); closeView.setScaleType(ImageView.ScaleType.CENTER); closeView.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonCancel, 0)); closeView.setBackgroundResource(ResourceUtils.getResourceId(context, android.R.attr.borderlessButtonStyle, android.R.attr.background, 0)); linearLayout.addView(closeView, size, size); closeView.setOnClickListener(closeButtonListener); } ViewHolder holder = new ViewHolder(); holder.icon = iconView; holder.text = textView; holder.extra = watcherView != null ? watcherView : closeView; linearLayout.setTag(holder); int layoutLeftDp = 0; int layoutRightDp = 0; int textLeftDp; int textRightDp; if (C.API_LOLLIPOP) { textLeftDp = 16; textRightDp = 16; if (icon) { layoutLeftDp = 16; textLeftDp = 32; } if (watcher || closeable) { layoutRightDp = 4; textRightDp = 8; } } else { textLeftDp = 8; textRightDp = 8; if (icon) { layoutLeftDp = 8; textLeftDp = 6; textView.setAllCaps(true); } if (watcher || closeable) { layoutRightDp = 0; textRightDp = 0; } } linearLayout.setPadding((int) (layoutLeftDp * density), 0, (int) (layoutRightDp * density), 0); textView.setPadding((int) (textLeftDp * density), 0, (int) (textRightDp * density), 0); return linearLayout; }
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void addYoutubeVideo(String url) { final String yturl; if (url.contains("embed")) { String temp = url.split("embed/")[1]; if (url.contains("feature")) { temp = temp.split("feature=")[0]; yturl = temp.substring(0, temp.length() - 1); } else//from w w w . j a va2 s .c om yturl = temp; } else if (url.contains("youtu.be")) { yturl = url.split("youtu.be/")[1]; } else return; final RelativeLayout rl = new RelativeLayout(getActivity()); YouTubeThumbnailView yt = new YouTubeThumbnailView(getActivity()); ImageView icon = new ImageView(getActivity()); try { yt.setTag(yturl); yt.initialize(Constants.YOUTUBE_API_TOKEN, new OnInitializedListener() { @Override public void onInitializationFailure(YouTubeThumbnailView thumbView, YouTubeInitializationResult error) { rl.setVisibility(View.GONE); } @Override public void onInitializationSuccess(YouTubeThumbnailView thumbView, YouTubeThumbnailLoader thumbLoader) { thumbLoader.setVideo(yturl); } }); } catch (Exception e) { e.printStackTrace(); } RelativeLayout.LayoutParams obj_params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); obj_params.addRule(RelativeLayout.CENTER_HORIZONTAL); obj_params.addRule(RelativeLayout.CENTER_VERTICAL); yt.setLayoutParams(obj_params); icon.setImageResource(R.drawable.yt_play_button); icon.setLayoutParams(obj_params); RelativeLayout.LayoutParams rl_params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rl_params.setMargins(0, 10, 0, 0); rl.setLayoutParams(rl_params); rl.setGravity(Gravity.CENTER_HORIZONTAL); rl.setClickable(true); rl.addView(yt); rl.addView(icon); rl.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getActivity(), YoutubeActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra(Constants.KEY_VIDEO_URL, yturl); startActivity(i); } }); lay.addView(rl); }
From source file:com.hichinaschool.flashcards.anki.CardEditor.java
@Override protected Dialog onCreateDialog(int id) { StyledDialog dialog = null;//from ww w .j ava 2s. c om Resources res = getResources(); StyledDialog.Builder builder = new StyledDialog.Builder(this); switch (id) { case DIALOG_TAGS_SELECT: builder.setTitle(R.string.card_details_tags); builder.setPositiveButton(res.getString(R.string.select), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mAddNote) { try { JSONArray ja = new JSONArray(); for (String t : selectedTags) { ja.put(t); } mCol.getModels().current().put("tags", ja); mCol.getModels().setChanged(); } catch (JSONException e) { throw new RuntimeException(e); } mEditorNote.setTags(selectedTags); } mCurrentTags = selectedTags; updateTags(); } }); builder.setNegativeButton(res.getString(R.string.cancel), null); mNewTagEditText = (EditText) new EditText(this); mNewTagEditText.setHint(R.string.add_new_tag); InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (source.charAt(i) == ' ' || source.charAt(i) == ',') { return ""; } } return null; } }; mNewTagEditText.setFilters(new InputFilter[] { filter }); ImageView mAddTextButton = new ImageView(this); mAddTextButton.setImageResource(R.drawable.ic_addtag); mAddTextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String tag = mNewTagEditText.getText().toString(); if (tag.length() != 0) { if (mEditorNote.hasTag(tag)) { mNewTagEditText.setText(""); return; } selectedTags.add(tag); actualizeTagDialog(mTagsDialog); mNewTagEditText.setText(""); } } }); FrameLayout frame = new FrameLayout(this); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL); params.rightMargin = 10; mAddTextButton.setLayoutParams(params); frame.addView(mNewTagEditText); frame.addView(mAddTextButton); builder.setView(frame, false, true); dialog = builder.create(); mTagsDialog = dialog; break; case DIALOG_DECK_SELECT: ArrayList<CharSequence> dialogDeckItems = new ArrayList<CharSequence>(); // Use this array to know which ID is associated with each // Item(name) final ArrayList<Long> dialogDeckIds = new ArrayList<Long>(); ArrayList<JSONObject> decks = mCol.getDecks().all(); Collections.sort(decks, new JSONNameComparator()); builder.setTitle(R.string.deck); for (JSONObject d : decks) { try { if (d.getInt("dyn") == 0) { dialogDeckItems.add(d.getString("name")); dialogDeckIds.add(d.getLong("id")); } } catch (JSONException e) { throw new RuntimeException(e); } } // Convert to Array String[] items = new String[dialogDeckItems.size()]; dialogDeckItems.toArray(items); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { long newId = dialogDeckIds.get(item); if (mCurrentDid != newId) { if (mAddNote) { try { // TODO: mEditorNote.setDid(newId); mEditorNote.model().put("did", newId); mCol.getModels().setChanged(); } catch (JSONException e) { throw new RuntimeException(e); } } mCurrentDid = newId; updateDeck(); } } }); dialog = builder.create(); mDeckSelectDialog = dialog; break; case DIALOG_MODEL_SELECT: ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>(); // Use this array to know which ID is associated with each // Item(name) final ArrayList<Long> dialogIds = new ArrayList<Long>(); ArrayList<JSONObject> models = mCol.getModels().all(); Collections.sort(models, new JSONNameComparator()); builder.setTitle(R.string.note_type); for (JSONObject m : models) { try { dialogItems.add(m.getString("name")); dialogIds.add(m.getLong("id")); } catch (JSONException e) { throw new RuntimeException(e); } } // Convert to Array String[] items2 = new String[dialogItems.size()]; dialogItems.toArray(items2); builder.setItems(items2, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { long oldModelId; try { oldModelId = mCol.getModels().current().getLong("id"); } catch (JSONException e) { throw new RuntimeException(e); } long newId = dialogIds.get(item); if (oldModelId != newId) { mCol.getModels().setCurrent(mCol.getModels().get(newId)); JSONObject cdeck = mCol.getDecks().current(); try { cdeck.put("mid", newId); } catch (JSONException e) { throw new RuntimeException(e); } mCol.getDecks().save(cdeck); int size = mEditFields.size(); String[] oldValues = new String[size]; for (int i = 0; i < size; i++) { oldValues[i] = mEditFields.get(i).getText().toString(); } setNote(); resetEditFields(oldValues); mTimerHandler.removeCallbacks(checkDuplicatesRunnable); duplicateCheck(false); } } }); dialog = builder.create(); break; case DIALOG_RESET_CARD: builder.setTitle(res.getString(R.string.reset_card_dialog_title)); builder.setMessage(res.getString(R.string.reset_card_dialog_message)); builder.setPositiveButton(res.getString(R.string.yes), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // for (long cardId : // mDeck.getCardsFromFactId(mEditorNote.getId())) { // mDeck.cardFromId(cardId).resetCard(); // } // mDeck.reset(); // setResult(Reviewer.RESULT_EDIT_CARD_RESET); // mCardReset = true; // Themes.showThemedToast(CardEditor.this, // getResources().getString( // R.string.reset_card_dialog_confirmation), true); } }); builder.setNegativeButton(res.getString(R.string.no), null); builder.setCancelable(true); dialog = builder.create(); break; case DIALOG_INTENT_INFORMATION: dialog = createDialogIntentInformation(builder, res); } return dialog; }
From source file:com.lloydtorres.stately.telegrams.TelegramsAdapter.java
/** * Changes the telegram alert to a certain style depending on its type. * @param type Telegram type/* ww w . j a v a2 s . c o m*/ * @param holder * @param icon * @param text */ public void setAlertState(int type, boolean isPreview, RelativeLayout holder, ImageView icon, TextView text) { if (type != Telegram.TELEGRAM_GENERIC) { holder.setVisibility(View.VISIBLE); int iconRes = isPreview ? R.drawable.ic_alert_recruitment : R.drawable.ic_alert_recruitment_white; int alertColor = R.color.colorChart1; int alertContent = R.string.telegrams_alert_recruitment; switch (type) { case Telegram.TELEGRAM_REGION: iconRes = isPreview ? R.drawable.ic_region_green : R.drawable.ic_region_white; alertColor = R.color.colorChart3; alertContent = R.string.telegrams_alert_region; break; case Telegram.TELEGRAM_WELCOME: iconRes = isPreview ? R.drawable.ic_region_green : R.drawable.ic_region_white; alertColor = R.color.colorChart3; alertContent = R.string.telegram_alert_welcome; break; case Telegram.TELEGRAM_MODERATOR: iconRes = isPreview ? R.drawable.ic_alert_moderator : R.drawable.ic_alert_moderator_white; alertColor = R.color.colorChart3; alertContent = R.string.telegrams_alert_mod; break; } icon.setImageResource(iconRes); text.setText(context.getString(alertContent)); if (isPreview) { text.setTextColor(ContextCompat.getColor(context, alertColor)); } else { holder.setBackgroundColor(ContextCompat.getColor(context, alertColor)); } } else { holder.setVisibility(View.GONE); } }
From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityCreateOrEditRoute.java
/** initAddDestButton() * adds the Driving Through button//from w ww . j av a 2 s .c om */ protected void initAddDestButton() { //Adds/enables the FrameLayout AddDestFrameLayout = new FrameLayout(this); AddDestFrameLayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, 80)); AddDestFrameLayout.setEnabled(true); //Fills the Image Icon ImageView destAddIcon = new ImageView(this); FrameLayout.LayoutParams lliDestIcon = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); lliDestIcon.setMargins(dipToPx(10), 0, 0, dipToPx(2)); destAddIcon.setLayoutParams(lliDestIcon); destAddIcon.setPadding(0, dipToPx(5), 0, 0); destAddIcon.setImageResource(R.drawable.google_marker_thumb_mini_through); //Adds the imageicon to the framelayout/enables it AddDestFrameLayout.addView(destAddIcon); //Fills/sets the text TextView destAddText = new TextView(this); FrameLayout.LayoutParams lliDest = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); lliDest.setMargins(0, dipToPx(5), 0, 0); destAddText.setLayoutParams(lliDest); destAddText.setPadding(dipToPx(40), dipToPx(6), 0, 0); destAddText.setTextSize(15); destAddText.setText(R.string.mapViewAcField); //Adds the text to the framelayout AddDestFrameLayout.addView(destAddText); //Adds the framelayout to the linearlayout (in the scrollview) sclLayout = (LinearLayout) findViewById(R.id.sclLayout); sclLayout.addView(AddDestFrameLayout, sclLayout.getChildCount()); final Button button = ((Button) findViewById(R.id.btnChooseRoute)); //Adds a clicklistener to the frameLayout AddDestFrameLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //Adds a new destination field initDestFrameLayout(); //Moves the button to the bottom setLayoutParams(); if (checkFields() == false) { button.setEnabled(false); button.setText("Show on map"); } else { mapView.getOverlays().clear(); createMap(); } } }); }
From source file:com.mappn.gfan.ui.HomeTabActivity.java
private void drawUpdateCount(Activity context, Resources res, ImageView view, boolean flag) { DisplayMetrics dm = new DisplayMetrics(); context.getWindowManager().getDefaultDisplay().getMetrics(dm); Bitmap cornerRes = BitmapFactory.decodeResource(res, R.drawable.notify_update); Bitmap appBitmapNormal = BitmapFactory.decodeResource(res, R.drawable.main_tab_app_unselect); Bitmap appBitmapPressed = BitmapFactory.decodeResource(res, R.drawable.main_tab_app_select); StateListDrawable stateDrawable = new StateListDrawable(); int stateSelected = android.R.attr.state_selected; if (flag) {/*from www . ja v a 2s . co m*/ Bitmap cornerBitmap = drawText(dm, res, cornerRes, mSession.getUpgradeNumber()); Bitmap newBitmapNormal = drawBitmap(dm, appBitmapNormal, cornerBitmap); Bitmap newBitmapPressed = drawBitmap(dm, appBitmapPressed, cornerBitmap); stateDrawable.addState(new int[] { -stateSelected }, new BitmapDrawable(res, newBitmapNormal)); stateDrawable.addState(new int[] { stateSelected }, new BitmapDrawable(res, newBitmapPressed)); view.setImageDrawable(stateDrawable); } else { view.setImageResource(R.drawable.main_tab_app_manager_selector); } }
From source file:com.android.settings.Settings.java
private void setupNetWork() { final Tab tab = mActionBar.newTab(); LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.setting_tab_new_ui, null); ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon); if (dialView != null) { dialView.setImageResource(R.drawable.tab_network); }//from www. jav a 2 s . c om TextView dialText = (TextView) view.findViewById(R.id.tab_text); if (dialText != null) { dialText.setText(R.string.network_settings_tab); } tab.setCustomView(view); tab.setTag(R.xml.settings_headers_network); tab.setTabListener(mTabListener); mActionBar.addTab(tab); }
From source file:com.android.settings.Settings.java
private void setupDevice() { final Tab tab = mActionBar.newTab(); LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.setting_tab_new_ui, null); ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon); if (dialView != null) { dialView.setImageResource(R.drawable.tab_device); }/*from w w w . j a v a2s. c om*/ TextView dialText = (TextView) view.findViewById(R.id.tab_text); if (dialText != null) { dialText.setText(R.string.device_settings_tab); } tab.setCustomView(view); tab.setTag(R.xml.settings_headers_device); tab.setTabListener(mTabListener); mActionBar.addTab(tab); }
From source file:com.android.settings.Settings.java
private void setupPersonal() { final Tab tab = mActionBar.newTab(); LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.setting_tab_new_ui, null); ImageView dialView = (ImageView) view.findViewById(R.id.tab_icon); if (dialView != null) { dialView.setImageResource(R.drawable.tab_personal); }/*from w w w . j ava 2s .c o m*/ TextView dialText = (TextView) view.findViewById(R.id.tab_text); if (dialText != null) { dialText.setText(R.string.personal_settings_tab); } tab.setCustomView(view); tab.setTag(R.xml.settings_headers_personal); tab.setTabListener(mTabListener); mActionBar.addTab(tab); }