@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;
  }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!passbook.isValid()) { // don't deal with invalid passes
      new AlertDialog.Builder(this)
          .setMessage(getString(R.string.pass_problem))
          .setTitle(getString(R.string.problem))
          .setPositiveButton(
              android.R.string.ok,
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  finish();
                }
              })
          .setNeutralButton(
              getString(R.string.send),
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  new ExportProblemPassToLigiAndFinishTask(
                          TicketViewActivity.this,
                          passbook.getPath(),
                          TicketDefinitions.getShareDir(TicketViewActivity.this),
                          "share.pkpass")
                      .execute();
                }
              })
          .show();
      return;
    }

    View contentView = getLayoutInflater().inflate(R.layout.activity_ticket_view, null);
    setContentView(contentView);

    ButterKnife.inject(this);

    barcode_img.setImageBitmap(
        passbook.getBarcodeBitmap(AXT.at(getWindowManager()).getSmallestSide() / 3));
    logo_img.setImageBitmap(passbook.getLogoBitmap());

    logo_img.setBackgroundColor(passbook.getBackGroundColor());
    thumbnail_img.setImageBitmap(passbook.getThumbnailImage());

    if (findViewById(R.id.map_container) != null) {
      if (!(passbook.getLocations().size() > 0 && PassbookMapsFacade.init(this))) {
        findViewById(R.id.map_container).setVisibility(View.GONE);
      }
    }

    if (passbook.getType() != null) {
      String front_str = "";
      front_str += PassVisualizer.getFieldListAsString(passbook.getPrimaryFields());
      front_str += PassVisualizer.getFieldListAsString(passbook.getSecondaryFields());
      front_str += PassVisualizer.getFieldListAsString(passbook.getHeaderFields());
      front_str += PassVisualizer.getFieldListAsString(passbook.getAuxiliaryFields());

      front_tv.setText(Html.fromHtml(front_str));
    }
    String back_str = "";

    if (App.isDeveloperMode()) {
      back_str += getPassDebugInfo(passbook);
    }

    back_str += PassVisualizer.getFieldListAsString(passbook.getBackFields());

    back_tv.setText(Html.fromHtml(back_str));

    Linkify.addLinks(back_tv, Linkify.ALL);
    PassVisualizer.visualize(this, new ReducedPassInformation(passbook), contentView);
  }