Skip to content

Instantly share code, notes, and snippets.

Avatar

Kamal Faraj kfaraj

View GitHub Profile
View SdkService.kt
val advertisingId = AdvertisingIdClient.getAdvertisingIdInfo(this).id
// Do something with the advertising ID.
View NotepadActivity.kt
val reviewManager = ReviewManagerFactory.create(this)
reviewManager.requestReviewFlow()
.addOnCompleteListener { task ->
if (task.isSuccessful) {
reviewManager.launchReviewFlow(this, task.result)
.addOnCompleteListener {
// Continue the normal user flow.
}
} else {
// Continue the normal user flow.
View build.gradle
implementation 'com.google.android.play:core:1.9.0'
implementation 'com.google.android.play:core-ktx:1.8.1'
View DarkThemeApplication.kt
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
val mode = prefs.getInt(Settings.NIGHT_MODE, Settings.MODE_NIGHT_DEFAULT)
AppCompatDelegate.setDefaultNightMode(mode)
View DarkThemeActivity.kt
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
prefs.edit().putInt(Settings.NIGHT_MODE, mode).apply()
AppCompatDelegate.setDefaultNightMode(mode)
View activity_dark_theme.xml
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/Widget.MaterialComponents.FloatingActionButton"
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/margin"
android:src="@drawable/ic_mode_night_default_black_24dp"
app:tint="?android:attr/textColorPrimaryInverse" />
View colors.xml
<color name="primary">#ff212121</color>
<color name="primary_dark">#ff000000</color>
<color name="accent">#ff80cbc4</color>
View colors.xml
<color name="primary">#fff5f5f5</color>
<color name="primary_dark">#ff757575</color>
<color name="accent">#ff009688</color>
View themes.xml
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
View themes.xml
<style name="Theme.MaterialComponents.DayNight.NoActionBar.Bridge" parent="Theme.MaterialComponents.NoActionBar.Bridge" />