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:com.vuze.android.remote.AndroidUtilsUI.java

public static boolean handleBrokenListViewScrolling(Activity a, int keyCode) {
    // Hack for FireTV 1st Gen (and possibly others):
    // sometimes scrolling up/down stops being processed by ListView,
    // even though there's more list to show.  Handle this manually
    // Dirty implemenation -- doesn't take into consideration disabled rows
    // or page-up/down/top/bottom key modifiers
    if (keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        ListView lv = null;

        View currentFocus = a.getCurrentFocus();
        if (currentFocus instanceof ListView) {
            lv = (ListView) currentFocus;
            if (lv.getChoiceMode() == ListView.CHOICE_MODE_SINGLE) {
                int position = lv.getSelectedItemPosition();
                if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                    position--;//  w  w  w  .  j av a2  s .c o m
                } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                    position++;
                }

                if (position > 0 && position < lv.getCount()) {
                    lv.setSelection(position);
                    return true;
                }
            }
        }

        //         // For RecyclerView, we just need to scroll the next item into
        //         // view, so that the super logic can find that the next down/up
        //         // item exists.
        //         // A PreCachingLayoutManager might also fix this problem
        //         if (currentFocus != null &&
        //               currentFocus.getParent() instanceof RecyclerView) {
        //            RecyclerView rv = (RecyclerView) currentFocus.getParent();
        //            RecyclerView.Adapter adapter = rv.getAdapter();
        //            if (adapter instanceof FlexibleRecyclerAdapter) {
        //               int position = ((FlexibleRecyclerAdapter) adapter)
        //                     .getSelectedPosition();
        //               if (position >= 0) {
        //                  if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
        //                     position--;
        //                  } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        //                     position++;
        //                  }
        //
        //                  if (position >= 0 && position < adapter.getItemCount()) {
        //                     rv.scrollToPosition(position);
        //                     Log.d(TAG, "handleBrokenListViewScrolling: DPAD HANDLED ");
        //                     return false;
        //                  }
        //               }
        //            }
        //         }
    }

    return false;
}

From source file:com.akalipetis.action_mode_list_fragment.ActionModeListFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    ListView list = getListView();
    int choiceMode = list.getChoiceMode();
    mLastChoiceMode = choiceMode;//from w  ww.  jav a2s.c  o  m
    if (choiceMode == ListView.CHOICE_MODE_SINGLE)
        mLastCheckedItem = list.getCheckedItemPosition();
    else
        mLastCheckedItem = ListView.INVALID_POSITION;
    if (Build.VERSION.SDK_INT < 11) {
        list.setItemChecked(mLastCheckedItem, false);

        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        list.setLongClickable(false);
        ((ActionBarActivity) getActivity()).startSupportActionMode(new InternalOlderListener());
        if (mListener != null)
            mListener.onItemCheckedStateChanged(mWrapper, position, id, true);
    } else {
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    }
    list.setItemChecked(position, true);
    return true;
}

From source file:com.akalipetis.fragment.ActionModeListFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    ListView list = getListView();
    int choiceMode = list.getChoiceMode();
    mLastChoiceMode = choiceMode;/*  w  w w  .j av a 2 s  .com*/
    if (choiceMode == ListView.CHOICE_MODE_SINGLE)
        mLastCheckedItem = list.getCheckedItemPosition();
    else
        mLastCheckedItem = ListView.INVALID_POSITION;
    if (Build.VERSION.SDK_INT < 11) {
        list.setItemChecked(mLastCheckedItem, false);

        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        list.setLongClickable(false);
        ((AppCompatActivity) getActivity()).startSupportActionMode(new InternalOlderListener());
        list.setItemChecked(position, true);
        if (mListener != null)
            mListener.onItemCheckedStateChanged(mWrapper, position, id, true);
    } else {
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        list.setItemChecked(position, true);
    }
    return true;
}

From source file:com.akalipetis.action_mode_list_fragment.ActionModeListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    int choiceMode = l.getChoiceMode();
    if (!(choiceMode == ListView.CHOICE_MODE_MULTIPLE))
        return;//from w  w w  .  j  a va  2  s .co  m
    boolean checked = l.isItemChecked(position);
    if (mListener != null)
        mListener.onItemCheckedStateChanged(mWrapper, position, id, checked);
    int checkedCount = calculateCheckedItems();
    if (checkedCount <= 0) {
        if (mWrapper != null)
            mWrapper.finish();
    }
}

From source file:com.tomeokin.lspush.ui.widget.dialog.BaseDialogFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (hasListItemClickListener) {
        OnListItemClickListener listener = getDialogListener(OnListItemClickListener.class);
        if (listener != null) {
            listener.onItemClick(getDialog(), requestCode, parent, view, position, id);
        } else {/*from w  ww  .  j  a  v  a2s . com*/
            Intent data = new Intent();
            data.putExtra(BaseDialogBuilder.EXTRA_LIST_ITEM_CLICK_POSITION, position);
            setResult(requestCode, Activity.RESULT_OK, data);
        }

        ListView listView = (ListView) parent;
        if (listView.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) {
            getDialog().dismiss();
        }
    }
}

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

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    int choiceMode = l.getChoiceMode();
    if (choiceMode == ListView.CHOICE_MODE_NONE || choiceMode == ListView.CHOICE_MODE_SINGLE) {
        ConversationListItem cv = (ConversationListItem) v;
        Conversation conv = cv.getConversation();

        ConversationsActivity parent = getParentActivity();
        if (parent != null)
            parent.openConversation(conv, position);
    } else {//from   w  w  w.j  a v a2 s  .  co  m
        super.onListItemClick(l, v, position, id);
    }
}

From source file:com.owncloud.android.ui.adapter.FileListListAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;//from   w ww.j  av  a  2  s .  c  o  m
    if (view == null) {
        LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflator.inflate(R.layout.list_item, null);
    }

    if (mFiles != null && mFiles.size() > position) {
        OCFile file = mFiles.get(position);
        TextView fileName = (TextView) view.findViewById(R.id.Filename);
        String name = file.getFileName();
        if (dataSourceShareFile == null)
            dataSourceShareFile = new DbShareFile(mContext);

        Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
        String[] accountNames = account.name.split("@");

        if (accountNames.length > 2) {
            accountName = accountNames[0] + "@" + accountNames[1];
            url = accountNames[2];
        }
        Map<String, String> fileSharers = dataSourceShareFile.getUsersWhoSharedFilesWithMe(accountName);
        TextView sharer = (TextView) view.findViewById(R.id.sharer);
        ImageView shareButton = (ImageView) view.findViewById(R.id.shareItem);
        fileName.setText(name);
        ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
        fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
        ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
        FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
        if (fileSharers.size() != 0 && (!file.equals("Shared") && file.getRemotePath().contains("Shared"))) {
            if (fileSharers.containsKey(name)) {
                sharer.setText(fileSharers.get(name));
                fileSharers.remove(name);
            } else {
                sharer.setText(" ");
            }
        } else {
            sharer.setText(" ");
        }

        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.downloading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.uploading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (file.isDown()) {
            localStateView.setImageResource(R.drawable.local_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else {
            localStateView.setVisibility(View.INVISIBLE);
        }

        TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
        TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
        ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
        shareButton.setOnClickListener(new OnClickListener() {
            String shareStatusDisplay;
            int flagShare = 0;

            @Override
            public void onClick(View v) {
                final Dialog dialog = new Dialog(mContext);
                final OCFile fileToBeShared = (OCFile) getItem(position);
                final ArrayAdapter<String> shareWithFriends;
                final ArrayAdapter<String> shareAdapter;
                final String filePath;
                sharedWith = new ArrayList<String>();
                dataSource = new DbFriends(mContext);
                dataSourceShareFile = new DbShareFile(mContext);
                dialog.setContentView(R.layout.share_file_with);
                dialog.setTitle("Share");
                Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
                String[] accountNames = account.name.split("@");

                if (accountNames.length > 2) {
                    accountName = accountNames[0] + "@" + accountNames[1];
                    url = accountNames[2];
                }

                final AutoCompleteTextView textView = (AutoCompleteTextView) dialog
                        .findViewById(R.id.autocompleteshare);
                Button shareBtn = (Button) dialog.findViewById(R.id.ShareBtn);
                Button doneBtn = (Button) dialog.findViewById(R.id.ShareDoneBtn);
                final ListView listview = (ListView) dialog.findViewById(R.id.alreadySharedWithList);

                textView.setThreshold(2);
                final String itemType;

                filePath = "files" + String.valueOf(fileToBeShared.getRemotePath());
                final String fileName = fileToBeShared.getFileName();
                final String fileRemotePath = fileToBeShared.getRemotePath();
                if (dataSourceShareFile == null)
                    dataSourceShareFile = new DbShareFile(mContext);
                sharedWith = dataSourceShareFile.getUsersWithWhomIhaveSharedFile(fileName, fileRemotePath,
                        accountName, String.valueOf(1));
                shareAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        sharedWith);
                listview.setAdapter(shareAdapter);
                final String itemSource;
                if (fileToBeShared.isDirectory()) {
                    itemType = "folder";
                    int lastSlashInFolderPath = filePath.lastIndexOf('/');
                    itemSource = filePath.substring(0, lastSlashInFolderPath);
                } else {
                    itemType = "file";
                    itemSource = filePath;
                }

                //Permissions disabled with friends app
                ArrayList<String> friendList = dataSource.getFriendList(accountName);
                dataSource.close();
                shareWithFriends = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        friendList);
                textView.setAdapter(shareWithFriends);
                textView.setFocusableInTouchMode(true);
                dialog.show();
                textView.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                    }
                });
                final Handler finishedHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        shareAdapter.notifyDataSetChanged();
                        Toast.makeText(mContext, shareStatusDisplay, Toast.LENGTH_SHORT).show();

                    }
                };
                shareBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final String shareWith = textView.getText().toString();

                        if (shareWith.equals("")) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext,
                                    "Please enter the friends name with whom you want to share",
                                    Toast.LENGTH_SHORT).show();
                        } else if (sharedWith.contains(shareWith)) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext, "You have shared the file with that person",
                                    Toast.LENGTH_SHORT).show();
                        } else {

                            textView.setText("");
                            Runnable runnable = new Runnable() {
                                @Override
                                public void run() {
                                    HttpPost post = new HttpPost(
                                            "http://" + url + "/owncloud/androidshare.php");
                                    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

                                    params.add(new BasicNameValuePair("itemType", itemType));
                                    params.add(new BasicNameValuePair("itemSource", itemSource));
                                    params.add(new BasicNameValuePair("shareType", shareType));
                                    params.add(new BasicNameValuePair("shareWith", shareWith));
                                    params.add(new BasicNameValuePair("permission", permissions));
                                    params.add(new BasicNameValuePair("uidOwner", accountName));
                                    HttpEntity entity;
                                    String shareSuccess = "false";
                                    try {
                                        entity = new UrlEncodedFormEntity(params, "utf-8");
                                        HttpClient client = new DefaultHttpClient();
                                        post.setEntity(entity);
                                        HttpResponse response = client.execute(post);

                                        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                                            HttpEntity entityresponse = response.getEntity();
                                            String jsonentity = EntityUtils.toString(entityresponse);
                                            JSONObject obj = new JSONObject(jsonentity);
                                            shareSuccess = obj.getString("SHARE_STATUS");
                                            flagShare = 1;
                                            if (shareSuccess.equals("true")) {
                                                dataSourceShareFile.putNewShares(fileName, fileRemotePath,
                                                        accountName, shareWith);
                                                sharedWith.add(shareWith);
                                                shareStatusDisplay = "File share succeeded";
                                            } else if (shareSuccess.equals("INVALID_FILE")) {
                                                shareStatusDisplay = "File you are trying to share does not exist";
                                            } else if (shareSuccess.equals("INVALID_SHARETYPE")) {
                                                shareStatusDisplay = "File Share type is invalid";
                                            } else {
                                                shareStatusDisplay = "Share did not succeed. Please check your internet connection";
                                            }

                                            finishedHandler.sendEmptyMessage(flagShare);

                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }

                                }
                            };
                            new Thread(runnable).start();

                        }

                        if (flagShare == 1) {
                        }

                    }

                });
                doneBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                        //dataSourceShareFile.close();
                    }
                });
            }

        });
        //dataSourceShareFile.close();
        if (!file.isDirectory()) {
            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            // this if-else is needed even thoe fav icon is visible by default
            // because android reuses views in listview
            if (!file.keepInSync()) {
                view.findViewById(R.id.imageView3).setVisibility(View.GONE);
            } else {
                view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
            }

            ListView parentList = (ListView) parent;
            if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
                checkBoxV.setVisibility(View.GONE);
            } else {
                if (parentList.isItemChecked(position)) {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
                } else {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
                }
                checkBoxV.setVisibility(View.VISIBLE);
            }

        } else {

            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            checkBoxV.setVisibility(View.GONE);
            view.findViewById(R.id.imageView3).setVisibility(View.GONE);
        }
    }

    return view;
}

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

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    int choiceMode = l.getChoiceMode();
    if (choiceMode == ListView.CHOICE_MODE_NONE || choiceMode == ListView.CHOICE_MODE_SINGLE) {
        // open identity dialog
        // one day this will be the contact info activity
        GroupMembersAdapter.GroupMember member = (GroupMembersAdapter.GroupMember) mMembersAdapter
                .getItem(position);/*from   w  w w . j av  a2s  .  c  o m*/
        showIdentityDialog(member.contact, member.subscribed);
    } else {
        super.onListItemClick(l, v, position, id);
    }
}

From source file:com.simas.vc.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(int position) {
    ListView lv = mNavDrawerFragment.getListView();

    if (position == ListView.INVALID_POSITION || position < lv.getHeaderViewsCount()
            || position >= lv.getCount() - lv.getFooterViewsCount()) {
        // Skip headers and footers
        //noinspection UnnecessaryReturnStatement
        return;//from w ww  . j a  va 2 s .  com
    } else {
        // Check the item in the drawer
        lv.setItemChecked(position, true);

        Object checkedItem = lv.getItemAtPosition(lv.getCheckedItemPosition());
        // Make sure the item is not already selected in the current EditorFragment
        if (lv.getChoiceMode() == ListView.CHOICE_MODE_SINGLE && getEditorFragment() != null
                && getEditorFragment().getItem() != checkedItem) {
            // Select item in pager
            int itemPosInPager = position - lv.getHeaderViewsCount() + 1; // +1 for empty item
            mViewPager.setCurrentItem(itemPosInPager);

            // Close drawer
            mNavDrawerFragment.setDrawerOpen(false);
        }
    }
}

From source file:org.kontalk.ui.AbstractComposeFragment.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 = 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);//from   w  ww  .  j  av a  2s.c o  m
            } else {
                // info & download dialog
                CharSequence message = MessageUtils.getFileInfoMessage(getActivity(), msg, getDecodedPeer(msg));

                MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity())
                        .title(R.string.title_file_info).content(message).negativeText(android.R.string.cancel)
                        .cancelable(true);

                if (!DownloadService.isQueued(attachment.getFetchUrl())) {
                    MaterialDialog.SingleButtonCallback startDL = new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            // start file download
                            startDownload(msg);
                        }
                    };
                    builder.positiveText(R.string.download).onPositive(startDL);
                } else {
                    MaterialDialog.SingleButtonCallback stopDL = new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            // cancel file download
                            stopDownload(msg);
                        }
                    };
                    builder.positiveText(R.string.download_cancel).onPositive(stopDL);
                }

                builder.show();
            }
        }

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