|
@@ -1,10 +1,8 @@
|
|
|
package macampcorp.macamp.activities.fragments;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
-import android.content.pm.PackageManager;
|
|
|
import android.os.Bundle;
|
|
|
import android.app.Fragment;
|
|
|
-import android.util.Log;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
@@ -23,7 +21,7 @@ import com.journeyapps.barcodescanner.DecoratedBarcodeView;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
-import macampcorp.macamp.activities.ChallengeDriver;
|
|
|
+import macampcorp.macamp.activities.HostActivity;
|
|
|
import macampcorp.macamp.activities.R;
|
|
|
import macampcorp.macamp.game.Game;
|
|
|
import macampcorp.macamp.game.challenges.Challenge;
|
|
@@ -39,11 +37,9 @@ import macampcorp.macamp.game.challenges.QRCodeTreasure;
|
|
|
* Use the {@link QRCodeFragment#newInstance} factory method to
|
|
|
* create an instance of this fragment.
|
|
|
*/
|
|
|
-public class QRCodeFragment extends ChallengeFragment implements
|
|
|
- DecoratedBarcodeView.TorchListener, BarcodeCallback, View.OnClickListener{
|
|
|
+public class QRCodeFragment extends ChallengeFragment implements BarcodeCallback, View.OnClickListener{
|
|
|
private CaptureManager capture;
|
|
|
private DecoratedBarcodeView barcodeScannerView;
|
|
|
- private Button switchFlashlightButton;
|
|
|
private TextView tvQuestion;
|
|
|
private Button goToScan;
|
|
|
private BeepManager beepManager;
|
|
@@ -98,7 +94,7 @@ public class QRCodeFragment extends ChallengeFragment implements
|
|
|
{
|
|
|
mQr=null;
|
|
|
}
|
|
|
- getDriver().setVisibilityView(R.id.btn_valid, View.INVISIBLE);
|
|
|
+ getHostActivity().setVisibilityView(R.id.btn_valid, View.INVISIBLE);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -116,7 +112,7 @@ public class QRCodeFragment extends ChallengeFragment implements
|
|
|
if(mUIGlobalIndice2!=null) {
|
|
|
mUIGlobalIndice2.setVisibility(View.GONE);
|
|
|
}
|
|
|
- getDriver().setVisibilityView(R.id.btn_valid, View.INVISIBLE);
|
|
|
+ getHostActivity().setVisibilityView(R.id.btn_valid, View.INVISIBLE);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -125,10 +121,8 @@ public class QRCodeFragment extends ChallengeFragment implements
|
|
|
// Inflate the layout for this fragment
|
|
|
View v = super.onCreateView(inflater, container, R.layout.fragment_qrcode);
|
|
|
barcodeScannerView = (DecoratedBarcodeView)v.findViewById(R.id.zxing_barcode_scanner);
|
|
|
- barcodeScannerView.setTorchListener(this);
|
|
|
beepManager=new BeepManager(getActivity());
|
|
|
|
|
|
- switchFlashlightButton = (Button)v.findViewById(R.id.switch_flashlight);
|
|
|
goToScan = (Button)v.findViewById(R.id.btn_scan);
|
|
|
goToScan.setOnClickListener(this);
|
|
|
vPresRoot=v.findViewById(R.id.presentation);
|
|
@@ -138,9 +132,6 @@ public class QRCodeFragment extends ChallengeFragment implements
|
|
|
mUITextIndices2= (LinearLayout) v.findViewById(R.id.ll_textIndices2);
|
|
|
mUIGlobalIndice2 = (LinearLayout) v.findViewById(R.id.ll_rootIndices2);
|
|
|
|
|
|
- if (!hasFlash()) {
|
|
|
- switchFlashlightButton.setVisibility(View.GONE);
|
|
|
- }
|
|
|
|
|
|
capture = new CaptureManager(getActivity(), barcodeScannerView);
|
|
|
capture.initializeFromIntent(getActivity().getIntent(), savedInstanceState);
|
|
@@ -185,32 +176,8 @@ public class QRCodeFragment extends ChallengeFragment implements
|
|
|
return barcodeScannerView.onKeyDown(keyCode, event) || getActivity().onKeyDown(keyCode, event);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Check if the device's camera has a Flashlight.
|
|
|
- * @return true if there is Flashlight, otherwise false.
|
|
|
- */
|
|
|
- private boolean hasFlash() {
|
|
|
- return getActivity().getApplicationContext().getPackageManager()
|
|
|
- .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
|
|
|
- }
|
|
|
|
|
|
- public void switchFlashlight(View view) {
|
|
|
- if ("on".equals(switchFlashlightButton.getText())) {
|
|
|
- barcodeScannerView.setTorchOn();
|
|
|
- } else {
|
|
|
- barcodeScannerView.setTorchOff();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public void onTorchOn() {
|
|
|
- switchFlashlightButton.setText("Off");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onTorchOff() {
|
|
|
- switchFlashlightButton.setText("On");
|
|
|
- }
|
|
|
|
|
|
public void barcodeResult(final BarcodeResult result) {
|
|
|
beepManager.playBeepSoundAndVibrate();
|
|
@@ -222,7 +189,7 @@ public class QRCodeFragment extends ChallengeFragment implements
|
|
|
Toast.makeText(getActivity(),mQr.getGoodMessage(), Toast.LENGTH_LONG).show();
|
|
|
barcodeScannerView.pause();
|
|
|
Activity act = getActivity();
|
|
|
- getDriver().challengeValidate(mChallenge, mGame, (ChallengeDriver)getActivity());
|
|
|
+ getHostActivity().challengeValidate(mChallenge, mGame, HostActivity.cast(getActivity()));
|
|
|
}else
|
|
|
{
|
|
|
if(mQr.getBadMessage()!=null)
|
|
@@ -259,7 +226,7 @@ public class QRCodeFragment extends ChallengeFragment implements
|
|
|
Indice indice = super.showIndice();
|
|
|
int indInd = mChallenge.getIndiceIndex();
|
|
|
|
|
|
- if(indice!=null && getActivity() instanceof ChallengeDriver)
|
|
|
+ if(indice!=null)
|
|
|
{
|
|
|
|
|
|
if(mUITextIndices2!=null)
|