Skip to content

Commit

Permalink
[SCL 3.21.0_01] Update from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
SolDev69 committed Apr 15, 2024
2 parents 3e3304b + 4caa308 commit bfd2d73
Show file tree
Hide file tree
Showing 37 changed files with 955 additions and 544 deletions.
2 changes: 1 addition & 1 deletion app_pojavlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ dependencies {
implementation 'com.github.PojavLauncherTeam:portrait-sdp:ed33e89cbc'
implementation 'com.github.PojavLauncherTeam:portrait-ssp:6c02fd739b'
implementation 'com.github.Mathias-Boulay:ExtendedView:1.0.0'
implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:a0fe7e72f2'
implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:06184ddbce'
implementation 'com.github.Mathias-Boulay:virtual-joystick-android:2e7aa25e50'

// implementation 'com.intuit.sdp:sdp-android:1.0.5'
Expand Down
26 changes: 18 additions & 8 deletions app_pojavlauncher/src/main/java/com/kdt/LoggerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.ToggleButton;

Expand All @@ -22,8 +21,8 @@
*/
public class LoggerView extends ConstraintLayout {
private Logger.eventLogListener mLogListener;
private ToggleButton mToggleButton;
private ScrollView mScrollView;
private ToggleButton mLogToggle;
private DefocusableScrollView mScrollView;
private TextView mLogTextView;


Expand All @@ -40,7 +39,7 @@ public LoggerView(@NonNull Context context, @Nullable AttributeSet attrs) {
public void setVisibility(int visibility) {
super.setVisibility(visibility);
// Triggers the log view shown state by default when viewing it
mToggleButton.setChecked(visibility == VISIBLE);
mLogToggle.setChecked(visibility == VISIBLE);
}

/**
Expand All @@ -56,8 +55,8 @@ private void init(){
mLogTextView.setVisibility(GONE);

// Toggle log visibility
mToggleButton = findViewById(R.id.content_log_toggle_log);
mToggleButton.setOnCheckedChangeListener(
mLogToggle = findViewById(R.id.content_log_toggle_log);
mLogToggle.setOnCheckedChangeListener(
(compoundButton, isChecked) -> {
mLogTextView.setVisibility(isChecked ? VISIBLE : GONE);
if(isChecked) {
Expand All @@ -68,21 +67,32 @@ private void init(){
// NOTE: was tested by rapidly smashing the log on/off button, no sync issues found :)
}
});
mToggleButton.setChecked(false);
mLogToggle.setChecked(false);

// Remove the loggerView from the user View
ImageButton cancelButton = findViewById(R.id.log_view_cancel);
cancelButton.setOnClickListener(view -> LoggerView.this.setVisibility(GONE));

// Set the scroll view
mScrollView = findViewById(R.id.content_log_scroll);
mScrollView.setKeepFocusing(true);

//Set up the autoscroll switch
ToggleButton autoscrollToggle = findViewById(R.id.content_log_toggle_autoscroll);
autoscrollToggle.setOnCheckedChangeListener(
(compoundButton, isChecked) -> {
if(isChecked) mScrollView.fullScroll(View.FOCUS_DOWN);
mScrollView.setKeepFocusing(isChecked);
}
);
autoscrollToggle.setChecked(true);

// Listen to logs
mLogListener = text -> {
if(mLogTextView.getVisibility() != VISIBLE) return;
post(() -> {
mLogTextView.append(text + '\n');
mScrollView.fullScroll(View.FOCUS_DOWN);
if(mScrollView.isKeepFocusing()) mScrollView.fullScroll(View.FOCUS_DOWN);
});

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Toast;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.core.content.res.ResourcesCompat;


import net.kdt.pojavlaunch.PojavProfile;
Expand All @@ -39,6 +44,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import fr.spse.extended_view.ExtendedTextView;
Expand Down Expand Up @@ -251,7 +257,7 @@ private void reloadAccounts(boolean fromFiles, int overridePosition){
}

String[] accountArray = mAccountList.toArray(new String[0]);
ArrayAdapter<String> accountAdapter = new ArrayAdapter<>(getContext(), R.layout.item_minecraft_account, accountArray);
AccountAdapter accountAdapter = new AccountAdapter(getContext(), R.layout.item_minecraft_account, accountArray);
accountAdapter.setDropDownViewResource(R.layout.item_minecraft_account);
setAdapter(accountAdapter);

Expand Down Expand Up @@ -306,6 +312,12 @@ private void pickAccount(int position){
}

mSelectecAccount = selectedAccount;
setImageFromSelectedAccount();
}

@Deprecated()
/* Legacy behavior, update the head image manually for the selected account */
private void setImageFromSelectedAccount(){
BitmapDrawable oldBitmapDrawable = mHeadDrawable;

if(mSelectecAccount != null){
Expand All @@ -314,21 +326,54 @@ private void pickAccount(int position){
Bitmap bitmap = mSelectecAccount.getSkinFace();
if(bitmap != null) {
mHeadDrawable = new BitmapDrawable(getResources(), bitmap);
mHeadDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());

view.setCompoundDrawables(mHeadDrawable, null, null, null);
view.postProcessDrawables();
}else{
view.setCompoundDrawables(null, null, null, null);
view.postProcessDrawables();
}
view.postProcessDrawables();
}
}

if(oldBitmapDrawable != null){
oldBitmapDrawable.getBitmap().recycle();
}
}


private static class AccountAdapter extends ArrayAdapter<String> {

private final HashMap<String, Drawable> mImageCache = new HashMap<>();
public AccountAdapter(@NonNull Context context, int resource, @NonNull String[] objects) {
super(context, resource, objects);
}

@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return getView(position, convertView, parent);
}

@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
if(convertView == null){
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_minecraft_account, parent, false);
}
ExtendedTextView textview = (ExtendedTextView) convertView;
textview.setText(super.getItem(position));

// Handle the "Add account section"
if(position == 0) textview.setCompoundDrawables(ResourcesCompat.getDrawable(parent.getResources(), R.drawable.ic_add, null), null, null, null);
else {
String username = super.getItem(position);
Drawable accountHead = mImageCache.get(username);
if (accountHead == null){
accountHead = new BitmapDrawable(parent.getResources(), MinecraftAccount.getSkinFace(username));
mImageCache.put(username, accountHead);
}
textview.setCompoundDrawables(accountHead, null, null, null);
}
return convertView;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void openProfileEditor(FragmentActivity fragmentActivity) {
if(currentSelection instanceof ProfileAdapterExtra) {
performExtraAction((ProfileAdapterExtra) currentSelection);
}else{
Tools.swapFragment(fragmentActivity, ProfileEditorFragment.class, ProfileEditorFragment.TAG, true, null);
Tools.swapFragment(fragmentActivity, ProfileEditorFragment.class, ProfileEditorFragment.TAG, null);
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ private void performExtraAction(ProfileAdapterExtra extra) {
//Replace with switch-case if you want to add more extra actions
if (extra.id == VERSION_SPINNER_PROFILE_CREATE) {
Tools.swapFragment((FragmentActivity) getContext(), ProfileTypeSelectFragment.class,
ProfileTypeSelectFragment.TAG, true, null);
ProfileTypeSelectFragment.TAG, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public class EfficientAndroidLWJGLKeycode {

add(KeyEvent.KEYCODE_CAPS_LOCK, LwjglGlfwKeycode.GLFW_KEY_CAPS_LOCK);
add(KeyEvent.KEYCODE_BREAK, LwjglGlfwKeycode.GLFW_KEY_PAUSE);
add(KeyEvent.KEYCODE_MOVE_HOME, LwjglGlfwKeycode.GLFW_KEY_HOME);
add(KeyEvent.KEYCODE_MOVE_END, LwjglGlfwKeycode.GLFW_KEY_END);
add(KeyEvent.KEYCODE_INSERT, LwjglGlfwKeycode.GLFW_KEY_INSERT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,18 @@ public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f)
// Allow starting the add account only from the main menu, should it be moved to fragment itself ?
if(!(fragment instanceof MainMenuFragment)) return false;

Tools.swapFragment(this, SelectAuthFragment.class, SelectAuthFragment.TAG, true, null);
Tools.swapFragment(this, SelectAuthFragment.class, SelectAuthFragment.TAG, null);
return false;
};

/* Listener for the settings fragment */
private final View.OnClickListener mSettingButtonListener = v -> {
Fragment fragment = getSupportFragmentManager().findFragmentById(mFragmentView.getId());
if(fragment instanceof MainMenuFragment){
Tools.swapFragment(this, LauncherPreferenceFragment.class, SETTING_FRAGMENT_TAG, true, null);
Tools.swapFragment(this, LauncherPreferenceFragment.class, SETTING_FRAGMENT_TAG, null);
} else{
// The setting button doubles as a home button now
while(!(getSupportFragmentManager().findFragmentById(mFragmentView.getId()) instanceof MainMenuFragment)){
getSupportFragmentManager().popBackStackImmediate();
}
Tools.backToMainMenu(this);
}
};

Expand Down Expand Up @@ -159,6 +157,14 @@ public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pojav_launcher);

// Manually add the first fragment to the backstack to get easily back to it
// There must be a better way to handle the root though...
this.getSupportFragmentManager().beginTransaction()
.setReorderingAllowed(true)
.addToBackStack("ROOT")
.add(R.id.container_fragment, MainMenuFragment.class, null, "ROOT").commit();

IconCacheJanitor.runJanitor();
mRequestNotificationPermissionLauncher = registerForActivityResult(
new ActivityResultContracts.RequestPermission(),
Expand Down Expand Up @@ -245,6 +251,11 @@ public void onBackPressed() {
}
}

// Check if we are at the root then
if(getVisibleFragment("ROOT") != null){
finish();
}

super.onBackPressed();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.kdt.pojavlaunch;

import static net.kdt.pojavlaunch.Architecture.ARCH_X86;
import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_SUSTAINED_PERFORMANCE;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_USE_ALTERNATE_SURFACE;
Expand All @@ -17,7 +16,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
Expand All @@ -44,7 +42,6 @@

import com.kdt.LoggerView;

import net.kdt.pojavlaunch.lifecycle.ContextExecutor;
import net.kdt.pojavlaunch.customcontrols.ControlButtonMenuListener;
import net.kdt.pojavlaunch.customcontrols.ControlData;
import net.kdt.pojavlaunch.customcontrols.ControlDrawerData;
Expand All @@ -54,6 +51,8 @@
import net.kdt.pojavlaunch.customcontrols.EditorExitable;
import net.kdt.pojavlaunch.customcontrols.keyboard.LwjglCharSender;
import net.kdt.pojavlaunch.customcontrols.keyboard.TouchCharInput;
import net.kdt.pojavlaunch.customcontrols.mouse.Touchpad;
import net.kdt.pojavlaunch.lifecycle.ContextExecutor;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.services.GameService;
import net.kdt.pojavlaunch.utils.JREUtils;
Expand Down Expand Up @@ -363,16 +362,6 @@ private void printLauncherInfo(String gameVersion, String javaArguments) {
Logger.appendToLog("Info: Custom Java arguments: \"" + javaArguments + "\"");
}

private void checkVulkanZinkIsSupported() {
if (Tools.DEVICE_ARCHITECTURE == ARCH_X86
|| Build.VERSION.SDK_INT < 25
|| !getPackageManager().hasSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_LEVEL)
|| !getPackageManager().hasSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_VERSION)) {
Logger.appendToLog("Error: Vulkan Zink renderer is not supported!");
throw new RuntimeException(getString(R.string. mcn_check_fail_vulkan_support));
}
}

private void dialogSendCustomKey() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.control_customkey);
Expand Down Expand Up @@ -630,7 +619,7 @@ public void exitEditor() {
public void onServiceConnected(ComponentName name, IBinder service) {
GameService.LocalBinder localBinder = (GameService.LocalBinder) service;
mServiceBinder = localBinder;
minecraftGLView.start(localBinder.isActive);
minecraftGLView.start(localBinder.isActive, touchpad);
localBinder.isActive = true;
}

Expand Down
Loading

0 comments on commit bfd2d73

Please sign in to comment.