Skip to content

Instantly share code, notes, and snippets.

View bapspatil's full-sized avatar
🪄

Bapusaheb Patil bapspatil

🪄
View GitHub Profile
@bapspatil
bapspatil / AndroidManifest.xml for feature1
Last active August 22, 2018 12:44
Manifest file for feature1 in Android App Bundle
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="your.packagename.feature1">
<dist:module
dist:onDemand="true"
dist:title="@string/title_feature1">
<dist:fusing include="true" />
</dist:module>
@bapspatil
bapspatil / build.gradle for app
Last active September 14, 2022 12:40
app module's build.gradle file for Android App Bundle
// 'app' module should have the application plugin.
apply plugin: 'com.android.application'
android {
defaultConfig {
...
// Specify the version code, only once for each new version of your app, for your App Bundle
// No need to have different version codes for different APKs generated.
// All split APKs will share the same version code once installed via Google Play.
versionCode 1
apply plugin: 'com.android.application'
android {
...
...
defaultConfig {
...
versionCode 2000
...
@bapspatil
bapspatil / CounterView.kt
Last active September 17, 2019 06:39
CounterView
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.inc_dec_view.view.*
/**
* Created by Bapusaheb Patil.
*/
class IncDecView : LinearLayout, View.OnClickListener {
@bapspatil
bapspatil / RealmInverseRelationships
Created February 13, 2018 11:45
How to work with inverse relationships in Realm
public class Dog extends RealmObject {
@PrimaryKey private String id;
private int age;
@LinkingObjects("dogs") // <-- !
private final RealmResults<Person> owners = null; // <-- !
// getters, setters
}
private int numberOfColumns() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
// You can change this divider to adjust the size of the poster
int widthDivider = 400;
int width = displayMetrics.widthPixels;
int nColumns = width / widthDivider;
return nColumns;
}
@bapspatil
bapspatil / CircleImageView.java
Created January 13, 2018 19:22
Creates a circular ImageView
package bapspatil.avatarimageview;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
@bapspatil
bapspatil / RetrofitCached.java
Created December 23, 2017 21:51
Make Retrofit work offline with caching
package bapspatil.pantheon.utils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import java.io.IOException;
import bapspatil.pantheon.network.RetrofitAPI;
import okhttp3.Cache;
@bapspatil
bapspatil / AA Transition App theme between light and dark themes
Created December 13, 2017 14:43 — forked from alphamu/AA Transition App theme between light and dark themes
Example of how to change themes at runtime with a smooth animation. In this example, we just switch between a light and a dark theme. The activity animation is defined in the theme and as such will be default on all activities with the set theme. [Demo Video here](http://youtu.be/Ps0phswbHls).
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class TransitionThemeActivity extends AppCompatActivity implements View.OnClickListener {
public class AnimatedActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//opening transition animations
overridePendingTransition(R.anim.activity_open_translate,R.anim.activity_close_scale);
}