@Override
    public CharSequence filter(
        CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

      CharSequence filtered = super.filter(source, start, end, dest, dstart, dend);
      if (filtered == null) {
        filtered = source.subSequence(start, end);
      }

      String result =
          String.valueOf(dest.subSequence(0, dstart))
              + filtered
              + dest.subSequence(dend, dest.length());

      if ("".equals(result)) {
        return result;
      }
      int val = getSelectedPos(result);

      /* Ensure the user can't type in a value greater
       * than the max allowed. We have to allow less than min
       * as the user might want to delete some numbers
       * and then type a new number.
       */
      if (val > mEnd) {
        return "";
      } else {
        return filtered;
      }
    }
 public CharSequence filter(
     CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
   if (mDisplayedValues == null) {
     return mNumberInputFilter.filter(source, start, end, dest, dstart, dend);
   }
   CharSequence filtered = String.valueOf(source.subSequence(start, end));
   String result =
       String.valueOf(dest.subSequence(0, dstart))
           + filtered
           + dest.subSequence(dend, dest.length());
   String str = String.valueOf(result).toLowerCase();
   for (String val : mDisplayedValues) {
     val = val.toLowerCase();
     if (val.startsWith(str)) {
       return filtered;
     }
   }
   return "";
 }
Пример #3
0
  /** @param bodyHtml escaped HTML (like in reddit Thing's body_html) */
  private CharSequence createSpanned(String bodyHtml) {
    try {
      // get unescaped HTML
      bodyHtml = Html.fromHtml(bodyHtml).toString();
      // fromHtml doesn't support all HTML tags. convert <code> and <pre>
      bodyHtml = Util.convertHtmlTags(bodyHtml);

      Spanned body = Html.fromHtml(bodyHtml);
      // remove last 2 newline character
      if (body.length() > 2) return body.subSequence(0, body.length() - 2);
      else return "";
    } catch (Exception e) {
      if (Constants.LOGGING) Log.e(TAG, "createSpanned failed", e);
      return null;
    }
  }
Пример #4
0
  @Override
  public CharSequence filter(
      CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
    String sourceText = source.toString();

    if (TextUtils.isEmpty(sourceText)) {
      return "";
    }

    Matcher matcher = mPattern.matcher(source);

    if (!matcher.matches()) {
      return "";
    }

    return dest.subSequence(dstart, dend) + sourceText;
  }
Пример #5
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    Item item = items.get(position);
    View view = convertView;

    if (view == null) {
      LayoutInflater inflater =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      view = inflater.inflate(R.layout.fragment_interview_list_item, null);
    }

    TextView title = (TextView) view.findViewById(R.id.interview_list_item_title);
    title.setText(item.getTitle());

    Spanned descriptionText = Html.fromHtml(item.getDescription());
    TextView description = (TextView) view.findViewById(R.id.interview_list_item_description);
    description.setText(descriptionText.subSequence(1, descriptionText.length()));

    return view;
  }
Пример #6
0
  private void parseOP(final ThingInfo data, final ThingInfo contextOP) {
    data.setIndent(0);
    data.setClicked(Common.isClicked(mActivity, data.getUrl()));

    mActivity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            mActivity.mObjectStates.mCommentsList.add(0, data);
            if (mJumpToCommentContext > 0) {
              // Need to add a fake comment to get it to draw in the comments list properly, without
              // 'hacking' the adapter to work properly.
              ThingInfo tempInfo = new ThingInfo();
              tempInfo.setIsContext(true);
              // Set the parent ID to allow the user to view the parent thread.
              tempInfo.setParent_id(contextOP.getParent_id());
              tempInfo.setId(mJumpToCommentId);
              mActivity.mObjectStates.mCommentsList.add(1, tempInfo);
            }
          }
        });

    if (data.isIs_self() && data.getSelftext_html() != null) {
      // HTML to Spanned
      String unescapedHtmlSelftext = Html.fromHtml(data.getSelftext_html()).toString();
      Spanned selftext = Html.fromHtml(Util.convertHtmlTags(unescapedHtmlSelftext));

      // remove last 2 newline characters
      if (selftext.length() > 2)
        data.setSpannedSelftext(selftext.subSequence(0, selftext.length() - 2));
      else data.setSpannedSelftext("");
    }

    // We might not have a title if we've intercepted a plain link to a thread.
    mThreadTitle = data.getTitle();
    mActivity.setThreadTitle(mThreadTitle);
    mSubreddit = data.getSubreddit();
    mThreadId = data.getId();

    mOpThingInfo = data;
  }
Пример #7
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    Item item = items.get(position);
    View view = convertView;

    if (view == null) {
      LayoutInflater inflater =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      view = inflater.inflate(R.layout.fragment_review_list_item, null);
    }

    ProgressBar progress = (ProgressBar) view.findViewById(R.id.review_list_item_progress);
    progress.setIndeterminate(true);

    HCLImageView image = (HCLImageView) view.findViewById(R.id.review_list_item_image);
    Util.DownloadImage(context, item.getImage(), image, progress);

    Spanned descriptionText = Html.fromHtml(item.getDescription());

    TextView description = (TextView) view.findViewById(R.id.review_list_item_description);
    description.setText(descriptionText.subSequence(1, descriptionText.length()));

    return view;
  }
Пример #8
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();
  }