List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:conexionSiabra.ConexionSiabra.java
public JSONObject agregarPerfil(String codigo) { Pair<String, String> elemento = new Pair<String, String>("codigo", codigo); ArrayList<Pair<String, String>> elementos = new ArrayList<Pair<String, String>>(); elementos.add(elemento);//from ww w. j ava 2 s . c om return oauth.peticionPost(elementos, url_agregar_perfil); }
From source file:com.docd.purefm.test.MediaStoreUtilsTest.java
private void testMoveFile(@NonNull final ContentResolver resolver) throws Throwable { final GenericFile test1dir = new JavaFile(TEST_ROOT, "test6.txt"); final GenericFile test2dir = new JavaFile(TEST_ROOT, "test7.txt"); test1dir.mkdir();//from w w w. j a v a 2 s. c om assertTrue(test1dir.exists()); assertTrue(test1dir.isDirectory()); test2dir.mkdir(); assertTrue(test2dir.exists()); assertTrue(test2dir.isDirectory()); final GenericFile test1file = new JavaFile(test1dir.toFile(), "test8.txt"); final GenericFile test2file = new JavaFile(test2dir.toFile(), "test8.txt"); test1file.createNewFile(); assertTrue(test1file.exists()); assertFalse(test1file.isDirectory()); MediaStoreUtils.addEmptyFileOrDirectory(resolver, test1dir); MediaStoreUtils.addEmptyFileOrDirectory(resolver, test2dir); MediaStoreUtils.addEmptyFileOrDirectory(resolver, test1file); assertTrue(isFileInMediaStore(resolver, test1dir)); assertTrue(isFileInMediaStore(resolver, test2dir)); assertTrue(isFileInMediaStore(resolver, test1file)); FileUtils.moveFile(test1file.toFile(), test2file.toFile()); final List<Pair<GenericFile, GenericFile>> files = new ArrayList<>(1); files.add(new Pair<>(test1file, test2file)); MediaStoreUtils.moveFiles(getContext(), files); assertTrue(isFileInMediaStore(resolver, test1dir)); assertTrue(isFileInMediaStore(resolver, test2dir)); assertFalse(isFileInMediaStore(resolver, test1file)); //there is no waiting for MediaScanner to finish, so we must skip this check //assertTrue(isFileInMediaStore(resolver, test2file)); test2file.delete(); test1dir.delete(); test2dir.delete(); MediaStoreUtils.deleteFileOrDirectory(resolver, test2file); MediaStoreUtils.deleteFileOrDirectory(resolver, test1dir); MediaStoreUtils.deleteFileOrDirectory(resolver, test2dir); assertFalse(isFileInMediaStore(resolver, test1dir)); assertFalse(isFileInMediaStore(resolver, test2dir)); assertFalse(isFileInMediaStore(resolver, test2file)); }
From source file:com.siahmsoft.soundwaper.net.SoundcloudApi.java
private Pair<Bitmap, Track> getRandomBitmap(List<Track> tracks) { Track track = null;//from w w w .j a v a2 s . c o m Bitmap bitmap = null; int randomIndex = 0; if (tracks.size() > 0) { randomIndex = roulette.nextInt(tracks.size()); track = tracks.get(randomIndex); if (track != null) { try { bitmap = retrieveBitmap(new URL(track.getWaveformUrl())); } catch (MalformedURLException e) { e.printStackTrace(); } } } return new Pair<Bitmap, Track>(bitmap, track); }
From source file:com.cerema.cloud2.lib.resources.shares.UpdateRemoteShareOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; /// prepare array of parameters to update List<Pair<String, String>> parametersToUpdate = new ArrayList<Pair<String, String>>(); if (mPassword != null) { parametersToUpdate.add(new Pair<String, String>(PARAM_PASSWORD, mPassword)); }/*from w ww. java 2s . c om*/ if (mExpirationDateInMillis < 0) { // clear expiration date parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, "")); } else if (mExpirationDateInMillis > 0) { // set expiration date DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE); Calendar expirationDate = Calendar.getInstance(); expirationDate.setTimeInMillis(mExpirationDateInMillis); String formattedExpirationDate = dateFormat.format(expirationDate.getTime()); parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate)); } // else, ignore - no update if (mPermissions > 0) { // set permissions parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions))); } if (mPublicUpload != null) { parametersToUpdate.add(new Pair(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload))); } /// perform required PUT requests PutMethod put = null; String uriString = null; try { Uri requestUri = client.getBaseUri(); Uri.Builder uriBuilder = requestUri.buildUpon(); uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH.substring(1)); uriBuilder.appendEncodedPath(Long.toString(mRemoteId)); uriString = uriBuilder.build().toString(); for (Pair<String, String> parameter : parametersToUpdate) { if (put != null) { put.releaseConnection(); } put = new PutMethod(uriString); put.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); put.setRequestEntity(new StringRequestEntity(parameter.first + "=" + parameter.second, ENTITY_CONTENT_TYPE, ENTITY_CHARSET)); status = client.executeMethod(put); if (status == HttpStatus.SC_OK) { String response = put.getResponseBodyAsString(); // Parse xml response ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( new ShareXMLParser()); parser.setOwnCloudVersion(client.getOwnCloudVersion()); parser.setServerBaseUri(client.getBaseUri()); result = parser.parse(response); } else { result = new RemoteOperationResult(false, status, put.getResponseHeaders()); } } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while updating remote share ", e); if (put != null) { put.releaseConnection(); } } finally { if (put != null) { put.releaseConnection(); } } return result; }
From source file:org.site_monitor.service.NetworkService.java
public void refreshSites(DBSiteSettings siteSettingDao, DBSiteCall dbSiteCall) throws SQLException { List<SiteSettings> siteSettingList = siteSettingDao.queryForAll(); List<Pair<SiteSettings, SiteCall>> failsPairs = new LinkedList<>(); if (BuildConfig.DEBUG) { Log.d(TAG, "action: " + REQUEST_REFRESH_SITES + " nbSites: " + siteSettingList.size()); }//from w ww . j a v a 2 s . c o m for (SiteSettings siteSettings : siteSettingList) { if (BuildConfig.DEBUG) { Log.v(TAG, "call: " + siteSettings); } BroadcastUtil.broadcast(this, ACTION_SITE_START_REFRESH, siteSettings); SiteCall siteCall = networkUtil.buildHeadHttpConnectionThenDoCall(this, siteSettings); siteCall.setSiteSettings(siteSettings); BroadcastUtil.broadcast(this, ACTION_SITE_END_REFRESH, siteSettings, siteCall); if (siteCall.getResult() == NetworkCallResult.FAIL) { failsPairs.add(new Pair<>(siteSettings, siteCall)); } dbSiteCall.create(siteCall); } boolean atLeastOneToNotify = false; if (!failsPairs.isEmpty()) { StringBuilder sb = new StringBuilder(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean limitToNewFail = preferences.getBoolean(PrefSettingsActivity.NOTIFICATION_LIMIT_TO_NEW_FAIL, true); for (Pair<SiteSettings, SiteCall> pair : failsPairs) { // never break to get all sites in fail if (sb.length() > 0) { sb.append(COMA); } sb.append(pair.first.getName()); if (pair.first.isNotificationEnabled()) { if (limitToNewFail) { if (pair.first.getSiteCalls().isEmpty()) { atLeastOneToNotify = true; } else { List<SiteCall> siteCalls = new ArrayList<>(pair.first.getSiteCalls()); Collections.sort(siteCalls, SiteCall.DESC_DATE); SiteCall previousCall = siteCalls.get(0); if (previousCall.getResult() == NetworkCallResult.SUCCESS) { atLeastOneToNotify = true; } } } else { atLeastOneToNotify = true; } } } if (atLeastOneToNotify) { PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = NotificationUtil.build(this, failsPairs.size() + " " + getString(R.string.state_unreachable), sb.toString(), pendingIntent); NotificationUtil.send(this, NotificationUtil.ID_NOT_REACHABLE, notificationBuilder.build()); } } WidgetManager.refresh(this); }
From source file:com.appnexus.opensdk.ANJAMImplementation.java
@SuppressLint("SetJavaScriptEnabled") private static void callInternalBrowser(AdWebView webView, Uri uri) { String urlParam = uri.getQueryParameter("url"); if ((webView.getContext() == null) || (urlParam == null) || (!urlParam.startsWith("http"))) { return;//w ww . j a v a 2s .c o m } String url = Uri.decode(urlParam); Class<?> activity_clz = AdActivity.getActivityClass(); Intent intent = new Intent(webView.getContext(), activity_clz); intent.putExtra(AdActivity.INTENT_KEY_ACTIVITY_TYPE, AdActivity.ACTIVITY_TYPE_BROWSER); WebView browserWebView = new WebView(webView.getContext()); WebviewUtil.setWebViewSettings(browserWebView); BrowserAdActivity.BROWSER_QUEUE.add(browserWebView); browserWebView.loadUrl(url); if (webView.adView.getBrowserStyle() != null) { String i = "" + browserWebView.hashCode(); intent.putExtra("bridgeid", i); AdView.BrowserStyle.bridge .add(new Pair<String, AdView.BrowserStyle>(i, webView.adView.getBrowserStyle())); } try { webView.getContext().startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(webView.getContext(), R.string.action_cant_be_completed, Toast.LENGTH_SHORT).show(); Clog.w(Clog.baseLogTag, Clog.getString(R.string.adactivity_missing, activity_clz.getName())); BrowserAdActivity.BROWSER_QUEUE.remove(); } }
From source file:com.rastating.droidbeard.net.SickbeardAsyncTask.java
protected String getJson(String cmd, String paramKey, Object paramValue) { List<Pair<String, Object>> params = new ArrayList<Pair<String, Object>>(); params.add(new Pair<String, Object>(paramKey, paramValue)); return getJson(cmd, params); }
From source file:co.uk.alt236.restclient4android.fragments.FragmentHeaders.java
private boolean saveHeader(int index, String name, String value) { name = name.trim();//from w w w . ja v a2 s. co m value = value.trim(); if (name.length() > 0) { Pair<String, String> header = new Pair<String, String>(name, value); if (index > 0) { RestClient4AndroidApplication.getRequest().getRequestHeaders().set(index, header); } else { RestClient4AndroidApplication.getRequest().getRequestHeaders().add(header); } mAdapter.notifyDataSetChanged(); Log.d(TAG, "^ HEADERS: " + mAdapter.getCount()); return true; } else { Toast.makeText(getActivity(), "A header must have a name!", Toast.LENGTH_SHORT); return false; } }
From source file:conexionSiabra.ConexionSiabra.java
public JSONObject getPerfil(String codigo) { Pair<String, String> elemento = new Pair<String, String>("codigo", codigo); return oauth.peticionGet(elemento, url_obtener_perfil); }
From source file:com.google.android.apps.dashclock.gmail.GmailExtension.java
@Override protected void onUpdateData(int reason) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); String labelCanonical = sp.getString(PREF_LABEL, "i"); Set<String> selectedAccounts = getSelectedAccounts(); if ("i".equals(labelCanonical)) { labelCanonical = GmailContract.Labels.LabelCanonicalNames.CANONICAL_NAME_INBOX; } else if ("p".equals(labelCanonical)) { labelCanonical = GmailContract.Labels.LabelCanonicalNames.CANONICAL_NAME_PRIORITY_INBOX; }//from ww w. jav a2 s . com int unread = 0; List<Pair<String, Integer>> unreadPerAccount = new ArrayList<Pair<String, Integer>>(); String lastUnreadLabelUri = null; for (String account : selectedAccounts) { Cursor cursor = tryOpenLabelsCursor(account); if (cursor == null || cursor.isAfterLast()) { LOGD(TAG, "No Gmail inbox information found for account."); if (cursor != null) { cursor.close(); } continue; } int accountUnread = 0; while (cursor.moveToNext()) { int thisUnread = cursor.getInt(LabelsQuery.NUM_UNREAD_CONVERSATIONS); String thisCanonicalName = cursor.getString(LabelsQuery.CANONICAL_NAME); if (labelCanonical.equals(thisCanonicalName)) { accountUnread = thisUnread; if (thisUnread > 0) { lastUnreadLabelUri = cursor.getString(LabelsQuery.URI); } break; } else if (!TextUtils.isEmpty(thisCanonicalName) && thisCanonicalName.startsWith(SECTIONED_INBOX_CANONICAL_NAME_PREFIX)) { accountUnread += thisUnread; if (thisUnread > 0 && SECTIONED_INBOX_CANONICAL_NAME_PERSONAL.equals(thisCanonicalName)) { lastUnreadLabelUri = cursor.getString(LabelsQuery.URI); } } } if (accountUnread > 0) { unreadPerAccount.add(new Pair<String, Integer>(account, accountUnread)); unread += accountUnread; } cursor.close(); } StringBuilder body = new StringBuilder(); for (Pair<String, Integer> pair : unreadPerAccount) { if (pair.second == 0) { continue; } if (body.length() > 0) { body.append("\n"); } body.append(pair.first).append(" (").append(pair.second).append(")"); } Intent clickIntent = null; if (lastUnreadLabelUri != null) { try { clickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(lastUnreadLabelUri)); if (getPackageManager().resolveActivity(clickIntent, 0) == null) { throw new IllegalStateException("Gmail can't open this label directly."); } } catch (Exception e) { LOGW(TAG, "Can't open Gmail label directly.", e); clickIntent = null; } } if (clickIntent == null) { clickIntent = new Intent(Intent.ACTION_MAIN).setPackage("com.google.android.gm") .addCategory(Intent.CATEGORY_LAUNCHER); } publishUpdate(new ExtensionData().visible(unread > 0).status(Integer.toString(unread)) .expandedTitle(getResources().getQuantityString(R.plurals.gmail_title_template, unread, unread)) .icon(R.drawable.ic_extension_gmail).expandedBody(body.toString()).clickIntent(clickIntent)); }