@@ -3,32 +3,40 @@ package tk.superl2.xwifi
33import android.app.Activity
44import android.app.AlertDialog
55import android.content.Intent
6+ import android.content.SharedPreferences
67import android.os.AsyncTask
78import android.os.Bundle
9+ import android.preference.PreferenceManager
810import android.text.Html
911import android.util.Log
1012import android.view.Menu
1113import android.view.MenuItem
12- import android.widget.*
14+ import android.widget.ArrayAdapter
15+ import android.widget.ImageView
16+ import android.widget.ProgressBar
1317import kotlinx.android.synthetic.main.activity_main.*
1418import net.glxn.qrgen.android.QRCode
1519import net.glxn.qrgen.core.scheme.Wifi
1620
1721const val TAG = " MainActivity"
18- const val QR_GENERATION_RESOLUTION = 300
22+ const val DEFAULT_QR_GENERATION_RESOLUTION = " 300"
1923
2024class MainActivity : Activity () {
2125 // This variable holds an ArrayList of WifiEntry objects that each contain a saved wifi SSID and
2226 // password. It is updated whenever focus returns to the app (onResume).
2327 private lateinit var wifiEntries: ArrayList <WifiEntry >
2428 private val wifiEntrySSIDs = ArrayList <String >()
2529 private lateinit var loadWifiEntriesInBackgroundTask: LoadWifiEntriesInBackground
30+ private lateinit var prefs: SharedPreferences
2631
2732 private lateinit var qrDialog: AlertDialog
2833 override fun onCreate (savedInstanceState : Bundle ? ) {
2934 super .onCreate(savedInstanceState)
3035 setContentView(R .layout.activity_main)
3136
37+ PreferenceManager .setDefaultValues(this , R .xml.preferences, false )
38+ prefs = PreferenceManager .getDefaultSharedPreferences(this )
39+
3240 wifi_ListView.adapter = ArrayAdapter (this , android.R .layout.simple_list_item_1, wifiEntrySSIDs)
3341 wifi_ListView.setOnItemClickListener { _, _, position, _ ->
3442 val qrCodeView = ImageView (this )
@@ -39,7 +47,7 @@ class MainActivity: Activity() {
3947 .withSsid(wifiEntrySSIDs[position])
4048 .withPsk(wifiEntries[position].getPassword(true ))
4149 .withAuthentication(wifiEntries[position].type.asQRCodeAuth()))
42- .withSize(QR_GENERATION_RESOLUTION , QR_GENERATION_RESOLUTION )
50+ .withSize(prefs.getString( " qr_code_resolution " , DEFAULT_QR_GENERATION_RESOLUTION ).toInt(), prefs.getString( " qr_code_resolution " , DEFAULT_QR_GENERATION_RESOLUTION ).toInt() )
4351 .bitmap())
4452
4553 val builder = AlertDialog .Builder (this )
@@ -135,7 +143,7 @@ class MainActivity: Activity() {
135143 }
136144 }
137145
138- override fun onCreateOptionsMenu (menu : Menu ? ): Boolean {
146+ override fun onCreateOptionsMenu (menu : Menu ): Boolean {
139147 menuInflater.inflate(R .menu.menu_activity_main, menu)
140148 return true
141149 }
0 commit comments