Initial commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package com.google.zxing.client.android.result.supplement;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.TextView;
|
||||
import com.google.zxing.client.android.HttpHelper;
|
||||
import com.google.zxing.client.android.LocaleManager;
|
||||
import com.google.zxing.client.android.R$string;
|
||||
import com.google.zxing.client.android.history.HistoryManager;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class BookResultInfoRetriever extends SupplementalInfoRetriever {
|
||||
private final String f;
|
||||
private final String g;
|
||||
private final Context h;
|
||||
|
||||
BookResultInfoRetriever(TextView textView, String str, HistoryManager historyManager, Context context) {
|
||||
super(textView, historyManager);
|
||||
this.f = str;
|
||||
this.g = context.getString(R$string.msg_google_books);
|
||||
this.h = context;
|
||||
}
|
||||
|
||||
@Override // com.google.zxing.client.android.result.supplement.SupplementalInfoRetriever
|
||||
void a() throws IOException {
|
||||
JSONObject jSONObject;
|
||||
ArrayList arrayList;
|
||||
CharSequence a = HttpHelper.a("https://www.googleapis.com/books/v1/volumes?q=isbn:" + this.f, HttpHelper.ContentType.JSON);
|
||||
if (a.length() == 0) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
JSONArray optJSONArray = ((JSONObject) new JSONTokener(a.toString()).nextValue()).optJSONArray("items");
|
||||
if (optJSONArray != null) {
|
||||
if (optJSONArray.isNull(0) || (jSONObject = ((JSONObject) optJSONArray.get(0)).getJSONObject("volumeInfo")) == null) {
|
||||
return;
|
||||
}
|
||||
String optString = jSONObject.optString("title");
|
||||
String optString2 = jSONObject.optString("pageCount");
|
||||
JSONArray optJSONArray2 = jSONObject.optJSONArray("authors");
|
||||
String str = null;
|
||||
if (optJSONArray2 == null || optJSONArray2.isNull(0)) {
|
||||
arrayList = null;
|
||||
} else {
|
||||
arrayList = new ArrayList(optJSONArray2.length());
|
||||
for (int i = 0; i < optJSONArray2.length(); i++) {
|
||||
arrayList.add(optJSONArray2.getString(i));
|
||||
}
|
||||
}
|
||||
ArrayList arrayList2 = new ArrayList();
|
||||
SupplementalInfoRetriever.a(optString, arrayList2);
|
||||
SupplementalInfoRetriever.a(arrayList, arrayList2);
|
||||
if (optString2 != null && !optString2.isEmpty()) {
|
||||
str = optString2 + "pp.";
|
||||
}
|
||||
SupplementalInfoRetriever.a(str, arrayList2);
|
||||
String str2 = "http://www.google." + LocaleManager.a(this.h) + "/search?tbm=bks&source=zxing&q=";
|
||||
a(this.f, this.g, (String[]) arrayList2.toArray(SupplementalInfoRetriever.e), str2 + this.f);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package com.google.zxing.client.android.result.supplement;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Html;
|
||||
import android.widget.TextView;
|
||||
import com.google.zxing.client.android.HttpHelper;
|
||||
import com.google.zxing.client.android.LocaleManager;
|
||||
import com.google.zxing.client.android.R$string;
|
||||
import com.google.zxing.client.android.history.HistoryManager;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class ProductResultInfoRetriever extends SupplementalInfoRetriever {
|
||||
private static final Pattern[] i = {Pattern.compile(",event\\)\">([^<]+)</a></h3>.+<span class=psrp>([^<]+)</span>"), Pattern.compile("owb63p\">([^<]+).+zdi3pb\">([^<]+)")};
|
||||
private final String f;
|
||||
private final String g;
|
||||
private final Context h;
|
||||
|
||||
ProductResultInfoRetriever(TextView textView, String str, HistoryManager historyManager, Context context) {
|
||||
super(textView, historyManager);
|
||||
this.f = str;
|
||||
this.g = context.getString(R$string.msg_google_product);
|
||||
this.h = context;
|
||||
}
|
||||
|
||||
@Override // com.google.zxing.client.android.result.supplement.SupplementalInfoRetriever
|
||||
void a() throws IOException {
|
||||
String str = "https://www.google." + LocaleManager.d(this.h) + "/m/products?ie=utf8&oe=utf8&scoring=p&source=zxing&q=" + URLEncoder.encode(this.f, "UTF-8");
|
||||
CharSequence a = HttpHelper.a(str, HttpHelper.ContentType.HTML);
|
||||
for (Pattern pattern : i) {
|
||||
Matcher matcher = pattern.matcher(a);
|
||||
if (matcher.find()) {
|
||||
a(this.f, this.g, new String[]{a(matcher.group(1)), a(matcher.group(2))}, str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String a(String str) {
|
||||
return Html.fromHtml(str).toString();
|
||||
}
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
package com.google.zxing.client.android.result.supplement;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.URLSpan;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
import com.google.zxing.client.android.history.HistoryManager;
|
||||
import com.google.zxing.client.result.ISBNParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ProductParsedResult;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class SupplementalInfoRetriever extends AsyncTask<Object, Object, Object> {
|
||||
static final String[] e = new String[0];
|
||||
private final WeakReference<TextView> a;
|
||||
private final WeakReference<HistoryManager> b;
|
||||
private final Collection<Spannable> c = new ArrayList();
|
||||
private final Collection<String[]> d = new ArrayList();
|
||||
|
||||
SupplementalInfoRetriever(TextView textView, HistoryManager historyManager) {
|
||||
this.a = new WeakReference<>(textView);
|
||||
this.b = new WeakReference<>(historyManager);
|
||||
}
|
||||
|
||||
public static void a(TextView textView, ParsedResult parsedResult, HistoryManager historyManager, Context context) {
|
||||
try {
|
||||
if (parsedResult instanceof URIParsedResult) {
|
||||
new URIResultInfoRetriever(textView, (URIParsedResult) parsedResult, historyManager, context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
|
||||
new TitleRetriever(textView, (URIParsedResult) parsedResult, historyManager).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
|
||||
} else if (parsedResult instanceof ProductParsedResult) {
|
||||
new ProductResultInfoRetriever(textView, ((ProductParsedResult) parsedResult).d(), historyManager, context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
|
||||
} else if (parsedResult instanceof ISBNParsedResult) {
|
||||
String c = ((ISBNParsedResult) parsedResult).c();
|
||||
new ProductResultInfoRetriever(textView, c, historyManager, context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
|
||||
new BookResultInfoRetriever(textView, c, historyManager, context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
|
||||
}
|
||||
} catch (RejectedExecutionException unused) {
|
||||
}
|
||||
}
|
||||
|
||||
abstract void a() throws IOException;
|
||||
|
||||
@Override // android.os.AsyncTask
|
||||
public final Object doInBackground(Object... objArr) {
|
||||
try {
|
||||
a();
|
||||
return null;
|
||||
} catch (IOException e2) {
|
||||
Log.w("SupplementalInfo", e2);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.os.AsyncTask
|
||||
protected final void onPostExecute(Object obj) {
|
||||
TextView textView = this.a.get();
|
||||
if (textView != null) {
|
||||
Iterator<Spannable> it = this.c.iterator();
|
||||
while (it.hasNext()) {
|
||||
textView.append(it.next());
|
||||
}
|
||||
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
HistoryManager historyManager = this.b.get();
|
||||
if (historyManager != null) {
|
||||
for (String[] strArr : this.d) {
|
||||
historyManager.a(strArr[0], strArr[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final void a(String str, String str2, String[] strArr, String str3) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (str2 != null) {
|
||||
sb.append(str2);
|
||||
sb.append(' ');
|
||||
}
|
||||
int length = sb.length();
|
||||
boolean z = true;
|
||||
for (String str4 : strArr) {
|
||||
if (z) {
|
||||
sb.append(str4);
|
||||
z = false;
|
||||
} else {
|
||||
sb.append(" [");
|
||||
sb.append(str4);
|
||||
sb.append(']');
|
||||
}
|
||||
}
|
||||
int length2 = sb.length();
|
||||
String sb2 = sb.toString();
|
||||
SpannableString spannableString = new SpannableString(sb2 + "\n\n");
|
||||
if (str3 != null) {
|
||||
if (str3.startsWith("HTTP://")) {
|
||||
str3 = "http" + str3.substring(4);
|
||||
} else if (str3.startsWith("HTTPS://")) {
|
||||
str3 = "https" + str3.substring(5);
|
||||
}
|
||||
spannableString.setSpan(new URLSpan(str3), length, length2, 33);
|
||||
}
|
||||
this.c.add(spannableString);
|
||||
this.d.add(new String[]{str, sb2});
|
||||
}
|
||||
|
||||
static void a(String str, Collection<String> collection) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
collection.add(str);
|
||||
}
|
||||
|
||||
static void a(Collection<String> collection, Collection<String> collection2) {
|
||||
if (collection == null || collection.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
boolean z = true;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String str : collection) {
|
||||
if (z) {
|
||||
z = false;
|
||||
} else {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(str);
|
||||
}
|
||||
collection2.add(sb.toString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package com.google.zxing.client.android.result.supplement;
|
||||
|
||||
import android.text.Html;
|
||||
import android.widget.TextView;
|
||||
import com.google.zxing.client.android.HttpHelper;
|
||||
import com.google.zxing.client.android.history.HistoryManager;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
import com.ubt.jimu.base.util.FileUtil;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class TitleRetriever extends SupplementalInfoRetriever {
|
||||
private static final Pattern g = Pattern.compile("<title>([^<]+)");
|
||||
private final String f;
|
||||
|
||||
TitleRetriever(TextView textView, URIParsedResult uRIParsedResult, HistoryManager historyManager) {
|
||||
super(textView, historyManager);
|
||||
this.f = uRIParsedResult.c();
|
||||
}
|
||||
|
||||
@Override // com.google.zxing.client.android.result.supplement.SupplementalInfoRetriever
|
||||
void a() {
|
||||
String group;
|
||||
try {
|
||||
CharSequence a = HttpHelper.a(this.f, HttpHelper.ContentType.HTML, FileUtil.ZIP_BUFFER_SIZE);
|
||||
if (a == null || a.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
Matcher matcher = g.matcher(a);
|
||||
if (!matcher.find() || (group = matcher.group(1)) == null || group.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String obj = Html.fromHtml(group).toString();
|
||||
if (obj.length() > 100) {
|
||||
obj = obj.substring(0, 100) + "...";
|
||||
}
|
||||
String str = this.f;
|
||||
a(str, (String) null, new String[]{obj}, str);
|
||||
} catch (IOException unused) {
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package com.google.zxing.client.android.result.supplement;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.TextView;
|
||||
import com.google.zxing.client.android.HttpHelper;
|
||||
import com.google.zxing.client.android.R$string;
|
||||
import com.google.zxing.client.android.history.HistoryManager;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class URIResultInfoRetriever extends SupplementalInfoRetriever {
|
||||
private final URIParsedResult f;
|
||||
private final String g;
|
||||
|
||||
URIResultInfoRetriever(TextView textView, URIParsedResult uRIParsedResult, HistoryManager historyManager, Context context) {
|
||||
super(textView, historyManager);
|
||||
this.g = context.getString(R$string.msg_redirect);
|
||||
this.f = uRIParsedResult;
|
||||
}
|
||||
|
||||
@Override // com.google.zxing.client.android.result.supplement.SupplementalInfoRetriever
|
||||
void a() throws IOException {
|
||||
try {
|
||||
URI uri = new URI(this.f.c());
|
||||
URI a = HttpHelper.a(uri);
|
||||
URI uri2 = uri;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
int i2 = i + 1;
|
||||
if (i >= 5 || uri2.equals(a)) {
|
||||
return;
|
||||
}
|
||||
a(this.f.a(), (String) null, new String[]{this.g + " : " + a}, a.toString());
|
||||
uri2 = a;
|
||||
a = HttpHelper.a(a);
|
||||
i = i2;
|
||||
}
|
||||
} catch (URISyntaxException unused) {
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user