This commit is contained in:
dgis 2018-12-18 19:29:06 +00:00
parent 76ccb7c9c4
commit 95dcba492c
5 changed files with 325 additions and 225 deletions

View file

@ -13,7 +13,7 @@ NOT WORKING
- Serial Ports (Wire or Ir)
TODO
- Change settings per settings
- Autosave
- Support 8bits images
- Put the KML title in the header of the menu in the drawer
- Bug: No refresh with the clock
@ -29,3 +29,4 @@ DONE
- Choose KML/Change KML/NewDocument
- Load/Save object
- Permission issues when reopening document after an OS restart
- Change settings per settings

View file

@ -65,12 +65,13 @@ BOOL SetCurrentDirectory(LPCTSTR path)
HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPVOID lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, LPVOID hTemplateFile)
{
BOOL forceNormalFile = FALSE;
if(_tcscmp(lpFileName, szPort2Filename) == 0) {
// Special case for Port2 filename
//TODO
forceNormalFile = TRUE;
}
if(szCurrentDirectorySet || _tcsncmp(lpFileName, assetsPrefix, assetsPrefixLength / sizeof(TCHAR)) == 0) {
if(!forceNormalFile && (szCurrentDirectorySet || _tcsncmp(lpFileName, assetsPrefix, assetsPrefixLength / sizeof(TCHAR)) == 0)) {
TCHAR szFileName[MAX_PATH];
AAsset * asset = NULL;
szFileName[0] = _T('\0');
@ -190,7 +191,7 @@ DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) {
*lpFileSizeHigh = 0;
if(hFile->handleType == HANDLE_TYPE_FILE) {
off_t currentPosition = lseek(hFile->fileDescriptor, 0, SEEK_CUR);
off_t fileLength = lseek(hFile->fileDescriptor, 0, SEEK_END) + 1;
off_t fileLength = lseek(hFile->fileDescriptor, 0, SEEK_END); // + 1;
lseek(hFile->fileDescriptor, currentPosition, SEEK_SET);
return fileLength;
} else if(hFile->handleType == HANDLE_TYPE_FILE_ASSET) {
@ -211,7 +212,7 @@ HANDLE CreateFileMapping(HANDLE hFile, LPSECURITY_ATTRIBUTES lpFileMappingAttrib
handle->handleType = HANDLE_TYPE_FILE_MAPPING_ASSET;
handle->fileAsset = hFile->fileAsset;
}
handle->fileMappingSize = (dwMaximumSizeHigh << 32) & dwMaximumSizeLow;
handle->fileMappingSize = (dwMaximumSizeHigh << 32) | dwMaximumSizeLow;
handle->fileMappingAddress = NULL;
return handle;
}

View file

@ -1,15 +1,22 @@
package com.regis.cosnier.emu48;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MotionEvent;
@ -45,7 +52,15 @@ import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private static final int INTENT_SETTINGS = 1;
public static final int INTENT_GETOPENFILENAME = 1;
public static final int INTENT_GETSAVEFILENAME = 2;
public static final int INTENT_OBJECT_LOAD = 3;
public static final int INTENT_OBJECT_SAVE = 4;
public static final int INTENT_SETTINGS = 5;
public static final int INTENT_PORT2LOAD = 6;
public static MainActivity mainActivity;
private static final String TAG = "MainActivity";
private MainScreenView mainScreenView;
SharedPreferences sharedPreferences;
@ -80,6 +95,8 @@ public class MainActivity extends AppCompatActivity
mainActivity = this;
ViewGroup mainScreenContainer = (ViewGroup)findViewById(R.id.main_screen_container);
mainScreenView = new MainScreenView(this); //, currentProject);
@ -101,7 +118,7 @@ public class MainActivity extends AppCompatActivity
toolbar.setVisibility(View.GONE);
mainScreenContainer.addView(mainScreenView, 0);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
updateFromPreferences(null, false);
sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
@ -332,11 +349,6 @@ public class MainActivity extends AppCompatActivity
}).show();
}
public static int INTENT_GETOPENFILENAME = 1;
public static int INTENT_GETSAVEFILENAME = 2;
public static int INTENT_OBJECT_LOAD = 3;
public static int INTENT_OBJECT_SAVE = 4;
private void OnFileOpen() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
@ -379,21 +391,40 @@ public class MainActivity extends AppCompatActivity
startActivityForResult(new Intent(this, SettingsActivity.class), INTENT_SETTINGS);
}
private void OnObjectLoad() {
private void openDocument() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
// //Intent.setType("application/*|text/*");
// String[] mimeTypes = {
// "text/plain",
// "application/pdf",
// "application/zip"
// };
// intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
// String[] mimeTypes = {
// "text/plain",
// "application/pdf",
// "application/zip"
// };
// intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
intent.putExtra(Intent.EXTRA_TITLE, "emu48-object.hp");
startActivityForResult(intent, INTENT_OBJECT_LOAD);
}
//NativeLib.onObjectLoad();
private void OnObjectLoad() {
if(sharedPreferences.getBoolean("settings_objectloadwarning", false)) {
DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
openDocument();
}
}
};
new AlertDialog.Builder(this)
.setMessage("Warning: Trying to load an object while the emulator is busy\n" +
"will certainly result in a memory lost. Before loading an object\n" +
"you should be sure that the calculator is in idle state.\n" +
"Do you want to see this warning next time you try to load an object?")
.setPositiveButton(android.R.string.yes, onClickListener)
.setNegativeButton(android.R.string.no, onClickListener)
.show();
} else
openDocument();
}
private void OnObjectSave() {
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
@ -401,9 +432,6 @@ public class MainActivity extends AppCompatActivity
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TITLE, "emu48-object.hp");
startActivityForResult(intent, INTENT_OBJECT_SAVE);
//NativeLib.onObjectSave();
}
private void OnViewCopy() {
NativeLib.onViewCopy();
@ -498,6 +526,8 @@ public class MainActivity extends AppCompatActivity
String url = uri.toString();
NativeLib.onObjectSave(url);
} else if(requestCode == INTENT_SETTINGS) {
}
}
super.onActivityResult(requestCode, resultCode, data);
@ -519,7 +549,7 @@ public class MainActivity extends AppCompatActivity
if(sharedPreferences.getBoolean("settings_alwaysdisplog", true)) {
String kmlLog = NativeLib.getKMLLog();
new AlertDialog.Builder(this)
.setTitle("Pick a calculator")
.setTitle("KML Script Compilation Result")
.setMessage(kmlLog)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@ -554,7 +584,6 @@ public class MainActivity extends AppCompatActivity
if(key == null) {
// boolean settingsAutosave = sharedPreferences.getBoolean("settings_autosave", false);
// boolean settingsAutosaveonexit = sharedPreferences.getBoolean("settings_autosaveonexit", false);
// boolean settingsObjectloadwarning = sharedPreferences.getBoolean("settings_objectloadwarning", false);
String[] settingKeys = { "settings_realspeed", "settings_grayscale", "settings_alwaysdisplog", "settings_port1", "settings_port2" };
for (String settingKey : settingKeys) {
updateFromPreferences(settingKey, false);

View file

@ -1,10 +1,12 @@
package com.regis.cosnier.emu48;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
@ -12,8 +14,10 @@ import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MenuItem;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.core.app.NavUtils;
@ -30,6 +34,38 @@ import androidx.core.app.NavUtils;
*/
public class SettingsActivity extends AppCompatPreferenceActivity {
private static final String TAG = "SettingsActivity";
private static SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
getFragmentManager().beginTransaction().replace(android.R.id.content, new GeneralPreferenceFragment()).commit();
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
if (!super.onMenuItemSelected(featureId, item)) {
NavUtils.navigateUpFromSameTask(this);
}
return true;
}
return super.onMenuItemSelected(featureId, item);
}
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
@ -69,91 +105,48 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToStringValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(preference.getContext());
// Trigger the listener immediately with the preference's
// current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, sharedPreferences.getString(preference.getKey(), ""));
}
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToIntValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(preference.getContext());
// Trigger the listener immediately with the preference's
// current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, sharedPreferences.getInt(preference.getKey(), 0));
}
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToBoolValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(preference.getContext());
// Trigger the listener immediately with the preference's
// current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, sharedPreferences.getBoolean(preference.getKey(), false));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
getFragmentManager().beginTransaction().replace(android.R.id.content, new GeneralPreferenceFragment()).commit();
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
if (!super.onMenuItemSelected(featureId, item)) {
NavUtils.navigateUpFromSameTask(this);
}
return true;
}
return super.onMenuItemSelected(featureId, item);
}
// /**
// * Binds a preference's summary to its value. More specifically, when the
// * preference's value is changed, its summary (line of text below the
// * preference title) is updated to reflect the value. The summary is also
// * immediately updated upon calling this method. The exact display format is
// * dependent on the type of preference.
// *
// * @see #sBindPreferenceSummaryToValueListener
// */
// private static void bindPreferenceSummaryToStringValue(Preference preference) {
// preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, sharedPreferences.getString(preference.getKey(), ""));
// }
//
// /**
// * Binds a preference's summary to its value. More specifically, when the
// * preference's value is changed, its summary (line of text below the
// * preference title) is updated to reflect the value. The summary is also
// * immediately updated upon calling this method. The exact display format is
// * dependent on the type of preference.
// *
// * @see #sBindPreferenceSummaryToValueListener
// */
// private static void bindPreferenceSummaryToIntValue(Preference preference) {
// preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, sharedPreferences.getInt(preference.getKey(), 0));
// }
//
// /**
// * Binds a preference's summary to its value. More specifically, when the
// * preference's value is changed, its summary (line of text below the
// * preference title) is updated to reflect the value. The summary is also
// * immediately updated upon calling this method. The exact display format is
// * dependent on the type of preference.
// *
// * @see #sBindPreferenceSummaryToValueListener
// */
// private static void bindPreferenceSummaryToBoolValue(Preference preference) {
// // Set the listener to watch for value changes.
// preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, sharedPreferences.getBoolean(preference.getKey(), false));
// }
/**
* {@inheritDoc}
@ -196,33 +189,164 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
addPreferencesFromResource(R.xml.pref_general);
setHasOptionsMenu(true);
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
// bindPreferenceSummaryToStringValue(findPreference("settings_input"));
// bindPreferenceSummaryToIntValue(findPreference("settings_audio_input"));
bindPreferenceSummaryToBoolValue(findPreference("settings_realspeed"));
bindPreferenceSummaryToBoolValue(findPreference("settings_grayscale"));
// bindPreferenceSummaryToBoolValue(findPreference("settings_alwaysontop"));
// bindPreferenceSummaryToBoolValue(findPreference("settings_actfollowsmouse"));
// bindPreferenceSummaryToBoolValue(findPreference("settings_singleinstance"));
bindPreferenceSummaryToBoolValue(findPreference("settings_autosave"));
bindPreferenceSummaryToBoolValue(findPreference("settings_autosaveonexit"));
bindPreferenceSummaryToBoolValue(findPreference("settings_objectloadwarning"));
bindPreferenceSummaryToBoolValue(findPreference("settings_alwaysdisplog"));
bindPreferenceSummaryToBoolValue(findPreference("settings_port1en"));
bindPreferenceSummaryToBoolValue(findPreference("settings_port1wr"));
bindPreferenceSummaryToBoolValue(findPreference("settings_port2en"));
bindPreferenceSummaryToBoolValue(findPreference("settings_port2wr"));
// General settings
boolean disablePortPreferences = (NativeLib.getIsPortExtensionPossible() == 0);
//TODO not working
findPreference("settings_port1en").setShouldDisableView(disablePortPreferences);
findPreference("settings_port1wr").setShouldDisableView(disablePortPreferences);
findPreference("settings_port2en").setShouldDisableView(disablePortPreferences);
findPreference("settings_port2wr").setShouldDisableView(disablePortPreferences);
Preference preferenceRealspeed = findPreference("settings_realspeed");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerRealspeed = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceRealspeed.setOnPreferenceChangeListener(onPreferenceChangeListenerRealspeed);
onPreferenceChangeListenerRealspeed.onPreferenceChange(preferenceRealspeed, sharedPreferences.getBoolean(preferenceRealspeed.getKey(), false));
Preference preferenceGrayscale = findPreference("settings_grayscale");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerGrayscale = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceGrayscale.setOnPreferenceChangeListener(onPreferenceChangeListenerGrayscale);
onPreferenceChangeListenerGrayscale.onPreferenceChange(preferenceGrayscale, sharedPreferences.getBoolean(preferenceGrayscale.getKey(), false));
Preference preferenceAutosave = findPreference("settings_autosave");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerAutosave = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceAutosave.setOnPreferenceChangeListener(onPreferenceChangeListenerAutosave);
onPreferenceChangeListenerAutosave.onPreferenceChange(preferenceAutosave, sharedPreferences.getBoolean(preferenceAutosave.getKey(), false));
Preference preferenceAutosaveonexit = findPreference("settings_autosaveonexit");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerAutosaveonexit = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceAutosaveonexit.setOnPreferenceChangeListener(onPreferenceChangeListenerAutosaveonexit);
onPreferenceChangeListenerAutosaveonexit.onPreferenceChange(preferenceAutosaveonexit, sharedPreferences.getBoolean(preferenceAutosaveonexit.getKey(), false));
Preference preferenceObjectloadwarning = findPreference("settings_objectloadwarning");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerObjectloadwarning = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceObjectloadwarning.setOnPreferenceChangeListener(onPreferenceChangeListenerObjectloadwarning);
onPreferenceChangeListenerObjectloadwarning.onPreferenceChange(preferenceObjectloadwarning, sharedPreferences.getBoolean(preferenceObjectloadwarning.getKey(), false));
Preference preferenceAlwaysdisplog = findPreference("settings_alwaysdisplog");
Preference.OnPreferenceChangeListener onPreferenceChangeListenerAlwaysdisplog = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferenceAlwaysdisplog.setOnPreferenceChangeListener(onPreferenceChangeListenerAlwaysdisplog);
onPreferenceChangeListenerAlwaysdisplog.onPreferenceChange(preferenceAlwaysdisplog, sharedPreferences.getBoolean(preferenceAlwaysdisplog.getKey(), false));
// Ports 1 & 2 settings
final Preference preferencePort1en = findPreference("settings_port1en");
final Preference preferencePort1wr = findPreference("settings_port1wr");
final Preference preferencePort2en = findPreference("settings_port2en");
final Preference preferencePort2wr = findPreference("settings_port2wr");
final Preference preferencePort2load = findPreference("settings_port2load");
final boolean enablePortPreferences = !(NativeLib.getIsPortExtensionPossible() == 0);
Preference.OnPreferenceChangeListener onPreferenceChangeListenerPort1en = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
Boolean booleanValue = (Boolean)value;
String stringValue = value.toString();
preference.setSummary(stringValue);
preferencePort1en.setEnabled(enablePortPreferences);
preferencePort1wr.setEnabled(enablePortPreferences && booleanValue.booleanValue());
return true;
}
};
preferencePort1en.setOnPreferenceChangeListener(onPreferenceChangeListenerPort1en);
onPreferenceChangeListenerPort1en.onPreferenceChange(preferencePort1en, sharedPreferences.getBoolean(preferencePort1en.getKey(), false));
Preference.OnPreferenceChangeListener onPreferenceChangeListenerPort1wr = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferencePort1wr.setOnPreferenceChangeListener(onPreferenceChangeListenerPort1wr);
onPreferenceChangeListenerPort1wr.onPreferenceChange(preferencePort1wr, sharedPreferences.getBoolean(preferencePort1wr.getKey(), false));
Preference.OnPreferenceChangeListener onPreferenceChangeListenerPort2en = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
Boolean booleanValue = (Boolean)value;
String stringValue = value.toString();
preference.setSummary(stringValue);
preferencePort2en.setEnabled(enablePortPreferences);
preferencePort2wr.setEnabled(enablePortPreferences && booleanValue.booleanValue());
preferencePort2load.setEnabled(enablePortPreferences && booleanValue.booleanValue());
return true;
}
};
preferencePort2en.setOnPreferenceChangeListener(onPreferenceChangeListenerPort2en);
onPreferenceChangeListenerPort2en.onPreferenceChange(preferencePort2en, sharedPreferences.getBoolean(preferencePort2en.getKey(), false));
Preference.OnPreferenceChangeListener onPreferenceChangeListenerPort2wr = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferencePort2wr.setOnPreferenceChangeListener(onPreferenceChangeListenerPort2wr);
onPreferenceChangeListenerPort2wr.onPreferenceChange(preferencePort2wr, sharedPreferences.getBoolean(preferencePort2wr.getKey(), false));
Preference.OnPreferenceChangeListener onPreferenceChangeListenerPort2load = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
preference.setSummary(stringValue);
return true;
}
};
preferencePort2load.setOnPreferenceChangeListener(onPreferenceChangeListenerPort2load);
onPreferenceChangeListenerPort2load.onPreferenceChange(preferencePort2load, sharedPreferences.getString(preferencePort2load.getKey(), ""));
preferencePort2load.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
//intent.setType("YOUR FILETYPE"); //not needed, but maybe usefull
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TITLE, "shared.bin");
getActivity().startActivityForResult(intent, MainActivity.INTENT_PORT2LOAD);
return true;
}
});
}
@Override
@ -235,4 +359,26 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
return super.onOptionsItemSelected(item);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if(resultCode == Activity.RESULT_OK) {
if(requestCode == MainActivity.INTENT_PORT2LOAD) {
Uri uri = data.getData();
//Log.d(TAG, "onActivityResult INTENT_PORT2LOAD " + uri.toString());
String url = uri.toString();
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("settings_port2load", url);
editor.commit();
makeUriPersistable(data, uri);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
private void makeUriPersistable(Intent data, Uri uri) {
//grantUriPermission(getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(uri, takeFlags);
}
}

View file

@ -1,90 +1,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--<ListPreference-->
<!--android:key="settings_input"-->
<!--android:defaultValue="0"-->
<!--android:title="@string/settings_input_title"-->
<!--android:entries="@array/settings_input_list_titles"-->
<!--android:entryValues="@array/settings_input_list_values"-->
<!--android:negativeButtonText="@null"-->
<!--android:positiveButtonText="@null"-->
<!--/>-->
<!--<ListPreference-->
<!--android:key="settings_audio_engine"-->
<!--android:defaultValue="0"-->
<!--android:title="@string/settings_audio_engine_title"-->
<!--android:entries="@array/settings_audio_engine_list_titles"-->
<!--android:entryValues="@array/settings_audio_engine_list_values"-->
<!--android:negativeButtonText="@null"-->
<!--android:positiveButtonText="@null"-->
<!--/>-->
<!--<com.regis.cosnier.emu48.AudioDeviceSpinnerPreference-->
<!--android:key="settings_audio_input"-->
<!--android:defaultValue="0"-->
<!--android:title="@string/settings_audio_input_title"-->
<!--android:dialogMessage="@string/settings_audio_input_title_dialog"-->
<!--/>-->
<!--<ListPreference-->
<!--android:key="settings_sample_rate"-->
<!--android:defaultValue="48000"-->
<!--android:title="@string/settings_sample_rate_title"-->
<!--android:entries="@array/settings_sample_rate_list_titles"-->
<!--android:entryValues="@array/settings_sample_rate_list_values"-->
<!--android:negativeButtonText="@null"-->
<!--android:positiveButtonText="@null"-->
<!--/>-->
<!--<ListPreference-->
<!--android:key="settings_fft_size"-->
<!--android:defaultValue="1024"-->
<!--android:title="@string/settings_fft_size_title"-->
<!--android:entries="@array/settings_fft_size_list_titles"-->
<!--android:entryValues="@array/settings_fft_size_list_values"-->
<!--android:negativeButtonText="@null"-->
<!--android:positiveButtonText="@null"-->
<!--/>-->
<!--<com.regis.cosnier.emu48.SeekBarPreference-->
<!--android:key="settings_volume_scale"-->
<!--android:title="@string/settings_volume_scale_title"-->
<!--android:dialogMessage="@string/settings_volume_scale_title"-->
<!--android:defaultValue="0"-->
<!--app:suffix="@string/settings_volume_scale_suffix"-->
<!--app:suffixes="@string/settings_volume_scale_suffixes"-->
<!--app:min="-1000"-->
<!--android:max="1000"-->
<!--/>-->
<!--<com.regis.cosnier.emu48.SeekBarPreference-->
<!--android:key="settings_tempo"-->
<!--android:title="settings_tempo_title"-->
<!--android:dialogMessage="settings_tempo_title"-->
<!--android:defaultValue="96"-->
<!--app:min="20"-->
<!--android:max="200"-->
<!--/>-->
<!--<com.regis.cosnier.emu48.SeekBarPreference-->
<!--android:key="settings_intensity_minimum"-->
<!--android:title="@string/settings_intensity_minimum_title"-->
<!--android:dialogMessage="@string/settings_intensity_minimum_title"-->
<!--android:defaultValue="20"-->
<!--app:min="1"-->
<!--android:max="90"-->
<!--/>-->
<!--<com.regis.cosnier.emu48.SeekBarPreference-->
<!--android:key="settings_translation"-->
<!--android:title="@string/settings_translation_title"-->
<!--android:dialogMessage="@string/settings_translation_title"-->
<!--android:defaultValue="0"-->
<!--app:min="-60"-->
<!--android:max="60"-->
<!--/>-->
<!-- General -->
<PreferenceCategory app:title="General">
<SwitchPreference
@ -138,21 +54,28 @@
<SwitchPreference
android:key="settings_port1en"
android:title="Port 1 is Plugged"
android:defaultValue="false" />
android:defaultValue="false"
/>
<SwitchPreference
android:key="settings_port1wr"
android:title="Port 1 is Writeable"
android:defaultValue="false" />
android:defaultValue="false"
/>
<SwitchPreference
android:key="settings_port2en"
android:title="Port 2 is Plugged"
android:defaultValue="false" />
android:defaultValue="false"
/>
<SwitchPreference
android:key="settings_port2wr"
android:title="Port 2 is Writeable"
android:defaultValue="false" />
<!--"Port 2 File :",IDC_STATIC,14,47,37,8-->
<!--"...",IDC_PORT2LOAD,227,45,10,12-->
android:defaultValue="false"
/>
<Preference
android:key="settings_port2load"
android:title="Port 2 File"
android:summary=""
/>
</PreferenceCategory>
<!-- Peripheral -->