|
1 | 1 | package com.codeheadsystems.mazer.android; |
2 | 2 |
|
| 3 | +import android.content.Intent; |
3 | 4 | import android.os.Bundle; |
4 | 5 | import android.view.WindowManager; |
| 6 | + |
5 | 7 | import com.badlogic.gdx.backends.android.AndroidApplication; |
6 | 8 | import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; |
7 | 9 | import com.codeheadsystems.mazer.MazerGame; |
| 10 | +import com.google.zxing.integration.android.IntentIntegrator; |
| 11 | +import com.google.zxing.integration.android.IntentResult; |
8 | 12 |
|
9 | 13 | public class AndroidLauncher extends AndroidApplication { |
10 | 14 |
|
| 15 | + private AndroidPlatformServices platformServices; |
| 16 | + |
11 | 17 | @Override |
12 | 18 | protected void onCreate(Bundle savedInstanceState) { |
13 | 19 | super.onCreate(savedInstanceState); |
14 | 20 |
|
15 | 21 | // Keep screen on during gameplay |
16 | 22 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
17 | 23 |
|
| 24 | + platformServices = new AndroidPlatformServices(this); |
| 25 | + |
18 | 26 | AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); |
19 | 27 | config.useAccelerometer = false; |
20 | 28 | config.useCompass = false; |
21 | | - config.useImmersiveMode = true; // hide system bars for fullscreen |
22 | | - config.numSamples = 2; // light anti-aliasing |
23 | | - initialize(new MazerGame(), config); |
| 29 | + config.useImmersiveMode = true; |
| 30 | + config.numSamples = 2; |
| 31 | + initialize(new MazerGame(platformServices), config); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Called by AndroidPlatformServices to launch the QR scanner. |
| 36 | + */ |
| 37 | + void launchQrScanner() { |
| 38 | + IntentIntegrator integrator = new IntentIntegrator(this); |
| 39 | + integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE); |
| 40 | + integrator.setPrompt("Scan the host's QR code to join"); |
| 41 | + integrator.setOrientationLocked(true); |
| 42 | + integrator.setBeepEnabled(false); |
| 43 | + integrator.initiateScan(); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 48 | + IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); |
| 49 | + if (result != null) { |
| 50 | + platformServices.onScanResult(result.getContents()); // null if cancelled |
| 51 | + } else { |
| 52 | + super.onActivityResult(requestCode, resultCode, data); |
| 53 | + } |
24 | 54 | } |
25 | 55 | } |
0 commit comments