Ejemplo n.º 1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater =
        (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    String base_fname = path + "/" + menu_items[position];

    View v;

    if (new File(base_fname).isDirectory()) {
      v = inflater.inflate(R.layout.sgf_dir_list_item, null);

      LinearLayout container = (LinearLayout) v.findViewById(R.id.thumb_container);
      container.setOrientation(LinearLayout.HORIZONTAL);

      container.setVisibility(View.GONE);

    } else {
      v = inflater.inflate(R.layout.sgf_tsumego_list_item, null);
    }

    TextView title_tv = (TextView) v.findViewById(R.id.filename);

    if (title_tv != null) {
      title_tv.setText(menu_items[position].replace(".sgf", ""));
    }

    String sgf_str = "";

    if (GoLink.isGoLink(base_fname)) {
      GoLink gl = new GoLink(base_fname);
      sgf_str = gl.getSGFString();
    } else {
      try {
        sgf_str = AXT.at(new File(base_fname)).readToString();
      } catch (IOException e) {
      }
    }

    GoGame game = SGFReader.sgf2game(sgf_str, null, SGFReader.BREAKON_FIRSTMOVE);
    LinearLayout container = (LinearLayout) v.findViewById(R.id.thumb_container);

    if (game != null) {

      TextView hints_tv = (TextView) v.findViewById(R.id.hints_tv);

      SGFMetaData meta = new SGFMetaData(base_fname);

      if (hints_tv != null) {
        if (meta.getHintsUsed() > 0)
          hints_tv.setText(String.format(hints_used_fmt, meta.getHintsUsed()));
        else hints_tv.setVisibility(View.GONE);
      }

      int transform = TsumegoHelper.calcTransform(game);

      if (transform != SGFReader.DEFAULT_SGF_TRANSFORM)
        game = SGFReader.sgf2game(sgf_str, null, SGFReader.BREAKON_FIRSTMOVE, transform);

      game.jump(game.getFirstMove());
      container.addView(new PreviewView(activity, game));
    }

    Log.i("loadingSGF " + base_fname);

    ImageView solve_img = (ImageView) v.findViewById(R.id.solve_status_image);

    if ((solve_img != null) && (new SGFMetaData(base_fname).getIsSolved())) {
      solve_img.setImageResource(R.drawable.solved);
    }

    return v;
  }
Ejemplo n.º 2
0
  @Override
  public void run() {
    Looper.prepare();

    final Uri intent_uri = getIntent().getData(); // extract the uri from
    // the intent

    if (intent_uri == null) {
      Log.e("SGFLoadActivity with intent_uri==null");
      finish();
      return;
    }

    if (intent_uri.toString().endsWith(".golink")) {
      Intent i = getIntent();
      i.setClass(this, GoLinkLoadActivity.class);
      this.startActivity(i);
      finish();
      return;
    }

    try {

      Log.i("load" + intent_uri);

      sgf = uri2string(intent_uri);

      Log.i("got sgf content:" + sgf);
      game = SGFHelper.sgf2game(sgf, this);

      // if it is a tsumego and we need a transformation to right corner
      // -> do so
      if (getApp().getInteractionScope().getMode() == InteractionScope.MODE_TSUMEGO) {
        int transform = TsumegoHelper.calcTransform(game);

        if (transform != SGFHelper.DEFAULT_SGF_TRANSFORM)
          game = SGFHelper.sgf2game(sgf, null, SGFHelper.BREAKON_NOTHING, transform);
      }

    } catch (Exception e) {
      Log.w("exception in load", e);
      game = null;
    }

    if (game == null) {
      handler.post(
          new Runnable() {

            @Override
            /**
             * if the sgf loading fails - give the user the option to send this SGF to me - to
             * perhaps fix the parser to load more SGF's - TODO remove this block if all SGF's load
             * fine ;-)
             */
            public void run() {
              alert_dlg.hide();
              new AlertDialog.Builder(SGFLoadActivity.this)
                  .setTitle(R.string.results)
                  .setMessage(
                      R.string
                          .problem_loading_sgf_would_you_like_to_send_ligi_this_sgf_to_fix_the_problem)
                  .setPositiveButton(
                      R.string.yes,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                          final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                          emailIntent.setType("plain/text");
                          emailIntent.putExtra(
                              android.content.Intent.EXTRA_EMAIL, new String[] {"*****@*****.**"});
                          emailIntent.putExtra(
                              android.content.Intent.EXTRA_SUBJECT,
                              "SGF Problem" + gobandroid.getVersionCode(SGFLoadActivity.this));
                          emailIntent.putExtra(
                              android.content.Intent.EXTRA_TEXT,
                              "uri: " + intent_uri + " sgf:\n" + sgf + "err:" + Log.getCachedLog());
                          SGFLoadActivity.this.startActivity(
                              Intent.createChooser(emailIntent, "Send mail..."));
                          finish();
                        }
                      })
                  .setNegativeButton(
                      R.string.no,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                          finish();
                        }
                      })
                  .show();
            }
          });

      return;
    }

    int move_num = getIntent().getIntExtra("move_num", -1);

    if (move_num != -1)
      for (int i = 0; i < move_num; i++) game.jump(game.getActMove().getnextMove(0));

    getApp().getInteractionScope().setGame(game);

    game.getMetaData().setFileName(intent_uri.toString());

    handler.post(
        new Runnable() {
          @Override
          public void run() {
            alert_dlg.hide();
            finish();
          }
        });

    SwitchModeHelper.startGameWithCorrectMode(this);
  }