use of androidx.annotation.NonNull in project Lightning-Browser by anthonycr.
the class ThemeUtils method getBitmapFromVectorDrawable.
// http://stackoverflow.com/a/38244327/1499541
@NonNull
public static Bitmap getBitmapFromVectorDrawable(@NonNull Context context, int drawableId) {
Drawable drawable = getVectorDrawable(context, drawableId);
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
use of androidx.annotation.NonNull in project Lightning-Browser by anthonycr.
the class ThemeUtils method createThemedBitmap.
/**
* Gets the icon with an applied color filter
* for the correct theme.
*
* @param context the context to use.
* @param res the drawable resource to use.
* @param dark true for icon suitable for use with a dark theme,
* false for icon suitable for use with a light theme.
* @return a themed icon.
*/
@NonNull
public static Bitmap createThemedBitmap(@NonNull Context context, @DrawableRes int res, boolean dark) {
int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
Bitmap sourceBitmap = getBitmapFromVectorDrawable(context, res);
Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(), Bitmap.Config.ARGB_8888);
Paint p = new Paint();
ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
p.setColorFilter(filter);
Canvas canvas = new Canvas(resultBitmap);
canvas.drawBitmap(sourceBitmap, 0, 0, p);
sourceBitmap.recycle();
return resultBitmap;
}
use of androidx.annotation.NonNull in project Lightning-Browser by anthonycr.
the class Utils method newEmailIntent.
/**
* Creates a new intent that can launch the email
* app with a subject, address, body, and cc. It
* is used to handle mail:to links.
*
* @param address the address to send the email to.
* @param subject the subject of the email.
* @param body the body of the email.
* @param cc extra addresses to CC.
* @return a valid intent.
*/
@NonNull
public static Intent newEmailIntent(String address, String subject, String body, String cc) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address });
intent.putExtra(Intent.EXTRA_TEXT, body);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_CC, cc);
intent.setType("message/rfc822");
return intent;
}
use of androidx.annotation.NonNull in project Lightning-Browser by anthonycr.
the class Utils method getDisplayDomainName.
/**
* Extracts the domain name from a URL.
* NOTE: Should be used for display only.
*
* @param url the URL to extract the domain from.
* @return the domain name, or the URL if the domain
* could not be extracted. The domain name may include
* HTTPS if the URL is an SSL supported URL.
*/
@NonNull
public static String getDisplayDomainName(@Nullable String url) {
if (url == null || url.isEmpty())
return "";
boolean ssl = URLUtil.isHttpsUrl(url);
int index = url.indexOf('/', 8);
if (index != -1) {
url = url.substring(0, index);
}
URI uri;
String domain;
try {
uri = new URI(url);
domain = uri.getHost();
} catch (URISyntaxException e) {
Log.e(TAG, "Unable to parse URI", e);
domain = null;
}
if (domain == null || domain.isEmpty()) {
return url;
}
if (ssl)
return Constants.HTTPS + domain;
else
return domain.startsWith("www.") ? domain.substring(4) : domain;
}
use of androidx.annotation.NonNull in project plaid by nickbutcher.
the class ReflowText method createRunAnimators.
/**
* Create Animators to transition each run of text from start to end position and size.
*/
@NonNull
private List<Animator> createRunAnimators(View view, ReflowData startData, ReflowData endData, Bitmap startText, Bitmap endText, List<Run> runs) {
List<Animator> animators = new ArrayList<>(runs.size());
int dx = startData.bounds.left - endData.bounds.left;
int dy = startData.bounds.top - endData.bounds.top;
long startDelay = 0L;
// move text closest to the destination first i.e. loop forward or backward over the runs
boolean upward = startData.bounds.centerY() > endData.bounds.centerY();
boolean first = true;
boolean lastRightward = true;
LinearInterpolator linearInterpolator = new LinearInterpolator();
for (int i = upward ? 0 : runs.size() - 1; ((upward && i < runs.size()) || (!upward && i >= 0)); i += (upward ? 1 : -1)) {
Run run = runs.get(i);
// skip text runs which aren't visible in either state
if (!run.startVisible && !run.endVisible)
continue;
// create & position the drawable which displays the run; add it to the overlay.
SwitchDrawable drawable = new SwitchDrawable(startText, run.start, startData.textSize, endText, run.end, endData.textSize);
drawable.setBounds(run.start.left + dx, run.start.top + dy, run.start.right + dx, run.start.bottom + dy);
view.getOverlay().add(drawable);
PropertyValuesHolder topLeft = PropertyValuesHolder.ofObject(SwitchDrawable.TOP_LEFT, null, getPathMotion().getPath(run.start.left + dx, run.start.top + dy, run.end.left, run.end.top));
PropertyValuesHolder width = PropertyValuesHolder.ofInt(SwitchDrawable.WIDTH, run.start.width(), run.end.width());
PropertyValuesHolder height = PropertyValuesHolder.ofInt(SwitchDrawable.HEIGHT, run.start.height(), run.end.height());
// the progress property drives the switching behaviour
PropertyValuesHolder progress = PropertyValuesHolder.ofFloat(SwitchDrawable.PROGRESS, 0f, 1f);
Animator runAnim = ObjectAnimator.ofPropertyValuesHolder(drawable, topLeft, width, height, progress);
boolean rightward = run.start.centerX() + dx < run.end.centerX();
if ((run.startVisible && run.endVisible) && !first && rightward != lastRightward) {
// increase the start delay (by a decreasing amount) for the next run
// (if it's visible throughout) to stagger the movement and try to minimize overlaps
startDelay += staggerDelay;
staggerDelay *= STAGGER_DECAY;
}
lastRightward = rightward;
first = false;
runAnim.setStartDelay(startDelay);
long animDuration = Math.max(minDuration, duration - (startDelay / 2));
runAnim.setDuration(animDuration);
animators.add(runAnim);
if (run.startVisible != run.endVisible) {
// if run is appearing/disappearing then fade it in/out
ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA, run.startVisible ? OPAQUE : TRANSPARENT, run.endVisible ? OPAQUE : TRANSPARENT);
fade.setDuration((duration + startDelay) / 2);
if (!run.startVisible) {
drawable.setAlpha(TRANSPARENT);
fade.setStartDelay((duration + startDelay) / 2);
} else {
fade.setStartDelay(startDelay);
}
animators.add(fade);
} else {
// slightly fade during transition to minimize movement
ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA, OPAQUE, OPACITY_MID_TRANSITION, OPAQUE);
fade.setStartDelay(startDelay);
fade.setDuration(duration + startDelay);
fade.setInterpolator(linearInterpolator);
animators.add(fade);
}
}
return animators;
}
Aggregations