Skip to content

Instantly share code, notes, and snippets.

View zerobranch's full-sized avatar

Arman Sargsyan zerobranch

View GitHub Profile
@zerobranch
zerobranch / SwipeLayout.java
Last active February 16, 2021 21:17
This custom view provides an opportunity to perform swipe for any layout. SwipeLayout is just a 'Custom ViewGroup', extended from FrameLayout, which provides easy and fast to use the 'swipe to dismiss' function, without using the ItemTouchHelper, for any layout.
/*
* The MIT License (MIT)
*
* Copyright (c) 2018 Arman Sargsyan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@zerobranch
zerobranch / CheckableLinearLayout.java
Last active October 3, 2018 07:43
Checkable Linear Layout
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.LinearLayout;
import java.util.HashSet;
import java.util.Set;
public class CheckableLinearLayout extends LinearLayout implements Checkable {
@zerobranch
zerobranch / TimerUtils.java
Created October 4, 2018 08:13
TimerUtils allows to start a timer
import java.util.Timer;
import java.util.TimerTask;
public class TimerUtils {
private TimerTask timerTask;
private Timer timer;
private Action action;
public void start(Action action, int delay) {
this.action = action;
@zerobranch
zerobranch / BaseMainFragment.java
Created October 4, 2018 08:23
When animating, the next fragment will be ABOVE the previous one. Copy xml resources to res/animator
public abstract class BaseMainFragment extends Fragment {
@Override
public Animation onCreateAnimation(int transit, final boolean enter, int nextAnim) {
if (nextAnim == R.animator.next_fragment_anim) {
Animation nextAnimation = AnimationUtils.loadAnimation(getContext(), nextAnim);
nextAnimation.setAnimationListener(new Animation.AnimationListener() {
private float startZ = 0f;
@Override
@zerobranch
zerobranch / KeyboardVisibilityUtils.java
Created October 4, 2018 08:27
Keyboard visibility utils
import android.app.Activity;
import android.view.View;
import android.view.ViewTreeObserver;
public class KeyboardVisibilityUtils {
private int appHeight;
private final View contentView;
private ViewTreeObserver.OnGlobalLayoutListener layoutListener;
public KeyboardVisibilityUtils(Activity activity) {
@zerobranch
zerobranch / CustomTypefaceSpan.java
Created October 4, 2018 08:34
SpannableUtils allows you to format a different part of a text
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;
public class CustomTypefaceSpan extends TypefaceSpan {
private final Typeface newType;
public CustomTypefaceSpan(String family, Typeface type) {
super(family);
@zerobranch
zerobranch / App.java
Created October 4, 2018 08:36
Class allows to catch all exceptions
import android.app.Application;
import timber.log.Timber;
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
@zerobranch
zerobranch / ProgressTextView.java
Last active February 27, 2019 19:30
ProgressTextView is a FrameLayout consisting of TextView and ProgressBar elements. It displays either text or download animation. It is also possible to specify the border of the element (color, width, radius) directly from the layout.
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Arman
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@zerobranch
zerobranch / RoundedTextView.java
Created April 13, 2019 17:58
RoundedTextView is a TextView that allows to specify parameters such as the border, the radius of the element, etc., directly from the layout.
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Arman
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@zerobranch
zerobranch / ripple_background.xml
Created September 5, 2020 12:50
Ripple background
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?colorControlHighlight">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#f7f7f7" />
<corners android:radius="10dp" />
</shape>