List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:com.money.manager.ex.common.AllDataListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setEmptyText(getString(R.string.no_data)); setListShown(false);/*from w w w.j av a2 s . co m*/ // Read arguments this.AccountId = getArguments().getInt(ARG_ACCOUNT_ID); // Read header indicator directly from the activity. // todo: make this a parameter or a property. if (getActivity() instanceof SearchActivity) { SearchActivity activity = (SearchActivity) getActivity(); setShownHeader(activity.ShowAccountHeaders); } // create adapter for data. AllDataAdapter adapter = new AllDataAdapter(getActivity(), null, TypeCursor.ALLDATA); adapter.setAccountId(this.AccountId); adapter.setShowAccountName(isShownHeader()); adapter.setShowBalanceAmount(isShownBalance()); // set multi-choice mode in the list view. mMultiChoiceModeListener = new AllDataMultiChoiceModeListener(); mMultiChoiceModeListener.setListener(this); getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(mMultiChoiceModeListener); // e item click getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (getListAdapter() != null && getListAdapter() instanceof AllDataAdapter) { Cursor cursor = ((AllDataAdapter) getListAdapter()).getCursor(); if (cursor.moveToPosition(position - (mListHeader != null ? 1 : 0))) { startEditAccountTransactionActivity(cursor.getInt(cursor.getColumnIndex(QueryAllData.ID))); } } } }); // Header and footer must be added before setAdapter(). // Add a header to the list view if one exists. if (getListAdapter() == null) { if (mListHeader != null) getListView().addHeaderView(mListHeader); } if (this.mShowFooter) { renderFooter(); } // set adapter setListAdapter(adapter); // register context menu registerForContextMenu(getListView()); // set animation progress setListShown(false); boolean showAddButton = getArguments().getBoolean(ARG_SHOW_FLOATING_BUTTON); if (showAddButton) { // Show floating action button. setFloatingActionButtonVisible(true); attachFloatingActionButtonToListView(); } // start loader if asked to do so by the caller. if (isAutoStarLoader()) { loadData(); } }
From source file:com.mpower.daktar.android.tasks.InstanceUploaderTask.java
@Override protected HashMap<String, String> doInBackground(final Long... values) { mResults = new HashMap<String, String>(); String postResponse;//from www . j a v a2 s .c o m String selection = BaseColumns._ID + "=?"; final String[] selectionArgs = new String[values.length]; for (int i = 0; i < values.length; i++) { if (i != values.length - 1) { selection += " or " + BaseColumns._ID + "=?"; } selectionArgs[i] = values[i].toString(); } // get shared HttpContext so that authentication and cookies are // retained. final HttpContext localContext = MIntel.getInstance().getHttpContext(); final HttpClient httpclient = WebUtils.createHttpClient(CONNECTION_TIMEOUT); final Map<URI, URI> uriRemap = new HashMap<URI, URI>(); final Cursor c = MIntel.getInstance().getContentResolver().query(InstanceColumns.CONTENT_URI, null, selection, selectionArgs, null); if (c.getCount() > 0) { c.moveToPosition(-1); next_submission: while (c.moveToNext()) { if (isCancelled()) return mResults; publishProgress(c.getPosition() + 1, c.getCount()); final String instance = c.getString(c.getColumnIndex(InstanceColumns.INSTANCE_FILE_PATH)); final String id = c.getString(c.getColumnIndex(BaseColumns._ID)); final Uri toUpdate = Uri.withAppendedPath(InstanceColumns.CONTENT_URI, id); String urlString = c.getString(c.getColumnIndex(InstanceColumns.SUBMISSION_URI)); if (urlString == null) { final SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(MIntel.getInstance()); urlString = settings.getString(PreferencesActivity.KEY_SERVER_URL, null); urlString = urlString + WebUtils.URL_PART_SUBMISSION; } final ContentValues cv = new ContentValues(); URI u = null; try { final URL url = new URL(URLDecoder.decode(urlString, "utf-8")); u = url.toURI(); } catch (final MalformedURLException e) { e.printStackTrace(); mResults.put(id, fail + "invalid url: " + urlString + " :: details: " + e.getMessage()); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } catch (final URISyntaxException e) { e.printStackTrace(); mResults.put(id, fail + "invalid uri: " + urlString + " :: details: " + e.getMessage()); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } catch (final UnsupportedEncodingException e) { e.printStackTrace(); mResults.put(id, fail + "invalid url: " + urlString + " :: details: " + e.getMessage()); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } boolean openRosaServer = false; if (uriRemap.containsKey(u)) { // we already issued a head request and got a response, // so we know the proper URL to send the submission to // and the proper scheme. We also know that it was an // OpenRosa compliant server. openRosaServer = true; u = uriRemap.get(u); } else { // we need to issue a head request final HttpHead httpHead = WebUtils.createOpenRosaHttpHead(u); // prepare response HttpResponse response = null; try { response = httpclient.execute(httpHead, localContext); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 401) { // we need authentication, so stop and return what // we've // done so far. mAuthRequestingServer = u; return null; } else if (statusCode == 204) { final Header[] locations = response.getHeaders("Location"); if (locations != null && locations.length == 1) { try { final URL url = new URL(URLDecoder.decode(locations[0].getValue(), "utf-8")); final URI uNew = url.toURI(); if (u.getHost().equalsIgnoreCase(uNew.getHost())) { openRosaServer = true; // trust the server to tell us a new // location // ... and possibly to use https // instead. uriRemap.put(u, uNew); u = uNew; } else { // Don't follow a redirection attempt to // a different host. // We can't tell if this is a spoof or // not. mResults.put(id, fail + "Unexpected redirection attempt to a different host: " + uNew.toString()); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } } catch (final Exception e) { e.printStackTrace(); mResults.put(id, fail + urlString + " " + e.getMessage()); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } } } else { // may be a server that does not handle try { // have to read the stream in order to reuse the // connection final InputStream is = response.getEntity().getContent(); // read to end of stream... final long count = 1024L; while (is.skip(count) == count) { ; } is.close(); } catch (final IOException e) { e.printStackTrace(); } catch (final Exception e) { e.printStackTrace(); } Log.w(t, "Status code on Head request: " + statusCode); if (statusCode >= 200 && statusCode <= 299) { mResults.put(id, fail + "Invalid status code on Head request. If you have a web proxy, you may need to login to your network. "); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } } } catch (final ClientProtocolException e) { e.printStackTrace(); Log.e(t, e.getMessage()); mResults.put(id, fail + "Client Protocol Exception"); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } catch (final ConnectTimeoutException e) { e.printStackTrace(); Log.e(t, e.getMessage()); mResults.put(id, fail + "Connection Timeout"); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } catch (final UnknownHostException e) { e.printStackTrace(); mResults.put(id, fail + e.getMessage() + " :: Network Connection Failed"); Log.e(t, e.getMessage()); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } catch (final Exception e) { e.printStackTrace(); mResults.put(id, fail + "Generic Exception"); Log.e(t, e.getMessage()); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } } // At this point, we may have updated the uri to use https. // This occurs only if the Location header keeps the host name // the same. If it specifies a different host name, we error // out. // // And we may have set authentication cookies in our // cookiestore (referenced by localContext) that will enable // authenticated publication to the server. // // get instance file final File instanceFile = new File(instance); if (!instanceFile.exists()) { mResults.put(id, fail + "instance XML file does not exist!"); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue; } // find all files in parent directory final File[] allFiles = instanceFile.getParentFile().listFiles(); // add media files final List<File> files = new ArrayList<File>(); for (final File f : allFiles) { final String fileName = f.getName(); final int dotIndex = fileName.lastIndexOf("."); String extension = ""; if (dotIndex != -1) { extension = fileName.substring(dotIndex + 1); } if (fileName.startsWith(".")) { // ignore invisible files continue; } if (fileName.equals(instanceFile.getName())) { continue; // the xml file has already been added } else if (openRosaServer) { files.add(f); } else if (extension.equals("jpg")) { // legacy 0.9x files.add(f); } else if (extension.equals("3gpp")) { // legacy 0.9x files.add(f); } else if (extension.equals("3gp")) { // legacy 0.9x files.add(f); } else if (extension.equals("mp4")) { // legacy 0.9x files.add(f); } else if (extension.equals("amr")) { // legacy 0.9x files.add(f); } else { Log.w(t, "unrecognized file type " + f.getName()); } } postResponse = ""; boolean first = true; int j = 0; while (j < files.size() || first) { first = false; final HttpPost httppost = WebUtils.createOpenRosaHttpPost(u, mAuth); final MimeTypeMap m = MimeTypeMap.getSingleton(); long byteCount = 0L; // mime post final MultipartEntity entity = new MultipartEntity(); // add the submission file first... FileBody fb = new FileBody(instanceFile, "text/xml"); entity.addPart("xml_submission_file", fb); Log.i(t, "added xml_submission_file: " + instanceFile.getName()); byteCount += instanceFile.length(); for (; j < files.size(); j++) { final File f = files.get(j); final String fileName = f.getName(); final int idx = fileName.lastIndexOf("."); String extension = ""; if (idx != -1) { extension = fileName.substring(idx + 1); } String contentType = m.getMimeTypeFromExtension(extension); // we will be processing every one of these, so // we only need to deal with the content type // determination... if (extension.equals("xml")) { fb = new FileBody(f, "text/xml"); entity.addPart(f.getName(), fb); byteCount += f.length(); Log.i(t, "added xml file " + f.getName()); } else if (extension.equals("jpg")) { fb = new FileBody(f, "image/jpeg"); entity.addPart(f.getName(), fb); byteCount += f.length(); Log.i(t, "added image file " + f.getName()); } else if (extension.equals("3gpp")) { fb = new FileBody(f, "audio/3gpp"); entity.addPart(f.getName(), fb); byteCount += f.length(); Log.i(t, "added audio file " + f.getName()); } else if (extension.equals("3gp")) { fb = new FileBody(f, "video/3gpp"); entity.addPart(f.getName(), fb); byteCount += f.length(); Log.i(t, "added video file " + f.getName()); } else if (extension.equals("mp4")) { fb = new FileBody(f, "video/mp4"); entity.addPart(f.getName(), fb); byteCount += f.length(); Log.i(t, "added video file " + f.getName()); } else if (extension.equals("csv")) { fb = new FileBody(f, "text/csv"); entity.addPart(f.getName(), fb); byteCount += f.length(); Log.i(t, "added csv file " + f.getName()); } else if (f.getName().endsWith(".amr")) { fb = new FileBody(f, "audio/amr"); entity.addPart(f.getName(), fb); Log.i(t, "added audio file " + f.getName()); } else if (extension.equals("xls")) { fb = new FileBody(f, "application/vnd.ms-excel"); entity.addPart(f.getName(), fb); byteCount += f.length(); Log.i(t, "added xls file " + f.getName()); } else if (contentType != null) { fb = new FileBody(f, contentType); entity.addPart(f.getName(), fb); byteCount += f.length(); Log.i(t, "added recognized filetype (" + contentType + ") " + f.getName()); } else { contentType = "application/octet-stream"; fb = new FileBody(f, contentType); entity.addPart(f.getName(), fb); byteCount += f.length(); Log.w(t, "added unrecognized file (" + contentType + ") " + f.getName()); } // we've added at least one attachment to the request... if (j + 1 < files.size()) { if (byteCount + files.get(j + 1).length() > 10000000L) { // the next file would exceed the 10MB // threshold... Log.i(t, "Extremely long post is being split into multiple posts"); try { final StringBody sb = new StringBody("yes", Charset.forName("UTF-8")); entity.addPart("*isIncomplete*", sb); } catch (final Exception e) { e.printStackTrace(); // never happens... } ++j; // advance over the last attachment // added... break; } } } httppost.setEntity(entity); // prepare response and return uploaded HttpResponse response = null; try { response = httpclient.execute(httppost, localContext); final int responseCode = response.getStatusLine().getStatusCode(); // try { // // have to read the stream in order to reuse the // connection // InputStream is = response.getEntity().getContent(); // // read to end of stream... // final long count = 1024L; // while (is.skip(count) == count) // ; // is.close(); // } catch (IOException e) { // e.printStackTrace(); // } catch (Exception e) { // e.printStackTrace(); // } final HttpEntity httpEntity = response.getEntity(); try { postResponse = EntityUtils.toString(httpEntity, HTTP.UTF_8).trim(); } catch (final IOException e) { e.printStackTrace(); } Log.i(t, "Response code:" + responseCode); // verify that the response was a 201 or 202. // If it wasn't, the submission has failed. if (responseCode != 201 && responseCode != 202) { if (responseCode == 200) { mResults.put(id, fail + "Network login failure? Again?"); } else { if (postResponse.length() > 0) { mResults.put(id, postResponse); } else { mResults.put(id, fail + response.getStatusLine().getReasonPhrase() + " (" + responseCode + ") at " + urlString); } } cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue next_submission; } } catch (final Exception e) { e.printStackTrace(); mResults.put(id, fail + " " + e.getMessage()); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMISSION_FAILED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); continue next_submission; } } // if it got here, it must have worked if (postResponse.length() > 0) { // Custom msg from server mResults.put(id, postResponse); } else { // There is no response from server, use default string mResults.put(id, MIntel.getInstance().getString(R.string.success)); } // mResults.put(id, // MIntel.getInstance().getString(R.string.success)); cv.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_SUBMITTED); MIntel.getInstance().getContentResolver().update(toUpdate, cv, null, null); } if (c != null) { c.close(); } } // end while return mResults; }
From source file:br.com.mybaby.contatos.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(); posicaoAnterior = position;/* w w w .java2 s. c o m*/ // 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 source file:io.nuclei.cyto.share.CytoFileProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor source = super.query(uri, projection, selection, selectionArgs, sortOrder); if (source == null) return null; try {/*from w w w .j a v a2s .co m*/ final String[] columnNames = source.getColumnNames(); String[] names = columnNames; List<String> missingNames = getMissingColumns(columnNames); int mimeTypeIndex = -1; if (missingNames.size() > 0) { String[] newColumnNames = Arrays.copyOf(columnNames, columnNames.length + missingNames.size()); int ix = columnNames.length; for (String missingName : missingNames) { newColumnNames[ix] = missingName; if (MediaStore.MediaColumns.MIME_TYPE.equals(missingName)) mimeTypeIndex = ix; ix++; } names = newColumnNames; } MatrixCursor cursor = new MatrixCursor(names, source.getCount()); source.moveToPosition(-1); int columnLength = columnNames.length; while (source.moveToNext()) { MatrixCursor.RowBuilder row = cursor.newRow(); for (int i = 0; i < names.length; i++) { if (i < columnLength) row.add(source.getString(i)); else if (i == mimeTypeIndex) { // populate the MIME_TYPE column with a guess as to the mime type of the file final int lastDot = uri.getPath().lastIndexOf('.'); if (lastDot >= 0) { String extension = uri.getPath().substring(lastDot + 1); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (mimeType != null) row.add(mimeType); else row.add("application/octet"); } else row.add("application/octet"); } else row.add(null); } } return cursor; } finally { source.close(); } }
From source file:com.silentcircle.contacts.list.ScContactEntryListAdapter.java
/** * Checks whether the contact entry at the given position represents the user's profile. *///from w w w . j a va 2s.c om protected boolean isUserProfile(int position) { // The profile only ever appears in the first position if it is present. So if the position // is anything beyond 0, it can't be the profile. boolean isUserProfile = false; if (position == 0) { int partition = getPartitionForPosition(position); if (partition >= 0) { // Save the old cursor position - the call to getItem() may modify the cursor // position. int offset = getCursor(partition).getPosition(); Cursor cursor = (Cursor) getItem(position); if (cursor != null) { int profileColumnIndex = cursor.getColumnIndex(RawContacts.CONTACT_TYPE); if (profileColumnIndex != -1) { isUserProfile = cursor.getInt(profileColumnIndex) == RawContacts.CONTACT_TYPE_OWN; } // Restore the old cursor position. cursor.moveToPosition(offset); } } } return isUserProfile; }
From source file:monakhv.android.samlib.AuthorListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int sel = item.getItemId(); if (sel == android.R.id.home) { //mCallbacks.onOpenPanel(); if (getSelection() != null) { refresh(null, null);//from ww w . j a v a 2s . c o m mCallbacks.onTitleChange(getString(R.string.app_name)); } } if (sel == R.id.menu_refresh) { startRefresh(); } if (sel == R.id.sort_option_item_books) { mCallbacks.selectBookSortOrder(); } if (sel == R.id.sort_option_item) { AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SortOrder so = SortOrder.values()[position]; mCallbacks.onAuthorSelected(0); setSortOrder(so); sortDialog.dismiss(); } }; sortDialog = SingleChoiceSelectDialog.getInstance(SortOrder.getTitles(getActivity()), listener, this.getString(R.string.dialog_title_sort_author), getSortOrder().ordinal()); sortDialog.show(getActivity().getSupportFragmentManager(), "DoSortDialog"); } if (sel == R.id.add_option_item) { View v = getActivity().findViewById(R.id.add_author_panel); v.setVisibility(View.VISIBLE); String txt = null; try { txt = getClipboardText(getActivity()); } catch (Exception ex) { Log.e(DEBUG_TAG, "Clipboard Error!", ex); } if (txt != null) { if (SamLibConfig.getParsedUrl(txt) != null) { EditText editText = (EditText) getActivity().findViewById(R.id.addUrlText); editText.setText(txt); } } } if (sel == R.id.settings_option_item) { Log.d(DEBUG_TAG, "go to Settings"); Intent prefsIntent = new Intent(getActivity().getApplicationContext(), SamlibPreferencesActivity.class); //prefsIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); getActivity().startActivityForResult(prefsIntent, MainActivity.PREFS_ACTIVITY); } if (sel == R.id.archive_option_item) { Log.d(DEBUG_TAG, "go to Archive"); Intent prefsIntent = new Intent(getActivity().getApplicationContext(), ArchiveActivity.class); //prefsIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); //startActivityForResult must be called via getActivity direct call produce wrong requestCode getActivity().startActivityForResult(prefsIntent, MainActivity.ARCHIVE_ACTIVITY); } if (sel == R.id.selected_option_item) { Log.d(DEBUG_TAG, "go to Selected"); cleanSelection(); mCallbacks.onAuthorSelected(SamLibConfig.SELECTED_BOOK_ID); } if (sel == R.id.menu_filter) { Log.d(DEBUG_TAG, "go to Filter"); Cursor tags = getActivity().getContentResolver().query(AuthorProvider.TAG_URI, null, null, null, SQLController.COL_TAG_NAME); MatrixCursor extras = new MatrixCursor( new String[] { SQLController.COL_ID, SQLController.COL_TAG_NAME }); extras.addRow(new String[] { Integer.toString(SamLibConfig.TAG_AUTHOR_ALL), getText(R.string.filter_all).toString() }); extras.addRow(new String[] { Integer.toString(SamLibConfig.TAG_AUTHOR_NEW), getText(R.string.filter_new).toString() }); Cursor[] cursors = { extras, tags }; final Cursor extendedCursor = new MergeCursor(cursors); AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { extendedCursor.moveToPosition(position); int tag_id = extendedCursor.getInt(extendedCursor.getColumnIndex(SQLController.COL_ID)); String tg_name = extendedCursor .getString(extendedCursor.getColumnIndex(SQLController.COL_TAG_NAME)); filterDialog.dismiss(); selection = SQLController.TABLE_TAGS + "." + SQLController.COL_ID + "=" + tag_id; if (tag_id == SamLibConfig.TAG_AUTHOR_ALL) { selection = null; mCallbacks.onTitleChange(getActivity().getText(R.string.app_name).toString()); } else { mCallbacks.onTitleChange(tg_name); } if (tag_id == SamLibConfig.TAG_AUTHOR_NEW) { selection = SQLController.TABLE_AUTHOR + "." + SQLController.COL_isnew + "=1"; } Log.i(DEBUG_TAG, "WHERE " + selection); refresh(selection, null); mCallbacks.onAuthorSelected(0); } }; filterDialog = FilterSelectDialog.getInstance(extendedCursor, listener, getText(R.string.dialog_title_filtr).toString()); filterDialog.show(getActivity().getSupportFragmentManager(), "FilterDialogShow"); } return super.onOptionsItemSelected(item); }
From source file:org.mozilla.gecko.home.TopSitesPanel.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { mEditPinnedSiteListener = new EditPinnedSiteListener(); mList.setTag(HomePager.LIST_TAG_TOP_SITES); mList.setHeaderDividersEnabled(false); mList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override// ww w . ja va2s . co m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final ListView list = (ListView) parent; final int headerCount = list.getHeaderViewsCount(); if (position < headerCount) { // The click is on a header, don't do anything. return; } // Absolute position for the adapter. position += (mGridAdapter.getCount() - headerCount); final Cursor c = mListAdapter.getCursor(); if (c == null || !c.moveToPosition(position)) { return; } final String url = c.getString(c.getColumnIndexOrThrow(TopSites.URL)); Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM); // This item is a TwoLinePageRow, so we allow switch-to-tab. mUrlOpenListener.onUrlOpen(url, EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB)); } }); mList.setContextMenuInfoFactory(new HomeContextMenuInfo.Factory() { @Override public HomeContextMenuInfo makeInfoForCursor(View view, int position, long id, Cursor cursor) { final HomeContextMenuInfo info = new HomeContextMenuInfo(view, position, id); info.url = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.URL)); info.title = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.TITLE)); info.historyId = cursor.getInt(cursor.getColumnIndexOrThrow(TopSites.HISTORY_ID)); info.itemType = RemoveItemType.HISTORY; final int bookmarkIdCol = cursor.getColumnIndexOrThrow(TopSites.BOOKMARK_ID); if (cursor.isNull(bookmarkIdCol)) { // If this is a combined cursor, we may get a history item without a // bookmark, in which case the bookmarks ID column value will be null. info.bookmarkId = -1; } else { info.bookmarkId = cursor.getInt(bookmarkIdCol); } return info; } }); mGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TopSitesGridItemView item = (TopSitesGridItemView) view; // Decode "user-entered" URLs before loading them. String url = StringUtils.decodeUserEnteredUrl(item.getUrl()); int type = item.getType(); // If the url is empty, the user can pin a site. // If not, navigate to the page given by the url. if (type != TopSites.TYPE_BLANK) { if (mUrlOpenListener != null) { final TelemetryContract.Method method; if (type == TopSites.TYPE_SUGGESTED) { method = TelemetryContract.Method.SUGGESTION; } else { method = TelemetryContract.Method.GRID_ITEM; } Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, method, Integer.toString(position)); // Record tile click events on non-private tabs. final Tab tab = Tabs.getInstance().getSelectedTab(); if (!tab.isPrivate()) { final Locale locale = Locale.getDefault(); final String localeTag = Locales.getLanguageTag(locale); TilesRecorder.recordAction(tab, TilesRecorder.ACTION_CLICK, position, getTilesSnapshot(), localeTag); } mUrlOpenListener.onUrlOpen(url, EnumSet.noneOf(OnUrlOpenListener.Flags.class)); } } else { if (mEditPinnedSiteListener != null) { mEditPinnedSiteListener.onEditPinnedSite(position, ""); } } } }); mGrid.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor cursor = (Cursor) parent.getItemAtPosition(position); TopSitesGridItemView item = (TopSitesGridItemView) view; if (cursor == null || item.getType() == TopSites.TYPE_BLANK) { mGrid.setContextMenuInfo(null); return false; } TopSitesGridContextMenuInfo contextMenuInfo = new TopSitesGridContextMenuInfo(view, position, id); updateContextMenuFromCursor(contextMenuInfo, cursor); mGrid.setContextMenuInfo(contextMenuInfo); return mGrid.showContextMenuForChild(mGrid); } /* * Update the fields of a TopSitesGridContextMenuInfo object * from a cursor. * * @param info context menu info object to be updated * @param cursor used to update the context menu info object */ private void updateContextMenuFromCursor(TopSitesGridContextMenuInfo info, Cursor cursor) { info.url = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.URL)); info.title = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.TITLE)); info.type = cursor.getInt(cursor.getColumnIndexOrThrow(TopSites.TYPE)); info.historyId = cursor.getInt(cursor.getColumnIndexOrThrow(TopSites.HISTORY_ID)); } }); registerForContextMenu(mList); registerForContextMenu(mGrid); }
From source file:net.simonvt.cathode.ui.fragment.ShowFragment.java
private void updateActorViews(Cursor c) { actors.removeAllViews();/*from w w w .j a v a 2s .c om*/ final int count = c.getCount(); Timber.d("Actor count: %d", count); final int visibility = count > 0 ? View.VISIBLE : View.GONE; actorsTitle.setVisibility(visibility); actorsParent.setVisibility(visibility); c.moveToPosition(-1); while (c.moveToNext()) { View v = LayoutInflater.from(getActivity()).inflate(R.layout.person, actors, false); RemoteImageView headshot = (RemoteImageView) v.findViewById(R.id.headshot); headshot.setImage(c.getString(c.getColumnIndex(PersonColumns.HEADSHOT))); TextView name = (TextView) v.findViewById(R.id.name); name.setText(c.getString(c.getColumnIndex(PersonColumns.NAME))); TextView character = (TextView) v.findViewById(R.id.job); character.setText(c.getString(c.getColumnIndex(ShowCharacterColumns.CHARACTER))); actors.addView(v); } }
From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java
private void displayRandomSounds(ViewGroup layout, Cursor cursor) { if (layout != null) { layout.removeAllViews();/*from ww w . j a va 2 s .c om*/ } if (cursor.getCount() <= 0 || layout == null) { return; } Random rdm = new Random(); for (int i = 0; i < getColumnNumber(); i++) { int pos; if (cursor.getCount() > getColumnNumber()) { pos = rdm.nextInt(cursor.getCount()); } else { pos = i; } View view = LayoutInflater.from(mContext).inflate(R.layout.grid_single, layout, false); cursor.moveToPosition(pos); if (i >= cursor.getCount()) { view.setVisibility(View.INVISIBLE); } else { bindSound(view, cursor); } layout.addView(view); } }
From source file:com.example.android.contactslist.ui.groupsEditor.GroupsEditorFragment.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); /*//from w w w .j a va 2 s .c o m // get the id of the group to pass on to the contact list final int group_id = cursor.getInt(GroupsListStatsQuery.GROUP_ID); final String group_name = cursor.getString(GroupsListStatsQuery.NAME); // This is making some methods not work right. // 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. mOnGroupSelectedListener.onGroupSelected(group_id, group_name); // 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); } */ }