Exemple #1
0
  private void showList() {

    this.setContentView(R.layout.mark_list);

    this.setTitle("所有书签");

    if (marksList == null || listmodified) {
      marksList = dbHelper.getAllMarks();
      listmodified = false;
    }

    marksString = new ArrayList<CharSequence>(marksList.size());

    for (Iterator<Mark> iterator = marksList.iterator(); iterator.hasNext(); ) {
      Mark mark = iterator.next();

      marksString.add(mark.toString());
    }

    listview = (ListView) findViewById(R.id.list_marks);
    listview.setAdapter(new BaseAdapterNull(this));

    final Adapter4MarkList baseAdapterNew = new Adapter4MarkList(this);

    baseAdapterNew.setContentList(marksString);

    baseAdapterNew.setTextsize(16);

    listview.setAdapter(baseAdapterNew);
    listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listview.setSelection(0);
    listview.requestFocus();

    Button btn = (Button) this.findViewById(R.id.btnRtnFromMarks);
    btn.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            MarkActivity.this.finish();
          }
        });

    this.registerForContextMenu(listview);
  }
Exemple #2
0
  public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    // long itemid = info.id;
    long itemposition = info.position;

    // System.out.println(itemid + ":" + itemposition);

    // TextView tv = (TextView) info.targetView;

    final Mark mark = marksList.get((int) itemposition);

    // System.out.println(mark);

    TextView content2;
    EditText tags2;

    Button btnreturn2;
    Button btnshowlist2;
    switch (item.getItemId()) {
      case CCM_LOCATE:
        String volume = mark.getVolume();
        int hindex = volume.indexOf(" ");
        String key = volume.substring(0, hindex).trim();
        int chapter = mark.getChapter();
        int subchapter = mark.getSubchapter();

        Intent mIntent = new Intent();
        Bundle bundle = new Bundle();

        bundle.putString("key", key);
        bundle.putInt("chapter", chapter);
        bundle.putInt("subchapter", subchapter);

        mIntent.putExtras(bundle);

        setResult(RESULT_OK, mIntent);

        finish();
        break;

      case CCM_SEND:
        volume = mark.getVolume();
        hindex = volume.indexOf(" ");
        key = volume.substring(0, hindex).trim();
        chapter = mark.getChapter();
        subchapter = mark.getSubchapter();

        Intent it = new Intent(Intent.ACTION_VIEW);
        it.putExtra("sms_body", mark.toString());
        it.setType("vnd.android-dir/mms-sms");
        startActivityForResult(it, 1);

        break;
      case CCM_EDIT:
        volume = mark.getVolume();
        hindex = volume.indexOf(" ");
        key = volume.substring(0, hindex).trim();
        chapter = mark.getChapter();
        subchapter = mark.getSubchapter();

        this.setContentView(R.layout.mark_add);

        TextView index = (TextView) this.findViewById(R.id.markIndex);
        index.setText(volume + "  " + chapter);

        final TextView content = (TextView) this.findViewById(R.id.markContent);

        content.setText(mark.getTags().split(MarkActivity.SPACE_THREE)[0]);

        final EditText tags = (EditText) this.findViewById(R.id.mark_tags);

        tags.setText(mark.getTags().split(MarkActivity.SPACE_THREE)[1]);

        Button btnreturn = (Button) this.findViewById(R.id.btnSaveMarkRtn);

        btnreturn.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                MarkActivity.this.finish();
              }
            });

        Button btnshowlist = (Button) this.findViewById(R.id.btnSaveMark2List);

        btnshowlist.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                showList();
              }
            });

        final Button btnsaveMark = (Button) this.findViewById(R.id.btnSaveMark);

        String string = get18n("修改书签");
        this.setTitle(string);
        String string2 = get18n("修改书签-确定");
        btnsaveMark.setText(string2);

        btnsaveMark.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {

                EditText xtags = (EditText) findViewById(R.id.mark_tags);

                mark.setTags(
                    content.getText().toString()
                        + MarkActivity.SPACE_THREE
                        + xtags
                            .getText()
                            .toString()
                            .replaceAll("\r", "")
                            .replaceAll("\n", "")
                            .replaceAll(SPACE_THREE, " ")
                            .replaceAll("  ", " "));
                // System.out.println(mark.getTags());

                String string3 = get18n("保存");
                String string5 = get18n("确定 ");
                try {
                  dbHelper.updateMark(mark);

                  listmodified = true;

                  btnsaveMark.setEnabled(false);

                  final AlertDialog.Builder builder = new AlertDialog.Builder(MarkActivity.this);

                  String string4 = get18n("修改完毕");
                  builder
                      .setTitle(string3)
                      .setMessage(string4)
                      .setCancelable(true)
                      .setNeutralButton(string5, null)
                      .show();

                } catch (Exception e) {

                  final AlertDialog.Builder builder = new AlertDialog.Builder(MarkActivity.this);
                  String string4 = get18n("修改失败");
                  builder
                      .setTitle(string3)
                      .setMessage(string4)
                      .setCancelable(true)
                      .setNeutralButton(string5, null)
                      .show();
                } finally {

                }
              }
            });

        break;
      case CCM_DELETE:
        volume = mark.getVolume();
        hindex = volume.indexOf(" ");
        key = volume.substring(0, hindex).trim();
        chapter = mark.getChapter();
        subchapter = mark.getSubchapter();

        this.setContentView(R.layout.mark_add);

        index = (TextView) this.findViewById(R.id.markIndex);
        index.setText(volume + "  " + chapter);

        content2 = (TextView) this.findViewById(R.id.markContent);

        content2.setText(mark.getTags().split(MarkActivity.SPACE_THREE)[0]);

        tags2 = (EditText) this.findViewById(R.id.mark_tags);

        tags2.setText(mark.getTags().split(MarkActivity.SPACE_THREE)[1]);

        btnreturn2 = (Button) this.findViewById(R.id.btnSaveMarkRtn);

        btnreturn2.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                MarkActivity.this.finish();
              }
            });

        btnshowlist2 = (Button) this.findViewById(R.id.btnSaveMark2List);

        btnshowlist2.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                showList();
              }
            });

        final Button btnsaveMark2 = (Button) this.findViewById(R.id.btnSaveMark);

        this.setTitle(get18n("删除书签"));
        btnsaveMark2.setText(get18n("删除书签-确定"));

        btnsaveMark2.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {

                String get18n = get18n("确定 ");
                String get18n2 = get18n("删除书签");
                try {
                  dbHelper.delete(mark.getId());
                  listmodified = true;

                  btnsaveMark2.setEnabled(false);

                  String get18n3 = get18n("删除完毕!");
                  new AlertDialog.Builder(MarkActivity.this)
                      .setTitle(get18n2)
                      .setMessage(get18n3)
                      .setCancelable(true)
                      .setNeutralButton(get18n, null)
                      .show();

                } catch (Exception e) {
                  // e.printStackTrace();

                  final AlertDialog.Builder builder = new AlertDialog.Builder(MarkActivity.this);
                  String get18n3 = get18n("删除失败!");
                  builder
                      .setTitle(get18n2)
                      .setMessage(get18n3)
                      .setCancelable(true)
                      .setNeutralButton(get18n, null)
                      .show();
                } finally {

                }
              }
            });

        break;
      default:
        break;
    }
    return true;
  }