/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * xscreensaver, Copyright (c) 2016-2018 Jamie Zawinski <jwz@jwz.org>
+ * xscreensaver, Copyright © 2016-2021 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
import org.jwz.xscreensaver.TTFAnalyzer;
import android.util.Log;
import android.view.Surface;
+import android.Manifest;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
+import android.os.Build;
+import android.content.pm.PackageManager;
public class jwxyz
implements GestureDetector.OnGestureListener,
public final static int FONT_FACE = 1;
public final static int FONT_RANDOM = 2;
+ public final static int MY_REQ_READ_EXTERNAL_STORAGE = 271828;
+
private long nativeRunningHackPtr;
private String hack;
// LOG ("unparsable system font: %s", file);
} else {
name = mungeFontName (name);
- if (! all_fonts.contains (name)) {
+ if (! all_fonts.contains (name.toLowerCase())) {
// LOG ("system font \"%s\" %s", name, file);
- all_fonts.put (name, name);
+ all_fonts.put (name.toLowerCase(), name);
}
}
}
tmpfile.delete();
name = mungeFontName (name);
- all_fonts.put (name, t);
+ all_fonts.put (name.toLowerCase(), t);
// LOG ("asset font \"%s\" %s", name, fn);
} catch (Exception e) {
if (tmpfile != null) tmpfile.delete();
// Parses "Native Font Name One 12, Native Font Name Two 14".
- // Returns [ String name, Typeface ]
+ // Returns [ String name, Typeface ] or null.
private Object[] parseNativeFont (String name) {
- Object font2 = all_fonts.get (name);
- if (font2 instanceof String)
+ Object font2 = all_fonts.get (name.toLowerCase());
+ if (font2 == null)
+ return null;
+ if (font2 instanceof String) // Might be a Typeface or a String
font2 = Typeface.create (name, Typeface.NORMAL);
return new Object[] { name, (Typeface)font2 };
}
// Returns [ Paint paint, String family_name, Float ascent, Float descent ]
+ // or null.
public Object[] loadFont(int mask, int traits, String name, int name_type,
float size) {
- Object pair[];
+ Object pair[] = null;
- if (name_type != FONT_RANDOM && name.equals("")) return null;
+ if (name_type != FONT_RANDOM && name.equals(""))
+ return null;
- if (name_type == FONT_FACE) {
+ if (name_type != FONT_RANDOM) // First try native or bundled names
pair = parseNativeFont (name);
- } else {
+
+ if (pair == null) // Then guess whether it's monospace
pair = parseXLFD (mask, traits, name, name_type);
- }
+
+ if (pair == null)
+ return null;
String name2 = (String) pair[0];
Typeface font = (Typeface) pair[1];
+ if (font == null)
+ return null;
+
size *= 2;
String suffix = (font.isBold() && font.isItalic() ? " bold italic" :
}
+ boolean havePermission(String permission) {
+
+ if (Build.VERSION.SDK_INT < 16) {
+ return true;
+ }
+
+ if (permissionGranted(permission)) {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ private boolean permissionGranted(String permission) {
+ boolean check = ContextCompat.checkSelfPermission(app, permission) ==
+ PackageManager.PERMISSION_GRANTED;
+ return check;
+ }
+
+ public Object[] checkThenLoadRandomImage (int target_width, int target_height,
+ boolean rotate_p) {
+ // RES introduced in API 16
+ String permission = Manifest.permission.READ_EXTERNAL_STORAGE;
+
+ if (havePermission(permission)) {
+ return loadRandomImage(target_width,target_height,rotate_p);
+ } else {
+ return null;
+ }
+ }
+
+ // "getBitmap(ContentResolver,Uri) in Media has been deprecated"
+ @SuppressWarnings("deprecation")
public Object[] loadRandomImage (int target_width, int target_height,
boolean rotate_p) {
ArrayList<String> imgs = new ArrayList<String>();
ContentResolver cr = app.getContentResolver();
+
+ // "DATA in MediaColumns has been deprecated"
+ @SuppressWarnings("deprecation")
String[] cols = { MediaColumns.DATA,
MediaColumns.MIME_TYPE,
MediaColumns.WIDTH,
try {
try {
+ // "getBitmap(ContentResolver,Uri) in Media has been deprecated"
+ // How do I do this for this block, instead of for the whole function?
+ // @SuppressWarnings("deprecation")
bitmap = MediaStore.Images.Media.getBitmap (cr, uri);
} catch (Exception e) {
LOG ("image %s unloadable: %s", which, e.toString());