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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations