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 / AnimatingDialogFragment.kt
Created May 23, 2018 15:01
DialogFragment which can have hide animations
/**
* Dialog Fragment with hide animations
*/
class AnimatingDialogFragment : DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.TvTheme_Dialog)
}
@dzolnai
dzolnai / ItemFocusHighlighter.kt
Created May 23, 2018 14:48
A Leanback focus highlight helper which can delay focus changes on demand.
@file:Suppress("PackageDirectoryMismatch")
package android.support.v17.leanback.widget
import android.os.Handler
import android.os.Looper
import android.view.View
import java.lang.ref.WeakReference
/**
@dzolnai
dzolnai / BaseGridFragment.kt
Created May 23, 2018 13:46
A BaseGridFragment contains a VerticalGridSupportFragment which is modified to allow focus to escape it.
abstract class BaseGridFragment : Fragment() {
private var lifecycleCallbacks: FragmentManager.FragmentLifecycleCallbacks? = null
/**
* If your fragment contains a VerticalGridSupportFragment, it automatically includes a search button you can disable.
* However, the focus search listener is not disabled, and it does conflict with our implementation for showing the menu.
* Don't forget to save a reference to the callbacks to unsubscribe when destroying the fragment.
*/
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@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 / simplex.c
Created January 17, 2017 18:46
Simplex solver article - gist 6
for (int j = start_index; j < end_index; j++) {
float value = get_element(tableau, tableau->rows - 1, j);
rsSetElementAt_float(solution_vector, value, j - start_index);
}
rsSetElementAt_int(result_size, end_index - start_index, 0);
@dzolnai
dzolnai / simplex.h
Created January 17, 2017 18:42
Simplex solver article - gist 5
#define DEBUG true
#if DEBUG
#define LOG(msg, param) rsDebug(msg, param)
#else
#define LOG(msg, param)
#endif
@dzolnai
dzolnai / simplex.c
Last active January 17, 2017 18:32
Simples solver article - gist 4
#pragma version(1)
#pragma rs java_package_name(com.egeniq.lpsolver.renderscript)
#pragma rs_fp_full
#include "simplex.rsh"
@dzolnai
dzolnai / SimplexRS.java
Created January 17, 2017 18:27
Simplex solver article - gist 3
Type solutionVectorType = new Type.Builder(renderScript, Element.F32(renderScript)).setX(script.get_MAX_COLS()).create();
Type resultSizeType = new Type.Builder(renderScript, Element.I32(renderScript)).create();
script.set_solution_vector(arrayAllocation);
script.set_result_size(resultSizeAllocation);
script.invoke_solve();
float[] solutionVector = new float[script.get_MAX_COLS()];
arrayAllocation.copyTo(solutionVector);
int[] resultSizeVector = new int[1];
resultSizeAllocation.copyTo(resultSizeVector);
@dzolnai
dzolnai / simplex.h
Created January 17, 2017 18:16
Simplex solver article - gist 1
typedef struct __attribute__((packed)) Tableau {
int rows, columns;
float matrix[MAX_ROWS * MAX_COLS];
bool dual_program;
} Tableau_t;
Tableau_t *tableau;
@dzolnai
dzolnai / SimplexRS.java
Last active January 17, 2017 18:17
Simplex solver article - gist 2
ScriptC_simplex script = new ScriptC_simplex(renderScript);
ScriptField_Tableau tableau = new ScriptField_Tableau(renderScript, 1);
int rowCount = data.length;
int columnCount = data[0].length;
tableau.set_rows(0, rowCount, false);
tableau.set_columns(0, columnCount, false);
tableau.set_dual_program(0, minimize, false);
tableau.set_matrix(0, data, false);
// Copy all values at once to the allocated memory of the struct.
tableau.copyAll();