From 6e21cbf23dd624e043500677e0cb83c8d6f354c4 Mon Sep 17 00:00:00 2001 From: Martin Williams Date: Mon, 10 Jun 2024 15:59:18 +0100 Subject: [PATCH] Fetch MY_DATA --- app/src/main/AndroidManifest.xml | 6 + .../com/samsung/microbit/ui/FetchPopups.java | 113 ++ .../java/com/samsung/microbit/ui/UIUtils.java | 274 +++++ .../microbit/ui/activity/FetchActivity.java | 1002 +++++++++++++++++ .../microbit/ui/activity/PopUpActivity.java | 3 + .../microbit/ui/activity/ProjectActivity.java | 33 +- .../com/samsung/microbit/utils/BLEFetch.java | 622 ++++++++++ .../microbit/utils/MicroBitUtility.java | 229 ++++ .../res/drawable-hdpi/ic_discover_black.png | Bin 0 -> 5215 bytes app/src/main/res/drawable-hdpi/ic_fetch.png | Bin 0 -> 6652 bytes .../main/res/drawable-hdpi/ic_more_vdotw.png | Bin 0 -> 334 bytes .../res/drawable-ldpi/ic_discover_black.png | Bin 0 -> 5045 bytes app/src/main/res/drawable-ldpi/ic_fetch.png | Bin 0 -> 4993 bytes .../main/res/drawable-ldpi/ic_more_vdotw.png | Bin 0 -> 269 bytes .../res/drawable-mdpi/ic_discover_black.png | Bin 0 -> 5045 bytes app/src/main/res/drawable-mdpi/ic_fetch.png | Bin 0 -> 4992 bytes .../main/res/drawable-mdpi/ic_more_vdotw.png | Bin 0 -> 269 bytes app/src/main/res/drawable-mdpi/v2only.png | Bin 0 -> 17713 bytes .../res/drawable-xhdpi/ic_discover_black.png | Bin 0 -> 5342 bytes app/src/main/res/drawable-xhdpi/ic_fetch.png | Bin 0 -> 5158 bytes .../main/res/drawable-xhdpi/ic_more_vdotw.png | Bin 0 -> 424 bytes .../res/drawable-xxhdpi/ic_discover_black.png | Bin 0 -> 5555 bytes app/src/main/res/drawable-xxhdpi/ic_fetch.png | Bin 0 -> 7368 bytes .../res/drawable-xxhdpi/ic_more_vdotw.png | Bin 0 -> 630 bytes .../drawable-xxxhdpi/ic_discover_black.png | Bin 0 -> 5656 bytes .../main/res/drawable-xxxhdpi/ic_fetch.png | Bin 0 -> 6308 bytes .../res/drawable-xxxhdpi/ic_more_vdotw.png | Bin 0 -> 776 bytes .../main/res/drawable/fetch_select_gray.xml | 10 + app/src/main/res/layout-land/fetch_select.xml | 255 +++++ .../res/layout/custom_projects_button.xml | 24 - app/src/main/res/layout/fetch_main.xml | 15 + app/src/main/res/layout/fetch_select.xml | 220 ++++ app/src/main/res/layout/fetch_web.xml | 64 ++ app/src/main/res/layout/project_items.xml | 1 - app/src/main/res/layout/projects_app_bar.xml | 15 +- .../res/layout/view_projects_projects.xml | 26 +- app/src/main/res/values-land/dimens.xml | 8 +- .../main/res/values-sw360dp-land/dimens.xml | 2 + .../main/res/values-sw360dp-port/dimens.xml | 2 + .../main/res/values-sw600dp-land/dimens.xml | 6 +- .../main/res/values-sw600dp-port/dimens.xml | 4 + .../main/res/values-sw720dp-land/dimens.xml | 2 + .../main/res/values-sw720dp-port/dimens.xml | 2 + app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/dimens.xml | 9 +- app/src/main/res/values/strings.xml | 24 +- app/src/main/res/values/styles.xml | 7 + 47 files changed, 2931 insertions(+), 48 deletions(-) create mode 100644 app/src/main/java/com/samsung/microbit/ui/FetchPopups.java create mode 100644 app/src/main/java/com/samsung/microbit/ui/UIUtils.java create mode 100644 app/src/main/java/com/samsung/microbit/ui/activity/FetchActivity.java create mode 100644 app/src/main/java/com/samsung/microbit/utils/BLEFetch.java create mode 100644 app/src/main/java/com/samsung/microbit/utils/MicroBitUtility.java create mode 100644 app/src/main/res/drawable-hdpi/ic_discover_black.png create mode 100644 app/src/main/res/drawable-hdpi/ic_fetch.png create mode 100644 app/src/main/res/drawable-hdpi/ic_more_vdotw.png create mode 100644 app/src/main/res/drawable-ldpi/ic_discover_black.png create mode 100644 app/src/main/res/drawable-ldpi/ic_fetch.png create mode 100644 app/src/main/res/drawable-ldpi/ic_more_vdotw.png create mode 100644 app/src/main/res/drawable-mdpi/ic_discover_black.png create mode 100644 app/src/main/res/drawable-mdpi/ic_fetch.png create mode 100644 app/src/main/res/drawable-mdpi/ic_more_vdotw.png create mode 100644 app/src/main/res/drawable-mdpi/v2only.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_discover_black.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_fetch.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_more_vdotw.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_discover_black.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_fetch.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_more_vdotw.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_discover_black.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_fetch.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_more_vdotw.png create mode 100644 app/src/main/res/drawable/fetch_select_gray.xml create mode 100644 app/src/main/res/layout-land/fetch_select.xml delete mode 100644 app/src/main/res/layout/custom_projects_button.xml create mode 100644 app/src/main/res/layout/fetch_main.xml create mode 100644 app/src/main/res/layout/fetch_select.xml create mode 100644 app/src/main/res/layout/fetch_web.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 514d5085..a7fe46a7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -159,6 +159,12 @@ android:label="MakeCode Webview" android:launchMode="singleTask" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/> + + diff --git a/app/src/main/java/com/samsung/microbit/ui/FetchPopups.java b/app/src/main/java/com/samsung/microbit/ui/FetchPopups.java new file mode 100644 index 00000000..03b06496 --- /dev/null +++ b/app/src/main/java/com/samsung/microbit/ui/FetchPopups.java @@ -0,0 +1,113 @@ +package com.samsung.microbit.ui; + +import android.content.Context; +import android.util.Log; +import android.view.View; +import com.samsung.microbit.R; + +import static com.samsung.microbit.BuildConfig.DEBUG; + +public class FetchPopups { + private static final String TAG = FetchPopups.class.getSimpleName(); + + public void logi(String message) { + if(DEBUG) { + Log.i(TAG, "### " + Thread.currentThread().getId() + " # " + message); + } + } + + /** + * Callback interface for client + */ + public interface Client { + Context fetchPopupsContext(); + void fetchPopupsCancelled(); + void fetchPopupsRequestBluetoothConnectPermissions(); + } + + Client mClient = null; + + public FetchPopups ( Client client) { + mClient = client; + } + + View.OnClickListener popupClickActivityCancelled = new View.OnClickListener() { + @Override + public void onClick(View v) { + logi("popupClickActivityCancelled"); + PopUp.hide(); + mClient.fetchPopupsCancelled(); + } + }; + + public void busy() { + // Another download session is in progress.xml + PopUp.show(mClient.fetchPopupsContext().getString(R.string.multple_flashing_session_msg), + "", + R.drawable.error_face, R.drawable.blue_btn, + PopUp.GIFF_ANIMATION_FLASH, + PopUp.TYPE_ALERT, + popupClickActivityCancelled, popupClickActivityCancelled); + } + + public void bluetoothOff() { + PopUp.show(mClient.fetchPopupsContext().getString(R.string.bluetooth_off_cannot_continue), //message + "", + R.drawable.error_face, R.drawable.red_btn, + PopUp.GIFF_ANIMATION_ERROR, + PopUp.TYPE_ALERT, + popupClickActivityCancelled, popupClickActivityCancelled); + } + + public void bluetoothConnectPermissionError() { + PopUp.show(mClient.fetchPopupsContext().getString(R.string.ble_permission_connect_error), + mClient.fetchPopupsContext().getString(R.string.permissions_needed_title), + R.drawable.error_face, R.drawable.red_btn, + PopUp.GIFF_ANIMATION_ERROR, + PopUp.TYPE_ALERT, + popupClickActivityCancelled, popupClickActivityCancelled); + } + + public void bluetoothConnectRequest() { + PopUp.show(mClient.fetchPopupsContext().getString(R.string.ble_permission_connect), + mClient.fetchPopupsContext().getString(R.string.permissions_needed_title), + R.drawable.message_face, R.drawable.blue_btn, PopUp.GIFF_ANIMATION_NONE, + PopUp.TYPE_CHOICE, + new View.OnClickListener() { + @Override + public void onClick(View v) { + logi("bluetoothPermissionOKHandler"); + PopUp.hide(); + mClient.fetchPopupsRequestBluetoothConnectPermissions(); + } + }, + new View.OnClickListener() { + @Override + public void onClick(View v) { + logi("bluetoothPermissionCancelHandler"); + PopUp.hide(); + bluetoothConnectPermissionError(); + } + }); + } + + public void fetchFailed( String message) { + PopUp.show( message, + mClient.fetchPopupsContext().getString(R.string.fetchFailed), + R.drawable.error_face, R.drawable.red_btn, + PopUp.GIFF_ANIMATION_ERROR, + PopUp.TYPE_ALERT, + popupClickActivityCancelled, popupClickActivityCancelled); + } + + public void fetchProgress() { + PopUp.show("", + mClient.fetchPopupsContext().getString(R.string.fetching), + R.drawable.flash_face, + R.drawable.blue_btn, + PopUp.GIFF_ANIMATION_FLASH, + PopUp.TYPE_PROGRESS, + popupClickActivityCancelled, popupClickActivityCancelled); + } + +} diff --git a/app/src/main/java/com/samsung/microbit/ui/UIUtils.java b/app/src/main/java/com/samsung/microbit/ui/UIUtils.java new file mode 100644 index 00000000..a85a129b --- /dev/null +++ b/app/src/main/java/com/samsung/microbit/ui/UIUtils.java @@ -0,0 +1,274 @@ +package com.samsung.microbit.ui; + +import android.app.Activity; +import android.graphics.Point; +import android.graphics.Rect; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.util.Log; +import android.util.TypedValue; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowMetrics; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.TextView; + +import com.samsung.microbit.R; + +import static com.samsung.microbit.BuildConfig.DEBUG; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.IdRes; + +import pl.droidsonroids.gif.GifDrawable; +import pl.droidsonroids.gif.GifImageView; + +public class UIUtils { + private static final String TAG = UIUtils.class.getSimpleName(); + + public void logi(String message) { + if(DEBUG) { + Log.i(TAG, "### " + Thread.currentThread().getId() + " # " + message); + } + } + + /** + * Callback interface for client + */ + public interface Client { + Activity uiUtilsActivity(); + } + + Client mClient = null; + + public UIUtils ( Client client) { + mClient = client; + } + + @NonNull + public Point displayWindowSize() { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { + WindowMetrics wm = null; + wm = mClient.uiUtilsActivity().getWindowManager().getCurrentWindowMetrics(); + Rect r = wm.getBounds(); + return new Point( r.width(), r.height()); + } + Point s = new Point(); + mClient.uiUtilsActivity().getWindowManager().getDefaultDisplay().getSize(s); + return s; + } + + public float labelFontSize() + { + Point s = displayWindowSize(); + + float fh; + float fw; + if ( s.y > s.x) // portrait + { + fh = (float) (12 * s.y) / 480; + fw = (float) (12 * s.x) / 320; + } + else + { + fh = (float) (12 * s.y) / 320; + fw = (float) (12 * s.x) / 480; + } + float f = Math.min(fw, fh); + logi( "displayLabelFontSize " + (double)f + ", " + (double)fw + ", " + (double)fh); + return f; + } + + + public float headerFontSize() + { + Point s = displayWindowSize(); + + float fh; + float fw; + if ( s.y > s.x) // portrait + { + fh = (float) (14 * s.y) / 480; + fw = (float) (14 * s.x) / 320; + } + else + { + fh = (float) (14 * s.y) / 320; + fw = (float) (14 * s.x) / 480; + } + float f = Math.min(fw, fh); + logi( "displayHeaderFontSize " + (double)f + ", " + (double)fw + ", " + (double)fh); + return f; + } + + + public float buttonFontSize() + { + Point s = displayWindowSize(); + + float fh; + float fw; + if ( s.y > s.x) // portrait + { + fh = (float) (10 * s.y) / 480; + fw = (float) (10 * s.x) / 320; + } + else + { + fh = (float) (10 * s.y) / 320; + fw = (float) (10 * s.x) / 480; + } + float f = Math.min(fw, fh); + logi( "displayButtonFontSize " + (double)f + ", " + (double)fw + ", " + (double)fh); + return f; + } + + public float tinyButtonFontSize() + { + Point s = displayWindowSize(); + + float fh; + float fw; + if ( s.y > s.x) // portrait + { + fh = (float) (44 * s.y) / 1024; + fw = (float) (44 * s.x) / 768; + } + else + { + fh = (float) (44 * s.y) / 768; + fw = (float) (44 * s.x) / 1024; + } + float f = Math.min(fw, fh); + if ( f < 22) f = 22; + logi( "displayTinyButtonFontSize " + (double)f + ", " + (double)fw + ", " + (double)fh); + return f; + } + + public void setTypeface( View view, Typeface typeface) { + if ( view != null) { + if ( view instanceof Button) { + logi( "Button " + ((Button) view).getText() + " = " + typeface.toString()); + ((Button) view).setTypeface(typeface); + } else if ( view instanceof TextView) { + logi( "TextView " + ((TextView) view).getText() + " = " + typeface.toString()); + ((TextView) view).setTypeface(typeface); + } + } + } + + public void setFontSize( View view, float size) { + if ( view != null) { + if ( view instanceof Button) { + logi("Button " + ((Button) view).getText() + " = " + size); + ((Button) view).setTextSize( TypedValue.COMPLEX_UNIT_PX, size); + } else if ( view instanceof TextView) { + logi("TextView " + ((TextView) view).getText() + " = " + size); + ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, size); + } + } + } + + @Nullable + public T findViewById(@IdRes int id) { + return mClient.uiUtilsActivity().findViewById(id); + } + + public void setTypeface(@IdRes int id, Typeface typeface) { + setTypeface( findViewById(id), typeface); + } + + public void setFontSize( @IdRes int id, float size) { + setFontSize( findViewById(id), size); + } + + public void setTypefaces(ViewGroup parent, Typeface button, Typeface textview) { + Class