Example usage for android.widget ImageView isSelected

List of usage examples for android.widget ImageView isSelected

Introduction

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

Prototype

@ViewDebug.ExportedProperty
public boolean isSelected() 

Source Link

Document

Indicates the selection state of this view.

Usage

From source file:Main.java

public static void startVDAnimation(ImageView imageView, @DrawableRes int inactiveResId,
        @DrawableRes int activeResId, int duration) {
    int drawableResId = imageView.isSelected() ? activeResId : inactiveResId;
    Drawable drawable = ContextCompat.getDrawable(imageView.getContext(), drawableResId);
    imageView.setImageDrawable(drawable);

    if (drawable instanceof Animatable) {
        Animatable animatable = (Animatable) drawable;
        if (animatable.isRunning()) {
            animatable.stop();/*from w w  w. j  ava2s . c o  m*/
        }

        animatable.start();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            imageView.setSelected(!imageView.isSelected());
        } else {
            imageView.postDelayed(() -> {
                imageView.setSelected(!imageView.isSelected());
                int nextDrawableResId = imageView.isSelected() ? activeResId : inactiveResId;
                Drawable nextDrawable = ContextCompat.getDrawable(imageView.getContext(), nextDrawableResId);
                imageView.setImageDrawable(nextDrawable);
            }, duration);
        }
    }
}

From source file:org.arasthel.almeribus.fragments.InfoParadaFragment.java

@Override
public void onStart() {
    ImageView favorito = (ImageView) getView().findViewById(R.id.favorito);
    favorito.setOnClickListener(new OnClickListener() {

        @Override/*  w  w w. j av  a 2 s. c  o  m*/
        public void onClick(View arg0) {
            ImageView favorito = (ImageView) getView().findViewById(R.id.favorito);
            if (favorito.isSelected()) {
                DataStorage.DBHelper.removeFavorito(mNumParada);
                favorito.setImageResource(R.drawable.favorite_button);
            } else {
                DataStorage.DBHelper.addFavorito(mNumParada);
                favorito.setImageResource(R.drawable.ic_menu_favorite_on);
            }
            favorito.setSelected(!favorito.isSelected());
            Intent i = new Intent(ListaParadasFragment.UPDATE_FILTER);
            getActivity().sendBroadcast(i);
        }
    });
    boolean isFavorito = DataStorage.DBHelper.isFavorito(mNumParada);
    if (isFavorito) {
        favorito.setSelected(true);
        favorito.setImageResource(R.drawable.ic_menu_favorite_on);
    } else {
        favorito.setSelected(false);
        favorito.setImageResource(R.drawable.favorite_button);
    }

    ImageView verEnMapa = (ImageView) getView().findViewById(R.id.abrir_mapa);
    verEnMapa.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            double[] coord = DataStorage.paradas.get(mNumParada).getCoord();
            if (coord != null) {
                ((Principal) getActivity()).abrirMapaParadas(new LatLng(coord[1], coord[0]), true);
                ((MostrarInfoParada) getParentFragment()).dismiss();
            }
        }
    });

    LinearLayout listaTiempos = (LinearLayout) content.findViewById(R.id.tiemposEspera);
    listaTiempos.removeAllViews();
    if (mLineas.isEmpty()) {
        TextView tv = new TextView(getActivity());
        tv.setGravity(Gravity.CENTER);
        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        lp.rightMargin = 10;
        lp.leftMargin = 10;
        lp.topMargin = 20;
        tv.setLayoutParams(lp);
        tv.setText(
                "No hay conexin de internet.\n\nPor favor, compruebe que dispone de conexin y vuelva a intentarlo.");
        listaTiempos.addView(tv);
    } else {
        calcularTiempos();
    }
    super.onStart();
}

From source file:com.android.dialer.DialtactsFragment.java

/**
 * @author bbk wangchunhe//from w w  w.j av a  2  s  .  c  o m
 * @Date 2016/07/15
 * add PopupWindow OnClickListener
 * @param popupWindow
 */
private void popupWindowItemSelect(final PopupWindow popupWindow) {
    View contentView = popupWindow.getContentView();
    RelativeLayout callLogsContainer = (RelativeLayout) contentView
            .findViewById(R.id.dialtacts_popupwindow_all_calls_cantainer);
    final TextView callLogsTxt = (TextView) contentView.findViewById(R.id.dialtacts_popupwindow_all_calls_txt);
    final ImageView callLogsImage = (ImageView) contentView
            .findViewById(R.id.dialtacts_popupwindow_all_calls_image);

    RelativeLayout callLogMissedContainer = (RelativeLayout) contentView
            .findViewById(R.id.dialtacts_popupwindow_call_log_missed_container);
    final TextView callLogMissedTxt = (TextView) contentView
            .findViewById(R.id.dialtacts_popupwindow_call_log_missed_txt);
    final ImageView callLogMissedImage = (ImageView) contentView
            .findViewById(R.id.dialtacts_popupwindow_call_log_missed_image);

    ColorStateList colorStateListTxt = getActivity().getColorStateList(R.color.popupwindows_item_text_color);
    ColorStateList colorStateListImage = getActivity().getColorStateList(R.color.popupwindows_item_image_color);

    callLogsImage.setImageTintList(colorStateListImage);
    callLogMissedImage.setImageTintList(colorStateListImage);

    callLogsTxt.setTextColor(colorStateListTxt);
    callLogMissedTxt.setTextColor(colorStateListTxt);

    if (!callLogMissedImage.isSelected()) {
        callLogsImage.setSelected(true);
        callLogsTxt.setSelected(true);
    }

    callLogsContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            callLogsImage.setSelected(true);
            callLogsTxt.setSelected(true);
            callLogMissedImage.setSelected(false);
            callLogMissedTxt.setSelected(false);
            showCallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL);
            //                mActionbarNameTxt.setText(getString(R.string.all_calls));
            //                mDialtactsActionBarController.setActionNameAndMenu(R.string.all_calls,R.string.call_log_missed,R.string.select_call_log);
            Log.e(TAG, " action Name  --1" + mDialtactsActionBarController.getmActionNameTxt().getText());
            mDialtactsActionBarController.setActionName(getString(R.string.all_calls));
            Log.e(TAG, " action Name  --2" + mDialtactsActionBarController.getmActionNameTxt().getText());
            mCallLogSelectPopupWindow.dismiss();

        }
    });

    callLogMissedContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            callLogsImage.setSelected(false);
            callLogsTxt.setSelected(false);
            callLogMissedImage.setSelected(true);
            callLogMissedTxt.setSelected(true);
            showCallLogFragment(Calls.MISSED_TYPE);
            //                mActionbarNameTxt.setText(getString(R.string.call_log_missed));
            //                mDialtactsActionBarController.setActionNameAndMenu(R.string.all_calls,R.string.call_log_missed,R.string.select_call_log);
            Log.e(TAG, " action Name  --3" + mDialtactsActionBarController.getmActionNameTxt().getText());
            mDialtactsActionBarController.setActionName(getString(R.string.call_log_missed));
            Log.e(TAG, " action Name  --4" + mDialtactsActionBarController.getmActionNameTxt().getText());
            mCallLogSelectPopupWindow.dismiss();

        }
    });

}