Initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.google.zxing.client.android.book;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import com.google.zxing.client.android.LocaleManager;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class BrowseBookListener implements AdapterView.OnItemClickListener {
|
||||
private final SearchBookContentsActivity a;
|
||||
private final List<SearchBookContentsResult> b;
|
||||
|
||||
BrowseBookListener(SearchBookContentsActivity searchBookContentsActivity, List<SearchBookContentsResult> list) {
|
||||
this.a = searchBookContentsActivity;
|
||||
this.b = list;
|
||||
}
|
||||
|
||||
@Override // android.widget.AdapterView.OnItemClickListener
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
|
||||
int i2;
|
||||
if (i >= 1 && (i2 = i - 1) < this.b.size()) {
|
||||
String a = this.b.get(i2).a();
|
||||
String e = SearchBookContentsResult.e();
|
||||
if (!LocaleManager.a(this.a.a()) || a.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String a2 = this.a.a();
|
||||
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://books.google." + LocaleManager.a(this.a) + "/books?id=" + a2.substring(a2.indexOf(61) + 1) + "&pg=" + a + "&vq=" + e));
|
||||
intent.addFlags(524288);
|
||||
this.a.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,218 @@
|
||||
package com.google.zxing.client.android.book;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
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$id;
|
||||
import com.google.zxing.client.android.R$layout;
|
||||
import com.google.zxing.client.android.R$string;
|
||||
import com.tencent.bugly.Bugly;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class SearchBookContentsActivity extends Activity {
|
||||
private static final String i = SearchBookContentsActivity.class.getSimpleName();
|
||||
private static final Pattern j = Pattern.compile("<.*?>");
|
||||
private static final Pattern k = Pattern.compile("<");
|
||||
private static final Pattern l = Pattern.compile(">");
|
||||
private static final Pattern m = Pattern.compile("'");
|
||||
private static final Pattern n = Pattern.compile(""");
|
||||
private String a;
|
||||
private EditText b;
|
||||
private View c;
|
||||
private ListView d;
|
||||
private TextView e;
|
||||
private AsyncTask<String, ?, ?> f;
|
||||
private final View.OnClickListener g = new View.OnClickListener() { // from class: com.google.zxing.client.android.book.SearchBookContentsActivity.1
|
||||
@Override // android.view.View.OnClickListener
|
||||
public void onClick(View view) {
|
||||
SearchBookContentsActivity.this.h();
|
||||
}
|
||||
};
|
||||
private final View.OnKeyListener h = new View.OnKeyListener() { // from class: com.google.zxing.client.android.book.SearchBookContentsActivity.2
|
||||
@Override // android.view.View.OnKeyListener
|
||||
public boolean onKey(View view, int i2, KeyEvent keyEvent) {
|
||||
if (i2 != 66 || keyEvent.getAction() != 0) {
|
||||
return false;
|
||||
}
|
||||
SearchBookContentsActivity.this.h();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void h() {
|
||||
String obj = this.b.getText().toString();
|
||||
if (obj == null || obj.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
AsyncTask<String, ?, ?> asyncTask = this.f;
|
||||
if (asyncTask != null) {
|
||||
asyncTask.cancel(true);
|
||||
}
|
||||
this.f = new NetworkTask();
|
||||
this.f.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, obj, this.a);
|
||||
this.e.setText(R$string.msg_sbc_searching_book);
|
||||
this.d.setAdapter((ListAdapter) null);
|
||||
this.b.setEnabled(false);
|
||||
this.c.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override // android.app.Activity
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
Intent intent = getIntent();
|
||||
if (intent == null || !"com.google.zxing.client.android.SEARCH_BOOK_CONTENTS".equals(intent.getAction())) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
this.a = intent.getStringExtra("ISBN");
|
||||
if (LocaleManager.a(this.a)) {
|
||||
setTitle(getString(R$string.sbc_name));
|
||||
} else {
|
||||
setTitle(getString(R$string.sbc_name) + ": ISBN " + this.a);
|
||||
}
|
||||
setContentView(R$layout.search_book_contents);
|
||||
this.b = (EditText) findViewById(R$id.query_text_view);
|
||||
String stringExtra = intent.getStringExtra("QUERY");
|
||||
if (stringExtra != null && !stringExtra.isEmpty()) {
|
||||
this.b.setText(stringExtra);
|
||||
}
|
||||
this.b.setOnKeyListener(this.h);
|
||||
this.c = findViewById(R$id.query_button);
|
||||
this.c.setOnClickListener(this.g);
|
||||
this.d = (ListView) findViewById(R$id.result_list_view);
|
||||
this.e = (TextView) LayoutInflater.from(this).inflate(R$layout.search_book_contents_header, (ViewGroup) this.d, false);
|
||||
this.d.addHeaderView(this.e);
|
||||
}
|
||||
|
||||
@Override // android.app.Activity
|
||||
protected void onPause() {
|
||||
AsyncTask<String, ?, ?> asyncTask = this.f;
|
||||
if (asyncTask != null) {
|
||||
asyncTask.cancel(true);
|
||||
this.f = null;
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override // android.app.Activity
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
this.b.selectAll();
|
||||
}
|
||||
|
||||
String a() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
private final class NetworkTask extends AsyncTask<String, Object, JSONObject> {
|
||||
private NetworkTask() {
|
||||
}
|
||||
|
||||
private void b(JSONObject jSONObject) {
|
||||
try {
|
||||
int i = jSONObject.getInt("number_of_results");
|
||||
SearchBookContentsActivity.this.e.setText(SearchBookContentsActivity.this.getString(R$string.msg_sbc_results) + " : " + i);
|
||||
if (i <= 0) {
|
||||
if (Bugly.SDK_IS_DEV.equals(jSONObject.optString("searchable"))) {
|
||||
SearchBookContentsActivity.this.e.setText(R$string.msg_sbc_book_not_searchable);
|
||||
}
|
||||
SearchBookContentsActivity.this.d.setAdapter((ListAdapter) null);
|
||||
return;
|
||||
}
|
||||
JSONArray jSONArray = jSONObject.getJSONArray("search_results");
|
||||
SearchBookContentsResult.a(SearchBookContentsActivity.this.b.getText().toString());
|
||||
ArrayList arrayList = new ArrayList(i);
|
||||
for (int i2 = 0; i2 < i; i2++) {
|
||||
arrayList.add(c(jSONArray.getJSONObject(i2)));
|
||||
}
|
||||
SearchBookContentsActivity.this.d.setOnItemClickListener(new BrowseBookListener(SearchBookContentsActivity.this, arrayList));
|
||||
SearchBookContentsActivity.this.d.setAdapter((ListAdapter) new SearchBookContentsAdapter(SearchBookContentsActivity.this, arrayList));
|
||||
} catch (JSONException e) {
|
||||
Log.w(SearchBookContentsActivity.i, "Bad JSON from book search", e);
|
||||
SearchBookContentsActivity.this.d.setAdapter((ListAdapter) null);
|
||||
SearchBookContentsActivity.this.e.setText(R$string.msg_sbc_failed);
|
||||
}
|
||||
}
|
||||
|
||||
private SearchBookContentsResult c(JSONObject jSONObject) {
|
||||
String str;
|
||||
String str2;
|
||||
boolean z = false;
|
||||
try {
|
||||
String string = jSONObject.getString("page_id");
|
||||
String optString = jSONObject.optString("page_number");
|
||||
String optString2 = jSONObject.optString("snippet_text");
|
||||
if (optString == null || optString.isEmpty()) {
|
||||
str = "";
|
||||
} else {
|
||||
str = SearchBookContentsActivity.this.getString(R$string.msg_sbc_page) + ' ' + optString;
|
||||
}
|
||||
if (optString2 != null && !optString2.isEmpty()) {
|
||||
z = true;
|
||||
}
|
||||
if (z) {
|
||||
str2 = SearchBookContentsActivity.n.matcher(SearchBookContentsActivity.m.matcher(SearchBookContentsActivity.l.matcher(SearchBookContentsActivity.k.matcher(SearchBookContentsActivity.j.matcher(optString2).replaceAll("")).replaceAll("<")).replaceAll(">")).replaceAll("'")).replaceAll("\"");
|
||||
} else {
|
||||
str2 = '(' + SearchBookContentsActivity.this.getString(R$string.msg_sbc_snippet_unavailable) + ')';
|
||||
}
|
||||
return new SearchBookContentsResult(string, str, str2, z);
|
||||
} catch (JSONException e) {
|
||||
Log.w(SearchBookContentsActivity.i, e);
|
||||
return new SearchBookContentsResult(SearchBookContentsActivity.this.getString(R$string.msg_sbc_no_page_returned), "", "", false);
|
||||
}
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: protected */
|
||||
@Override // android.os.AsyncTask
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public JSONObject doInBackground(String... strArr) {
|
||||
String str;
|
||||
try {
|
||||
String str2 = strArr[0];
|
||||
String str3 = strArr[1];
|
||||
if (LocaleManager.a(str3)) {
|
||||
str = "http://www.google.com/books?id=" + str3.substring(str3.indexOf(61) + 1) + "&jscmd=SearchWithinVolume2&q=" + str2;
|
||||
} else {
|
||||
str = "http://www.google.com/books?vid=isbn" + str3 + "&jscmd=SearchWithinVolume2&q=" + str2;
|
||||
}
|
||||
return new JSONObject(HttpHelper.a(str, HttpHelper.ContentType.JSON).toString());
|
||||
} catch (IOException | JSONException e) {
|
||||
Log.w(SearchBookContentsActivity.i, "Error accessing book search", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: protected */
|
||||
@Override // android.os.AsyncTask
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void onPostExecute(JSONObject jSONObject) {
|
||||
if (jSONObject == null) {
|
||||
SearchBookContentsActivity.this.e.setText(R$string.msg_sbc_failed);
|
||||
} else {
|
||||
b(jSONObject);
|
||||
}
|
||||
SearchBookContentsActivity.this.b.setEnabled(true);
|
||||
SearchBookContentsActivity.this.b.selectAll();
|
||||
SearchBookContentsActivity.this.c.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.google.zxing.client.android.book;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import com.google.zxing.client.android.R$layout;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class SearchBookContentsAdapter extends ArrayAdapter<SearchBookContentsResult> {
|
||||
SearchBookContentsAdapter(Context context, List<SearchBookContentsResult> list) {
|
||||
super(context, R$layout.search_book_contents_list_item, 0, list);
|
||||
}
|
||||
|
||||
@Override // android.widget.ArrayAdapter, android.widget.Adapter
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
View view2;
|
||||
SearchBookContentsListItem searchBookContentsListItem;
|
||||
if (view != null) {
|
||||
boolean z = view instanceof SearchBookContentsListItem;
|
||||
view2 = view;
|
||||
if (z) {
|
||||
searchBookContentsListItem = (SearchBookContentsListItem) view;
|
||||
}
|
||||
return view2;
|
||||
}
|
||||
searchBookContentsListItem = (SearchBookContentsListItem) LayoutInflater.from(getContext()).inflate(R$layout.search_book_contents_list_item, viewGroup, false);
|
||||
searchBookContentsListItem.set(getItem(i));
|
||||
view2 = searchBookContentsListItem;
|
||||
return view2;
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
package com.google.zxing.client.android.book;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.google.zxing.client.android.R$id;
|
||||
import java.util.Locale;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class SearchBookContentsListItem extends LinearLayout {
|
||||
private TextView a;
|
||||
private TextView b;
|
||||
|
||||
SearchBookContentsListItem(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override // android.view.View
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
this.a = (TextView) findViewById(R$id.page_number_view);
|
||||
this.b = (TextView) findViewById(R$id.snippet_view);
|
||||
}
|
||||
|
||||
public void set(SearchBookContentsResult searchBookContentsResult) {
|
||||
this.a.setText(searchBookContentsResult.b());
|
||||
String c = searchBookContentsResult.c();
|
||||
if (c.isEmpty()) {
|
||||
this.b.setText("");
|
||||
return;
|
||||
}
|
||||
if (!searchBookContentsResult.d()) {
|
||||
this.b.setText(c);
|
||||
return;
|
||||
}
|
||||
String lowerCase = SearchBookContentsResult.e().toLowerCase(Locale.getDefault());
|
||||
String lowerCase2 = c.toLowerCase(Locale.getDefault());
|
||||
SpannableString spannableString = new SpannableString(c);
|
||||
StyleSpan styleSpan = new StyleSpan(1);
|
||||
int length = lowerCase.length();
|
||||
int i = 0;
|
||||
while (true) {
|
||||
int indexOf = lowerCase2.indexOf(lowerCase, i);
|
||||
if (indexOf < 0) {
|
||||
this.b.setText(spannableString);
|
||||
return;
|
||||
} else {
|
||||
int i2 = indexOf + length;
|
||||
spannableString.setSpan(styleSpan, indexOf, i2, 0);
|
||||
i = i2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SearchBookContentsListItem(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.google.zxing.client.android.book;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class SearchBookContentsResult {
|
||||
private static String e;
|
||||
private final String a;
|
||||
private final String b;
|
||||
private final String c;
|
||||
private final boolean d;
|
||||
|
||||
SearchBookContentsResult(String str, String str2, String str3, boolean z) {
|
||||
this.a = str;
|
||||
this.b = str2;
|
||||
this.c = str3;
|
||||
this.d = z;
|
||||
}
|
||||
|
||||
public static void a(String str) {
|
||||
e = str;
|
||||
}
|
||||
|
||||
public static String e() {
|
||||
return e;
|
||||
}
|
||||
|
||||
public String b() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public String c() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public boolean d() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
public String a() {
|
||||
return this.a;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user