391 lines
13 KiB
Java
391 lines
13 KiB
Java
package com.google.zxing.client.android.result;
|
|
|
|
import android.app.Activity;
|
|
import android.app.AlertDialog;
|
|
import android.content.ActivityNotFoundException;
|
|
import android.content.ContentValues;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.os.Parcelable;
|
|
import android.preference.PreferenceManager;
|
|
import android.provider.ContactsContract;
|
|
import android.telephony.PhoneNumberUtils;
|
|
import android.util.Log;
|
|
import com.google.zxing.Result;
|
|
import com.google.zxing.client.android.Contents;
|
|
import com.google.zxing.client.android.LocaleManager;
|
|
import com.google.zxing.client.android.R$string;
|
|
import com.google.zxing.client.android.book.SearchBookContentsActivity;
|
|
import com.google.zxing.client.result.ParsedResult;
|
|
import com.google.zxing.client.result.ParsedResultType;
|
|
import com.google.zxing.client.result.ResultParser;
|
|
import com.ubt.jimu.blockly.command.BlocklyCommandController;
|
|
import com.unity3d.ads.metadata.MediationMetaData;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.net.URLEncoder;
|
|
import java.util.ArrayList;
|
|
import java.util.Locale;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class ResultHandler {
|
|
private static final String e = "ResultHandler";
|
|
private static final String[] f = {"home", "work", "mobile"};
|
|
private static final String[] g = {"home", "work", "mobile", "fax", "pager", "main"};
|
|
private static final String[] h = {"home", "work"};
|
|
private static final int[] i = {1, 2, 4};
|
|
private static final int[] j = {1, 3, 2, 4, 6, 12};
|
|
private static final int[] k = {1, 2};
|
|
private final ParsedResult a;
|
|
private final Activity b;
|
|
private final Result c;
|
|
private final String d;
|
|
|
|
ResultHandler(Activity activity, ParsedResult parsedResult) {
|
|
this(activity, parsedResult, null);
|
|
}
|
|
|
|
static String m(String str) {
|
|
return PhoneNumberUtils.formatNumber(str);
|
|
}
|
|
|
|
private static int n(String str) {
|
|
return a(str, h, k);
|
|
}
|
|
|
|
private static int o(String str) {
|
|
return a(str, f, i);
|
|
}
|
|
|
|
private static int p(String str) {
|
|
return a(str, g, j);
|
|
}
|
|
|
|
public abstract int a(int i2);
|
|
|
|
final void a(String[] strArr, String[] strArr2) {
|
|
a(null, null, null, null, null, strArr, strArr2, null, null, null, null, null, null, null, null, null);
|
|
}
|
|
|
|
public boolean a() {
|
|
return false;
|
|
}
|
|
|
|
final Activity b() {
|
|
return this.b;
|
|
}
|
|
|
|
public abstract void b(int i2);
|
|
|
|
public abstract int c();
|
|
|
|
final String c(String str) {
|
|
if (this.d == null) {
|
|
return str;
|
|
}
|
|
try {
|
|
str = URLEncoder.encode(str, "UTF-8");
|
|
} catch (UnsupportedEncodingException unused) {
|
|
}
|
|
String str2 = this.d;
|
|
Result result = this.c;
|
|
if (result != null) {
|
|
str2 = str2.replaceFirst("%f(?![0-9a-f])", result.a().toString());
|
|
if (str2.contains("%t")) {
|
|
str2 = str2.replace("%t", ResultParser.c(this.c).b().toString());
|
|
}
|
|
}
|
|
return str2.replace("%s", str);
|
|
}
|
|
|
|
public Integer d() {
|
|
return null;
|
|
}
|
|
|
|
final void d(String str) {
|
|
a(new Intent("android.intent.action.VIEW", Uri.parse("http://books.google." + LocaleManager.a(this.b) + "/books?vid=isbn" + str)));
|
|
}
|
|
|
|
public CharSequence e() {
|
|
return this.a.a().replace("\r", "");
|
|
}
|
|
|
|
public abstract int f();
|
|
|
|
final void f(String str) {
|
|
a(new Intent("android.intent.action.VIEW", Uri.parse("http://www.google." + LocaleManager.d(this.b) + "/m/products?q=" + str + "&source=zxing")));
|
|
}
|
|
|
|
public final ParsedResult g() {
|
|
return this.a;
|
|
}
|
|
|
|
public final ParsedResultType h() {
|
|
return this.a.b();
|
|
}
|
|
|
|
final boolean i() {
|
|
return this.d != null;
|
|
}
|
|
|
|
final void j(String str) {
|
|
a(null, null, null, null, str);
|
|
}
|
|
|
|
final void k(String str) {
|
|
b("smsto:", str);
|
|
}
|
|
|
|
final void l(String str) {
|
|
Intent intent = new Intent("android.intent.action.WEB_SEARCH");
|
|
intent.putExtra(BlocklyCommandController.QUERY, str);
|
|
a(intent);
|
|
}
|
|
|
|
ResultHandler(Activity activity, ParsedResult parsedResult, Result result) {
|
|
this.a = parsedResult;
|
|
this.b = activity;
|
|
this.c = result;
|
|
this.d = j();
|
|
}
|
|
|
|
private String j() {
|
|
String string = PreferenceManager.getDefaultSharedPreferences(this.b).getString("preferences_custom_product_search", null);
|
|
if (string == null || !string.trim().isEmpty()) {
|
|
return string;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
final void a(String[] strArr, String[] strArr2, String str, String[] strArr3, String[] strArr4, String[] strArr5, String[] strArr6, String str2, String str3, String str4, String str5, String str6, String str7, String[] strArr7, String str8, String[] strArr8) {
|
|
int n;
|
|
int o;
|
|
int p;
|
|
Intent intent = new Intent("android.intent.action.INSERT_OR_EDIT", ContactsContract.Contacts.CONTENT_URI);
|
|
intent.setType("vnd.android.cursor.item/contact");
|
|
a(intent, MediationMetaData.KEY_NAME, (strArr == null || strArr.length <= 0) ? null : strArr[0]);
|
|
a(intent, "phonetic_name", str);
|
|
if (strArr3 != null) {
|
|
int min = Math.min(strArr3.length, Contents.a.length);
|
|
for (int i2 = 0; i2 < min; i2++) {
|
|
a(intent, Contents.a[i2], strArr3[i2]);
|
|
if (strArr4 != null && i2 < strArr4.length && (p = p(strArr4[i2])) >= 0) {
|
|
intent.putExtra(Contents.b[i2], p);
|
|
}
|
|
}
|
|
}
|
|
if (strArr5 != null) {
|
|
int min2 = Math.min(strArr5.length, Contents.c.length);
|
|
for (int i3 = 0; i3 < min2; i3++) {
|
|
a(intent, Contents.c[i3], strArr5[i3]);
|
|
if (strArr6 != null && i3 < strArr6.length && (o = o(strArr6[i3])) >= 0) {
|
|
intent.putExtra(Contents.d[i3], o);
|
|
}
|
|
}
|
|
}
|
|
ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
|
|
if (strArr7 != null) {
|
|
int length = strArr7.length;
|
|
int i4 = 0;
|
|
while (true) {
|
|
if (i4 >= length) {
|
|
break;
|
|
}
|
|
String str9 = strArr7[i4];
|
|
if (str9 != null && !str9.isEmpty()) {
|
|
ContentValues contentValues = new ContentValues(2);
|
|
contentValues.put("mimetype", "vnd.android.cursor.item/website");
|
|
contentValues.put("data1", str9);
|
|
arrayList.add(contentValues);
|
|
break;
|
|
}
|
|
i4++;
|
|
}
|
|
}
|
|
if (str8 != null) {
|
|
ContentValues contentValues2 = new ContentValues(3);
|
|
contentValues2.put("mimetype", "vnd.android.cursor.item/contact_event");
|
|
contentValues2.put("data2", (Integer) 3);
|
|
contentValues2.put("data1", str8);
|
|
arrayList.add(contentValues2);
|
|
}
|
|
if (strArr2 != null) {
|
|
int length2 = strArr2.length;
|
|
int i5 = 0;
|
|
while (true) {
|
|
if (i5 >= length2) {
|
|
break;
|
|
}
|
|
String str10 = strArr2[i5];
|
|
if (str10 != null && !str10.isEmpty()) {
|
|
ContentValues contentValues3 = new ContentValues(3);
|
|
contentValues3.put("mimetype", "vnd.android.cursor.item/nickname");
|
|
contentValues3.put("data2", (Integer) 1);
|
|
contentValues3.put("data1", str10);
|
|
arrayList.add(contentValues3);
|
|
break;
|
|
}
|
|
i5++;
|
|
}
|
|
}
|
|
if (!arrayList.isEmpty()) {
|
|
intent.putParcelableArrayListExtra("data", arrayList);
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
if (str2 != null) {
|
|
sb.append('\n');
|
|
sb.append(str2);
|
|
}
|
|
if (strArr8 != null && strArr8.length >= 2) {
|
|
sb.append('\n');
|
|
sb.append(strArr8[0]);
|
|
sb.append(',');
|
|
sb.append(strArr8[1]);
|
|
}
|
|
if (sb.length() > 0) {
|
|
a(intent, "notes", sb.substring(1));
|
|
}
|
|
if (str3 == null || !str3.startsWith("xmpp:")) {
|
|
a(intent, "im_handle", str3);
|
|
} else {
|
|
intent.putExtra("im_protocol", 7);
|
|
intent.putExtra("im_handle", str3.substring(5));
|
|
}
|
|
a(intent, "postal", str4);
|
|
if (str5 != null && (n = n(str5)) >= 0) {
|
|
intent.putExtra("postal_type", n);
|
|
}
|
|
a(intent, "company", str6);
|
|
a(intent, "job_title", str7);
|
|
a(intent);
|
|
}
|
|
|
|
final void b(String[] strArr, String[] strArr2) {
|
|
a(null, null, null, strArr, strArr2, null, null, null, null, null, null, null, null, null, null, null);
|
|
}
|
|
|
|
final void g(String str) {
|
|
if (str.startsWith("HTTP://")) {
|
|
str = "http" + str.substring(4);
|
|
} else if (str.startsWith("HTTPS://")) {
|
|
str = "https" + str.substring(5);
|
|
}
|
|
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(str));
|
|
try {
|
|
a(intent);
|
|
} catch (ActivityNotFoundException unused) {
|
|
Log.w(e, "Nothing available to handle " + intent);
|
|
}
|
|
}
|
|
|
|
final void h(String str) {
|
|
Intent intent = new Intent("com.google.zxing.client.android.SEARCH_BOOK_CONTENTS");
|
|
intent.setClassName(this.b, SearchBookContentsActivity.class.getName());
|
|
a(intent, "ISBN", str);
|
|
a(intent);
|
|
}
|
|
|
|
final void i(String str) {
|
|
a(new Intent("android.intent.action.VIEW", Uri.parse("geo:0,0?q=" + Uri.encode(str))));
|
|
}
|
|
|
|
private void b(String str, String str2) {
|
|
Intent intent = new Intent("android.intent.action.SENDTO", Uri.parse(str));
|
|
a(intent, "sms_body", str2);
|
|
intent.putExtra("compose_mode", true);
|
|
a(intent);
|
|
}
|
|
|
|
final void e(String str) {
|
|
a(new Intent("android.intent.action.VIEW", Uri.parse(str)));
|
|
}
|
|
|
|
private void b(String str, String str2, String str3) {
|
|
Intent intent = new Intent("android.intent.action.SENDTO", Uri.parse(str));
|
|
if (str2 != null && !str2.isEmpty()) {
|
|
a(intent, "subject", str2);
|
|
} else {
|
|
a(intent, "subject", this.b.getString(R$string.msg_default_mms_subject));
|
|
}
|
|
a(intent, "sms_body", str3);
|
|
intent.putExtra("compose_mode", true);
|
|
a(intent);
|
|
}
|
|
|
|
final void b(String str) {
|
|
a(new Intent("android.intent.action.DIAL", Uri.parse(str)));
|
|
}
|
|
|
|
final void b(Intent intent) {
|
|
if (intent != null) {
|
|
intent.addFlags(524288);
|
|
this.b.startActivity(intent);
|
|
}
|
|
}
|
|
|
|
private static int a(String str, String[] strArr, int[] iArr) {
|
|
if (str == null) {
|
|
return -1;
|
|
}
|
|
for (int i2 = 0; i2 < strArr.length; i2++) {
|
|
String str2 = strArr[i2];
|
|
if (str.startsWith(str2) || str.startsWith(str2.toUpperCase(Locale.ENGLISH))) {
|
|
return iArr[i2];
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
final void a(String[] strArr, String[] strArr2, String[] strArr3, String str, String str2) {
|
|
Intent intent = new Intent("android.intent.action.SEND", Uri.parse("mailto:"));
|
|
if (strArr != null && strArr.length != 0) {
|
|
intent.putExtra("android.intent.extra.EMAIL", strArr);
|
|
}
|
|
if (strArr2 != null && strArr2.length != 0) {
|
|
intent.putExtra("android.intent.extra.CC", strArr2);
|
|
}
|
|
if (strArr3 != null && strArr3.length != 0) {
|
|
intent.putExtra("android.intent.extra.BCC", strArr3);
|
|
}
|
|
a(intent, "android.intent.extra.SUBJECT", str);
|
|
a(intent, "android.intent.extra.TEXT", str2);
|
|
intent.setType("text/plain");
|
|
a(intent);
|
|
}
|
|
|
|
final void a(String str, String str2) {
|
|
b("smsto:" + str, str2);
|
|
}
|
|
|
|
final void a(String str, String str2, String str3) {
|
|
b("mmsto:" + str, str2, str3);
|
|
}
|
|
|
|
final void a(String str) {
|
|
a(new Intent("android.intent.action.DIAL", Uri.parse("tel:" + str)));
|
|
}
|
|
|
|
final void a(double d, double d2) {
|
|
a(new Intent("android.intent.action.VIEW", Uri.parse("http://maps.google." + LocaleManager.c(this.b) + "/maps?f=d&daddr=" + d + ',' + d2)));
|
|
}
|
|
|
|
final void a(Intent intent) {
|
|
try {
|
|
b(intent);
|
|
} catch (ActivityNotFoundException unused) {
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this.b);
|
|
builder.setTitle(R$string.scan_name);
|
|
builder.setMessage(R$string.msg_intent_failed);
|
|
builder.setPositiveButton(R$string.button_ok, (DialogInterface.OnClickListener) null);
|
|
builder.show();
|
|
}
|
|
}
|
|
|
|
private static void a(Intent intent, String str, String str2) {
|
|
if (str2 == null || str2.isEmpty()) {
|
|
return;
|
|
}
|
|
intent.putExtra(str, str2);
|
|
}
|
|
}
|