This commit is contained in:
dgis 2019-01-17 19:18:54 +00:00
parent 56f637d211
commit 2bf6c09550
9 changed files with 76 additions and 29 deletions

View file

@ -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

View file

@ -605,4 +605,4 @@ Button 126
End
End
Include "KEYB3940.KMI"
Include "keyb3940.kmi"

View file

@ -632,4 +632,4 @@ Button 128
End
End
Include "KEYB4950.KMI"
Include "keyb4950.kmi"

View file

@ -628,4 +628,4 @@ Button 128
End
End
Include "KEYB4950.KMI"
Include "keyb4950.kmi"

View file

@ -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);
}
}

View file

@ -21,9 +21,11 @@ public class MainScreenView extends SurfaceView {
protected static final String TAG = "MainScreenView";
private Bitmap bitmapMainScreen;
private HashMap<Integer, Integer> 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();
}
}

View file

@ -27,6 +27,15 @@
android:key="settings_alwaysdisplog"
android:title="Always Show KML Compilation Result"
android:defaultValue="true" />
<SwitchPreference
android:key="settings_allow_rotation"
android:title="Allow rotation"
android:defaultValue="false" />
<SwitchPreference
android:key="settings_fill_screen"
android:title="Fill screen"
android:defaultValue="false" />
</PreferenceCategory>
<!--<PreferenceCategory app:title="Style">
"Show Title",IDC_SHOWTITLE

View file

@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong

View file

@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#Thu Jan 17 15:25:15 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip