Skip to content

Commit 22a2388

Browse files
committed
Add qr code quality option
1 parent ebc3228 commit 22a2388

File tree

5 files changed

+83
-7
lines changed

5 files changed

+83
-7
lines changed

app/src/main/java/tk/superl2/xwifi/MainActivity.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,40 @@ package tk.superl2.xwifi
33
import android.app.Activity
44
import android.app.AlertDialog
55
import android.content.Intent
6+
import android.content.SharedPreferences
67
import android.os.AsyncTask
78
import android.os.Bundle
9+
import android.preference.PreferenceManager
810
import android.text.Html
911
import android.util.Log
1012
import android.view.Menu
1113
import android.view.MenuItem
12-
import android.widget.*
14+
import android.widget.ArrayAdapter
15+
import android.widget.ImageView
16+
import android.widget.ProgressBar
1317
import kotlinx.android.synthetic.main.activity_main.*
1418
import net.glxn.qrgen.android.QRCode
1519
import net.glxn.qrgen.core.scheme.Wifi
1620

1721
const val TAG = "MainActivity"
18-
const val QR_GENERATION_RESOLUTION = 300
22+
const val DEFAULT_QR_GENERATION_RESOLUTION = "300"
1923

2024
class 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
}

app/src/main/java/tk/superl2/xwifi/SettingsActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package tk.superl2.xwifi
22

33
import android.os.Bundle
44
import android.preference.PreferenceActivity
5-
import android.R.xml
65
import android.preference.PreferenceFragment
76

87

9-
108
/**
119
* A [PreferenceActivity] that presents a set of application settings. On
1210
* handset devices, settings are presented as a single list. On tablets,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M19,12h-2v3h-3v2h5v-5zM7,9h3L10,7L5,7v5h2L7,9zM21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19.01L3,19.01L3,4.99h18v14.02z"/>
9+
</vector>

app/src/main/res/values/arrays.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string-array name="qr_code_resolutions_entries" >
4+
<item>100x100</item>
5+
<item>150x150</item>
6+
<item>200x200</item>
7+
<item>250x250</item>
8+
<item>300x300</item>
9+
<item>350x350</item>
10+
<item>400x400</item>
11+
<item>450x450</item>
12+
<item>500x500</item>
13+
<item>550x550</item>
14+
<item>600x600</item>
15+
<item>650x650</item>
16+
<item>700x700</item>
17+
<item>750x750</item>
18+
<item>800x800</item>
19+
<item>850x850</item>
20+
<item>900x900</item>
21+
<item>950x950</item>
22+
<item>1000x1000</item>
23+
<item>1050x1050</item>
24+
</string-array>
25+
<string-array name="qr_code_resolutions_values" >
26+
<item>100</item>
27+
<item>150</item>
28+
<item>200</item>
29+
<item>250</item>
30+
<item>300</item>
31+
<item>350</item>
32+
<item>400</item>
33+
<item>450</item>
34+
<item>500</item>
35+
<item>550</item>
36+
<item>600</item>
37+
<item>650</item>
38+
<item>700</item>
39+
<item>750</item>
40+
<item>800</item>
41+
<item>850</item>
42+
<item>900</item>
43+
<item>950</item>
44+
<item>1000</item>
45+
<item>1050</item>
46+
</string-array>
47+
</resources>

app/src/main/res/xml/preferences.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
3-
3+
<!--<ListPreference-->
4+
<!--android:defaultValue="Light"-->
5+
<!--android:entries="@array/themes"-->
6+
<!--android:entryValues="@array/themes"-->
7+
<!--android:key="theme"-->
8+
<!--android:summary="%s"-->
9+
<!--android:title="App theme" />-->
10+
<ListPreference
11+
android:defaultValue="300"
12+
android:entries="@array/qr_code_resolutions_entries"
13+
android:entryValues="@array/qr_code_resolutions_values"
14+
android:icon="@drawable/ic_aspect_ratio_black_24dp"
15+
android:key="qr_code_resolution"
16+
android:summary="%s"
17+
android:title="Resolution of generated QR codes" />
418
</PreferenceScreen>

0 commit comments

Comments
 (0)