Skip to content

Instantly share code, notes, and snippets.

View zakrodionov's full-sized avatar
🇺🇦
Peace For Ukraine

Zakhar Rodionov zakrodionov

🇺🇦
Peace For Ukraine
View GitHub Profile
@loukwn
loukwn / NestedRecycler.java
Last active December 3, 2019 08:53
A recyclerview that respects the nested scrolling of its children (Translated from its kotlin version here https://medium.com/widgetlabs-engineering/scrollable-nestedscrollviews-inside-recyclerview-ca65050d828a ) Credits for the original code go to Marc Knaup.
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.view.NestedScrollingParent;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class NestedRecycler extends RecyclerView implements NestedScrollingParent {
@bunjix
bunjix / Activity_or_Fragment.java
Last active January 9, 2020 10:28
Pick an image on Android
private static final int PICK_PHOTO_FOR_AVATAR = 0;
public void pickImage() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, PICK_PHOTO_FOR_AVATAR);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
@Jeevuz
Jeevuz / EnterStringDialogFragment.kt
Last active October 26, 2020 09:10
Universal DialogFragments
package ru.mobileup.businessnavigator.ui.base.dialog
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.support.annotation.LayoutRes
import android.support.annotation.StringRes
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatDialogFragment
import android.text.Editable
@artem-zinnatullin
artem-zinnatullin / gist:6916740
Last active October 26, 2020 12:15
Android support library onActivityResult() bug fix for nested fragments
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// notifying nested fragments (support library bug fix)
final FragmentManager childFragmentManager = getChildFragmentManager();
if (childFragmentManager != null) {
final List<Fragment> nestedFragments = childFragmentManager.getFragments();
@ZacSweers
ZacSweers / DiscussionGuidelines.md
Created November 20, 2017 07:04
Discussion guidelines

Guidelines

To keep the arguments and examples to the point there are few helpful rules:

  • No abstract examples/arguments. These cause the discussion to lose focus and make examples harder to follow. The example/argument must be traceable to a real-world problem - ___ is intended to solve real problems, not imaginary ones.
  • Examples must show the full complexity of the problem domain. Simplified examples trivialize the problems and the solutions intended to solve those simplified examples may not work for the complex problems.
  • Examples of problematic ___ code must be the “best way” of writing the code in ___ - if it can be improved then the improved version should be used instead.
  • Arguments must be straight to the point and as concise as possible.
  • Arguments should take the point of view of an average programmer - not the über-programmer who doesn’t make design mistakes.
class FragmentViewBindingDelegate<T : ViewBinding>(private val factory: (View) -> T) : ReadOnlyProperty<Fragment, T> {
private var backingValue: T? = null
override operator fun getValue(thisRef: Fragment, property: KProperty<*>): T = when (val binding = backingValue) {
null -> {
thisRef.parentFragmentManager.registerFragmentLifecycleCallbacks(object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentViewDestroyed(fm: FragmentManager, fragment: Fragment) {
if (fragment != thisRef) return
backingValue = null
fm.unregisterFragmentLifecycleCallbacks(this)
@granoeste
granoeste / MainActivity.java
Created August 8, 2012 03:06
[Android] Button background change for state. (selector)
package com.example.sellectorsample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
@morenodoug
morenodoug / utilsAndroid.java
Created June 27, 2020 18:37
Adding an image to mediaStore(see in phone gallery) on Android
public static void notifyMediaStoreScanner(Context mContext, Uri cacheImageUri) throws IOException {
Uri newImageUri = createImageInMediaStore(mContext, cacheImageUri);
ContentResolver resolver = mContext
.getContentResolver();
FileInputStream input ;
FileOutputStream outputStream ;
try (ParcelFileDescriptor pfd = resolver
.openFileDescriptor(newImageUri, "w", null)) {
// Write data into the pending image.
@JorgeCastilloPrz
JorgeCastilloPrz / RatingStars.kt
Last active August 29, 2021 23:43
Composable to show rating stars. Noninteractive.
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
@sdex
sdex / CountryAutoCompleteAdapter.java
Created November 20, 2015 11:28
Android: AutoCompleteTextView with Realm.io database
/*
* Copyright 2015 Yuriy Mysochenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software