Example usage for android.widget ImageView getContext

List of usage examples for android.widget ImageView getContext

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:fr.eoit.util.ImageDownloader.java

/**
 * Same as {@link #download(String, ImageView)}, with the possibility to provide an additional
 * cookie that will be used when the image will be retrieved.
 *
 * @param url The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 * @param cookie A cookie String that will be used by the http connection.
 *///from   w  w w .  java  2  s .  c  o m
public void download(String url, ImageView imageView, String cookie) {
    Bitmap bitmap = getBitmapFromCache(url, imageView.getContext());

    if (bitmap == null) {
        forceDownload(url, imageView, cookie);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.rubengees.introductionsample.MainActivity.java

public void onAsynchronousClick(View view) {
    List<Slide> slides = new ArrayList<>();

    slides.add(0, new Slide().withTitle("Asynchronous")
            .withDescription("The next image will be loaded asynchronously").withColorResource(R.color.purple));
    slides.add(1, new Slide().withTitle("Asynchronous").withDescription("This image was loaded asynchronously")
            .withColorResource(R.color.indigo));

    new IntroductionBuilder(this).withSlides(slides)
            .withOnSlideListener(new IntroductionConfiguration.OnSlideListener() {
                @Override/*from   w ww . jav  a 2s  . c om*/
                protected void onSlideInit(int position, @NonNull TextView title, @NonNull ImageView image,
                        @NonNull TextView description) {
                    if (position == 1) {
                        Glide.with(image.getContext()).load(R.drawable.image3)
                                .diskCacheStrategy(DiskCacheStrategy.NONE).into(image);
                    }
                }
            }).introduceMyself();
}

From source file:com.rubengees.introductionsample.MainActivity.java

public void onRequestPermissionClick(View view) {
    List<Slide> slides = generateSlides();

    slides.add(0,/*  w w  w.  j ava  2 s. com*/
            new Slide().withTitle("Permission Request")
                    .withDescription("You can request permissions with the listener")
                    .withColorResource(R.color.purple));

    new IntroductionBuilder(this).withSlides(slides)
            .withOnSlideListener(new IntroductionConfiguration.OnSlideListener() {
                @Override
                public void onSlideChanged(int from, int to) {
                    if (from == 0 && to == 1) {
                        if (ActivityCompat.checkSelfPermission(MainActivity.this,
                                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                            ActivityCompat.requestPermissions(MainActivity.this,
                                    new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 12);
                        } else {
                            Toast.makeText(MainActivity.this, "Permission is already granted",
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                }

                @Override
                protected void onSlideInit(int position, @NonNull TextView title, @NonNull ImageView image,
                        @NonNull TextView description) {
                    if (position == 2) {
                        Glide.with(image.getContext()).load(R.drawable.image3).into(image);
                    }
                }
            }).introduceMyself();
}

From source file:email.schaal.ocreader.view.drawer.TreeItemDrawerItem.java

@Override
protected void bindViewHelper(BaseViewHolder viewHolder) {
    super.bindViewHelper(viewHolder);

    if (icon != null && icon.getUri() != null) {
        ImageView imageView = getImageView(viewHolder);
        ImageHolder.applyTo(icon, imageView);
    } else if (feed != null) {
        if (feed.isConsideredFailed()) {
            withTextColor(ContextCompat.getColor(viewHolder.itemView.getContext(), R.color.error));
        }//w ww .jav  a 2 s.c  o  m
        ImageView imageView = getImageView(viewHolder);
        imageView.setImageDrawable(FaviconLoader.getDrawable(imageView.getContext(), feed));
    }
}

From source file:com.android.settings.users.EditUserPhotoController.java

public EditUserPhotoController(Fragment fragment, ImageView view, Bitmap bitmap, Drawable drawable,
        boolean waiting) {
    mContext = view.getContext();
    mFragment = fragment;/* w ww.j a  va2  s  .  c  o m*/
    mImageView = view;
    mCropPictureUri = createTempImageUri(mContext, CROP_PICTURE_FILE_NAME, !waiting);
    mTakePictureUri = createTempImageUri(mContext, TAKE_PICTURE_FILE_NAME, !waiting);
    mPhotoSize = getPhotoSize(mContext);
    mImageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showUpdatePhotoPopup();
        }
    });
    mNewUserPhotoBitmap = bitmap;
    mNewUserPhotoDrawable = drawable;
}

From source file:com.poloniumarts.utils.ImageDownloader.java

/**
 * Download the specified image from the Internet and binds it to the
 * provided ImageView. The binding is immediate if the image is found in the
 * cache and will be done asynchronously otherwise. A null bitmap will be
 * associated to the ImageView if an error occurs.
 * //  www  .  j  av  a  2  s .c om
 * @param url
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 */
public void download(String url, ImageView imageView) {
    if (bitmapCachePath == null) {
        if (imageView.getContext().getExternalFilesDir(null) != null) {
            bitmapCachePath = imageView.getContext().getExternalFilesDir(null).getAbsolutePath()
                    + "/ImageDownloaderCache";
        }
    }
    resetPurgeTimer();

    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.keylesspalace.tusky.activity.MainActivity.java

private void setupDrawer() {
    headerResult = new AccountHeaderBuilder().withActivity(this).withSelectionListEnabledForSingleProfile(false)
            .withDividerBelowHeader(false).withCompactStyle(true).build();

    DrawerImageLoader.init(new AbstractDrawerImageLoader() {
        @Override/*w w w . ja va2  s .  co  m*/
        public void set(ImageView imageView, Uri uri, Drawable placeholder) {
            Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Override
        public void cancel(ImageView imageView) {
            Picasso.with(imageView.getContext()).cancelRequest(imageView);
        }
    });

    drawer = new DrawerBuilder().withActivity(this)
            //.withToolbar(toolbar)
            .withAccountHeader(headerResult).withHasStableIds(true).withSelectedItem(-1)
            .addDrawerItems(
                    new PrimaryDrawerItem().withIdentifier(0).withName(R.string.action_view_profile)
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person),
                    new PrimaryDrawerItem().withIdentifier(1)
                            .withName(getString(R.string.action_view_favourites)).withSelectable(false)
                            .withIcon(GoogleMaterial.Icon.gmd_star),
                    new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_blocks))
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block),
                    new PrimaryDrawerItem().withIdentifier(5).withName("#gopseudo").withSelectable(false)
                            .withIcon(R.mipmap.ic_evil_logo))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    if (drawerItem != null) {
                        long drawerItemIdentifier = drawerItem.getIdentifier();

                        if (drawerItemIdentifier == 0) {
                            if (loggedInAccountId != null) {
                                Intent intent = new Intent(MainActivity.this, AccountActivity.class);
                                intent.putExtra("id", loggedInAccountId);
                                startActivity(intent);
                            }
                        } else if (drawerItemIdentifier == 1) {
                            Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 2) {
                            Intent intent = new Intent(MainActivity.this, BlocksActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 3) {
                            Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 4) {
                            logout();
                        } else if (drawerItemIdentifier == 5) {
                            if (Utils.isPackageInstalled("co.gopseudo.android",
                                    MainActivity.this.getPackageManager())) {
                                PackageManager pm = MainActivity.this.getPackageManager();
                                Intent launchIntent = pm.getLaunchIntentForPackage("co.gopseudo.android");
                                MainActivity.this.startActivity(launchIntent);
                            } else {
                                Utils.urlIntent(MainActivity.this,
                                        "https://play.google.com/store/apps/details?id=co.gopseudo.android");
                            }
                        }
                    }

                    return false;
                }
            }).build();

    drawer.addStickyFooterItem(new SecondaryDrawerItem().withIdentifier(3)
            .withName(getString(R.string.action_view_preferences)).withSelectable(false));
    drawer.addStickyFooterItem(new SecondaryDrawerItem().withIdentifier(4)
            .withName(getString(R.string.action_logout)).withSelectable(false));
}

From source file:com.keylesspalace.tusky.MainActivity.java

private void setupDrawer() {
    headerResult = new AccountHeaderBuilder().withActivity(this).withDividerBelowHeader(false)
            .withHeaderBackgroundScaleType(ImageView.ScaleType.CENTER_CROP).withCurrentProfileHiddenInList(true)
            .withOnAccountHeaderListener((view, profile, current) -> handleProfileClick(profile, current))
            .addProfiles(new ProfileSettingDrawerItem().withIdentifier(DRAWER_ITEM_ADD_ACCOUNT)
                    .withName(R.string.add_account_name).withDescription(R.string.add_account_description)
                    .withIcon(GoogleMaterial.Icon.gmd_add))
            .build();/*from   w  ww .j  a  va 2s  .  c  o  m*/

    headerResult.getView().findViewById(R.id.material_drawer_account_header_current)
            .setContentDescription(getString(R.string.action_view_profile));

    ImageView background = headerResult.getHeaderBackgroundView();
    background.setColorFilter(ContextCompat.getColor(this, R.color.header_background_filter));
    background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));

    DrawerImageLoader.init(new AbstractDrawerImageLoader() {
        @Override
        public void set(ImageView imageView, Uri uri, Drawable placeholder, String tag) {
            Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Override
        public void cancel(ImageView imageView) {
            Picasso.with(imageView.getContext()).cancelRequest(imageView);
        }
    });

    VectorDrawableCompat muteDrawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_mute_24dp,
            getTheme());
    ThemeUtils.setDrawableTint(this, muteDrawable, R.attr.toolbar_icon_tint);

    List<IDrawerItem> listItems = new ArrayList<>(11);
    listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_EDIT_PROFILE)
            .withName(R.string.action_edit_profile).withSelectable(false)
            .withIcon(GoogleMaterial.Icon.gmd_person));
    listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_FAVOURITES)
            .withName(R.string.action_view_favourites).withSelectable(false)
            .withIcon(GoogleMaterial.Icon.gmd_star));
    listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_LISTS).withName(R.string.action_lists)
            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_list));
    listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_MUTED_USERS)
            .withName(R.string.action_view_mutes).withSelectable(false).withIcon(muteDrawable));
    listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_BLOCKED_USERS)
            .withName(R.string.action_view_blocks).withSelectable(false)
            .withIcon(GoogleMaterial.Icon.gmd_block));
    listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SEARCH).withName(R.string.action_search)
            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_search));
    listItems.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SAVED_TOOT)
            .withName(R.string.action_access_saved_toot).withSelectable(false)
            .withIcon(GoogleMaterial.Icon.gmd_save));
    listItems.add(new DividerDrawerItem());
    listItems.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_PREFERENCES)
            .withName(R.string.action_view_preferences).withSelectable(false)
            .withIcon(GoogleMaterial.Icon.gmd_settings));
    listItems.add(
            new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_ABOUT).withName(R.string.about_title_activity)
                    .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info));
    listItems.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_LOG_OUT).withName(R.string.action_logout)
            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app));

    drawer = new DrawerBuilder().withActivity(this).withAccountHeader(headerResult).withHasStableIds(true)
            .withSelectedItem(-1).withDrawerItems(listItems)
            .withOnDrawerItemClickListener((view, position, drawerItem) -> {
                if (drawerItem != null) {
                    long drawerItemIdentifier = drawerItem.getIdentifier();

                    if (drawerItemIdentifier == DRAWER_ITEM_EDIT_PROFILE) {
                        Intent intent = new Intent(MainActivity.this, EditProfileActivity.class);
                        startActivityWithSlideInAnimation(intent);
                    } else if (drawerItemIdentifier == DRAWER_ITEM_FAVOURITES) {
                        Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
                        startActivityWithSlideInAnimation(intent);
                    } else if (drawerItemIdentifier == DRAWER_ITEM_MUTED_USERS) {
                        Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                        intent.putExtra("type", AccountListActivity.Type.MUTES);
                        startActivityWithSlideInAnimation(intent);
                    } else if (drawerItemIdentifier == DRAWER_ITEM_BLOCKED_USERS) {
                        Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                        intent.putExtra("type", AccountListActivity.Type.BLOCKS);
                        startActivityWithSlideInAnimation(intent);
                    } else if (drawerItemIdentifier == DRAWER_ITEM_SEARCH) {
                        Intent intent = new Intent(MainActivity.this, SearchActivity.class);
                        startActivityWithSlideInAnimation(intent);
                    } else if (drawerItemIdentifier == DRAWER_ITEM_PREFERENCES) {
                        Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
                        startActivityWithSlideInAnimation(intent);
                    } else if (drawerItemIdentifier == DRAWER_ITEM_ABOUT) {
                        Intent intent = new Intent(MainActivity.this, AboutActivity.class);
                        startActivityWithSlideInAnimation(intent);
                    } else if (drawerItemIdentifier == DRAWER_ITEM_LOG_OUT) {
                        logout();
                    } else if (drawerItemIdentifier == DRAWER_ITEM_FOLLOW_REQUESTS) {
                        Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                        intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS);
                        startActivityWithSlideInAnimation(intent);
                    } else if (drawerItemIdentifier == DRAWER_ITEM_SAVED_TOOT) {
                        Intent intent = new Intent(MainActivity.this, SavedTootActivity.class);
                        startActivityWithSlideInAnimation(intent);
                    } else if (drawerItemIdentifier == DRAWER_ITEM_LISTS) {
                        startActivityWithSlideInAnimation(ListsActivity.newIntent(this));
                    }

                }

                return false;
            }).build();

    if (BuildConfig.DEBUG) {
        IDrawerItem debugItem = new SecondaryDrawerItem().withIdentifier(1337).withName("debug")
                .withDisabledTextColor(Color.GREEN).withSelectable(false).withEnabled(false);
        drawer.addItem(debugItem);
    }

    updateProfiles();
}

From source file:com.landenlabs.all_devtool.IconBaseFragment.java

/**
 * Show a 'LayerDrawable'  information.//from w ww . ja  va  2  s .c  o m
 *
 * @param imageView
 * @param row1
 * @param row2
 * @param iconD
 * @param layerIdx
 */
private void showLayerIcon(final ImageView imageView, TableRow row1, TableRow row2, Drawable iconD,
        int layerIdx) {

    if (iconD != null) {
        ImageView layerImageView = new ImageView(imageView.getContext());

        layerImageView.setImageDrawable(iconD);
        layerImageView.setPadding(10, 10, 10, 10);
        layerImageView.setMinimumHeight(8);
        layerImageView.setMinimumWidth(8);
        layerImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView.setImageDrawable(((ImageView) v).getDrawable());
            }
        });

        TextView stateTextView = new TextView(imageView.getContext());
        stateTextView.setText(String.valueOf(layerIdx));
        stateTextView.setTextSize(12);
        stateTextView.setGravity(Gravity.CENTER);

        row1.addView(stateTextView);
        row2.addView(layerImageView);
    }
}

From source file:net.maa123.tatuky.MainActivity.java

private void setupDrawer() {
    headerResult = new AccountHeaderBuilder().withActivity(this).withSelectionListEnabledForSingleProfile(false)
            .withDividerBelowHeader(false)
            .withOnAccountHeaderProfileImageListener(new AccountHeader.OnAccountHeaderProfileImageListener() {
                @Override// w w w . j  av  a 2s  .  c  o  m
                public boolean onProfileImageClick(View view, IProfile profile, boolean current) {
                    if (current && loggedInAccountId != null) {
                        Intent intent = new Intent(MainActivity.this, AccountActivity.class);
                        intent.putExtra("id", loggedInAccountId);
                        startActivity(intent);
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean onProfileImageLongClick(View view, IProfile profile, boolean current) {
                    return false;
                }
            }).withCompactStyle(true).build();
    headerResult.getView().findViewById(R.id.material_drawer_account_header_current)
            .setContentDescription(getString(R.string.action_view_profile));

    DrawerImageLoader.init(new AbstractDrawerImageLoader() {
        @Override
        public void set(ImageView imageView, Uri uri, Drawable placeholder) {
            Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Override
        public void cancel(ImageView imageView) {
            Picasso.with(imageView.getContext()).cancelRequest(imageView);
        }
    });

    VectorDrawableCompat muteDrawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_mute_24dp,
            getTheme());
    ThemeUtils.setDrawableTint(this, muteDrawable, R.attr.toolbar_icon_tint);

    drawer = new DrawerBuilder().withActivity(this)
            //.withToolbar(toolbar)
            .withAccountHeader(headerResult).withHasStableIds(true).withSelectedItem(-1)
            .addDrawerItems(
                    new PrimaryDrawerItem().withIdentifier(0).withName(getString(R.string.action_edit_profile))
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person),
                    new PrimaryDrawerItem().withIdentifier(1)
                            .withName(getString(R.string.action_view_favourites)).withSelectable(false)
                            .withIcon(GoogleMaterial.Icon.gmd_star),
                    new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_mutes))
                            .withSelectable(false).withIcon(muteDrawable),
                    new PrimaryDrawerItem().withIdentifier(3).withName(getString(R.string.action_view_blocks))
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block),
                    new DividerDrawerItem(),
                    new SecondaryDrawerItem().withIdentifier(4)
                            .withName(getString(R.string.action_view_preferences)).withSelectable(false)
                            .withIcon(GoogleMaterial.Icon.gmd_settings),
                    new SecondaryDrawerItem().withIdentifier(5)
                            .withName(getString(R.string.about_title_activity)).withSelectable(false)
                            .withIcon(GoogleMaterial.Icon.gmd_info),
                    new SecondaryDrawerItem().withIdentifier(6).withName(getString(R.string.action_logout))
                            .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    if (drawerItem != null) {
                        long drawerItemIdentifier = drawerItem.getIdentifier();

                        if (drawerItemIdentifier == 0) {
                            Intent intent = new Intent(MainActivity.this, EditProfileActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 1) {
                            Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 2) {
                            Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                            intent.putExtra("type", AccountListActivity.Type.MUTES);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 3) {
                            Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                            intent.putExtra("type", AccountListActivity.Type.BLOCKS);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 4) {
                            Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 5) {
                            Intent intent = new Intent(MainActivity.this, AboutActivity.class);
                            startActivity(intent);
                        } else if (drawerItemIdentifier == 6) {
                            logout();
                        } else if (drawerItemIdentifier == 7) {
                            Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                            intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS);
                            startActivity(intent);
                        }
                    }

                    return false;
                }
            }).build();
}