Begin to add a custom background color.
This commit is contained in:
parent
1af35b0986
commit
4ddaf75ce0
8 changed files with 145 additions and 119 deletions
|
@ -292,7 +292,9 @@ static __inline VOID AdjustSpeed(VOID) // adjust emulation speed
|
|||
{
|
||||
DWORD dwCycles,dwTicks;
|
||||
|
||||
EnterCriticalSection(&csSlowLock);
|
||||
LOGD("bEnableSlow: %d, bCpuSlow: %d, bKeySlow: %d, bSoundSlow: %d, nOpcSlow: %d", bEnableSlow, bCpuSlow, bKeySlow, bSoundSlow, nOpcSlow);
|
||||
|
||||
EnterCriticalSection(&csSlowLock);
|
||||
{
|
||||
// cycles elapsed for next check
|
||||
if ((dwCycles = (DWORD) (Chipset.cycles & 0xFFFFFFFF)-dwOldCyc) >= dwT2Cycles)
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
package org.emulator.forty.eight;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
/**
|
||||
* A {@link PreferenceActivity} which implements and proxies the necessary calls
|
||||
* to be used with AppCompat.
|
||||
*/
|
||||
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
|
||||
|
||||
private AppCompatDelegate mDelegate;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
getDelegate().installViewFactory();
|
||||
getDelegate().onCreate(savedInstanceState);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
getDelegate().onPostCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
public ActionBar getSupportActionBar() {
|
||||
return getDelegate().getSupportActionBar();
|
||||
}
|
||||
|
||||
public void setSupportActionBar(@Nullable Toolbar toolbar) {
|
||||
getDelegate().setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuInflater getMenuInflater() {
|
||||
return getDelegate().getMenuInflater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(@LayoutRes int layoutResID) {
|
||||
getDelegate().setContentView(layoutResID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view) {
|
||||
getDelegate().setContentView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
||||
getDelegate().setContentView(view, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addContentView(View view, ViewGroup.LayoutParams params) {
|
||||
getDelegate().addContentView(view, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
getDelegate().onPostResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTitleChanged(CharSequence title, int color) {
|
||||
super.onTitleChanged(title, color);
|
||||
getDelegate().setTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
getDelegate().onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
getDelegate().onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
getDelegate().onDestroy();
|
||||
}
|
||||
|
||||
public void invalidateOptionsMenu() {
|
||||
getDelegate().invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private AppCompatDelegate getDelegate() {
|
||||
if (mDelegate == null) {
|
||||
mDelegate = AppCompatDelegate.create(this, null);
|
||||
}
|
||||
return mDelegate;
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import android.view.MenuItem;
|
|||
import android.view.SubMenu;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -112,14 +113,15 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
mainActivity = this;
|
||||
|
||||
|
||||
ViewGroup mainScreenContainer = findViewById(R.id.main_screen_container);
|
||||
mainScreenView = new MainScreenView(this);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
mainScreenView.setStatusBarColor(getWindow().getStatusBarColor());
|
||||
}
|
||||
|
||||
toolbar.setVisibility(View.GONE);
|
||||
mainScreenContainer.addView(mainScreenView, 0);
|
||||
|
@ -1201,6 +1203,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
String[] settingKeys = {
|
||||
"settings_realspeed", "settings_grayscale", "settings_allow_rotation", "settings_fill_screen",
|
||||
"settings_scale", "settings_allow_sound", "settings_haptic_feedback",
|
||||
"settings_background_kml_color", "settings_background_fallback_color",
|
||||
"settings_kml", "settings_port1", "settings_port2" };
|
||||
for (String settingKey : settingKeys) {
|
||||
updateFromPreferences(settingKey, false);
|
||||
|
@ -1236,6 +1239,16 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
// Nothing to do
|
||||
break;
|
||||
|
||||
case "settings_background_kml_color":
|
||||
mainScreenView.setBackgroundKmlColor(sharedPreferences.getBoolean("settings_background_kml_color", false));
|
||||
break;
|
||||
case "settings_background_fallback_color":
|
||||
String fallbackColor = sharedPreferences.getString("settings_background_fallback_color", "0");
|
||||
try {
|
||||
mainScreenView.setBackgroundFallbackColor(Integer.parseInt(fallbackColor));
|
||||
} catch (NumberFormatException ex) {}
|
||||
break;
|
||||
|
||||
case "settings_kml":
|
||||
case "settings_kml_default":
|
||||
case "settings_kml_folder":
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.graphics.Canvas;
|
|||
import android.graphics.Color;
|
||||
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -28,7 +29,10 @@ public class MainScreenView extends SurfaceView {
|
|||
private float screenOffsetY= 0.0f;
|
||||
private boolean fillScreen = false;
|
||||
private float fixScale = 0.0f;
|
||||
private int backgroundColor = Color.BLACK;
|
||||
private int kmlBackgroundColor = Color.BLACK;
|
||||
private boolean useKmlBackgroundColor = false;
|
||||
private int fallbackBackgroundColorType = 0;
|
||||
private int statusBarColor = 0;
|
||||
|
||||
public MainScreenView(Context context) {
|
||||
super(context);
|
||||
|
@ -223,7 +227,7 @@ public class MainScreenView extends SurfaceView {
|
|||
protected void onDraw(Canvas canvas) {
|
||||
//Log.d(TAG, "Emu48-PAINT onDraw() mIsScaling: " + mIsScaling + ", mIsPanning: " + mIsPanning + ", mIsFlinging: " + mIsFlinging);
|
||||
|
||||
canvas.drawColor(backgroundColor);
|
||||
canvas.drawColor(getBackgroundColor());
|
||||
|
||||
canvas.save();
|
||||
canvas.translate(screenOffsetX, screenOffsetY);
|
||||
|
@ -248,8 +252,9 @@ public class MainScreenView extends SurfaceView {
|
|||
Bitmap oldBitmapMainScreen = bitmapMainScreen;
|
||||
bitmapMainScreen = Bitmap.createBitmap(Math.max(1, param1), Math.max(1, param2), Bitmap.Config.ARGB_8888);
|
||||
int globalColor = NativeLib.getGlobalColor();
|
||||
backgroundColor = Color.argb(255, (globalColor & 0x00FF0000) >> 16, (globalColor & 0x0000FF00) >> 8, globalColor & 0x000000FF);
|
||||
bitmapMainScreen.eraseColor(backgroundColor);
|
||||
kmlBackgroundColor = Color.argb(255, (globalColor & 0x00FF0000) >> 16, (globalColor & 0x0000FF00) >> 8, globalColor & 0x000000FF);
|
||||
|
||||
bitmapMainScreen.eraseColor(getBackgroundColor());
|
||||
NativeLib.changeBitmap(bitmapMainScreen);
|
||||
|
||||
if(oldBitmapMainScreen != null) {
|
||||
|
@ -277,4 +282,32 @@ public class MainScreenView extends SurfaceView {
|
|||
calcTranslateAndScale(getWidth(), getHeight());
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
public void setBackgroundKmlColor(boolean useKmlBackgroundColor) {
|
||||
this.useKmlBackgroundColor = useKmlBackgroundColor;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
public void setBackgroundFallbackColor(int fallbackBackgroundColorType) {
|
||||
this.fallbackBackgroundColorType = fallbackBackgroundColorType;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
public void setStatusBarColor(int statusBarColor) {
|
||||
this.statusBarColor = statusBarColor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private int getBackgroundColor() {
|
||||
if(useKmlBackgroundColor) {
|
||||
return kmlBackgroundColor;
|
||||
} else switch(fallbackBackgroundColorType) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return statusBarColor;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,12 +115,56 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere
|
|||
addPreferencesFromResource(R.xml.pref_general);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// Sound settings
|
||||
|
||||
Preference preferenceAllowSound = findPreference("settings_allow_sound");
|
||||
if(preferenceAllowSound != null && !NativeLib.getSoundEnabled()) {
|
||||
preferenceAllowSound.setSummary("Cannot initialize the sound engine.");
|
||||
preferenceAllowSound.setEnabled(false);
|
||||
}
|
||||
|
||||
// Background color settings
|
||||
|
||||
Preference preferenceBackgroundFallbackColor = findPreference("settings_background_fallback_color");
|
||||
// final ColorPickerPreferenceCompat preferenceBackgroundCustomColor = (ColorPickerPreferenceCompat)findPreference("settings_background_custom_color");
|
||||
if(preferenceBackgroundFallbackColor != null /*&& preferenceBackgroundCustomColor != null*/) {
|
||||
final String[] stringArrayBackgroundFallbackColor = getResources().getStringArray(R.array.settings_background_fallback_color_item);
|
||||
Preference.OnPreferenceChangeListener onPreferenceChangeListenerBackgroundFallbackColor = new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
if(value != null) {
|
||||
String stringValue = value.toString();
|
||||
int backgroundFallbackColor = -1;
|
||||
try {
|
||||
backgroundFallbackColor = Integer.parseInt(stringValue);
|
||||
} catch (NumberFormatException ex) {}
|
||||
if(backgroundFallbackColor >= 0 && backgroundFallbackColor < stringArrayBackgroundFallbackColor.length)
|
||||
preference.setSummary(stringArrayBackgroundFallbackColor[backgroundFallbackColor]);
|
||||
// preferenceBackgroundCustomColor.setEnabled(backgroundFallbackColor == 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
preferenceBackgroundFallbackColor.setOnPreferenceChangeListener(onPreferenceChangeListenerBackgroundFallbackColor);
|
||||
onPreferenceChangeListenerBackgroundFallbackColor.onPreferenceChange(preferenceBackgroundFallbackColor,
|
||||
sharedPreferences.getString(preferenceBackgroundFallbackColor.getKey(), "0"));
|
||||
|
||||
|
||||
//preferenceBackgroundCustomColor.setColorValue(customColor);
|
||||
|
||||
// Preference.OnPreferenceChangeListener onPreferenceChangeListenerBackgroundCustomColor = new Preference.OnPreferenceChangeListener() {
|
||||
// @Override
|
||||
// public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
// if(value != null) {
|
||||
// int customColor = (Integer)value;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// };
|
||||
// preferenceBackgroundCustomColor.setOnPreferenceChangeListener(onPreferenceChangeListenerBackgroundCustomColor);
|
||||
// onPreferenceChangeListenerBackgroundCustomColor.onPreferenceChange(preferenceBackgroundCustomColor, sharedPreferences.getBoolean(preferenceBackgroundCustomColor.getKey(), false));
|
||||
}
|
||||
|
||||
// Ports 1 & 2 settings
|
||||
|
||||
final Preference preferencePort1en = findPreference("settings_port1en");
|
||||
|
|
15
app/src/main/res/values/arrays.xml
Normal file
15
app/src/main/res/values/arrays.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string-array name="settings_background_fallback_color_item">
|
||||
<item>Black (default)</item>
|
||||
<item>Status bar color</item>
|
||||
<!--<item>Custom color</item>-->
|
||||
</string-array>
|
||||
<string-array name="settings_background_fallback_color_value">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<!--<item>2</item>-->
|
||||
</string-array>
|
||||
|
||||
</resources>
|
|
@ -66,6 +66,13 @@
|
|||
<string name="settings_fill_screen_title">Fill screen</string>
|
||||
<string name="settings_allow_sound_title">Allow sounds</string>
|
||||
<string name="settings_haptic_feedback_title">Allow haptic feedback</string>
|
||||
<string name="settings_category_background_title">Background Color</string>
|
||||
<string name="settings_background_kml_color_title">Use KML color</string>
|
||||
<string name="settings_background_kml_color_summary">Use default KML transparency color of the background bitmap (if exist)</string>
|
||||
<string name="settings_background_fallback_color_title">Other possible colors</string>
|
||||
<string name="settings_background_fallback_color_summary">Else if the KML color is not used</string>
|
||||
<string name="settings_background_custom_color_title">Custom color</string>
|
||||
<string name="settings_background_custom_color_summary">Used when selecting the \'Custom color\' in the \'Other possible colors\'</string>
|
||||
<string name="settings_category_memory_cards_title">Memory Cards</string>
|
||||
<string name="settings_port1en_title">Port 1 is Plugged</string>
|
||||
<string name="settings_port1wr_title">Port 1 is Writable</string>
|
||||
|
@ -73,5 +80,4 @@
|
|||
<string name="settings_port2wr_title">Port 2 is Writable</string>
|
||||
<string name="settings_port2load_title">Port 2 File</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -42,6 +42,29 @@
|
|||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/settings_category_background_title">
|
||||
<SwitchPreference
|
||||
android:key="settings_background_kml_color"
|
||||
android:title="@string/settings_background_kml_color_title"
|
||||
android:summary="@string/settings_background_kml_color_summary"
|
||||
android:defaultValue="false" />
|
||||
<ListPreference
|
||||
android:key="settings_background_fallback_color"
|
||||
android:title="@string/settings_background_fallback_color_title"
|
||||
android:dialogTitle="@string/settings_background_fallback_color_title"
|
||||
android:summary="@string/settings_background_fallback_color_summary"
|
||||
android:entries="@array/settings_background_fallback_color_item"
|
||||
android:entryValues="@array/settings_background_fallback_color_value"
|
||||
android:defaultValue="0"
|
||||
/>
|
||||
<!--<org.emulator.forty.eight.helpers.colorpicker.ColorPickerPreferenceCompat-->
|
||||
<!--android:key="settings_background_custom_color"-->
|
||||
<!--android:title="@string/settings_background_custom_color_title"-->
|
||||
<!--android:summary="@string/settings_background_custom_color_summary"-->
|
||||
<!--android:defaultValue="#FF000000"-->
|
||||
<!--/>-->
|
||||
</PreferenceCategory>
|
||||
|
||||
<!--<PreferenceCategory app:title="Style">
|
||||
"Show Title",IDC_SHOWTITLE
|
||||
"Show Menu",IDC_SHOWMENU
|
||||
|
|
Loading…
Reference in a new issue