List of usage examples for android.net Uri buildUpon
public abstract Builder buildUpon();
From source file:org.onebusaway.android.ui.ArrivalsListHeader.java
void initView(View view) { // Clear any existing arrival info mArrivalInfo = null;// ww w. j a v a2 s.c o m mHeaderArrivalInfo.clear(); mNumHeaderArrivals = -1; // Cache the ArrivalsListHeader height values HEADER_HEIGHT_ONE_ARRIVAL_DP = view.getResources().getDimension(R.dimen.arrival_header_height_one_arrival) / view.getResources().getDisplayMetrics().density; HEADER_HEIGHT_TWO_ARRIVALS_DP = view.getResources().getDimension(R.dimen.arrival_header_height_two_arrivals) / view.getResources().getDisplayMetrics().density; HEADER_OFFSET_FILTER_ROUTES_DP = view.getResources() .getDimension(R.dimen.arrival_header_height_offset_filter_routes) / view.getResources().getDisplayMetrics().density; HEADER_HEIGHT_EDIT_NAME_DP = view.getResources().getDimension(R.dimen.arrival_header_height_edit_name) / view.getResources().getDisplayMetrics().density; // Init views mView = view; mMainContainerView = mView.findViewById(R.id.main_header_content); mNameContainerView = mView.findViewById(R.id.stop_name_and_info_container); mEditNameContainerView = mView.findViewById(R.id.edit_name_container); mNameView = (TextView) mView.findViewById(R.id.stop_name); mEditNameView = (EditText) mView.findViewById(R.id.edit_name); mStopFavorite = (ImageButton) mView.findViewById(R.id.stop_favorite); mStopFavorite.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mFilterGroup = mView.findViewById(R.id.filter_group); mShowAllView = (TextView) mView.findViewById(R.id.show_all); // Remove any previous clickable spans - we're recycling views between fragments for efficiency UIUtils.removeAllClickableSpans(mShowAllView); mShowAllClick = new ClickableSpan() { public void onClick(View v) { mController.setRoutesFilter(new ArrayList<String>()); } }; UIUtils.setClickableSpan(mShowAllView, mShowAllClick); mNoArrivals = (TextView) mView.findViewById(R.id.no_arrivals); // First ETA row mEtaContainer1 = mView.findViewById(R.id.eta_container1); mEtaRouteFavorite1 = (ImageButton) mEtaContainer1.findViewById(R.id.eta_route_favorite); mEtaRouteFavorite1.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaReminder1 = (ImageButton) mEtaContainer1.findViewById(R.id.reminder); mEtaReminder1.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaRouteName1 = (TextView) mEtaContainer1.findViewById(R.id.eta_route_name); mEtaRouteDirection1 = (TextView) mEtaContainer1.findViewById(R.id.eta_route_direction); mEtaAndMin1 = (RelativeLayout) mEtaContainer1.findViewById(R.id.eta_and_min); mEtaArrivalInfo1 = (TextView) mEtaContainer1.findViewById(R.id.eta); mEtaMin1 = (TextView) mEtaContainer1.findViewById(R.id.eta_min); mEtaRealtime1 = (ViewGroup) mEtaContainer1.findViewById(R.id.eta_realtime_indicator); mEtaMoreVert1 = (ImageButton) mEtaContainer1.findViewById(R.id.eta_more_vert); mEtaMoreVert1.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaSeparator = mView.findViewById(R.id.eta_separator); // Second ETA row mEtaContainer2 = mView.findViewById(R.id.eta_container2); mEtaRouteFavorite2 = (ImageButton) mEtaContainer2.findViewById(R.id.eta_route_favorite); mEtaRouteFavorite2.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaReminder2 = (ImageButton) mEtaContainer2.findViewById(R.id.reminder); mEtaReminder2.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mEtaRouteName2 = (TextView) mEtaContainer2.findViewById(R.id.eta_route_name); mEtaAndMin2 = (RelativeLayout) mEtaContainer2.findViewById(R.id.eta_and_min); mEtaRouteDirection2 = (TextView) mEtaContainer2.findViewById(R.id.eta_route_direction); mEtaArrivalInfo2 = (TextView) mEtaContainer2.findViewById(R.id.eta); mEtaMin2 = (TextView) mEtaContainer2.findViewById(R.id.eta_min); mEtaRealtime2 = (ViewGroup) mEtaContainer2.findViewById(R.id.eta_realtime_indicator); mEtaMoreVert2 = (ImageButton) mEtaContainer2.findViewById(R.id.eta_more_vert); mEtaMoreVert2.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mProgressBar = (ProgressBar) mView.findViewById(R.id.header_loading_spinner); mStopInfo = (ImageButton) mView.findViewById(R.id.stop_info_button); mExpandCollapse = (ImageView) mView.findViewById(R.id.expand_collapse); mAlertView = (ImageView) mView.findViewById(R.id.alert); mAlertView.setColorFilter(mView.getResources().getColor(R.color.header_text_color)); mAlertView.setVisibility(View.GONE); resetExpandCollapseAnimation(); // Initialize right margin view visibilities UIUtils.showViewWithAnimation(mProgressBar, mShortAnimationDuration); UIUtils.hideViewWithAnimation(mEtaContainer1, mShortAnimationDuration); UIUtils.hideViewWithAnimation(mEtaSeparator, mShortAnimationDuration); UIUtils.hideViewWithAnimation(mEtaContainer2, mShortAnimationDuration); // Initialize stop info view final ObaRegion obaRegion = Application.get().getCurrentRegion(); if (obaRegion == null || TextUtils.isEmpty(obaRegion.getStopInfoUrl())) { // This region doesn't support StopInfo - hide the info icon mStopInfo.setVisibility(View.GONE); } else { mStopInfo.setVisibility(View.VISIBLE); mStopInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Assemble StopInfo URL for the current stop Uri stopInfoUri = Uri.parse(obaRegion.getStopInfoUrl()); Uri.Builder stopInfoBuilder = stopInfoUri.buildUpon(); stopInfoBuilder.appendPath(mContext.getString(R.string.stop_info_url_path)); stopInfoBuilder.appendPath(mController.getStopId()); Log.d(TAG, "StopInfoUrl - " + stopInfoBuilder.build()); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(stopInfoBuilder.build()); mContext.startActivity(i); //Analytics if (obaRegion != null && obaRegion.getName() != null) ObaAnalytics.reportEventWithCategory(ObaAnalytics.ObaEventCategory.UI_ACTION.toString(), mContext.getString(R.string.analytics_action_button_press), mContext.getString(R.string.analytics_label_button_press_stopinfo) + obaRegion.getName()); } }); } mStopFavorite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mController.setFavoriteStop(!mController.isFavoriteStop()); refreshStopFavorite(); } }); mNameView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { beginNameEdit(null); } }); // Implement the "Save" and "Clear" buttons View save = mView.findViewById(R.id.edit_name_save); save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mController.setUserStopName(mEditNameView.getText().toString()); endNameEdit(); } }); mEditNameView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { mController.setUserStopName(mEditNameView.getText().toString()); endNameEdit(); return true; } return false; } }); // "Cancel" View cancel = mView.findViewById(R.id.edit_name_cancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { endNameEdit(); } }); View clear = mView.findViewById(R.id.edit_name_revert); clear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mController.setUserStopName(null); endNameEdit(); } }); }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public android.support.v4.content.CursorLoader createSupportLoader(Uri uri, String[] projection, String sortOrder, boolean enableNotifications) { uri = uri.buildUpon() .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(enableNotifications)) .build();/*from w w w . ja v a 2 s . c o m*/ return new android.support.v4.content.CursorLoader(Mechanoid.getApplicationContext(), uri, projection, toString(), getArgsArray(), sortOrder); }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public int count(Uri uri) { ContentResolver resolver = Mechanoid.getContentResolver(); Cursor c = null;/*from www.j a v a2s . c o m*/ uri = uri.buildUpon().appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, "false").build(); try { c = resolver.query(uri, new String[] { "count(*)" }, toString(), getArgsArray(), null); int count = 0; if (c.moveToFirst()) { count = c.getInt(0); } return count; } finally { Closeables.closeSilently(c); } }
From source file:com.robotoworks.mechanoid.db.SQuery.java
@TargetApi(11) public android.content.CursorLoader createLoader(Uri uri, String[] projection, boolean enableNotifications) { if (Build.VERSION.SDK_INT < 11) { return null; }//from w w w . ja v a2 s .c om uri = uri.buildUpon() .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(enableNotifications)) .build(); return new android.content.CursorLoader(Mechanoid.getApplicationContext(), uri, projection, toString(), getArgsArray(), null); }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public Cursor select(Uri uri, String[] projection, String sortOrder, boolean enableNotifications) { ContentResolver resolver = Mechanoid.getContentResolver(); uri = uri.buildUpon() .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(enableNotifications)) .build();/* w w w. j a va2 s . c o m*/ return resolver.query(uri, projection, toString(), getArgsArray(), sortOrder); }
From source file:jp.mixi.android.sdk.MixiContainerImpl.java
@Override public void showDialog(final Context context, String action, Map<String, String> parameters, final CallbackListener listener, final boolean isCancelable) { Uri uri = Uri.parse(Constants.GRAPH_BASE_URL); android.net.Uri.Builder builder = uri.buildUpon(); builder.appendEncodedPath("dialog" + action); for (Entry<String, String> param : parameters.entrySet()) { builder.appendQueryParameter(param.getKey(), param.getValue()); }// w w w . j av a 2 s. c om final String url = builder.build().toString(); AsyncTask<String, Void, Void> tasc = new AsyncTask<String, Void, Void>() { private Exception e; @Override protected Void doInBackground(String... params) { try { refreshToken(); } catch (RemoteException e) { this.e = e; } catch (ApiException e) { this.e = e; } return null; } @Override protected void onPostExecute(Void res) { if (e == null) { HashMap<String, String> map = new HashMap<String, String>(); map.put("oauth_token", getAccessToken()); new MixiDialog(context, url, map, listener, isCancelable).show(); } else { Log.v(TAG, "refresh token error"); listener.onFatal(new ErrorInfo(e)); } } }; tasc.execute(url); }
From source file:com.robotoworks.mechanoid.db.SQuery.java
@TargetApi(11) public android.content.CursorLoader createLoader(Uri uri, String[] projection, String sortOrder, boolean enableNotifications) { if (Build.VERSION.SDK_INT < 11) { return null; }//ww w . ja va 2 s . c o m uri = uri.buildUpon() .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(enableNotifications)) .build(); return new android.content.CursorLoader(Mechanoid.getApplicationContext(), uri, projection, toString(), getArgsArray(), sortOrder); }
From source file:org.restcomm.app.qoslib.Utils.QosInfo.java
/** * Called Internally to initialize all of the current measurements for every type of connected newtork * This is like a snapshot of everything at this moment in time * The information comes from various sources and it mainly fetched from the database for this call, or from APIs such as WiFi *//* w w w . j av a2 s . c o m*/ private void updateFromDB() { Cursor sig_cursor = null; Cursor cell_cursor = null; try { Uri signalUri = UriMatch.SIGNAL_STRENGTHS.getContentUri(); Uri limitSignalUri = signalUri.buildUpon().appendQueryParameter("limit", "1").build(); // sig_cursor = managedQuery( Provider dbProvider = ReportManager.getInstance(context.getApplicationContext()).getDBProvider(); if (dbProvider == null) { return; } sig_cursor = dbProvider.query(UriMatch.SIGNAL_STRENGTHS.getContentUri(), null, null, null, Tables.TIMESTAMP_COLUMN_NAME + " DESC"); sig_cursor.moveToFirst(); Uri baseStationTable = (UriMatch.BASE_STATIONS .getContentUri()/*telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA ? UriMatchOld.BASE_STATIONS_CDMA.getContentUri() : UriMatchOld.BASE_STATIONS_GSM.getContentUri()*/ ); Uri limitBSUri = baseStationTable.buildUpon().appendQueryParameter("limit", "1").build(); // Cursor cell_cursor = managedQuery( cell_cursor = dbProvider.query(limitBSUri, null, null, null, Tables.TIMESTAMP_COLUMN_NAME + " DESC"); cell_cursor.moveToFirst(); int LowIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_LOW); int MidIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_MID); int HighIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_HIGH); int CodeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CODE); int BandIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_BAND); int ChanIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CHAN); int netTypeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.NET_TYPE); String netType = cell_cursor.getString(netTypeIndex); int bsLow = cell_cursor.getInt(LowIndex); int bsMid = cell_cursor.getInt(MidIndex); int bsHigh = cell_cursor.getInt(HighIndex); int bsCode = cell_cursor.getInt(CodeIndex); int bsBand = cell_cursor.getInt(BandIndex); int bsChan = cell_cursor.getInt(ChanIndex); if (netType.equals("cdma")) { if (LowIndex != -1) BID = bsLow; if (MidIndex != -1) NID = bsMid; if (HighIndex != -1) SID = bsHigh; } else if (netType.equals("gsm")) { if (LowIndex != -1) { RNC = bsMid; CellID = cell_cursor.getInt(LowIndex); } // the network Id is kept 0 for gsm phones if (HighIndex != -1) LAC = bsHigh; if (bsCode > 0 && bsCode < 1000) PSC = bsCode; else PSC = 0; if (bsBand > 0) Band = bsBand; else Band = 0; if (bsChan > 0) Channel = bsChan; else Channel = 0; } if (sig_cursor.getCount() != 0) { int signalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL); int signal2GIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL2G); int rsrpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRP); int rsrqIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRQ); int lteSnrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SNR); int lteSignalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SIGNAL); int lteCqiIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_CQI); int ecioIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECI0); int ecnoIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECN0); int snrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SNR); int berIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.BER); int rscpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.RSCP); int tierIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.COVERAGE); Integer tier = sig_cursor.isNull(tierIndex) ? null : sig_cursor.getInt(tierIndex); Integer rssi = sig_cursor.isNull(signalIndex) ? null : sig_cursor.getInt(signalIndex); Integer rssi2G = sig_cursor.isNull(signal2GIndex) ? null : sig_cursor.getInt(signal2GIndex); Integer rsrp = sig_cursor.isNull(rsrpIndex) ? null : sig_cursor.getInt(rsrpIndex); Float lteSnr = (sig_cursor.isNull(lteSnrIndex) ? null : (float) sig_cursor.getInt(lteSnrIndex)); Integer lteSignal = sig_cursor.isNull(lteSignalIndex) ? null : sig_cursor.getInt(lteSignalIndex); Integer lteCqi = sig_cursor.isNull(lteCqiIndex) ? null : sig_cursor.getInt(lteCqiIndex); Integer rsrq = sig_cursor.isNull(rsrqIndex) ? null : sig_cursor.getInt(rsrqIndex); Integer eci0 = sig_cursor.isNull(ecioIndex) ? null : sig_cursor.getInt(ecioIndex); Integer ecn0 = sig_cursor.isNull(ecnoIndex) ? null : sig_cursor.getInt(ecnoIndex); Integer snr = sig_cursor.isNull(snrIndex) ? null : sig_cursor.getInt(snrIndex); Integer ber = sig_cursor.isNull(berIndex) ? null : sig_cursor.getInt(berIndex); Integer rscp = sig_cursor.isNull(rscpIndex) ? null : sig_cursor.getInt(rscpIndex); if (eci0 != null && (netType.equals("cdma") || netType.equals("lte")) && eci0 <= -30) eci0 = (eci0 / 10); else if (ecn0 != null && ecn0 > 1 && ecn0 < 60 && netType.equals("gsm")) ecn0 = -(ecn0 / 2); else if (eci0 != null && eci0 > 1 && eci0 < 60 && netType.equals("gsm")) eci0 = -(eci0 / 2); // if (lteSnr != null && lteSnr > 1 && lteSnr < 500) // lteSnr = (lteSnr+5)/10; if (lteSignal != null && lteSignal > -120 && lteSignal < -20) // rssi == lteSignal) { LTE_RSSI = simpleValidate(lteSignal); RSSI = 0; } else if (rssi == null || rssi == -255) RSSI = 0; else if (rssi == -256) RSSI = -256; else { String name = "RSCP: "; int spacing = 15; if (netType.equals("gsm") && (tier == 3 || tier == 4)) { RSCP = rssi; RSSI = 0; } else { RSSI = rssi; RSCP = 0; } LTE_RSSI = 0; } if (netType.equals("cdma") && rssi2G != null && rssi2G < -30 && rssi2G >= -120) CDMA_RSSI = rssi2G; if (tier == 5) { if (lteSnr != null && lteSnr > -101) lteSnr = lteSnr / 10; if (rsrq != null && rsrq > 0) rsrq = -rsrq; LTE_RSRP = simpleValidate(rsrp); LTE_RSRQ = simpleValidate(rsrq); LTE_SNR = simpleValidate(lteSnr); LTE_CQI = simpleValidate(lteCqi); ECIO = simpleValidate(eci0); ECNO = simpleValidate(ecn0); } //nerdview.setValue(0, "RSCP", simpleValidate(rscp, "RSCP", "dBm")); //BER = simpleValidate(ber); SNR = simpleValidate(snr); if (rsrp != null && rsrp <= -10 && rsrp >= -140 && tier == 5) { LTEIdentity = ReportManager.getInstance(context.getApplicationContext()).getNeighbors(); } else { LTEIdentity = null; Neighbors = ReportManager.getInstance(context.getApplicationContext()).getNeighbors(); } } location = ReportManager.getInstance(context.getApplicationContext()).getLastKnownLocation(); try { JSONObject serviceMode = PhoneState.getServiceMode(); if (serviceMode != null && serviceMode.getLong("time") + 5000 > System.currentTimeMillis()) { if (serviceMode.has("rrc") && serviceMode.getString("rrc").length() > 1) { RRC = serviceMode.getString("rrc"); } else RRC = null; if (serviceMode.has("band") && serviceMode.getString("band").length() > 0) { Band = Integer.parseInt(serviceMode.getString("band")); } //else if (serviceMode.has("freq") && serviceMode.getString("freq").length() > 0) { Band = Integer.parseInt(serviceMode.getString("freq")); } else Band = 0; if (serviceMode.has("channel") && serviceMode.getString("channel").length() > 0) { Channel = Integer.parseInt(serviceMode.getString("channel")); } else Channel = 0; } else { RRC = null; Band = 0; Channel = 0; } TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Service.TELEPHONY_SERVICE); String carrier = telephonyManager.getNetworkOperatorName(); String mcc = "0", mnc = "0"; if (telephonyManager.getNetworkOperator() != null && telephonyManager.getNetworkOperator().length() >= 4) { mcc = telephonyManager.getNetworkOperator().substring(0, 3); mnc = telephonyManager.getNetworkOperator().substring(3); } int networkType = telephonyManager.getNetworkType(); int networkTier = PhoneState.getNetworkGeneration(networkType); String nettype = PhoneState.getNetworkName(telephonyManager.getNetworkType()); String data = PhoneState.getNetworkName(telephonyManager.getNetworkType()) + " "; int dataState = telephonyManager.getDataState(); if (dataState == TelephonyManager.DATA_CONNECTED) { String activity = getActivityName(telephonyManager.getDataActivity()); data += activity; } else if (telephonyManager.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) { String state = getStateName(telephonyManager.getDataState()); data += state; } Data = data; Carrier = carrier; Date date = new Date(System.currentTimeMillis()); final String dateStr = DateFormat.getDateFormat(context).format(date); final String timeStr = dateStr + " " + DateFormat.getTimeFormat(context).format(date); Time = timeStr; MCC = Integer.parseInt(mcc); MNC = Integer.parseInt(mnc); // Tell the service we're watching the signal, so keep it updated Intent intent = new Intent(CommonIntentActionsOld.VIEWING_SIGNAL); context.sendBroadcast(intent); WifiInfo wifiinfo = getWifiInfo(); WifiConfiguration wifiConfig = getWifiConfig(); setWifi(wifiinfo, wifiConfig); // Instantiate only the relevant Network type if (netType.equals("cdma")) connectedNetwork = CDMAInfo = new CDMAInfo(this); else if (netType.equals("gsm") && networkTier < 3) connectedNetwork = GSMInfo = new GSMInfo(this); else if (netType.equals("gsm") && networkTier < 5) connectedNetwork = WCDMAInfo = new WCDMAInfo(this); if (networkTier == 5) // LTE connectedNetwork = LTEInfo = new LTEInfo(this); if (wifiConfig != null) connectedNetwork = WiFiInfo = new WIFIInfo(this); // The most relevant network ends up in NetworkInfo } catch (Exception e) { } } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "updateNerdViewFromDB", "exception querying signal data: " + e.getMessage()); } finally { if (cell_cursor != null) cell_cursor.close(); if (sig_cursor != null) sig_cursor.close(); } }
From source file:com.android.music.TrackBrowserFragment.java
private Cursor getTrackCursor(TrackListAdapter.TrackQueryHandler queryhandler, String filter, boolean async) { if (queryhandler == null) { throw new IllegalArgumentException(); }//w w w .jav a 2 s . c o m Cursor ret = null; mSortOrder = MediaStore.Audio.Media.TITLE_KEY; StringBuilder where = new StringBuilder(); where.append(MediaStore.Audio.Media.TITLE + " != ''"); if (mGenre != null) { Uri uri = MediaStore.Audio.Genres.Members.getContentUri("external", Integer.valueOf(mGenre)); if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); } mSortOrder = MediaStore.Audio.Genres.Members.DEFAULT_SORT_ORDER; ret = queryhandler.doQuery(uri, mCursorCols, where.toString(), null, mSortOrder, async); } else if (mPlaylist != null) { if (mPlaylist.equals("nowplaying")) { if (MusicUtils.sService != null) { ret = new NowPlayingCursor(MusicUtils.sService, mCursorCols); if (ret.getCount() == 0) { getActivity().finish(); } } else { // Nothing is playing. } } else if (mPlaylist.equals("podcasts")) { where.append(" AND " + MediaStore.Audio.Media.IS_PODCAST + "=1"); Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); } ret = queryhandler.doQuery(uri, mCursorCols, where.toString(), null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER, async); } else if (mPlaylist.equals("recentlyadded")) { // do a query for all songs added in the last X weeks Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); } int X = MusicUtils.getIntPref(getActivity(), "numweeks", 2) * (3600 * 24 * 7); where.append(" AND " + MediaStore.MediaColumns.DATE_ADDED + ">"); where.append(System.currentTimeMillis() / 1000 - X); ret = queryhandler.doQuery(uri, mCursorCols, where.toString(), null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER, async); } else { Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", Long.valueOf(mPlaylist)); if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); } mSortOrder = MediaStore.Audio.Playlists.Members.DEFAULT_SORT_ORDER; ret = queryhandler.doQuery(uri, mPlaylistMemberCols, where.toString(), null, mSortOrder, async); } } else { if (mAlbumId != null) { where.append(" AND " + MediaStore.Audio.Media.ALBUM_ID + "=" + mAlbumId); mSortOrder = MediaStore.Audio.Media.TRACK + ", " + mSortOrder; } if (mArtistId != null) { where.append(" AND " + MediaStore.Audio.Media.ARTIST_ID + "=" + mArtistId); } where.append(" AND " + MediaStore.Audio.Media.IS_MUSIC + "=1"); Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); } ret = queryhandler.doQuery(uri, mCursorCols, where.toString(), null, mSortOrder, async); } // This special case is for the "nowplaying" cursor, which cannot be handled // asynchronously using AsyncQueryHandler, so we do some extra initialization here. if (ret != null && async) { init(ret, false); setTitle(); } return ret; }
From source file:org.voidsink.anewjkuapp.calendar.CalendarUtils.java
private static boolean deleteKusssEvents(Context context, String calId) { if (calId != null) { ContentProviderClient provider = context.getContentResolver() .acquireContentProviderClient(CalendarContractWrapper.Events.CONTENT_URI()); if (provider == null) { return false; }// w ww.j a va 2 s. c om try { Uri calUri = CalendarContractWrapper.Events.CONTENT_URI(); Cursor c = loadEvent(provider, calUri, calId); if (c != null) { try { ArrayList<ContentProviderOperation> batch = new ArrayList<>(); long deleteFrom = new Date().getTime() - DateUtils.DAY_IN_MILLIS; while (c.moveToNext()) { long eventDTStart = c.getLong(CalendarUtils.COLUMN_EVENT_DTSTART); if (eventDTStart > deleteFrom) { String eventId = c.getString(COLUMN_EVENT_ID); // Log.d(TAG, "---------"); String eventKusssId = null; // get kusssId from extended properties Cursor c2 = provider.query(CalendarContract.ExtendedProperties.CONTENT_URI, CalendarUtils.EXTENDED_PROPERTIES_PROJECTION, CalendarContract.ExtendedProperties.EVENT_ID + " = ?", new String[] { eventId }, null); if (c2 != null) { while (c2.moveToNext()) { if (c2.getString(1).contains(EXTENDED_PROPERTY_NAME_KUSSS_ID)) { eventKusssId = c2.getString(2); } } c2.close(); } if (TextUtils.isEmpty(eventKusssId)) { eventKusssId = c.getString(COLUMN_EVENT_KUSSS_ID_LEGACY); } if (!TextUtils.isEmpty(eventKusssId)) { if (eventKusssId.startsWith("at-jku-kusss-exam-") || eventKusssId.startsWith("at-jku-kusss-coursedate-")) { Uri deleteUri = calUri.buildUpon().appendPath(eventId).build(); Log.d(TAG, "Scheduling delete: " + deleteUri); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } } } if (batch.size() > 0) { Log.d(TAG, "Applying batch update"); provider.applyBatch(batch); Log.d(TAG, "Notify resolver"); } else { Log.w(TAG, "No batch operations found! Do nothing"); } } catch (RemoteException | OperationApplicationException e) { Analytics.sendException(context, e, true); return false; } } } finally { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { provider.close(); } else { provider.release(); } } return false; } return true; }