This commit is contained in:
parent
8d6db0ca1e
commit
72ddaacff6
4 changed files with 139 additions and 18 deletions
|
@ -4,7 +4,7 @@ android {
|
|||
compileSdkVersion 28
|
||||
defaultConfig {
|
||||
applicationId "org.emulator.forty.eight"
|
||||
minSdkVersion 19
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
|
|
@ -66,7 +66,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
public static final int INTENT_OBJECT_SAVE = 4;
|
||||
public static final int INTENT_SETTINGS = 5;
|
||||
public static final int INTENT_PORT2LOAD = 6;
|
||||
public static final int INTENT_PICK_KML_FILE = 7;
|
||||
public static final int INTENT_PICK_KML_FOLDER = 7;
|
||||
public static final int INTENT_PICK_KML_FILE = 8;
|
||||
|
||||
public static MainActivity mainActivity;
|
||||
|
||||
|
@ -556,12 +557,28 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if(which == lastIndex) {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
// Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
// //intent.setType("file/*");
|
||||
// //intent.setType("*/*");
|
||||
// intent.setType("application/vnd.google-earth.kml+xml");
|
||||
// intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
||||
// startActivityForResult(intent, INTENT_PICK_KML_FILE);
|
||||
//Intent intent = new Intent(Intent.ACTION_PICK);
|
||||
//Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
//Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Files.);
|
||||
//intent.setType("file/*");
|
||||
//intent.setType("*/*");
|
||||
intent.setType("application/vnd.google-earth.kml+xml");
|
||||
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
||||
startActivityForResult(intent, INTENT_PICK_KML_FILE);
|
||||
|
||||
// Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
// intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
// intent.setType("application/vnd.google-earth.kml+xml");
|
||||
// intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
||||
// startActivityForResult(intent, INTENT_PICK_KML_FILE);
|
||||
|
||||
//https://github.com/googlesamples/android-DirectorySelection
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
startActivityForResult(intent, INTENT_PICK_KML_FOLDER);
|
||||
|
||||
} else {
|
||||
String kmlScriptFilename = kmlScripts.get(which).filename;
|
||||
newFileFromKML(kmlScriptFilename);
|
||||
|
@ -820,8 +837,19 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
}
|
||||
case INTENT_SETTINGS:
|
||||
break;
|
||||
case INTENT_PICK_KML_FILE:
|
||||
Log.d(TAG, "onActivityResult INTENT_OBJECT_SAVE " + url);
|
||||
// case INTENT_PICK_KML_FILE:
|
||||
// Log.d(TAG, "onActivityResult INTENT_PICK_KML_FILE " + url);
|
||||
// String filePath = Utils.getFilePath(this, url);
|
||||
// newFileFromKML(filePath);
|
||||
// break;
|
||||
case INTENT_PICK_KML_FOLDER:
|
||||
Log.d(TAG, "onActivityResult INTENT_PICK_KML_FOLDER " + url);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putBoolean("settings_kml_default", false);
|
||||
editor.putString("settings_kml_folder", url);
|
||||
editor.apply();
|
||||
makeUriPersistableReadOnly(data, uri);
|
||||
|
||||
String filePath = Utils.getFilePath(this, url);
|
||||
newFileFromKML(filePath);
|
||||
break;
|
||||
|
@ -847,6 +875,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
getContentResolver().takePersistableUriPermission(uri, takeFlags);
|
||||
}
|
||||
private void makeUriPersistableReadOnly(Intent data, Uri uri) {
|
||||
//grantUriPermission(getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
getContentResolver().takePersistableUriPermission(uri, takeFlags);
|
||||
}
|
||||
|
||||
|
||||
private int onFileOpen(String url) {
|
||||
int result = NativeLib.onFileOpen(url);
|
||||
|
@ -1065,7 +1099,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
private void updateFromPreferences(String key, boolean isDynamic) {
|
||||
int isDynamicValue = isDynamic ? 1 : 0;
|
||||
if(key == null) {
|
||||
String[] settingKeys = { "settings_realspeed", "settings_grayscale", "settings_port1", "settings_port2" };
|
||||
String[] settingKeys = { "settings_realspeed", "settings_grayscale", "settings_kml", "settings_port1", "settings_port2" };
|
||||
for (String settingKey : settingKeys) {
|
||||
updateFromPreferences(settingKey, false);
|
||||
}
|
||||
|
@ -1077,6 +1111,27 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
case "settings_grayscale":
|
||||
NativeLib.setConfiguration(key, isDynamicValue, sharedPreferences.getBoolean(key, false) ? 1 : 0, 0, null);
|
||||
break;
|
||||
|
||||
case "settings_allow_rotation":
|
||||
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
|
||||
settingUpdateAllowRotation();
|
||||
break;
|
||||
case "settings_fill_screen":
|
||||
mainScreenView.setFillScreen(sharedPreferences.getBoolean("settings_fill_screen", false));
|
||||
break;
|
||||
|
||||
case "settings_kml":
|
||||
case "settings_kml_default":
|
||||
case "settings_kml_folder":
|
||||
boolean useDefaultKMLFolder = sharedPreferences.getBoolean("settings_kml_default", true);
|
||||
if(!useDefaultKMLFolder) {
|
||||
String kmlFolderURL = sharedPreferences.getString("settings_kml_folder", "");
|
||||
// https://github.com/googlesamples/android-DirectorySelection
|
||||
// https://stackoverflow.com/questions/44185477/intent-action-open-document-tree-doesnt-seem-to-return-a-real-path-to-drive/44185706
|
||||
// https://stackoverflow.com/questions/26744842/how-to-use-the-new-sd-card-access-api-presented-for-android-5-0-lollipop
|
||||
}
|
||||
break;
|
||||
|
||||
case "settings_port1":
|
||||
case "settings_port1en":
|
||||
case "settings_port1wr":
|
||||
|
@ -1094,14 +1149,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
sharedPreferences.getBoolean("settings_port2wr", false) ? 1 : 0,
|
||||
sharedPreferences.getString("settings_port2load", ""));
|
||||
break;
|
||||
|
||||
case "settings_allow_rotation":
|
||||
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
|
||||
settingUpdateAllowRotation();
|
||||
break;
|
||||
case "settings_fill_screen":
|
||||
mainScreenView.setFillScreen(sharedPreferences.getBoolean("settings_fill_screen", false));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -267,6 +267,49 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
preferenceAlwaysdisplog.setOnPreferenceChangeListener(onPreferenceChangeListenerAlwaysdisplog);
|
||||
onPreferenceChangeListenerAlwaysdisplog.onPreferenceChange(preferenceAlwaysdisplog, sharedPreferences.getBoolean(preferenceAlwaysdisplog.getKey(), false));
|
||||
|
||||
|
||||
// KML settings
|
||||
|
||||
final Preference preferenceKMLDefault = findPreference("settings_kml_default");
|
||||
final Preference preferenceKMLFolder = findPreference("settings_kml_folder");
|
||||
|
||||
Preference.OnPreferenceChangeListener onPreferenceChangeListenerKMLDefault = new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
Boolean booleanValue = (Boolean)value;
|
||||
String stringValue = value.toString();
|
||||
preference.setSummary(stringValue);
|
||||
preferenceKMLFolder.setEnabled(booleanValue);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
preferenceKMLDefault.setOnPreferenceChangeListener(onPreferenceChangeListenerKMLDefault);
|
||||
onPreferenceChangeListenerKMLDefault.onPreferenceChange(preferenceKMLDefault, sharedPreferences.getBoolean(preferenceKMLDefault.getKey(), true));
|
||||
|
||||
Preference.OnPreferenceChangeListener onPreferenceChangeListenerKMLFolder = new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
String stringValue = value.toString();
|
||||
String displayName = stringValue;
|
||||
try {
|
||||
displayName = Utils.getFileName(getActivity(), stringValue);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
preference.setSummary(displayName);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
preferenceKMLFolder.setOnPreferenceChangeListener(onPreferenceChangeListenerKMLFolder);
|
||||
onPreferenceChangeListenerKMLFolder.onPreferenceChange(preferenceKMLFolder, sharedPreferences.getString(preferenceKMLFolder.getKey(), ""));
|
||||
preferenceKMLFolder.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
startActivityForResult(intent, MainActivity.INTENT_PICK_KML_FOLDER);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// Ports 1 & 2 settings
|
||||
|
||||
final Preference preferencePort1en = findPreference("settings_port1en");
|
||||
|
@ -377,8 +420,15 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
String url = uri.toString();
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("settings_port2load", url);
|
||||
editor.commit();
|
||||
editor.apply();
|
||||
makeUriPersistable(data, uri);
|
||||
} else if(requestCode == MainActivity.INTENT_PICK_KML_FOLDER) {
|
||||
Uri uri = data.getData();
|
||||
String url = uri.toString();
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("settings_kml_folder", url);
|
||||
editor.apply();
|
||||
makeUriPersistableReadOnly(data, uri);
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
@ -389,4 +439,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
getContentResolver().takePersistableUriPermission(uri, takeFlags);
|
||||
}
|
||||
private void makeUriPersistableReadOnly(Intent data, Uri uri) {
|
||||
//grantUriPermission(getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
getContentResolver().takePersistableUriPermission(uri, takeFlags);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,26 @@
|
|||
android:key="settings_fill_screen"
|
||||
android:title="Fill screen"
|
||||
android:defaultValue="false" />
|
||||
<Preference
|
||||
android:key="settings_kml_folder"
|
||||
android:title="Custom KML Folder"
|
||||
android:summary=""
|
||||
/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="General">
|
||||
<SwitchPreference
|
||||
android:key="settings_kml_default"
|
||||
android:title="Default Internal KML Folder"
|
||||
android:defaultValue="true" />
|
||||
<Preference
|
||||
android:key="settings_kml_folder"
|
||||
android:title="Custom KML Folder"
|
||||
android:summary=""
|
||||
/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<!--<PreferenceCategory app:title="Style">
|
||||
"Show Title",IDC_SHOWTITLE
|
||||
"Show Menu",IDC_SHOWMENU
|
||||
|
|
Loading…
Reference in a new issue