Exemple #1
0
  // 仅仅运行一次
  @Override
  protected Dialog onCreateDialog(int id) {
    // TODO Auto-generated method stub
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    LinearLayout linearLayout = null;
    switch (id) {
      case ADDTYPE:
        builder.setTitle("添加分组");
        linearLayout =
            (LinearLayout) getLayoutInflater().inflate(R.layout.addtype_dialog_layout, null);
        final EditText editText = (EditText) linearLayout.findViewById(R.id.addtype_edit);
        builder.setCancelable(false);
        builder.setPositiveButton(
            "确定",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                String string = editText.getText().toString().trim();

                if (!string.equals("")) {
                  // 判断长度
                  if (string.length() > 10) {
                    editText.setError("长度不能超过10个字符!");
                    keepDialog(dialog);
                  } else {
                    // 判断组名是否已存在
                    if (!noteTypeDao.isExist(string)) {
                      noteTypeDao.addNewType(string);
                      AddRadioButton(string);

                      Toast.makeText(
                              MainActivity.this, "已添加新分组'" + string + "'", Toast.LENGTH_SHORT)
                          .show();

                      // 让新添加的分组为选中状态
                      SelectOneType(typeGroup.getChildCount() - 1);

                      destoryDialog(dialog);
                    } else {
                      editText.setError("该组名已存在!");
                      keepDialog(dialog);
                    }
                  }

                } else {
                  editText.setError("不能为空!");
                  keepDialog(dialog);
                }
              }
            });

        builder.setNegativeButton(
            "取消",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                destoryDialog(dialog);
              }
            });

        builder.setView(linearLayout);

        return builder.create();

      case SELECT_OPR:
        builder.setTitle("请选择操作:");
        builder.setItems(
            R.array.selecthandle,
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

                if (which == 0) {
                  showDialog(EDITTYPE);
                } else {
                  showDialog(SURE_DEL_TYPE);
                }
              }
            });
        return builder.create();

      case SURE_DEL_TYPE:
        builder.setTitle("确定删除吗?");
        builder.setPositiveButton(
            "是",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                // 从数据库中删除
                noteTypeDao.deleteType(selectedTypeNameString);
                typeGroup.removeView(findViewById(selectedTypeId)); // 通过id删除radiobutton

                Toast.makeText(MainActivity.this, "删除成功", Toast.LENGTH_SHORT).show();

                // 如果删除的组号为当前选中的组,则删除后让“全部”为选中状态
                if (typeGroup.getCheckedRadioButtonId() == selectedTypeId) {
                  SelectOneType(0);
                }
              }
            });
        builder.setNegativeButton("否", null);
        return builder.create();

      case EDITTYPE:
        builder.setTitle("修改分组名称");
        linearLayout =
            (LinearLayout) getLayoutInflater().inflate(R.layout.addtype_dialog_layout, null);
        typeEditText = (EditText) linearLayout.findViewById(R.id.addtype_edit);
        typeEditText.setText(selectedTypeNameString);

        builder.setCancelable(false);
        builder.setPositiveButton(
            "确定",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                String string = typeEditText.getText().toString().trim();

                if (!string.equals("")) {
                  // 判断长度
                  if (string.length() > 10) {
                    typeEditText.setError("长度不能超过10个字符!");
                    keepDialog(dialog);
                  } else {
                    // 判断组名是否存在
                    if (!noteTypeDao.isExist(string)) {
                      // 修改数据库中的信息
                      noteTypeDao.updateType(selectedTypeNameString, string);
                      // 修改显示
                      RadioButton radioButton = (RadioButton) findViewById(selectedTypeId);
                      radioButton.setText(string);

                      showTypeView.setText(string);

                      Toast.makeText(MainActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                      destoryDialog(dialog);
                    } else {
                      typeEditText.setError("该组名已存在!");
                      keepDialog(dialog);
                    }
                  }

                } else {
                  typeEditText.setError("不能为空!");
                  keepDialog(dialog);
                }
              }
            });

        builder.setNegativeButton(
            "取消",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                destoryDialog(dialog);
              }
            });

        builder.setView(linearLayout);

        return builder.create();

      case SURE_DEL_NOTE:
        builder.setTitle("确定删除所选记事本吗?");
        builder.setPositiveButton(
            "是",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                List<String> selectedList = new ArrayList<String>();

                for (int i = 0; i < listAdapter.map.size(); i++) {
                  // 找出选中的记事本
                  if (listAdapter.map.get(i)) {
                    selectedList.add(noteList.get(i).get("nid").toString());
                    // deleteSelectedNote(noteList.get(i)
                    // .get("nid").toString());
                    // 如果有加锁记事本则不能进行删除
                    if (noteList.get(i).get("locked").toString().equals("1")) {
                      Toast.makeText(MainActivity.this, "选中的记事本中包含锁定记事,不能进行删除!", Toast.LENGTH_SHORT)
                          .show();
                      return;
                    }
                  }
                }

                // 删除所选记事本
                for (int j = 0; j < selectedList.size(); j++) {
                  deleteSelectedNote(selectedList.get(j));
                }

                // 回到正常模式
                toNormal();
                // 刷新listview
                showListView();
              }
            });
        builder.setNegativeButton("否", null);

        return builder.create();

      case SELECT_GROUP:
        builder.setTitle("移动到该分组:");
        // 获取所有分类
        typeList = noteTypeDao.getAllTyep();
        CharSequence[] items = new CharSequence[typeList.size()];
        for (int i = 0; i < items.length; i++) {
          items[i] = typeList.get(i).get("type").toString();
        }
        builder.setItems(
            items,
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface arg0, int which) {
                // TODO Auto-generated method stub
                // 修改所有选中的记事本所在分组
                for (int i = 0; i < listAdapter.map.size(); i++) {
                  if (listAdapter.map.get(i)) {
                    noteDetailDao.updateNoteType(
                        noteList.get(i).get("nid").toString(),
                        typeList.get(which).get("tid").toString());
                  }
                }
                toNormal();
                showListView();
              }
            });

        return builder.create();

      case CREATE_PASSWD:
        builder.setTitle("创建密码");
        builder.setCancelable(false);
        linearLayout =
            (LinearLayout) getLayoutInflater().inflate(R.layout.createpasswd_dialog_layout, null);
        final EditText passwdEditText = (EditText) linearLayout.findViewById(R.id.addpasswd_edit);
        builder.setPositiveButton(
            "确定",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                String passwdString = passwdEditText.getText().toString();
                if (passwdString.length() < 5) {
                  passwdEditText.setError("密码太短!");
                  keepDialog(dialog);
                } else {
                  // 保存密码
                  Utils.savePasswd(sharedPreferences, passwdString);
                  Toast.makeText(MainActivity.this, "密码创建成功", Toast.LENGTH_SHORT).show();
                  destoryDialog(dialog);
                }
              }
            });
        builder.setNegativeButton(
            "取消",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                destoryDialog(dialog);
              }
            });
        builder.setView(linearLayout);

        return builder.create();

      case INPUT_PASSWD:
        builder.setTitle("该记事本已加密");
        builder.setCancelable(false);
        linearLayout =
            (LinearLayout) getLayoutInflater().inflate(R.layout.createpasswd_dialog_layout, null);
        final EditText inputEditText = (EditText) linearLayout.findViewById(R.id.addpasswd_edit);
        builder.setPositiveButton(
            "确定",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                String passwdString = inputEditText.getText().toString();
                // 验证通过则开启记事本
                if (passwdString.equals(Utils.getPasswd(sharedPreferences))) {
                  destoryDialog(dialog);

                  Intent intent = new Intent(MainActivity.this, EditNoteActivity.class);
                  intent.putExtra("nid", noteList.get(nowPosition).get("nid").toString());
                  startActivityForResult(intent, EDITNOTE);

                  Toast.makeText(MainActivity.this, "密码正确!", Toast.LENGTH_SHORT).show();

                  // 清空输入框
                  inputEditText.setText("");

                } else {
                  keepDialog(dialog);
                  inputEditText.setError("密码错误!");
                }
              }
            });
        builder.setNegativeButton(
            "取消",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                destoryDialog(dialog);
              }
            });
        builder.setView(linearLayout);

        return builder.create();

      case UPDATE:
        updateProgressDialog = new ProgressDialog(MainActivity.this);
        updateProgressDialog.setMessage("正在下载更新包...");
        updateProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        updateProgressDialog.setCancelable(false);
        updateProgressDialog.show();
        return updateProgressDialog;
    }
    return super.onCreateDialog(id);
  }
Exemple #2
0
  /** 初始化控件 */
  public void initWidget() {
    slidingMenu = new SlidingMenu(this);
    slidingMenu.setMode(SlidingMenu.LEFT);
    slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    slidingMenu.setBehindScrollScale(0);
    slidingMenu.setFadeDegree(1f);
    slidingMenu.setFadeEnabled(true);
    slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);

    slidingMenu.setBehindOffset(getScreenWidth() / 2);
    slidingMenu.setMenu(R.layout.sidebar_layout);

    editTopLayout = (RelativeLayout) findViewById(R.id.edit_top_title);
    searchTitle = (RelativeLayout) findViewById(R.id.main_top_search);
    bottomLayout = (LinearLayout) findViewById(R.id.main_bottom);
    seeAllButton = (ImageButton) findViewById(R.id.seeallbtn);
    addNoteButton = (ImageButton) findViewById(R.id.addnotebtn);
    addTypeButton = (ImageButton) findViewById(R.id.addtype_btn);
    deleteButton = (ImageButton) findViewById(R.id.delete_btn_main);
    shareButton = (ImageButton) findViewById(R.id.share_btn_main);
    moveButton = (ImageButton) findViewById(R.id.move_btn_main);
    lockedButton = (ImageButton) findViewById(R.id.locked_btn_main);
    unlockedButton = (ImageButton) findViewById(R.id.unlocked_btn_main);
    showTypeView = (TextView) findViewById(R.id.showtype);
    showSelectView = (TextView) findViewById(R.id.showselect);
    showNowDateView = (TextView) findViewById(R.id.nowdate_tv);
    typeGroup = (RadioGroup) findViewById(R.id.typegroup);
    noteListView = (ListView) findViewById(R.id.notelist);
    showEmptyView = (LinearLayout) findViewById(R.id.showempty_view);
    showSearchButton = (Button) findViewById(R.id.searchbtn_sidebar);
    calendarButton = (Button) findViewById(R.id.calendarbtn_sidebar);
    albumButton = (Button) findViewById(R.id.albumbtn_sidebar);
    passwdButton = (Button) findViewById(R.id.passwdbtn_sidebar);
    feedbackButton = (Button) findViewById(R.id.feedbackbtn_sidebar);
    shareAppButton = (Button) findViewById(R.id.shareappbtn_sidebar);
    aboutButton = (Button) findViewById(R.id.aboutbtn_sidebar);
    startSearchButton = (ImageButton) findViewById(R.id.startsearch_btn);
    voiceSearchButton = (ImageButton) findViewById(R.id.voice_search_btn);
    searchEditText = (EditText) findViewById(R.id.edittext_search);
    changeOrderButton = (ImageButton) findViewById(R.id.changebtn);

    seeAllButton.setOnClickListener(this);
    addNoteButton.setOnClickListener(this);
    addTypeButton.setOnClickListener(this);
    deleteButton.setOnClickListener(this);
    shareButton.setOnClickListener(this);
    moveButton.setOnClickListener(this);
    lockedButton.setOnClickListener(this);
    unlockedButton.setOnClickListener(this);
    showSearchButton.setOnClickListener(this);
    startSearchButton.setOnClickListener(this);
    calendarButton.setOnClickListener(this);
    albumButton.setOnClickListener(this);
    passwdButton.setOnClickListener(this);
    feedbackButton.setOnClickListener(this);
    shareAppButton.setOnClickListener(this);
    aboutButton.setOnClickListener(this);
    voiceSearchButton.setOnClickListener(this);
    changeOrderButton.setOnClickListener(this);
    noteListView.setOnItemClickListener(this);
    noteListView.setOnItemLongClickListener(this);

    noteTypeDao = new NoteTypeDao(MainActivity.this);

    // 初始化语音识别器
    initVoiceRecognizer();

    // 获取所有分类
    typeList = noteTypeDao.getAllTyep();
    // 动态加载radiobutton
    for (int i = 0; i < typeList.size(); i++) {
      AddRadioButton(typeList.get(i).get("type").toString());
    }

    // 初始化所有的记事本并显示
    noteDetailDao = new NoteDetailDao(MainActivity.this);

    // 显示当前时间
    showNowDate();

    // 创建需要用到的文件夹
    createDir();
  }