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:org.npr.android.news.NewsListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.news_item, parent, false);
    }//from  w  w w  . j a v  a  2 s  .co m

    Story story = getItem(position);

    ImageView image = (ImageView) convertView.findViewById(R.id.NewsItemImage);
    TextView teaser = (TextView) convertView.findViewById(R.id.NewsItemTeaserText);
    TextView name = (TextView) convertView.findViewById(R.id.NewsItemNameText);

    if (story != null) {
        image.setImageDrawable(getContext().getResources()
                .getDrawable(isPlayable(story) ? R.drawable.icon_listen_main : R.drawable.bullet));
        image.setVisibility(View.VISIBLE);
        name.setTypeface(headlineTypeface, Typeface.NORMAL);
        name.setText(story.toString());
        String teaserText = story.getMiniTeaser();
        if (teaserText == null) {
            teaserText = story.getTeaser();
        }
        if (teaserText != null && teaserText.length() > 0) {
            // Disable for now.
            //        teaser.setText(story.getTeaser());
            //        teaser.setVisibility(View.VISIBLE);
        } else {
            teaser.setVisibility(View.INVISIBLE);
        }
        teaser.setVisibility(View.GONE);
    } else {
        // null marker means it's the end of the list.
        image.setVisibility(View.INVISIBLE);
        teaser.setVisibility(View.INVISIBLE);
        name.setTypeface(Typeface.SANS_SERIF, Typeface.ITALIC);
        name.setText(R.string.msg_load_more);
    }
    return convertView;
}

From source file:com.example.hifadhi.utils.CacheImageDownloader.java

/**
 * Same as download but the image is always downloaded and the cache is not
 * used. Kept private at the moment as its interest is not clear.
 *///from   w  w w  . j  a v  a2 s.  c om
private void forceDownload(final String url, final ImageView imageView, final String cookie) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        imageView.setVisibility(View.GONE);
        return;
    }

    if (CacheImageDownloader.cancelPotentialDownload(url, imageView)) {
        final BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        final DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
        imageView.setImageDrawable(downloadedDrawable);
        task.execute(url, cookie);
    }
}

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

/**
 * Method to show a GO Icon inside the cardview in {@link it.polimi.wifidirect.DeviceDetailFragment}
 * of the connected device.//from  ww w. j  a v a2 s. c o m
 * This is useful to identify which device is a GO.
 */
public void showConnectedDeviceGoIcon() {
    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.setImageDrawable(getResources().getDrawable(R.drawable.go_logo_black));
        deviceGoLogoImageView.setVisibility(View.VISIBLE);
        device_i_am_a_go_textView.setVisibility(View.VISIBLE);
    }
}

From source file:org.nativescript.widgets.TabLayout.java

private void setupItem(LinearLayout ll, TextView textView, ImageView imgView, TabItemSpec tabItem) {
    float density = getResources().getDisplayMetrics().density;

    if (tabItem.iconId != 0) {
        imgView.setImageResource(tabItem.iconId);
        imgView.setVisibility(VISIBLE);
    } else if (tabItem.iconDrawable != null) {
        imgView.setImageDrawable(tabItem.iconDrawable);
        imgView.setVisibility(VISIBLE);/*from w w  w.  jav  a2s .  c o  m*/
    } else {
        imgView.setVisibility(GONE);
    }

    if (tabItem.title != null && !tabItem.title.isEmpty()) {
        textView.setText(tabItem.title);
        textView.setVisibility(VISIBLE);
    } else {
        textView.setVisibility(GONE);
    }

    if (imgView.getVisibility() == VISIBLE && textView.getVisibility() == VISIBLE) {
        ll.setMinimumHeight((int) (LARGE_MIN_HEIGHT * density));
    } else {
        ll.setMinimumHeight((int) (SMALL_MIN_HEIGHT * density));
    }

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

From source file:com.rainmakerlabs.bleepsample.BleepService.java

public void imgShow(Bitmap bitmap, String strImgMsg) {
    MainActivity.adlib.put(strImgMsg, bitmap);
    Log.d("Portal", "Added an image. Size is now " + MainActivity.adlib.size());
    Log.i("Portal", "Image added for key " + strImgMsg);

    if (MainActivity.myGallery == null)
        return;//from   ww w . ja  v a2 s. co m

    if (MainActivity.gal_size < MainActivity.adlib.size()) { //new image has been added and the layout is initialized
        LinearLayout superLL = (LinearLayout) MainActivity.myGallery.getParent().getParent();

        if (MainActivity.gal_size < 1) {
            ImageView imgSplash = (ImageView) superLL.findViewById(R.id.imgSplash);
            imgSplash.setVisibility(View.INVISIBLE);
        }

        LinearLayout layout = new LinearLayout(getApplicationContext());
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        layout.setGravity(Gravity.CENTER);

        ImageView imageview = new ImageView(getApplicationContext());
        imageview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1000));
        imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageview.setImageBitmap(bitmap);

        //Add a button to go with it
        Button btnBuy = new Button(getApplicationContext());
        LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        btnParams.setMargins(-10, -10, -10, -10);
        btnBuy.setLayoutParams(btnParams);
        btnBuy.setText("Buy Now (" + strImgMsg + ")");
        btnBuy.setBackgroundColor(MainActivity.getDominantColor(bitmap));
        btnBuy.setTextColor(Color.WHITE);

        btnBuy.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent newActivity = new Intent(getApplicationContext(), WebActivity.class);
                newActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                newActivity.putExtra("URL", "https://portal-battlehack.herokuapp.com/");
                startActivity(newActivity);
            }
        });

        layout.addView(imageview);
        layout.addView(btnBuy);
        MainActivity.myGallery.addView(layout);
        MainActivity.gal_size++;
    }

}

From source file:com.android.calendar.event.EventLocationAdapter.java

@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
    View view = convertView;//from  ww w  .j av  a  2 s.  com
    if (view == null) {
        view = mInflater.inflate(R.layout.location_dropdown_item, parent, false);
    }
    final Result result = getItem(position);
    if (result == null) {
        return view;
    }

    // Update the display name in the item in auto-complete list.
    TextView nameView = (TextView) view.findViewById(R.id.location_name);
    if (nameView != null) {
        if (result.mName == null) {
            nameView.setVisibility(View.GONE);
        } else {
            nameView.setVisibility(View.VISIBLE);
            nameView.setText(result.mName);
        }
    }

    // Update the address line.
    TextView addressView = (TextView) view.findViewById(R.id.location_address);
    if (addressView != null) {
        addressView.setText(result.mAddress);
    }

    // Update the icon.
    final ImageView imageView = (ImageView) view.findViewById(R.id.icon);
    if (imageView != null) {
        if (result.mDefaultIcon == null) {
            imageView.setVisibility(View.INVISIBLE);
        } else {
            imageView.setVisibility(View.VISIBLE);
            imageView.setImageResource(result.mDefaultIcon);

            // Save the URI on the view, so we can check against it later when updating
            // the image.  Otherwise the async image update with using 'convertView' above
            // resulted in the wrong list items being updated.
            imageView.setTag(result.mContactPhotoUri);
            if (result.mContactPhotoUri != null) {
                Bitmap cachedPhoto = mPhotoCache.get(result.mContactPhotoUri);
                if (cachedPhoto != null) {
                    // Use photo in cache.
                    imageView.setImageBitmap(cachedPhoto);
                } else {
                    // Asynchronously load photo and update.
                    asyncLoadPhotoAndUpdateView(result.mContactPhotoUri, imageView);
                }
            }
        }
    }
    return view;
}

From source file:com.andrewshu.android.reddit.threads.BitmapManager.java

public void fetchBitmapOnThread(final String urlString, final ImageView imageView,
        final ProgressBar indeterminateProgressBar, final Activity act) {
    SoftReference<Bitmap> ref = mCache.get(urlString);
    if (ref != null && ref.get() != null) {
        imageView.setImageBitmap(ref.get());
        return;/*from   ww  w  .  jav  a  2 s.c o  m*/
    }

    final Runnable progressBarShow = new Runnable() {
        public void run() {
            if (indeterminateProgressBar != null) {
                imageView.setVisibility(View.GONE);
                indeterminateProgressBar.setVisibility(View.VISIBLE);
            }
        }
    };
    final Runnable progressBarHide = new Runnable() {
        public void run() {
            if (indeterminateProgressBar != null) {
                indeterminateProgressBar.setVisibility(View.GONE);
                imageView.setVisibility(View.VISIBLE);
            }
        }
    };

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            if (indeterminateProgressBar != null && act != null)
                act.runOnUiThread(progressBarHide);
            imageView.setImageBitmap((Bitmap) message.obj);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            if (indeterminateProgressBar != null && act != null)
                act.runOnUiThread(progressBarShow);
            Bitmap bitmap = fetchBitmap(urlString);
            Message message = handler.obtainMessage(1, bitmap);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

From source file:com.money.manager.ex.fragment.HomeFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    MainActivity mainActivity = null;//w  ww  .ja v  a  2 s  .com
    if (getActivity() != null && getActivity() instanceof MainActivity)
        mainActivity = (MainActivity) getActivity();

    switch (loader.getId()) {
    case ID_LOADER_USER_NAME:
        if (data != null && data.moveToFirst()) {
            while (data.isAfterLast() == false) {
                String infoValue = data.getString(data.getColumnIndex(infoTable.INFONAME));
                // save into preferences username and basecurrency id
                if (Constants.INFOTABLE_USERNAME.equalsIgnoreCase(infoValue)) {
                    application.setUserName(data.getString(data.getColumnIndex(infoTable.INFOVALUE)));
                } else if (Constants.INFOTABLE_BASECURRENCYID.equalsIgnoreCase(infoValue)) {
                    //application.setBaseCurrencyId(data.getInt(data.getColumnIndex(infoTable.INFOVALUE)));
                }
                data.moveToNext();
            }
        }
        // show username
        if (!TextUtils.isEmpty(application.getUserName()))
            ((SherlockFragmentActivity) getActivity()).getSupportActionBar()
                    .setSubtitle(application.getUserName());
        // set user name on drawer
        if (mainActivity != null)
            mainActivity.setDrawableUserName(application.getUserName());

        break;

    case ID_LOADER_ACCOUNT_BILLS:
        double curTotal = 0, curReconciled = 0;
        AccountBillsAdapter adapter = null;

        linearHome.setVisibility(data != null && data.getCount() > 0 ? View.VISIBLE : View.GONE);
        linearWelcome.setVisibility(linearHome.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);

        // cycle cursor
        if (data != null && data.moveToFirst()) {
            while (data.isAfterLast() == false) {
                curTotal += data.getDouble(data.getColumnIndex(QueryAccountBills.TOTALBASECONVRATE));
                curReconciled += data.getDouble(data.getColumnIndex(QueryAccountBills.RECONCILEDBASECONVRATE));
                data.moveToNext();
            }
            // create adapter
            adapter = new AccountBillsAdapter(getActivity(), data);
        }
        // write accounts total
        txtTotalAccounts.setText(currencyUtils.getBaseCurrencyFormatted(curTotal));
        // manage footer listview
        if (linearFooter == null) {
            linearFooter = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.item_account_bills,
                    null);
            // textview into layout
            txtFooterSummary = (TextView) linearFooter.findViewById(R.id.textVievItemAccountTotal);
            txtFooterSummaryReconciled = (TextView) linearFooter
                    .findViewById(R.id.textVievItemAccountTotalReconciled);
            // set text
            TextView txtTextSummary = (TextView) linearFooter.findViewById(R.id.textVievItemAccountName);
            txtTextSummary.setText(R.string.summary);
            // invisibile image
            ImageView imgSummary = (ImageView) linearFooter.findViewById(R.id.imageViewAccountType);
            imgSummary.setVisibility(View.INVISIBLE);
            // set color textview
            txtTextSummary.setTextColor(Color.GRAY);
            txtFooterSummary.setTextColor(Color.GRAY);
            txtFooterSummaryReconciled.setTextColor(Color.GRAY);
        }
        // remove footer
        lstAccountBills.removeFooterView(linearFooter);
        // set text
        txtFooterSummary.setText(txtTotalAccounts.getText());
        txtFooterSummaryReconciled.setText(currencyUtils.getBaseCurrencyFormatted(curReconciled));
        // add footer
        lstAccountBills.addFooterView(linearFooter, null, false);
        // set adapter and shown
        lstAccountBills.setAdapter(adapter);
        setListViewAccountBillsVisible(true);
        // set total accounts in drawer
        if (mainActivity != null) {
            mainActivity.setDrawableTotalAccounts(txtTotalAccounts.getText().toString());
        }
        break;

    case ID_LOADER_BILL_DEPOSITS:
        mainActivity.setDrawableRepeatingTransactions(data != null ? data.getCount() : 0);
        break;

    case ID_LOADER_INCOME_EXPENSES:
        double income = 0, expenses = 0;
        if (data != null && data.moveToFirst()) {
            while (!data.isAfterLast()) {
                expenses = data.getDouble(data.getColumnIndex(QueryReportIncomeVsExpenses.Expenses));
                income = data.getDouble(data.getColumnIndex(QueryReportIncomeVsExpenses.Income));
                //move to next record
                data.moveToNext();
            }
        }
        TextView txtIncome = (TextView) getActivity().findViewById(R.id.textViewIncome);
        TextView txtExpenses = (TextView) getActivity().findViewById(R.id.textViewExpenses);
        TextView txtDifference = (TextView) getActivity().findViewById(R.id.textViewDifference);
        // set value
        if (txtIncome != null)
            txtIncome.setText(currencyUtils.getCurrencyFormatted(currencyUtils.getBaseCurrencyId(), income));
        if (txtExpenses != null)
            txtExpenses.setText(
                    currencyUtils.getCurrencyFormatted(currencyUtils.getBaseCurrencyId(), Math.abs(expenses)));
        if (txtDifference != null)
            txtDifference.setText(currencyUtils.getCurrencyFormatted(currencyUtils.getBaseCurrencyId(),
                    income - Math.abs(expenses)));
        // manage progressbar
        final ProgressBar barIncome = (ProgressBar) getActivity().findViewById(R.id.progressBarIncome);
        final ProgressBar barExpenses = (ProgressBar) getActivity().findViewById(R.id.progressBarExpenses);

        if (barIncome != null && barExpenses != null) {
            barIncome.setMax((int) (Math.abs(income) + Math.abs(expenses)));
            barExpenses.setMax((int) (Math.abs(income) + Math.abs(expenses)));

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                ObjectAnimator animationIncome = ObjectAnimator.ofInt(barIncome, "progress",
                        (int) Math.abs(income));
                animationIncome.setDuration(1000); // 0.5 second
                animationIncome.setInterpolator(new DecelerateInterpolator());
                animationIncome.start();

                ObjectAnimator animationExpenses = ObjectAnimator.ofInt(barExpenses, "progress",
                        (int) Math.abs(expenses));
                animationExpenses.setDuration(1000); // 0.5 second
                animationExpenses.setInterpolator(new DecelerateInterpolator());
                animationExpenses.start();
            } else {
                barIncome.setProgress((int) Math.abs(income));
                barExpenses.setProgress((int) Math.abs(expenses));
            }
        }
    }
}

From source file:au.org.ala.fielddata.mobile.service.FieldDataServiceClient.java

public void loadSurveyImage(ImageView imageView, String imageUrl) {
    String url = getServerUrl() + imageUrl;
    Log.d("FieldDataServiceClient", "loading survey image: " + url);
    Log.d("URL", "downloading species: " + url);
    ImageLoader.getInstance().displayImage(url, imageView, new SimpleImageLoadingListener() {

        public void onLoadingComplete(String arg0, View imageView, Bitmap arg2) {
            imageView.setVisibility(View.VISIBLE);
        }// www .j a v a 2  s  .  com
    });
}

From source file:com.google.dotorg.crisisresponse.translationcards.RecordingActivity.java

private void moveToLabelStep() {
    setContentView(R.layout.recording_label);
    recycleBitmap();//from  w  w w .ja v  a  2s . c o  m
    currentBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.recording_label_image);
    currentBitmapView = (ImageView) findViewById(R.id.recording_label_image);
    currentBitmapView.setImageBitmap(currentBitmap);
    final EditText labelField = (EditText) findViewById(R.id.recording_label_field);
    if (label != null) {
        labelField.setText(label);
        labelField.setTextColor(Color.BLACK);
        labelField.setSelection(label.length());
        setLabelNextButtonEnabled(true);
    }
    if (inEditMode) {
        ImageView deleteButton = (ImageView) findViewById(R.id.recording_label_delete_image);
        deleteButton.setVisibility(View.VISIBLE);
        deleteButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DbManager dbm = new DbManager(RecordingActivity.this);
                dbm.deleteTranslation(translationId);
                if (!isAsset) {
                    File oldFile = new File(filename);
                    oldFile.delete();
                    if (!savedIsAsset && (savedFilename != null) && !savedFilename.equals(filename)) {
                        oldFile = new File(savedFilename);
                        oldFile.delete();
                    }
                }
                setResult(RESULT_OK);
                finish();
            }
        });
        findViewById(R.id.recording_label_step_marker).setVisibility(View.GONE);
    }
    labelField.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus
                    && labelField.getText().toString().equals(getString(R.string.recording_label_hint_text))) {
                labelField.setText("");
                labelField.setTextColor(Color.BLACK);
            } else if (!hasFocus && labelField.getText().toString().equals("")) {
                labelField.setText(getString(R.string.recording_label_hint_text));
                labelField.setTextColor(getResources().getColor(R.color.borderColor));
            }
            if (hasFocus) {
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                inputMethodManager.toggleSoftInputFromWindow(labelField.getApplicationWindowToken(),
                        InputMethodManager.SHOW_FORCED, 0);
            }
        }
    });
    labelField.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Do nothing here.
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() != 0 && !s.equals(getString(R.string.recording_label_hint_text))) {
                setLabelNextButtonEnabled(true);
            } else {
                setLabelNextButtonEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
            // Do nothing here.
        }
    });
    View nextButton = (View) findViewById(R.id.recording_label_next);
    nextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            label = labelField.getText().toString();
            if (label.length() == 0 || label.equals(getString(R.string.recording_label_hint_text))) {
                return;
            }
            moveToAudioStep();
        }
    });
    stepHistory.push(Step.LABEL);
}