Skip to content

Instantly share code, notes, and snippets.

View rocboronat's full-sized avatar
🦆
Bulding Flutter apps

Roc Boronat rocboronat

🦆
Bulding Flutter apps
View GitHub Profile
@rocboronat
rocboronat / BluetoothUtil.java
Last active March 5, 2018 07:24
Some Bluetooth Android actions
package net.rocboronat.android.utils;
import java.lang.reflect.Method;
import java.util.Set;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.util.Log;
public class BluetoothUtil {
@rocboronat
rocboronat / dimens.xml
Last active June 30, 2018 19:04
A basic dimens.xml for Android, with applied Android Design guidelines
<resources>
<!-- http://developer.android.com/design/style/metrics-grids.html -->
<dimen name="gap_small">4dp</dimen>
<dimen name="gap_medium">8dp</dimen>
<dimen name="gap_large">16dp</dimen>
<dimen name="gap_xlarge">32dp</dimen>
<dimen name="gap_xxlarge">64dp</dimen>
<!-- http://developer.android.com/design/style/typography.html -->
@rocboronat
rocboronat / SomeActivity.java
Last active August 29, 2015 14:06
Show a PopupWindow with negative margin on a MenuItem of the ActionBar
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_listoffers, menu);
new Handler().post(new Runnable() {
@Override
public void run() {
final View menuItemView = findViewById(R.id.action_search);
@rocboronat
rocboronat / BaseActivity.java
Last active April 13, 2016 08:16
Calling setTaskDescription() in a reflected way
private void setTaskDescription(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
String title = getString(R.string.app_name);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
int color = getResources().getColor(R.color.task_background);
// The legacy method call
// setTaskDescription(new ActivityManager.TaskDescription(title, icon, color));
// The reflected method call
@rocboronat
rocboronat / RippleDelayedRunner.java
Last active November 29, 2020 12:42
A simple way to call the common new Handler().postDelayed(..., time);
package com.fewlaps.android.quitnow.base.customview;
import android.os.Handler;
import android.view.View;
/**A simple way to call the common new Handler().postDelayed(..., time);
*
* Created by Roc Boronat on 12/12/2014.
*/
public class RippleDelayedRunner implements View.OnClickListener {
@rocboronat
rocboronat / CubicBezierInterpolator.java
Created March 17, 2015 11:22
Cubic Bezier Android interpolator
package com.infojobs.app.base.utils.animation;
import android.graphics.PointF;
import android.view.animation.Interpolator;
/**
* Derived from: https://github.com/rdallasgray/bez
*/
public class CubicBezierInterpolator implements Interpolator {
@rocboronat
rocboronat / GetMonthName.java
Last active June 30, 2018 19:04
Get the names of the months, from strings.xml or the SimpleDateFormat class
public String getDateMonthFromStrings(Context context, DateTime date) {
String result;
if (date.getMonthOfYear() == 1) {
result = context.getString(R.string.month_january);
} else if (date.getMonthOfYear() == 2) {
result = context.getString(R.string.month_february);
} else if (date.getMonthOfYear() == 3) {
result = context.getString(R.string.month_march);
} else if (date.getMonthOfYear() == 4) {
result = context.getString(R.string.month_april);
@rocboronat
rocboronat / ConfirmCancelDialogFragment.java
Last active August 29, 2015 14:20
A common DialogFragment with a confirm and a cancel button
package com.infojobs.app.base.view.fragment;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
@rocboronat
rocboronat / DarkOrLightColour.java
Last active June 30, 2018 19:04
Know if a text on a dynamic background colour must be black or white to be easy to read
int color = palette.getVibrantColor(defaultColor);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;
row.setBackgroundColor(color);
//@see http://stackoverflow.com/questions/12043187/how-to-check-if-hex-color-is-too-black
double luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
@rocboronat
rocboronat / KeyboardUtil.java
Created June 3, 2015 09:24
The common util with common methods to work with Android SoftKeyboard (the common one)
package at.rocboron.android.utils;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
public class SoftKeyboardUtil {