Example usage for android.widget ImageView getVisibility

List of usage examples for android.widget ImageView getVisibility

Introduction

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

Prototype

@ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"),
        @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"),
        @ViewDebug.IntToString(from = GONE, to = "GONE") })
@Visibility
public int getVisibility() 

Source Link

Document

Returns the visibility status for this view.

Usage

From source file:com.example.android.tourguide.ObjectAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    View listItemView = convertView;
    if (listItemView == null) {
        listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
    }/*from   w w  w  . ja v  a  2s.  c  o m*/

    // Get the {@link Object} object located at this position in the list
    final Object currentObject = getItem(position);

    // Find the TextView in the list_item.xml layout with the ID name_text_view.
    TextView objectNameTV = (TextView) listItemView.findViewById(R.id.name_text_view);
    objectNameTV.setSelected(true);
    objectNameTV.setText(currentObject.getObjectName());

    // Find the TextView in the list_item.xml layout with the ID address_text_view.
    TextView addressTV = (TextView) listItemView.findViewById(R.id.address_text_view);
    addressTV.setSelected(true);
    addressTV.setText(currentObject.getObjectAddress());

    // Find the TextView in the list_item.xml layout with the ID description_text_view.
    TextView objectDescription = (TextView) listItemView.findViewById(R.id.description_text_view);
    objectDescription.setText(currentObject.getObjectDescription());

    // Find the ImageView in the list_item.xml layout with the ID image.
    final ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);
    // Check if an image is provided for this word or not
    if (currentObject.hasImage()) {
        // If an image is available, display the provided image based on the resource ID
        imageView.setImageResource(currentObject.getImageResourceId());
        // Make sure the view is visible
        imageView.setVisibility(View.VISIBLE);
    } else {
        // Otherwise hide the ImageView (set visibility to GONE)
        imageView.setVisibility(View.GONE);
    }

    LinearLayout textContainer = (LinearLayout) listItemView.findViewById(R.id.text_container);
    int color = ContextCompat.getColor(getContext(), mColorResourceId);
    textContainer.setBackgroundColor(color);

    textContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (currentObject.hasImage()) {
                if (imageView.getVisibility() == View.GONE) {
                    imageView.setVisibility(View.VISIBLE);
                } else {
                    imageView.setVisibility(View.GONE);
                }
            }
        }
    });

    // Return the whole list item layout (containing 2 TextViews) so that it can be shown in
    // the ListView.
    return listItemView;
}

From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java

public void performEntryTransition(final Activity activity, final ViewGroup contentView, int iconResourceId,
        Uri iconResourceUri, final ImageView icon, final TextView title, final TextView description,
        final TextView breadcrumb) {
    // Pull out the root layout of the dialog and set the background drawable, to be
    // faded in during the transition.
    final ViewGroup twoPane = (ViewGroup) contentView.getChildAt(0);
    twoPane.setVisibility(View.INVISIBLE);

    // If the appropriate data is embedded in the intent and there is an icon specified
    // in the content fragment, we animate the icon from its initial position to the final
    // position. Otherwise, we perform a simpler transition in which the ActionFragment
    // slides in and the ContentFragment text fields slide in.
    mIntroAnimationInProgress = true;/*from  w w w  . j  ava 2s. c o m*/
    List<TransitionImage> images = TransitionImage.readMultipleFromIntent(activity, activity.getIntent());
    TransitionImageAnimation ltransitionAnimation = null;
    final Uri iconUri;
    final int color;
    if (images != null && images.size() > 0) {
        if (iconResourceId != 0) {
            iconUri = Uri.parse(UriUtils.getAndroidResourceUri(activity, iconResourceId));
        } else if (iconResourceUri != null) {
            iconUri = iconResourceUri;
        } else {
            iconUri = null;
        }
        TransitionImage src = images.get(0);
        color = src.getBackground();
        if (iconUri != null) {
            ltransitionAnimation = new TransitionImageAnimation(contentView);
            ltransitionAnimation.addTransitionSource(src);
            ltransitionAnimation.transitionDurationMs(ANIMATE_IN_DURATION).transitionStartDelayMs(0)
                    .interpolator(new DecelerateInterpolator(1f));
        }
    } else {
        iconUri = null;
        color = 0;
    }
    final TransitionImageAnimation transitionAnimation = ltransitionAnimation;

    // Fade out the old activity, and hard cut the new activity.
    activity.overridePendingTransition(R.anim.hard_cut_in, R.anim.fade_out);

    int bgColor = mFragment.getResources().getColor(R.color.dialog_activity_background);
    mBgDrawable.setColor(bgColor);
    mBgDrawable.setAlpha(0);
    twoPane.setBackground(mBgDrawable);

    // If we're animating the icon, we create a new ImageView in which to place the embedded
    // bitmap. We place it in the root layout to match its location in the previous activity.
    mShadowLayer = (FrameLayoutWithShadows) twoPane.findViewById(R.id.shadow_layout);
    if (transitionAnimation != null) {
        transitionAnimation.listener(new TransitionImageAnimation.Listener() {
            @Override
            public void onRemovedView(TransitionImage src, TransitionImage dst) {
                if (icon != null) {
                    //want to make sure that users still see at least the source image
                    // if the dst image is too large to finish downloading before the
                    // animation is done. Check if the icon is not visible. This mean
                    // BaseContentFragement have not finish downloading the image yet.
                    if (icon.getVisibility() != View.VISIBLE) {
                        icon.setImageDrawable(src.getBitmap());
                        int intrinsicWidth = icon.getDrawable().getIntrinsicWidth();
                        LayoutParams lp = icon.getLayoutParams();
                        lp.height = lp.width * icon.getDrawable().getIntrinsicHeight() / intrinsicWidth;
                        icon.setVisibility(View.VISIBLE);
                    }
                    icon.setAlpha(1f);
                }
                if (mShadowLayer != null) {
                    mShadowLayer.setShadowsAlpha(1f);
                }
                onIntroAnimationFinished();
            }
        });
        icon.setAlpha(0f);
        if (mShadowLayer != null) {
            mShadowLayer.setShadowsAlpha(0f);
        }
    }

    // We need to defer the remainder of the animation preparation until the first
    // layout has occurred, as we don't yet know the final location of the icon.
    twoPane.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            twoPane.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            // if we buildLayer() at this time,  the texture is actually not created
            // delay a little so we can make sure all hardware layer is created before
            // animation, in that way we can avoid the jittering of start animation
            twoPane.postOnAnimationDelayed(mEntryAnimationRunnable, ANIMATE_DELAY);
        }

        final Runnable mEntryAnimationRunnable = new Runnable() {
            @Override
            public void run() {
                if (!mFragment.isAdded()) {
                    // We have been detached before this could run, so just bail
                    return;
                }

                twoPane.setVisibility(View.VISIBLE);
                final int secondaryDelay = SLIDE_IN_DISTANCE;

                // Fade in the activity background protection
                ObjectAnimator oa = ObjectAnimator.ofInt(mBgDrawable, "alpha", 255);
                oa.setDuration(ANIMATE_IN_DURATION);
                oa.setStartDelay(secondaryDelay);
                oa.setInterpolator(new DecelerateInterpolator(1.0f));
                oa.start();

                View actionFragmentView = activity.findViewById(mActionAreaId);
                boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL;
                int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE;
                int endDist = isRtl ? -actionFragmentView.getMeasuredWidth()
                        : actionFragmentView.getMeasuredWidth();

                // Fade in and slide in the ContentFragment TextViews from the start.
                prepareAndAnimateView(title, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(breadcrumb, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(description, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                // Fade in and slide in the ActionFragment from the end.
                prepareAndAnimateView(actionFragmentView, 0, endDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                if (icon != null && transitionAnimation != null) {
                    // now we get the icon view in place,  update the transition target
                    TransitionImage target = new TransitionImage();
                    target.setUri(iconUri);
                    target.createFromImageView(icon);
                    if (icon.getBackground() instanceof ColorDrawable) {
                        ColorDrawable d = (ColorDrawable) icon.getBackground();
                        target.setBackground(d.getColor());
                    }
                    transitionAnimation.addTransitionTarget(target);
                    transitionAnimation.startTransition();
                } else if (icon != null) {
                    prepareAndAnimateView(icon, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                            new DecelerateInterpolator(1.0f), true /* is the icon */);
                    if (mShadowLayer != null) {
                        mShadowLayer.setShadowsAlpha(0f);
                    }
                }
            }
        };
    });
}