Search in sources :

Example 26 with NonNull

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

the class ArticleTextExtractor method extractContent.

@NonNull
private JResult extractContent(@NonNull JResult res, @NonNull Document doc, @NonNull OutputFormatter formatter, Boolean extractimages, int maxContentSize) throws Exception {
    Document origDoc = doc.clone();
    JResult result = extractContent(res, doc, formatter, extractimages, maxContentSize, true);
    // System.out.println("result.getText().length()="+result.getText().length());
    if (result.getText().isEmpty()) {
        result = extractContent(res, origDoc, formatter, extractimages, maxContentSize, false);
    }
    return result;
}
Also used : Document(org.jsoup.nodes.Document) NonNull(androidx.annotation.NonNull)

Example 27 with NonNull

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

the class ArticleTextExtractor method removeScriptsAndStyles.

@NonNull
private static Document removeScriptsAndStyles(@NonNull Document doc) {
    Elements scripts = doc.getElementsByTag("script");
    for (Element item : scripts) {
        item.remove();
    }
    Elements noscripts = doc.getElementsByTag("noscript");
    for (Element item : noscripts) {
        item.remove();
    }
    Elements styles = doc.getElementsByTag("style");
    for (Element style : styles) {
        style.remove();
    }
    return doc;
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements) NonNull(androidx.annotation.NonNull)

Example 28 with NonNull

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

the class DrawableUtils method createRoundedLetterImage.

/**
 * Creates a rounded square of a certain color with
 * a character imprinted in white on it.
 *
 * @param character the character to write on the image.
 * @param width     the width of the final image.
 * @param height    the height of the final image.
 * @param color     the background color of the rounded square.
 * @return a valid bitmap of a rounded square with a character on it.
 */
@NonNull
public static Bitmap createRoundedLetterImage(@NonNull Character character, int width, int height, int color) {
    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    Paint paint = new Paint();
    paint.setColor(color);
    Typeface boldText = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
    paint.setTypeface(boldText);
    paint.setTextSize(Utils.dpToPx(14));
    paint.setAntiAlias(true);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
    int radius = Utils.dpToPx(2);
    RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
    canvas.drawRoundRect(outer, radius, radius, paint);
    int xPos = (canvas.getWidth() / 2);
    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));
    paint.setColor(Color.WHITE);
    canvas.drawText(character.toString(), xPos, yPos, paint);
    return image;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Typeface(android.graphics.Typeface) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint) NonNull(androidx.annotation.NonNull)

Example 29 with NonNull

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

the class DrawableUtils method createImageInsetInRoundedSquare.

/**
 * Creates a white rounded drawable with an inset image of a different color.
 *
 * @param context     the context needed to work with resources.
 * @param drawableRes the drawable to inset on the rounded drawable.
 * @return a bitmap with the desired content.
 */
@NonNull
public static Bitmap createImageInsetInRoundedSquare(Context context, @DrawableRes int drawableRes) {
    final Bitmap icon = ThemeUtils.getBitmapFromVectorDrawable(context, drawableRes);
    final Bitmap image = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(image);
    final Paint paint = new Paint();
    paint.setColor(Color.WHITE);
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    final int radius = Utils.dpToPx(2);
    final RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
    canvas.drawRoundRect(outer, radius, radius, paint);
    final Rect dest = new Rect(Math.round(outer.left + radius), Math.round(outer.top + radius), Math.round(outer.right - radius), Math.round(outer.bottom - radius));
    canvas.drawBitmap(icon, null, dest, paint);
    return image;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint) NonNull(androidx.annotation.NonNull)

Example 30 with NonNull

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

the class ProxyUtils method checkForProxy.

/*
     * If Orbot/Tor or I2P is installed, prompt the user if they want to enable
     * proxying for this session
     */
public void checkForProxy(@NonNull final Activity activity) {
    final ProxyChoice currentProxyChoice = userPreferences.getProxyChoice();
    final boolean orbotInstalled = OrbotHelper.isOrbotInstalled(activity);
    boolean orbotChecked = developerPreferences.getCheckedForTor();
    boolean orbot = orbotInstalled && !orbotChecked;
    boolean i2pInstalled = i2PAndroidHelper.isI2PAndroidInstalled();
    boolean i2pChecked = developerPreferences.getCheckedForI2P();
    boolean i2p = i2pInstalled && !i2pChecked;
    // Do only once per install
    if (currentProxyChoice != ProxyChoice.NONE && (orbot || i2p)) {
        if (orbot) {
            developerPreferences.setCheckedForTor(true);
        }
        if (i2p) {
            developerPreferences.setCheckedForI2P(true);
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        if (orbotInstalled && i2pInstalled) {
            String[] proxyChoices = activity.getResources().getStringArray(R.array.proxy_choices_array);
            final List<ProxyChoice> values = Arrays.asList(ProxyChoice.NONE, ProxyChoice.ORBOT, ProxyChoice.I2P);
            final List<Pair<ProxyChoice, String>> list = new ArrayList<>();
            for (ProxyChoice proxyChoice : values) {
                list.add(new Pair<>(proxyChoice, proxyChoices[proxyChoice.getValue()]));
            }
            builder.setTitle(activity.getResources().getString(R.string.http_proxy));
            AlertDialogExtensionsKt.withSingleChoiceItems(builder, list, userPreferences.getProxyChoice(), newProxyChoice -> {
                userPreferences.setProxyChoice(newProxyChoice);
                return Unit.INSTANCE;
            });
            builder.setPositiveButton(activity.getResources().getString(R.string.action_ok), (dialog, which) -> {
                if (userPreferences.getProxyChoice() != ProxyChoice.NONE) {
                    initializeProxy(activity);
                }
            });
        } else {
            DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
                switch(which) {
                    case DialogInterface.BUTTON_POSITIVE:
                        userPreferences.setProxyChoice(orbotInstalled ? ProxyChoice.ORBOT : ProxyChoice.I2P);
                        initializeProxy(activity);
                        break;
                    case DialogInterface.BUTTON_NEGATIVE:
                        userPreferences.setProxyChoice(ProxyChoice.NONE);
                        break;
                }
            };
            builder.setMessage(orbotInstalled ? R.string.use_tor_prompt : R.string.use_i2p_prompt).setPositiveButton(R.string.yes, dialogClickListener).setNegativeButton(R.string.no, dialogClickListener);
        }
        Dialog dialog = builder.show();
        BrowserDialog.setDialogSize(activity, dialog);
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) AlertDialogExtensionsKt(acr.browser.lightning.extensions.AlertDialogExtensionsKt) Arrays(java.util.Arrays) AlertDialog(androidx.appcompat.app.AlertDialog) I2PAndroidHelper(net.i2p.android.ui.I2PAndroidHelper) NonNull(androidx.annotation.NonNull) Pair(kotlin.Pair) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) OrbotHelper(info.guardianproject.netcipher.proxy.OrbotHelper) Singleton(javax.inject.Singleton) BrowserApp(acr.browser.lightning.BrowserApp) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) List(java.util.List) UserPreferences(acr.browser.lightning.preference.UserPreferences) Unit(kotlin.Unit) DeveloperPreferences(acr.browser.lightning.preference.DeveloperPreferences) ActivityExtensions(acr.browser.lightning.extensions.ActivityExtensions) R(acr.browser.lightning.R) ProxyChoice(acr.browser.lightning.browser.ProxyChoice) Activity(android.app.Activity) Log(android.util.Log) DialogInterface(android.content.DialogInterface) WebkitProxy(info.guardianproject.netcipher.webkit.WebkitProxy) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) ProxyChoice(acr.browser.lightning.browser.ProxyChoice) AlertDialog(androidx.appcompat.app.AlertDialog) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) Pair(kotlin.Pair)

Aggregations

NonNull (androidx.annotation.NonNull)1200 View (android.view.View)192 ArrayList (java.util.ArrayList)154 Context (android.content.Context)128 Nullable (androidx.annotation.Nullable)128 TextView (android.widget.TextView)118 Intent (android.content.Intent)115 List (java.util.List)110 Recipient (org.thoughtcrime.securesms.recipients.Recipient)109 IOException (java.io.IOException)103 Bundle (android.os.Bundle)102 WorkerThread (androidx.annotation.WorkerThread)94 LayoutInflater (android.view.LayoutInflater)89 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)82 AlertDialog (androidx.appcompat.app.AlertDialog)77 Log (org.signal.core.util.logging.Log)76 Cursor (android.database.Cursor)68 ViewGroup (android.view.ViewGroup)65 LinkedList (java.util.LinkedList)64 Stream (com.annimon.stream.Stream)62