Skip to content

Instantly share code, notes, and snippets.

View SerggioC's full-sized avatar
🎯
Focusing

Sergio C SerggioC

🎯
Focusing
  • Portugal
View GitHub Profile
DBHelper dbHelper = new DBHelper(getContext());
SQLiteDatabase db = dbHelper.getWritableDatabase();
List<String> distinct_id_products = new ArrayList<>();
ArrayList<ArrayList<Double>> priceValues_Array_arrayList = new ArrayList<>();
String query1 = "SELECT DISTINCT " + ProductsContract.PricesEntry.COLUMN_ID_PRODUCTS +
" FROM " + ProductsContract.PricesEntry.TABLE_NAME +
" ORDER BY " + ProductsContract.PricesEntry.COLUMN_ID_PRODUCTS;
Cursor cursor1 = db.rawQuery(query1, null);
int cursor1Count = cursor1.getCount();
@SerggioC
SerggioC / build.gradle
Last active April 30, 2018 15:13
build.gradle (app module) optimized template
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.android.mygarden"
minSdkVersion 15
targetSdkVersion 27
@SerggioC
SerggioC / build.gradle
Created March 27, 2018 23:06
build.gradle (project module) optimized template
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
// Android Plugin for Gradle
@SerggioC
SerggioC / gradle.properties
Created March 27, 2018 23:08
gradle.properties Project-wide Gradle settings optimized template
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
@SerggioC
SerggioC / gradle-wrapper.properties
Created March 27, 2018 23:14
gradle-wrapper.properties latest version @ gradle\wrapper\gradle-wrapper.properties
#Tue Mar 27 18:24:31 BST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
# Android Plugin for Gradle version (3.1) vs Required Gradle version (4.4)
# https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle
@SerggioC
SerggioC / TimberImplementation.java
Created March 27, 2018 23:18
TimberImplementation.java default Timber logging template
import timber.log.Timber;
public class TimberImplementation {
public static void init() {
Timber.plant(new Timber.DebugTree() {
@Override
protected String createStackElementTag(StackTraceElement element) {
return String.format("Sergio> %s; Method %s; Line %s",
super.createStackElementTag(element),
element.getMethodName(),
fun View.flickerAnimation() {
AnimatorInflater.loadAnimator(this.context, R.animator.cycle_alpha_animator).apply {
setTarget(this)
start()
}
}
import com.the.package.name.extensions.get
import com.the.package.name.extensions.myPreferences
import com.the.package.name.extensions.set
val Context.myPreferences: SharedPreferences
get() = this.getSharedPreferences("${this.packageName} ${this.javaClass.simpleName}", MODE_PRIVATE)
@Suppress("UNCHECKED_CAST")
@SerggioC
SerggioC / getCurrentWindow
Created May 17, 2020 21:19
Access the window object from SceneDelegate or AppDelegate
func getCurrentWindow() -> UIWindow? {
if #available(iOS 13.0, *) {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let sceneDelegate = windowScene.delegate as? SceneDelegate {
return sceneDelegate.window
} else {
return nil
}
} else {
// Fallback on earlier versions
@SerggioC
SerggioC / byte array to Hex String
Created July 10, 2022 21:27
byte array to Hex String
private fun bytesToHex(bytes: ByteArray): String {
val result = bytes.joinToString(separator = "") { eachByte ->
"%02x".format(eachByte)
}
return result
}