Exemple #1
0
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

      Note note = mNoteList.get(position);
      holder.tvNoteTitle.setText(note.getTitle());

      String time = note.getTime();
      // reformat date to "dd/mm/yyyy"
      Date date = DateUtils.stringToDate(time);
      SimpleDateFormat fomatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
      String newTime = fomatter.format(date);

      String content = note.getContent();
      String newContent = newTime + " " + content;
      // change time's color in textview
      SpannableStringBuilder style = new SpannableStringBuilder(newContent);
      style.setSpan(
          new ForegroundColorSpan(getResources().getColor(R.color.jikelv)),
          0,
          newTime.length(),
          Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
      holder.tvNoteContent.setText(style);

      String imagePath = note.getImagePath();
      if (!TextUtils.isEmpty(imagePath)) {
        mBitmapUtils.display(holder.ivPhoto, imagePath);
        holder.ivPhoto.setVisibility(View.VISIBLE);
      } else {
        holder.ivPhoto.setVisibility(View.GONE);
      }
    }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (requestCode == VIEW_REQUEST_CODE && resultCode == RESULT_OK) {
     //            Note note = (Note) data.getSerializableExtra("request_note");
     mNote = (Note) data.getSerializableExtra("request_note");
     tvTitle.setText(mNote.getTitle());
     tvContent.setText(mNote.getContent());
     tvViewCategory.setText(mNote.getCategory());
     String imagePath = mNote.getImagePath();
     //            System.out.println("imagePath: " + imagePath);
     if (!TextUtils.isEmpty(imagePath)) {
       BitmapUtils bitmapUtils = new BitmapUtils(this);
       bitmapUtils.display(ivShowPhoto, imagePath);
       ivShowPhoto.setVisibility(View.VISIBLE);
     }
     String videoPath = mNote.getVideoPath();
     if (!TextUtils.isEmpty(videoPath)) {
       vvViewVideo.setVideoURI(Uri.parse(videoPath));
       vvViewVideo.setVisibility(View.VISIBLE);
       if (!vvViewVideo.isPlaying()) {
         vvViewVideo.start();
       }
     }
   }
 }
  private void initViews() {

    tvTitle = (TextView) findViewById(R.id.tvTitle);
    tvTitle.setText(mNote.getTitle());

    tvViewCategory = (TextView) findViewById(R.id.tvViewCategory);
    tvViewCategory.setText(mNote.getCategory());

    tvContent = (TextView) findViewById(R.id.tvContent);
    tvContent.setText(mNote.getContent());

    ivShowPhoto = (ImageView) findViewById(R.id.ivShowPhoto);
    String imagePath = mNote.getImagePath();
    if (!TextUtils.isEmpty(imagePath)) {
      BitmapUtils bitmapUtils = new BitmapUtils(this);
      bitmapUtils.display(ivShowPhoto, imagePath);
      ivShowPhoto.setVisibility(View.VISIBLE);
    }

    vvViewVideo = (VideoView) findViewById(R.id.vvViewVideo);
    String videoPath = mNote.getVideoPath();
    if (!TextUtils.isEmpty(videoPath)) {
      vvViewVideo.setVideoURI(Uri.parse(videoPath));
      vvViewVideo.setVisibility(View.VISIBLE);
      if (!vvViewVideo.isPlaying()) {
        vvViewVideo.start();
      }
    }
  }
  private void showShare() {
    ShareSDK.initSDK(this);
    OnekeyShare oks = new OnekeyShare();
    // 关闭sso授权
    oks.disableSSOWhenAuthorize();

    // title标题:微信、QQ(新浪微博不需要标题)
    String title = mNote.getTitle();
    oks.setTitle(title); // 最多30个字符

    // text是分享文本:所有平台都需要这个字段
    String content = mNote.getContent();
    oks.setText(content); // 最多40个字符

    // imagePath是图片的本地路径:除Linked-In以外的平台都支持此参数
    // oks.setImagePath(Environment.getExternalStorageDirectory() + "/meinv.jpg");//确保SDcard下面存在此张图片
    String imagePath = mNote.getImagePath();
    if (!TextUtils.isEmpty(imagePath)) {
      String rawImagePath = Uri.parse(imagePath).getPath();
      oks.setImagePath(rawImagePath);
    }

    // 网络图片的url:所有平台
    // oks.setImageUrl("http://7sby7r.com1.z0.glb.clouddn.com/CYSJ_02.jpg");//网络图片rul

    // url:仅在微信(包括好友和朋友圈)中使用
    //        oks.setUrl("http://sharesdk.cn");   //网友点进链接后,可以看到分享的详情

    // Url:仅在QQ空间使用
    //        oks.setTitleUrl("http://www.baidu.com");  //网友点进链接后,可以看到分享的详情

    // 启动分享GUI
    oks.show(this);
  }
Exemple #5
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = View.inflate(MainActivity.this, R.layout.item_list_main, null);
        holder.tvNoteTitle = (TextView) convertView.findViewById(R.id.tvNoteTitle);
        holder.tvNoteContent = (TextView) convertView.findViewById(R.id.tvNoteContent);
        holder.ivPhoto = (ImageView) convertView.findViewById(R.id.ivPhoto);
        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }

      Note note = mNoteList.get(position);
      holder.tvNoteTitle.setText(note.getTitle());
      String time = note.getTime();

      // reformat date to "dd/mm/yyyy"
      Date date = DateUtils.stringToDate(time);
      SimpleDateFormat fomatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
      String newTime = fomatter.format(date);

      String content = note.getContent();
      String newContent = newTime + " " + content;
      // change time's color in textview
      SpannableStringBuilder style = new SpannableStringBuilder(newContent);
      style.setSpan(
          new ForegroundColorSpan(getResources().getColor(R.color.jikelv)),
          0,
          newTime.length(),
          Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
      holder.tvNoteContent.setText(style);

      String imagePath = note.getImagePath();
      if (!TextUtils.isEmpty(imagePath)) {
        //                Bitmap bitmap = BitmapUtil.getBitmapLocal(MainActivity.this,
        // Uri.parse(imagePath));
        //                Bitmap bitmap = null;
        BitmapUtils bitmapUtils = new BitmapUtils(MainActivity.this);
        bitmapUtils.display(holder.ivPhoto, imagePath);
        //                    bitmap = BitmapFactory.decodeStream(getContentResolver()
        //                            .openInputStream(Uri.parse(imagePath)));
        //                holder.ivPhoto.setImageBitmap(bitmap);
        holder.ivPhoto.setVisibility(View.VISIBLE);
      } else {
        holder.ivPhoto.setVisibility(View.GONE);
      }

      return convertView;
    }