Пример #1
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.exchange_hole_puzzle);
    sounds = new Sounds(this.getApplicationContext());
    // aciertos = (TextView) findViewById(R.id.editAciertos);
    intentos = (TextView) findViewById(R.id.editIntentos);
    ttiempo = (TextView) findViewById(R.id.tiempo);
    tiempo = (ProgressBar) findViewById(R.id.progressTime);

    tiempo.setMax(maxTime);
    tiempo.setProgress(0);
    if (maxTime == 0) {
      tiempo.setVisibility(tiempo.INVISIBLE);
      ttiempo.setVisibility(ttiempo.INVISIBLE);
    }
    bMenu = (Button) findViewById(R.id.menu);

    try {

      agafarDades();
      comprobarInicial();
      if (CO.imatge != null) {
        if (CO.exemple) {
          InputStream in = this.getAssets().open(CO.imatge);

          File dst = new File("/sdcard/tmp/jclic/imatge.jpg");
          dst.createNewFile();

          OutputStream out = new FileOutputStream(dst);

          byte[] buf = new byte[1024];
          int len;

          while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
          }

          in.close();
          out.close();

          posarImatges(dst.getAbsolutePath());
        } else {
          if (Descompressor.descompressor(CO.imatge, CO.path)) {
            posarImatges("/sdcard/tmp/jclic/" + CO.imatge);
          }
        }
      }
      sounds.playStart();
      setOnClickListener();
      if (maxTime != 0) {
        timer =
            new CountDownTimer(maxTime * 1000, 1000) {

              @Override
              public void onFinish() {
                ++contadorT;
                tiempo.setProgress(contadorT);
                setMissatges();
              }

              @Override
              public void onTick(long arg0) {
                contadorT++;
                tiempo.setProgress(contadorT);
                setMissatges();
              }
            }.start();
      }
    } catch (Exception e) {
      Log.d("Error", "catch ExchangePuzzle: " + e);
    }

    // Insertar esto en una actividad para el uso del menu.
    final Context aC = this;
    bMenu.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Dialog dialog = new Dialog(aC, R.style.Dialog);
            dialog.setContentView(R.layout.menu_clic);
            dialog.setCanceledOnTouchOutside(true);
            dialog.show();
            MenuActivitats ma = new MenuActivitats(timer);
            ma.butsMenu(dialog, aC, vecDraw);
          }
        });
  }