Skip to content

Instantly share code, notes, and snippets.

View smoralb's full-sized avatar
Not all who wander are lost

Sergio smoralb

Not all who wander are lost
View GitHub Profile
apply plugin: 'jacoco'
apply from: "../reports/jacoco/jacoco-report-exclusions.gradle"
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
getClassDirectories().from(fileTree(
dir: "$buildDir/tmp/kotlin-classes/debug",
excludes: jacocoExclusions))
apply plugin: 'org.sonarqube'
apply from : "../reports/jacoco/jacoco-report-exclusions.gradle"
sonar {
properties {
property "sonar.projectKey", "App-Android"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.projectName", "yourAppName"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.sources", "${project.projectDir}/src/main/java"
class CustomBroadcastReceiver: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// All the logic we want to execute when the app receive the event/intent.
}
}
<manifest ... >
...
<application ... >
<service android:name=".ExampleService" />
...
</application>
</manifest>
<receiver android:name=".MyBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
@smoralb
smoralb / SampleViewModel.kt
Created March 31, 2022 19:22
How a ViewModel can receive a lifecycle event and make some action.
class SampleViewModel : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun initializeCamera() {
if (camera == null) {
getCamera()
}
}
}
@smoralb
smoralb / SomeActivity
Created March 31, 2022 18:24
Creating a layout withint the need to create an XML file
override fun onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
// creating LinearLayout
val linLayout: LinearLayout = LinearLayout(this)
// specifying vertical orientation
linLayout.setOrientation(LinearLayout.VERTICAL)
// creating LayoutParams
val linLayoutParam: LayoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
// set LinearLayout as a root element of the screen
setContentView(linLayout, linLayoutParam);
@smoralb
smoralb / App.js
Last active January 11, 2022 22:13
import './App.css'
import SectionItem from './components/section-item/sectionItem'
import { useTranslation } from 'react-i18next'
import React from 'react'
export default function App () {
const { t } = useTranslation()
var section = t('section', { returnObjects: true }) // Return the array from my local JSON file
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import reportWebVitals from './reportWebVitals'
import i18n from './i18n'
import { I18nextProvider } from 'react-i18next'
import React, { Suspense } from 'react'
ReactDOM.render(
<React.StrictMode>
{
"title": "title",
"section": [
{
"title": "Some title",
"subtitle": "Some subtitle",
"description": "Some description"
},
{
"title": "Some title 1",