Added New User Registration button to authentication activity
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package uk.org.openseizuredetector;
|
package uk.org.openseizuredetector;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
@@ -46,6 +48,8 @@ public class AuthenticateActivity extends AppCompatActivity {
|
|||||||
logoutCancelBtn.setOnClickListener(onCancel);
|
logoutCancelBtn.setOnClickListener(onCancel);
|
||||||
Button logoutBtn = (Button)findViewById(R.id.logoutBtn);
|
Button logoutBtn = (Button)findViewById(R.id.logoutBtn);
|
||||||
logoutBtn.setOnClickListener(onLogout);
|
logoutBtn.setOnClickListener(onLogout);
|
||||||
|
Button registerBtn = (Button) findViewById(R.id.RegisterBtn);
|
||||||
|
registerBtn.setOnClickListener(onRegister);
|
||||||
|
|
||||||
mUnameEt = (EditText) findViewById(R.id.username);
|
mUnameEt = (EditText) findViewById(R.id.username);
|
||||||
mPasswdEt = (EditText) findViewById(R.id.password);
|
mPasswdEt = (EditText) findViewById(R.id.password);
|
||||||
@@ -158,6 +162,22 @@ public class AuthenticateActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
View.OnClickListener onRegister =
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Log.d(TAG, "onRegisterBtn");
|
||||||
|
//Intent i;
|
||||||
|
//i = new Intent(getApplicationContext(), RemoteDbActivity.class);
|
||||||
|
//i.putExtra("url", "https://osdapi.ddns.net/static/register.html");
|
||||||
|
//startActivity(i);
|
||||||
|
String url = "https://osdapi.ddns.net/static/register.html";
|
||||||
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||||
|
i.setData(Uri.parse(url));
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private void saveAuthToken(String tokenStr) {
|
private void saveAuthToken(String tokenStr) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||||
prefs.edit().putString(TOKEN_ID, tokenStr).commit();
|
prefs.edit().putString(TOKEN_ID, tokenStr).commit();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class RemoteDbActivity extends AppCompatActivity {
|
|||||||
private OsdUtil mUtil;
|
private OsdUtil mUtil;
|
||||||
final Handler serverStatusHandler = new Handler();
|
final Handler serverStatusHandler = new Handler();
|
||||||
private String TOKEN_ID = "webApiAuthToken";
|
private String TOKEN_ID = "webApiAuthToken";
|
||||||
|
private String mRemtoteUrl = "https://osdapi.ddns.net/";
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,6 +41,14 @@ public class RemoteDbActivity extends AppCompatActivity {
|
|||||||
mUtil = new OsdUtil(getApplicationContext(), serverStatusHandler);
|
mUtil = new OsdUtil(getApplicationContext(), serverStatusHandler);
|
||||||
mConnection = new SdServiceConnection(getApplicationContext());
|
mConnection = new SdServiceConnection(getApplicationContext());
|
||||||
mUtil.bindToServer(getApplicationContext(), mConnection);
|
mUtil.bindToServer(getApplicationContext(), mConnection);
|
||||||
|
|
||||||
|
Bundle extras = getIntent().getExtras();
|
||||||
|
if (extras != null) {
|
||||||
|
String remoteUrl = extras.getString("url");
|
||||||
|
mRemtoteUrl = remoteUrl;
|
||||||
|
Log.d(TAG, "onCreate - mRemoteUrl=" + mRemtoteUrl);
|
||||||
|
}
|
||||||
|
|
||||||
waitForConnection();
|
waitForConnection();
|
||||||
|
|
||||||
//mLm= new LogManager(mContext);
|
//mLm= new LogManager(mContext);
|
||||||
@@ -62,7 +71,7 @@ public class RemoteDbActivity extends AppCompatActivity {
|
|||||||
// the mConnection to bind to the service, so we delay half a second to give it chance
|
// the mConnection to bind to the service, so we delay half a second to give it chance
|
||||||
// to connect before trying to update the UI for the first time (it happens again periodically using the uiTimer)
|
// to connect before trying to update the UI for the first time (it happens again periodically using the uiTimer)
|
||||||
if (mConnection.mBound) {
|
if (mConnection.mBound) {
|
||||||
Log.v(TAG, "waitForConnection - Bound!");
|
Log.d(TAG, "waitForConnection - Bound!");
|
||||||
initialiseServiceConnection();
|
initialiseServiceConnection();
|
||||||
} else {
|
} else {
|
||||||
Log.v(TAG, "waitForConnection - waiting...");
|
Log.v(TAG, "waitForConnection - waiting...");
|
||||||
@@ -77,6 +86,7 @@ public class RemoteDbActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void initialiseServiceConnection() {
|
private void initialiseServiceConnection() {
|
||||||
mLm = mConnection.mSdServer.mLm;
|
mLm = mConnection.mSdServer.mLm;
|
||||||
|
mWebView.loadUrl(mRemtoteUrl, getAuthHeaders());
|
||||||
//mWac = mConnection.mSdServer.mLm.mWac;
|
//mWac = mConnection.mSdServer.mLm.mWac;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +109,6 @@ public class RemoteDbActivity extends AppCompatActivity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
startUiTimer();
|
startUiTimer();
|
||||||
mWebView.loadUrl("https://osdapi.ddns.net/api/events/", getAuthHeaders());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, String> getAuthHeaders() {
|
private HashMap<String, String> getAuthHeaders() {
|
||||||
@@ -132,12 +141,14 @@ public class RemoteDbActivity extends AppCompatActivity {
|
|||||||
// Remote Database Information
|
// Remote Database Information
|
||||||
tv = (TextView)findViewById(R.id.authStatusTv);
|
tv = (TextView)findViewById(R.id.authStatusTv);
|
||||||
btn = (Button)findViewById(R.id.auth_button);
|
btn = (Button)findViewById(R.id.auth_button);
|
||||||
if (mLm.mWac.isLoggedIn()) {
|
if (mLm != null) {
|
||||||
tv.setText("Authenticated");
|
if (mLm.mWac.isLoggedIn()) {
|
||||||
btn.setText("Log Out");
|
tv.setText("Authenticated");
|
||||||
} else {
|
btn.setText("Log Out");
|
||||||
tv.setText("NOT AUTHENTICATED");
|
} else {
|
||||||
btn.setText("Log In");
|
tv.setText("NOT AUTHENTICATED");
|
||||||
|
btn.setText("Log In");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,12 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/authenticate" />
|
android:text="@string/authenticate" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/RegisterBtn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/register" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
@@ -327,4 +327,5 @@
|
|||||||
<string name="refreshBtn">Refresh</string>
|
<string name="refreshBtn">Refresh</string>
|
||||||
<string name="back">Back</string>
|
<string name="back">Back</string>
|
||||||
<string name="unvalidatedEventsTitle">Unvalidated Seizure Events</string>
|
<string name="unvalidatedEventsTitle">Unvalidated Seizure Events</string>
|
||||||
|
<string name="register">Register New User</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user