mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-22 12:21:15 +00:00
Added QR code scanner on when adding node (closes #39).
This uses intents, not a built-in scanner, so a seperate app is required (eg "Barcode Scanner").
This commit is contained in:
parent
6ccf1667e8
commit
87daf00867
3 changed files with 36 additions and 1 deletions
|
@ -2,6 +2,7 @@ package com.nutomic.syncthingandroid.gui;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
@ -16,6 +17,7 @@ import android.preference.Preference;
|
|||
import android.preference.PreferenceActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
|
@ -39,6 +41,8 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
|||
|
||||
public static final String KEY_NODE_ID = "node_id";
|
||||
|
||||
private static final int SCAN_QR_REQUEST_CODE = 235;
|
||||
|
||||
private SyncthingService mSyncthingService;
|
||||
|
||||
private final ServiceConnection mSyncthingServiceConnection = new ServiceConnection() {
|
||||
|
@ -254,4 +258,27 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends QR code scanning intent when clicking the qrcode icon.
|
||||
*/
|
||||
public void onClick(View view) {
|
||||
Intent intentScan = new Intent("com.google.zxing.client.android.SCAN");
|
||||
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
startActivityForResult(intentScan, SCAN_QR_REQUEST_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives value of scanned QR code and sets it as node ID.
|
||||
*/
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == SCAN_QR_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
||||
mNode.NodeID = data.getStringExtra("SCAN_RESULT");
|
||||
((EditTextPreference) mNodeId).setText(mNode.NodeID);
|
||||
mNodeId.setSummary(mNode.NodeID);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
7
src/main/res/layout/scan_qr_code_widget.xml
Normal file
7
src/main/res/layout/scan_qr_code_widget.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="48dip"
|
||||
android:layout_height="48dip"
|
||||
android:src="@drawable/ic_qrcode"
|
||||
android:onClick="onClick" />
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
<EditTextPreference
|
||||
android:key="node_id"
|
||||
android:title="@string/node_id" />
|
||||
android:title="@string/node_id"
|
||||
android:widgetLayout="@layout/scan_qr_code_widget" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="name"
|
||||
|
|
Loading…
Reference in a new issue