Skip to content

Commit

Permalink
Merge branch 'heads/final-ui' into ui
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBRDeveloper committed Dec 18, 2023
2 parents b42c7a1 + c17c230 commit 9ca7e88
Show file tree
Hide file tree
Showing 27 changed files with 384 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
package com.panda3ds.pandroid.app;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class BaseActivity extends AppCompatActivity {}
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.data.config.GlobalConfig;

public class BaseActivity extends AppCompatActivity {
private int currentTheme = GlobalConfig.get(GlobalConfig.KEY_APP_THEME);
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
applyTheme();
super.onCreate(savedInstanceState);
}

@Override
protected void onResume() {
super.onResume();
if (GlobalConfig.get(GlobalConfig.KEY_APP_THEME) != currentTheme){
recreate();
}
}

private void applyTheme(){
switch (GlobalConfig.get(GlobalConfig.KEY_APP_THEME)){
case GlobalConfig.VALUE_THEME_ANDROID:
setTheme(R.style.Theme_Pandroid);
break;
case GlobalConfig.VALUE_THEME_LIGHT:
setTheme(R.style.Theme_Pandroid_Light);
break;
case GlobalConfig.VALUE_THEME_DARK:
setTheme(R.style.Theme_Pandroid_Dark);
break;
case GlobalConfig.VALUE_THEME_BLACK:
setTheme(R.style.Theme_Pandroid_Black);
break;
}
currentTheme = GlobalConfig.get(GlobalConfig.KEY_APP_THEME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import com.panda3ds.pandroid.app.PreferenceActivity;
import com.panda3ds.pandroid.app.base.BasePreferenceFragment;
import com.panda3ds.pandroid.app.preferences.InputMapPreferences;
import com.panda3ds.pandroid.app.preferences.AppearancePreferences;

public class SettingsFragment extends BasePreferenceFragment {
@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
setPreferencesFromResource(R.xml.start_preferences, rootKey);
setItemClick("inputMap", (item) -> PreferenceActivity.launch(requireContext(), InputMapPreferences.class));
setItemClick("appearance", (item)-> PreferenceActivity.launch(requireContext(), AppearancePreferences.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.panda3ds.pandroid.app.preferences;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.app.BaseActivity;
import com.panda3ds.pandroid.app.base.BasePreferenceFragment;
import com.panda3ds.pandroid.data.config.GlobalConfig;
import com.panda3ds.pandroid.view.preferences.SingleSelectionPreferences;

public class AppearancePreferences extends BasePreferenceFragment {
@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
setPreferencesFromResource(R.xml.appearance_preference, rootKey);

((BaseActivity) requireActivity()).getSupportActionBar().setTitle(R.string.appearance);

SingleSelectionPreferences themePreference = findPreference("theme");
themePreference.setSelectedItem(GlobalConfig.get(GlobalConfig.KEY_APP_THEME));
themePreference.setOnPreferenceChangeListener((preference, value) -> {
GlobalConfig.set(GlobalConfig.KEY_APP_THEME, (int) value);
return false;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.SeekBarPreference;

import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.app.BaseActivity;
import com.panda3ds.pandroid.app.base.BasePreferenceFragment;
import com.panda3ds.pandroid.input.InputMap;
import com.panda3ds.pandroid.input.KeyName;
Expand All @@ -19,16 +21,35 @@ public class InputMapPreferences extends BasePreferenceFragment implements Activ
private ActivityResultLauncher<String> requestKey;
private String currentKey;

private SeekBarPreference deadZonePreference;

@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
setPreferencesFromResource(R.xml.input_map_preferences, rootKey);

((BaseActivity) requireActivity()).getSupportActionBar().setTitle(R.string.controller_mapping);

for (KeyName key : KeyName.values()) {
if (key == KeyName.NULL) return;
if (key == KeyName.NULL) continue;
setItemClick(key.name(), this::onItemPressed);
}

deadZonePreference = getPreferenceScreen().findPreference("dead_zone");

deadZonePreference.setOnPreferenceChangeListener((preference, value) -> {
InputMap.setDeadZone(((int)value/100.0f));
refreshList();
return false;
});

refreshList();
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
Expand Down Expand Up @@ -56,6 +77,8 @@ public void onResume() {
}

private void refreshList() {
deadZonePreference.setValue((int)(InputMap.getDeadZone()*100));
deadZonePreference.setSummary(deadZonePreference.getValue()+"%");
for (KeyName key : KeyName.values()) {
if (key == KeyName.NULL) continue;
findPreference(key.name()).setSummary(InputMap.relative(key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
public class GlobalConfig {
private static SharedPreferences data;

public static final int VALUE_THEME_ANDROID = 0;
public static final int VALUE_THEME_LIGHT = 1;
public static final int VALUE_THEME_DARK = 2;
public static final int VALUE_THEME_BLACK = 3;

public static final Key<Integer> KEY_APP_THEME = new Key<>("app.theme", VALUE_THEME_ANDROID);

public static void initialize() {
data = PandroidApplication.getAppContext()
.getSharedPreferences(Constants.PREF_GLOBAL_CONFIG, Context.MODE_PRIVATE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.panda3ds.pandroid.data.game;

import android.graphics.Bitmap;

import java.util.UUID;

public class GameMetadata {

private final String id;
private final String romPath;
private final String title;
private final int[] icon = new int[48 * 48];
private transient final Bitmap icon = Bitmap.createBitmap(48,48, Bitmap.Config.RGB_565);
private final String publisher;
private final GameRegion[] regions = new GameRegion[]{GameRegion.None};

Expand All @@ -34,7 +36,7 @@ public String getPublisher() {
return publisher;
}

public int[] getIcon() {
public Bitmap getIcon() {
return icon;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static KeyName relative(String name) {
}

public static void setDeadZone(float value) {
data.edit().putFloat(KEY_DEAD_ZONE, Math.max(0, Math.min(1.0F, value))).apply();
data.edit().putFloat(KEY_DEAD_ZONE, Math.max(0.0f, Math.min(1.0f, value))).apply();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.util.Log;

import androidx.documentfile.provider.DocumentFile;

Expand All @@ -27,15 +25,6 @@ public static String getName(String path) {
return file.getName();
}

public static long getSize(String path) {
return DocumentFile.fromSingleUri(getContext(), parseUri(path)).length();
}


public static String getCacheDir() {
return getContext().getCacheDir().getAbsolutePath();
}

public static void makeUriPermanent(String uri, String mode) {

int flags = Intent.FLAG_GRANT_READ_URI_PERMISSION;
Expand All @@ -44,20 +33,4 @@ public static void makeUriPermanent(String uri, String mode) {

getContext().getContentResolver().takePersistableUriPermission(parseUri(uri), flags);
}

public static int openContentUri(String path, String mode) {
try {
Uri uri = parseUri(path);
ParcelFileDescriptor descriptor = getContext().getContentResolver().openFileDescriptor(uri, mode);
int fd = descriptor.getFd();
descriptor.detachFd();
descriptor.close();
return fd;
} catch (Exception e) {
Log.e(Constants.LOG_TAG, "Error on openContentUri: " + e);
}

return -1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public ItemHolder(@NonNull View itemView) {
public void apply(GameMetadata game) {
((AppCompatTextView) itemView.findViewById(R.id.title))
.setText(game.getTitle());
((GameIconView) itemView.findViewById(R.id.icon))
.setImageBitmap(game.getIcon());
((AppCompatTextView) itemView.findViewById(R.id.description))
.setText(game.getPublisher());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.panda3ds.pandroid.view.preferences;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;

import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.Constants;

public class SingleSelectionPreferences extends PreferenceCategory implements Preference.OnPreferenceClickListener {
private final Drawable transparent = new ColorDrawable(Color.TRANSPARENT);
private final Drawable doneDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_done);

public SingleSelectionPreferences(@NonNull Context context) {
super(context);
}

public SingleSelectionPreferences(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public SingleSelectionPreferences(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public SingleSelectionPreferences(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

{
try {
TypedArray color = getContext().obtainStyledAttributes(new int[]{
android.R.attr.textColorSecondary
});
doneDrawable.setTint(color.getColor(0, Color.RED));
color.recycle();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
color.close();
}
} catch (Exception e) {
Log.e(Constants.LOG_TAG, "Error on obtain text color secondary: ", e);
}
}

@Override
public void onAttached() {
super.onAttached();
for (int i = 0; i < getPreferenceCount();i++) {
getPreference(i).setOnPreferenceClickListener(this);
}
}

public void setSelectedItem(int index){
onPreferenceClick(getPreference(index));
}

@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
int index = 0;
for (int i = 0; i < getPreferenceCount(); i++){
Preference item = getPreference(i);
if (item == preference){
index = i;
item.setIcon(R.drawable.ic_done);
} else {
item.setIcon(transparent);
}
}

callChangeListener(index);
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?colorOnSecondary" android:state_checked="true"/>
<item android:color="?colorOnSurface"/>
</selector>
9 changes: 9 additions & 0 deletions src/pandroid/app/src/main/res/color/text_secondary_dark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="true" android:color="#000"/>

<item android:state_activated="false" android:color="#8000"/>
<item android:state_enabled="false" android:color="#8000"/>

<item android:color="#000"/>
</selector>
8 changes: 8 additions & 0 deletions src/pandroid/app/src/main/res/color/text_secondary_light.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="true" android:color="#FFF"/>

<item android:state_activated="false" android:color="#AFFF"/>
<item android:state_enabled="false" android:color="#AFFF"/>
<item android:color="#FFF"/>
</selector>
5 changes: 5 additions & 0 deletions src/pandroid/app/src/main/res/drawable/ic_done.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>
5 changes: 5 additions & 0 deletions src/pandroid/app/src/main/res/drawable/ic_theme.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9c0.83,0 1.5,-0.67 1.5,-1.5 0,-0.39 -0.15,-0.74 -0.39,-1.01 -0.23,-0.26 -0.38,-0.61 -0.38,-0.99 0,-0.83 0.67,-1.5 1.5,-1.5L16,16c2.76,0 5,-2.24 5,-5 0,-4.42 -4.03,-8 -9,-8zM6.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,9 6.5,9 8,9.67 8,10.5 7.33,12 6.5,12zM9.5,8C8.67,8 8,7.33 8,6.5S8.67,5 9.5,5s1.5,0.67 1.5,1.5S10.33,8 9.5,8zM14.5,8c-0.83,0 -1.5,-0.67 -1.5,-1.5S13.67,5 14.5,5s1.5,0.67 1.5,1.5S15.33,8 14.5,8zM17.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S16.67,9 17.5,9s1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z"/>
</vector>
Binary file not shown.
3 changes: 2 additions & 1 deletion src/pandroid/app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/main_activity_navigation"
app:labelVisibilityMode="selected"/>
app:labelVisibilityMode="selected"
style="@style/ThemedNavigationBottom"/>

</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 2 additions & 1 deletion src/pandroid/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/fragment_container"
app:labelVisibilityMode="selected"
app:menu="@menu/main_activity_navigation"/>
app:menu="@menu/main_activity_navigation"
style="@style/ThemedNavigationBottom"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 9ca7e88

Please sign in to comment.