Exemplo n.º 1
0
  @SuppressLint("NewApi")
  public void onMenuCopyClicked() {
    String text =
        dobroitem.post.getMessage() == null
            ? dobroitem.post.getFormattedText().toString()
            : dobroitem.post.getMessage();
    /*
    Intent i = new Intent(getContext(), CopyPasteActivity.class);
    i.putExtra("text", );
    i.putExtra(GDActivity.GD_ACTION_BAR_TITLE, "Скопируйте текст");
    getContext().startActivity(i);
    */
    View v = null;
    if (Build.VERSION.SDK_INT < 11) {
      EditText edit = new EditText(getContext());
      edit.setPadding(10, 10, 10, 10);
      edit.setGravity(Gravity.TOP);
      edit.setTextColor(Color.BLACK);
      edit.setBackgroundColor(Color.WHITE);
      edit.setInputType(InputType.TYPE_NULL);
      edit.setHorizontallyScrolling(false);
      edit.setSingleLine(false);
      edit.setText(text);
      v = edit;
    } else {
      SharedPreferences prefs = DobroApplication.getApplicationStatic().getDefaultPrefs();
      int font_size = 10;
      try {
        font_size = Integer.parseInt(prefs.getString("font_size", "16"));
      } catch (Exception e) {
      }
      if (font_size < 10) font_size = 10;

      TextView edit = new TextView(getContext());
      edit.setPadding(10, 10, 10, 10);
      edit.setTextSize(font_size);
      edit.setTextColor(Color.BLACK);
      edit.setBackgroundColor(Color.WHITE);
      edit.setFocusable(true);
      edit.setTextIsSelectable(true);
      edit.setText(text);
      v = edit;
    }
    Dialog d = new Dialog(getContext(), android.R.style.Theme_NoTitleBar_Fullscreen);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setCanceledOnTouchOutside(true);
    d.setContentView(v);
    d.show();
  }
Exemplo n.º 2
0
 public void onMenulastClicked() {
   SharedPreferences prefs = DobroApplication.getApplicationStatic().getDefaultPrefs();
   Intent intent = new Intent(getContext(), DobroThreadActivity.class);
   if (dobroitem.post.getThreadDisplay_id() == null)
     intent.putExtra(DobroConstants.THREAD_ID, dobroitem.post.getThread_id());
   intent.putExtra(DobroConstants.BOARD, ((DobroPostItem) dobroitem).post.getBoardName());
   intent.putExtra(DobroConstants.THREAD, ((DobroPostItem) dobroitem).post.getThreadDisplay_id());
   intent.putExtra(DobroConstants.COUNT, prefs.getString("last_count", "50"));
   if (((DobroPostItem) dobroitem).post.getThread() != null)
     intent.putExtra(
         GDActivity.GD_ACTION_BAR_TITLE, ((DobroPostItem) dobroitem).post.getThread().getTitle());
   else
     intent.putExtra(
         GDActivity.GD_ACTION_BAR_TITLE, ((DobroPostItem) dobroitem).post.getMessage());
   getContext().startActivity(intent);
 }
Exemplo n.º 3
0
  @Override
  public void setObject(Item item) {
    try {
      dobroitem = (DobroPostItem) item;
    } catch (ClassCastException e) {
      e.printStackTrace();
      return;
    }
    if (dobroitem == null || dobroitem.post == null) return;
    dobroitem.post.setLastContext(getContext());
    this.board = dobroitem.post.getBoardName();
    this.thread = dobroitem.post.getThreadDisplay_id();
    ((HorizontalScrollView) findViewById(R.id.horizScroll)).scrollTo(0, 0);

    CharSequence txt = dobroitem.post.getFormattedText();
    if (txt.length() > 800) {
      Pattern p1 = Pattern.compile("\\.|\n");
      Matcher m1 = p1.matcher(txt);
      Pattern p2 = Pattern.compile("\\b");
      Matcher m2 = p2.matcher(txt);
      if (m1.find(500) && m1.end() < 700) txt = txt.subSequence(0, m1.end());
      else if (m2.find(500) && m2.start() < 700) txt = txt.subSequence(0, m2.start());
      else txt = txt.subSequence(0, 500);
      messageView.setText(txt, BufferType.SPANNABLE);
      SpannableStringBuilder builder =
          new SpannableStringBuilder("\nСообщение слишком длинное. Полная версия");
      builder.setSpan(
          new ClickableSpan() {
            @Override
            public void onClick(View widget) {
              try {
                messageView.setText(dobroitem.post.getFormattedText(), BufferType.SPANNABLE);
              } catch (IndexOutOfBoundsException e) {

              }
            }
          },
          1,
          builder.length(),
          0);
      messageView.append(builder.subSequence(0, builder.length()));
    } else messageView.setText(txt, BufferType.SPANNABLE);
    // FIXME
    messageView.setMovementMethod(LinkMovementMethod.getInstance());
    messageView.setClickable(false);
    messageView.setFocusable(false);
    messageView.setFocusableInTouchMode(false);
    /*
    refsView.setMovementMethod(LinkMovementMethod.getInstance());
    refsView.setClickable(false);
    refsView.setFocusable(false);
    refsView.setFocusableInTouchMode(false);
    */
    //
    imagesLayout.removeAllViewsInLayout();
    if (dobroitem.post.isOp()) {
      numberView.setVisibility(GONE);
      titleView.setText(
          dobroitem.post.getSubject().length() == 0
              ? getContext().getString(R.string.untitled)
              : dobroitem.post.getSubject());
      titleView.setVisibility(VISIBLE);
    } else {
      int pos = dobroitem.post.getNumber();
      if (pos > 0) {
        numberView.setVisibility(VISIBLE);
        numberView.setText(String.valueOf(pos));
      } else numberView.setVisibility(GONE);
      titleView.setText("");
      titleView.setVisibility(GONE);
    }

    TypedValue backgroundRef = new TypedValue();
    getContext().getTheme().resolveAttribute(R.attr.dcPicrelatedColor, backgroundRef, true);
    int backgroundColor = getContext().getResources().getColor(backgroundRef.resourceId);
    SharedPreferences prefs = DobroApplication.getApplicationStatic().getDefaultPrefs();
    boolean show_info = prefs.getBoolean("show_fileinfo", true);
    boolean force_op_load = prefs.getBoolean("op_pictures_force", false);

    if (dobroitem.post.getFiles().length > 0) {
      for (DobroFile file : dobroitem.post.getFiles()) {
        CachedAsyncImageView imageView = new CachedAsyncImageView(getContext());
        VerticalTextView textView = null;
        String fname1 = file.getThumb().substring(file.getThumb().lastIndexOf("/") + 1);
        int e = fname1.lastIndexOf("s.");
        if (e > 0)
          fname1 = fname1.substring(0, e) + file.getSrc().substring(file.getSrc().lastIndexOf("."));
        String fname2 = file.getSrc().substring(file.getSrc().lastIndexOf("/") + 1);
        String size = humanReadableByteCount(file.getSize(), true);
        String date = getThumbnailDate(file.getThumb());
        if (date == null)
          try {
            date = file.getSrc().split("/")[2];
            date = date.substring(2) + "." + date.substring(0, 2);
          } catch (Exception ex) {
            date = "?";
          }
        imageView.setInfo(
            getContext()
                .getString(
                    R.string.file_info_parretn,
                    fname1,
                    fname2,
                    size,
                    date,
                    file.getRating(),
                    getMetadataText(file.getMetadata())));
        if (file.getMetadata().width != null)
          imageView.setSize(file.getMetadata().height, file.getMetadata().width);
        if (show_info) {
          textView = new VerticalTextView(getContext(), null);
          textView.setLinkedImageView(imageView);
          String text = "";
          if (dobroitem.post.getBoardName().equals("b")
              || dobroitem.post.getBoardName().equals("rf")) text += fname1;
          else text += fname2;
          text += "\n" + size;
          if (file.getMetadata() != null
              && file.getMetadata().width != null
              && file.getMetadata().height != null) {
            text +=
                ", "
                    + String.valueOf(file.getMetadata().width)
                    + "x"
                    + String.valueOf(file.getMetadata().height);
          }
          textView.setText(text);
          textView.setGravity(Gravity.BOTTOM);
          textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
        }
        imageView.setRating(file.getRat());
        imageView.setForceLoad(force_op_load && dobroitem.post.isOp());
        imageView.setUrl(file.getThumb());
        final String urlTag = file.getSrc();
        imageView.setTag(urlTag);
        imageView.setPadding(2, 2, 2, 2);
        imageView.setAdjustViewBounds(true);
        imageView.setMaxHeight(mImageHeight);
        imageView.setMaxWidth(mImageHeight);
        imageView.setBackgroundColor(backgroundColor);
        imageView.setScaleType(ScaleType.CENTER);
        imageView.setOnCreateContextMenuListener(imageView);
        float h = mImageHeight;
        int w =
            Math.min(
                Math.round((h / (float) file.getThumb_height()) * file.getThumb_width()),
                file.getThumb_width());
        imageView.setLayoutParams(new LayoutParams(w + 4, mImageHeight + 4));
        if (show_info) {
          textView.setWidth(mImageHeight + 4);
          textView.setLinkedImageView(imageView);
          imagesLayout.addView(textView);
        }
        imagesLayout.addView(imageView);
      }
      imagesLayout.setVisibility(VISIBLE);
    } else {
      imagesLayout.setVisibility(GONE);
    }
    if (prefs.getBoolean("youtube", true)) {
      Spanned s = null;
      boolean cast_ok = false;
      try {
        s = (Spanned) dobroitem.post.getFormattedText();
        cast_ok = true;
      } catch (ClassCastException e) {
        cast_ok = false;
      }
      if (cast_ok) {
        URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
        for (URLSpan span : spans) {
          String url = span.getURL();
          Pattern p = Pattern.compile("(youtube\\.com/watch\\?v=|youtu\\.be/)(\\S{11})");
          Matcher m = p.matcher(url);
          if (!m.find()) continue;
          String yt_id = m.group(2);
          String text = s.subSequence(s.getSpanStart(span), s.getSpanEnd(span)).toString();
          CachedAsyncImageView imageView = new CachedAsyncImageView(getContext());
          imageView.setLayoutParams(
              new LayoutParams((int) ((mImageHeight + 4) / 0.75), mImageHeight + 4));

          imageView.setRating(Rating.SWF);
          imageView.setForceLoad(false);
          imageView.setTag(url);
          imageView.setPadding(2, 2, 2, 2);
          imageView.setAdjustViewBounds(true);
          imageView.setMaxHeight(mImageHeight);
          imageView.setMaxWidth((int) ((mImageHeight + 4) / 0.75));

          imageView.setUrl("http://img.youtube.com/vi/" + yt_id + "/0.jpg");

          imageView.setBackgroundColor(backgroundColor);
          imageView.setScaleType(ScaleType.CENTER);

          VerticalTextView textView = new VerticalTextView(getContext(), null);
          textView.setGravity(Gravity.BOTTOM);
          textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
          textView.setText(text);
          textView.setLinkedImageView(imageView);
          textView.setWidth(mImageHeight + 4);

          if (show_info) imagesLayout.addView(textView);
          imagesLayout.addView(imageView);
          imagesLayout.setVisibility(VISIBLE);
        }
      }
    }
    metadataRightView.setText(
        getContext()
            .getString(
                R.string.post_date, String.valueOf(dobroitem.post.getDate().replace(' ', '\n'))));
    metadataLeftView.setText(
        dobroitem.post.getName()
            + "\n"
            + getContext()
                .getString(R.string.post_id, String.valueOf(dobroitem.post.getDisplay_id())));
    List<String> refs = dobroitem.post.getRefs();
    if (!refs.isEmpty()) {
      /*
      CharSequence seq = getContext().getText(R.string.answers);
      SpannableStringBuilder s = new SpannableStringBuilder(seq);
      s.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, seq.length(), 0);
      s.append(" ");
      for (String ref : refs) {
      	int start = s.length();
      	s.append(ref + ", ");
      	s.setSpan(
      			new DobroLinkSpan(dobroitem.post.getBoardName(), ref
      					.substring(2), getContext(), null), start, start
      					+ ref.length(), 0);
      }
      refsView.setText(s.subSequence(0, s.length() - 2),
      		BufferType.SPANNABLE);
       */
      refsButton.setText(String.format("/%d", refs.size()));
      refsButton.setVisibility(View.VISIBLE);
    } else refsButton.setVisibility(View.GONE);
    checkSpells();
  }
Exemplo n.º 4
0
  @Override
  public void prepareItemView() {
    messageView = (TextViewWithSpoilers) findViewById(R.id.messageView);
    SharedPreferences prefs = DobroApplication.getApplicationStatic().getDefaultPrefs();
    int font_size = Integer.parseInt(prefs.getString("font_size", "16"));
    if (font_size < 10) font_size = 10;
    messageView.setTextSize(TypedValue.COMPLEX_UNIT_SP, font_size);
    metadataLeftView = (TextView) findViewById(R.id.metadataLeftView);
    metadataRightView = (TextView) findViewById(R.id.metadataRightView);
    numberView = (TextView) findViewById(R.id.postNumber);
    imagesLayout = (LinearLayout) findViewById(R.id.imagesLayout);
    ViewGroup.LayoutParams p = imagesLayout.getLayoutParams();
    mImageHeight = Integer.parseInt(prefs.getString("images_size", "200"));
    if (mImageHeight <= 0 || mImageHeight > 200) mImageHeight = 200;
    p.height = mImageHeight;
    imagesLayout.setLayoutParams(p);
    titleView = (TextView) findViewById(R.id.titleView);
    metadataLayout = (LinearLayout) findViewById(R.id.metadataLayout);
    //		refsView = (TextView) findViewById(R.id.refsView);
    refsButton = (TextView) findViewById(R.id.refsButton);
    refsButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            IPostsList activity = null;
            try {
              activity = (IPostsList) getContext();
            } catch (ClassCastException e) {
            }
            if (activity == null) return;
            activity.openLinks(dobroitem.post.getRefs());
          }
        });
    // QA
    messageView.setOnLongClickListener(
        new OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            DobroPostItemView.this.onShowBar(v);
            return true;
          }
        });

    metadataLayout.setOnLongClickListener(
        new OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            DobroPostItemView.this.onShowBar(v);
            return true;
          }
        });

    titleView.setOnLongClickListener(
        new OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            DobroPostItemView.this.onShowBar(v);
            return true;
          }
        });

    metadataLayout.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            DobroPostItemView.this.onAnyViewClick(v);
            if (!DobroApplication.getApplicationStatic().show_spoilers) messageView.performClick();
          }
        });

    titleView.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            DobroPostItemView.this.onAnyViewClick(v);
          }
        });
  }