Skip to content

Instantly share code, notes, and snippets.

View dzolnai's full-sized avatar

Dániel Zolnai dzolnai

  • Egeniq
  • Budapest
View GitHub Profile
@dzolnai
dzolnai / AutoHotKey.ahk
Last active May 13, 2025 16:40
AutoHotKey for remapping Windows + 1, 2, 3... to Windows + Q, W, E...
; Windows + Q calls Windows + 1
#q::
Send {LWin Down}1
Sleep 200
While GetKeyState("LWin","P")
{
KeyWait, q, D T0.3
If !ErrorLevel ; if you do press q
{
Send {Blind}1
@dzolnai
dzolnai / View.kt
Last active August 2, 2023 15:12
Expandable TextView with clickable '...read more'
import android.annotation.SuppressLint
import android.content.Context
import android.text.Layout
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.StaticLayout
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
@dzolnai
dzolnai / DisallowToolbarExpand.kt
Created December 28, 2020 15:20
Disallow the toolbar expand on a collapsible toolbar layout
internal fun disallowToolbarExpand() {
// Taken from: https://stackoverflow.com/a/49218710/1395437
binding.appBar.setExpanded(false, false)
ViewCompat.setNestedScrollingEnabled(binding.content, false)
val params = binding.appBar.layoutParams as CoordinatorLayout.LayoutParams
if (params.behavior == null) {
params.behavior = AppBarLayout.Behavior()
}
val behaviour = params.behavior as AppBarLayout.Behavior
behaviour.setDragCallback(object : AppBarLayout.Behavior.DragCallback() {
@dzolnai
dzolnai / OAuthClient.java
Last active August 18, 2021 07:23
Retrofit OAuth2 refreshing tokens without modifying all requests.
package com.example.yourapp;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.example.yourapp.AuthenticationModel;
import retrofit.client.Header;
import retrofit.client.OkClient;
@dzolnai
dzolnai / fragment_genres.xml
Created February 3, 2021 07:30
Genre fragment with a CollapsingToolbarLayout
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:expandedTitleMarginStart="@dimen/genre_clickable_title_left_margin"
app:expandedTitleMarginBottom="@dimen/genre_clickable_title_bottom_margin"
app:expandedTitleMarginTop="0dp"
app:collapsedTitleGravity="center"
android:background="@color/background"
app:collapsedTitleTextAppearance="@style/AppTheme.CollapsingToolbarTitle.Collapsed"
@dzolnai
dzolnai / AppBarOffsetChangeListener.kt
Created December 28, 2020 15:09
Detect appbar offset
binding.appBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
// By updating the LayoutParams, we trigger the offset change listener, which then results in a somewhat infinite loop.
// This flag makes sure that we discard the next callback after updating the layout.
if (verticalOffset == lastOffset) {
return@OnOffsetChangedListener
}
val offsetPercentage = verticalOffset / -maxOffset // 0 is fully expanded, 1 is fully collapsed
val interpolatedPercentage = interpolator.getInterpolation(offsetPercentage)
val baseWidth = expandedTextWidth - (expandedTextWidth - collapsedTextWidth) * interpolatedPercentage
val marginExtra = expandedMargin - (expandedMargin - collapsedMargin) * offsetPercentage
public class PracticalInfoFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_practical_info, container, false);
TextView practicalInfo = (TextView)view.findViewById(R.id.practical_info);
practicalInfo.setMovementMethod(LinkMovementMethod.getInstance());
String infoString = _readStringFromAssets(); // Not detailed here, content can be seen in the other file below
_setTextViewLinks(practicalInfo, infoString);
return view;
@dzolnai
dzolnai / CustomMediaRouteButton.kt
Last active April 23, 2020 09:26
Custom Media Route button which hides when there are no Cast devices on the network
@file:Suppress("PackageDirectoryMismatch")
package androidx.mediarouter.app
import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat
import androidx.mediarouter.media.MediaRouter
class CustomMediaRouteButton : MediaRouteButton {
@dzolnai
dzolnai / SubRowsSupportFragment.kt
Last active April 22, 2020 08:06
RowsSupportFragment which also remembers position in last selected row.
@file:Suppress("PackageDirectoryMismatch")
package android.support.v17.leanback.widget
import android.os.Bundle
import android.support.v17.leanback.app.RowsSupportFragment
import android.support.v7.widget.RecyclerView
import android.view.View
/**
* RowsSupportFragment which also remembers the subposition in the rows.
@dzolnai
dzolnai / MainActivity.kt
Created November 29, 2019 13:06
Creating an ExoPlayer with your own audioprocessor
private val fftAudioProcessor = FFTAudioProcessor()
val renderersFactory = object : DefaultRenderersFactory(this) {
override fun buildAudioProcessors(): Array<AudioProcessor> {
val processors = super.buildAudioProcessors()
return processors + fftAudioProcessor
}
}
player = ExoPlayerFactory.newSimpleInstance(this, renderersFactory, DefaultTrackSelector())