List of usage examples for android.util Pair Pair
public Pair(F first, S second)
From source file:com.crowflying.buildwatch.ConfigurationActivity.java
/** * Refresh the summaries of the prefs. This is done in one single hunk for * all prefs which is suboptimal from a performance point of view, but is * less code to write. To optimize, only refresh summaries on the settings * that actually changed./*from w w w. j ava 2s.co m*/ */ private void refreshSummaries() { long t1 = System.currentTimeMillis(); List<Pair<String, Integer>> setSummaryTextPrefs = new LinkedList<Pair<String, Integer>>(); setSummaryTextPrefs .add(new Pair<String, Integer>(PREFS_KEY_GCM_SENDER_ID, R.string.config_gcm_sender_id_summary)); setSummaryTextPrefs.add(new Pair<String, Integer>(PREFS_KEY_GCM_TOKEN, R.string.config_gcm_token_summary)); setSummaryTextPrefs .add(new Pair<String, Integer>(PREFS_KEY_JENKINS_TOKEN, R.string.config_jenkins_token_summary)); setSummaryTextPrefs .add(new Pair<String, Integer>(PREFS_KEY_JENKINS_URL, R.string.config_jenkins_base_url_summary)); setSummaryTextPrefs.add( new Pair<String, Integer>(PREFS_KEY_JENKINS_USERNAME, R.string.config_jenkins_username_summary)); SharedPreferences prefs = getPreferenceScreen().getSharedPreferences(); for (Pair<String, Integer> p : setSummaryTextPrefs) { Preference pref = findPreference(p.first); if (pref != null) { pref.setSummary(String.format(getString(p.second), prefs.getString(p.first, ""))); } } // Add 'press to share' to GCM token pref, if there is a token // configured. if (!TextUtils.isEmpty(prefs.getString(PREFS_KEY_GCM_TOKEN, ""))) { Preference pref = findPreference(PREFS_KEY_GCM_TOKEN); if (pref != null) { CharSequence summary = pref.getSummary(); summary = summary + " " + getString(R.string.config_gcm_token_summary_share); pref.setSummary(summary); } } Log.d(LOG_TAG, String.format("Updating summaries took %s ms. This can easily be optimized.", (System.currentTimeMillis() - t1))); }
From source file:com.evgenyvyaz.cinaytaren.activity.FaceTrackerActivity.java
public void loadMyLocation() { MyLocation.getLocation(this, new MyLocation.OnLocationListener() { @Override/*from w w w.j a v a 2 s . co m*/ public void onComplete(Location location) { System.out.println("lat1 = " + location.getLatitude()); YandexRequests.requestGetPlaces(new YandexRequests.OnYandexPlacesListener() { @Override public void success(JSONObject jsonObject) { if (jsonObject == null) { Toast.makeText(getApplicationContext(), " ?... ? ? ? API yandex", Toast.LENGTH_LONG).show(); } organizations = new ArrayList<>(); try { JSONArray features = jsonObject.getJSONArray("features"); for (int i = 0; i < features.length(); i++) { if (features.getJSONObject(i).has("properties") && features.getJSONObject(i).getJSONObject("properties") .has("CompanyMetaData") && features.getJSONObject(i).getJSONObject("properties") .getJSONObject("CompanyMetaData").has("Categories") && features.getJSONObject(i).getJSONObject("properties") .getJSONObject("CompanyMetaData").getJSONArray("Categories") .length() != 0 && features.getJSONObject(i).getJSONObject("properties") .getJSONObject("CompanyMetaData").getJSONArray("Categories") .optJSONObject(0).has("class")) { String orgType = features.getJSONObject(i).getJSONObject("properties") .getJSONObject("CompanyMetaData").getJSONArray("Categories") .optJSONObject(0).getString("class"); JSONArray geometry = features.getJSONObject(i).getJSONObject("geometry") .getJSONArray("coordinates"); Map<String, Double> values = new HashMap<>(); values.put("angle", getAngle(geometry.getDouble(1), geometry.getDouble(0), Double.parseDouble(Preferences.getMyLat(getApplicationContext())), Double.parseDouble(Preferences.getMyLong(getApplicationContext())))); values.put("distance", distance(geometry.getDouble(1), geometry.getDouble(0), Double.parseDouble(Preferences.getMyLat(getApplicationContext())), Double.parseDouble(Preferences.getMyLong(getApplicationContext())))); Pair<String, Map<String, Double>> org = new Pair<>(orgType, values); organizations.add(org); view.setTypes(organizations); } } } catch (JSONException e) { e.printStackTrace(); } } @Override public void failure() { System.out.println("request fail = "); } }, getApplicationContext()); // loadContent(Preferences.Settings.getMyLat(getApplicationContext()), Preferences.Settings.getMyLong(getApplicationContext())); } }); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.MobileServiceFeaturesTests.java
public void testTypedTableUpdateWithParametersFeatureHeader() { testTableFeatureHeader(new TableTestOperation() { @Override//from w w w .ja v a2 s . c o m public void executeOperation(MobileServiceTable<PersonTestObjectWithStringId> typedTable, MobileServiceJsonTable jsonTable) throws Exception { PersonTestObjectWithStringId pto = new PersonTestObjectWithStringId("John", "Doe", 33); pto.setId("the-id"); List<Pair<String, String>> queryParams = new ArrayList<Pair<String, String>>(); queryParams.add(new Pair<String, String>("a", "b")); typedTable.update(pto, queryParams).get(); } }, false, "QS,TT"); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.PictureObj.java
@Override public Pair<JSONObject, byte[]> handleOutgoing(JSONObject json) { byte[] bytes = FastBase64.decode(json.optString(DATA)); json.remove(DATA);/*from ww w . jav a 2s . c o m*/ return new Pair<JSONObject, byte[]>(json, bytes); }
From source file:it.geosolutions.geocollect.android.core.mission.utils.MissionUtils.java
/** * checks if mandatory fields were compiled using the mandatory field of the defaulttemplate * //from w w w . j a va 2 s. c om * @param form the form to check * @param id to refer to * @param db to read from * @param tableName to refer to * @return ArrayList with the fields label which was not compiled or an empty list if all was done */ public static ArrayList<String> checkIfAllMandatoryFieldsAreSatisfied(final Form form, final String id, final Database db, final String tableName) { ArrayList<String> missingEntries = new ArrayList<String>(); Stmt st = null; //find mandatory fields ArrayList<Pair<String, String>> missingFieldIDs = new ArrayList<Pair<String, String>>(); for (Page page : form.pages) { for (Field f : page.fields) { if (f.mandatory) { missingFieldIDs.add(new Pair<String, String>(f.fieldId, f.label)); } } } //if no mandatory fields no need to continue if (missingFieldIDs.isEmpty()) { return missingEntries; } //create selection String selection = ""; for (int i = 0; i < missingFieldIDs.size(); i++) { selection += missingFieldIDs.get(i).first; if (i < missingFieldIDs.size() - 1) { selection += ","; } } //create query final String s = "SELECT " + selection + " FROM '" + tableName + "' WHERE ORIGIN_ID = '" + id + "';"; //do the query if (jsqlite.Database.complete(s)) { try { st = db.prepare(s); if (st.step()) { for (int j = 0; j < st.column_count(); j++) { //if mandatory field is null or empty, add it to the missing entries if (st.column_string(j) == null || st.column_string(j).equals("")) { missingEntries.add(missingFieldIDs.get(j).second); } } } } catch (Exception e) { Log.d(MissionUtils.class.getSimpleName(), "Error checkIfAllMandatoryFieldsArsSatisfied", e); } } else { if (BuildConfig.DEBUG) { Log.w(TAG, "Query is not complete: " + s); } } return missingEntries; }
From source file:dynamite.zafroshops.app.fragment.TypedZopsFragment.java
private void setZops(final boolean force) { Activity activity = getActivity();// w w w . j a va 2 s .c o m adapter = new TypedZopListViewAdapter(getActivity(), R.id.listViewItem, typedZops); final SharedPreferences preferences = activity.getPreferences(0); final SharedPreferences.Editor editor = preferences.edit(); final ZopType type = (ZopType) getArguments().get(ARG_ZOP_TYPE); final String key = StorageKeys.ZOPS_KEY + type.toString(); zopType = type; if (!preferences.contains(key)) { InputStream is = getResources().openRawResource(R.raw.zops); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); typedZops = new ArrayList<>(Collections2.filter( (ArrayList<MobileZop>) new Gson().fromJson(reader, new TypeToken<ArrayList<MobileZop>>() { }.getType()), new Predicate<MobileZop>() { @Override public boolean apply(MobileZop input) { return input.Type == type && (!preferences.contains(StorageKeys.COUNTRY_KEY) || preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("") || input.CountryID.equals(preferences.getString(StorageKeys.COUNTRY_KEY, ""))); } })); try { FileOutputStream fos = activity.openFileOutput(key, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); int count = typedZops.size(); oos.writeObject(typedZops); oos.close(); fos.close(); editor.putString(key, Integer.toString(count)); editor.commit(); setCount(count); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else if (preferences.contains(key)) { try { FileInputStream fis = activity.openFileInput(key); ObjectInputStream ois = new ObjectInputStream(fis); ArrayList<MobileZop> temp = (ArrayList) ois.readObject(); typedZops = new ArrayList<>(Collections2.filter(temp, new Predicate<MobileZop>() { @Override public boolean apply(MobileZop input) { return input.Type == type && (!preferences.contains(StorageKeys.COUNTRY_KEY) || preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("") || input.CountryID.equals(preferences.getString(StorageKeys.COUNTRY_KEY, ""))); } })); ois.close(); fis.close(); setCount(typedZops.size()); if (adapter != null) { adapter.setObjects(typedZops); adapter.notifyDataSetChanged(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } if (force) { final ArrayList<Pair<String, String>> parameters; if (MainActivity.LastLocation != null) { parameters = new ArrayList<Pair<String, String>>() { { add(new Pair<>("latitude", Double.toString(MainActivity.LastLocation.Latitude))); add(new Pair<>("longitude", Double.toString(MainActivity.LastLocation.Longitude))); add(new Pair<>("type", type.getText())); } }; } else { parameters = new ArrayList<Pair<String, String>>() { { add(new Pair<>("type", type.getText())); } }; } ListenableFuture<JsonElement> result = MainActivity.MobileClient.invokeApi("mobileZop", "GET", parameters); Futures.addCallback(result, new FutureCallback<JsonElement>() { Activity activity = getActivity(); @Override public void onSuccess(JsonElement result) { JsonArray typesAsJson = result.getAsJsonArray(); if (typesAsJson != null) { ArrayList<MobileZop> temp = new Gson().fromJson(result, new TypeToken<ArrayList<MobileZop>>() { }.getType()); int max = Collections.max(temp, new Comparator<MobileZop>() { @Override public int compare(MobileZop lhs, MobileZop rhs) { if (lhs.DataVersion < rhs.DataVersion) { return -1; } else if (lhs.DataVersion > rhs.DataVersion) { return 1; } else { return 0; } } }).DataVersion; ((MainActivity) activity).Versions.put(zopType, max); try { FileOutputStream fos = activity.openFileOutput(key, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); int count = typedZops.size(); typedZops = new ArrayList<>(Collections2.filter(temp, new Predicate<MobileZop>() { @Override public boolean apply(MobileZop input) { return input.Type == type && (!preferences.contains(StorageKeys.COUNTRY_KEY) || preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("") || input.CountryID .equals(preferences.getString(StorageKeys.COUNTRY_KEY, ""))); } })); oos.writeObject(typedZops); oos.close(); fos.close(); editor.putString(key, Integer.toString(count)); editor.commit(); setCount(count); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } if (adapter != null) { adapter.setObjects(typedZops); resetVisibility(false); adapter.notifyDataSetChanged(); } } @Override public void onFailure(@NonNull Throwable t) { ListView zops = (ListView) activity.findViewById(R.id.listViewZops); RelativeLayout loader = (RelativeLayout) activity.findViewById(R.id.relativeLayoutLoader); LinearLayout noZops = (LinearLayout) activity.findViewById(R.id.noZops); resetVisibility(zops, noZops, loader, false); } }); } }
From source file:it.mb.whatshare.SendToGCMActivity.java
/** * Loads the ID and name of the paired device in use to share content when * Whatsapp is not installed on this device. * //w ww . jav a 2s . c o m * @param activity * the calling activity * @return the device loaded from file if any is configured, * <code>null</code> otherwise * @throws OptionalDataException * @throws ClassNotFoundException * @throws IOException */ static Pair<PairedDevice, String> loadOutboundPairing(Context activity) throws OptionalDataException, ClassNotFoundException, IOException { FileInputStream fis = activity.openFileInput("pairing"); Scanner scanner = new Scanner(fis).useDelimiter("\\Z"); JSONObject json; try { json = new JSONObject(scanner.next()); String name = json.getString("name"); String type = json.getString("type"); String assignedID = json.getString("assignedID"); return new Pair<PairedDevice, String>(new PairedDevice(assignedID, name, type), assignedID); } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VideoObj.java
@Override public Pair<JSONObject, byte[]> handleOutgoing(JSONObject json) { byte[] bytes = Base64.decode(json.optString(DATA)); json.remove(DATA);//from w w w . j av a 2 s. co m return new Pair<JSONObject, byte[]>(json, bytes); }
From source file:com.easemob.qixin.activity.ContactlistFragment.java
/** * ??//from w w w . j av a 2 s .co m * * @param context * @return + */ private List<QXUser> loadConversationsWithRecentChat() { Hashtable<String, EMConversation> conversations = EMChatManager.getInstance().getAllConversations(); // messages size0conversation /** * ??lastMsgTime?? ??Collection.sort * ??ConversationSort????? ??? */ List<Pair<Long, String>> sortList = new ArrayList<Pair<Long, String>>(); synchronized (conversations) { for (EMConversation conversation : conversations.values()) { if (conversation.getAllMessages().size() != 0) { sortList.add(new Pair<Long, String>(conversation.getLastMessage().getMsgTime(), conversation.getUserName())); } } } try { // Internal is TimSort algorithm, has bug sortConversationByLastChatTime(sortList); } catch (Exception e) { e.printStackTrace(); } list.clear(); for (Pair<Long, String> sortItem : sortList) { for (QXUser user : DemoApplication.getInstance().getAllUsers()) { if (user.getHXid().equals(sortItem.second)) { list.add(user); } } } return list; }
From source file:com.tmall.wireless.tangram.util.Utils.java
/** * <pre>/*from w ww.j av a2 s . co m*/ * parse image ratio from imageurl with regex as follows: * (\d+)-(\d+)(_?q\d+)?(\.[jpg|png|gif]) * (\d+)x(\d+)(_?q\d+)?(\.[jpg|png|gif]) * * samples urls: * http://img.alicdn.com/tps/i1/TB1x623LVXXXXXZXFXXzo_ZPXXX-372-441.png --> return 372, 441 * http://img.alicdn.com/tps/i1/TB1P9AdLVXXXXa_XXXXzo_ZPXXX-372-441.png --> return 372, 441 * http://img.alicdn.com/tps/i1/TB1NZxRLFXXXXbwXFXXzo_ZPXXX-372-441.png --> return 372, 441 * http://img07.taobaocdn.com/tfscom/T10DjXXn4oXXbSV1s__105829.jpg_100x100.jpg --> return 100, 100 * http://img07.taobaocdn.com/tfscom/T10DjXXn4oXXbSV1s__105829.jpg_100x100q90.jpg --> return 100, 100 * http://img07.taobaocdn.com/tfscom/T10DjXXn4oXXbSV1s__105829.jpg_100x100q90.jpg_.webp --> return 100, 100 * http://img03.taobaocdn.com/tps/i3/T1JYROXuRhXXajR_DD-1680-446.jpg_q50.jpg --> return 1680, 446 * </pre> * @param imageUrl image url * @return width and height pair parsed from url */ public static Pair<Integer, Integer> getImageSize(String imageUrl) { if (TextUtils.isEmpty(imageUrl)) return null; try { Matcher matcher = REGEX_1.matcher(imageUrl); String widthStr; String heightStr; if (matcher.find()) { if (matcher.groupCount() >= 2) { widthStr = matcher.group(1); heightStr = matcher.group(2); if (widthStr.length() < 5 && heightStr.length() < 5) { int urlWidth = Integer.parseInt(widthStr); int urlHeight = Integer.parseInt(heightStr); return new Pair<>(urlWidth, urlHeight); } } } else { matcher = REGEX_2.matcher(imageUrl); if (matcher.find()) { if (matcher.groupCount() >= 2) { widthStr = matcher.group(1); heightStr = matcher.group(2); if (widthStr.length() < 5 && heightStr.length() < 5) { int urlWidth = Integer.parseInt(widthStr); int urlHeight = Integer.parseInt(heightStr); return new Pair<>(urlWidth, urlHeight); } } } } } catch (Exception e) { e.printStackTrace(); } return null; }