Skip to content

Instantly share code, notes, and snippets.

View PrashamTrivedi's full-sized avatar
🏠
Working from home

Prasham Trivedi PrashamTrivedi

🏠
Working from home
View GitHub Profile
public Bitmap getScreenshotFromRecyclerView(RecyclerView view) {
RecyclerView.Adapter adapter = view.getAdapter();
Bitmap bigBitmap = null;
if (adapter != null) {
int size = adapter.getItemCount();
int height = 0;
Paint paint = new Paint();
int iHeight = 0;
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
@PrashamTrivedi
PrashamTrivedi / RecyclerViewTarget.java
Last active September 12, 2017 21:19
Target file to properly cover recyclerview in showcase view(https://github.com/amlcurran/ShowcaseView)
/**
* Target file for ShowcaseView library, it will always points to first item of recyclerview child.
*/
public class RecyclerViewTarget implements Target {
RecyclerView recyclerView;
public RecyclerViewTarget(RecyclerView recyclerView) {
this.recyclerView = recyclerView;
}
@PrashamTrivedi
PrashamTrivedi / publish.gradle
Created August 27, 2015 07:24
Gradle file for copying release ready apk to desired directory.
def getReleasePath() {
//Define RELEASE_PATH anywhere(in properties file) and your apk + mapping file will be copied there.
return hasProperty('RELEASE_PATH') ? RELEASE_PATH : "${project.rootDir}\\Release"
}
android.applicationVariants.all { variant ->
//Mapping file for proguard path for each variant
def mappingFile = variant.variantData.mappingFile
@PrashamTrivedi
PrashamTrivedi / after-activity.java
Last active March 2, 2016 07:34
code snippets for databinding post
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_login);
viewModel = new LoginViewModel(this);
binding.setLogin(viewModel);
setSupportActionBar(binding.toolBar);
}

Using: Android Studio 2.2 beta 5.

Tip: Go to logcat > Edit Filter Configuration > Create a new one or update an existing > Enter below value in Log Tag> Check Regex Checkbox

Devices

Vivo - ^(?!.*(MALI|FeatureProxyBase|STATUSBAR_DEBUG|Surface|GraphicBuffer|OpenGLRenderer|MaliEGL|NativeCrypto|InputMethodManager|OpenSSLLib|Proxy|Posix|MPlugin|jianghong|ViewRootImpl|libc-netbsd|PhoneWindow)).*$

Gionee (Added Vivo Tags for safety) - ^(?!.*(MALI|FeatureProxyBase|STATUSBAR_DEBUG|Surface|GraphicBuffer|OpenGLRenderer|MaliEGL|NativeCrypto|InputMethodManager|OpenSSLLib|Proxy|Posix|MPlugin|jianghong|ViewRootImpl|libc-netbsd|PhoneWindow|ADB_SERVICES|SensorService|SignalClusterView|NetworkController|BatteryService|wpa_supplicant|WifiHW|WifiStateMachine|Tethering|wifi2agps|agps|SettingsInterface|WifiAutoJoinController|ActivityThread)).*$

@PrashamTrivedi
PrashamTrivedi / Callbacks.kt
Last active April 12, 2017 05:58
Kotlin examples for my post
//DataRepository.kt, which handles all db handling, where I have passed 3 callbacks, finished, error or maximum tabs reached
public fun addTab(tabModelToInsert: TabModel,
onFinished: (tabModel: TabModel) -> Unit = {},
onError: (tabModel: TabModel, message: String) -> Unit = { tabModel, message -> },
onMaxTabReached: (tabModel: TabModel) -> Unit = {}) {
if (canAddMoreTabs()) {
val currentMaxId = getCurrentMaxId() ?: 0
try {
realm.executeTransaction {
addTabModelToRealm()
//DataRepository.kt, which handles all db handling, where I have passed 3 callbacks, finished, error or maximum tabs reached
public fun addTab(tabModelToInsert: TabModel,
onFinished: (tabModel: TabModel) -> Unit = {},
onError: (tabModel: TabModel, message: String) -> Unit = { tabModel, message -> },
onMaxTabReached: (tabModel: TabModel) -> Unit = {}) {
if (canAddMoreTabs()) {
val currentMaxId = getCurrentMaxId() ?: 0
try {
realm.executeTransaction {
addTabModelToRealm()
//Part of Functions.kt, this and below 3 functions helps to create dialog.
public fun Context.showDialog(cancelable: Boolean = false, cancelableTouchOutside: Boolean = false, builderFunction: AlertDialog.Builder.() -> Any) {
val builder = AlertDialog.Builder(this)
builder.builderFunction()
val dialog = builder.create();
dialog.setCancelable(cancelable)
dialog.setCanceledOnTouchOutside(cancelableTouchOutside)
dialog.show()
}