Example usage for android.widget ImageView setImageResource

List of usage examples for android.widget ImageView setImageResource

Introduction

In this page you can find the example usage for android.widget ImageView setImageResource.

Prototype

@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync")
public void setImageResource(@DrawableRes int resId) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:com.example.mindhelper.mindhelper.SlidingTabLayout.java

private void populateTabStrip() {
    final TabFragmentPagerAdapter adapter = (TabFragmentPagerAdapter) mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/* w ww  . j  a  v  a 2 s.  c o m*/
        TextView tabTitleView = null;
        ImageView tabIcon = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
            tabIcon = (ImageView) tabView.findViewById(mTabViewIconId);
        }

        if (tabIcon != null) {
            tabIcon.setImageResource(adapter.getIconResId(i));
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:com.githang.androidkit.app.IntroActivity.java

/**
 * /*  ww w .j  a va2 s  .  com*/
 */
private void createContentView() {
    // ?
    mIntroResource = new IntroResource();
    setIntroViews(mIntroResource);

    // 
    RelativeLayout rootView = new RelativeLayout(this);
    rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    // 
    mViewPager = new ViewPager(this);
    RelativeLayout.LayoutParams pagerParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    rootView.addView(mViewPager, pagerParams);

    // 
    LinearLayout indicatorLayout = new LinearLayout(this);
    RelativeLayout.LayoutParams indicatorParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    indicatorParams.bottomMargin = mIntroResource.indicatorMarginBottom;
    indicatorParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    indicatorParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    indicatorLayout.setLayoutParams(indicatorParams);
    indicatorLayout.setOrientation(LinearLayout.HORIZONTAL);

    // 
    int indicatorCount = mIntroResource.views.size();
    int padding = mIntroResource.indicatorImagePadding;
    mIndicator = new ArrayList<ImageView>();
    for (int i = 0; i < indicatorCount; i++) {
        ImageView imageView = new ImageView(this);
        LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        imageView.setPadding(padding, padding, padding, padding);
        imageView.setClickable(true);
        imageView.setOnClickListener(this);
        imageView.setImageResource(mIntroResource.indicatorNoSelectedId);
        imageView.setTag(i);
        mIndicator.add(imageView);
        indicatorLayout.addView(imageView, imageParams);
    }

    rootView.addView(indicatorLayout);

    setContentView(rootView);
}

From source file:com.lurencun.cfuture09.androidkit.uilibs.IntroActivity.java

/**
 * /*from   ww w.  ja va2 s. com*/
 */
private void createContentView() {
    // ?
    mIntroResource = new IntroResource();
    setIntroViews(mIntroResource);

    // 
    RelativeLayout rootView = new RelativeLayout(this);
    rootView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    // 
    mViewPager = new ViewPager(this);
    RelativeLayout.LayoutParams pagerParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    rootView.addView(mViewPager, pagerParams);

    // 
    LinearLayout indicatorLayout = new LinearLayout(this);
    RelativeLayout.LayoutParams indicatorParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    indicatorParams.bottomMargin = mIntroResource.indicatorMarginBottom;
    indicatorParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    indicatorParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    indicatorLayout.setLayoutParams(indicatorParams);
    indicatorLayout.setOrientation(LinearLayout.HORIZONTAL);

    // 
    int indicatorCount = mIntroResource.views.size();
    int padding = mIntroResource.indicatorImagePadding;
    mIndicator = new ArrayList<ImageView>();
    for (int i = 0; i < indicatorCount; i++) {
        ImageView imageView = new ImageView(this);
        LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        imageView.setPadding(padding, padding, padding, padding);
        imageView.setClickable(true);
        imageView.setOnClickListener(this);
        imageView.setImageResource(mIntroResource.indicatorNoSelectedId);
        imageView.setTag(i);
        mIndicator.add(imageView);
        indicatorLayout.addView(imageView, imageParams);
    }

    rootView.addView(indicatorLayout);

    setContentView(rootView);
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

private void addNewItem(Menu menu, int group, int order, @StringRes int text, MenuMetadata meta,
        @DrawableRes int icon, @DrawableRes Integer actionViewIcon) {
    if (BuildConfig.DEBUG && menu.findItem(order) != null)
        throw new IllegalStateException("Item already id exists: " + order);

    MenuItem item = menu.add(group, order, order, text).setIcon(icon);
    dataUtils.putDrawerMetadata(item, meta);
    if (actionViewIcon != null) {
        item.setActionView(R.layout.layout_draweractionview);

        ImageView imageView = item.getActionView().findViewById(R.id.imageButton);
        imageView.setImageResource(actionViewIcon);
        if (!mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
            imageView.setColorFilter(Color.WHITE);
        }//from  w  w w  .  j  ava  2  s . c  o m

        item.getActionView().setOnClickListener((view) -> onNavigationItemActionClick(item));
    }
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

private void addNewItem(Menu menu, int group, int order, String text, MenuMetadata meta, @DrawableRes int icon,
        @DrawableRes Integer actionViewIcon) {
    if (BuildConfig.DEBUG && menu.findItem(order) != null)
        throw new IllegalStateException("Item already id exists: " + order);

    MenuItem item = menu.add(group, order, order, text).setIcon(icon);
    dataUtils.putDrawerMetadata(item, meta);

    if (actionViewIcon != null) {
        item.setActionView(R.layout.layout_draweractionview);

        ImageView imageView = item.getActionView().findViewById(R.id.imageButton);
        imageView.setImageResource(actionViewIcon);
        if (!mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
            imageView.setColorFilter(Color.WHITE);
        }/*from   ww w  .  j ava2  s  . co  m*/

        item.getActionView().setOnClickListener((view) -> onNavigationItemActionClick(item));
    }
}

From source file:android.support.v7.widget.SuggestionsAdapter.java

/**
 * Tags the view with cached child view look-ups.
 *///ww  w.  j  a va 2  s .  co m
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    final View v = super.newView(context, cursor, parent);
    v.setTag(new ChildViewCache(v));

    // Set up icon.
    final ImageView iconRefine = (ImageView) v.findViewById(R.id.edit_query);
    iconRefine.setImageResource(mCommitIconResId);
    return v;
}

From source file:org.hfoss.posit.android.functionplugin.reminder.SetReminder.java

/**
 * Called from FindActivity.onActivityResult(). Used to 
 * update the Find's View, specifically the date, lat, long,
 * and alarm icon fields.//from   w  ww . ja v  a 2  s.  co  m
 * 
 * @param context, the calling Activity
 * @param find, the current Find
 * @param view, the FindActivity's content view
 * @param intent, the Intent that is passed to the menu activity
 */
public void onActivityResultCallback(Context context, Find find, View view, Intent intent) {
    Log.i(TAG, "onActivityResultCallbac");
    // Intent is NOT null, meaning it includes reminder
    // date and location information set by the user
    if (intent != null) {
        Bundle bundle = intent.getExtras();

        // Get date, longitude, and latitude
        String date = bundle.getString(Find.TIME);
        Double longitude = bundle.getDouble(Find.LONGITUDE);
        Double latitude = bundle.getDouble(Find.LATITUDE);

        TextView tv = (TextView) view.findViewById(R.id.isAdhocTextView);

        Integer is_adhoc = bundle.getInt(Find.IS_ADHOC);
        Log.i(TAG, "is_adhoc = " + is_adhoc);
        if (tv != null) {
            Log.i(TAG, "Setting isAdhocTextView to " + is_adhoc);
            tv.setText("" + is_adhoc);
        }

        // Display user specified longitude and latitude
        tv = (TextView) view.findViewById(R.id.longitudeValueTextView);
        tv.setText(String.valueOf(longitude));
        tv = (TextView) view.findViewById(R.id.latitudeValueTextView);
        tv.setText(String.valueOf(latitude));

        // Remove the old row that displays time and replace it
        // with a new row that include an alarm clock icon to
        // visually indicate this find has a reminder attached
        ViewGroup parent = (ViewGroup) view.findViewById(R.id.timeValueTextView).getParent();
        parent.removeAllViews();
        ImageView alarmIcon = new ImageView(context);
        alarmIcon.setImageResource(R.drawable.reminder_alarm);
        TableRow.LayoutParams lp1 = new TableRow.LayoutParams(30, 30);
        lp1.setMargins(0, 6, 80, 0);
        parent.addView(alarmIcon, lp1);
        TextView mCloneTimeTV = new TextView(context);
        mCloneTimeTV.setId(R.id.timeValueTextView);
        mCloneTimeTV.setText(date);
        mCloneTimeTV.setTextSize(12);
        TextView mTimeTV = (TextView) view.findViewById(R.id.timeValueTextView);
        mTimeTV = mCloneTimeTV;
        TableRow.LayoutParams lp2 = new TableRow.LayoutParams();
        lp2.setMargins(6, 6, 0, 0);
        parent.addView(mTimeTV, lp2);
    }
}

From source file:com.android.inputmethod.keyboard.emoji.EmojiPalettesView.java

private void addTab(final TabHost host, final int categoryId) {
    final String tabId = EmojiCategory.getCategoryName(categoryId, 0 /* categoryPageId */);
    final TabHost.TabSpec tspec = host.newTabSpec(tabId);
    tspec.setContent(R.id.emoji_keyboard_dummy);
    final ImageView iconView = (ImageView) LayoutInflater.from(getContext())
            .inflate(R.layout.emoji_keyboard_tab_icon, null);
    // TODO: Replace background color with its own setting rather than using the
    //       category page indicator background as a workaround.
    iconView.setBackgroundColor(mCategoryPageIndicatorBackground);
    iconView.setImageResource(mEmojiCategory.getCategoryTabIcon(categoryId));
    iconView.setContentDescription(mEmojiCategory.getAccessibilityDescription(categoryId));
    tspec.setIndicator(iconView);//from w  ww .  j a v a  2 s  .  c  o  m
    host.addTab(tspec);
}

From source file:com.kubotaku.android.sample.sensordataviewer.SensorDataActivity.java

private void setupTopBackImage() {
    ImageView topBackImageView = (ImageView) findViewById(R.id.data_view_image_back);
    final int sensorType = channelEntity.getSensorType();
    switch (sensorType) {
    case ChannelEntity.SENSOR_TEMPERATURE: {
        topBackImageView.setImageResource(R.mipmap.ic_temperature);
    }// w w w  . ja  v  a  2  s.  c  o m
        break;

    case ChannelEntity.SENSOR_OCCUPANCY:
        topBackImageView.setImageResource(R.mipmap.ic_occupancy_off);
        break;

    case ChannelEntity.SENSOR_ROCKER_SWITCH:
        topBackImageView.setImageResource(R.mipmap.ic_bell_off);
        break;

    default:
        topBackImageView.setImageResource(R.mipmap.ic_launcher);
        break;
    }
}

From source file:com.negaheno.ui.IntroActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_TMessages);/*from   w ww . j a  v  a2  s.c o  m*/
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (AndroidUtilities.isTablet()) {
        setContentView(R.layout.intro_layout_tablet);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.intro_layout);
    }

    if (LocaleController.isRTL) {
        icons = new int[] { R.drawable.intro7, R.drawable.intro6, R.drawable.intro5, R.drawable.intro4,
                R.drawable.intro3, R.drawable.intro2, R.drawable.intro1 };
        titles = new int[] { R.string.Page7Title, R.string.Page6Title, R.string.Page5Title, R.string.Page4Title,
                R.string.Page3Title, R.string.Page2Title, R.string.Page1Title };
        messages = new int[] { R.string.Page7Message, R.string.Page6Message, R.string.Page5Message,
                R.string.Page4Message, R.string.Page3Message, R.string.Page2Message, R.string.Page1Message };
    } else {
        icons = new int[] { R.drawable.intro1, R.drawable.intro2, R.drawable.intro3, R.drawable.intro4,
                R.drawable.intro5, R.drawable.intro6, R.drawable.intro7 };
        titles = new int[] { R.string.Page1Title, R.string.Page2Title, R.string.Page3Title, R.string.Page4Title,
                R.string.Page5Title, R.string.Page6Title, R.string.Page7Title };
        messages = new int[] { R.string.Page1Message, R.string.Page2Message, R.string.Page3Message,
                R.string.Page4Message, R.string.Page5Message, R.string.Page6Message, R.string.Page7Message };
    }
    viewPager = (ViewPager) findViewById(R.id.intro_view_pager);
    TextView startMessagingButton = (TextView) findViewById(R.id.start_messaging_button);
    startMessagingButton
            .setText(LocaleController.getString("StartMessaging", R.string.StartMessaging).toUpperCase());
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator
                .ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                .setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator
                .ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                .setDuration(200));
        startMessagingButton.setStateListAnimator(animator);
    }
    topImage1 = (ImageView) findViewById(R.id.icon_image1);
    topImage2 = (ImageView) findViewById(R.id.icon_image2);
    bottomPages = (ViewGroup) findViewById(R.id.bottom_pages);
    topImage2.setVisibility(View.GONE);
    viewPager.setAdapter(new IntroAdapter());
    viewPager.setPageMargin(0);
    viewPager.setOffscreenPageLimit(1);
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int i) {

        }

        @Override
        public void onPageScrollStateChanged(int i) {
            if (i == ViewPager.SCROLL_STATE_IDLE || i == ViewPager.SCROLL_STATE_SETTLING) {
                if (lastPage != viewPager.getCurrentItem()) {
                    lastPage = viewPager.getCurrentItem();

                    final ImageView fadeoutImage;
                    final ImageView fadeinImage;
                    if (topImage1.getVisibility() == View.VISIBLE) {
                        fadeoutImage = topImage1;
                        fadeinImage = topImage2;

                    } else {
                        fadeoutImage = topImage2;
                        fadeinImage = topImage1;
                    }

                    fadeinImage.bringToFront();
                    fadeinImage.setImageResource(icons[lastPage]);
                    fadeinImage.clearAnimation();
                    fadeoutImage.clearAnimation();

                    Animation outAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                            R.anim.icon_anim_fade_out);
                    outAnimation.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            fadeoutImage.setVisibility(View.GONE);
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });

                    Animation inAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                            R.anim.icon_anim_fade_in);
                    inAnimation.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                            fadeinImage.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });

                    fadeoutImage.startAnimation(outAnimation);
                    fadeinImage.startAnimation(inAnimation);
                }
            }
        }
    });

    startMessagingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (startPressed) {
                return;
            }
            startPressed = true;
            Intent intent2 = new Intent(IntroActivity.this, LaunchActivity.class);
            intent2.putExtra("fromIntro", true);
            startActivity(intent2);
            finish();
        }
    });

    justCreated = true;
}