Skip to content

Instantly share code, notes, and snippets.

View douglasjunior's full-sized avatar
:atom:
yarn start

Douglas Nassif Roma Junior douglasjunior

:atom:
yarn start
View GitHub Profile
@douglasjunior
douglasjunior / BluetoothWriter.h
Last active August 29, 2015 14:21
Exemplo de código Objective-C
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface BluetoothWriter : NSObject
-(id) initWithPeripheral:(CBPeripheral *) peripheral characteristic:(CBCharacteristic *)characteristic;
- (void) writeString:(NSString *) value;
- (void) writeData:(NSData *) value;
-(void) writeColorWithRed:(int)red withGreen:(int)green withBlue:(int)blue;
@douglasjunior
douglasjunior / BluetoothWriter.swift
Created May 21, 2015 15:02
Exemplo de código Swift
import Foundation
import CoreBluetooth
class BluetoothWriter : NSObject {
private weak var peripheral: CBPeripheral!;
private weak var characteristic: CBCharacteristic!;
init(peripheral : CBPeripheral, characteristic:CBCharacteristic) {
self.peripheral = peripheral;
//
// AsyncTask.swift
//
// Created by Douglas Nassif Roma Junior on 08/06/15.
// Copyright (c) 2015 Douglas Nassif Roma Junior. All rights reserved.
//
import Foundation
class AsyncTask<Params, Progress, Result> : NSObject {
@douglasjunior
douglasjunior / exemploJson.php
Last active August 20, 2022 17:23
Exemplo de consulta no banco de dados e retorno de JSON utilizando PHP e MySQL.
<?php
header('Content-Type: application/json');
header('Character-Encoding: utf-8');
// recebe os parâmetros
$QTD = (int) filter_input(INPUT_GET, 'qtd', FILTER_VALIDATE_INT);
$LAT = (float) filter_input(INPUT_GET, 'lat', FILTER_VALIDATE_FLOAT);
$LNG = (float) filter_input(INPUT_GET, 'lng', FILTER_VALIDATE_FLOAT);
if ($LAT && $LNG) {
@douglasjunior
douglasjunior / AbstractAdapter.java
Last active September 10, 2015 00:33
Exemplo de uso do Adapter com RecyclerView
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import java.util.ArrayList;
import java.util.List;
@douglasjunior
douglasjunior / OnItemSelectedListener.java
Last active January 20, 2019 00:49
Implementação de Adapter genérico para utilizar no com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner (ver comentários)
package com.youtproject.util;
import android.text.Editable;
import android.text.TextWatcher;
/**
* Listener used to capture "on selected item" event on MaterialBetterSpinner.
* Created by douglas on 22/09/15.
*/
public abstract class OnItemSelectedListener implements TextWatcher {
@douglasjunior
douglasjunior / CustomMaterialSpinner.java
Created September 30, 2015 12:29
Override to fix enable/disable problem.
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner;
/**
* Created by Douglas Nassif Roma Junior on 30/09/15.
*/
public class CustomMaterialSpinner extends MaterialBetterSpinner {
@douglasjunior
douglasjunior / ProgressRequestBody.java
Created February 19, 2016 11:33
Class used to monitoring the file upload progress in Retrofit2 library.
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.BufferedSink;
@douglasjunior
douglasjunior / MyActivity.java
Last active October 11, 2018 19:47
Allows RecyclerView work like a FlowLayout.
public class MyActivity extends Activity {
public void onCreate(...){
RecyclerView rv = findViewByIdCast(R.id.rv);
// 2 is the number of columns
rv.setLayoutManager(new GridLayoutManager(this, 2));
// Calculates the width of the "CardView" dynamically.
int cardViewWidth = getResources().getDimension(R.dimen.my_cardview_width) + getResources().getDimension(R.dimen.my_cardview_margin) * 2;
rv.getViewTreeObserver().addOnGlobalLayoutListener(new OnFlowLayoutListener(rv, cardViewWidth));
}
@douglasjunior
douglasjunior / Connectivity.java
Created September 12, 2016 11:49 — forked from emil2k/Connectivity.java
Android utility class for checking device's network connectivity and speed.
package com.emil.android.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/**
* Check device's network connectivity and speed
* @author emil http://stackoverflow.com/users/220710/emil