add more Java APIs needed for OctoDroid

This commit is contained in:
Julian Winkler
2024-08-05 17:17:53 +02:00
parent 6c2585ab4b
commit 3e7fdac663
21 changed files with 184 additions and 5 deletions

View File

@@ -1,6 +1,13 @@
package android.text;
import android.graphics.drawable.Drawable;
public class Html {
public static interface ImageGetter {
public Drawable getDrawable(String source);
}
public static Spanned fromHtml(String source) {
return new SpannableString(source.replace("<br/>", "\n")
.replace("<br>", "\n")

View File

@@ -330,4 +330,12 @@ public class TextUtils {
private static Object sLock = new Object();
private static char[] sTemp = null;
public static int getTrimmedLength(CharSequence s) {
return s.toString().trim().length();
}
public static String htmlEncode(String s) {
return s;
}
}

View File

@@ -0,0 +1,12 @@
package android.text.format;
import java.util.Date;
import android.content.Context;
public class DateUtils {
public static CharSequence getRelativeTimeSpanString(Context context, long millis, boolean withPreposition) {
return new Date(millis).toString();
}
}

View File

@@ -5,6 +5,18 @@ import android.content.Context;
public class Formatter {
public static String formatShortFileSize(Context context, long size) {
return String.valueOf(size);
return formatFileSize(context, size);
}
public static String formatFileSize(Context context, long size) {
if (size > 1024 * 1024 * 1024) {
return String.format("%.1f GiB", size / 1024.0 / 1024.0 / 1024.0);
} else if (size > 1024 * 1024) {
return String.format("%.1f MiB", size / 1024.0 / 1024.0);
} else if (size > 1024) {
return String.format("%.1f KiB", size / 1024.0);
} else {
return String.format("%d B", size);
}
}
}

View File

@@ -4,5 +4,17 @@ import android.graphics.drawable.Drawable;
public class ImageSpan extends DynamicDrawableSpan {
public ImageSpan(Drawable d) {}
private Drawable drawable;
public ImageSpan(Drawable d) {
drawable = d;
}
public ImageSpan(Drawable d, String source) {
drawable = d;
}
public Drawable getDrawable() {
return drawable;
}
}