mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 08:38:03 -06:00
Add team icons and colored cards
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package com.ridgebotics.ridgescout.utility;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
// https://stackoverflow.com/questions/37510411/download-an-image-into-bitmap-file-in-android
|
||||
public class ImageRequestTask extends AsyncTask<String, Void, Bitmap> {
|
||||
|
||||
Function<Bitmap, Void> resultFunction = null;
|
||||
public static Bitmap getBitmapFromURL(String src) {
|
||||
try {
|
||||
URL url = new URL(src);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.connect();
|
||||
InputStream input = connection.getInputStream();
|
||||
return BitmapFactory.decodeStream(input);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null;
|
||||
} catch (IOException e){
|
||||
AlertManager.error("Error downloading image " + src, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Bitmap doInBackground(String... params) {
|
||||
return getBitmapFromURL(params[0]);
|
||||
}
|
||||
|
||||
public void onResult(Function<Bitmap, Void> func) {
|
||||
this.resultFunction = func;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Bitmap result) {
|
||||
super.onPostExecute(result);
|
||||
if(resultFunction != null){
|
||||
resultFunction.apply(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ridgebotics.ridgescout.utility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.ridgebotics.ridgescout.types.frcEvent;
|
||||
import com.ridgebotics.ridgescout.types.frcTeam;
|
||||
@@ -401,8 +403,13 @@ public final class fileEditor {
|
||||
return filenames;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// https://stackoverflow.com/questions/7620401/how-to-convert-image-file-data-in-a-byte-array-to-a-bitmap
|
||||
// public static String imageToBitMap(byte[] data) throws IOException {
|
||||
// Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
||||
// return bitmap;
|
||||
// ByteArrayOutputStream blob = new ByteArrayOutputStream();
|
||||
// bitmap.compress(Bitmap.CompressFormat.PNG, 0 /* Ignored for PNGs */, blob);
|
||||
// }
|
||||
|
||||
|
||||
public static boolean setTeams(Context context, String key, ArrayList<frcTeam> teams){
|
||||
|
||||
Reference in New Issue
Block a user