Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Shubham Gupta shubham08gupta

🏠
Working from home
View GitHub Profile
@shubham08gupta
shubham08gupta / MyApplication.kt
Created April 8, 2020 09:56
A sample to give the option to switch the theme b/w the light and dark mode
View MyApplication.kt
class MyApplication : Application(){
override fun onCreate() {
super.onCreate()
applyTheme()
}
private fun applyTheme() {
PreferenceManager.getDefaultSharedPreferences(this)
.getString(getString(R.string.key_app_theme), ThemeHelper.DEFAULT_MODE)?.apply {
@shubham08gupta
shubham08gupta / try-catch-finally separation.java
Created February 24, 2018 09:21
write try-catch-finally cleanly
View try-catch-finally separation.java
public void delete(Page page) {
try {
deletePageAndAllReferences(page);
}
catch (Exception e) {
logError(e);
}
}
private void deletePageAndAllReferences(Page page) throws Exception {
View gist:6668b85b943df4ff1ed63a410baf5649
╔=============|=====================╗==============================================================================|
║ AppState |Notification ║ Data | Both |
╠════════=════|════════=============╣===================|==========================================================|
║ Foreground | onMessageReceived ║ onMessageReceived | onMessageReceived |
║ Background | System tray ║ onMessageReceived | Notification: system tray. Data: in extras of the intent |
╚════════════=╩════════=============|===================|==========================================================|
View CircularRevealActivity.java
/*
create a new circular reaveal on the give view. This view is initially invisible. In this case the view covers full screen
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void createCircularReveal(final View view) {
// to get the center of FAB
int centerX = (int) mFab.getX() + mFab.getWidth() / 2;
int centerY = (int) mFab.getY();
float finalRadius = (float) Math.hypot(view.getWidth(), view.getHeight());
View custom_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<explode xmlns:android="http://schemas.android.com/apk/res/android">
<targets>
<target android:excludeId="@android:id/statusBarBackground" />
<target android:excludeId="@id/toolbar_container" />
</targets>
</explode>
View styles-v21.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="BaseTheme">
<!-- enable activity transitions -->
<item name="android:windowActivityTransitions">true</item>
<!-- enable window content transitions -->
<item name="android:windowContentTransitions">true</item>
View SmallDotActivity.java
@Override
public void onClick(View v) {
if (v instanceof Button) {
ImageView circleImage = (ImageView) findViewById(R.id.iv_circle);
Intent intent = new Intent(AnimationActivity.this,ImageDetailActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
startActivity(intent,
ActivityOptions.makeSceneTransitionAnimation(
this,
new Pair<View, String>(circleImage,
@shubham08gupta
shubham08gupta / styles-v21.xml
Last active August 15, 2017 17:33
Styles-v21 file for android animations
View styles-v21.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
@shubham08gupta
shubham08gupta / MarshmallowPermissions.java
Created September 17, 2016 08:34
A simple class to manage android permissions in Marshmallow version (Android 6.0) or above.
View MarshmallowPermissions.java
package com.example.logintutorial;
import android.Manifest;
import android.annotation.TargetApi;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;