Skip to content

Instantly share code, notes, and snippets.

View reuniware's full-sized avatar
🎯
Focusing

Quant & Fintech Opensource Projects reuniware

🎯
Focusing
View GitHub Profile
@reuniware
reuniware / LogError.kt
Created May 23, 2019 16:30
SyncAdapter Log and Timber
package com.datasync
import android.accounts.Account
import android.content.*
import android.os.Bundle
import android.util.Log
import timber.log.Timber
class SyncAdapter @JvmOverloads constructor(
context: Context,
@reuniware
reuniware / StatsActivity.kt
Created July 5, 2019 11:55
Kotlin Google Charts API easy and basic implementation
package com.activity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_statistiques.*
class StatsActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@reuniware
reuniware / MPAndroidChartActivity.kt
Created July 5, 2019 13:49
Kotlin MPAndroidChart Basic Code
package com.activity
import android.graphics.Color
import android.graphics.DashPathEffect
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.github.mikephil.charting.charts.LineChart
import com.github.mikephil.charting.components.Legend
import com.github.mikephil.charting.components.LimitLine
import com.github.mikephil.charting.components.LimitLine.LimitLabelPosition
@reuniware
reuniware / show_date_picker.kt
Created July 9, 2019 13:38
Show Date Picker dialog in Android
/*
https://ntic974.blogspot.com
*/
// Définir la date de début de stats par défaut au 1er janvier de l'année en cours
val cal = Calendar.getInstance()
cal.set(Calendar.MONTH, 0)
cal.set(Calendar.DAY_OF_MONTH, 1)
val year_start = cal.get(Calendar.YEAR)
val month_start = cal.get(Calendar.MONTH) // Mois de 0 à 11
@reuniware
reuniware / first_and_last_day_of_year.kt
Last active July 31, 2019 13:02
Android Kotlin Calendar get 1st day of year and last day of year
// first day of year
val cal = Calendar.getInstance()
cal.set(Calendar.MONTH, 0)
cal.set(Calendar.DAY_OF_MONTH, 1)
val year_start = cal.get(Calendar.YEAR)
val month_start = cal.get(Calendar.MONTH) // Mois de 0 à 11
val day_start = cal.get(Calendar.DAY_OF_MONTH)
textViewStartDate.setText("${String.format("%02d", day_start)}/${String.format("%02d", month_start+1)}/${String.format("%04d", year_start)}")
// last day of year
@reuniware
reuniware / contacts.kt
Created October 8, 2019 15:42
Access contacts with Kotlin on Android
//https://medium.com/@manuaravindpta/fetching-contacts-from-device-using-kotlin-6c6d3e76574f
package com.dev2qa.example.datasharing.contacts;
import android.Manifest;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.pm.PackageManager;
@reuniware
reuniware / read_phone_contacts.kt
Created October 10, 2019 15:41
Read phone contacts in Kotlin
if (!hasPhoneContactsPermission(Manifest.permission.READ_CONTACTS)) {
requestReadContactsPermission(Manifest.permission.READ_CONTACTS)
} else {
val cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null)
if (cursor != null) {
if (cursor.count > 0) {
while (cursor.moveToNext()) {
val id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID))
val name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME))
val phoneNumber = (cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))).toInt()
@reuniware
reuniware / observer.kt
Created October 11, 2019 12:45
Kotlin Observer example
phoneContact.addObserver(MyObserver(recyclerViewPhoneContacts))
class PhoneContact: Observable() {
var id = ""
var name = ""
var phoneNumbers = arrayListOf<String>()
var emailAddresses = arrayListOf<String>()
var addresses = arrayListOf<String>()
var selected = false
@reuniware
reuniware / get_contact_web_url.kt
Created October 15, 2019 10:20
Android : Get website address from phone contact
fun getPhoneContacts() : List<PhoneContact> {
phoneContactsList = ArrayList<PhoneContact>()
if (!hasPhoneContactsPermission(Manifest.permission.READ_CONTACTS)) {
requestReadContactsPermission(Manifest.permission.READ_CONTACTS)
} else {
//showOkDialog("permissions contacts", "permissions accordées", this as AppCompatActivity, false)
val cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null)
if (cursor != null) {
if (cursor.count > 0) {
while (cursor.moveToNext()) {
@reuniware
reuniware / androidx-class-mapping.csv
Created October 16, 2019 12:30 — forked from alexjlockwood/androidx-class-mapping.csv
Android X migration script
android.support.v7.widget.util.SortedListAdapterCallback androidx.recyclerview.widget.SortedListAdapterCallback
android.support.v7.widget.helper.ItemTouchUIUtilImpl androidx.recyclerview.widget.ItemTouchUIUtilImpl
android.support.v7.widget.helper.ItemTouchUIUtil androidx.recyclerview.widget.ItemTouchUIUtil
android.support.v7.widget.helper.ItemTouchHelper androidx.recyclerview.widget.ItemTouchHelper
android.support.v7.widget.WithHint androidx.appcompat.widget.WithHint
android.support.v7.widget.ViewUtils androidx.appcompat.widget.ViewUtils
android.support.v7.widget.ViewStubCompat androidx.appcompat.widget.ViewStubCompat
android.support.v7.widget.ViewInfoStore androidx.recyclerview.widget.ViewInfoStore
android.support.v7.widget.ViewBoundsCheck androidx.recyclerview.widget.ViewBoundsCheck
android.support.v7.widget.VectorEnabledTintResources androidx.appcompat.widget.VectorEnabledTintResources