List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:ga.aditya.udacity01sunshine.app.ForecastFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { mForecastAdapter.swapCursor(data);/*from w w w. j a v a 2 s .co m*/ updateEmptyView(); if (data.getCount() == 0) { getActivity().supportStartPostponedEnterTransition(); } else { mRecyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { // Since we know we're going to get items, we keep the listener around until // we see Children. if (mRecyclerView.getChildCount() > 0) { mRecyclerView.getViewTreeObserver().removeOnPreDrawListener(this); int position = mForecastAdapter.getSelectedItemPosition(); if (position == RecyclerView.NO_POSITION && -1 != mInitialSelectedDate) { Cursor data = mForecastAdapter.getmCursor(); int count = data.getCount(); int dateColumn = data.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_DATE); for (int i = 0; i < count; i++) { data.moveToPosition(i); if (data.getLong(dateColumn) == mInitialSelectedDate) { position = i; break; } } } if (position == RecyclerView.NO_POSITION) position = 0; // If we don't need to restart the loader, and there's a desired position to restore // to, do so now. mRecyclerView.smoothScrollToPosition(position); RecyclerView.ViewHolder vh = mRecyclerView.findViewHolderForAdapterPosition(position); if (null != vh && mAutoSelectView) { mForecastAdapter.selectView(vh); } if (mHoldForTransition) { getActivity().supportStartPostponedEnterTransition(); } return true; } return false; } } ); } }
From source file:com.example.contactslist.ui.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(); TextView artistInfoView = (TextView) v.findViewById(R.id.artistInfo); String artistinfo = artistInfoView.getText().toString(); TextView trackInfoView = (TextView) v.findViewById(R.id.trackInfo); String trackinfo = trackInfoView.getText().toString(); StringAppService.get(getActivity()).playBroadcastedSong(getActivity(), artistinfo, trackinfo); // 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 ContactDetailFragment 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); // If two-pane layout sets the selected item to checked so it remains highlighted. In a // single-pane layout a new activity is started so this is not needed. if (mIsTwoPaneLayout) { getListView().setItemChecked(position, true); }/*from w w w . j a v a 2 s .co m*/ }
From source file:com.example.kylelehman.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The SimpleCursorAdapter will take data from the database through the // Loader and use it to populate the ListView it's attached to. mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null, // the column names to use to fill the textviews new String[] { WeatherEntry.COLUMN_DATETEXT, WeatherEntry.COLUMN_SHORT_DESC, WeatherEntry.COLUMN_MAX_TEMP, WeatherEntry.COLUMN_MIN_TEMP }, // the textviews to fill with the data pulled from the columns above new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview, R.id.list_item_high_textview, R.id.list_item_low_textview }, 0);/* w w w . ja va2 s.co m*/ mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { boolean isMetric = Utility.isMetric(getActivity()); switch (columnIndex) { case COL_WEATHER_MAX_TEMP: case COL_WEATHER_MIN_TEMP: { // we have to do some formatting and possibly a conversion ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric)); return true; } case COL_WEATHER_DATE: { String dateString = cursor.getString(columnIndex); TextView dateView = (TextView) view; dateView.setText(Utility.formatDate(dateString)); return true; } } return false; } }); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Cursor cursor = mForecastAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { Intent intent = new Intent(getActivity(), DetailActivity.class) .putExtra(DetailActivity.DATE_KEY, cursor.getString(COL_WEATHER_DATE)); startActivity(intent); } } }); return rootView; }
From source file:com.kmshack.BusanBus.activity.SearchMainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_common); setTitle(""); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setDrawerListener(new DrawerListener() { public void onDrawerOpened(View drawerView) { mDrawerToggle.onDrawerOpened(drawerView); getActionBarHelper().onDrawerOpened(); }/*ww w .jav a 2 s . com*/ public void onDrawerClosed(View drawerView) { mDrawerToggle.onDrawerClosed(drawerView); getActionBarHelper().onDrawerClosed(); } public void onDrawerSlide(View drawerView, float slideOffset) { mDrawerToggle.onDrawerSlide(drawerView, slideOffset); } public void onDrawerStateChanged(int newState) { mDrawerToggle.onDrawerStateChanged(newState); } }); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerToggle = new SherlockActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_dark, R.string.drawer_open, R.string.drawer_close); mDrawerToggle.syncState(); mBusDb = BusDb.getInstance(getApplicationContext()); mUserDb = UserDb.getInstance(getApplicationContext()); mBusanBusPrefrence = BusanBusPrefrence.getInstance(getApplicationContext()); mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case TAB_NOSUN: searchNosun((String) msg.obj); break; case TAB_BUSSTOP: searchBusStop((String) msg.obj); break; } } }; mImageFavorite = (ImageView) findViewById(R.id.main_tap_favorite_image); mImageNosun = (ImageView) findViewById(R.id.main_tap_nosun_image); mImageBusstop = (ImageView) findViewById(R.id.main_tap_busstop_image); mImageLocation = (ImageView) findViewById(R.id.main_tap_setting_image); mFavoriteImageNosun = (TextView) findViewById(R.id.favorite_tab_nosun); mFavoriteImageBusstop = (TextView) findViewById(R.id.favorite_tab_busstop); mTextFavorite = (TextView) findViewById(R.id.main_tap_favorite_text); mTextNosun = (TextView) findViewById(R.id.main_tap_nosun_text); mTextBusstop = (TextView) findViewById(R.id.main_tap_busstop_text); mTextSetting = (TextView) findViewById(R.id.main_tap_setting_text); mNosunListView = (ListView) findViewById(R.id.lv_nosun); mBusStopListView = (ListView) findViewById(R.id.lv_busstop); mFavoriteListView = (DragSortListView) findViewById(R.id.lv_favorite); mNosunListView.setEmptyView((TextView) findViewById(R.id.nosun_empty)); mBusStopListView.setEmptyView((TextView) findViewById(R.id.busstop_empty)); mFavoriteListView.setEmptyView((TextView) findViewById(R.id.favorite_empty)); mFavoriteListView.setDropListener(mOnDrop); mFavoriteListView.setRemoveListener(mOnRemove); mTextSettingNotice = (TextView) findViewById(R.id.setting_notice); mTextSettingUpdate = (TextView) findViewById(R.id.setting_update); mLayoutSettingTextSize = (LinearLayout) findViewById(R.id.setting_textsize_sun); mLayoutSettingArrive = (LinearLayout) findViewById(R.id.setting_arrive_sun); mLayoutSettingFavorite = (LinearLayout) findViewById(R.id.setting_favorite_start); mLayoutSettingFavoriteLocation = (LinearLayout) findViewById(R.id.setting_favorite_location); mTextViewSettingTextSize = (TextView) findViewById(R.id.setting_textsize_value); mCheckSettingArrive = (ImageView) findViewById(R.id.setting_check_arrive_sun); mCheckSettingFavorite = (ImageView) findViewById(R.id.setting_check_favorite_start); mCheckSettingFavoriteLocation = (ImageView) findViewById(R.id.setting_check_favorite_location); mTextSettingNotice.setOnClickListener(mSettingClick); mTextSettingUpdate.setOnClickListener(mSettingClick); mLayoutSettingTextSize.setOnClickListener(mSettingClick); mLayoutSettingArrive.setOnClickListener(mSettingClick); mLayoutSettingFavorite.setOnClickListener(mSettingClick); mLayoutSettingFavoriteLocation.setOnClickListener(mSettingClick); findViewById(R.id.setting_opensource).setOnClickListener(mSettingClick); findViewById(R.id.setting_bin).setOnClickListener(mSettingClick); if (mBusanBusPrefrence.getIsArriveSort()) mCheckSettingArrive.setImageResource(R.drawable.btn_setting_checkbox_check); else mCheckSettingArrive.setImageResource(R.drawable.btn_setting_checkbox_uncheck); if (mBusanBusPrefrence.getIsFavoriteStart()) mCheckSettingFavorite.setImageResource(R.drawable.btn_setting_checkbox_check); else mCheckSettingFavorite.setImageResource(R.drawable.btn_setting_checkbox_uncheck); if (mBusanBusPrefrence.getIsFavoriteLocation()) mCheckSettingFavoriteLocation.setImageResource(R.drawable.btn_setting_checkbox_check); else mCheckSettingFavoriteLocation.setImageResource(R.drawable.btn_setting_checkbox_uncheck); mNosunSearchView = (LinearLayout) LayoutInflater.from(getApplicationContext()) .inflate(R.layout.search_bar_nosun, null); mNosunSearchView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); mNosunEditText = (EditText) mNosunSearchView.findViewById(R.id.et_search_nosun); mNosunEditText.setHint(" "); mNosunEditText.setInputType(InputType.TYPE_CLASS_NUMBER); mNosunEditText.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { mHandler.removeMessages(TAB_NOSUN); Message msg = Message.obtain(mHandler, TAB_NOSUN, s.toString()); mHandler.sendMessageDelayed(msg, 200); } public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } }); ((LinearLayout) findViewById(R.id.search_nosun)).addView(mNosunSearchView); mNosunListView.setOnScrollListener(new OnScrollListener() { public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) { } public void onScrollStateChanged(AbsListView arg0, int arg1) { mInputMethodManager.hideSoftInputFromWindow(mNosunEditText.getWindowToken(), 0); } }); mNosunListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { Cursor cursor = mMainNosunSearchAdapter.getCursor(); cursor.moveToPosition(position); String nosun = cursor.getString(1); String realtime = cursor.getString(cursor.getColumnIndexOrThrow("WEBREALTIME")); String up = cursor.getString(2); String down = cursor.getString(3); Intent intent = new Intent(getApplicationContext(), NosunDetailActivity.class); intent.putExtra("NoSun", nosun); intent.putExtra("RealTimeNoSun", realtime); intent.putExtra("Up", up); intent.putExtra("Down", down); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); mBusstopSearchView = (LinearLayout) LayoutInflater.from(getApplicationContext()) .inflate(R.layout.search_bar_busstop, null); mBusStopEditText = (EditText) mBusstopSearchView.findViewById(R.id.et_search_busstop); mBusStopEditText.setHint("/ "); mBusStopEditText.setInputType(InputType.TYPE_CLASS_TEXT); mBusStopEditText.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { mHandler.removeMessages(TAB_BUSSTOP); Message msg = Message.obtain(mHandler, TAB_BUSSTOP, s.toString()); mHandler.sendMessageDelayed(msg, 200); } public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } }); ((LinearLayout) findViewById(R.id.search_busstop)).addView(mBusstopSearchView); mBusStopListView.setOnScrollListener(new OnScrollListener() { public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) { } public void onScrollStateChanged(AbsListView arg0, int arg1) { mInputMethodManager.hideSoftInputFromWindow(mBusStopEditText.getWindowToken(), 0); } }); mBusStopListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { Cursor cursor = mMainStopSearchAdapter.getCursor(); cursor.moveToPosition(position); String busStop = cursor.getString(2).toString(); Intent intent = new Intent(getApplicationContext(), BusstopDetailActivity.class); intent.putExtra("BusStop", busStop); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); mFavoriteListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { Cursor cursor = null; switch (mFavoriteMode) { case FAVORITE_TAB_NOSUN: cursor = mMainNosunFavoriteAdapter.getCursor(); break; default: cursor = mMainStopFavoriteAdapter.getCursor(); break; } if (cursor.getCount() > 0) { cursor.moveToPosition(position); Intent intent = null; switch (mFavoriteMode) { case FAVORITE_TAB_NOSUN: intent = new Intent(getApplicationContext(), BusArriveActivity.class); intent.putExtra("NOSUN", cursor.getString(1)); intent.putExtra("UNIQUEID", cursor.getString(2)); intent.putExtra("BUSSTOPNAME", cursor.getString(3)); intent.putExtra("UPDOWN", cursor.getString(4)); intent.putExtra("ORD", cursor.getString(6)); break; case FAVORITE_TAB_BUSSTOP: intent = new Intent(getApplicationContext(), BusstopDetailActivity.class); intent.putExtra("BusStop", cursor.getString(2)); break; } if (intent != null) { intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } } } }); mTabFavorite = (LinearLayout) findViewById(R.id.main_tap_favorite); mTabNosun = (LinearLayout) findViewById(R.id.main_tap_nosun); mTabBusstop = (LinearLayout) findViewById(R.id.main_tap_busstop); mTabLocation = (LinearLayout) findViewById(R.id.main_tap_location); mLayoutFavorite = (LinearLayout) findViewById(R.id.layout_main_favorite); mLayoutNosun = (LinearLayout) findViewById(R.id.layout_main_nosun_search); mLayoutBusstop = (LinearLayout) findViewById(R.id.layout_main_busstop_search); mLayoutLocation = (LinearLayout) findViewById(R.id.layout_main_location); mTabFavorite.setOnClickListener(mTabClickListener); mTabNosun.setOnClickListener(mTabClickListener); mTabBusstop.setOnClickListener(mTabClickListener); mTabLocation.setOnClickListener(mTabClickListener); mFavoriteImageNosun.setOnClickListener(mTabClickListener); mFavoriteImageBusstop.setOnClickListener(mTabClickListener); searchNosun(""); searchBusStop(""); if (mBusanBusPrefrence.getIsFavoriteStart()) { setTabChange(TAB_FAVORITE); } else { setTabChange(DEFAULT_TAB); } tracker.trackPageView("/SearchMain"); loadSettingTextSizeSelect(); }
From source file:alberthsu.sunshine.app.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The SimpleCursorAdapter will take data from the database through the // Loader and use it to populate the ListView it's attached to. mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null, // the column names to use to fill the textviews new String[] { WeatherEntry.COLUMN_DATETEXT, WeatherEntry.COLUMN_SHORT_DESC, WeatherEntry.COLUMN_MAX_TEMP, WeatherEntry.COLUMN_MIN_TEMP }, // the textviews to fill with the data pulled from the columns above new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview, R.id.list_item_high_textview, R.id.list_item_low_textview }, 0);// ww w. j ava 2 s . co m mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { boolean isMetric = Utility.isMetric(getActivity()); switch (columnIndex) { case COL_WEATHER_MAX_TEMP: case COL_WEATHER_MIN_TEMP: { // we have to do some formatting and possibly a conversion ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric)); return true; } case COL_WEATHER_DATE: { String dateString = cursor.getString(columnIndex); TextView dateView = (TextView) view; dateView.setText(Utility.formatDate(dateString)); return true; } } return false; } }); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Cursor cursor = mForecastAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { Intent intent = new Intent(getActivity(), detailedActivity.class) .putExtra(detailedActivity.DATE_KEY, cursor.getString(COL_WEATHER_DATE)); startActivity(intent); } } }); return rootView; }
From source file:com.acl.sunshine.app.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The SimpleCursorAdapter will take data from the database through the // Loader and use it to populate the ListView it's attached to. mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null, // the column names to use to fill the textviews new String[] { WeatherEntry.COLUMN_DATETEXT, WeatherEntry.COLUMN_SHORT_DESC, WeatherEntry.COLUMN_MAX_TEMP, WeatherEntry.COLUMN_MIN_TEMP }, // the textviews to fill with the data pulled from the columns above new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview, R.id.list_item_high_textview, R.id.list_item_low_textview }, 0);//from w ww .j a v a2 s . c o m mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { boolean isMetric = Utility.isMetric(getActivity()); switch (columnIndex) { case COL_WEATHER_MAX_TEMP: case COL_WEATHER_MIN_TEMP: { // we have to do some formatting and possibly a conversion ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric)); return true; } case COL_WEATHER_DATE: { String dateString = cursor.getString(columnIndex); TextView dateView = (TextView) view; dateView.setText(Utility.formatDate(dateString)); return true; } } return false; } }); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Cursor cursor = mForecastAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { String dateString = Utility.formatDate(cursor.getString(COL_WEATHER_DATE)); String weatherDescription = cursor.getString(COL_WEATHER_DESC); boolean isMetric = Utility.isMetric(getActivity()); String high = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MAX_TEMP), isMetric); String low = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MIN_TEMP), isMetric); String detailString = String.format("%s - %s - %s/%s", dateString, weatherDescription, high, low); Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, detailString); startActivity(intent); } } }); return rootView; }
From source file:com.example.contactslist.ui.ContactsListFragment.java
public void processCursor(Cursor data) { mAdapter.swapCursor(data);/*from w ww .jav a2 s . co m*/ // If this is a two-pane layout and there is a search query then // there is some additional work to do around default selected // search item. if (mIsTwoPaneLayout && !TextUtils.isEmpty(mSearchTerm) && mSearchQueryChanged) { // Selects the first item in results, unless this fragment has // been restored from a saved state (like orientation change) // in which case it selects the previously selected search item. if (data != null && data.moveToPosition(mPreviouslySelectedSearchItem)) { // Creates the content Uri for the previously selected contact by appending the // contact's ID to the Contacts table content Uri final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(data.getLong(ContactsQuery.ID))); mOnContactSelectedListener.onContactSelected(uri); getListView().setItemChecked(mPreviouslySelectedSearchItem, true); } else { // No results, clear selection. onSelectionCleared(); } // Only restore from saved state one time. Next time fall back // to selecting first item. If the fragment state is saved again // then the currently selected item will once again be saved. mPreviouslySelectedSearchItem = 0; mSearchQueryChanged = false; } // Populate itemsMap and pass to service }
From source file:com.markupartist.sthlmtraveling.RoutesActivity.java
/** * Updates the journey history./*from w w w . j a v a 2 s . co m*/ */ private void updateJourneyHistory() { // TODO: Move to async task. String json; try { json = mJourneyQuery.toJson(false).toString(); } catch (JSONException e) { Log.e(TAG, "Failed to convert journey to a json document."); return; } String[] projection = new String[] { Journeys._ID, // 0 Journeys.JOURNEY_DATA, // 1 Journeys.STARRED, // 2 }; String selection = Journeys.JOURNEY_DATA + " = ?"; Cursor cursor = managedQuery(Journeys.CONTENT_URI, projection, selection, new String[] { json }, null); startManagingCursor(cursor); ContentValues values = new ContentValues(); Uri journeyUri; if (cursor.getCount() > 0) { cursor.moveToFirst(); journeyUri = ContentUris.withAppendedId(Journeys.CONTENT_URI, cursor.getInt(0)); getContentResolver().update(journeyUri, values, null, null); } else { // Not sure if this is the best way to do it, but the lack limit and // offset in on a content provider leaves us to fetch all and iterate. values.put(Journeys.JOURNEY_DATA, json); journeyUri = getContentResolver().insert(Journeys.CONTENT_URI, values); Cursor notStarredCursor = managedQuery(Journeys.CONTENT_URI, projection, Journeys.STARRED + " = ? OR " + Journeys.STARRED + " IS NULL", new String[] { "0" }, Journeys.DEFAULT_SORT_ORDER); startManagingCursor(notStarredCursor); // +1 because the position is zero-based. if (notStarredCursor.moveToPosition(Journeys.DEFAULT_HISTORY_SIZE + 1)) { do { Uri deleteUri = ContentUris.withAppendedId(Journeys.CONTENT_URI, notStarredCursor.getInt(0)); getContentResolver().delete(deleteUri, null, null); } while (notStarredCursor.moveToNext()); } stopManagingCursor(notStarredCursor); } stopManagingCursor(cursor); // TODO: Store created id and work on that while toggling if starred or not. }
From source file:com.google.samples.apps.iosched.ui.SessionDetailActivity.java
private void onSpeakersQueryComplete(Cursor cursor) { mSpeakersCursor = true;// w ww . j a v a 2s.co m final ViewGroup speakersGroup = (ViewGroup) findViewById(R.id.session_speakers_block); // Remove all existing speakers (everything but first child, which is the header) for (int i = speakersGroup.getChildCount() - 1; i >= 1; i--) { speakersGroup.removeViewAt(i); } final LayoutInflater inflater = getLayoutInflater(); boolean hasSpeakers = false; cursor.moveToPosition(-1); // move to just before first record while (cursor.moveToNext()) { final String speakerName = cursor.getString(SpeakersQuery.SPEAKER_NAME); if (TextUtils.isEmpty(speakerName)) { continue; } final String speakerImageUrl = cursor.getString(SpeakersQuery.SPEAKER_IMAGE_URL); final String speakerCompany = cursor.getString(SpeakersQuery.SPEAKER_COMPANY); final String speakerUrl = cursor.getString(SpeakersQuery.SPEAKER_URL); final String speakerAbstract = cursor.getString(SpeakersQuery.SPEAKER_ABSTRACT); String speakerHeader = speakerName; if (!TextUtils.isEmpty(speakerCompany)) { speakerHeader += ", " + speakerCompany; } final View speakerView = inflater.inflate(R.layout.speaker_detail, speakersGroup, false); final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.speaker_header); final ImageView speakerImageView = (ImageView) speakerView.findViewById(R.id.speaker_image); final TextView speakerAbstractView = (TextView) speakerView.findViewById(R.id.speaker_abstract); if (!TextUtils.isEmpty(speakerImageUrl) && mSpeakersImageLoader != null) { mSpeakersImageLoader.loadImage(speakerImageUrl, speakerImageView); } speakerHeaderView.setText(speakerHeader); speakerImageView.setContentDescription(getString(R.string.speaker_googleplus_profile, speakerHeader)); UIUtils.setTextMaybeHtml(speakerAbstractView, speakerAbstract); if (!TextUtils.isEmpty(speakerUrl)) { speakerImageView.setEnabled(true); speakerImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(speakerUrl)); speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); UIUtils.preferPackageForIntent(SessionDetailActivity.this, speakerProfileIntent, UIUtils.GOOGLE_PLUS_PACKAGE_NAME); startActivity(speakerProfileIntent); } }); } else { speakerImageView.setEnabled(false); speakerImageView.setOnClickListener(null); } speakersGroup.addView(speakerView); hasSpeakers = true; mHasSummaryContent = true; } speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE); updateEmptyView(); }
From source file:com.ncode.android.apps.schedo.ui.EventDetailActivity.java
private void onSpeakersQueryComplete(Cursor cursor) { mSpeakersCursor = true;//from w w w.j a va 2 s. c om final ViewGroup speakersGroup = (ViewGroup) findViewById(R.id.session_speakers_block); // Remove all existing speakers (everything but first child, which is the header) for (int i = speakersGroup.getChildCount() - 1; i >= 1; i--) { speakersGroup.removeViewAt(i); } final LayoutInflater inflater = getLayoutInflater(); boolean hasSpeakers = false; cursor.moveToPosition(-1); // move to just before first record while (cursor.moveToNext()) { final String speakerName = cursor.getString(SpeakersQuery.SPEAKER_NAME); if (TextUtils.isEmpty(speakerName)) { continue; } final String speakerImageUrl = cursor.getString(SpeakersQuery.SPEAKER_IMAGE_URL); final String speakerCompany = cursor.getString(SpeakersQuery.SPEAKER_COMPANY); final String speakerUrl = cursor.getString(SpeakersQuery.SPEAKER_URL); final String speakerAbstract = cursor.getString(SpeakersQuery.SPEAKER_ABSTRACT); String speakerHeader = speakerName; if (!TextUtils.isEmpty(speakerCompany)) { speakerHeader += ", " + speakerCompany; } final View speakerView = inflater.inflate(R.layout.speaker_detail, speakersGroup, false); final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.speaker_header); final ImageView speakerImageView = (ImageView) speakerView.findViewById(R.id.speaker_image); final TextView speakerAbstractView = (TextView) speakerView.findViewById(R.id.speaker_abstract); if (!TextUtils.isEmpty(speakerImageUrl) && mSpeakersImageLoader != null) { mSpeakersImageLoader.loadImage(speakerImageUrl, speakerImageView); } speakerHeaderView.setText(speakerHeader); speakerImageView.setContentDescription(getString(R.string.speaker_googleplus_profile, speakerHeader)); UIUtils.setTextMaybeHtml(speakerAbstractView, speakerAbstract); if (!TextUtils.isEmpty(speakerUrl)) { speakerImageView.setEnabled(true); speakerImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(speakerUrl)); speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); UIUtils.preferPackageForIntent(EventDetailActivity.this, speakerProfileIntent, UIUtils.GOOGLE_PLUS_PACKAGE_NAME); startActivity(speakerProfileIntent); } }); } else { speakerImageView.setEnabled(false); speakerImageView.setOnClickListener(null); } speakersGroup.addView(speakerView); hasSpeakers = true; mHasSummaryContent = true; } speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE); updateEmptyView(); }