List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:ga.aditya.udacity01sunshine.app.ForecastFragment.java
private void openPreferredLocationInMap() { // Using the URI scheme for showing a location found on a map. This super-handy // intent can is detailed in the "Common Intents" page of Android's developer site: // http://developer.android.com/guide/components/intents-common.html#Maps if (null != mForecastAdapter) { Cursor c = mForecastAdapter.getmCursor(); if (null != c) { c.moveToPosition(0); String posLat = c.getString(COL_COORD_LAT); String posLong = c.getString(COL_COORD_LONG); Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geoLocation); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent);//w w w . j a v a 2 s. c o m } else { Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!"); } } } }
From source file:org.mozilla.gecko.home.RecentTabsPanel.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { mList = (HomeListView) view.findViewById(R.id.list); mList.setTag(HomePager.LIST_TAG_RECENT_TABS); mList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from www . j a v a 2 s. co m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Cursor c = mAdapter.getCursor(); if (c == null || !c.moveToPosition(position)) { return; } final int itemType = c.getInt(c.getColumnIndexOrThrow(RecentTabs.TYPE)); if (itemType == RecentTabs.TYPE_OPEN_ALL_LAST_TIME) { openTabsWithType(RecentTabs.TYPE_LAST_TIME); return; } if (itemType == RecentTabs.TYPE_OPEN_ALL_CLOSED) { openTabsWithType(RecentTabs.TYPE_CLOSED); return; } Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM); final List<String> dataList = new ArrayList<>(); dataList.add(c.getString(c.getColumnIndexOrThrow(RecentTabs.DATA))); restoreSessionWithHistory(dataList); } }); mList.setContextMenuInfoFactory(new HomeContextMenuInfo.Factory() { @Override public HomeContextMenuInfo makeInfoForCursor(View view, int position, long id, Cursor cursor) { // Don't show context menus for the "Open all" rows. final int itemType = cursor.getInt(cursor.getColumnIndexOrThrow(RecentTabs.TYPE)); if (itemType == RecentTabs.TYPE_OPEN_ALL_LAST_TIME || itemType == RecentTabs.TYPE_OPEN_ALL_CLOSED) { return null; } final HomeContextMenuInfo info = new HomeContextMenuInfo(view, position, id); info.url = cursor.getString(cursor.getColumnIndexOrThrow(RecentTabs.URL)); info.title = cursor.getString(cursor.getColumnIndexOrThrow(RecentTabs.TITLE)); return info; } }); registerForContextMenu(mList); EventDispatcher.getInstance().registerGeckoThreadListener(this, "ClosedTabs:Data"); GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("ClosedTabs:StartNotifications", null)); }
From source file:com.dazone.crewchat.libGallery.fragment.ImageFragment.java
private void setAdapter(Cursor imagecursor) { if (imagecursor.getCount() > 0) { mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false); mGalleryModelList.add(galleryModel); }/*from www. java 2 s . c o m*/ mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false); mImageGridView.setAdapter(mImageAdapter); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mImageGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); return true; } }); mImageGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), false); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) { if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } } // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); MediaChooserConstants.SELECTED_MEDIA_COUNT++; } else { mSelectedItems.remove(galleryModel.url.toString().trim()); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } if (mCallback != null) { mCallback.onImageSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.money.manager.ex.fragment.PayeeListFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; Cursor cursor = ((SimpleCursorAdapter) getListAdapter()).getCursor(); cursor.moveToPosition(info.position); menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(Payee.PAYEENAME))); menu.add(Menu.NONE, ContextMenuIds.EDIT.getId(), Menu.NONE, getString(R.string.edit)); menu.add(Menu.NONE, ContextMenuIds.DELETE.getId(), Menu.NONE, getString(R.string.delete)); menu.add(Menu.NONE, ContextMenuIds.VIEW_TRANSACTIONS.getId(), Menu.NONE, getString(R.string.view_transactions)); }
From source file:net.kayateia.lifestream.TabRecentImages.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final View _view = inflater.inflate(R.layout.recent_history, container, false); ProcessedImages images = ProcessedImages.GetSingleton(getActivity()); final Cursor cursor = images.getCursorOfAll(); if (cursor == null || _view == null) return _view; // getActivity().startManagingCursor(cursor); ListView list = (ListView) _view.findViewById(R.id.listImages); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) { cursor.moveToPosition(position); final String fullName = cursor.getString(cursor.getColumnIndex(ProcessedImages.KEY_FULLNAME)); final Activity activity = getActivity(); if (fullName != null && activity != null) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + fullName), "image/*"); activity.startActivity(intent); }//from w w w. j av a 2s . co m } }); ImageCursorAdapter adapter = new ImageCursorAdapter(getActivity(), cursor); list.setAdapter(adapter); return _view; }
From source file:com.example.de.taomi2.mediachooser.fragment.ImageFragment.java
private void setAdapter(Cursor imagecursor) { if (imagecursor.getCount() > 0) { mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false); mGalleryModelList.add(galleryModel); }//www . ja va2 s .co m mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false); mImageGridView.setAdapter(mImageAdapter); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mImageGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); return true; } }); mImageGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), false); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } /* if((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)){ if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } */ } /* // inverse the status galleryModel.status = ! galleryModel.status; adapter.notifyDataSetChanged(); */ int i = 0; for (; i < adapter.getCount(); i++) { if (i != position) { adapter.getItem(i).status = false; } } galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); mSelectedItems.clear(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); //MediaChooserConstants.SELECTED_MEDIA_COUNT ++; } else { //mSelectedItems.remove(galleryModel.url.toString().trim()); //MediaChooserConstants.SELECTED_MEDIA_COUNT --; } if (mCallback != null) { mCallback.onImageSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.rsegismont.androlife.programlist.FragmentListProgrammes.java
private void setSelection(long date) { int index = -1; final Cursor cursor = getCursor(); final int columnDateIndex = cursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue); final int initialPosition = cursor.getPosition(); for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); if (date == cursor.getLong(columnDateIndex)) { index = i;//from ww w .j a va2 s . c om break; } } if (initialPosition >= 0) cursor.moveToPosition(initialPosition); final int finalIndex = index; try { getListView().post(new Runnable() { @Override public void run() { getListView().setItemChecked(finalIndex, true); getListView().setSelectionFromTop(finalIndex, 0); } }); } catch (Throwable e) { } }
From source file:com.money.manager.ex.recurring.transactions.RecurringTransactionListFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; // take a cursor and move to position Cursor cursor = ((AllDataAdapter) getListAdapter()).getCursor(); if (cursor != null) { cursor.moveToPosition(info.position); // set title and inflate menu menu.setHeaderTitle(getActivity().getTitle()); getActivity().getMenuInflater().inflate(R.menu.contextmenu_repeating_transactions, menu); }//from ww w . ja va 2 s . c om }
From source file:com.zzx.photo.ImageFragment.java
private void setAdapter(Cursor imagecursor) { if (imagecursor.getCount() > 0) { ///storage/sdcard0/Toast/download/T1bRVvBCWv1RXrhCrK_l.jpg ///storage/sdcard1/Toast/download/4_1.png mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); int nameColumuIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME); String url = imagecursor.getString(dataColumnIndex).toString(); String name = imagecursor.getString(nameColumuIndex); MediaModel galleryModel = new MediaModel(url, false, name); mGalleryModelList.add(galleryModel); mUrlList.add(url);/*w w w . ja va 2 s . c om*/ } mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false); mImageGridView.setAdapter(mImageAdapter); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mImageGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); String nameString = mUrlList.get(position); Intent intent = new Intent(getActivity(), ViewPagerActivity.class); intent.putExtra("imageurl", mUrlList); intent.putExtra("currentPosition", position); startActivity(intent); // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); // if (mCallback != null) { // mCallback.onImageSelected(mSelectedItems.size()); // Intent intent = new Intent(); // intent.putStringArrayListExtra("list", mSelectedItems); // getActivity().setResult(Activity.RESULT_OK, intent); // } } }); }
From source file:org.mariotaku.twidere.adapter.ParcelableStatusesAdapter.java
@Override public long getStatusTimestamp(int adapterPosition) { int dataPosition = adapterPosition - getStatusStartIndex(); if (dataPosition < 0 || dataPosition >= getRawStatusCount()) return -1; if (mData instanceof ObjectCursor) { final Cursor cursor = ((ObjectCursor) mData).getCursor(); if (!cursor.moveToPosition(dataPosition)) return -1; final ParcelableStatusCursorIndices indices = (ParcelableStatusCursorIndices) ((ObjectCursor) mData) .getIndices();//w ww . ja v a 2 s. c o m return cursor.getLong(indices.timestamp); } return mData.get(dataPosition).timestamp; }