Esempio n. 1
0
  /**
   * 删除选中的记事本,并且把所属的多媒体文件从Sdcard中删除
   *
   * @param nid
   */
  public void deleteSelectedNote(String nid) {
    PictureDao pictureDao = new PictureDao(MainActivity.this);
    VoiceDao voiceDao = new VoiceDao(MainActivity.this);
    VideoDao videoDao = new VideoDao(MainActivity.this);

    List<PictureModel> picList = pictureDao.getPicFromNid(nid);
    // 若有图片则先删除SDcard中的图片
    if (picList.size() > 0) {
      FileUtil.deleteMediaInSdcard(picList);
    }

    List<String> voiList = voiceDao.getVoiFromNid(nid);
    // 若有录音则先删除SDcard中的录音
    if (voiList.size() > 0) {
      FileUtil.deleteMediaInSdcard(voiList, Utils.VOI_PATH);
    }
    // 若有视频则先删除SDcard中的视频
    List<String> videoList = videoDao.getVideoFromNid(nid);
    if (videoList.size() > 0) {
      FileUtil.deleteMediaInSdcard(videoList, Utils.VID_PATH);
    }

    // 删除数据库中数据,仅需删除note表,其他表将级联删除
    noteDetailDao.deleteNote(nid);
  }
Esempio n. 2
0
  public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent intent = null;
    switch (v.getId()) {
      case R.id.seeallbtn:
        slidingMenu.toggle();
        break;

      case R.id.addnotebtn:
        intent = new Intent(MainActivity.this, AddNoteActivity.class);
        intent.putExtra("index", currentGroupIndex);
        startActivityForResult(intent, ADDNOTE);
        break;

      case R.id.addtype_btn:
        showDialog(ADDTYPE);
        break;

      case R.id.delete_btn_main:
        showDialog(SURE_DEL_NOTE);

        break;

      case R.id.share_btn_main:
        int which = 0; // 判断选中哪个一个记事本
        for (int i = 0; i < listAdapter.map.size(); i++) {
          if (listAdapter.map.get(i)) {
            which = i;
            break;
          }
        }

        // 通过which获取记事本的nid,再获取该记事本的基本信息
        NoteDetail noteDetail = noteDetailDao.getOneNote(noteList.get(which).get("nid").toString());

        intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/*");
        // 设置邮件默认标题
        intent.putExtra(Intent.EXTRA_SUBJECT, "我正在使用XNote超级记事本!");

        // 分享图片
        if (noteList.get(which).get("pic") != null) {
          File file = new File(Utils.PIC_PATH + noteList.get(which).get("pic"));
          intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        }

        // 分享的内容
        intent.putExtra(Intent.EXTRA_TEXT, "我用XNote写了一篇记事:\n" + noteDetail.getContent());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        // gettitle获取app的名字,显示在最上面
        startActivity(Intent.createChooser(intent, getTitle()));
        break;

      case R.id.move_btn_main:
        showDialog(SELECT_GROUP);
        break;

      case R.id.searchbtn_sidebar:
        if (listAdapter == null) {
          Toast.makeText(MainActivity.this, "暂无记事本,不能进行搜索服务", Toast.LENGTH_SHORT).show();
        } else {
          // 收取侧栏
          slidingMenu.toggle();
          toSearch();
        }

        break;

      case R.id.startsearch_btn:
        if (searchEditText.getText().toString().trim().equals("")) {
          searchEditText.setError("请输入内容");
        } else {
          String searchString = prepareSearch(searchEditText.getText().toString());

          System.out.println("组号----------" + currentGroupIndex);
          List<Map<String, Object>> searchList =
              noteDetailDao.getSearchResult(currentGroupIndex, searchString);
          if (searchList.size() > 0) {
            toNormal();
            // 让软键盘消失
            ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(
                    MainActivity.this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            showListView(searchList);

          } else {
            searchEditText.setError("对不起,无搜索结果");
          }
        }
        break;

      case R.id.calendarbtn_sidebar:
        // 收起侧栏
        slidingMenu.toggle();
        // 选中“全部”
        SelectOneType(0);
        intent = new Intent(MainActivity.this, CalendarActivity.class);
        startActivityForResult(intent, CALENDAR);

        break;

      case R.id.albumbtn_sidebar:
        PictureDao pictureDao = new PictureDao(this);
        if (pictureDao.checkHasPic()) {
          intent = new Intent(MainActivity.this, AlbumActivity.class);
          startActivity(intent);
        } else {
          Toast toast = Toast.makeText(this, "您的记事本中还没有添加相片哦!", Toast.LENGTH_SHORT);
          toast.setGravity(Gravity.CENTER, 0, 0);
          toast.show();
        }

        break;

      case R.id.passwdbtn_sidebar:

        // 查看用户是否设置过密码,若无则创建密码
        if (Utils.getPasswd(sharedPreferences) == null) {
          showDialog(CREATE_PASSWD);
        } else {
          intent = new Intent(MainActivity.this, EncryptSettingActivity.class);
          startActivity(intent);
        }

        break;

      case R.id.feedbackbtn_sidebar:
        agent.startFeedbackActivity();
        break;

      case R.id.shareappbtn_sidebar:
        // UMServiceFactory.shareTo(MainActivity.this,
        // "我使用了快速分享接口(UMServiceFactory.share)", null);

        // UMSocialService controller = UMServiceFactory.getUMSocialService(
        // MainActivity.class.getName(), RequestType.SOCIAL);
        umSocialService.setShareContent(
            "我正在使用一款功能强大的记事本XNote,个性化的工具和多媒体的记录让我爱不释手,你们也赶快去下载吧,各大安卓应用市场搜索“XNote”!"); // 设置分享文字内容

        // 设置分享图片
        UMImage shareImage = new UMImage(MainActivity.this, getString(R.string.poster_url));

        umSocialService.setShareMedia(shareImage);

        UMWXHandler.WX_APPID = "wxab4a81c9399bba08"; // 设置微信的Appid

        // 添加微信平台
        umSocialService.getConfig().supportWXPlatform(MainActivity.this);

        // 添加微信朋友圈
        umSocialService
            .getConfig()
            .supportWXPlatform(
                MainActivity.this,
                UMServiceFactory.getUMWXHandler(MainActivity.this).setToCircle(true));
        // 微信图文分享必须设置一个url,默认"http://www.umeng.com"
        UMWXHandler.CONTENT_URL = getString(R.string.poster_url);

        umSocialService.openShare(MainActivity.this, false);
        break;

      case R.id.aboutbtn_sidebar:
        intent = new Intent(MainActivity.this, AboutActivity.class);
        startActivity(intent);

        break;

      case R.id.voice_search_btn:
        // 显示语音输入提示框
        voiceRecognizerDialog.show();
        break;

      case R.id.changebtn:
        if (orderString.contains("asc")) {
          // 如果为顺序则改为逆序
          orderString = orderString.replace("asc", "desc");
        } else {
          // 如果为逆序则改为顺序
          orderString = orderString.replace("desc", "asc");
        }

        showListView();

        break;

      case R.id.locked_btn_main:

        // 查看用户是否设置过密码,若无则创建密码
        if (Utils.getPasswd(sharedPreferences) == null) {
          showDialog(CREATE_PASSWD);
        } else {
          for (int i = 0; i < listAdapter.map.size(); i++) {
            // 找出选中的记事本并加锁
            if (listAdapter.map.get(i)) {
              noteDetailDao.updateNoteLock(noteList.get(i).get("nid").toString(), 1);
            }
          }

          Toast.makeText(MainActivity.this, "加锁成功!", Toast.LENGTH_SHORT).show();
          // 回到正常模式
          toNormal();
          // 刷新列表
          showListView();
        }

        break;

      case R.id.unlocked_btn_main:
        boolean hasLocked = false;
        // 判断是否选中的记事本均未加锁
        for (int i = 0; i < listAdapter.map.size(); i++) {
          // 找出选中的记事本
          if (listAdapter.map.get(i)) {
            if (noteList.get(i).get("locked").toString().equals("1")) {
              hasLocked = true;
            }
          }
        }
        // 如果选中的都未加锁则直接返回
        if (!hasLocked) {
          Toast.makeText(MainActivity.this, "亲,没有加锁怎么解锁呢?!", Toast.LENGTH_SHORT).show();
          return;
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("请输入密码进行解锁!");
        final EditText editText = new EditText(MainActivity.this);
        editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
        editText.setHint("请输入密码");
        builder.setNegativeButton("取消", null);
        builder.setPositiveButton(
            "确定",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                String passwdString = editText.getText().toString();
                // 密码正确
                if (passwdString.equals(Utils.getPasswd(sharedPreferences))) {
                  for (int i = 0; i < listAdapter.map.size(); i++) {
                    // 找出选中的记事本并解锁
                    if (listAdapter.map.get(i)) {
                      noteDetailDao.updateNoteLock(noteList.get(i).get("nid").toString(), 0);
                    }
                  }

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

                  toNormal();
                  // 刷新列表
                  showListView();
                } else {
                  Toast.makeText(MainActivity.this, "密码错误,解锁失败!", Toast.LENGTH_SHORT).show();
                }
              }
            });

        builder.setView(editText);
        builder.show();

        break;
    }
  }