diff --git a/ReadMe.txt b/ReadMe.txt index 098789f..30ec34b 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -13,11 +13,10 @@ NOT WORKING TODO - Change the logo following the template -- Find a new open source package name +- Find a new open source package name (org.forty-eight.emulator) - Improve loading errors - Allows to see the errors in a log - Improve button support with HDC operations -- Option to allow rotation - Option to auto hide the menu - Open Emu48 with a state file shared with it (Can not work) @@ -51,3 +50,5 @@ DONE - Bug with android back button acts as the hp48 back button! - Add new KMLs and ROMs. - If KML not found in OpenDocument, allow to choose a new one +- Allow to fill the screen +- Option to allow rotation diff --git a/app/src/main/assets/calculators/real40gs-l.kml b/app/src/main/assets/calculators/real40gs-l.kml index 4fb0529..287581e 100644 --- a/app/src/main/assets/calculators/real40gs-l.kml +++ b/app/src/main/assets/calculators/real40gs-l.kml @@ -605,4 +605,4 @@ Button 126 End End -Include "KEYB3940.KMI" +Include "keyb3940.kmi" diff --git a/app/src/main/assets/calculators/real48gii-l.kml b/app/src/main/assets/calculators/real48gii-l.kml index b8bfd9f..28473cc 100644 --- a/app/src/main/assets/calculators/real48gii-l.kml +++ b/app/src/main/assets/calculators/real48gii-l.kml @@ -632,4 +632,4 @@ Button 128 End End -Include "KEYB4950.KMI" +Include "keyb4950.kmi" diff --git a/app/src/main/assets/calculators/real49gp-l.kml b/app/src/main/assets/calculators/real49gp-l.kml index c62ba2b..90a7c6e 100644 --- a/app/src/main/assets/calculators/real49gp-l.kml +++ b/app/src/main/assets/calculators/real49gp-l.kml @@ -628,4 +628,4 @@ Button 128 End End -Include "KEYB4950.KMI" +Include "keyb4950.kmi" diff --git a/app/src/main/java/com/regis/cosnier/emu48/MainActivity.java b/app/src/main/java/com/regis/cosnier/emu48/MainActivity.java index dbe6835..7dbe764 100644 --- a/app/src/main/java/com/regis/cosnier/emu48/MainActivity.java +++ b/app/src/main/java/com/regis/cosnier/emu48/MainActivity.java @@ -9,6 +9,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.graphics.Bitmap; @@ -64,8 +65,7 @@ import androidx.core.content.FileProvider; import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; -public class MainActivity extends AppCompatActivity - implements NavigationView.OnNavigationItemSelectedListener, SharedPreferences.OnSharedPreferenceChangeListener{ +public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, SharedPreferences.OnSharedPreferenceChangeListener { public static final int INTENT_GETOPENFILENAME = 1; public static final int INTENT_GETSAVEFILENAME = 2; @@ -80,6 +80,7 @@ public class MainActivity extends AppCompatActivity private SharedPreferences sharedPreferences; private NavigationView navigationView; private DrawerLayout drawer; + private MainScreenView mainScreenView; private final static int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 2; @@ -125,7 +126,7 @@ public class MainActivity extends AppCompatActivity ViewGroup mainScreenContainer = findViewById(R.id.main_screen_container); - MainScreenView mainScreenView = new MainScreenView(this); + mainScreenView = new MainScreenView(this); // mainScreenView.setOnTouchListener(new View.OnTouchListener() { // @Override // public boolean onTouch(View view, MotionEvent motionEvent) { @@ -143,6 +144,8 @@ public class MainActivity extends AppCompatActivity // }); toolbar.setVisibility(View.GONE); mainScreenContainer.addView(mainScreenView, 0); + mainScreenView.setFillScreen(sharedPreferences.getBoolean("settings_fill_screen", false)); + settingUpdateAllowRotation(); AssetManager assetManager = getResources().getAssets(); NativeLib.start(assetManager, mainScreenView.getBitmapMainScreen(), this, mainScreenView); @@ -1083,7 +1086,22 @@ public class MainActivity extends AppCompatActivity 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; } } } + + private void settingUpdateAllowRotation() { + if(sharedPreferences.getBoolean("settings_allow_rotation", false)) + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + else + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } } diff --git a/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java b/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java index 0c3e7e2..72a9cca 100644 --- a/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java +++ b/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java @@ -21,9 +21,11 @@ public class MainScreenView extends SurfaceView { protected static final String TAG = "MainScreenView"; private Bitmap bitmapMainScreen; private HashMap vkmap; - private float screenScale = 1.0f; + private float screenScaleX = 1.0f; + private float screenScaleY = 1.0f; private float screenOffsetX = 0.0f; private float screenOffsetY= 0.0f; + private boolean fillScreen = false; public MainScreenView(Context context) { super(context); @@ -137,14 +139,14 @@ public class MainScreenView extends SurfaceView { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: //Log.d(TAG, "ACTION_DOWN/ACTION_POINTER_DOWN count: " + touchCount + ", actionIndex: " + actionIndex); - NativeLib.buttonDown((int)((event.getX(actionIndex) - screenOffsetX) / screenScale), (int)((event.getY(actionIndex) - screenOffsetY) / screenScale)); + NativeLib.buttonDown((int)((event.getX(actionIndex) - screenOffsetX) / screenScaleX), (int)((event.getY(actionIndex) - screenOffsetY) / screenScaleY)); break; // case MotionEvent.ACTION_MOVE: // break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: //Log.d(TAG, "ACTION_UP/ACTION_POINTER_UP count: " + touchCount + ", actionIndex: " + actionIndex); - NativeLib.buttonUp((int)((event.getX(actionIndex) - screenOffsetX) / screenScale), (int)((event.getY(actionIndex) - screenOffsetY) / screenScale)); + NativeLib.buttonUp((int)((event.getX(actionIndex) - screenOffsetX) / screenScaleX), (int)((event.getY(actionIndex) - screenOffsetY) / screenScaleY)); break; // case MotionEvent.ACTION_CANCEL: // break; @@ -210,20 +212,26 @@ public class MainScreenView extends SurfaceView { if(imageSizeX > 0 && imageSizeY > 0 && viewWidth > 0.0f && viewHeight > 0.0f) { // Find the scale factor and the translate offset to fit and to center the image in the view bounds. - float translateX, translateY, scale; - float viewRatio = (float)viewHeight / (float)viewWidth; - float imageRatio = imageSizeY / imageSizeX; - if(viewRatio > imageRatio) { - scale = viewWidth / imageSizeX; - translateX = 0.0f; - translateY = (viewHeight - scale * imageSizeY) / 2.0f; + float translateX = 0.0f, translateY = 0.0f, scaleX, scaleY; + if(fillScreen) { + scaleX = viewWidth / imageSizeX; + scaleY = viewHeight / imageSizeY; } else { - scale = viewHeight / imageSizeY; - translateX = (viewWidth - scale * imageSizeX) / 2.0f; - translateY = 0.0f; + float viewRatio = (float)viewHeight / (float)viewWidth; + float imageRatio = imageSizeY / imageSizeX; + if(viewRatio > imageRatio) { + scaleX = scaleY = viewWidth / imageSizeX; + translateX = 0.0f; + translateY = (viewHeight - scaleY * imageSizeY) / 2.0f; + } else { + scaleX = scaleY = viewHeight / imageSizeY; + translateX = (viewWidth - scaleX * imageSizeX) / 2.0f; + translateY = 0.0f; + } } - screenScale = scale; + screenScaleX = scaleX; + screenScaleY = scaleY; screenOffsetX = translateX; screenOffsetY = translateY; } @@ -234,7 +242,7 @@ public class MainScreenView extends SurfaceView { //Log.d(TAG, "onDraw() mIsScaling: " + mIsScaling + ", mIsPanning: " + mIsPanning + ", mIsFlinging: " + mIsFlinging); canvas.save(); canvas.translate(screenOffsetX, screenOffsetY); - canvas.scale(screenScale, screenScale); + canvas.scale(screenScaleX, screenScaleY); canvas.drawBitmap(bitmapMainScreen, 0, 0, null); canvas.restore(); } @@ -260,4 +268,14 @@ public class MainScreenView extends SurfaceView { public Bitmap getBitmapMainScreen() { return bitmapMainScreen; } + + public boolean getFillScreen() { + return fillScreen; + } + + public void setFillScreen(boolean fillScreen) { + this.fillScreen = fillScreen; + calcTranslateAndScale(getWidth(), getHeight()); + postInvalidate(); + } } diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 94c4511..ec5ca76 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -27,6 +27,15 @@ android:key="settings_alwaysdisplog" android:title="Always Show KML Compilation Result" android:defaultValue="true" /> + + +