-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from odaridavid/dark-variant
Add a dark variant
- Loading branch information
Showing
44 changed files
with
545 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* | ||
* Copyright 2020 David Odari | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
* | ||
**/ | ||
@charset "utf-8"; | ||
|
||
body { | ||
font-family: Helvetica, Arial, Freesans, clean, sans-serif; | ||
font-size:1.2em; | ||
padding:0.5em; | ||
margin:auto; | ||
color:#a69b97; | ||
max-width:42em; | ||
background:#494949; | ||
} | ||
code, pre { | ||
color: inherit; | ||
} | ||
pre { | ||
line-height: 1.25em; | ||
overflow: auto; | ||
padding: 6px 10px; | ||
} | ||
pre > code { | ||
border: 0; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
code { | ||
margin: 0 2px; | ||
padding: 0 5px; | ||
} | ||
.keyword{ | ||
color:#0097a7; | ||
} | ||
.types{ | ||
color:#c25e00; | ||
} | ||
.generic{ | ||
color:#c75b39; | ||
} | ||
.annotation{ | ||
color:#c75b39; | ||
} | ||
.arguments{ | ||
color:#D2691E; | ||
} | ||
.string{ | ||
color:#99d066; | ||
} | ||
.comments{ | ||
color:#8e8e8e; | ||
} | ||
.assertions{ | ||
color:#b39ddb; | ||
} | ||
.stdlib{ | ||
color:#c49000; | ||
} | ||
.literals{ | ||
color:#1E90FF; | ||
} | ||
.static{ | ||
color:#c49000; | ||
} | ||
.string-template{ | ||
color:#c49000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ body { | |
background:#eeeeee; | ||
} | ||
code, pre { | ||
background-color: #F8F8F8; | ||
color: inherit; | ||
} | ||
pre { | ||
|
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/github/odaridavid/designpatterns/DesignPatternsApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* | ||
* Copyright 2020 David Odari | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
* | ||
**/ | ||
package com.github.odaridavid.designpatterns | ||
|
||
import android.app.Application | ||
import androidx.preference.PreferenceManager | ||
import com.github.odaridavid.designpatterns.helpers.ThemeUtils | ||
|
||
|
||
internal class DesignPatternsApp : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
val sp = PreferenceManager.getDefaultSharedPreferences(baseContext) | ||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false) | ||
ThemeUtils.updateTheme(sp, getString(R.string.key_theme_preference)) | ||
} | ||
|
||
} |
78 changes: 70 additions & 8 deletions
78
app/src/main/java/com/github/odaridavid/designpatterns/base/BaseActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,86 @@ | ||
package com.github.odaridavid.designpatterns.base | ||
|
||
import android.content.Context | ||
import android.content.res.Configuration | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.os.PowerManager | ||
import android.view.View | ||
import androidx.annotation.RequiresApi | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.preference.PreferenceManager | ||
import com.github.odaridavid.designpatterns.R | ||
import com.github.odaridavid.designpatterns.helpers.SdkUtils | ||
import com.github.odaridavid.designpatterns.helpers.SdkUtils.versionFrom | ||
import com.github.odaridavid.designpatterns.helpers.SdkUtils.versionUntil | ||
import com.github.odaridavid.designpatterns.helpers.ThemeUtils | ||
|
||
abstract class BaseActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
matchStatusBarWithBackground() | ||
super.onCreate(savedInstanceState) | ||
private val powerManager: PowerManager by lazy { | ||
getSystemService(Context.POWER_SERVICE) as PowerManager | ||
} | ||
|
||
private fun matchStatusBarWithBackground() { | ||
if (SdkUtils.versionFrom(Build.VERSION_CODES.M)) { | ||
override fun onResume() { | ||
matchSystemBarsWithBackground() | ||
super.onResume() | ||
} | ||
|
||
private fun matchSystemBarsWithBackground() { | ||
val sp = PreferenceManager.getDefaultSharedPreferences(baseContext) | ||
val theme = sp.getString(getString(R.string.key_theme_preference), ThemeUtils.THEME_LIGHT) | ||
if (versionFrom(Build.VERSION_CODES.M)) | ||
handleSystemBars(theme) | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.M) | ||
private fun handleSystemBars(theme: String?) { | ||
when (theme) { | ||
ThemeUtils.THEME_LIGHT -> setLightSystemBars() | ||
ThemeUtils.THEME_DARK -> setDarkSystemBars() | ||
ThemeUtils.THEME_SYSTEM -> { | ||
if (versionUntil(Build.VERSION_CODES.P)) { | ||
onPowerSaverModeChange() | ||
} else { | ||
onUiModeConfigChange() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.M) | ||
private fun onPowerSaverModeChange() { | ||
if (powerManager.isPowerSaveMode) | ||
setDarkSystemBars() | ||
else | ||
setLightSystemBars() | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.M) | ||
private fun onUiModeConfigChange() { | ||
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) { | ||
Configuration.UI_MODE_NIGHT_NO -> { | ||
setLightSystemBars() | ||
} | ||
Configuration.UI_MODE_NIGHT_YES -> { | ||
setDarkSystemBars() | ||
} | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.M) | ||
private fun setLightSystemBars() { | ||
if (versionFrom(Build.VERSION_CODES.O)) { | ||
window.decorView.systemUiVisibility = | ||
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | ||
} else { | ||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | ||
window.statusBarColor = getColor(R.color.colorPrimary) | ||
} | ||
window.statusBarColor = getColor(android.R.color.background_light) | ||
window.navigationBarColor = getColor(android.R.color.background_light) | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.M) | ||
private fun setDarkSystemBars() { | ||
window.statusBarColor = getColor(android.R.color.background_dark) | ||
window.navigationBarColor = getColor(android.R.color.background_dark) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.