mirror of
https://github.com/moparisthebest/android_external_GmsLib
synced 2024-12-03 22:22:21 -05:00
Add some new classes and utilities to play-services-base
This commit is contained in:
parent
f635d6a931
commit
fa1c8c261a
@ -0,0 +1,156 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package com.google.android.gms.common.images;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import org.json.JSONArray;
|
||||
import org.microg.gms.common.Objects;
|
||||
import org.microg.safeparcel.AutoSafeParcelable;
|
||||
import org.microg.safeparcel.SafeParcelUtil;
|
||||
import org.microg.safeparcel.SafeParcelable;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public final class WebImage implements SafeParcelable {
|
||||
public static final Creator<WebImage> CREATOR = new AutoSafeParcelable.AutoCreator<>(WebImage.class);
|
||||
private final int versionCode;
|
||||
private final Uri url;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
WebImage(int versionCode, Uri url, int width, int height) {
|
||||
this.versionCode = versionCode;
|
||||
this.url = url;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public WebImage(Uri url, int width, int height) throws IllegalArgumentException {
|
||||
this(1, url, width, height);
|
||||
if(url == null) {
|
||||
throw new IllegalArgumentException("url cannot be null");
|
||||
} else if(width < 0 || height < 0) {
|
||||
throw new IllegalArgumentException("width and height must not be negative");
|
||||
}
|
||||
}
|
||||
|
||||
public WebImage(Uri url) throws IllegalArgumentException {
|
||||
this(url, 0, 0);
|
||||
}
|
||||
|
||||
public WebImage(JSONObject json) throws IllegalArgumentException {
|
||||
this(parseUrl(json), json.optInt("width", 0), json.optInt("height", 0));
|
||||
}
|
||||
|
||||
int getVersionCode() {
|
||||
return this.versionCode;
|
||||
}
|
||||
|
||||
private static Uri parseUrl(JSONObject json) {
|
||||
if(json.has("url")) {
|
||||
try {
|
||||
return Uri.parse(json.getString("url"));
|
||||
} catch (JSONException var3) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Uri getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("Image %dx%d %s", this.width, this.height, this.url.toString());
|
||||
}
|
||||
|
||||
public JSONObject toJson() {
|
||||
JSONObject var1 = new JSONObject();
|
||||
|
||||
try {
|
||||
var1.put("url", this.url.toString());
|
||||
var1.put("width", this.width);
|
||||
var1.put("height", this.height);
|
||||
} catch (JSONException var3) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if(this == other) {
|
||||
return true;
|
||||
} else if(other != null && other instanceof WebImage) {
|
||||
WebImage var2 = (WebImage)other;
|
||||
return Objects.equals(this.url, var2.url) && this.width == var2.width && this.height == var2.height;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.url, this.width, this.height);
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
SafeParcelUtil.writeObject(this, out, flags);
|
||||
}
|
||||
|
||||
public static void writeToJson(JSONObject json, List<WebImage> images) {
|
||||
if(images != null && !images.isEmpty()) {
|
||||
JSONArray array = new JSONArray();
|
||||
|
||||
for(WebImage image : images)
|
||||
array.put(image.toJson());
|
||||
|
||||
try {
|
||||
json.put("images", array);
|
||||
} catch (JSONException var5) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void parseFromJson(List<WebImage> images, JSONObject json) {
|
||||
try {
|
||||
images.clear();
|
||||
JSONArray var2 = json.getJSONArray("images");
|
||||
int var3 = var2.length();
|
||||
|
||||
for(int var4 = 0; var4 < var3; ++var4) {
|
||||
JSONObject var5 = var2.getJSONObject(var4);
|
||||
|
||||
try {
|
||||
images.add(new WebImage(var5));
|
||||
} catch (IllegalArgumentException var7) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
} catch (JSONException var8) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
package org.microg.gms.common;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by mopar on 10/1/15.
|
||||
*/
|
||||
public class Objects {
|
||||
private Objects() {
|
||||
throw new RuntimeException("no");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the arguments are equal to each other
|
||||
* and {@code false} otherwise.
|
||||
* Consequently, if both arguments are {@code null}, {@code true}
|
||||
* is returned and if exactly one argument is {@code null}, {@code
|
||||
* false} is returned. Otherwise, equality is determined by using
|
||||
* the {@link Object#equals equals} method of the first
|
||||
* argument.
|
||||
*
|
||||
* @param a an object
|
||||
* @param b an object to be compared with {@code a} for equality
|
||||
* @return {@code true} if the arguments are equal to each other
|
||||
* and {@code false} otherwise
|
||||
* @see Object#equals(Object)
|
||||
*/
|
||||
public static boolean equals(Object a, Object b) {
|
||||
return (a == b) || (a != null && a.equals(b));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash code of a non-{@code null} argument and 0 for
|
||||
* a {@code null} argument.
|
||||
*
|
||||
* @param o an object
|
||||
* @return the hash code of a non-{@code null} argument and 0 for
|
||||
* a {@code null} argument
|
||||
* @see Object#hashCode
|
||||
*/
|
||||
public static int hashCode(Object o) {
|
||||
return o != null ? o.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a hash code for a sequence of input values. The hash
|
||||
* code is generated as if all the input values were placed into an
|
||||
* array, and that array were hashed by calling {@link
|
||||
* Arrays#hashCode(Object[])}.
|
||||
* <p/>
|
||||
* <p>This method is useful for implementing {@link
|
||||
* Object#hashCode()} on objects containing multiple fields. For
|
||||
* example, if an object that has three fields, {@code x}, {@code
|
||||
* y}, and {@code z}, one could write:
|
||||
* <p/>
|
||||
* <blockquote><pre>
|
||||
* @Override public int hashCode() {
|
||||
* return Objects.hash(x, y, z);
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
* <p/>
|
||||
* <b>Warning: When a single object reference is supplied, the returned
|
||||
* value does not equal the hash code of that object reference.</b> This
|
||||
* value can be computed by calling {@link #hashCode(Object)}.
|
||||
*
|
||||
* @param values the values to be hashed
|
||||
* @return a hash value of the sequence of input values
|
||||
* @see Arrays#hashCode(Object[])
|
||||
* @see List#hashCode
|
||||
*/
|
||||
public static int hash(Object... values) {
|
||||
return Arrays.hashCode(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the specified object reference is not {@code null}. This
|
||||
* method is designed primarily for doing parameter validation in methods
|
||||
* and constructors, as demonstrated below:
|
||||
* <blockquote><pre>
|
||||
* public Foo(Bar bar) {
|
||||
* this.bar = Objects.requireNonNull(bar);
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param obj the object reference to check for nullity
|
||||
* @param <T> the type of the reference
|
||||
* @return {@code obj} if not {@code null}
|
||||
* @throws NullPointerException if {@code obj} is {@code null}
|
||||
*/
|
||||
public static <T> T requireNonNull(T obj) {
|
||||
if (obj == null)
|
||||
throw new NullPointerException();
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the specified object reference is not {@code null} and
|
||||
* throws a customized {@link NullPointerException} if it is. This method
|
||||
* is designed primarily for doing parameter validation in methods and
|
||||
* constructors with multiple parameters, as demonstrated below:
|
||||
* <blockquote><pre>
|
||||
* public Foo(Bar bar, Baz baz) {
|
||||
* this.bar = Objects.requireNonNull(bar, "bar must not be null");
|
||||
* this.baz = Objects.requireNonNull(baz, "baz must not be null");
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param obj the object reference to check for nullity
|
||||
* @param message detail message to be used in the event that a {@code
|
||||
* NullPointerException} is thrown
|
||||
* @param <T> the type of the reference
|
||||
* @return {@code obj} if not {@code null}
|
||||
* @throws NullPointerException if {@code obj} is {@code null}
|
||||
*/
|
||||
public static <T> T requireNonNull(T obj, String message) {
|
||||
if (obj == null)
|
||||
throw new NullPointerException(message);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static boolean jsonEquals(Object var0, Object var1) {
|
||||
if(var0 == null && var1 == null) {
|
||||
return true;
|
||||
} else if(var0 != null && var1 != null) {
|
||||
Object var6;
|
||||
if(var0 instanceof JSONObject && var1 instanceof JSONObject) {
|
||||
JSONObject var10 = (JSONObject)var0;
|
||||
JSONObject var11 = (JSONObject)var1;
|
||||
if(var10.length() != var11.length()) {
|
||||
return false;
|
||||
} else {
|
||||
Iterator var12 = var10.keys();
|
||||
|
||||
while(var12.hasNext()) {
|
||||
String var13 = (String)var12.next();
|
||||
if(!var11.has(var13)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
var6 = var10.get(var13);
|
||||
Object var7 = var11.get(var13);
|
||||
if(!jsonEquals(var6, var7)) {
|
||||
return false;
|
||||
}
|
||||
} catch (JSONException var8) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} else if(var0 instanceof JSONArray && var1 instanceof JSONArray) {
|
||||
JSONArray var2 = (JSONArray)var0;
|
||||
JSONArray var3 = (JSONArray)var1;
|
||||
if(var2.length() != var3.length()) {
|
||||
return false;
|
||||
} else {
|
||||
for(int var4 = 0; var4 < var2.length(); ++var4) {
|
||||
try {
|
||||
Object var5 = var2.get(var4);
|
||||
var6 = var3.get(var4);
|
||||
if(!jsonEquals(var5, var6)) {
|
||||
return false;
|
||||
}
|
||||
} catch (JSONException var9) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return var0.equals(var1);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package org.microg.gms.common.api;
|
||||
|
||||
import com.google.android.gms.common.api.PendingResult;
|
||||
import com.google.android.gms.common.api.Result;
|
||||
import com.google.android.gms.common.api.ResultCallback;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by mopar on 10/1/15.
|
||||
*/
|
||||
public class DummyPendingResult<T extends Result> implements PendingResult<T> {
|
||||
|
||||
private final T result;
|
||||
|
||||
private boolean canceled = false;
|
||||
|
||||
public DummyPendingResult(T result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T await() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T await(long time, TimeUnit unit) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResultCallback(ResultCallback<T> callback, long time, TimeUnit unit) {
|
||||
setResultCallback(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResultCallback(ResultCallback<T> callback) {
|
||||
callback.onResult(result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user