Skip to content

Instantly share code, notes, and snippets.

Avatar
💻

Heitor Paceli Maranhão heitorpaceli

💻
View GitHub Profile
@heitorpaceli
heitorpaceli / MainActivity.kt
Created Mar 2, 2022
ActivityPerAppLanguage
View MainActivity.kt
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
View MainActivity.kt
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
}
}
View MainActivity.kt
private fun updateAppLocales(vararg locales: Locale) {
val localeManager = getSystemService(LocaleManager::class.java)
localeManager.applicationLocales = LocaleList(*locales)
}
View MainActivity.kt
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 Mar 2, 2022
helloWorldActivityLayout
View activity_main.xml
<?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"
View build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkPreview "android-Tiramisu"
defaultConfig {
applicationId "com.paceli.sampleperapplanguage"
@heitorpaceli
heitorpaceli / WifiTest.kt
Last active Nov 3, 2021
Tear down method UI Automator medium article
View WifiTest.kt
@After
fun tearDown() {
// Press Home key after running the test
device.pressHome()
}
@heitorpaceli
heitorpaceli / WifiTest.kt
Last active Nov 3, 2021
Set up method UI Automator medium article
View WifiTest.kt
@Before
fun setUp() {
// Press Home key before running the test
device.pressHome()
}
@heitorpaceli
heitorpaceli / WifiTest.kt
Last active Nov 3, 2021
Test method - UI Automator medium article
View WifiTest.kt
@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 Nov 3, 2021
Get SSID of connected WiFi Get SSID of connected WiFi
View WifiTest.kt
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("\"")
}