Example usage for android.widget ListView isItemChecked

List of usage examples for android.widget ListView isItemChecked

Introduction

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

Prototype

public boolean isItemChecked(int position) 

Source Link

Document

Returns the checked state of the specified position.

Usage

From source file:com.morestudio.littledot.doctor.ui.calllog.CallLogListFragment.java

private void actionModeDelete() {
    ListView lv = getListView();

    ArrayList<Long> checkedIds = new ArrayList<Long>();

    for (int i = 0; i < lv.getCount(); i++) {
        if (lv.isItemChecked(i)) {
            long[] selectedIds = mAdapter.getCallIdsAtPosition(i);

            for (long id : selectedIds) {
                checkedIds.add(id);/*from  w ww  . ja v  a  2s  .c  o  m*/
            }

        }
    }
    if (checkedIds.size() > 0) {
        String strCheckedIds = TextUtils.join(", ", checkedIds);
        Log.d(THIS_FILE, "Checked positions (" + strCheckedIds + ")");
        getActivity().getContentResolver().delete(SipManager.CALLLOG_URI,
                Calls._ID + " IN (" + strCheckedIds + ")", null);
        mMode.finish();
    }
}

From source file:com.csipsimple.ui.calllog.CallLogListFragment.java

private void actionModeDelete() {
    ListView lv = getListView();

    ArrayList<Long> checkedIds = new ArrayList<Long>();

    for (int i = 0; i < lv.getCount(); i++) {
        if (lv.isItemChecked(i)) {
            long[] selectedIds = mAdapter.getCallIdsAtPosition(i);

            for (long id : selectedIds) {
                checkedIds.add(id);/*from w  ww. ja v a 2s  .com*/
            }

        }
    }
    if (checkedIds.size() > 0) {
        String strCheckedIds = TextUtils.join(", ", checkedIds);
        Log.d(THIS_FILE, "Checked positions (" + strCheckedIds + ")");
        getActivity().getContentResolver().delete(SipManager.CALLLOG_URI,
                CallLog.Calls._ID + " IN (" + strCheckedIds + ")", null);
        mMode.finish();
    }
}

From source file:com.silentcircle.contacts.editor.GroupMembershipView.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ListView list = (ListView) parent;
    int count = mAdapter.getCount();

    if (list.isItemChecked(count - 1)) {
        list.setItemChecked(count - 1, false);
        createNewGroup();/*from ww  w . j  a v a2  s  .  c  om*/
        return;
    }

    for (int i = 0; i < count; i++) {
        mAdapter.getItem(i).setChecked(list.isItemChecked(i));
    }

    // First remove the memberships that have been unchecked
    ArrayList<RawContactDelta.ValuesDelta> entries = mState.getMimeEntries(GroupMembership.CONTENT_ITEM_TYPE);
    if (entries != null) {
        for (RawContactDelta.ValuesDelta entry : entries) {
            if (!entry.isDelete()) {
                Long groupId = entry.getGroupRowId();
                if (groupId != null && groupId != mFavoritesGroupId
                        && (groupId != mDefaultGroupId || mDefaultGroupVisible) && !isGroupChecked(groupId)) {
                    entry.markDeleted();
                }
            }
        }
    }

    // Now add the newly selected items
    for (int i = 0; i < count; i++) {
        GroupSelectionItem item = mAdapter.getItem(i);
        long groupId = item.getGroupId();
        if (item.isChecked() && !hasMembership(groupId)) {
            RawContactDelta.ValuesDelta entry = RawContactModifier.insertChild(mState, mKind);
            entry.setGroupRowId(groupId);
        }
    }
    updateView();
}

From source file:com.openerp.addons.note.EditNoteFragment.java

public void openTagList() {

    AlertDialog.Builder builder = new AlertDialog.Builder(scope.context());
    note_tags = db.getAllNoteTags();/*w ww  . j av  a  2 s.c o  m*/
    ArrayList<String> keyList = new ArrayList<String>(note_tags.keySet());

    if (keyList.size() > 0) {
        stringArray = new String[keyList.size() - 1];
        stringArray = keyList.toArray(stringArray);

        builder.setTitle("");
        builder.setMultiChoiceItems(stringArray, null, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int item, boolean isChecked) {
            }
        });

        builder.setPositiveButton("", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                AlertDialog d = (AlertDialog) dialog;
                ListView v = d.getListView();
                int i = 0;
                while (i < stringArray.length) {
                    if (v.isItemChecked(i)) {
                        Integer id = Integer
                                .parseInt(note_tags.get(v.getItemAtPosition(i).toString()).toString());

                        if (!selectedTags.containsKey(note_tags.get(v.getItemAtPosition(i).toString()))) {
                            noteTags.addObject(new TagsItems(id, stringArray[i], ""));
                        }
                    }
                    i++;
                }
            }
        });
    } else {
        builder.setTitle(" \n");
    }

    builder.setNegativeButton("?", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface di, int i) {
        }
    });

    builder.setNeutralButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            createNotetag();
        }
    });

    final Dialog dialog = builder.create();
    dialog.show();
}

From source file:com.silentcircle.contacts.editor.GroupMembershipView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void setGroupMetaData(Cursor groupMetaData) {
    this.mGroupMetaData = groupMetaData;
    updateView();/*w w  w .j a  va2 s.c o  m*/
    // Open up the list of groups if a new group was just created.
    if (mCreatedNewGroup) {
        mCreatedNewGroup = false;
        onClick(this); // This causes the popup to open.
        if (mPopup != null || dialogPopup != null) {
            // Ensure that the newly created group is checked.
            int position = mAdapter.getCount() - 2;
            ListView listView = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) ? mPopup.getListView()
                    : GroupCheckPopup.modeList;
            if (!listView.isItemChecked(position)) {
                // Newly created group is not checked, so check it.
                listView.setItemChecked(position, true);
                onItemClick(listView, null, position, listView.getItemIdAtPosition(position));
            }
        }
    }
}

From source file:com.roamprocess1.roaming4world.ui.calllog.CallLogListFragment.java

private void actionModeDialpad() {

    ListView lv = getListView();

    for (int i = 0; i < lv.getCount(); i++) {
        if (lv.isItemChecked(i)) {
            mAdapter.getItem(i);/*w  w w .j a  v  a 2 s . com*/
            /*
            System.out.println("CallLogListFragment =====actionModeDialpad");      
            System.out.println("CallLogListFragment Step 22"); 
              */

            String number = mAdapter.getCallRemoteAtPostion(i);
            if (!TextUtils.isEmpty(number)) {
                Intent it = new Intent(Intent.ACTION_DIAL);
                it.setData(SipUri.forgeSipUri(SipManager.PROTOCOL_SIP, number));
                startActivity(it);
            }
            break;
        }
    }
    mMode.invalidate();

}

From source file:com.roamprocess1.roaming4world.ui.calllog.CallLogListFragment.java

@Override
public void viewDetails(int position, long[] callIds) {
    ListView lv = getListView();
    if (mMode != null) {
        lv.setItemChecked(position, !lv.isItemChecked(position));
        mMode.invalidate();/*from  www  .  j ava2s . c  om*/
        // Don't see details in this case

        System.out.println("CallLogListFragment Step 12");
        return;
    }

    if (mDualPane) {

        System.out.println("CallLogListFragment  === mDualPane");

        System.out.println("CallLogListFragment Step 13");

        // If we are not currently showing a fragment for the new
        // position, we need to create and install a new one.
        CallLogDetailsFragment df = new CallLogDetailsFragment();
        Bundle bundle = new Bundle();
        bundle.putLongArray(CallLogDetailsFragment.EXTRA_CALL_LOG_IDS, callIds);
        df.setArguments(bundle);
        // Execute a transaction, replacing any existing fragment
        // with this one inside the frame.
        System.out.println("CallLogListFragment Step 14");

        try {

            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.replace(R.id.details, df, null);
            ft.addToBackStack(null);
            System.out.println("CallLogListFragment Step 15");
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.commit();

        } catch (Exception e) {
            // TODO: handle exception
        }

        getListView().setItemChecked(position, true);
    } else {
        Intent it = new Intent(getActivity(), CallLogDetailsActivity.class);
        it.putExtra(CallLogDetailsFragment.EXTRA_CALL_LOG_IDS, callIds);
        System.out.println("CallLogListFragment Step 16");
        try {
            getActivity().startActivity(it);
        } catch (Exception e) {
            // TODO: handle exception
        }

    }
}

From source file:org.odk.collect.android.fragments.AppListFragment.java

/**
 * Returns the IDs of the checked items, using the ListView provided
 *//*from www.  j a v a 2 s  . c o  m*/
protected long[] getCheckedIds(ListView lv) {
    // This method could be simplified by using getCheckedItemIds, if one ensured that
    // IDs were stable? (see the getCheckedItemIds doc).
    int itemCount = lv.getCount();
    int checkedItemCount = lv.getCheckedItemCount();
    long[] checkedIds = new long[checkedItemCount];
    int resultIndex = 0;
    for (int posIdx = 0; posIdx < itemCount; posIdx++) {
        if (lv.isItemChecked(posIdx)) {
            checkedIds[resultIndex] = lv.getItemIdAtPosition(posIdx);
            resultIndex++;
        }
    }
    return checkedIds;
}

From source file:org.flerda.android.honeypad.NoteListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (!mIsV11) {
        /*//w  ww  . ja  va2s .c o m
         * Slight Hack: Multiselect lists are automatically
         * Checked/unchecked. If the item was previously checked, it will
         * now be unchecked, etc. We compensate for that here.
         */
        l.setItemChecked(position, !l.isItemChecked(position));
    }
    mCurrentActivePosition = position;
    mContainerCallback.onNoteSelected(ContentUris.withAppendedId(NotesProvider.CONTENT_URI, 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 ww w . j a va 2s .  co 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;
}