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>
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>
import android.app.Activity;
import android.app.AlertDialog;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
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;
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";
private Result mLastResult;
private boolean mHasSurface;
private boolean mPlayBeep;
+ private boolean mVibrate;
+ private boolean mCopyToClipboard;
private boolean mScanIntent;
private String mDecodeMode;
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();
}
*/
public void handleDecode(Result rawResult, Bitmap barcode, int duration) {
mLastResult = rawResult;
- playBeepSound();
+ playBeepSoundAndVibrate();
drawResultPoints(barcode, rawResult);
if (mScanIntent) {
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();
button.setVisibility(View.GONE);
}
}
+
+ if (mCopyToClipboard) {
+ ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
+ clipboard.setText(displayContents);
+ }
}
}
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());
}
}
- 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) {
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) {
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