From 0b0b0410faf9c94a383f59b6f51a360b5ec095fb Mon Sep 17 00:00:00 2001 From: wildercayden Date: Fri, 2 Oct 2026 16:31:25 -0400 Subject: [PATCH] fixed stuff --- .../com/example/generator/EndActivity.java | 52 +++++++++++++------ .../com/example/generator/MainActivity.java | 2 +- .../app/src/main/res/layout/activity_end.xml | 15 +++--- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/Generator/app/src/main/java/com/example/generator/EndActivity.java b/Generator/app/src/main/java/com/example/generator/EndActivity.java index 8db18b1a..29dd0621 100644 --- a/Generator/app/src/main/java/com/example/generator/EndActivity.java +++ b/Generator/app/src/main/java/com/example/generator/EndActivity.java @@ -1,10 +1,15 @@ package com.example.generator; +import android.content.ContentValues; import android.content.Intent; import android.content.res.ColorStateList; +import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.provider.MediaStore; import android.widget.TextView; +import android.widget.Toast; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; @@ -19,10 +24,8 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; import java.io.IOException; +import java.io.OutputStream; public class EndActivity extends AppCompatActivity { @@ -61,7 +64,6 @@ public class EndActivity extends AppCompatActivity { jsonObject.put("ColorP", ColorP); jsonObject.put("ColorS", ColorS); jsonObject.put("startingPositions", EventsActivity.Data.getNumPos()); - jsonObject.put("Base64", EventsActivity.Data.getBase64()); jsonObject.put("eventn1", EventsActivity.Data.getEventn1()); jsonObject.put("eventa1", EventsActivity.Data.getEventa1()); jsonObject.put("eventn2", EventsActivity.Data.getEventn2()); @@ -90,23 +92,41 @@ public class EndActivity extends AppCompatActivity { jsonObject.put("CheckBox3", EventsActivity.Data.getCheckBox3()); jsonObject.put("CheckBox4", EventsActivity.Data.getCheckBox4()); jsonObject.put("climbLevels", EventsActivity.Data.getClimbLevels()); - String jsonString = jsonObject.toString(4); TextView textView = findViewById(R.id.textView4); textView.setText(jsonString); + jsonObject.put("Base64", EventsActivity.Data.getBase64()); + jsonString = jsonObject.toString(4); + ContentValues values = new ContentValues(); + values.put(MediaStore.MediaColumns.DISPLAY_NAME, "ScountInfo.json"); + values.put(MediaStore.MediaColumns.MIME_TYPE, "json/plain"); - File downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); - File file = new File(downloadDir, "ScountInfo.json"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS); + } + Uri externalUri; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + externalUri = MediaStore.Downloads.EXTERNAL_CONTENT_URI; + } else { + externalUri = MediaStore.Files.getContentUri("external"); + } - FileWriter fileWriter = new FileWriter(file); - BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); - bufferedWriter.write(jsonString); - bufferedWriter.close(); - } catch (JSONException e) { - throw new RuntimeException(e); - } catch (IOException e) { + Uri fileUri = getContentResolver().insert(externalUri, values); + + if (fileUri != null) { + try (OutputStream outputStream = getContentResolver().openOutputStream(fileUri)) { + if (outputStream != null) { + outputStream.write(jsonString.getBytes()); + outputStream.flush(); + Toast.makeText(this, "File saved to Downloads", Toast.LENGTH_SHORT).show(); + } + } + } else { + throw new IOException(); + } + } catch (JSONException | IOException e) { throw new RuntimeException(e); } }); @@ -131,7 +151,5 @@ public class EndActivity extends AppCompatActivity { nextButton.setStrokeWidth(0); backButton.setStrokeWidth(0); } - - } -} \ No newline at end of file +} diff --git a/Generator/app/src/main/java/com/example/generator/MainActivity.java b/Generator/app/src/main/java/com/example/generator/MainActivity.java index fa0bcaf8..583616df 100644 --- a/Generator/app/src/main/java/com/example/generator/MainActivity.java +++ b/Generator/app/src/main/java/com/example/generator/MainActivity.java @@ -40,7 +40,7 @@ public class MainActivity extends AppCompatActivity { startActivity(intent); }); Button DebugButton = (Button) findViewById(R.id.Debug); - //DebugButton.setVisibility(View.GONE); + DebugButton.setVisibility(View.GONE); DebugButton.setOnClickListener((v) -> { Intent intent = new Intent(this, DebugActivity.class); startActivity(intent); diff --git a/Generator/app/src/main/res/layout/activity_end.xml b/Generator/app/src/main/res/layout/activity_end.xml index 2ad8e491..1a277adc 100644 --- a/Generator/app/src/main/res/layout/activity_end.xml +++ b/Generator/app/src/main/res/layout/activity_end.xml @@ -52,29 +52,32 @@ android:id="@+id/textView5" android:layout_width="match_parent" android:layout_height="wrap_content" + android:text="Preview of file (without base64 image)" android:textAlignment="center" android:textColor="@color/white" - tools:layout_editor_absoluteX="1dp" - tools:layout_editor_absoluteY="53dp" /> + app:layout_constraintBottom_toTopOf="@+id/scrollView2" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textPine4" /> + app:layout_constraintTop_toBottomOf="@+id/textView5"> + android:orientation="vertical">