Java Code Examples for android.widget.ImageView#setAlpha()

The following examples show how to use android.widget.ImageView#setAlpha() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CityImageSliderAdapter.java    From Travel-Mate with MIT License 6 votes vote down vote up
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
    ImageView imageView = new ImageView(mContext);
    //display default city image if no image is present in array
    if (mImagesArray.size() == 0) {
        Picasso.with(mContext).load(R.drawable.placeholder_image)
                .error(R.drawable.placeholder_image).fit().centerCrop().into(imageView);
    }
    Picasso.with(mContext).load(mImagesArray.get(position))
            .error(R.drawable.placeholder_image).fit().centerCrop().into(imageView);
    container.addView(imageView);
    imageView.setOnClickListener(v -> {
        Intent fullScreenIntent = FullScreenImage.getStartIntent(mContext,
                mImagesArray.get(position), mCityName);
        mContext.startActivity(fullScreenIntent);
    });
    imageView.setBackgroundColor(Color.TRANSPARENT);
    imageView.setAlpha(0.6f);
    return imageView;
}
 
Example 2
Source File: KenBurnsView.java    From LLApp with Apache License 2.0 6 votes vote down vote up
private void swapImage() {
    Log.d(TAG, "swapImage active=" + mActiveImageIndex);
    if(mActiveImageIndex == -1) {
        mActiveImageIndex = 1;
        animate(mImageViews[mActiveImageIndex]);
        return;
    }

    int inactiveIndex = mActiveImageIndex;
    mActiveImageIndex = (1 + mActiveImageIndex) % mImageViews.length;
    Log.d(TAG, "new active=" + mActiveImageIndex);

    final ImageView activeImageView = mImageViews[mActiveImageIndex];
    activeImageView.setAlpha(0.0f);
    ImageView inactiveImageView = mImageViews[inactiveIndex];

    animate(activeImageView);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(mFadeInOutMs);
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(inactiveImageView, "alpha", 1.0f, 0.0f),
            ObjectAnimator.ofFloat(activeImageView, "alpha", 0.0f, 1.0f)
    );
    animatorSet.start();
}
 
Example 3
Source File: TableFixHeaders.java    From BlurTestAndroid with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressWarnings("deprecation")
private void setAlpha(ImageView imageView, float alpha) {
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
		imageView.setAlpha(alpha);
	} else {
		imageView.setAlpha(Math.round(alpha * 255));
	}
}
 
Example 4
Source File: IconHelper.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
/**
 * Load thumbnails for a directory list item.
 * @param uri The URI for the file being represented.
 * @param mimeType The mime type of the file being represented.
 * @param docFlags Flags for the file being represented.
 * @param iconThumb The itemview's thumbnail icon.
 * @param iconMimeBackground
 * @return
 */
public void loadThumbnail(Uri uri, String path, String mimeType, int docFlags, int docIcon,
                          ImageView iconMime, ImageView iconThumb, View iconMimeBackground) {
    boolean cacheHit = false;

    final String docAuthority = uri.getAuthority();
    String docId = DocumentsContract.getDocumentId(uri);
    final boolean supportsThumbnail = (docFlags & Document.FLAG_SUPPORTS_THUMBNAIL) != 0;
    final boolean allowThumbnail = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, mimeType);
    final boolean showThumbnail = supportsThumbnail && allowThumbnail && mThumbnailsEnabled;
    if (showThumbnail) {
        final Bitmap cachedResult = mCache.get(uri);
        if (cachedResult != null) {
            iconThumb.setImageBitmap(cachedResult);
            cacheHit = true;
            iconMimeBackground.setVisibility(View.GONE);
        } else {
            iconThumb.setImageDrawable(null);
            final LoaderTask task = new LoaderTask(uri, path, mimeType, mThumbSize, iconThumb,
                    iconMime, iconMimeBackground);
            iconThumb.setTag(task);
            ProviderExecutor.forAuthority(docAuthority).execute(task);
        }
    }

    if (cacheHit) {
        iconMime.setImageDrawable(null);
        iconMime.setAlpha(0f);
        iconThumb.setAlpha(1f);
    } else {
        // Add a mime icon if the thumbnail is being loaded in the background.
        iconThumb.setImageDrawable(null);
        iconMime.setImageDrawable(getDocumentIcon(mContext, docAuthority, docId, mimeType, docIcon));
        iconMime.setAlpha(1f);
        iconThumb.setAlpha(0f);
    }
}
 
Example 5
Source File: ImageLoader.java    From MicroReader with MIT License 5 votes vote down vote up
public static void loadImage(Context context, String url, ImageView imageView) {
    if (Config.isNight) {
        imageView.setAlpha(0.2f);
        imageView.setBackgroundColor(Color.BLACK);
    }
    Glide.with(context).load(url).into(imageView);
}
 
Example 6
Source File: BlurAnimMode.java    From ECardFlow with MIT License 5 votes vote down vote up
@Override
public void transformPage(ImageView ivBg, float position, int direction) {
    float mFraction = (float) Math.cos(2 * Math.PI * position);
    if (mFraction < 0)
        mFraction = 0;
        ivBg.setAlpha(mFraction);
}
 
Example 7
Source File: NotificationPeekActivity.java    From NotificationPeekPort with Apache License 2.0 5 votes vote down vote up
/**
 * Update small notification icons when there is new notification coming, and the
 * Activity is in foreground.
 */
private void updateNotificationIcons() {

    if (mNotificationsContainer.getVisibility() != View.VISIBLE) {
        mNotificationsContainer.setVisibility(View.VISIBLE);
    }

    NotificationHub notificationHub = NotificationHub.getInstance();

    int iconSize = getResources().getDimensionPixelSize(R.dimen.small_notification_icon_size);
    int padding = getResources().getDimensionPixelSize(R.dimen.small_notification_icon_padding);

    final StatusBarNotification n = notificationHub.getCurrentNotification();
    ImageView icon = new ImageView(this);
    icon.setAlpha(NotificationPeek.ICON_LOW_OPACITY);

    icon.setPadding(padding, 0, padding, 0);
    icon.setImageDrawable(NotificationPeekViewUtils.getIconFromResource(this, n));
    icon.setTag(n);

    restoreFirstIconVisibility();

    int oldIndex = getOldIconViewIndex(notificationHub);

    if (oldIndex >= 0) {
        mNotificationsContainer.removeViewAt(oldIndex);
    }

    mNotificationsContainer.addView(icon);
    LinearLayout.LayoutParams linearLayoutParams =
            new LinearLayout.LayoutParams(iconSize, iconSize);

    // Wrap LayoutParams to GridLayout.LayoutParams.
    GridLayout.LayoutParams gridLayoutParams = new GridLayout.LayoutParams(linearLayoutParams);
    icon.setLayoutParams(gridLayoutParams);
}
 
Example 8
Source File: LocalWorker.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
private void playImageViewAnimation(final ImageView view, final Bitmap bitmap) {

        view.setImageBitmap(bitmap);
        resetProgressBarStatues();
        view.setAlpha(0f);
        view.animate().alpha(1.0f).setDuration(500).setListener(new LayerEnablingAnimatorListener(view, null));
        view.setTag(getUrl());

    }
 
Example 9
Source File: RunningAppLauncher.java    From DistroHopper with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void iconChanged ()
{
	if (! this.isInEditMode ())
	{
		ImageView imgIcon = (ImageView) this.findViewById (R.id.imgIcon);
		imgIcon.setImageDrawable (this.getIcon ().getDrawable ());

		LinearLayout llBackground = (LinearLayout) this.findViewById (R.id.llBackground);
		if (llBackground != null && (! this.isSpecial ()))
			this.colourChanged ();
		
		imgIcon.setAlpha (0.9F);
	}
}
 
Example 10
Source File: GameActivity.java    From SchoolQuest with GNU General Public License v3.0 5 votes vote down vote up
public void enableCancelButton() {
    ImageView cancelButton = findViewById(R.id.cancel_button);
    ImageView lessonCancelButton = findViewById(R.id.lesson_c_cancel_button);

    cancelButton.setAlpha(1f);
    cancelButton.setEnabled(true);

    lessonCancelButton.setAlpha(1f);
    lessonCancelButton.setEnabled(true);
}
 
Example 11
Source File: BubbleActionOverlay.java    From BubbleActions with Apache License 2.0 5 votes vote down vote up
BubbleActionOverlay(Context context) {
    super(context);
    contentClipRect = new RectF();
    dragShadowBuilder = new DragShadowBuilder();
    dragData = DragUtils.getClipData();

    LayoutInflater inflater = LayoutInflater.from(context);
    bubbleActionIndicator = (ImageView) inflater.inflate(R.layout.bubble_actions_indicator, this, false);
    bubbleActionIndicator.setAlpha(0f);
    addView(bubbleActionIndicator, -1);

    interpolator = new OvershootInterpolator(OVERSHOOT_TENSION);

    int transparentBackgroundColor = ContextCompat.getColor(context, R.color.bubble_actions_background_transparent);
    int darkenedBackgroundColor = ContextCompat.getColor(context, R.color.bubble_actions_background_darkened);
    setBackgroundColor(transparentBackgroundColor);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        backgroundAnimator = ObjectAnimator.ofArgb(this, "backgroundColor", transparentBackgroundColor, darkenedBackgroundColor);
    } else {
        backgroundAnimator = ObjectAnimator.ofObject(this, "backgroundColor", new BackgroundAlphaTypeEvaluator(), transparentBackgroundColor, darkenedBackgroundColor);
    }

    animationDuration = BASE_ANIMATION_DURATION;

    bubbleDimension = (int) getResources().getDimension(R.dimen.bubble_actions_indicator_dimension);
    startActionDistanceFromCenter = getResources().getDimension(R.dimen.bubble_actions_start_distance);
    stopActionDistanceFromCenter = getResources().getDimension(R.dimen.bubble_actions_stop_distance);

    for (int i = 0; i < MAX_ACTIONS; i++) {
        BubbleView itemView = new BubbleView(getContext());
        itemView.setVisibility(INVISIBLE);
        itemView.setAlpha(0f);
        addView(itemView, -1, new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    }
}
 
Example 12
Source File: ImageLoader.java    From ghwatch with Apache License 2.0 5 votes vote down vote up
protected void showImageInView(ImageView iv, Bitmap bitmap, boolean animate) {
  iv.clearAnimation();
  if (animate)
    iv.setAlpha(0f);
  iv.setImageBitmap(bitmap);
  setProgressBarVisibility(iv, false);
  if (animate)
    iv.animate().alpha(1f).setDuration(200).start();
}
 
Example 13
Source File: MainActivity.java    From TestChat with Apache License 2.0 5 votes vote down vote up
@Override
public void initView() {
    LogUtil.e("initMain123");
    RecentFragment recentFragment = new RecentFragment();
    ContactsFragment contactsFragment = new ContactsFragment();
    InvitationFragment invitationFragment = new InvitationFragment();
    ShareMessageFragment shareMessageFragment = new ShareMessageFragment();
    mFragments[0] = recentFragment;
    mFragments[1] = contactsFragment;
    mFragments[2] = invitationFragment;
    mFragments[3] = shareMessageFragment;
    container = (DragLayout) findViewById(R.id.drag_container);
    menuDisplay = (RecyclerView) findViewById(R.id.rev_menu_display);
    nick = (TextView) findViewById(R.id.tv_menu_nick);
    signature = (TextView) findViewById(R.id.tv_menu_signature);
    avatar = (RoundAngleImageView) findViewById(R.id.riv_menu_avatar);
    headLayout = (RelativeLayout) findViewById(R.id.rl_menu_head_layout);
    bg = (ImageView) findViewById(R.id.iv_main_bg);
    net = (TextView) findViewById(R.id.tv_main_net);
    weatherCity = (TextView) findViewById(R.id.tv_menu_weather_city);
    weatherTemperature = (TextView) findViewById(R.id.tv_menu_weather_temperature);
    bottomLayout = (LinearLayout) findViewById(R.id.ll_menu_bottom_container);
    bg.setAlpha((float) 0.0);
    menuDisplay.setLayoutManager(new LinearLayoutManager(this));
    menuDisplay.setHasFixedSize(true);
    menuDisplay.setItemAnimator(new DefaultItemAnimator());
    container.setListener(this);
    headLayout.setOnClickListener(this);
    net.setOnClickListener(this);
    bottomLayout.setOnClickListener(this);
    initActionBarView();
}
 
Example 14
Source File: KenBurnsView.java    From KenBurnsView with Apache License 2.0 4 votes vote down vote up
private void autoSwapImage() {

        if (mImageViews.length <= 0) {
            return;
        }

        if (mActiveImageIndex == -1) {
            mActiveImageIndex = FIRST_IMAGE_VIEW_INDEX;
            animate(mImageViews[mActiveImageIndex]);
            return;
        }

        int inactiveIndex = mActiveImageIndex;
        mActiveImageIndex = (1 + mActiveImageIndex);

        if (mActiveImageIndex >= mImageViews.length) {
            mActiveImageIndex = FIRST_IMAGE_VIEW_INDEX;
        }

        if (mLoopViewPager != null) {
            mPosition++;

            if (mPosition >= getSizeByLoadType()) {
                mPosition = 0;
            }

            mLoopViewPager.setCurrentItemAfterCancelListener(mPosition, false);
        }

        final ImageView activeImageView = mImageViews[mActiveImageIndex];
        loadImages(mPosition, mActiveImageIndex);
        activeImageView.setAlpha(0.0f);

        ImageView inactiveImageView = mImageViews[inactiveIndex];

        animate(activeImageView);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(mFadeInOutMs);
        animatorSet.playTogether(
                ObjectAnimator.ofFloat(inactiveImageView, PROPERTY_ALPHA, 1.0f, 0.0f),
                ObjectAnimator.ofFloat(activeImageView, PROPERTY_ALPHA, 0.0f, 1.0f)
        );
        animatorSet.start();
    }
 
Example 15
Source File: Utility.java    From utexas-utilities with Apache License 2.0 4 votes vote down vote up
public static void setImageAlpha(ImageView iv, int alpha) {
    // imageView#setImageAlpha method seems to be broken on 4.x, so use the View.setAlpha
    // method instead.
    iv.setAlpha(alpha/255f);
}
 
Example 16
Source File: TimeLineBitmapDownloader.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void displayImageView(final ImageView view, final String urlKey, final FileLocationMethod method,
                              boolean isFling, boolean isMultiPictures) {
    view.clearAnimation();

    if (!shouldReloadPicture(view, urlKey)) {
        return;
    }

    final Bitmap bitmap = getBitmapFromMemCache(urlKey);
    if (bitmap != null) {
        view.setImageBitmap(bitmap);
        view.setTag(urlKey);
        if (view.getAlpha() != 1.0f) {
            view.setAlpha(1.0f);
        }
        cancelPotentialDownload(urlKey, view);
    } else {

        if (isFling) {
            view.setImageResource(defaultPictureResId);
            return;
        }

        if (!cancelPotentialDownload(urlKey, view)) {
            return;
        }

        final LocalOrNetworkChooseWorker newTask = new LocalOrNetworkChooseWorker(view, urlKey, method, isMultiPictures);
        PictureBitmapDrawable downloadedDrawable = new PictureBitmapDrawable(newTask);
        view.setImageDrawable(downloadedDrawable);

        // listview fast scroll performance
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                if (getBitmapDownloaderTask(view) == newTask) {
                    newTask.executeOnNormal();
                }
                return;

            }
        }, 400);

    }

}
 
Example 17
Source File: GameActivity.java    From SchoolQuest with GNU General Public License v3.0 4 votes vote down vote up
public void enableSkipButton() {
    ImageView skipButton = findViewById(R.id.skip_button);

    skipButton.setAlpha(1f);
    skipButton.setEnabled(true);
}
 
Example 18
Source File: KenBurnsView.java    From KenBurnsView with Apache License 2.0 4 votes vote down vote up
private void forceSwapImage() {

        if (mImageViews.length <= 0) {
            return;
        }

        if (mActiveImageIndex == -1) {
            mActiveImageIndex = FIRST_IMAGE_VIEW_INDEX;
            animate(mImageViews[mActiveImageIndex]);
            return;
        }

        int inactiveIndex = mActiveImageIndex;

        if (mPreviousPosition >= mPosition) {
            mActiveImageIndex = swapDirection(mActiveImageIndex, true);
        } else {
            mActiveImageIndex = swapDirection(mActiveImageIndex, false);
        }

        if (mPreviousPosition == 0 && mPosition == getSizeByLoadType() - 1) {
            mActiveImageIndex = swapDirection(mActiveImageIndex, true);
        }

        if (mPreviousPosition == getSizeByLoadType() - 1 && mPosition == 0) {
            mActiveImageIndex = swapDirection(mActiveImageIndex, false);
        }

        if (mActiveImageIndex >= mImageViews.length) {
            mActiveImageIndex = FIRST_IMAGE_VIEW_INDEX;
        }

        final ImageView activeImageView = mImageViews[mActiveImageIndex];
        loadImages(mPosition, mActiveImageIndex);
        activeImageView.setAlpha(0.0f);

        ImageView inactiveImageView = mImageViews[inactiveIndex];

        animate(activeImageView);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(mFadeInOutMs);
        animatorSet.playTogether(
                ObjectAnimator.ofFloat(inactiveImageView, PROPERTY_ALPHA, 1.0f, 0.0f),
                ObjectAnimator.ofFloat(activeImageView, PROPERTY_ALPHA, 0.0f, 1.0f)
        );
        animatorSet.start();
    }
 
Example 19
Source File: DecorationListFragment.java    From MonsterHunter4UDatabase with MIT License 4 votes vote down vote up
@Override
public void bindView(View view, Context context, Cursor cursor) {
    // Get the decoration for the current row
    Decoration decoration = mDecorationCursor.getDecoration();

    RelativeLayout itemLayout = (RelativeLayout) view.findViewById(R.id.listitem);

    // Set up the text view
    ImageView itemImageView = (ImageView) view.findViewById(R.id.item_image);
    TextView decorationNameTextView = (TextView) view.findViewById(R.id.item);
    TextView skill1TextView = (TextView) view.findViewById(R.id.skill1);
    TextView skill1amtTextView = (TextView) view.findViewById(R.id.skill1_amt);
    TextView skill2TextView = (TextView) view.findViewById(R.id.skill2);
    TextView skill2amtTextView = (TextView) view.findViewById(R.id.skill2_amt);

    String decorationNameText = decoration.getName();
    String skill1Text = decoration.getSkill1Name();
    String skill1amtText = "" + decoration.getSkill1Point();
    String skill2Text = decoration.getSkill2Name();
    String skill2amtText = "";
    if (decoration.getSkill2Point() != 0) {
        skill2amtText = skill2amtText + decoration.getSkill2Point();
    }

    Drawable i = null;
    String cellImage = "icons_items/" + decoration.getFileLocation();
    try {
        i = Drawable.createFromStream(
                context.getAssets().open(cellImage), null);
    } catch (IOException e) {
        e.printStackTrace();
    }

    itemImageView.setImageDrawable(i);

    decorationNameTextView.setText(decorationNameText);
    skill1TextView.setText(skill1Text);
    skill1amtTextView.setText(skill1amtText);

    skill2TextView.setVisibility(View.GONE);
    skill2amtTextView.setVisibility(View.GONE);

    if (!skill2amtText.equals("")) {
        skill2TextView.setText(skill2Text);
        skill2amtTextView.setText(skill2amtText);
        skill2TextView.setVisibility(View.VISIBLE);
        skill2amtTextView.setVisibility(View.VISIBLE);
    }

    itemLayout.setTag(decoration.getId());

    if (fromAsb) {
        boolean fitsInArmor = (decoration.getNumSlots() <= maxSlots);
        view.setEnabled(fitsInArmor);

        // Set the jewel image to be translucent if disabled
        // TODO: If a way to use alpha with style selectors exist, use that instead
        itemImageView.setAlpha((fitsInArmor) ? 1.0f : 0.5f);

        if (fitsInArmor) {
            itemLayout.setOnClickListener(new DecorationClickListener(context, decoration.getId(), true, activity));
        }
    }
    else {
        itemLayout.setOnClickListener(new DecorationClickListener(context, decoration.getId()));
    }
}
 
Example 20
Source File: RichEditText.java    From RichEditText with Apache License 2.0 2 votes vote down vote up
private void letImageViewOn(ImageView iv) {
    iv.setAlpha(1.0f);

}