List of usage examples for android.util Pair create
public static <A, B> Pair<A, B> create(A a, B b)
From source file:com.taobao.weex.extend.module.actionsheet.WXActionSheet.java
private void prepareArguments() { Bundle bundle = getArguments();/*from w w w .ja v a2 s. co m*/ if (bundle != null) { titleText = bundle.getString(KEY_TITLE); messageText = bundle.getString(KEY_MESSAGE); actionItems = new ArrayList<>(); ArrayList<String> items = bundle.getStringArrayList(KEY_ITEMS); if (items != null) { for (String item : items) { String[] splited = item.split(SEPARATOR); if (splited.length == 2) { actionItems.add(Pair.create(splited[0], splited[1])); } } } } }
From source file:org.mariotaku.twidere.fragment.UserFragment.java
private void displayRelationship(@Nullable final ParcelableUser user, @Nullable final UserRelationship userRelationship) { if (user == null) { mRelationship = null;/*from w w w . j a va2 s. com*/ return; } if (user.account_key.maybeEquals(user.key)) { mFollowButton.setText(R.string.edit); mFollowButton.setVisibility(View.VISIBLE); mRelationship = userRelationship; return; } if (userRelationship == null || !userRelationship.check(user)) { mRelationship = null; return; } else { mRelationship = userRelationship; } invalidateOptionsMenu(); mFollowButton.setEnabled(userRelationship.blocking || !userRelationship.blocked_by); if (userRelationship.blocked_by) { mPagesErrorContainer.setVisibility(View.GONE); mPagesErrorText.setText(null); mPagesContent.setVisibility(View.VISIBLE); } else if (!userRelationship.following && user.is_protected) { mPagesErrorContainer.setVisibility(View.VISIBLE); mPagesErrorText.setText(R.string.user_protected_summary); mPagesErrorIcon.setImageResource(R.drawable.ic_info_locked); mPagesContent.setVisibility(View.GONE); } else { mPagesErrorContainer.setVisibility(View.GONE); mPagesErrorText.setText(null); mPagesContent.setVisibility(View.VISIBLE); } if (userRelationship.blocking) { mFollowButton.setText(R.string.unblock); } else if (userRelationship.following) { mFollowButton.setText(R.string.unfollow); } else if (user.is_follow_request_sent) { mFollowButton.setText(R.string.requested); } else { mFollowButton.setText(R.string.follow); } mFollowButton.setCompoundDrawablePadding(Math.round(mFollowButton.getTextSize() * 0.25f)); mFollowingYouIndicator.setVisibility(userRelationship.followed_by ? View.VISIBLE : View.GONE); final CacheUserInfoTask task = new CacheUserInfoTask(getContext().getApplicationContext()); task.setParams(Pair.create(user, userRelationship)); TaskStarter.execute(task); mFollowButton.setVisibility(View.VISIBLE); }
From source file:com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.java
/** * Executes the query against the table//www. j av a 2s. c om * * @param request Request to execute * @param content The content of the request body * @param httpMethod The method of the HTTP request * @param requestHeaders Additional request headers used in the HTTP request * @param parameters A list of user-defined parameters and values to include in the * request URI query string * @param features The features used in the request */ private ListenableFuture<Pair<JsonObject, ServiceFilterResponse>> executeTableOperation(String path, String content, String httpMethod, List<Pair<String, String>> requestHeaders, List<Pair<String, String>> parameters, EnumSet<MobileServiceFeatures> features) { final SettableFuture<Pair<JsonObject, ServiceFilterResponse>> future = SettableFuture.create(); MobileServiceHttpClient httpClient = new MobileServiceHttpClient(mClient); if (requestHeaders == null) { requestHeaders = new ArrayList<Pair<String, String>>(); } if (content != null) { requestHeaders .add(new Pair<String, String>(HTTP.CONTENT_TYPE, MobileServiceConnection.JSON_CONTENTTYPE)); } ListenableFuture<ServiceFilterResponse> internalFuture = httpClient.request(path, content, httpMethod, requestHeaders, parameters, features); Futures.addCallback(internalFuture, new FutureCallback<ServiceFilterResponse>() { @Override public void onFailure(Throwable exc) { future.setException(transformHttpException(exc)); } @Override public void onSuccess(ServiceFilterResponse result) { String content = null; content = result.getContent(); if (content == null) { future.set(null); } else { JsonObject newEntityJson = new JsonParser().parse(content).getAsJsonObject(); future.set(Pair.create(newEntityJson, result)); } } }); return future; }
From source file:com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.java
/** * Retrieves a set of rows from using the specified URL * * @param query The URL used to retrieve the rows * @param features The features used in this request *//*ww w. j a v a 2 s. c o m*/ private ListenableFuture<Pair<JsonElement, ServiceFilterResponse>> executeGetRecords(final String url, EnumSet<MobileServiceFeatures> features) { final SettableFuture<Pair<JsonElement, ServiceFilterResponse>> future = SettableFuture.create(); ServiceFilterRequest request = new ServiceFilterRequestImpl(new HttpGet(url), mClient.getAndroidHttpClientFactory()); String featuresHeader = MobileServiceFeatures.featuresToString(features); if (featuresHeader != null) { request.addHeader(MobileServiceHttpClient.X_ZUMO_FEATURES, featuresHeader); } MobileServiceConnection conn = mClient.createConnection(); // Create AsyncTask to execute the request and parse the results new RequestAsyncTask(request, conn) { @Override protected void onPostExecute(ServiceFilterResponse response) { if (mTaskException == null && response != null) { JsonElement results = null; try { // Parse the results using the given Entity class String content = response.getContent(); JsonElement json = new JsonParser().parse(content); results = json; future.set(Pair.create(results, response)); } catch (Exception e) { future.setException(new MobileServiceException("Error while retrieving data from response.", e, response)); } } else { future.setException(mTaskException); } } }.executeTask(); return future; }
From source file:android.content.pm.PackageParser.java
private static Pair<String, String> parsePackageSplitNames(XmlPullParser parser, AttributeSet attrs, int flags) throws IOException, XmlPullParserException, PackageParserException { int type;//from w w w . j a v a2s. c om while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { } if (type != XmlPullParser.START_TAG) { throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, "No start tag found"); } if (!parser.getName().equals("manifest")) { throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, "No <manifest> tag"); } final String packageName = attrs.getAttributeValue(null, "package"); if (!"android".equals(packageName)) { final String error = validateName(packageName, true, true); if (error != null) { throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, "Invalid manifest package: " + error); } } String splitName = attrs.getAttributeValue(null, "split"); if (splitName != null) { if (splitName.length() == 0) { splitName = null; } else { final String error = validateName(splitName, false, false); if (error != null) { throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME, "Invalid manifest split: " + error); } } } return Pair.create(packageName.intern(), (splitName != null) ? splitName.intern() : splitName); }
From source file:org.appcelerator.titanium.view.TiUIView.java
/** * "Forget" the values we save after scale and rotation and alpha animations. *//*from www. j a v a2 s .c o m*/ private void resetPostAnimationValues() { animatedRotationDegrees = 0f; // i.e., no rotation. animatedScaleValues = Pair.create(Float.valueOf(1f), Float.valueOf(1f)); // 1 means no scaling animatedAlpha = Float.MIN_VALUE; // we use min val to signal no val. }
From source file:com.parse.OfflineStore.java
/** * This should be called by the ParseObject constructor notify the store that there is an object * with this className and objectId.//from w w w .j a va 2 s.c om */ /* package */ void registerNewObject(ParseObject object) { synchronized (lock) { String objectId = object.getObjectId(); if (objectId != null) { String className = object.getClassName(); Pair<String, String> classNameAndObjectId = Pair.create(className, objectId); classNameAndObjectIdToObjectMap.put(classNameAndObjectId, object); } } }
From source file:com.parse.OfflineStore.java
void unregisterObject(ParseObject object) { synchronized (lock) { String objectId = object.getObjectId(); if (objectId != null) { classNameAndObjectIdToObjectMap.remove(Pair.create(object.getClassName(), objectId)); }//from w w w . java 2 s.c o m } }
From source file:com.parse.OfflineStore.java
/** * This should only ever be called from ParseObject.createWithoutData(). * * @return a pair of ParseObject and Boolean. The ParseObject is the object. The Boolean is true * iff the object was newly created. *//*from w w w .j ava 2s . co m*/ /* package */ ParseObject getObject(String className, String objectId) { if (objectId == null) { throw new IllegalStateException("objectId cannot be null."); } Pair<String, String> classNameAndObjectId = Pair.create(className, objectId); // This lock should never be held by anyone doing disk or database access. synchronized (lock) { return classNameAndObjectIdToObjectMap.get(classNameAndObjectId); } }
From source file:com.parse.OfflineStore.java
/** * When an object is finished saving, it gets an objectId. Then it should call this method to * clean up the bookeeping around ids./* w w w. ja v a 2 s . c o m*/ */ /* package */ void updateObjectId(ParseObject object, String oldObjectId, String newObjectId) { if (oldObjectId != null) { if (oldObjectId.equals(newObjectId)) { return; } throw new RuntimeException("objectIds cannot be changed in offline mode."); } String className = object.getClassName(); Pair<String, String> classNameAndNewObjectId = Pair.create(className, newObjectId); synchronized (lock) { // See if there's already an entry for the new object id. ParseObject existing = classNameAndObjectIdToObjectMap.get(classNameAndNewObjectId); if (existing != null && existing != object) { throw new RuntimeException( "Attempted to change an objectId to one that's " + "already known to the Offline Store."); } // Okay, all clear to add the new reference. classNameAndObjectIdToObjectMap.put(classNameAndNewObjectId, object); } }