List of usage examples for android.widget ImageView setBackgroundResource
@RemotableViewMethod public void setBackgroundResource(@DrawableRes int resid)
From source file:com.sft.blackcatapp.EnrollSchoolActivity.java
private void setViewPager() { InfinitePagerAdapter adapter = null; int length = 0; if (adImageUrl != null && adImageUrl.length > 0) { adapter = new InfinitePagerAdapter(this, adImageUrl, screenWidth, viewPagerHeight); length = adImageUrl.length;/* w w w .j a va 2 s . com*/ } else { adapter = new InfinitePagerAdapter(this, new int[] { R.drawable.defaultimage }); length = 1; defaultImage.setVisibility(View.GONE); } adapter.setPageClickListener(new MyPageClickListener()); adapter.setURLErrorListener(this); topViewPager.setAdapter(adapter); imageViews = new ImageView[length]; ImageView imageView = null; dotLayout.removeAllViews(); LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams((int) (8 * screenDensity), (int) (4 * screenDensity)); dotLayout.addView(new TextView(this), textParams); // ? for (int i = 0; i < length; i++) { imageView = new ImageView(this); // ?imageview? imageView.setLayoutParams(new LayoutParams((int) (6 * screenDensity), (int) (6 * screenDensity)));// ?20 // // ?layout imageView.setBackgroundResource(R.drawable.enroll_school_dot_selector); imageViews[i] = imageView; // ??? if (i == 0) { imageView.setEnabled(true); } else { imageView.setEnabled(false); } // imageviews? dotLayout.addView(imageViews[i]); dotLayout.addView(new TextView(this), textParams); } }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
private View makeHeader(ViewGroup parent, boolean button, float density) { if (C.API_LOLLIPOP) { LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); View divider = makeSimpleDivider(); int paddingTop = divider.getPaddingBottom(); divider.setPadding(divider.getPaddingLeft(), divider.getPaddingTop(), divider.getPaddingRight(), 0); linearLayout.addView(divider, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); TextView textView = makeCommonTextView(true); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, (int) (32f * density), 1); layoutParams.setMargins((int) (16f * density), paddingTop, (int) (16f * density), (int) (8f * density)); linearLayout2.addView(textView, layoutParams); ViewHolder holder = new ViewHolder(); holder.text = textView;/* w w w. jav a 2 s .co m*/ if (button) { ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setBackgroundResource(ResourceUtils.getResourceId(context, android.R.attr.borderlessButtonStyle, android.R.attr.background, 0)); imageView.setOnClickListener(headerButtonListener); imageView.setImageAlpha(0x5e); int size = (int) (48f * density); layoutParams = new LinearLayout.LayoutParams(size, size); layoutParams.rightMargin = (int) (4f * density); linearLayout2.addView(imageView, layoutParams); holder.extra = imageView; holder.icon = imageView; } linearLayout.setTag(holder); return linearLayout; } else { View view = LayoutInflater.from(context) .inflate(ResourceUtils.getResourceId(context, android.R.attr.preferenceCategoryStyle, android.R.attr.layout, android.R.layout.preference_category), parent, false); ViewHolder holder = new ViewHolder(); holder.text = (TextView) view.findViewById(android.R.id.title); if (button) { int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); view.measure(measureSpec, measureSpec); int size = view.getMeasuredHeight(); if (size == 0) { size = (int) (32f * density); } FrameLayout frameLayout = new FrameLayout(context); frameLayout.addView(view); view = frameLayout; ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); int padding = (int) (4f * density); imageView.setPadding(padding, padding, padding, padding); frameLayout.addView(imageView, new FrameLayout.LayoutParams((int) (48f * density), size, Gravity.END)); View buttonView = new View(context); buttonView.setBackgroundResource( ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0)); buttonView.setOnClickListener(headerButtonListener); frameLayout.addView(buttonView, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); holder.extra = buttonView; holder.icon = imageView; } view.setTag(holder); return view; } }
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;//from ww w . ja v a2 s . com 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.liangxun.university.huanxin.chat.activity.ChatActivity.java
/** * ?// w w w. ja va2 s .com */ private void Init_Point() { pointViews = new ArrayList<ImageView>(); ImageView imageView; for (int i = 0; i < views.size(); i++) { imageView = new ImageView(this); imageView.setBackgroundResource(R.drawable.d1); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(new ViewGroup.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); layoutParams.leftMargin = 10; layoutParams.rightMargin = 10; layoutParams.width = 8; layoutParams.height = 8; layout_point.addView(imageView, layoutParams); // if (i == 0 || i == views.size() - 1) { // imageView.setVisibility(View.GONE); // } if (i == 0) { imageView.setBackgroundResource(R.drawable.d2); } pointViews.add(imageView); } }
From source file:com.cnm.cnmrc.fragment.rc.RcBase.java
/** * Loading TapPressAnimation <br>//from w w w . j a v a 2 s. c o m */ protected void startLoadingAni(ImageButton view, final ImageView animView) { if (view != null) { view.post(new Runnable() { @Override public void run() { try { mTapPressAnimation = new AnimationDrawable(); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress01), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress02), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress03), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress04), 60); mTapPressAnimation.setOneShot(true); animView.setImageDrawable(mTapPressAnimation); // API 2.3.4? ?... ??? // animView.setBackgroundResource(R.drawable.anim_tappress); // mTapPressAnimation = (AnimationDrawable) // animView.getBackground(); mTapPressDuration = 0; for (int i = 0; i < mTapPressAnimation.getNumberOfFrames(); i++) { mTapPressDuration += mTapPressAnimation.getDuration(i); } animView.setVisibility(View.VISIBLE); // Start the animation (looped playback by default). mTapPressAnimation.start(); mHandler.postDelayed(new Runnable() { public void run() { mTapPressAnimation.stop(); mTapPressAnimation = null; animView.setBackgroundResource(0); animView.setVisibility(View.INVISIBLE); oneClickTapPress = true; } }, mTapPressDuration); } catch (Exception e) { e.getStackTrace(); } } }); } //view.post(new Starter()); }
From source file:org.naturenet.ui.MainActivity.java
/** * Sets the gallery of recent images when the user selects 'add observation' button. *//*from w w w . ja v a 2 s .com*/ public void setGallery() { Picasso.with(MainActivity.this).cancelTag(ImageGalleryAdapter.class.getSimpleName()); recentImageGallery = getRecentImagesUris(); if (recentImageGallery.size() != 0) { gridview.setAdapter(new ImageGalleryAdapter(this, recentImageGallery)); //Here we handle clicks to the recent images. Let user select as many images as they want to submit. gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ImageView iv = (ImageView) v.findViewById(R.id.gallery_iv); //if the image the user selects hasn't been selected yet if (!selectedImages.contains(recentImageGallery.get(position))) { //add the clicked image to the selectedImages List selectedImages.add(recentImageGallery.get(position)); iv.setBackground( ContextCompat.getDrawable(MainActivity.this, R.drawable.border_selected_image)); select.setVisibility(View.VISIBLE); //here we handle the case of selecting an image that's already been selected } else if (selectedImages.contains(recentImageGallery.get(position))) { selectedImages.remove(recentImageGallery.get(position)); iv.setBackgroundResource(0); } //check to see if there are no selected images. if so, make select button 'unselectable' if (selectedImages.size() == 0) select.setVisibility(View.GONE); } }); } }
From source file:com.cnm.cnmrc.fragment.RcChannelVolume.java
/** * Loading TapPressAnimation <br>// w w w . ja va 2s . c o m */ private void startLoadingAni(ImageButton view, final ImageView animView) { if (view != null) { view.post(new Runnable() { @Override public void run() { try { mTapPressAnimation = new AnimationDrawable(); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress01), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress02), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress03), 60); mTapPressAnimation.addFrame(getResources().getDrawable(R.drawable.tappress04), 60); mTapPressAnimation.setOneShot(true); animView.setImageDrawable(mTapPressAnimation); // API 2.3.4? ?... ??? // animView.setBackgroundResource(R.drawable.anim_tappress); // mTapPressAnimation = (AnimationDrawable) // animView.getBackground(); mTapPressDuration = 0; for (int i = 0; i < mTapPressAnimation.getNumberOfFrames(); i++) { mTapPressDuration += mTapPressAnimation.getDuration(i); } animView.setVisibility(View.VISIBLE); // Start the animation (looped playback by default). mTapPressAnimation.start(); mHandler.postDelayed(new Runnable() { public void run() { mTapPressAnimation.stop(); mTapPressAnimation = null; animView.setBackgroundResource(0); animView.setVisibility(View.INVISIBLE); oneClickTapPress = true; } }, mTapPressDuration); } catch (Exception e) { e.getStackTrace(); } } }); } //view.post(new Starter()); }
From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java
private void setOrAnimateReadPubIcon(final ImageView imageView, PublicationState currentState, boolean allowAnimate) { final int imageResId = currentState.equals(PublicationState.READY_FOR_READING) ? R.drawable.read_pub_button_icon_checked : currentState.equals(PublicationState.DOWNLOADING) ? R.drawable.download_pub_icon_fab_up : R.drawable.read_pub_button_icon_unchecked; if (imageView.getTag() != null) { if (imageView.getTag() instanceof Animator) { Animator anim = (Animator) imageView.getTag(); anim.end();//from ww w. ja va 2 s .c o m ViewHelper.setAlpha(imageView, 1f); } } /* if (imageView.getBackground() instanceof AnimationDrawable) { AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground(); frameAnimation.stop(); imageView.setBackgroundResource(0); }*/ if (allowAnimate && currentState.equals(PublicationState.DOWNLOADING)) { int duration = getResources().getInteger(android.R.integer.config_shortAnimTime); Animator outAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 0f); outAnimator.setDuration(duration); outAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageDrawable(null); imageView.setBackgroundResource(imageResId); Drawable frameAnimation = imageView.getBackground(); if (frameAnimation instanceof AnimationDrawable) { ((AnimationDrawable) frameAnimation).start(); } } }); ObjectAnimator inAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 1f); inAnimator.setDuration(duration * 2); final AnimatorSet set = new AnimatorSet(); set.playSequentially(outAnimator, inAnimator); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setTag(null); } }); imageView.setTag(set); set.start(); } else if (allowAnimate && currentState.equals(PublicationState.READY_FOR_READING)) { int duration = getResources().getInteger(android.R.integer.config_shortAnimTime); Animator outAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 0f); outAnimator.setDuration(duration); outAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setBackgroundResource(0); imageView.setImageResource(imageResId); } }); ObjectAnimator inAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 1f); inAnimator.setDuration(duration * 2); final AnimatorSet set = new AnimatorSet(); set.playSequentially(outAnimator, inAnimator); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setTag(null); } }); imageView.setTag(set); set.start(); } else if (!allowAnimate && currentState.equals(PublicationState.DOWNLOADING)) { mHandler.post(new Runnable() { @Override public void run() { imageView.setImageDrawable(null); imageView.setBackgroundResource(imageResId); AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground(); frameAnimation.start(); } }); } else { mHandler.post(new Runnable() { @Override public void run() { imageView.setBackgroundResource(0); imageView.setImageResource(imageResId); } }); } }
From source file:com.haomee.chat.activity.ChatActivity.java
/** * /* w w w.j av a 2 s. c om*/ */ private void init_new_emotions(final String path) { File file = new File(emotions_base_path); File[] files = file.listFiles();// ? for (File f : files) { if (path == null) { return; } if (f == null) { return; } if (!file.exists() || !file.isDirectory()) { return; } // if (f.listFiles().length == 0) { // return; // } if (path.equals(f.getName())) {// ?? File[] file_image_list = f.listFiles(); image_path = new ArrayList<String>(); image_name = new ArrayList<String>(); if (file_image_list == null) { return; } for (int j = 0; j < file_image_list.length; j++) { File file_image = file_image_list[j]; try { String newFileName = new String(file_image.getName().getBytes(), "UTF-8"); if (newFileName.contains(big_cover_name) || newFileName.contains(simall_cover_name)) { // final ImageView iv_bottom_emotion = new ImageView(ChatActivity.this); Bitmap decodeFile = BitmapFactory.decodeFile(file_image.getAbsolutePath()); iv_bottom_emotion.setImageBitmap(decodeFile); int screen_width = ViewUtil.getScreenWidth(ChatActivity.this); layoutParams.width = screen_width / 8; layoutParams.height = screen_width / 8; iv_bottom_emotion.setLayoutParams(layoutParams); iv_bottom_emotion.setBackgroundResource(R.drawable.grid_line); iv_bottom_emotion.setTag(path); // imag_list.add(iv_bottom_emotion); imag_list.add(0, iv_bottom_emotion); iv_bottom_emotion.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub selected_pager = (String) iv_bottom_emotion.getTag(); iv_expression_emoji.setBackgroundResource(R.drawable.grid_line); for (ImageView iv : imag_list) { if (selected_pager.equals(iv.getTag())) { iv.setBackgroundResource(R.drawable.grid_line_press); } else { iv.setBackgroundResource(R.drawable.grid_line); } } search_selected_emotions((String) iv_bottom_emotion.getTag()); } }); ll_emotions_content.addView(iv_bottom_emotion); viewpager.setTag(tab_emotions_tag);// ? } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addNextImages(int level, boolean recycle) { if (level < BACKGROUNDS.length) { // Add the background image ImageView iv = new ImageView(this); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); // This is being background loaded. Should already be loaded, but if not, wait. while (mBackgrounds[level] == null) { synchronized (mBackgrounds) { if (mBackgrounds[level] == null) { try { mBackgrounds.wait(); } catch (InterruptedException e) { }/* www . j a v a 2 s .c o m*/ } } } iv.setImageBitmap(mBackgrounds[level]); if (recycle) { iv.setTag(new Pair<Integer, Integer>(0, level)); } LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mBackgroundLayout.addView(iv, lp); iv = new ImageView(this); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (recycle) { iv.setTag(new Pair<Integer, Integer>(0, level)); } iv.setImageBitmap(mBackgrounds2[level]); mBackgroundLayout.addView(iv, lp); // Add the foreground image if (FOREGROUNDS[level] == -1) { View view = new View(this); lp = new LinearLayout.LayoutParams(mScreenWidth * 2, 10); mForegroundLayout.addView(view, lp); } else { iv = new ImageView(this); iv.setBackgroundResource(R.drawable.img_snow_ground_tiles); if (recycle) { iv.setTag(level); } lp = new LinearLayout.LayoutParams(mScreenWidth * 2, LinearLayout.LayoutParams.WRAP_CONTENT); mForegroundLayout.addView(iv, lp); iv = new ImageView(this); if (recycle) { iv.setTag(level); } iv.setBackgroundResource(R.drawable.img_snow_ground_tiles); mForegroundLayout.addView(iv, lp); } } }