Skip to content

Instantly share code, notes, and snippets.

View felipeslongo's full-sized avatar
🌴
Having Fun With Threads

Felipe de Souza Longo felipeslongo

🌴
Having Fun With Threads
View GitHub Profile
@joaocruz04
joaocruz04 / android_room_fts4.md
Last active May 21, 2024 04:40
Enabling FTS4 on an Android + Room project

Enabling FTS4 on an Android project with Room

You can do a SQL text query by using the LIKE operator. The issue is that using it requires a lot of computation, as a complete string query is done. Also if you want to have more search options (more fields), your query will grow a lot in complexity. To solve this issue, there's a concept of virtual tables for full text search (FTS).

We will build our solution using Room (already set in the project). We're using version 2.2.0-rc01 for that.

Step 1 - Create new Virtual Table

With Room, the only thing we need is to create the new class with @FTS4 notation. By specifying contentEntity to be the Route class, it means that it will reuse the values from the Route table instead of populating this one with copies. The fields in question should match the ones from the Route table. In this example we only need the title.

@jimmgarrido
jimmgarrido / workaround.md
Last active October 2, 2018 07:37
Broken Support Library Download Workaround

1. Go to %LOCALAPPDATA%\Xamarin

2. If it doesn't already exist, create a new folder named after the support library NuGet package, e.g. Xamarin.Android.Support.v4

3. Repeat for every support library package in your project:

4. Open the Xamarin Android SDK Manager and download the Android Support Repository (under Tools > Extras):

5. Go to [Android SDK location]\extras\android\m2repository\com\android\support and open the directory for the support library you need

6. Find the correct version and copy the entire folder to directory you created in step 2. The correct version is the one that matches or is nearest to the NuGet package version. For example, if the package version is 23.4.0.1 the support library version would be 23.4.0. If you did not create a folder in

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.kelvinchandra.myapplication.MainActivity">
@florina-muntenescu
florina-muntenescu / Data.kt
Last active October 16, 2024 21:39
Using RoomDatabase#Callback to pre-populate the database - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
public class DumbViewHolder extends RecyclerView.ViewHolder {
TextView textTitle;
TextView textLocation;
TextView textDate;
ImageView mapIcon;
public DumbViewHolder(View itemView) {
super(itemView);
textTitle = (TextView) itemView.findViewById(R.id.text_title);
textLocation = (TextView) itemView.findViewById(R.id.text_location);
@jonfhancock
jonfhancock / ExcellentAdventure.java
Last active February 25, 2021 07:00
This set of classes demonstrates what a Not Dumb ViewHolder should look like. It lightens the load on the Adapter, and places decisions about what to do with user interactions on the Activity where it belongs.
public class ExcellentAdventure {
@Retention(SOURCE)
@StringDef({ERA_BC, ERA_AD})
public @interface Era {
}
public static final String ERA_BC = "BC";
public static final String ERA_AD = "AD";
@liberorignanese
liberorignanese / MarginSpan.java
Last active January 12, 2024 18:05
Android TextInputLayout with credit card mask
package com.liberorignanese.android.gist;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.style.ReplacementSpan;
/**
* Created by Libero Rignanese.
*/
@Ilya-Gazman
Ilya-Gazman / HtmlBuilder.java
Last active February 19, 2018 21:06
An easy way to work with HTML in Android. Just set the textView with the build result.
public class HtmlBuilder {
public static final String COLOR = "[color]";
public enum Type{
BOLD("strong"),
ITALIC("em"),
COLOR("font color=\"#"+ HtmlBuilder.COLOR + "\""),
SMALL("small")
;
public final String stringType;
@aspnetde
aspnetde / .View
Last active September 28, 2021 10:11
Xamarin.iOS MemoryUtility
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.MessageUI;
using MonoTouch.UIKit;
namespace MyApp
{
public interface ICanCleanUpMyself
{
@vkhorikov
vkhorikov / CustomerController.cs
Last active July 30, 2024 14:25
Handling failures and input errors in a functional way
[HttpPost]
public HttpResponseMessage CreateCustomer(string name, string billingInfo)
{
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo);
Result<CustomerName> customerNameResult = CustomerName.Create(name);
return Result.Combine(billingInfoResult, customerNameResult)
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value))
.OnSuccess(() => new Customer(customerNameResult.Value))
.OnSuccess(