mirror of
https://github.com/dgis/emu48android
synced 2024-12-26 09:58:49 +01:00
This commit is contained in:
parent
ae82c3d4b5
commit
537e9238b5
3 changed files with 62 additions and 12 deletions
|
@ -69,17 +69,32 @@ void mainViewResizeCallback(int x, int y) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fillNullCharacter(const OPENFILENAME *ofn) {
|
TCHAR * fillNullCharacter(TCHAR * fileFilter) {
|
||||||
TCHAR * pos = ofn->lpstrFilter;
|
TCHAR * pos = fileFilter;
|
||||||
|
int length = 0;
|
||||||
if(pos) {
|
if(pos) {
|
||||||
for (;;) {
|
for (;; pos++, length++) {
|
||||||
if (*pos == 0) {
|
if (*pos == 0) {
|
||||||
*pos = _T("|");
|
if (*(pos + 1) == 0)
|
||||||
if (*(pos + 1) = 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TCHAR * newFileFilter = malloc(length + 1);
|
||||||
|
TCHAR * newPos = newFileFilter;
|
||||||
|
pos = fileFilter;
|
||||||
|
for (;; pos++, newPos++) {
|
||||||
|
if (*pos == 0) {
|
||||||
|
*newPos = _T('|');
|
||||||
|
if (*(pos + 1) == 0) {
|
||||||
|
*(newPos + 1) = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
*newPos = *pos;
|
||||||
|
}
|
||||||
|
return newFileFilter;
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mainViewGetOpenFileNameCallback(OPENFILENAME * ofn) {
|
int mainViewGetOpenFileNameCallback(OPENFILENAME * ofn) {
|
||||||
|
@ -101,13 +116,15 @@ int mainViewGetOpenFileNameCallback(OPENFILENAME * ofn) {
|
||||||
//
|
//
|
||||||
// ofn->nMaxFile = ARRAYSIZEOF(szBuffer);
|
// ofn->nMaxFile = ARRAYSIZEOF(szBuffer);
|
||||||
// ofn->lpstrFile = szBuffer;
|
// ofn->lpstrFile = szBuffer;
|
||||||
fillNullCharacter(ofn);
|
TCHAR * lpstrFilter = fillNullCharacter(ofn->lpstrFilter);
|
||||||
mainViewCallback(CALLBACK_TYPE_GETOPENFILENAME, ofn->nFilterIndex, ofn->Flags, ofn->lpstrFilter, ofn->lpstrDefExt);
|
mainViewCallback(CALLBACK_TYPE_GETOPENFILENAME, ofn->nFilterIndex, ofn->Flags, lpstrFilter, ofn->lpstrDefExt);
|
||||||
|
free(lpstrFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mainViewGetSaveFileNameCallback(OPENFILENAME * ofn) {
|
int mainViewGetSaveFileNameCallback(OPENFILENAME * ofn) {
|
||||||
fillNullCharacter(ofn);
|
TCHAR * lpstrFilter = fillNullCharacter(ofn->lpstrFilter);
|
||||||
mainViewCallback(CALLBACK_TYPE_GETSAVEFILENAME, ofn->nFilterIndex, ofn->Flags, ofn->lpstrFilter, ofn->lpstrDefExt);
|
mainViewCallback(CALLBACK_TYPE_GETSAVEFILENAME, ofn->nFilterIndex, ofn->Flags, lpstrFilter, ofn->lpstrDefExt);
|
||||||
|
free(lpstrFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,7 +146,10 @@ int mainViewCallback(int type, int param1, int param2, const TCHAR * param3, con
|
||||||
jclass viewToUpdateClass = (*jniEnv)->GetObjectClass(jniEnv, viewToUpdate);
|
jclass viewToUpdateClass = (*jniEnv)->GetObjectClass(jniEnv, viewToUpdate);
|
||||||
//jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, viewToUpdateClass, "updateCallback", "()V");
|
//jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, viewToUpdateClass, "updateCallback", "()V");
|
||||||
jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, viewToUpdateClass, "updateCallback", "(IIILjava/lang/String;Ljava/lang/String;)I");
|
jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, viewToUpdateClass, "updateCallback", "(IIILjava/lang/String;Ljava/lang/String;)I");
|
||||||
int result = (*jniEnv)->CallIntMethod(jniEnv, viewToUpdate, midStr, type, param1, param2, param3, param4);
|
jstring utfParam3 = (*jniEnv)->NewStringUTF(jniEnv, param3);
|
||||||
|
jstring utfParam4 = (*jniEnv)->NewStringUTF(jniEnv, param4);
|
||||||
|
int result = (*jniEnv)->CallIntMethod(jniEnv, viewToUpdate, midStr, type, param1, param2, utfParam3, utfParam4);
|
||||||
|
|
||||||
// if(needDetach)
|
// if(needDetach)
|
||||||
// ret = (*java_machine)->DetachCurrentThread(java_machine);
|
// ret = (*java_machine)->DetachCurrentThread(java_machine);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
package com.regis.cosnier.emu48;
|
package com.regis.cosnier.emu48;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.google.android.material.navigation.NavigationView;
|
import com.google.android.material.navigation.NavigationView;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
@ -17,11 +21,16 @@ import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity
|
public class MainActivity extends AppCompatActivity
|
||||||
implements NavigationView.OnNavigationItemSelectedListener {
|
implements NavigationView.OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
private static final int INTENT_SETTINGS = 1;
|
private static final int INTENT_SETTINGS = 1;
|
||||||
|
private static final String TAG = "MainActivity";
|
||||||
private MainScreenView mainScreenView;
|
private MainScreenView mainScreenView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,4 +231,25 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||||
|
if(requestCode == MainScreenView.INTENT_GETSAVEFILENAME && resultCode == Activity.RESULT_OK) {
|
||||||
|
Uri uri = data.getData();
|
||||||
|
|
||||||
|
//just as an example, I am writing a String to the Uri I received from the user:
|
||||||
|
Log.d(TAG, "onActivityResult INTENT_GETSAVEFILENAME " + uri.toString());
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// OutputStream output = getContentResolver().openOutputStream(uri);
|
||||||
|
//
|
||||||
|
// output.write(SOME_CONTENT.getBytes());
|
||||||
|
// output.close();
|
||||||
|
// }
|
||||||
|
// catch(IOException e) {
|
||||||
|
// Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,7 +243,7 @@ public class MainScreenView extends SurfaceView {
|
||||||
final int CALLBACK_TYPE_GETOPENFILENAME = 2;
|
final int CALLBACK_TYPE_GETOPENFILENAME = 2;
|
||||||
final int CALLBACK_TYPE_GETSAVEFILENAME = 3;
|
final int CALLBACK_TYPE_GETSAVEFILENAME = 3;
|
||||||
|
|
||||||
final int INTENT_GETSAVEFILENAME = 1;
|
public static int INTENT_GETSAVEFILENAME = 1;
|
||||||
int updateCallback(int type, int param1, int param2, String param3, String param4) {
|
int updateCallback(int type, int param1, int param2, String param3, String param4) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CALLBACK_TYPE_INVALIDATE:
|
case CALLBACK_TYPE_INVALIDATE:
|
||||||
|
@ -259,7 +259,7 @@ public class MainScreenView extends SurfaceView {
|
||||||
case CALLBACK_TYPE_GETSAVEFILENAME:
|
case CALLBACK_TYPE_GETSAVEFILENAME:
|
||||||
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
intent.setType("YOUR FILETYPE"); //not needed, but maybe usefull
|
//intent.setType("YOUR FILETYPE"); //not needed, but maybe usefull
|
||||||
intent.putExtra(Intent.EXTRA_TITLE, "YOUR FILENAME"); //not needed, but maybe usefull
|
intent.putExtra(Intent.EXTRA_TITLE, "YOUR FILENAME"); //not needed, but maybe usefull
|
||||||
((Activity)getContext()).startActivityForResult(intent, INTENT_GETSAVEFILENAME);
|
((Activity)getContext()).startActivityForResult(intent, INTENT_GETSAVEFILENAME);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue