package ssrmarcsautelet.automation.appli.ssrmarcsautelet;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;


/**
 * Created by Robin on 30/01/2017.
 */

public class activity_age1 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_age1);

        ImageButton btnScan = (ImageButton) findViewById(R.id.mode_aventure);
        ImageButton btnColo = (ImageButton) findViewById(R.id.dessine);

        final Activity activity = this;

        btnScan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentIntegrator integrator = new IntentIntegrator(activity);
                integrator.initiateScan();
            }
        });

        btnColo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = getPackageManager().getLaunchIntentForPackage("anupam.acrylic");
                if (intent != null) {
                    // We found the activity now start the activity
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else {
                    // Bring user to the market or let them choose an app?
                    intent = new Intent(Intent.ACTION_VIEW);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setData(Uri.parse("market://details?id=" + "anupam.acrylic"));
                    startActivity(intent);
                }

            }
        });

    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (result != null) {
            if (result.getContents() == null)
            {
                Toast.makeText(this, "Scan arrêté", Toast.LENGTH_LONG).show();
            } else {
                Intent i = new Intent(activity_age1.this, educ1.class);
                i.putExtra("result_flash",result.getContents());
                startActivity(i);
            }
        } else
        {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}




