List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:com.tct.mail.ui.ActionBarController.java
@Override public boolean onSuggestionClick(int position) { final Cursor c = mSearchWidget.getSuggestionsAdapter().getCursor(); final boolean haveValidQuery = (c != null) && c.moveToPosition(position); if (!haveValidQuery) { LogUtils.d(LOG_TAG, "onSuggestionClick: Couldn't get a search query"); // We haven't handled this query, but the default behavior will // leave EXTRA_ACCOUNT un-populated, leading to a crash. So claim // that we have handled the event. return true; }/*from ww w . j a v a2 s . co m*/ collapseSearch(); // what is in the text field String queryText = mSearchWidget.getQuery().toString(); // What the suggested query is String query = c.getString(c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1)); // If the text the user typed in is a prefix of what is in the search // widget suggestion query, just take the search widget suggestion // query. Otherwise, it is a suffix and we want to remove matching // prefix portions. if (!TextUtils.isEmpty(queryText) && query.indexOf(queryText) != 0) { final int queryTokenIndex = queryText .lastIndexOf(SearchRecentSuggestionsProvider.QUERY_TOKEN_SEPARATOR); if (queryTokenIndex > -1) { queryText = queryText.substring(0, queryTokenIndex); } // Since we auto-complete on each token in a query, if the query the // user typed up until the last token is a substring of the // suggestion they click, make sure we don't double include the // query text. For example: // user types john, that matches john palo alto // User types john p, that matches john john palo alto // Remove the first john // Only do this if we have multiple query tokens. if (queryTokenIndex > -1 && !TextUtils.isEmpty(query) && query.contains(queryText) && queryText.length() < query.length()) { int start = query.indexOf(queryText); query = query.substring(0, start) + query.substring(start + queryText.length()); } } //TS: junwei-xu 2015-10-27 EMAIL BUGFIX-791734 MOD_S //NOTE: Check if mController is null if (mController != null) { mController.executeSearch(query.trim()); } //TS: junwei-xu 2015-10-27 EMAIL BUGFIX-791734 MOD_E return true; }
From source file:com.xandy.calendar.selectcalendars.SelectCalendarsSyncAdapter.java
private void initData(Cursor c) { if (c == null) { mRowCount = 0;/*from w w w . ja va 2s.c om*/ mData = null; return; } mIdColumn = c.getColumnIndexOrThrow(Calendars._ID); mNameColumn = c.getColumnIndexOrThrow(Calendars.CALENDAR_DISPLAY_NAME); mColorColumn = c.getColumnIndexOrThrow(Calendars.CALENDAR_COLOR); mSyncedColumn = c.getColumnIndexOrThrow(Calendars.SYNC_EVENTS); mAccountNameColumn = c.getColumnIndexOrThrow(Calendars.ACCOUNT_NAME); mAccountTypeColumn = c.getColumnIndexOrThrow(Calendars.ACCOUNT_TYPE); mRowCount = c.getCount(); mData = new CalendarRow[mRowCount]; c.moveToPosition(-1); int p = 0; while (c.moveToNext()) { long id = c.getLong(mIdColumn); mData[p] = new CalendarRow(); mData[p].id = id; mData[p].displayName = c.getString(mNameColumn); mData[p].color = c.getInt(mColorColumn); mData[p].originalSynced = c.getInt(mSyncedColumn) != 0; mData[p].accountName = c.getString(mAccountNameColumn); mData[p].accountType = c.getString(mAccountTypeColumn); if (mChanges.containsKey(id)) { mData[p].synced = mChanges.get(id).synced; } else { mData[p].synced = mData[p].originalSynced; } p++; } }
From source file:com.frostwire.android.gui.Librarian.java
/** * Returns a list of Files./*from w w w .jav a2 s. com*/ * * @param offset - from where (starting at 0) * @param pageSize - how many results * @param fetcher - An implementation of TableFetcher * @return List<FileDescriptor> */ private List<FileDescriptor> getFiles(final Context context, int offset, int pageSize, TableFetcher fetcher, String where, String[] whereArgs) { List<FileDescriptor> result = new ArrayList<>(0); if (context == null || fetcher == null) { return result; } Cursor c = null; try { ContentResolver cr = context.getContentResolver(); String[] columns = fetcher.getColumns(); String sort = fetcher.getSortByExpression(); if (where == null) { where = fetcher.where(); whereArgs = fetcher.whereArgs(); } c = cr.query(fetcher.getContentUri(), columns, where, whereArgs, sort); if (c == null || !c.moveToPosition(offset)) { return result; } fetcher.prepare(c); int count = 1; do { FileDescriptor fd = fetcher.fetch(c); result.add(fd); } while (c.moveToNext() && count++ < pageSize); } catch (Throwable e) { Log.e(TAG, "General failure getting files", e); } finally { if (c != null) { c.close(); } } return result; }
From source file:net.ddns.mlsoftlaberge.mlsoft.contacts.ContactsListFragment.java
@Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // Gets the Cursor object currently bound to the ListView final Cursor cursor = mAdapter.getCursor(); // Moves to the Cursor row corresponding to the ListView item that was clicked cursor.moveToPosition(position); // Creates a contact lookup Uri from contact ID and lookup_key final Uri uri = Contacts.getLookupUri(cursor.getLong(ContactsQuery.ID), cursor.getString(ContactsQuery.LOOKUP_KEY)); // Notifies the parent activity that the user selected a contact. In a two-pane layout, the // parent activity loads a ContactAdminFragment that displays the details for the selected // contact. In a single-pane layout, the parent activity starts a new activity that // displays contact details in its own Fragment. mOnContactSelectedListener.onContactSelected(uri); }
From source file:com.gigathinking.simpleapplock.AppListFragment.java
private void loadAppList() { Cursor cursor = MainActivity.getAppListData().getAppListInfo(); cursor.moveToFirst();/* w w w . j av a 2s . co m*/ if (mList == null) { mList = new ArrayList<String>(); } else { mList.clear(); } mAppMap = new HashMap<String, Boolean>(); int count = cursor.getCount(); for (int i = 0; i < count; ++i) { cursor.moveToPosition(i); mList.add(cursor.getString(2)); mAppMap.put(cursor.getString(2), Boolean.valueOf(cursor.getString(3))); } cursor.close(); }
From source file:com.money.manager.ex.reports.IncomeVsExpensesListFragment.java
private void showChartInternal() { // take a adapter and cursor IncomeVsExpensesAdapter adapter = ((IncomeVsExpensesAdapter) getListAdapter()); if (adapter == null) return;/*from w w w . j a va2s .com*/ Cursor cursor = adapter.getCursor(); if (cursor == null) return; // Move to the first record. if (cursor.getCount() <= 0) return; // arrays ArrayList<Double> incomes = new ArrayList<>(); ArrayList<Double> expenses = new ArrayList<>(); ArrayList<String> titles = new ArrayList<>(); // Reset cursor to initial position. cursor.moveToPosition(-1); // cycle cursor while (cursor.moveToNext()) { int month = cursor.getInt(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Month)); // check if not subtotal if (month != IncomeVsExpensesActivity.SUBTOTAL_MONTH) { // incomes and expenses incomes.add(cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Income))); expenses.add( Math.abs(cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Expenses)))); // titles int year = cursor.getInt(cursor.getColumnIndex(IncomeVsExpenseReportEntity.YEAR)); // format month Calendar calendar = Calendar.getInstance(); calendar.set(year, month - 1, 1); // titles titles.add(Integer.toString(year) + "-" + new SimpleDateFormat("MMM").format(calendar.getTime())); } } //compose bundle for arguments Bundle args = new Bundle(); args.putDoubleArray(IncomeVsExpensesChartFragment.KEY_EXPENSES_VALUES, ArrayUtils.toPrimitive(expenses.toArray(new Double[0]))); args.putDoubleArray(IncomeVsExpensesChartFragment.KEY_INCOME_VALUES, ArrayUtils.toPrimitive(incomes.toArray(new Double[0]))); args.putStringArray(IncomeVsExpensesChartFragment.KEY_XTITLES, titles.toArray(new String[titles.size()])); //get fragment manager FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); if (fragmentManager != null) { IncomeVsExpensesChartFragment fragment; fragment = (IncomeVsExpensesChartFragment) fragmentManager .findFragmentByTag(IncomeVsExpensesChartFragment.class.getSimpleName()); if (fragment == null) { fragment = new IncomeVsExpensesChartFragment(); } fragment.setChartArguments(args); fragment.setDisplayHomeAsUpEnabled(true); if (fragment.isVisible()) fragment.onResume(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (((IncomeVsExpensesActivity) getActivity()).mIsDualPanel) { fragmentTransaction.replace(R.id.fragmentChart, fragment, IncomeVsExpensesChartFragment.class.getSimpleName()); } else { fragmentTransaction.replace(R.id.fragmentMain, fragment, IncomeVsExpensesChartFragment.class.getSimpleName()); fragmentTransaction.addToBackStack(null); } fragmentTransaction.commit(); } }
From source file:com.visva.voicerecorder.view.fragments.FragmentContact.java
@Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // Gets the Cursor object currently bound to the ListView if (mIsOnItemLongClick) { mIsOnItemLongClick = false;//from ww w . j ava 2 s.c om return; } final Cursor cursor = mAdapter.getCursor(); // Moves to the Cursor row corresponding to the ListView item that was clicked cursor.moveToPosition(position); // Creates a contact lookup Uri from contact ID and lookup_key final Uri uri = Contacts.getLookupUri(cursor.getLong(ContactsQuery.ID), cursor.getString(ContactsQuery.LOOKUP_KEY)); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); if (mIsTwoPaneLayout) { mListContact.setItemChecked(position, true); } }
From source file:de.fahrgemeinschaft.RideDetailsFragment.java
@Override public void onViewCreated(View layout, Bundle savedInstanceState) { super.onViewCreated(layout, savedInstanceState); left_arrow = layout.findViewById(R.id.left_arrow); right_arrow = layout.findViewById(R.id.right_arrow); pager = (ViewPager) layout.findViewById(R.id.pager); pager.setAdapter(new BasePagerAdapter() { @Override//from www . j av a 2 s. c om public int getCount() { if (getCursor() == null) return 0; else return getCursor().getCount(); } @Override protected View getView(Object position, View v, ViewGroup parent) { if (v == null) { v = getActivity().getLayoutInflater().inflate(R.layout.view_ride_details, null, false); v.findViewById(R.id.btn_contact).setOnClickListener(RideDetailsFragment.this); } Cursor cursor = getCursor(); if (cursor.isClosed()) return v; RideView view = (RideView) v; if (view.content.getChildCount() > 5) view.content.removeViews(1, view.content.getChildCount() - 5); cursor.moveToPosition((Integer) position); view.url = null; view.from_place.setText(cursor.getString(COLUMNS.FROM_ADDRESS)); view.to_place.setText(cursor.getString(COLUMNS.TO_ADDRESS)); view.row.bind(cursor, getActivity()); view.reoccur.setDays(Ride.getDetails(cursor)); if (view.reoccur.isReoccuring()) view.reoccur.setVisibility(View.VISIBLE); else view.reoccur.setVisibility(View.GONE); if (cursor.getString(COLUMNS.MODE).equals(Mode.CAR.name())) { view.transport_mode.setImageResource(R.drawable.icn_mode_car); } else { view.transport_mode.setImageResource(R.drawable.icn_mode_train); } try { view.details.setText(Ride.getDetails(cursor).getString(FahrgemeinschaftConnector.COMMENT)); } catch (JSONException e) { e.printStackTrace(); } getActivity().getSupportLoaderManager().initLoader((int) cursor.getLong(0), null, view); view.avatar.setImageResource(R.drawable.icn_view_user); view.name.setText(EMPTY); view.last_login.setText(EMPTY); view.reg_date.setText(EMPTY); view.name_loading.setVisibility(View.VISIBLE); view.name.setVisibility(View.GONE); view.last_login.setVisibility(View.GONE); view.reg_date.setVisibility(View.GONE); if (isMyRide(cursor)) { if ((isFuture(cursor.getLong(COLUMNS.DEPARTURE)) && isActive(cursor)) || isReoccuring(cursor)) { view.streifenhoernchen.setVisibility(View.GONE); } else { view.streifenhoernchen.setVisibility(View.VISIBLE); } } else { view.streifenhoernchen.setVisibility(View.GONE); } if (cursor.getString(COLUMNS.WHO).equals(EMPTY)) { String user = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString(CONTACT.USER, EMPTY); queue.add(new ProfileRequest(user, view, RideDetailsFragment.this)); view.userId = user; } else { queue.add(new ProfileRequest(cursor.getString(COLUMNS.WHO), view, RideDetailsFragment.this)); view.userId = cursor.getString(COLUMNS.WHO); } view.visible = Util.isVisible(NAME, Ride.getDetails(cursor)); view.content.setOnTouchListener(RideDetailsFragment.this); return view; } @Override protected Object getItem(int position) { return position; } }); pager.requestFocus(); pulseSwipeArrows(); }
From source file:com.visva.voicerecorder.view.fragments.FragmentContact.java
private void shareThisContactAction(int selectedPosition) { Cursor cursor = mAdapter.getCursor(); // Moves to the Cursor row corresponding to the ListView item that was clicked cursor.moveToPosition(selectedPosition); String contactId = cursor.getString(ContactsQuery.ID); if (StringUtility.isEmpty(contactId)) return;// ww w. j a v a2 s .com ArrayList<String> phones = Utils.getContactUriTypeFromContactId(getActivity().getContentResolver(), contactId); String phone = ""; if (phones == null || phones.size() == 0) { phone = ""; } else phone = phones.get(0); String displayName = cursor.getString(ContactsQuery.DISPLAY_NAME); Resources res = getActivity().getResources(); StringBuilder builder = new StringBuilder(); if (!phone.equals(displayName)) builder.append(res.getString(R.string.name)).append(displayName + "\n"); if (!StringUtility.isEmpty(phone)) { builder.append(res.getString(R.string.phone_no)).append(phone); } Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, res.getString(R.string.share_contact)); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, builder.toString()); startActivity(Intent.createChooser(sharingIntent, displayName)); }
From source file:com.logilite.vision.camera.CameraLauncher.java
private int getImageOrientation(Uri uri) { int rotate = 0; String[] cols = { MediaStore.Images.Media.ORIENTATION }; try {/* ww w . ja va2 s.com*/ Cursor cursor = cordova.getActivity().getContentResolver().query(uri, cols, null, null, null); if (cursor != null) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } } catch (Exception e) { // You can get an IllegalArgumentException if ContentProvider doesn't support querying for orientation. } return rotate; }