fixed stuff
This commit is contained in:
@@ -1,10 +1,15 @@
|
|||||||
package com.example.generator;
|
package com.example.generator;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.activity.EdgeToEdge;
|
import androidx.activity.EdgeToEdge;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@@ -19,10 +24,8 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
public class EndActivity extends AppCompatActivity {
|
public class EndActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@@ -61,7 +64,6 @@ public class EndActivity extends AppCompatActivity {
|
|||||||
jsonObject.put("ColorP", ColorP);
|
jsonObject.put("ColorP", ColorP);
|
||||||
jsonObject.put("ColorS", ColorS);
|
jsonObject.put("ColorS", ColorS);
|
||||||
jsonObject.put("startingPositions", EventsActivity.Data.getNumPos());
|
jsonObject.put("startingPositions", EventsActivity.Data.getNumPos());
|
||||||
jsonObject.put("Base64", EventsActivity.Data.getBase64());
|
|
||||||
jsonObject.put("eventn1", EventsActivity.Data.getEventn1());
|
jsonObject.put("eventn1", EventsActivity.Data.getEventn1());
|
||||||
jsonObject.put("eventa1", EventsActivity.Data.getEventa1());
|
jsonObject.put("eventa1", EventsActivity.Data.getEventa1());
|
||||||
jsonObject.put("eventn2", EventsActivity.Data.getEventn2());
|
jsonObject.put("eventn2", EventsActivity.Data.getEventn2());
|
||||||
@@ -90,23 +92,41 @@ public class EndActivity extends AppCompatActivity {
|
|||||||
jsonObject.put("CheckBox3", EventsActivity.Data.getCheckBox3());
|
jsonObject.put("CheckBox3", EventsActivity.Data.getCheckBox3());
|
||||||
jsonObject.put("CheckBox4", EventsActivity.Data.getCheckBox4());
|
jsonObject.put("CheckBox4", EventsActivity.Data.getCheckBox4());
|
||||||
jsonObject.put("climbLevels", EventsActivity.Data.getClimbLevels());
|
jsonObject.put("climbLevels", EventsActivity.Data.getClimbLevels());
|
||||||
|
|
||||||
String jsonString = jsonObject.toString(4);
|
String jsonString = jsonObject.toString(4);
|
||||||
TextView textView = findViewById(R.id.textView4);
|
TextView textView = findViewById(R.id.textView4);
|
||||||
textView.setText(jsonString);
|
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);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
File file = new File(downloadDir, "ScountInfo.json");
|
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);
|
Uri fileUri = getContentResolver().insert(externalUri, values);
|
||||||
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
|
|
||||||
bufferedWriter.write(jsonString);
|
if (fileUri != null) {
|
||||||
bufferedWriter.close();
|
try (OutputStream outputStream = getContentResolver().openOutputStream(fileUri)) {
|
||||||
} catch (JSONException e) {
|
if (outputStream != null) {
|
||||||
throw new RuntimeException(e);
|
outputStream.write(jsonString.getBytes());
|
||||||
} catch (IOException e) {
|
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);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -131,7 +151,5 @@ public class EndActivity extends AppCompatActivity {
|
|||||||
nextButton.setStrokeWidth(0);
|
nextButton.setStrokeWidth(0);
|
||||||
backButton.setStrokeWidth(0);
|
backButton.setStrokeWidth(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
});
|
});
|
||||||
Button DebugButton = (Button) findViewById(R.id.Debug);
|
Button DebugButton = (Button) findViewById(R.id.Debug);
|
||||||
//DebugButton.setVisibility(View.GONE);
|
DebugButton.setVisibility(View.GONE);
|
||||||
DebugButton.setOnClickListener((v) -> {
|
DebugButton.setOnClickListener((v) -> {
|
||||||
Intent intent = new Intent(this, DebugActivity.class);
|
Intent intent = new Intent(this, DebugActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|||||||
@@ -52,29 +52,32 @@
|
|||||||
android:id="@+id/textView5"
|
android:id="@+id/textView5"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Preview of file (without base64 image)"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
tools:layout_editor_absoluteX="1dp"
|
app:layout_constraintBottom_toTopOf="@+id/scrollView2"
|
||||||
tools:layout_editor_absoluteY="53dp" />
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/textPine4" />
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
|
android:id="@+id/scrollView2"
|
||||||
android:layout_width="409dp"
|
android:layout_width="409dp"
|
||||||
android:layout_height="649dp"
|
android:layout_height="0dp"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/nextButton"
|
app:layout_constraintBottom_toTopOf="@+id/nextButton"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textPine4">
|
app:layout_constraintTop_toBottomOf="@+id/textView5">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView4"
|
android:id="@+id/textView4"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Preview of file"
|
|
||||||
android:textColor="@color/white" />
|
android:textColor="@color/white" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user