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

Dark mode #322

Merged
merged 16 commits into from
Dec 9, 2019
Merged

Dark mode #322

merged 16 commits into from
Dec 9, 2019

Conversation

TheLastProject
Copy link
Contributor

@TheLastProject TheLastProject commented Dec 2, 2019

Fixes #298. Defaults to whatever the system theme is. When changing the value in settings, instantly swaps theme.

Yes, this is really all that needed to be done. Android did a pretty good job at making dark themes possible easily.

Screenshot_1575300538
Screenshot_1575300550
Screenshot_1575300553
Screenshot_1575300557
Screenshot_1575300567
Screenshot_1575300569
Screenshot_1575300574
Screenshot_1575303009


This change is Reviewable

@brarcher
Copy link
Owner

brarcher commented Dec 4, 2019

Experimenting with this on an emulator, I find that if the dark theme setting is configured, then the app is launched clean, it works as expected. However, if the app was running already when the dark mode setting is changed, the app may not take the theme or may do so improperly. Here is an example.

  1. System in light mode, app in light mode
  2. Launch app, enter app settings
  3. Configure app to use dark mode
  4. Click back to go to main app activity

image

Note that the title text is really dark. A similar situation happens when switching from dark to light.

image

I'm not sure yet what is causing this behavior on only what appears to be the card title text. (The note text is correct). Are you able to duplicate this on your test device or emulator?

@TheLastProject
Copy link
Contributor Author

I did run into this issue earlier but I thought I fixed it. Seems I did miss a case. I'll take another look at it, thank you

Copy link
Owner

@brarcher brarcher left a comment

Choose a reason for hiding this comment

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

Reviewed 8 of 11 files at r1, 3 of 3 files at r2.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @TheLastProject)

a discussion (no related file):
I've only a few comments on the code. Let me know if you track down the theme change issue I mentioned, and I'll take a look again.



app/src/main/java/protect/card_locker/preferences/SettingsActivity.java, line 58 at r2 (raw file):

            findPreference(getResources().getString(R.string.settings_key_theme)).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object o) {

I do not mind if the { is at the end of the line or on the next line. Kindly make it consistent in the file, though.


app/src/main/java/protect/card_locker/preferences/SettingsActivity.java, line 65 at r2 (raw file):

                        return true;
                    }
                    else if(o.toString().equals(getResources().getString(R.string.settings_key_dark_theme)))

Could the if/else if/ pattern be changed either to if/else if/else or if/if/? That is,

if ( /*check light theme*/) {
   // something
} else if (/*check dark theme*/) {
  //something
} else {
  //something
}
return true

or

if (/*check*) {
  //something 
  return true
}

if (/*check*/) {
  //something 
  return true
}

// last option
return true;

app/src/main/java/protect/card_locker/preferences/SettingsActivity.java, line 73 at r2 (raw file):

                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
                    getActivity().recreate();

If all paths end up recreating and returning true, why not do the common work at the end and return once?

@TheLastProject
Copy link
Contributor Author

I'll deal with the code comments soon, thanks for reviewing.

I've only a few comments on the code. Let me know if you track down the theme change issue I mentioned, and I'll take a look again.

The issue became less prevalent with recent commits, but it still does occur on some elements (like the border around the about webview). I'm not sure why that happens so it may take some time until I can figure that out, if ever. I will notify you if I believe I found it though.

@TheLastProject
Copy link
Contributor Author

Because a picture is worth more than a thousand words, this is the issue I mean: the dialog uses a dark theme after switching to light theme. I am still going to try to fix this but it... feels like a pretty weird issue.

photo_2019-12-05_20-23-23

Copy link
Contributor Author

@TheLastProject TheLastProject left a comment

Choose a reason for hiding this comment

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

Reviewable status: 10 of 13 files reviewed, 4 unresolved discussions (waiting on @brarcher)

a discussion (no related file):

Previously, brarcher (Branden Archer) wrote…

I've only a few comments on the code. Let me know if you track down the theme change issue I mentioned, and I'll take a look again.

Done.



app/src/main/java/protect/card_locker/preferences/SettingsActivity.java, line 58 at r2 (raw file):

Previously, brarcher (Branden Archer) wrote…

I do not mind if the { is at the end of the line or on the next line. Kindly make it consistent in the file, though.

Done.


app/src/main/java/protect/card_locker/preferences/SettingsActivity.java, line 65 at r2 (raw file):

Previously, brarcher (Branden Archer) wrote…

Could the if/else if/ pattern be changed either to if/else if/else or if/if/? That is,

if ( /*check light theme*/) {
   // something
} else if (/*check dark theme*/) {
  //something
} else {
  //something
}
return true

or

if (/*check*) {
  //something 
  return true
}

if (/*check*/) {
  //something 
  return true
}

// last option
return true;

Done.


app/src/main/java/protect/card_locker/preferences/SettingsActivity.java, line 73 at r2 (raw file):

Previously, brarcher (Branden Archer) wrote…

If all paths end up recreating and returning true, why not do the common work at the end and return once?

Done.

Copy link
Owner

@brarcher brarcher left a comment

Choose a reason for hiding this comment

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

Have you ever seen the issue when launching the app when it was not running? That is, the theme was already configured, the app was swiped from recents then re-launched? Having the dark theme work well in that scenario will be more important that when the theme is being toggled, as I anticipate that if one configures their phone to be a theme it will stay that way. (Is that a valid assumption?) It may not look polished if there are transient issues when the theme changes, however having dark mode work well all other times may balance it out.

Reviewable status: 10 of 13 files reviewed, 4 unresolved discussions (waiting on @brarcher)

@TheLastProject
Copy link
Contributor Author

I've only ever seen it go wrong for the very specific scenario you mentioned, and I managed to fix that so it only bugs out the about dialog now:

  1. System in light mode, app in light mode
  2. Launch app, enter app settings
  3. Configure app to use dark mode
  4. Click back to go to main app activity

Copy link
Owner

@brarcher brarcher left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r3, 1 of 1 files at r4.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @brarcher and @TheLastProject)


app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java, line 115 at r4 (raw file):

            int bitMatrixHeight = bitMatrix.getHeight();

            // Returns: left,top,width,height enclosing rectangle of all 1 bits, or null if it is all white

I'm thinking that there still needs to be a white border around the barcode. The reason is, if the barcode goes right to the edge and it is dark theme, a detector will not be able to distinguish the boundaries of the barcode. For example, in my test setup I have an emulator and a physical phone, and I have my phone attempt to read the barcode from the emulator's screen. The phone is able to read this one:

image.png

but not this one:

image copy 1.png

With the barcode drawing changes reverted one gets the following:

image copy 3.png

which is successfully read. I recall from somewhere that barcode are intended to have a certain amount of buffer space to avoid these issues. We may not be able to remove the buffer space that the ZXing library generates.

@TheLastProject
Copy link
Contributor Author

Reviewable keeps crashing whenever I try to log in on it now, so I can't leave my reply there...

Anyway, it seems you're completely right.

While I don't believe all the padding is intended because some of it is kinda absurd:
photo_2019-12-08_18-07-09

I tried changing the code to ensure that 20 pixels of padding remains, so it only removes the absurd padding:
photo_2019-12-08_18-07-11

But the 1D code there still didn't scan (but the QR code did)!

So it indeed seems some of the codes really need all the padding they are given and because doing this only for some codes and not others will very likely lead us to some edge cases with certain scanners, I've reverted the code to clean up the rectangles.

Copy link
Owner

@brarcher brarcher left a comment

Choose a reason for hiding this comment

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

Reviewable status: 12 of 13 files reviewed, 4 unresolved discussions (waiting on @brarcher and @TheLastProject)


app/src/main/java/protect/card_locker/BarcodeImageWriterTask.java, line 118 at r5 (raw file):

            int[] enclosingRectangle = bitMatrix.getEnclosingRectangle();

            // We add 20 pixels on all sides to ensure small intentional padding around the barcodes isn't removed

Arguably 20 pixels is arbitrary. My understanding is that the padding, or quiet zone, around a barcode should be "at least seven to ten times of the narrowest bar width in the barcode."

https://www.cognex.com/what-is/industrial-barcode-reading/1d-barcodes

I think that ZXing takes care of creating an appropriate quiet zone. My concern is that with changing the effective drawing area for the barcode that the expected quiet zone may be eroded. Can these changes be removed? Or, are they addressing a concern that I do not quite get yet?

@TheLastProject
Copy link
Contributor Author

Yeah, I indeed reverted it.

Copy link
Owner

@brarcher brarcher left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r6.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @brarcher and @TheLastProject)

@brarcher
Copy link
Owner

brarcher commented Dec 9, 2019

Yeah, I indeed reverted it.

Sorry, did not see your reply initially. Sounds good!

@brarcher brarcher merged commit acfb92e into brarcher:master Dec 9, 2019
@brarcher
Copy link
Owner

brarcher commented Dec 9, 2019

Thanks for adding this feature!

@TheLastProject
Copy link
Contributor Author

And thank you for reviewing, testing and accepting it :)

@TheLastProject TheLastProject deleted the feature/dark_mode branch October 24, 2020 12:03
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
2 participants