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:gravity="center"
|
||||||
android:background="@color/share_view"
|
android:background="@color/share_view"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dip">
|
android:padding="8dip">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
@ -29,13 +29,14 @@
|
||||||
android:textColor="@color/share_text"
|
android:textColor="@color/share_text"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:text="@string/msg_share_explanation"
|
android:text="@string/msg_share_explanation"
|
||||||
android:paddingBottom="24dip"/>
|
android:paddingBottom="12dip"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/share_view"
|
android:background="@color/share_view"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal"
|
||||||
|
android:paddingBottom="12dip">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -50,12 +51,12 @@
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<Button android:id="@+id/app_button"
|
<Button android:id="@+id/share_app_button"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/button_share_app"/>
|
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_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/button_share_contact"/>
|
android:text="@string/button_share_contact"/>
|
||||||
|
@ -68,12 +69,12 @@
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<Button android:id="@+id/bookmark_button"
|
<Button android:id="@+id/share_bookmark_button"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/button_share_bookmark"/>
|
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_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/button_share_clipboard"/>
|
android:text="@string/button_share_clipboard"/>
|
||||||
|
@ -82,4 +83,12 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</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>
|
</LinearLayout>
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dip">
|
android:padding="8dip">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -40,14 +40,14 @@
|
||||||
android:textColor="@color/share_text"
|
android:textColor="@color/share_text"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:text="@string/msg_share_explanation"
|
android:text="@string/msg_share_explanation"
|
||||||
android:paddingBottom="24dip"/>
|
android:paddingBottom="8dip"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:scaleType="center"
|
android:scaleType="center"
|
||||||
android:src="@drawable/share_via_barcode"
|
android:src="@drawable/share_via_barcode"
|
||||||
android:paddingBottom="24dip"/>
|
android:paddingBottom="8dip"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
@ -55,13 +55,13 @@
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingBottom="8dip">
|
android:paddingBottom="8dip">
|
||||||
|
|
||||||
<Button android:id="@+id/app_button"
|
<Button android:id="@+id/share_app_button"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/button_share_app"/>
|
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_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
@ -72,15 +72,16 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
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_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/button_share_contact"/>
|
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_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
@ -88,6 +89,14 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</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>
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
<string name="msg_sbc_unknown_page">Unknown page</string>
|
<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_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_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="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_actions_title">When a barcode is found\u2026</string>
|
||||||
<string name="preferences_bulk_mode_summary">Scan and save many barcodes continuously</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() {
|
private final View.OnKeyListener keyListener = new View.OnKeyListener() {
|
||||||
public boolean onKey(View view, int keyCode, KeyEvent event) {
|
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();
|
launchSearch();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,23 +16,26 @@
|
||||||
|
|
||||||
package com.google.zxing.client.android.share;
|
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.app.Activity;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.BaseColumns;
|
||||||
import android.provider.Browser;
|
import android.provider.Browser;
|
||||||
import android.provider.Contacts;
|
import android.provider.Contacts;
|
||||||
import android.provider.BaseColumns;
|
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import com.google.zxing.BarcodeFormat;
|
import android.widget.TextView;
|
||||||
import com.google.zxing.client.android.Intents;
|
|
||||||
import com.google.zxing.client.android.Contents;
|
|
||||||
import com.google.zxing.client.android.R;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Barcode Scanner can share data like contacts and bookmarks by displaying a QR Code on screen,
|
* 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);
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
// Should always be true, because we grey out the clipboard button in onResume() if it's empty
|
// Should always be true, because we grey out the clipboard button in onResume() if it's empty
|
||||||
if (clipboard.hasText()) {
|
if (clipboard.hasText()) {
|
||||||
Intent intent = new Intent(Intents.Encode.ACTION);
|
launchSearch(clipboard.getText().toString());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
setContentView(R.layout.share);
|
setContentView(R.layout.share);
|
||||||
|
|
||||||
findViewById(R.id.contact_button).setOnClickListener(contactListener);
|
findViewById(R.id.share_contact_button).setOnClickListener(contactListener);
|
||||||
findViewById(R.id.bookmark_button).setOnClickListener(bookmarkListener);
|
findViewById(R.id.share_bookmark_button).setOnClickListener(bookmarkListener);
|
||||||
findViewById(R.id.app_button).setOnClickListener(appListener);
|
findViewById(R.id.share_app_button).setOnClickListener(appListener);
|
||||||
clipboardButton = (Button) findViewById(R.id.clipboard_button);
|
clipboardButton = (Button) findViewById(R.id.share_clipboard_button);
|
||||||
clipboardButton.setOnClickListener(clipboardListener);
|
clipboardButton.setOnClickListener(clipboardListener);
|
||||||
|
findViewById(R.id.share_text_view).setOnKeyListener(textListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue