Skip to content

Instantly share code, notes, and snippets.

View shubham08gupta's full-sized 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
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 / MarshmallowPermissions.java
Created September 17, 2016 08:34
A simple class to manage android permissions in Marshmallow version (Android 6.0) or above.
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;
@shubham08gupta
shubham08gupta / try-catch-finally separation.java
Created February 24, 2018 09:21
write try-catch-finally cleanly
public void delete(Page page) {
try {
deletePageAndAllReferences(page);
}
catch (Exception e) {
logError(e);
}
}
private void deletePageAndAllReferences(Page page) throws Exception {
╔=============|=====================╗==============================================================================|
║ AppState |Notification ║ Data | Both |
╠════════=════|════════=============╣===================|==========================================================|
║ Foreground | onMessageReceived ║ onMessageReceived | onMessageReceived |
║ Background | System tray ║ onMessageReceived | Notification: system tray. Data: in extras of the intent |
╚════════════=╩════════=============|===================|==========================================================|
/*
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());
<?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>
<?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>
@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
<?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>