View MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun updateAppLocales(vararg locales: Locale) { | |
val localeManager = getSystemService(LocaleManager::class.java) | |
localeManager.applicationLocales = LocaleList(*locales) | |
} |
View MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
View activity_main.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'com.android.application' | |
id 'kotlin-android' | |
} | |
android { | |
compileSdkPreview "android-Tiramisu" | |
defaultConfig { | |
applicationId "com.paceli.sampleperapplanguage" |
View WifiTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@After | |
fun tearDown() { | |
// Press Home key after running the test | |
device.pressHome() | |
} |
View WifiTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Before | |
fun setUp() { | |
// Press Home key before running the test | |
device.pressHome() | |
} |
View WifiTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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( |
View WifiTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("\"") | |
} |
NewerOlder