Skip to content
This repository has been archived by the owner on May 30, 2020. It is now read-only.

Commit

Permalink
Fix layout so output is full width.
Browse files Browse the repository at this point in the history
Does not pull up keyboard when selecting.
Text is not editable, but selectable still.
  • Loading branch information
NanoDano committed Apr 2, 2019
1 parent 0ceab57 commit b371a5d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -25,20 +25,15 @@ class MainActivity : AppCompatActivity() {

val commonlyUsedPorts = intArrayOf(22, 80, 443, 3306, 21, 25, 53, 8080, 8988, 9999)
for (port in commonlyUsedPorts) {
//val worker = Thread(PortScan(this.scrollView2.portScanResults, host, port))
val worker = PortScan(this.scrollView2.portScanResults, host, port)
executor.execute(worker)
}

executor.shutdown()
// while (!executor.isTerminated()) { // This will lock up UI thread
// // Threads are still running
// }

return@OnNavigationItemSelectedListener false
}
R.id.navigation_settings -> {
// Replace screen fragment with settings
// setContentView()?
return@OnNavigationItemSelectedListener true
}
}
Expand All @@ -48,11 +43,7 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)

this.scrollView2.portScanResults.setText("Hello!\nNo results yet.\nStart a scan.")
}


}
14 changes: 7 additions & 7 deletions app/src/main/java/com/devdungeon/android/portscanner/PortScan.kt
Expand Up @@ -3,32 +3,32 @@ package com.devdungeon.android.portscanner
import android.widget.EditText
import java.net.Socket

class PortScan(val results: EditText, val host: String, val portNumber: Int) : Thread() {
class PortScan(private val results: EditText, private val host: String, private val portNumber: Int) : Thread() {

override fun run() {
try {
val sock = Socket(host, portNumber)
if (sock.isConnected) {
results.post(Runnable() {
results.post {
val newMessage = "${results.text}" + "\n" +
"$portNumber is open."
results.setText(newMessage)
})
}
sock.close()
} else {
results.post(Runnable() {
results.post {
val newMessage = "${results.text}" + "\n" +
"$portNumber is not connected."
results.setText(newMessage)
})
}
}

} catch (e: Exception) {
results.post(Runnable() {
results.post {
val newMessage = "${results.text}" + "\n" +
"$portNumber is N/A."
results.setText(newMessage)
})
}
}
}
}
43 changes: 24 additions & 19 deletions app/src/main/res/layout/activity_main.xml
Expand Up @@ -9,28 +9,33 @@
tools:context=".MainActivity">

<ScrollView
android:layout_width="395dp"
android:layout_height="577dp" android:layout_marginEnd="8dp"
android:layout_marginRight="8dp" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toTopOf="@+id/navigation" android:id="@+id/scrollView2"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toTopOf="parent" android:layout_marginBottom="16dp">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/portScanResults"
android:text="asdfasdf\nasdf\nasdfasd\nasdfasd" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="241dp" android:layout_marginRight="241dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp"
android:layout_marginStart="8dp" android:layout_marginBottom="437dp"
app:layout_constraintBottom_toTopOf="@+id/navigation" android:layout_marginTop="43dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0"/>
android:orientation="vertical"
android:id="@+id/scrollView2">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/portScanResults"
android:hint="@string/no_scan_results_yet"
android:autofillHints=""
android:editable="false"
android:autoText="false"
android:cursorVisible="true"
android:clickable="true"
android:focusableInTouchMode="false"
android:textIsSelectable="true"/>
</LinearLayout>
</ScrollView>

<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/colors.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="colorPrimary">#006D5C</color>
<color name="colorPrimaryDark">#222222</color>
<color name="colorAccent">#4CB6B6</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -3,4 +3,5 @@
<string name="title_home">Port Scanner</string>
<string name="title_startscan">Start scan</string>
<string name="title_settings">Settings</string>
<string name="no_scan_results_yet">No scan results yet.\nStart a scan.</string>
</resources>

0 comments on commit b371a5d

Please sign in to comment.