Skip to content

Instantly share code, notes, and snippets.

@mzgreen
mzgreen / GLTextureView.java
Created Jan 4, 2019
GLTextureView based on updated version of GLSurfaceView (commit: 6e80c54 on 9 Aug 2018)
View GLTextureView.java
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 / SizeHelper.kt
Last active Jul 6, 2020
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.
View SizeHelper.kt
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 / ScrollingSwipeRefreshLayoutBehavior.java
Created Jul 13, 2015
ScrollingSwipeRefreshLayoutBehavior
View ScrollingSwipeRefreshLayoutBehavior.java
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 / activity_part_three.xml
Created Jun 23, 2015
HideOnScrollExample - adding behavior to the fab
View activity_part_three.xml
<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"
app:layout_behavior="pl.michalz.hideonscrollexample.ScrollingFABBehavior" />
@mzgreen
mzgreen / ScrollingFABBehavior.java
Last active Jan 25, 2019
HideOnScrollExample - custom fab behavior
View ScrollingFABBehavior.java
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 / activity_part_three.xml
Created Jun 23, 2015
HideOnScrollExample - adding fab
View activity_part_three.xml
<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" />
@mzgreen
mzgreen / activity_part_three.xml
Created Jun 23, 2015
HidingScrollExample - scrolling Toolbar
View activity_part_three.xml
<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 Jun 23, 2015
HideOnScrollExample - behavior added to a ViewPager
View activity_part_three.xml
<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 / PartThreeActivity.java
Created Jun 23, 2015
HideOnScrollExample - PartThreeActivity pager and tabs initialization
View PartThreeActivity.java
private void initViewPagerAndTabs() {
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager());
pagerAdapter.addFragment(PartThreeFragment.createInstance(20), getString(R.string.tab_1));
pagerAdapter.addFragment(PartThreeFragment.createInstance(4), getString(R.string.tab_2));
viewPager.setAdapter(pagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);
tabLayout.setupWithViewPager(viewPager);
}
@mzgreen
mzgreen / activity_part_three.xml
Created Jun 23, 2015
HideOnScrollExample - activity_part_three layout
View activity_part_three.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
You can’t perform that action at this time.