Skip to content

Commit

Permalink
Add qr code quality option
Browse files Browse the repository at this point in the history
  • Loading branch information
hacker1024 committed Mar 18, 2018
1 parent ebc3228 commit 22a2388
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
16 changes: 12 additions & 4 deletions app/src/main/java/tk/superl2/xwifi/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,40 @@ package tk.superl2.xwifi
import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.content.SharedPreferences
import android.os.AsyncTask
import android.os.Bundle
import android.preference.PreferenceManager
import android.text.Html
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.widget.*
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.ProgressBar
import kotlinx.android.synthetic.main.activity_main.*
import net.glxn.qrgen.android.QRCode
import net.glxn.qrgen.core.scheme.Wifi

const val TAG = "MainActivity"
const val QR_GENERATION_RESOLUTION = 300
const val DEFAULT_QR_GENERATION_RESOLUTION = "300"

class MainActivity: Activity() {
// This variable holds an ArrayList of WifiEntry objects that each contain a saved wifi SSID and
// password. It is updated whenever focus returns to the app (onResume).
private lateinit var wifiEntries: ArrayList<WifiEntry>
private val wifiEntrySSIDs = ArrayList<String>()
private lateinit var loadWifiEntriesInBackgroundTask: LoadWifiEntriesInBackground
private lateinit var prefs: SharedPreferences

private lateinit var qrDialog: AlertDialog
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
prefs = PreferenceManager.getDefaultSharedPreferences(this)

wifi_ListView.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, wifiEntrySSIDs)
wifi_ListView.setOnItemClickListener { _, _, position, _ ->
val qrCodeView = ImageView(this)
Expand All @@ -39,7 +47,7 @@ class MainActivity: Activity() {
.withSsid(wifiEntrySSIDs[position])
.withPsk(wifiEntries[position].getPassword(true))
.withAuthentication(wifiEntries[position].type.asQRCodeAuth()))
.withSize(QR_GENERATION_RESOLUTION, QR_GENERATION_RESOLUTION)
.withSize(prefs.getString("qr_code_resolution", DEFAULT_QR_GENERATION_RESOLUTION).toInt(), prefs.getString("qr_code_resolution", DEFAULT_QR_GENERATION_RESOLUTION).toInt())
.bitmap())

val builder = AlertDialog.Builder(this)
Expand Down Expand Up @@ -135,7 +143,7 @@ class MainActivity: Activity() {
}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_activity_main, menu)
return true
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/tk/superl2/xwifi/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package tk.superl2.xwifi

import android.os.Bundle
import android.preference.PreferenceActivity
import android.R.xml
import android.preference.PreferenceFragment



/**
* A [PreferenceActivity] that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_aspect_ratio_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
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"/>
</vector>
47 changes: 47 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="qr_code_resolutions_entries" >
<item>100x100</item>
<item>150x150</item>
<item>200x200</item>
<item>250x250</item>
<item>300x300</item>
<item>350x350</item>
<item>400x400</item>
<item>450x450</item>
<item>500x500</item>
<item>550x550</item>
<item>600x600</item>
<item>650x650</item>
<item>700x700</item>
<item>750x750</item>
<item>800x800</item>
<item>850x850</item>
<item>900x900</item>
<item>950x950</item>
<item>1000x1000</item>
<item>1050x1050</item>
</string-array>
<string-array name="qr_code_resolutions_values" >
<item>100</item>
<item>150</item>
<item>200</item>
<item>250</item>
<item>300</item>
<item>350</item>
<item>400</item>
<item>450</item>
<item>500</item>
<item>550</item>
<item>600</item>
<item>650</item>
<item>700</item>
<item>750</item>
<item>800</item>
<item>850</item>
<item>900</item>
<item>950</item>
<item>1000</item>
<item>1050</item>
</string-array>
</resources>
16 changes: 15 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<!--<ListPreference-->
<!--android:defaultValue="Light"-->
<!--android:entries="@array/themes"-->
<!--android:entryValues="@array/themes"-->
<!--android:key="theme"-->
<!--android:summary="%s"-->
<!--android:title="App theme" />-->
<ListPreference
android:defaultValue="300"
android:entries="@array/qr_code_resolutions_entries"
android:entryValues="@array/qr_code_resolutions_values"
android:icon="@drawable/ic_aspect_ratio_black_24dp"
android:key="qr_code_resolution"
android:summary="%s"
android:title="Resolution of generated QR codes" />
</PreferenceScreen>

0 comments on commit 22a2388

Please sign in to comment.