Skip to content

Instantly share code, notes, and snippets.

@mzgreen
mzgreen / SizeHelper.kt
Last active February 13, 2021 15:23
A ConstraintHelper implementation that has additional layout params: screenHeight_percent and screenWidth_percent which allow to make referenced views height and width to be equal to screenHeight(or screenWidth)*some_percent_value. Where some_percent_value is a value between 0.0 and 1.0.
class SizeHelper @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintHelper(context, attrs, defStyleAttr) {
private val screenHeight: Int = resources.displayMetrics.heightPixels
private val screenWidth: Int = resources.displayMetrics.widthPixels
private var layoutConstraintScreenHeightPercent = UNSPECIFIED_CONSTRAINT_SCREEN_PERCENT
@mzgreen
mzgreen / GLTextureView.java
Created January 4, 2019 10:00
GLTextureView based on updated version of GLSurfaceView (commit: 6e80c54 on 9 Aug 2018)
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.opengl.EGL14;
import android.opengl.EGLExt;
import android.opengl.GLDebugHelper;
import android.opengl.GLSurfaceView;
import android.os.Trace;
import android.util.AttributeSet;
import android.util.Log;
import android.view.TextureView;
@mzgreen
mzgreen / ScrollingFABBehavior.java
Last active January 25, 2019 05:52
HideOnScrollExample - custom fab behavior
public class ScrollingFABBehavior extends CoordinatorLayout.Behavior<FloatingActionButton> {
private int toolbarHeight;
public ScrollingFABBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
this.toolbarHeight = Utils.getToolbarHeight(context);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton fab, View dependency) {
@mzgreen
mzgreen / ScrollingSwipeRefreshLayoutBehavior.java
Created July 13, 2015 10:08
ScrollingSwipeRefreshLayoutBehavior
public class ScrollingSwipeRefreshLayoutBehavior extends AppBarLayout.ScrollingViewBehavior {
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
return super.layoutDependsOn(parent, child, dependency) || (dependency instanceof AppBarLayout);
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
boolean returnValue = super.onDependentViewChanged(parent, child, dependency);
@mzgreen
mzgreen / HidingScrollListener.java
Created February 15, 2015 11:18
HideOnScrollExample - HidingScrollListener class
public abstract class HidingScrollListener extends RecyclerView.OnScrollListener {
private static final int HIDE_THRESHOLD = 20;
private int scrolledDistance = 0;
private boolean controlsVisible = true;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
@mzgreen
mzgreen / MainActivity.java
Created February 15, 2015 11:12
HideOnScrollExample - MainActivity class
public class MainActivity extends ActionBarActivity {
private Toolbar mToolbar;
private ImageButton mFabButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initToolbar();
mFabButton = (ImageButton) findViewById(R.id.fabButton);
@mzgreen
mzgreen / fragment_part_three.xml
Created June 23, 2015 10:48
HideOnScrollExample - fragment_part_three layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
@mzgreen
mzgreen / activity_part_three.xml
Created June 23, 2015 11:54
HidingScrollExample - scrolling Toolbar
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways" />
@mzgreen
mzgreen / activity_part_three.xml
Created June 23, 2015 11:22
HideOnScrollExample - behavior added to a ViewPager
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
@mzgreen
mzgreen / activity_part_three.xml
Created June 23, 2015 12:03
HideOnScrollExample - adding fab
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_favorite_outline_white_24dp"
app:borderWidth="0dp" />