Skip to content

Instantly share code, notes, and snippets.

View maiconhellmann's full-sized avatar
:octocat:

Maicon Hellmann maiconhellmann

:octocat:
View GitHub Profile
/**
* Check if a point cliked is in the are of a line.
*/
class CheckLineClicked {
/**
* Returns the distance between a point(clickPosition) and a line(start and end point).
*/
fun checkLineClicked(clickPosition: PointF, startPoint: PointF, endPointF: PointF): Float {
val x = clickPosition.x
@maiconhellmann
maiconhellmann / MyAmazingActivity
Created November 30, 2020 13:46
screenOrientation - smartphone = PORTRAIT and tablet = DYNAMIC
class MyAmazingActivity: AppCompatActivity {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (resources.getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR)
}
}
@maiconhellmann
maiconhellmann / view.xml
Last active March 20, 2020 14:30
Android - makes a view consumes all available space(fixes an issue related to the width of the component when used inside a RecyclerView). This is also a work around, the real problem is when a component is instantiated in code it should provide the layoutParams.
<View
....
app:layout_constraintHorizontal_bias="0"
android:layout_width="0dp"
app:layout_constraintWidth_default="wrap" >
</View>
@maiconhellmann
maiconhellmann / adapter.kt
Created September 1, 2019 11:52
A simple recyclerView adapter/viewHolder
class CurrencyAdapter: RecyclerView.Adapter<CurrencyAdapter.ViewHolder>() {
var data: List<YourModelName> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(parent)
import io.reactivex.Single
import io.reactivex.SingleSource
import io.reactivex.SingleTransformer
/**
* Sealed class to handle ViewStates.
*
* When an error happens it will return a [ViewState.Failed] with a [ViewState.Failed.throwable] field
*
@maiconhellmann
maiconhellmann / API url
Last active June 12, 2020 20:37
Htpp client using Koin DI, Retrofit and OkHttp
//more plugins here....
apply plugin: 'kotlin-kapt'
android {
//your stuff...
buildTypes {
release {
//your stuff...
buildConfigField "String", "BASE_URL", "\"https://your.api.url//\""
@maiconhellmann
maiconhellmann / bg_radio_toggle_left.xml
Created April 8, 2018 10:31
RadioButton with a behavior of a ToggleButton or TabButton
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape android:shape="rectangle">
<solid android:color="#3B5A9A" />
<corners android:bottomLeftRadius="4dp"
android:topLeftRadius="4dp"/>
</shape>
</item>
@maiconhellmann
maiconhellmann / sendImageMultipartRetrofitRxJava.kt
Created March 11, 2018 12:10
Send image or file multipart retrofit RxJava
//Preparing the request
val filePart = MultipartBody.Part
.createFormData("file", "fileName",
RequestBody.create(MediaType.parse("image/jpeg"), File("/your/File/Path.jpg")))
//service.sendFile(id, filePart)
//Request definition retrofit
@PUT("https://www.yourdomain.com/api/file/{id}")
@Multipart
fun sendFile(@Path("id") id: Long, @Part file: MultipartBody.Part ) : Observable<YourModel>
@maiconhellmann
maiconhellmann / CustomMapMarker.java
Created December 2, 2017 14:07
Custom map Marker in Java
private MarkerOptions createMarkerIcon(LatLng position) {
FrameLayout frameLayout = new FrameLayout(getContext());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
frameLayout.setLayoutParams(params);
View markerView = getActivity().getLayoutInflater().inflate(R.layout.custom_map_marker, frameLayout);
BitmapDescriptor bitmapMerged = BitmapDescriptorFactory.fromBitmap(BitmapUtils.createDrawableFromView(getContext(), markerView));
@maiconhellmann
maiconhellmann / RxJavaTimerTask.kt
Last active November 4, 2020 23:22
Timer task in RxJava kotlin/java
val subscription = Observable.interval(0, 5, TimeUnit.SECONDS)
.timeInterval()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe {
//TODO
}