-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package fr.gaulupeau.apps.Poche.ui.preferences; | ||
|
||
import android.app.Activity; | ||
import android.content.ActivityNotFoundException; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
|
@@ -34,6 +36,8 @@ public class ConnectionWizardActivity extends AppCompatActivity { | |
|
||
private static final String TAG = "ConnectionWizard"; | ||
|
||
private static final int REQUEST_CODE_QR_CODE = 1; | ||
|
||
private static final String DATA_PROVIDER = "provider"; | ||
private static final String DATA_URL = "url"; | ||
private static final String DATA_USERNAME = "username"; | ||
|
@@ -118,6 +122,32 @@ protected void onCreate(Bundle savedInstanceState) { | |
} | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
|
||
if(requestCode == REQUEST_CODE_QR_CODE) { | ||
if(resultCode == RESULT_OK) { | ||
String resultString = data.getStringExtra("SCAN_RESULT"); | ||
Log.d(TAG, "onActivityResult() got string: " + resultString); | ||
|
||
if(resultString == null) return; | ||
|
||
Uri uri = Uri.parse(resultString); | ||
if(!"wallabag".equals(uri.getScheme())) { | ||
Log.i(TAG, "onActivityResult() unrecognized URI scheme: " + uri.getScheme()); | ||
Toast.makeText(this, "Unrecognized URI scheme", Toast.LENGTH_SHORT).show(); | ||
return; | ||
} | ||
|
||
Intent intent = getIntent(); | ||
intent.setData(uri); | ||
startActivity(intent); | ||
finish(); | ||
} | ||
} | ||
} | ||
|
||
private ConnectionData parseLoginData(String connectionUri) { | ||
// wallabag://[email protected] | ||
String prefix = "wallabag://"; | ||
|
@@ -139,6 +169,25 @@ private ConnectionData parseLoginData(String connectionUri) { | |
return new ConnectionData(values[0], values[1]); | ||
} | ||
|
||
public void scanQrCode() { | ||
try { | ||
Intent intent = new Intent("com.google.zxing.client.android.SCAN"); | ||
intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); | ||
|
||
startActivityForResult(intent, REQUEST_CODE_QR_CODE); | ||
} catch(ActivityNotFoundException e) { | ||
Log.i(TAG, "scanQrCode() exception", e); | ||
|
||
Toast.makeText(this, "Please install QR-code scanner", Toast.LENGTH_LONG).show(); | ||
|
||
Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android"); | ||
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri); | ||
startActivity(marketIntent); | ||
} catch(Exception e) { | ||
Log.e(TAG, "scanQrCode() exception", e); | ||
} | ||
} | ||
|
||
public void prev(WizardPageFragment fragment, Bundle bundle) { | ||
String currentPage = fragment != null ? fragment.getPageName() : PAGE_NONE; | ||
|
||
|
@@ -312,6 +361,21 @@ protected int getLayoutResourceID() { | |
return R.layout.connection_wizard_provider_selection_fragment; | ||
} | ||
|
||
@Override | ||
protected void initButtons(View v) { | ||
super.initButtons(v); | ||
|
||
Button scanCodeButton = (Button)v.findViewById(R.id.scanQrCodeButton); | ||
if(scanCodeButton != null) { | ||
scanCodeButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
activity.scanQrCode(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
@Override | ||
protected void nextButtonPressed() { | ||
Bundle bundle = getArguments(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters