fixed stuff

This commit is contained in:
2026-10-02 16:31:25 -04:00
parent 1a5252f48d
commit 0b0b0410fa
3 changed files with 45 additions and 24 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);

View File

@@ -52,18 +52,22 @@
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" />
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="409dp"
android:layout_height="649dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/nextButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textPine4">
app:layout_constraintTop_toBottomOf="@+id/textView5">
<LinearLayout
android:layout_width="match_parent"
@@ -74,7 +78,6 @@
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Preview of file"
android:textColor="@color/white" />
</LinearLayout>