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.gdgdevfest.android.apps.devfestbcn.ui.SessionDetailFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) {
    if (UIUtils.hasICS() && imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();/*  w w w.jav  a  2s  .c  o  m*/
            imageView.setAlpha(1f);
        }
    }

    animate = animate && UIUtils.hasICS();
    if (animate) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        outAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        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 {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:com.linkedin.android.eventsapp.AttendeeAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.attendee_list_item, parent, false);
    TextView attendeeNameView = (TextView) rowView.findViewById(R.id.attendeeName);
    final TextView attendeeHeadlineView = (TextView) rowView.findViewById(R.id.attendeeHeadline);
    final ImageView attendeeImageView = (ImageView) rowView.findViewById(R.id.attendeeImage);

    Person attendee = attendees[position];
    attendeeNameView.setText(attendee.getFirstName() + " " + attendee.getLastName());

    boolean isAccessTokenValid = LISessionManager.getInstance(context).getSession().isValid();
    if (isAccessTokenValid) {
        String url = Constants.personByIdBaseUrl + attendee.getLinkedinId() + Constants.personProjection;
        //LISession liSession = LISessionManager.getInstance(context).getSession()
        APIHelper.getInstance(context).getRequest(context, url, new ApiListener() {
            @Override//from   w  w w .  j  a va 2s . c o  m
            public void onApiSuccess(ApiResponse apiResponse) {
                try {
                    JSONObject dataAsJson = apiResponse.getResponseDataAsJson();
                    String headline = dataAsJson.has("headline") ? dataAsJson.getString("headline") : "";
                    String pictureUrl = dataAsJson.has("pictureUrl") ? dataAsJson.getString("pictureUrl")
                            : null;
                    JSONObject location = dataAsJson.getJSONObject("location");

                    attendeeHeadlineView.setText(headline);
                    if (pictureUrl != null) {
                        new com.linkedin.android.eventsapp.FetchImageTask(attendeeImageView)
                                .execute(pictureUrl);
                    } else {
                        attendeeImageView.setImageResource(R.drawable.ghost_person);
                    }
                } catch (JSONException e) {

                }

            }

            @Override
            public void onApiError(LIApiError apiError) {

            }
        });
    } else {
        attendeeImageView.setImageResource(R.drawable.ghost_person);
    }

    return rowView;
}

From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java

private void downloadProfilePicture(final String profileId, Uri pictureUri, final ImageView imageView) {
    if (pictureUri == null) {
        return;//from   w ww  .ja  v  a 2  s.  c o  m
    }

    // If we don't have an imageView, we are pre-fetching this image to store in-memory because we
    // think the user might scroll to its corresponding list row. If we do have an imageView, we
    // only want to queue a download if the view's tag isn't already set to the URL (which would mean
    // it's already got the correct picture).
    boolean prefetching = imageView == null;
    if (prefetching || !pictureUri.equals(imageView.getTag())) {
        if (!prefetching) {
            // Setting the tag to the profile ID indicates that we're currently downloading the
            // picture for this profile; we'll set it to the actual picture URL when complete.
            imageView.setTag(profileId);
            imageView.setImageResource(getDefaultPicture());
        }

        ImageRequest.Builder builder = new ImageRequest.Builder(context.getApplicationContext(), pictureUri)
                .setCallerTag(this).setCallback(new ImageRequest.Callback() {
                    @Override
                    public void onCompleted(ImageResponse response) {
                        processImageResponse(response, profileId, imageView);
                    }
                });

        ImageRequest newRequest = builder.build();
        pendingRequests.put(profileId, newRequest);

        ImageDownloader.downloadAsync(newRequest);
    }
}

From source file:com.trk.aboutme.facebook.widget.GraphObjectAdapter.java

private void downloadProfilePicture(final String profileId, URL pictureURL, final ImageView imageView) {
    if (pictureURL == null) {
        return;/*from   w  w  w .  ja  v a 2  s  .c om*/
    }

    // If we don't have an imageView, we are pre-fetching this image to store in-memory because we
    // think the user might scroll to its corresponding list row. If we do have an imageView, we
    // only want to queue a download if the view's tag isn't already set to the URL (which would mean
    // it's already got the correct picture).
    boolean prefetching = imageView == null;
    if (prefetching || !pictureURL.equals(imageView.getTag())) {
        if (!prefetching) {
            // Setting the tag to the profile ID indicates that we're currently downloading the
            // picture for this profile; we'll set it to the actual picture URL when complete.
            imageView.setTag(profileId);
            imageView.setImageResource(getDefaultPicture());
        }

        ImageRequest.Builder builder = new ImageRequest.Builder(context.getApplicationContext(), pictureURL)
                .setCallerTag(this).setCallback(new ImageRequest.Callback() {
                    @Override
                    public void onCompleted(ImageResponse response) {
                        processImageResponse(response, profileId, imageView);
                    }
                });

        ImageRequest newRequest = builder.build();
        pendingRequests.put(profileId, newRequest);

        ImageDownloader.downloadAsync(newRequest);
    }
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

public DrawerForm(Context context, Context unstyledContext, Callback callback,
        WatcherService.Client watcherServiceClient) {
    this.context = context;
    this.unstyledContext = unstyledContext;
    this.callback = callback;
    this.watcherServiceClient = watcherServiceClient;
    float density = ResourceUtils.obtainDensity(context);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setLayoutParams(new SortableListView.LayoutParams(SortableListView.LayoutParams.MATCH_PARENT,
            SortableListView.LayoutParams.WRAP_CONTENT));
    LinearLayout editTextContainer = new LinearLayout(context);
    editTextContainer.setGravity(Gravity.CENTER_VERTICAL);
    linearLayout.addView(editTextContainer);
    searchEdit = new SafePasteEditText(context);
    searchEdit.setOnKeyListener((v, keyCode, event) -> {
        if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
            v.clearFocus();/* ww  w.  j  av  a  2s  .co  m*/
        }
        return false;
    });
    searchEdit.setHint(context.getString(R.string.text_code_number_address));
    searchEdit.setOnEditorActionListener(this);
    searchEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    searchEdit.setImeOptions(EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    ImageView searchIcon = new ImageView(context, null, android.R.attr.buttonBarButtonStyle);
    searchIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonForward, 0));
    searchIcon.setScaleType(ImageView.ScaleType.CENTER);
    searchIcon.setOnClickListener(this);
    editTextContainer.addView(searchEdit,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    editTextContainer.addView(searchIcon, (int) (40f * density), (int) (40f * density));
    if (C.API_LOLLIPOP) {
        editTextContainer.setPadding((int) (12f * density), (int) (8f * density), (int) (8f * density), 0);
    } else {
        editTextContainer.setPadding(0, (int) (2f * density), (int) (4f * density), (int) (2f * density));
    }
    LinearLayout selectorContainer = new LinearLayout(context);
    selectorContainer.setBackgroundResource(
            ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0));
    selectorContainer.setOrientation(LinearLayout.HORIZONTAL);
    selectorContainer.setGravity(Gravity.CENTER_VERTICAL);
    selectorContainer.setOnClickListener(v -> {
        hideKeyboard();
        setChanSelectMode(!chanSelectMode);
    });
    linearLayout.addView(selectorContainer);
    selectorContainer.setMinimumHeight((int) (40f * density));
    if (C.API_LOLLIPOP) {
        selectorContainer.setPadding((int) (16f * density), 0, (int) (16f * density), 0);
        ((LinearLayout.LayoutParams) selectorContainer.getLayoutParams()).topMargin = (int) (4f * density);
    } else {
        selectorContainer.setPadding((int) (8f * density), 0, (int) (12f * density), 0);
    }
    chanNameView = new TextView(context, null, android.R.attr.textAppearanceListItem);
    chanNameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f);
    if (C.API_LOLLIPOP) {
        chanNameView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
    } else {
        chanNameView.setFilters(new InputFilter[] { new InputFilter.AllCaps() });
    }
    selectorContainer.addView(chanNameView,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    chanSelectorIcon = new ImageView(context);
    chanSelectorIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonDropDownDrawer, 0));
    selectorContainer.addView(chanSelectorIcon, (int) (24f * density), (int) (24f * density));
    ((LinearLayout.LayoutParams) chanSelectorIcon.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL
            | Gravity.END;
    headerView = linearLayout;
    inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    chans.add(new ListItem(ListItem.ITEM_DIVIDER, 0, 0, null));
    int color = ResourceUtils.getColor(context, R.attr.drawerIconColor);
    ChanManager manager = ChanManager.getInstance();
    Collection<String> availableChans = manager.getAvailableChanNames();
    for (String chanName : availableChans) {
        ChanConfiguration configuration = ChanConfiguration.get(chanName);
        if (configuration.getOption(ChanConfiguration.OPTION_READ_POSTS_COUNT)) {
            watcherSupportSet.add(chanName);
        }
        Drawable drawable = manager.getIcon(chanName, color);
        chanIcons.put(chanName, drawable);
        chans.add(
                new ListItem(ListItem.ITEM_CHAN, chanName, null, null, configuration.getTitle(), 0, drawable));
    }
    if (availableChans.size() == 1) {
        selectorContainer.setVisibility(View.GONE);
    }
}

From source file:com.devwang.logcabin.LogCabinMainActivity.java

private void toastDisplay(Context context, CharSequence text, int gravity, int ResImgId, int duration) {
    Toast toast = Toast.makeText(context, text, duration);
    if (gravity != 0) {
        switch (gravity) {
        case Gravity.CENTER:
            toast.setGravity(Gravity.CENTER, 0, 0);//  x,y0
            break;
        case Gravity.FILL:
            toast.setGravity(Gravity.FILL, 0, 0);//  x,y0
            break;
        case Gravity.BOTTOM:
            toast.setGravity(Gravity.BOTTOM, 0, 0);
            break;
        default:/*from   ww w  .  ja  v  a  2s.c  o  m*/
            break;
        }
    }
    if (ResImgId != 0) {
        LinearLayout toastView = (LinearLayout) toast.getView();
        ImageView imageCodeProject = new ImageView(getApplicationContext());
        imageCodeProject.setImageResource(ResImgId);
        toastView.addView(imageCodeProject, 0);
    }

    toast.show();
}

From source file:com.facebook.widget.GraphObjectAdapter.java

private void downloadProfilePicture(final String profileId, URI pictureURI, final ImageView imageView) {
    if (pictureURI == null) {
        return;/*  w ww.jav a 2  s . co  m*/
    }

    // If we don't have an imageView, we are pre-fetching this image to store in-memory because we
    // think the user might scroll to its corresponding list row. If we do have an imageView, we
    // only want to queue a download if the view's tag isn't already set to the URL (which would mean
    // it's already got the correct picture).
    boolean prefetching = imageView == null;
    if (prefetching || !pictureURI.equals(imageView.getTag())) {
        if (!prefetching) {
            // Setting the tag to the profile ID indicates that we're currently downloading the
            // picture for this profile; we'll set it to the actual picture URL when complete.
            imageView.setTag(profileId);
            imageView.setImageResource(getDefaultPicture());
        }

        ImageRequest.Builder builder = new ImageRequest.Builder(context.getApplicationContext(), pictureURI)
                .setCallerTag(this).setCallback(new ImageRequest.Callback() {
                    @Override
                    public void onCompleted(ImageResponse response) {
                        processImageResponse(response, profileId, imageView);
                    }
                });

        ImageRequest newRequest = builder.build();
        pendingRequests.put(profileId, newRequest);

        ImageDownloader.downloadAsync(newRequest);
    }
}

From source file:com.jins_meme.bridge.MainActivity.java

void changeSettingButton(final boolean isRev) {
    final String overflowDesc = getString(R.string.accessibility_overflow);

    final ViewGroup decor = (ViewGroup) getWindow().getDecorView();

    decor.post(new Runnable() {
        @Override/*from w ww.j  a  v a2 s  .c o  m*/
        public void run() {
            final ArrayList<View> outViews = new ArrayList<>();

            decor.findViewsWithText(outViews, overflowDesc, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);

            if (outViews.isEmpty()) {
                return;
            }

            ImageView overflow = (ImageView) outViews.get(0);
            if (isRev) {
                overflow.setImageResource(R.mipmap.ic_setting_rev);
            } else {
                overflow.setImageResource(R.mipmap.ic_setting);
            }
        }
    });
}

From source file:com.mishiranu.dashchan.ui.navigator.page.PostsPage.java

@Override
protected void onCreate() {
    Activity activity = getActivity();/*from   ww w. j  a v a 2  s  .c  o  m*/
    PullableListView listView = getListView();
    PageHolder pageHolder = getPageHolder();
    UiManager uiManager = getUiManager();
    hidePerformer = new HidePerformer();
    PostsExtra extra = getExtra();
    listView.setDivider(ResourceUtils.getDrawable(activity, R.attr.postsDivider, 0));
    ChanConfiguration.Board board = getChanConfiguration().safe().obtainBoard(pageHolder.boardName);
    if (board.allowPosting) {
        replyable = data -> getUiManager().navigator().navigatePosting(pageHolder.chanName,
                pageHolder.boardName, pageHolder.threadNumber, data);
    }
    PostsAdapter adapter = new PostsAdapter(activity, pageHolder.chanName, pageHolder.boardName, uiManager,
            replyable, hidePerformer, extra.userPostNumbers, listView);
    initAdapter(adapter, adapter);
    ImageLoader.getInstance().observable().register(this);
    listView.getWrapper().setPullSides(PullableWrapper.Side.BOTH);
    uiManager.observable().register(this);
    hidePerformer.setPostsProvider(adapter);

    Context darkStyledContext = new ContextThemeWrapper(activity, R.style.Theme_General_Main_Dark);
    searchController = new LinearLayout(darkStyledContext);
    searchController.setOrientation(LinearLayout.HORIZONTAL);
    searchController.setGravity(Gravity.CENTER_VERTICAL);
    float density = ResourceUtils.obtainDensity(getResources());
    int padding = (int) (10f * density);
    searchTextResult = new Button(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
    searchTextResult.setTextSize(11f);
    if (!C.API_LOLLIPOP) {
        searchTextResult.setTypeface(null, Typeface.BOLD);
    }
    searchTextResult.setPadding((int) (14f * density), 0, (int) (14f * density), 0);
    searchTextResult.setMinimumWidth(0);
    searchTextResult.setMinWidth(0);
    searchTextResult.setOnClickListener(v -> showSearchDialog());
    searchController.addView(searchTextResult, LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    ImageView backButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
    backButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    backButtonView.setImageResource(obtainIcon(R.attr.actionBack));
    backButtonView.setPadding(padding, padding, padding, padding);
    backButtonView.setOnClickListener(v -> findBack());
    searchController.addView(backButtonView, (int) (48f * density), (int) (48f * density));
    ImageView forwardButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
    forwardButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    forwardButtonView.setImageResource(obtainIcon(R.attr.actionForward));
    forwardButtonView.setPadding(padding, padding, padding, padding);
    forwardButtonView.setOnClickListener(v -> findForward());
    searchController.addView(forwardButtonView, (int) (48f * density), (int) (48f * density));
    if (C.API_LOLLIPOP) {
        for (int i = 0, last = searchController.getChildCount() - 1; i <= last; i++) {
            View view = searchController.getChildAt(i);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            if (i == 0) {
                layoutParams.leftMargin = (int) (-6f * density);
            }
            if (i == last) {
                layoutParams.rightMargin = (int) (6f * density);
            } else {
                layoutParams.rightMargin = (int) (-6f * density);
            }
        }
    }

    scrollToPostNumber = pageHolder.initialPostNumber;
    FavoritesStorage.getInstance().getObservable().register(this);
    LocalBroadcastManager.getInstance(activity).registerReceiver(galleryPagerReceiver,
            new IntentFilter(C.ACTION_GALLERY_NAVIGATE_POST));
    boolean hasNewPostDatas = handleNewPostDatas();
    extra.forceRefresh = hasNewPostDatas || !pageHolder.initialFromCache;
    if (extra.cachedPosts != null && extra.cachedPostItems.size() > 0) {
        onDeserializePostsCompleteInternal(true, extra.cachedPosts, new ArrayList<>(extra.cachedPostItems),
                true);
    } else {
        deserializeTask = new DeserializePostsTask(this, pageHolder.chanName, pageHolder.boardName,
                pageHolder.threadNumber, extra.cachedPosts);
        deserializeTask.executeOnExecutor(DeserializePostsTask.THREAD_POOL_EXECUTOR);
        getListView().getWrapper().startBusyState(PullableWrapper.Side.BOTH);
        switchView(ViewType.PROGRESS, null);
    }
    pageHolder.setInitialPostsData(false, null);
}

From source file:com.closedevice.fastapp.view.tab.SlidingTabLayout.java

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

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*from  w  w  w .  j  a va 2s  .co  m*/
        TextView tabTitleView = 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);
            if (mTabViewTextViewId != 0) {
                tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);

            }
        }

        ImageView tabIconView = null;
        if (mTabViewIconId != 0 && mIconListener != null) {
            tabIconView = (ImageView) tabView.findViewById(mTabViewIconId);
        }

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

        if (tabView != null && i == 1) {
            //mTvMessageCount = (TextView) tabView.findViewById(R.id.tv_unread_count);
        }

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

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (tabTitleView != null)
            tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        if (tabIconView != null) {
            int icon = mIconListener.getPageIcon(i);
            if (icon != 0)
                tabIconView.setImageResource(icon);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}