mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-20 05:20:14 -07:00
Load a config and smaller scale steps
This commit is contained in:
parent
a0afe5d587
commit
b09dddfb56
5 changed files with 178 additions and 107 deletions
|
|
@ -1,20 +1,85 @@
|
|||
package net.kdt.pojavlaunch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.FileUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Switch;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class SettingsMenu extends Activity {
|
||||
|
||||
private static final int FILE_SELECT_CODE = 0;
|
||||
|
||||
private void showFileChooser() {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("*/*");
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
|
||||
try {
|
||||
startActivityForResult(
|
||||
Intent.createChooser(intent, "Select a File to Upload"),
|
||||
FILE_SELECT_CODE);
|
||||
} catch (android.content.ActivityNotFoundException ex) {
|
||||
// Potentially direct the user to the Market with a Dialog
|
||||
Toast.makeText(this, "Please install a File Manager.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case FILE_SELECT_CODE:
|
||||
if (resultCode == RESULT_OK) {
|
||||
// Get the Uri of the selected file
|
||||
Uri uri = data.getData();
|
||||
Log.d("TAG", "File Uri: " + uri.toString());
|
||||
// Get the path
|
||||
Log.d("TAG", "File Path: " + uri.getPath());
|
||||
// Get the file instance
|
||||
File config = new File(getFilesDir(), "config.json");
|
||||
try {
|
||||
Log.d("TAG", "Starting copy: " + uri.getPath());
|
||||
InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(config);
|
||||
byte buf[]=new byte[1024];
|
||||
int len;
|
||||
while((len=inputStream.read(buf))>0) {
|
||||
fileOutputStream.write(buf,0,len);
|
||||
}
|
||||
fileOutputStream.close();
|
||||
inputStream.close();
|
||||
System.out.println("Wrote new config to Local");
|
||||
} catch (IOException e1) {
|
||||
Log.d("error", "Error with file " + e1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -28,6 +93,23 @@ public class SettingsMenu extends Activity {
|
|||
final EditText username = findViewById(R.id.username);
|
||||
final EditText password = findViewById(R.id.password);
|
||||
final Switch righthanded = findViewById(R.id.righthanded);
|
||||
final Button loadConfig = findViewById(R.id.loadconfig);
|
||||
|
||||
loadConfig.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
switch(event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
Log.i("Pressed","Button");
|
||||
showFileChooser();
|
||||
return true; // if you want to handle the touch event
|
||||
case MotionEvent.ACTION_UP:
|
||||
// RELEASED
|
||||
return true; // if you want to handle the touch event
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//For storing string value in sharedPreference
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue