Skip to content

Instantly share code, notes, and snippets.

View heitorpaceli's full-sized avatar
💻

Heitor Paceli Maranhão heitorpaceli

💻
View GitHub Profile
@heitorpaceli
heitorpaceli / MainActivity.kt
Created March 2, 2022 03:59
ActivityPerAppLanguage
package com.paceli.sampleperapplanguage
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Spinner
import android.app.LocaleManager
import android.os.Build
@heitorpaceli
heitorpaceli / MainActivity.kt
Created March 2, 2022 03:55
updateActivityTitle
private fun updateActivityTitle() {
val localeManager = getSystemService(LocaleManager::class.java)
val appLocales = localeManager.applicationLocales
title = if (appLocales.isEmpty) {
getString(R.string.system_locale)
} else {
appLocales.get(0).displayName
}
}
@heitorpaceli
heitorpaceli / MainActivity.kt
Created March 2, 2022 03:46
updateAppLocales
private fun updateAppLocales(vararg locales: Locale) {
val localeManager = getSystemService(LocaleManager::class.java)
localeManager.applicationLocales = LocaleList(*locales)
}
@heitorpaceli
heitorpaceli / MainActivity.kt
Last active March 2, 2022 03:25
initLocalePicker
private fun initLocalePicker() {
val systemLocale = getString(R.string.system_locale)
val spinner: Spinner = findViewById(R.id.localePicker)
val locales = listOf(systemLocale, "en-US", "es-ES", "iw-IL", "ja-JP", "uk-UA")
spinner.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, locales)
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val selectedLocale = spinner.adapter.getItem(position) as String
if (selectedLocale != systemLocale) {
updateAppLocales(Locale.forLanguageTag(selectedLocale))
@heitorpaceli
heitorpaceli / activity_main.xml
Created March 2, 2022 01:28
helloWorldActivityLayout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
@heitorpaceli
heitorpaceli / build.gradle
Created March 2, 2022 01:02
tiramisuBuildGradle
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkPreview "android-Tiramisu"
defaultConfig {
applicationId "com.paceli.sampleperapplanguage"
@heitorpaceli
heitorpaceli / WifiTest.kt
Last active November 3, 2021 00:58
Tear down method UI Automator medium article
@After
fun tearDown() {
// Press Home key after running the test
device.pressHome()
}
@heitorpaceli
heitorpaceli / WifiTest.kt
Last active November 3, 2021 00:59
Set up method UI Automator medium article
@Before
fun setUp() {
// Press Home key before running the test
device.pressHome()
}
@heitorpaceli
heitorpaceli / WifiTest.kt
Last active November 3, 2021 01:03
Test method - UI Automator medium article
@Test
fun validateWifi() {
// Open apps list by scrolling on home screen
val workspace = device.findObject(
By.res("com.google.android.apps.nexuslauncher:id/workspace")
)
workspace.scroll(Direction.DOWN, 1.0f)
// Click on Settings icon to launch the app
val settings = device.findObject(
@heitorpaceli
heitorpaceli / WifiTest.kt
Last active November 3, 2021 00:57
Get SSID of connected WiFi Get SSID of connected WiFi
private fun getCurrentWifiSsid(): String? {
val context = InstrumentationRegistry.getInstrumentation().context
val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
val wifiInfo = wifiManager.connectionInfo
// The SSID is quoted, then we need to remove quotes
return wifiInfo.ssid?.removeSurrounding("\"")
}