mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Issue 821: Add text box for encoding arbitrary QR Code contents.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1766 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
66836c74f9
commit
75cc7fe591
|
@ -21,7 +21,7 @@
|
|||
android:gravity="center"
|
||||
android:background="@color/share_view"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dip">
|
||||
android:padding="8dip">
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
|
@ -29,13 +29,14 @@
|
|||
android:textColor="@color/share_text"
|
||||
android:textSize="18sp"
|
||||
android:text="@string/msg_share_explanation"
|
||||
android:paddingBottom="24dip"/>
|
||||
android:paddingBottom="12dip"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/share_view"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="12dip">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -50,12 +51,12 @@
|
|||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button android:id="@+id/app_button"
|
||||
<Button android:id="@+id/share_app_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_share_app"/>
|
||||
|
||||
<Button android:id="@+id/contact_button"
|
||||
<Button android:id="@+id/share_contact_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_share_contact"/>
|
||||
|
@ -68,12 +69,12 @@
|
|||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button android:id="@+id/bookmark_button"
|
||||
<Button android:id="@+id/share_bookmark_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_share_bookmark"/>
|
||||
|
||||
<Button android:id="@+id/clipboard_button"
|
||||
<Button android:id="@+id/share_clipboard_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_share_clipboard"/>
|
||||
|
@ -82,4 +83,12 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<EditText android:id="@+id/share_text_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:hint="@string/msg_share_text"
|
||||
android:singleLine="true"
|
||||
android:selectAllOnFocus="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
android:layout_height="fill_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dip">
|
||||
android:padding="8dip">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -40,14 +40,14 @@
|
|||
android:textColor="@color/share_text"
|
||||
android:textSize="18sp"
|
||||
android:text="@string/msg_share_explanation"
|
||||
android:paddingBottom="24dip"/>
|
||||
android:paddingBottom="8dip"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/share_via_barcode"
|
||||
android:paddingBottom="24dip"/>
|
||||
android:paddingBottom="8dip"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
|
@ -55,13 +55,13 @@
|
|||
android:orientation="horizontal"
|
||||
android:paddingBottom="8dip">
|
||||
|
||||
<Button android:id="@+id/app_button"
|
||||
<Button android:id="@+id/share_app_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/button_share_app"/>
|
||||
|
||||
<Button android:id="@+id/bookmark_button"
|
||||
<Button android:id="@+id/share_bookmark_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
@ -72,15 +72,16 @@
|
|||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="8dip">
|
||||
|
||||
<Button android:id="@+id/contact_button"
|
||||
<Button android:id="@+id/share_contact_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/button_share_contact"/>
|
||||
|
||||
<Button android:id="@+id/clipboard_button"
|
||||
<Button android:id="@+id/share_clipboard_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
@ -88,6 +89,14 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<EditText android:id="@+id/share_text_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:hint="@string/msg_share_text"
|
||||
android:singleLine="true"
|
||||
android:selectAllOnFocus="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
<string name="msg_sbc_unknown_page">Unknown page</string>
|
||||
<string name="msg_share_explanation">You can share data by displaying a barcode on your screen and scanning it with another phone.</string>
|
||||
<string name="msg_share_subject_line">Here are the contents of a barcode I scanned</string>
|
||||
<string name="msg_share_text">Or type some text and press Enter</string>
|
||||
<string name="msg_unmount_usb">Sorry, the SD card is not accessible.</string>
|
||||
<string name="preferences_actions_title">When a barcode is found\u2026</string>
|
||||
<string name="preferences_bulk_mode_summary">Scan and save many barcodes continuously</string>
|
||||
|
|
|
@ -100,7 +100,7 @@ public final class SearchBookContentsActivity extends Activity {
|
|||
|
||||
private final View.OnKeyListener keyListener = new View.OnKeyListener() {
|
||||
public boolean onKey(View view, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
launchSearch();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -16,23 +16,26 @@
|
|||
|
||||
package com.google.zxing.client.android.share;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.client.android.Contents;
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.google.zxing.client.android.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.Browser;
|
||||
import android.provider.Contacts;
|
||||
import android.provider.BaseColumns;
|
||||
import android.text.ClipboardManager;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.google.zxing.client.android.Contents;
|
||||
import com.google.zxing.client.android.R;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Barcode Scanner can share data like contacts and bookmarks by displaying a QR Code on screen,
|
||||
|
@ -98,26 +101,44 @@ public final class ShareActivity extends Activity {
|
|||
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
// Should always be true, because we grey out the clipboard button in onResume() if it's empty
|
||||
if (clipboard.hasText()) {
|
||||
Intent intent = new Intent(Intents.Encode.ACTION);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
|
||||
intent.putExtra(Intents.Encode.DATA, clipboard.getText().toString());
|
||||
intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
|
||||
startActivity(intent);
|
||||
launchSearch(clipboard.getText().toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final View.OnKeyListener textListener = new View.OnKeyListener() {
|
||||
public boolean onKey(View view, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
String text = ((TextView) view).getText().toString();
|
||||
if (text != null && text.length() > 0) {
|
||||
launchSearch(text);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private void launchSearch(String text) {
|
||||
Intent intent = new Intent(Intents.Encode.ACTION);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
|
||||
intent.putExtra(Intents.Encode.DATA, text);
|
||||
intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.share);
|
||||
|
||||
findViewById(R.id.contact_button).setOnClickListener(contactListener);
|
||||
findViewById(R.id.bookmark_button).setOnClickListener(bookmarkListener);
|
||||
findViewById(R.id.app_button).setOnClickListener(appListener);
|
||||
clipboardButton = (Button) findViewById(R.id.clipboard_button);
|
||||
findViewById(R.id.share_contact_button).setOnClickListener(contactListener);
|
||||
findViewById(R.id.share_bookmark_button).setOnClickListener(bookmarkListener);
|
||||
findViewById(R.id.share_app_button).setOnClickListener(appListener);
|
||||
clipboardButton = (Button) findViewById(R.id.share_clipboard_button);
|
||||
clipboardButton.setOnClickListener(clipboardListener);
|
||||
findViewById(R.id.share_text_view).setOnKeyListener(textListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -151,7 +172,7 @@ public final class ShareActivity extends Activity {
|
|||
}
|
||||
|
||||
private void showTextAsBarcode(String text) {
|
||||
Log.i(TAG, "Showing text as barcode: " + text);
|
||||
Log.i(TAG, "Showing text as barcode: " + text);
|
||||
if (text == null) {
|
||||
return; // Show error?
|
||||
}
|
||||
|
@ -233,7 +254,7 @@ public final class ShareActivity extends Activity {
|
|||
}
|
||||
|
||||
Intent intent = new Intent(Intents.Encode.ACTION);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.putExtra(Intents.Encode.TYPE, Contents.Type.CONTACT);
|
||||
intent.putExtra(Intents.Encode.DATA, bundle);
|
||||
intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
|
||||
|
|
Loading…
Reference in a new issue