Skip to content

Instantly share code, notes, and snippets.

View Subtle-fox's full-sized avatar

Andrey Kolpakov Subtle-fox

  • Avito
  • St. Petersburg, Russia
View GitHub Profile
@Subtle-fox
Subtle-fox / PaginationScrollListener.kt
Last active May 30, 2019 13:38
RecyclerView's scroll listener with pagination callback
/*
https://github.com/codepath/android_guides/wiki/Endless-Scrolling-with-AdapterViews-and-RecyclerView
Contributed content licensed under cc-wiki with attribution required
*/
abstract class PaginationScrollListener(var layoutManager: LinearLayoutManager) : RecyclerView.OnScrollListener() {
// The minimum number of items to have below your current scroll position
// before loading more.
private var visibleThreshold = 20
// The current offset index of data you have loaded
@Subtle-fox
Subtle-fox / build.gradle
Created July 5, 2018 07:11
gradle : resolve version conflicts
buildscript { ... }
allprojects { ... }
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support') {
details.useVersion "27.1.1"
}
@Subtle-fox
Subtle-fox / Constraints
Created June 29, 2018 12:55
Modify constraints programmatically
ConstraintSet set = new ConstraintSet();
ConstraintLayout layout;
layout = (ConstraintLayout) findViewById(R.id.layout);
set.clone(layout);
// The following breaks the connection.
set.clear(R.id.bottomText, ConstraintSet.TOP);
// Comment out line above and uncomment line below to make the connection.
// set.connect(R.id.bottomText, ConstraintSet.TOP, R.id.imageView, ConstraintSet.BOTTOM, 0);
set.applyTo(layout);
@Subtle-fox
Subtle-fox / getParentView
Created April 6, 2018 12:25
Get root view in activity
public static View getParentView(Activity activity) {
return ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
}
@Subtle-fox
Subtle-fox / MultilineImeAction.txt
Last active April 6, 2018 12:22
Set soft keyboard action for multiline text
public static void setMultilineImeAction(EditText view, int imeAction) {
int inputType = view.getInputType();
inputType &= ~InputType.TYPE_TEXT_FLAG_MULTI_LINE;
view.setInputType(inputType);
view.setHorizontallyScrolling(false);
view.setMaxLines(Integer.MAX_VALUE);
view.setImeOptions(imeAction);
}
@Subtle-fox
Subtle-fox / FabMenu.java
Created March 6, 2018 12:38
"Floating Action Button" menu
/**
* Created by Andrey Kolpakov on 19.01.2018
*/
public class FabMenu {
private final ViewGroup parent;
private final Context context;
private final FloatingActionButton fab;
private boolean isFabMenuOpened;
private View maskedView;
@Subtle-fox
Subtle-fox / getResourceId
Last active July 12, 2017 13:36
Obtain resourse identifier by it's name
public static int getResIdByName(Context appContext, String resType, String name) {
return appContext.getResources().getIdentifier(name, resType, appContext.getPackageName());
}
// usage:
getResIdByName(appContext, "string", name);
getResIdByName(appContext, "drawable", name);
getResIdByName(appContext, "layout", name);
@Subtle-fox
Subtle-fox / library_version.gradle
Created July 7, 2017 13:32
Samle how to use variables in build.gradle
ext {
support_version = '25.0.0'
play_service_version = '11.0.0'
}
android {
...
}
dependencies {
@Subtle-fox
Subtle-fox / fabric_gradle_task.gradle
Created July 7, 2017 13:24
Task for publishing in Fabric (with build number increment)
...
android {
def versionPropsFile = file('version.properties')
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def buildNumber = versionProps['VERSION_BUILD'].toInteger() + 1
defaultConfig {
versionCode buildNumber