Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#16 Add dark mode #26

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

deifyed
Copy link

@deifyed deifyed commented Dec 5, 2023

privacy

This PR closes #16 by implementing theme switching functionality and a dark theme based on native Android dark mode colors. Images should still be updated to fit the dark background.

Let me know if I missed something and I'll sort it out. I'm not an Android developer, so I apologize for any silly mistakes.

@@ -40,6 +42,7 @@ public class AboutActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(GetThemeRes(getApplicationContext()));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik, we need to set the theme per activity

else
setColor(context.getResources().getColor(R.color.button_empty_2));

setColor(GetColorRes(context, R.attr.buttonEmpty));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference in colors are now handled by the ThemeResolver file

setContentView(R.layout.activity_settings);

//setupActionBar();

overridePendingTransition(0, 0);
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to have an instant change in themes when selecting it in the menu

import org.secuso.privacyfriendly2048.R

@StyleRes
fun GetThemeRes(ctx: Context): Int {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function returns the correct style depending on preferences/settings

}

@ColorRes
fun GetColorRes(ctx: Context, res: Int): Int {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function returns the correct color depending on the color scheme chosen through preferences/settings

}

@ColorInt
fun GetColorInt(ctx: Context, res: Int): Int {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setTextColor requires an actual color instead of a reference like the GetColorRes function. Somehow it works if I just cast the reference to an int

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dark theme
1 participant