From 31fd0b37d06dc93b8e76acae7fca5a6167521abf Mon Sep 17 00:00:00 2001 From: Greg Alexander Date: Sun, 19 Jun 2016 16:12:19 -0400 Subject: [PATCH] now it compiles --- src/org/galexander/sshd/AuthKeys.java | 24 ++++++++++++++-------- src/org/galexander/sshd/AuthKeysFetch.java | 15 +++++++------- src/org/galexander/sshd/AuthKeysLoad.java | 6 +++++- src/org/galexander/sshd/AuthKeysSave.java | 2 +- src/org/galexander/sshd/SimpleSSHD.java | 5 +++-- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/org/galexander/sshd/AuthKeys.java b/src/org/galexander/sshd/AuthKeys.java index 0464b03..edd6a79 100644 --- a/src/org/galexander/sshd/AuthKeys.java +++ b/src/org/galexander/sshd/AuthKeys.java @@ -1,13 +1,18 @@ package org.galexander.sshd; import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; +import android.text.InputType; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.Messenger; -import android.widget.EditText; import android.view.View; +import android.widget.EditText; +import android.widget.Toast; public class AuthKeys extends Activity { private EditText authtext; @@ -34,16 +39,16 @@ public class AuthKeys extends Activity { AlertDialog.Builder ab = new AlertDialog.Builder(this); ab.setTitle("Fetch authorized_keys"); final EditText url = new EditText(this); - url.setInputType(EditText.TYPE_CLASS_TEXT | - EditText.TYPE_TEXT_VARIATION_URI); + url.setInputType(InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_URI); ab.setView(url); ab.setPositiveButton("OK", - new DialogInterface.onClickListener() { + new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int which) { start_fetch(url.getText().toString()); } }); ab.setNegativeButton("Cancel", - new DialogInterface.onClickListener() { + new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int which) { d.cancel(); } }); @@ -62,7 +67,7 @@ public class AuthKeys extends Activity { private void save_authtext() { String s = get_authtext(); - if ((authtext_orig_str != null) && (s != null) && + if ((authtext_orig != null) && (s != null) && !s.equals(authtext_orig)) { Intent i = new Intent(this, AuthKeysSave.class); i.putExtra("s", s); @@ -102,8 +107,9 @@ public class AuthKeys extends Activity { private void start_fetch(String url) { Intent i = new Intent(this, AuthKeysFetch.class); - i.putExtra("url", url.getText().toString()); - i.putExtra("m", Messenger m = new Messenger(new Handler() { + final Context ctx = this; + i.putExtra("url", url); + i.putExtra("m", new Messenger(new Handler() { public void handleMessage(Message msg) { Object o = msg.obj; if (o == null) { @@ -116,7 +122,7 @@ public class AuthKeys extends Activity { append_authtext(s); } else { /* s must be an error message */ - Toast.makeText(this, s, + Toast.makeText(ctx, s, Toast.LENGTH_LONG).show(); } } } )); diff --git a/src/org/galexander/sshd/AuthKeysFetch.java b/src/org/galexander/sshd/AuthKeysFetch.java index ab3bba4..97b04da 100644 --- a/src/org/galexander/sshd/AuthKeysFetch.java +++ b/src/org/galexander/sshd/AuthKeysFetch.java @@ -4,18 +4,19 @@ import android.app.IntentService; import android.content.Intent; import android.os.Message; import android.os.Messenger; +import java.io.InputStream; import java.net.URL; import java.net.HttpURLConnection; -public class AuthKeysSave extends IntentService { - public AuthKeysSave() { - super("SimpleSSHDAuthKeysSave"); +public class AuthKeysFetch extends IntentService { + public AuthKeysFetch() { + super("SimpleSSHDAuthKeysFetch"); } protected void onHandleIntent(Intent i) { - Messenger m = (Messenger)i.getExtra("m"); - Message msg = m.obtain(); - String url = i.getStringExtra("url", null); + Messenger m = (Messenger)i.getParcelableExtra("m"); + Message msg = Message.obtain(); + String url = i.getStringExtra("url"); String result = ""; byte[] b = new byte[1024]; @@ -26,7 +27,7 @@ public class AuthKeysSave extends IntentService { } URL u = new URL(url); HttpURLConnection conn = (HttpURLConnection) - url.openConnection(); + u.openConnection(); try { InputStream in = conn.getInputStream(); try { diff --git a/src/org/galexander/sshd/AuthKeysLoad.java b/src/org/galexander/sshd/AuthKeysLoad.java index 9e37786..18b5f4e 100644 --- a/src/org/galexander/sshd/AuthKeysLoad.java +++ b/src/org/galexander/sshd/AuthKeysLoad.java @@ -2,6 +2,10 @@ package org.galexander.sshd; import android.app.Activity; import android.os.AsyncTask; +import android.widget.Toast; +import java.io.File; +import java.io.FileInputStream; + public class AuthKeysLoad extends AsyncTask { private AuthKeys act = null; @@ -13,8 +17,8 @@ public class AuthKeysLoad extends AsyncTask { } AuthKeysLoad(AuthKeys act_) { - act = act_; super(); + act = act_; } protected Void doInBackground(Void... v) { diff --git a/src/org/galexander/sshd/AuthKeysSave.java b/src/org/galexander/sshd/AuthKeysSave.java index b617e35..16444e5 100644 --- a/src/org/galexander/sshd/AuthKeysSave.java +++ b/src/org/galexander/sshd/AuthKeysSave.java @@ -10,7 +10,7 @@ public class AuthKeysSave extends IntentService { super("SimpleSSHDAuthKeysSave"); } protected void onHandleIntent(Intent i) { - String s = i.getStringExtra("s", null); + String s = i.getStringExtra("s"); if (s == null) { return; } diff --git a/src/org/galexander/sshd/SimpleSSHD.java b/src/org/galexander/sshd/SimpleSSHD.java index bf91a6c..06ec4f1 100644 --- a/src/org/galexander/sshd/SimpleSSHD.java +++ b/src/org/galexander/sshd/SimpleSSHD.java @@ -11,6 +11,7 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; import android.widget.Button; +import android.widget.Toast; import android.view.View; import android.view.Menu; import android.view.MenuItem; @@ -226,12 +227,12 @@ public class SimpleSSHD extends Activity } /* called from AuthKeysSave (in its own worker thread) if it fails */ - public static void toast(String s) { + public static void toast(final String s) { synchronized (lock) { if (curr != null) { curr.runOnUiThread(new Runnable() { public void run() { - Toast.makeText(this, s, + Toast.makeText(curr, s, Toast.LENGTH_LONG).show(); } }); } else {