Example usage for android.widget ImageView setVisibility

List of usage examples for android.widget ImageView setVisibility

Introduction

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

Prototype

@RemotableViewMethod
    @Override
    public void setVisibility(int visibility) 

Source Link

Usage

From source file:it.polimi.wifidirect.DeviceDetailFragment.java

/**
 * Method to hide a GO Icon inside the cardview in {@link it.polimi.wifidirect.DeviceDetailFragment}
 * of the connected device.// w  w w . j av  a  2  s.  c o m
 * This is useful to identify which device is a GO.
 */
public void hideConnectedDeviceGoIcon() {
    if (getView() != null && getView().findViewById(R.id.peerlist_go_logo) != null
            && getView().findViewById(R.id.peerlist_i_am_a_go_textview) != null) {
        ImageView deviceGoLogoImageView = (ImageView) getView().findViewById(R.id.peerlist_go_logo);
        TextView device_i_am_a_go_textView = (TextView) getView()
                .findViewById(R.id.peerlist_i_am_a_go_textview);

        deviceGoLogoImageView.setVisibility(View.INVISIBLE);
        device_i_am_a_go_textView.setVisibility(View.INVISIBLE);
    }
}

From source file:com.dexin.MainActivity.java

private void callCloudVision(final Bitmap bitmap) throws IOException {
    // Switch text to loading
    findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE);
    getWindow().getDecorView().setBackground(null);
    getWindow().getDecorView().setBackgroundColor(Color.WHITE);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setImageDrawable(getResources().getDrawable(R.drawable.check));

    ImageView viewImage = (ImageView) findViewById(R.id.main_image);
    viewImage.setVisibility(View.VISIBLE);

    mImageDetails.setText(R.string.loading_message);

    // Do the real work in an async task, because we need to use the network anyway
    new AsyncTask<Object, Void, String>() {
        @Override/*  w ww .jav  a 2 s  .  c om*/
        protected String doInBackground(Object... params) {
            try {
                HttpTransport httpTransport = AndroidHttp.newCompatibleTransport();
                JsonFactory jsonFactory = GsonFactory.getDefaultInstance();

                VisionRequestInitializer requestInitializer = new VisionRequestInitializer(
                        CLOUD_VISION_API_KEY) {
                    /**
                     * We override this so we can inject important identifying fields into the HTTP
                     * headers. This enables use of a restricted cloud platform API key.
                     */
                    @Override
                    protected void initializeVisionRequest(VisionRequest<?> visionRequest) throws IOException {
                        super.initializeVisionRequest(visionRequest);

                        String packageName = getPackageName();
                        visionRequest.getRequestHeaders().set(ANDROID_PACKAGE_HEADER, packageName);

                        String sig = PackageManagerUtils.getSignature(getPackageManager(), packageName);

                        visionRequest.getRequestHeaders().set(ANDROID_CERT_HEADER, sig);
                    }
                };

                Vision.Builder builder = new Vision.Builder(httpTransport, jsonFactory, null);
                builder.setVisionRequestInitializer(requestInitializer);

                Vision vision = builder.build();

                BatchAnnotateImagesRequest batchAnnotateImagesRequest = new BatchAnnotateImagesRequest();
                batchAnnotateImagesRequest.setRequests(new ArrayList<AnnotateImageRequest>() {
                    {
                        AnnotateImageRequest annotateImageRequest = new AnnotateImageRequest();

                        // Add the image
                        Image base64EncodedImage = new Image();
                        // Convert the bitmap to a JPEG
                        // Just in case it's a format that Android understands but Cloud Vision
                        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, byteArrayOutputStream);
                        byte[] imageBytes = byteArrayOutputStream.toByteArray();

                        // Base64 encode the JPEG
                        base64EncodedImage.encodeContent(imageBytes);
                        annotateImageRequest.setImage(base64EncodedImage);

                        // add the features we want
                        annotateImageRequest.setFeatures(new ArrayList<Feature>() {
                            {
                                Feature labelDetection = new Feature();
                                labelDetection.setType("LABEL_DETECTION");
                                labelDetection.setMaxResults(10);
                                add(labelDetection);
                            }
                        });

                        // Add the list of one thing to the request
                        add(annotateImageRequest);
                    }
                });

                Vision.Images.Annotate annotateRequest = vision.images().annotate(batchAnnotateImagesRequest);
                // Due to a bug: requests to Vision API containing large images fail when GZipped.
                annotateRequest.setDisableGZipContent(true);
                Log.d(TAG, "created Cloud Vision request object, sending request");

                BatchAnnotateImagesResponse response = annotateRequest.execute();
                return convertResponseToString(response);

            } catch (GoogleJsonResponseException e) {
                Log.d(TAG, "failed to make API request because " + e.getContent());
            } catch (IOException e) {
                Log.d(TAG, "failed to make API request because of other IOException " + e.getMessage());
            }
            return "Cloud Vision API request failed. Check logs for details.";
        }

        protected void onPostExecute(String result) {
            findViewById(R.id.loadingPanel).setVisibility(View.GONE);
            mImageDetails.setText(Html.fromHtml(result));
        }
    }.execute();
}

From source file:eu.pellerito.movies.fragment.BaseFragment.java

private void updateUI() {

    ImageView noInternetImage = (ImageView) getActivity().findViewById(R.id.no_internet_imageView);

    // adapter work clear and send
    mUIAdapter.notifyDataSetChanged();//from w w w.ja va 2  s .  c  om
    mUIAdapter.clear();

    // network state validation
    if (new NetworkState(getActivity()).isConnected()) {
        noInternetImage.setVisibility(View.INVISIBLE);
        new FetchTask(getActivity(), this).execute(mOrder);

    } else {
        noInternetImage.setVisibility(View.VISIBLE);

        Glide.with(getActivity()).load(R.drawable.no_internet).into(noInternetImage);

        Toast.makeText(getActivity(), R.string.network_state_not_connected, Toast.LENGTH_LONG).show();
    }
}

From source file:org.odk.collect.android.activities.SplashScreenActivity.java

private void startSplashScreen(String path) {

    // add items to the splash screen here. makes things less distracting.
    ImageView iv = (ImageView) findViewById(R.id.splash);
    LinearLayout ll = (LinearLayout) findViewById(R.id.splash_default);

    File f = new File(path);
    if (f.exists()) {
        iv.setImageBitmap(decodeFile(f));
        ll.setVisibility(View.GONE);
        iv.setVisibility(View.VISIBLE);
    }// w w w  . ja v a  2s  . c om

    // create a thread that counts up to the timeout
    Thread t = new Thread() {
        int count = 0;

        @Override
        public void run() {
            try {
                super.run();
                while (count < mSplashTimeout) {
                    sleep(100);
                    count += 100;
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                endSplashScreen();
            }
        }
    };
    t.start();
}

From source file:com.DGSD.Teexter.UI.Recipient.RecipientAlternatesAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    int position = cursor.getPosition();

    TextView display = (TextView) view.findViewById(android.R.id.title);
    ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
    RecipientEntry entry = getRecipientEntry(position);
    if (position == 0) {
        display.setText(cursor.getString(EmailQuery.NAME));
        display.setVisibility(View.VISIBLE);
        imageView.setImageURI(entry.getPhotoThumbnailUri());
        imageView.setVisibility(View.VISIBLE);
    } else {//from  w w  w . j a v a2 s. com
        display.setVisibility(View.GONE);
        imageView.setVisibility(View.GONE);
    }
    TextView destination = (TextView) view.findViewById(android.R.id.text1);
    destination.setText(cursor.getString(EmailQuery.ADDRESS));

    TextView destinationType = (TextView) view.findViewById(android.R.id.text2);
    if (destinationType != null) {
        destinationType
                .setText(Email.getTypeLabel(context.getResources(), cursor.getInt(EmailQuery.ADDRESS_TYPE),
                        cursor.getString(EmailQuery.ADDRESS_LABEL)).toString().toUpperCase());
    }
}

From source file:org.totschnig.myexpenses.dialog.TransactionDetailFragment.java

public void fillData(Transaction o) {
    final FragmentActivity ctx = getActivity();
    mLayout.findViewById(R.id.progress).setVisibility(View.GONE);
    mTransaction = o;//from   w  w w  .ja v a  2  s  .c  o m
    if (mTransaction == null) {
        TextView error = (TextView) mLayout.findViewById(R.id.error);
        error.setVisibility(View.VISIBLE);
        error.setText(R.string.transaction_deleted);
        return;
    }
    boolean doShowPicture = false;
    if (mTransaction.getPictureUri() != null) {
        doShowPicture = true;
        if (mTransaction.getPictureUri().getScheme().equals("file")) {
            if (!new File(mTransaction.getPictureUri().getPath()).exists()) {
                Toast.makeText(getActivity(), R.string.image_deleted, Toast.LENGTH_SHORT).show();
                doShowPicture = false;
            }
        }
    }
    AlertDialog dlg = (AlertDialog) getDialog();
    if (dlg != null) {
        Button btn = dlg.getButton(AlertDialog.BUTTON_POSITIVE);
        if (btn != null) {
            if (mTransaction.crStatus != Transaction.CrStatus.VOID) {
                btn.setEnabled(true);
            } else {
                btn.setVisibility(View.GONE);
            }
        }
        btn = dlg.getButton(AlertDialog.BUTTON_NEUTRAL);
        if (btn != null) {
            btn.setVisibility(doShowPicture ? View.VISIBLE : View.GONE);
        }
    }
    mLayout.findViewById(R.id.Table).setVisibility(View.VISIBLE);
    int title;
    boolean type = mTransaction.getAmount().getAmountMinor() > 0 ? ExpenseEdit.INCOME : ExpenseEdit.EXPENSE;

    if (mTransaction instanceof SplitTransaction) {
        mLayout.findViewById(R.id.SplitContainer).setVisibility(View.VISIBLE);
        //TODO: refactor duplicated code with SplitPartList
        title = R.string.split_transaction;
        View emptyView = mLayout.findViewById(R.id.empty);

        ListView lv = (ListView) mLayout.findViewById(R.id.list);
        // Create an array to specify the fields we want to display in the list
        String[] from = new String[] { KEY_LABEL_MAIN, KEY_AMOUNT };

        // and an array of the fields we want to bind those fields to 
        int[] to = new int[] { R.id.category, R.id.amount };

        // Now create a simple cursor adapter and set it to display
        mAdapter = new SplitPartAdapter(ctx, R.layout.split_part_row, null, from, to, 0,
                mTransaction.getAmount().getCurrency());
        lv.setAdapter(mAdapter);
        lv.setEmptyView(emptyView);

        LoaderManager manager = getLoaderManager();
        if (manager.getLoader(SPLIT_PART_CURSOR) != null && !manager.getLoader(SPLIT_PART_CURSOR).isReset()) {
            manager.restartLoader(SPLIT_PART_CURSOR, null, this);
        } else {
            manager.initLoader(SPLIT_PART_CURSOR, null, this);
        }

    } else {
        if (mTransaction instanceof Transfer) {
            title = R.string.transfer;
            ((TextView) mLayout.findViewById(R.id.AccountLabel)).setText(R.string.transfer_from_account);
            ((TextView) mLayout.findViewById(R.id.CategoryLabel)).setText(R.string.transfer_to_account);
        } else {
            title = type ? R.string.income : R.string.expense;
        }
    }

    String amountText;
    String accountLabel = Account.getInstanceFromDb(mTransaction.accountId).label;
    if (mTransaction instanceof Transfer) {
        ((TextView) mLayout.findViewById(R.id.Account)).setText(type ? mTransaction.label : accountLabel);
        ((TextView) mLayout.findViewById(R.id.Category)).setText(type ? accountLabel : mTransaction.label);
        if (((Transfer) mTransaction).isSameCurrency()) {
            amountText = formatCurrencyAbs(mTransaction.getAmount());
        } else {
            String self = formatCurrencyAbs(mTransaction.getAmount());
            String other = formatCurrencyAbs(mTransaction.getTransferAmount());
            amountText = type == ExpenseEdit.EXPENSE ? (self + " => " + other) : (other + " => " + self);
        }
    } else {
        ((TextView) mLayout.findViewById(R.id.Account)).setText(accountLabel);
        if ((mTransaction.getCatId() != null && mTransaction.getCatId() > 0)) {
            ((TextView) mLayout.findViewById(R.id.Category)).setText(mTransaction.label);
        } else {
            mLayout.findViewById(R.id.CategoryRow).setVisibility(View.GONE);
        }
        amountText = formatCurrencyAbs(mTransaction.getAmount());
    }

    //noinspection SetTextI18n
    ((TextView) mLayout.findViewById(R.id.Date))
            .setText(DateFormat.getDateInstance(DateFormat.FULL).format(mTransaction.getDate()) + " "
                    + DateFormat.getTimeInstance(DateFormat.SHORT).format(mTransaction.getDate()));

    ((TextView) mLayout.findViewById(R.id.Amount)).setText(amountText);

    if (!mTransaction.comment.equals("")) {
        ((TextView) mLayout.findViewById(R.id.Comment)).setText(mTransaction.comment);
    } else {
        mLayout.findViewById(R.id.CommentRow).setVisibility(View.GONE);
    }

    if (!mTransaction.referenceNumber.equals("")) {
        ((TextView) mLayout.findViewById(R.id.Number)).setText(mTransaction.referenceNumber);
    } else {
        mLayout.findViewById(R.id.NumberRow).setVisibility(View.GONE);
    }

    if (!mTransaction.payee.equals("")) {
        ((TextView) mLayout.findViewById(R.id.Payee)).setText(mTransaction.payee);
        ((TextView) mLayout.findViewById(R.id.PayeeLabel)).setText(type ? R.string.payer : R.string.payee);
    } else {
        mLayout.findViewById(R.id.PayeeRow).setVisibility(View.GONE);
    }

    if (mTransaction.methodId != null) {
        ((TextView) mLayout.findViewById(R.id.Method))
                .setText(PaymentMethod.getInstanceFromDb(mTransaction.methodId).getLabel());
    } else {
        mLayout.findViewById(R.id.MethodRow).setVisibility(View.GONE);
    }

    if (Account.getInstanceFromDb(mTransaction.accountId).type.equals(AccountType.CASH)) {
        mLayout.findViewById(R.id.StatusRow).setVisibility(View.GONE);
    } else {
        TextView tv = (TextView) mLayout.findViewById(R.id.Status);
        tv.setBackgroundColor(mTransaction.crStatus.color);
        tv.setText(mTransaction.crStatus.toString());
    }

    if (mTransaction.originTemplate == null) {
        mLayout.findViewById(R.id.PlannerRow).setVisibility(View.GONE);
    } else {
        ((TextView) mLayout.findViewById(R.id.Plan))
                .setText(mTransaction.originTemplate.getPlan() == null ? getString(R.string.plan_event_deleted)
                        : Plan.prettyTimeInfo(getActivity(), mTransaction.originTemplate.getPlan().rrule,
                                mTransaction.originTemplate.getPlan().dtstart));
    }

    dlg.setTitle(title);
    if (doShowPicture) {
        ImageView image = ((ImageView) dlg.getWindow().findViewById(android.R.id.icon));
        image.setVisibility(View.VISIBLE);
        image.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Picasso.with(ctx).load(mTransaction.getPictureUri()).fit().into(image);
    }
}

From source file:org.mariotaku.twidere.adapter.AutoCompleteAdapter.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    if (isCursorClosed())
        return;/*from  w  w w . j  a v  a2 s .com*/
    final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
    final TextView text2 = (TextView) view.findViewById(android.R.id.text2);
    final ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
    if (mScreenNameIdx != -1) {
        text1.setText(cursor.getString(mNameIdx));
        text2.setText("@" + cursor.getString(mScreenNameIdx));
    } else {
        text1.setText("#" + cursor.getString(mNameIdx));
        text2.setText(R.string.hashtag);
    }
    icon.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
    if (mProfileImageUrlIdx != -1) {
        if (mDisplayProfileImage && mProfileImageLoader != null) {
            final String profile_image_url_string = cursor.getString(mProfileImageUrlIdx);
            mProfileImageLoader.displayImage(icon, profile_image_url_string);
        } else {
            icon.setImageResource(R.drawable.ic_profile_image_default);
        }
    } else {
        icon.setImageResource(R.drawable.ic_menu_hashtag);
    }
    super.bindView(view, context, cursor);
}

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  ww.j a va 2s .  co 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:org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder.java

private void displayUserProfileImages(final ParcelableUser[] statuses) {
    final MediaLoaderWrapper imageLoader = adapter.getMediaLoader();
    if (statuses == null) {
        for (final ImageView view : profileImageViews) {
            imageLoader.cancelDisplayTask(view);
            view.setVisibility(View.GONE);
        }/*from   w ww . ja  v  a2 s . c  o  m*/
        return;
    }
    final int length = Math.min(profileImageViews.length, statuses.length);
    final boolean shouldDisplayImages = adapter.isProfileImageEnabled();
    profileImagesContainer.setVisibility(shouldDisplayImages ? View.VISIBLE : View.GONE);
    if (!shouldDisplayImages)
        return;
    for (int i = 0, j = profileImageViews.length; i < j; i++) {
        final ImageView view = profileImageViews[i];
        view.setImageDrawable(null);
        if (i < length) {
            view.setVisibility(View.VISIBLE);
            imageLoader.displayProfileImage(view, statuses[i].profile_image_url);
        } else {
            imageLoader.cancelDisplayTask(view);
            view.setVisibility(View.GONE);
        }
    }
    if (statuses.length > profileImageViews.length) {
        final Context context = adapter.getContext();
        final int moreNumber = statuses.length - profileImageViews.length;
        profileImageMoreNumber.setVisibility(View.VISIBLE);
        profileImageMoreNumber.setText(context.getString(R.string.and_more, moreNumber));
    } else {
        profileImageMoreNumber.setVisibility(View.GONE);
    }
}

From source file:com.android.contacts.list.MultiSelectContactsListFragment.java

protected void bindListHeaderCustom(View listView, View accountFilterContainer) {
    bindListHeaderCommon(listView, accountFilterContainer);

    final TextView accountFilterHeader = (TextView) accountFilterContainer
            .findViewById(R.id.account_filter_header);
    accountFilterHeader.setText(R.string.listCustomView);
    accountFilterHeader.setAllCaps(false);

    final ImageView accountFilterHeaderIcon = (ImageView) accountFilterContainer
            .findViewById(R.id.account_filter_icon);
    accountFilterHeaderIcon.setVisibility(View.GONE);
}