186 lines
6.7 KiB
Java
186 lines
6.7 KiB
Java
package com.google.zxing.client.android.encode;
|
|
|
|
import android.app.Activity;
|
|
import android.app.AlertDialog;
|
|
import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Point;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.Environment;
|
|
import android.util.Log;
|
|
import android.view.Display;
|
|
import android.view.Menu;
|
|
import android.view.MenuItem;
|
|
import android.view.WindowManager;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
import com.google.zxing.WriterException;
|
|
import com.google.zxing.client.android.FinishListener;
|
|
import com.google.zxing.client.android.R$id;
|
|
import com.google.zxing.client.android.R$layout;
|
|
import com.google.zxing.client.android.R$menu;
|
|
import com.google.zxing.client.android.R$string;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.regex.Pattern;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class EncodeActivity extends Activity {
|
|
private static final String b = EncodeActivity.class.getSimpleName();
|
|
private static final Pattern c = Pattern.compile("[^A-Za-z0-9]");
|
|
private QRCodeEncoder a;
|
|
|
|
private void a() {
|
|
QRCodeEncoder qRCodeEncoder = this.a;
|
|
if (qRCodeEncoder == null) {
|
|
Log.w(b, "No existing barcode to send?");
|
|
return;
|
|
}
|
|
String b2 = qRCodeEncoder.b();
|
|
if (b2 == null) {
|
|
Log.w(b, "No existing barcode to send?");
|
|
return;
|
|
}
|
|
try {
|
|
Bitmap a = qRCodeEncoder.a();
|
|
if (a == null) {
|
|
return;
|
|
}
|
|
File file = new File(new File(Environment.getExternalStorageDirectory(), "BarcodeScanner"), "Barcodes");
|
|
if (!file.exists() && !file.mkdirs()) {
|
|
Log.w(b, "Couldn't make dir " + file);
|
|
a(R$string.msg_unmount_usb);
|
|
return;
|
|
}
|
|
File file2 = new File(file, ((Object) a(b2)) + ".png");
|
|
if (!file2.delete()) {
|
|
Log.w(b, "Could not delete " + file2);
|
|
}
|
|
try {
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file2);
|
|
try {
|
|
a.compress(Bitmap.CompressFormat.PNG, 0, fileOutputStream);
|
|
fileOutputStream.close();
|
|
Intent intent = new Intent("android.intent.action.SEND", Uri.parse("mailto:"));
|
|
intent.putExtra("android.intent.extra.SUBJECT", getString(R$string.scan_name) + " - " + qRCodeEncoder.d());
|
|
intent.putExtra("android.intent.extra.TEXT", b2);
|
|
intent.putExtra("android.intent.extra.STREAM", Uri.parse("file://" + file2.getAbsolutePath()));
|
|
intent.setType("image/png");
|
|
intent.addFlags(524288);
|
|
startActivity(Intent.createChooser(intent, null));
|
|
} finally {
|
|
}
|
|
} catch (IOException e) {
|
|
Log.w(b, "Couldn't access file " + file2 + " due to " + e);
|
|
a(R$string.msg_unmount_usb);
|
|
}
|
|
} catch (WriterException e2) {
|
|
Log.w(b, e2);
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
Intent intent = getIntent();
|
|
if (intent == null) {
|
|
finish();
|
|
return;
|
|
}
|
|
String action = intent.getAction();
|
|
if ("com.google.zxing.client.android.ENCODE".equals(action) || "android.intent.action.SEND".equals(action)) {
|
|
setContentView(R$layout.encode);
|
|
} else {
|
|
finish();
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
getMenuInflater().inflate(R$menu.encode, menu);
|
|
QRCodeEncoder qRCodeEncoder = this.a;
|
|
int i = qRCodeEncoder != null && qRCodeEncoder.e() ? R$string.menu_encode_mecard : R$string.menu_encode_vcard;
|
|
MenuItem findItem = menu.findItem(R$id.menu_encode);
|
|
findItem.setTitle(i);
|
|
Intent intent = getIntent();
|
|
if (intent != null) {
|
|
findItem.setVisible("CONTACT_TYPE".equals(intent.getStringExtra("ENCODE_TYPE")));
|
|
}
|
|
return super.onCreateOptionsMenu(menu);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public boolean onOptionsItemSelected(MenuItem menuItem) {
|
|
Intent intent;
|
|
int itemId = menuItem.getItemId();
|
|
if (itemId == R$id.menu_share) {
|
|
a();
|
|
return true;
|
|
}
|
|
if (itemId != R$id.menu_encode || (intent = getIntent()) == null) {
|
|
return false;
|
|
}
|
|
intent.putExtra("USE_VCARD", !this.a.e());
|
|
intent.addFlags(67108864);
|
|
startActivity(intent);
|
|
finish();
|
|
return true;
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onResume() {
|
|
super.onResume();
|
|
Display defaultDisplay = ((WindowManager) getSystemService("window")).getDefaultDisplay();
|
|
Point point = new Point();
|
|
defaultDisplay.getSize(point);
|
|
int i = point.x;
|
|
int i2 = point.y;
|
|
if (i >= i2) {
|
|
i = i2;
|
|
}
|
|
int i3 = (i * 7) / 8;
|
|
Intent intent = getIntent();
|
|
if (intent == null) {
|
|
return;
|
|
}
|
|
try {
|
|
this.a = new QRCodeEncoder(this, intent, i3, intent.getBooleanExtra("USE_VCARD", false));
|
|
Bitmap a = this.a.a();
|
|
if (a == null) {
|
|
Log.w(b, "Could not encode barcode");
|
|
a(R$string.msg_encode_contents_failed);
|
|
this.a = null;
|
|
return;
|
|
}
|
|
((ImageView) findViewById(R$id.image_view)).setImageBitmap(a);
|
|
TextView textView = (TextView) findViewById(R$id.contents_text_view);
|
|
if (intent.getBooleanExtra("ENCODE_SHOW_CONTENTS", true)) {
|
|
textView.setText(this.a.c());
|
|
setTitle(this.a.d());
|
|
} else {
|
|
textView.setText("");
|
|
setTitle("");
|
|
}
|
|
} catch (WriterException e) {
|
|
Log.w(b, "Could not encode barcode", e);
|
|
a(R$string.msg_encode_contents_failed);
|
|
this.a = null;
|
|
}
|
|
}
|
|
|
|
private static CharSequence a(CharSequence charSequence) {
|
|
String replaceAll = c.matcher(charSequence).replaceAll("_");
|
|
return replaceAll.length() > 24 ? replaceAll.substring(0, 24) : replaceAll;
|
|
}
|
|
|
|
private void a(int i) {
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
builder.setMessage(i);
|
|
builder.setPositiveButton(R$string.button_ok, new FinishListener(this));
|
|
builder.setOnCancelListener(new FinishListener(this));
|
|
builder.show();
|
|
}
|
|
}
|