Search in sources :

Example 21 with Nullable

use of androidx.annotation.Nullable in project MovieGuide by esoxjem.

the class MoviesListingAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    holder.itemView.setOnClickListener(holder);
    holder.movie = movies.get(position);
    holder.name.setText(holder.movie.getTitle());
    RequestOptions options = new RequestOptions().centerCrop().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).priority(Priority.HIGH);
    Glide.with(context).asBitmap().load(Api.getPosterPath(holder.movie.getPosterPath())).apply(options).into(new BitmapImageViewTarget(holder.poster) {

        @Override
        public void onResourceReady(Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
            super.onResourceReady(bitmap, transition);
            Palette.from(bitmap).generate(palette -> setBackgroundColor(palette, holder));
        }
    });
}
Also used : Context(android.content.Context) Api(com.esoxjem.movieguide.Api) RequestOptions(com.bumptech.glide.request.RequestOptions) ButterKnife(butterknife.ButterKnife) LayoutInflater(android.view.LayoutInflater) ImageView(android.widget.ImageView) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) ViewGroup(android.view.ViewGroup) BindView(butterknife.BindView) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Glide(com.bumptech.glide.Glide) Priority(com.bumptech.glide.Priority) Bitmap(android.graphics.Bitmap) Transition(com.bumptech.glide.request.transition.Transition) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) R(com.esoxjem.movieguide.R) Palette(androidx.palette.graphics.Palette) Movie(com.esoxjem.movieguide.Movie) Bitmap(android.graphics.Bitmap) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 22 with Nullable

use of androidx.annotation.Nullable in project fresco by facebook.

the class HierarcherImpl method buildProgressDrawable.

@Override
@Nullable
public Drawable buildProgressDrawable(Resources resources, ImageOptions imageOptions) {
    if (FrescoSystrace.isTracing()) {
        FrescoSystrace.beginSection("HierarcherImpl#buildProgressDrawable");
    }
    try {
        if (imageOptions.getProgressRes() == 0 && imageOptions.getProgressDrawable() == null) {
            return null;
        }
        Drawable progressDrawable = imageOptions.getProgressDrawable();
        if (progressDrawable == null) {
            progressDrawable = resources.getDrawable(imageOptions.getProgressRes());
        }
        if (progressDrawable == null) {
            return null;
        }
        progressDrawable.setLevel(0);
        if (imageOptions.getProgressScaleType() != null) {
            return new ScaleTypeDrawable(progressDrawable, imageOptions.getProgressScaleType());
        }
        return progressDrawable;
    } finally {
        if (FrescoSystrace.isTracing()) {
            FrescoSystrace.endSection();
        }
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) NopDrawable(com.facebook.fresco.vito.core.NopDrawable) ForwardingDrawable(com.facebook.drawee.drawable.ForwardingDrawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) Nullable(androidx.annotation.Nullable)

Example 23 with Nullable

use of androidx.annotation.Nullable in project fresco by facebook.

the class FrescoDrawable2 method setOverlayDrawable.

@Override
@Nullable
public Drawable setOverlayDrawable(@Nullable Drawable drawable) {
    Drawable result = setDrawable(OVERLAY_DRAWABLE_INDEX, drawable);
    showLayerImmediately(OVERLAY_DRAWABLE_INDEX);
    return result;
}
Also used : FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) Drawable(android.graphics.drawable.Drawable) TransformAwareDrawable(com.facebook.drawee.drawable.TransformAwareDrawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) Nullable(androidx.annotation.Nullable)

Example 24 with Nullable

use of androidx.annotation.Nullable in project Lightning-Browser by anthonycr.

the class ArticleTextExtractor method determineImageSource.

@Nullable
private static Element determineImageSource(@NonNull Element el, @NonNull List<ImageResult> images) {
    int maxWeight = 0;
    Element maxNode = null;
    Elements els = el.select("img");
    if (els.isEmpty())
        els = el.parent().select("img");
    double score = 1;
    for (Element e : els) {
        String sourceUrl = e.attr("src");
        if (sourceUrl.isEmpty() || isAdImage(sourceUrl))
            continue;
        int weight = 0;
        int height = 0;
        try {
            height = Integer.parseInt(e.attr("height"));
            if (height >= 50)
                weight += 20;
            else
                weight -= 20;
        } catch (Exception ignored) {
        }
        int width = 0;
        try {
            width = Integer.parseInt(e.attr("width"));
            if (width >= 50)
                weight += 20;
            else
                weight -= 20;
        } catch (Exception ignored) {
        }
        String alt = e.attr("alt");
        if (alt.length() > 35)
            weight += 20;
        String title = e.attr("title");
        if (title.length() > 35)
            weight += 20;
        String rel;
        boolean noFollow = false;
        if (e.parent() != null) {
            rel = e.parent().attr("rel");
            if (rel != null && rel.contains("nofollow")) {
                noFollow = rel.contains("nofollow");
                weight -= 40;
            }
        }
        weight = (int) (weight * score);
        if (weight > maxWeight) {
            maxWeight = weight;
            maxNode = e;
            score = score / 2;
        }
        ImageResult image = new ImageResult(sourceUrl, weight, title, height, width, alt, noFollow);
        images.add(image);
    }
    Collections.sort(images, new ImageComparator());
    return maxNode;
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements) SelectorParseException(org.jsoup.select.Selector.SelectorParseException) Nullable(androidx.annotation.Nullable)

Example 25 with Nullable

use of androidx.annotation.Nullable in project Lightning-Browser by anthonycr.

the class ArticleTextExtractor method getBestMatchElement.

// Returns the best node match based on the weights (see getWeight for strategy)
@Nullable
private Element getBestMatchElement(@NonNull Collection<Element> nodes) {
    // why -200 now instead of 0?
    int maxWeight = -200;
    Element bestMatchElement = null;
    for (Element entry : nodes) {
        int currentWeight = getWeight(entry, false);
        if (currentWeight > maxWeight) {
            maxWeight = currentWeight;
            bestMatchElement = entry;
        /*
                // NOTE: This optimization fails with large pages that
                contains chunks of text that can be mistaken by articles, since we 
                want the best accuracy possible, I am disabling it for now. AP.

                // The original code had a limit of 200, the intention was that
                // if a node had a weight greater than it, then it most likely
                // it was the main content.
                // However this assumption fails when the amount of text in the 
                // children (or grandchildren) is too large. If we detect this
                // case then the limit is ignored and we try all the nodes to select
                // the one with the absolute maximum weight.
                if (maxWeight > 500){
                    ignoreMaxWeightLimit = true;
                    continue;
                } 
                
                // formerly 200, increased to 250 to account for the fact
                // we are not adding the weights of the grand children to the
                // tally.
                
                if (maxWeight > 250 && !ignoreMaxWeightLimit) 
                    break;
                */
        }
    }
    return bestMatchElement;
}
Also used : Element(org.jsoup.nodes.Element) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1206 View (android.view.View)207 Bundle (android.os.Bundle)118 IOException (java.io.IOException)106 ArrayList (java.util.ArrayList)104 TextView (android.widget.TextView)102 NonNull (androidx.annotation.NonNull)101 Context (android.content.Context)95 Cursor (android.database.Cursor)78 SuppressLint (android.annotation.SuppressLint)74 Uri (android.net.Uri)69 RecyclerView (androidx.recyclerview.widget.RecyclerView)64 List (java.util.List)63 ViewGroup (android.view.ViewGroup)60 Intent (android.content.Intent)58 Test (org.junit.Test)55 Recipient (org.thoughtcrime.securesms.recipients.Recipient)52 LayoutInflater (android.view.LayoutInflater)48 R (org.thoughtcrime.securesms.R)46 ImageView (android.widget.ImageView)45