Example usage for android.widget ListView getChoiceMode

List of usage examples for android.widget ListView getChoiceMode

Introduction

In this page you can find the example usage for android.widget ListView getChoiceMode.

Prototype

public int getChoiceMode() 

Source Link

Usage

From source file:org.kontalk.ui.ComposeMessageFragment.java

@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    int choiceMode = listView.getChoiceMode();
    if (choiceMode == ListView.CHOICE_MODE_NONE || choiceMode == ListView.CHOICE_MODE_SINGLE) {
        MessageListItem item = (MessageListItem) view;
        final CompositeMessage msg = item.getMessage();

        AttachmentComponent attachment = (AttachmentComponent) msg.getComponent(AttachmentComponent.class);

        if (attachment != null && (attachment.getFetchUrl() != null || attachment.getLocalUri() != null)) {

            // outgoing message or already fetched
            if (attachment.getLocalUri() != null) {
                // open file
                openFile(msg);/*  ww  w .j  a v a  2  s.  co  m*/
            } else {
                // info & download dialog
                CharSequence message = MessageUtils.getFileInfoMessage(getActivity(), msg,
                        mUserPhone != null ? mUserPhone : mUserJID);

                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity())
                        .setTitle(R.string.title_file_info).setMessage(message)
                        .setNegativeButton(android.R.string.cancel, null).setCancelable(true);

                if (!DownloadService.isQueued(attachment.getFetchUrl())) {
                    DialogInterface.OnClickListener startDL = new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // start file download
                            startDownload(msg);
                        }
                    };
                    builder.setPositiveButton(R.string.download, startDL);
                } else {
                    DialogInterface.OnClickListener stopDL = new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // cancel file download
                            stopDownload(msg);
                        }
                    };
                    builder.setPositiveButton(R.string.download_cancel, stopDL);
                }

                builder.show();
            }
        }

        else {
            item.onClick();
        }
    } else {
        super.onListItemClick(listView, view, position, id);
    }
}