Added two new preferences: vibrate on scan, and copy contents to clipboard on scan.

git-svn-id: https://zxing.googlecode.com/svn/trunk@783 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2008-12-11 17:09:12 +00:00
parent 8a80d1ef46
commit c91265df17
5 changed files with 44 additions and 8 deletions

View file

@ -98,4 +98,5 @@ versionName is 2.31, 2.4, or 3.0. -->
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="android.permission.VIBRATE"/>
</manifest>

View file

@ -76,12 +76,14 @@
your screen and scanning it with another phone.</string>
<string name="msg_share_subject_line">Here\'s the contents of a barcode I scanned</string>
<string name="preferences_actions_title">When a barcode is found\u2026</string>
<string name="preferences_copy_to_clipboard_title">Copy contents to clipboard</string>
<string name="preferences_decode_1D_title">Decode 1D barcodes</string>
<string name="preferences_decode_QR_title">Decode QR Codes</string>
<string name="preferences_general_title">General settings</string>
<string name="preferences_name">Settings</string>
<string name="preferences_play_beep_title">Beep when a barcode is found</string>
<string name="preferences_sounds_title">Sounds</string>
<string name="preferences_play_beep_title">Beep</string>
<string name="preferences_vibrate_title">Vibrate</string>
<string name="result_address_book">Found contact info</string>
<string name="result_calendar">Found calendar event</string>

View file

@ -25,10 +25,18 @@
android:defaultValue="true"
android:title="@string/preferences_decode_QR_title"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preferences_sounds_title">
<PreferenceCategory android:title="@string/preferences_actions_title">
<CheckBoxPreference
android:key="preferences_play_beep"
android:defaultValue="true"
android:title="@string/preferences_play_beep_title"/>
<CheckBoxPreference
android:key="preferences_vibrate"
android:defaultValue="false"
android:title="@string/preferences_vibrate_title"/>
<CheckBoxPreference
android:key="preferences_copy_to_clipboard"
android:defaultValue="true"
android:title="@string/preferences_copy_to_clipboard_title"/>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -18,6 +18,7 @@ package com.google.zxing.client.android;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@ -35,8 +36,10 @@ import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.text.SpannableStringBuilder;
import android.text.ClipboardManager;
import android.text.style.UnderlineSpan;
import android.view.Gravity;
import android.view.KeyEvent;
@ -73,6 +76,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private static final int MAX_RESULT_IMAGE_SIZE = 150;
private static final int INTENT_RESULT_DURATION = 1500;
private static final float BEEP_VOLUME = 0.15f;
private static final long VIBRATE_DURATION = 200;
private static final String PACKAGE_NAME = "com.google.zxing.client.android";
@ -85,6 +89,8 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private Result mLastResult;
private boolean mHasSurface;
private boolean mPlayBeep;
private boolean mVibrate;
private boolean mCopyToClipboard;
private boolean mScanIntent;
private String mDecodeMode;
@ -141,6 +147,8 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
mPlayBeep = prefs.getBoolean(PreferencesActivity.KEY_PLAY_BEEP, true);
mVibrate = prefs.getBoolean(PreferencesActivity.KEY_VIBRATE, false);
mCopyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true);
initBeepSound();
}
@ -266,7 +274,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
*/
public void handleDecode(Result rawResult, Bitmap barcode, int duration) {
mLastResult = rawResult;
playBeepSound();
playBeepSoundAndVibrate();
drawResultPoints(barcode, rawResult);
if (mScanIntent) {
@ -294,7 +302,8 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
CharSequence title = getString(resultHandler.getDisplayTitle());
SpannableStringBuilder styled = new SpannableStringBuilder(title + "\n\n");
styled.setSpan(new UnderlineSpan(), 0, title.length(), 0);
styled.append(resultHandler.getDisplayContents());
CharSequence displayContents = resultHandler.getDisplayContents();
styled.append(displayContents);
contentsTextView.setText(styled);
int buttonCount = resultHandler.getButtonCount();
@ -310,6 +319,11 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
button.setVisibility(View.GONE);
}
}
if (mCopyToClipboard) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(displayContents);
}
}
}
@ -358,6 +372,11 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
mStatusView.setBackgroundColor(getResources().getColor(R.color.transparent));
if (mCopyToClipboard) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(resultHandler.getDisplayContents());
}
// Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when
// the deprecated intent is retired.
Intent intent = new Intent(getIntent().getAction());
@ -413,10 +432,14 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
}
}
private void playBeepSound() {
private void playBeepSoundAndVibrate() {
if (mPlayBeep && mMediaPlayer != null) {
mMediaPlayer.start();
}
if (mVibrate) {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_DURATION);
}
}
private void initCamera(SurfaceHolder surfaceHolder) {

View file

@ -27,12 +27,15 @@ public final class PreferencesActivity extends android.preference.PreferenceActi
static final String KEY_DECODE_1D = "preferences_decode_1D";
static final String KEY_DECODE_QR = "preferences_decode_QR";
static final String KEY_PLAY_BEEP = "preferences_play_beep";
static final String KEY_VIBRATE = "preferences_vibrate";
static final String KEY_COPY_TO_CLIPBOARD = "preferences_copy_to_clipboard";
static final String KEY_HELP_VERSION_SHOWN = "preferences_help_version_shown";
CheckBoxPreference mDecode1D;
CheckBoxPreference mDecodeQR;
CheckBoxPreference mPlayBeep;
@Override
protected void onCreate(Bundle icicle) {
@ -43,7 +46,6 @@ public final class PreferencesActivity extends android.preference.PreferenceActi
preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
mDecode1D = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_1D);
mDecodeQR = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_QR);
mPlayBeep = (CheckBoxPreference) preferences.findPreference(KEY_PLAY_BEEP);
}
// Prevent the user from turning off both decode options