added authentication response handler, comment fixes

revert-70aa11f8
inosh-perera 10 years ago
parent b7ca60d802
commit 8de9a702d7

@ -28,6 +28,7 @@ import org.wso2.cdm.agent.proxy.IdentityProxy;
import org.wso2.cdm.agent.services.AlarmReceiver; import org.wso2.cdm.agent.services.AlarmReceiver;
import org.wso2.cdm.agent.utils.CommonDialogUtils; import org.wso2.cdm.agent.utils.CommonDialogUtils;
import org.wso2.cdm.agent.utils.CommonUtilities; import org.wso2.cdm.agent.utils.CommonUtilities;
import org.wso2.cdm.agent.utils.Constant;
import org.wso2.cdm.agent.utils.HTTPConnectorUtils; import org.wso2.cdm.agent.utils.HTTPConnectorUtils;
import org.wso2.cdm.agent.utils.Preference; import org.wso2.cdm.agent.utils.Preference;
import org.wso2.cdm.agent.utils.ServerUtils; import org.wso2.cdm.agent.utils.ServerUtils;
@ -66,24 +67,26 @@ import com.actionbarsherlock.view.MenuItem;
import com.google.android.gcm.GCMRegistrar; import com.google.android.gcm.GCMRegistrar;
/** /**
* Activity that captures username, password and device ownership details * Activity that captures username, password and device ownership details.
*/ */
public class AuthenticationActivity extends SherlockActivity implements APIAccessCallBack, public class AuthenticationActivity extends SherlockActivity implements APIAccessCallBack,
APIResultCallBack { APIResultCallBack {
private String TAG = AuthenticationActivity.class.getSimpleName(); private String TAG = AuthenticationActivity.class.getSimpleName();
Button authenticate; Button btnRegister;
EditText username; EditText etUsername;
EditText txtDomain; EditText etDomain;
EditText password; EditText etPassword;
RadioButton radioBYOD, radioCOPE; RadioButton radioBYOD, radioCOPE;
String deviceType; String deviceType;
Context context; Context context;
String senderId = ""; String senderId;
String usernameForRegister = ""; String usernameForRegister;
String usernameVal; String usernameVal;
String passwordVal; String passwordVal;
String domain;
ProgressDialog progressDialog; ProgressDialog progressDialog;
AlertDialog.Builder alertDialog; AlertDialog.Builder alertDialog;
@ -103,21 +106,21 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
context = AuthenticationActivity.this; context = AuthenticationActivity.this;
deviceType = getResources().getString(R.string.device_enroll_type_byod); deviceType = getResources().getString(R.string.device_enroll_type_byod);
txtDomain = (EditText) findViewById(R.id.txtDomain); etDomain = (EditText) findViewById(R.id.etDomain);
username = (EditText) findViewById(R.id.username); etUsername = (EditText) findViewById(R.id.etUsername);
password = (EditText) findViewById(R.id.editText2); etPassword = (EditText) findViewById(R.id.etPassword);
radioBYOD = (RadioButton) findViewById(R.id.radioBYOD); radioBYOD = (RadioButton) findViewById(R.id.radioBYOD);
radioCOPE = (RadioButton) findViewById(R.id.radioCOPE); radioCOPE = (RadioButton) findViewById(R.id.radioCOPE);
txtDomain.setFocusable(true); etDomain.setFocusable(true);
txtDomain.requestFocus(); etDomain.requestFocus();
authenticate = (Button) findViewById(R.id.btnRegister); btnRegister = (Button) findViewById(R.id.btnRegister);
authenticate.setEnabled(false); btnRegister.setEnabled(false);
authenticate.setOnClickListener(onClickAuthenticate); btnRegister.setOnClickListener(onClickAuthenticate);
// change button color background till user enters a valid input // change button color background till user enters a valid input
authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey)); btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey));
authenticate.setTextColor(getResources().getColor(R.color.black)); btnRegister.setTextColor(getResources().getColor(R.color.black));
username.addTextChangedListener(new TextWatcher() { etUsername.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
} }
@ -133,7 +136,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
} }
}); });
password.addTextChangedListener(new TextWatcher() { etPassword.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
} }
@ -155,18 +158,14 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (username.getText() != null && !username.getText().toString().trim().equals("") && if (etUsername.getText() != null &&
password.getText() != null && !password.getText().toString().trim().equals("")) { !etUsername.getText().toString().trim().equals("") &&
etPassword.getText() != null && !etPassword.getText().toString().trim().equals("")) {
passwordVal = password.getText().toString().trim();
if (txtDomain.getText() != null &&
!txtDomain.getText().toString().trim().equals("")) {
usernameVal =
username.getText().toString().trim() + "@" +
txtDomain.getText().toString().trim();
} else { passwordVal = etPassword.getText().toString().trim();
usernameVal = username.getText().toString().trim(); usernameVal = etUsername.getText().toString().trim();
if (etDomain.getText() != null && !etDomain.getText().toString().trim().equals("")) {
usernameVal += "@" + etDomain.getText().toString().trim();
} }
if (radioBYOD.isChecked()) { if (radioBYOD.isChecked()) {
@ -174,22 +173,24 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
} else { } else {
deviceType = getResources().getString(R.string.device_enroll_type_cope); deviceType = getResources().getString(R.string.device_enroll_type_cope);
} }
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append(getResources().getString(R.string.dialog_init_middle));
messageBuilder.append(" ");
messageBuilder.append(deviceType);
messageBuilder.append(" ");
messageBuilder.append(getResources().getString(R.string.dialog_init_end));
alertDialog = alertDialog =
CommonDialogUtils.getAlertDialogWithTwoButtonAndTitle(context, CommonDialogUtils.getAlertDialogWithTwoButtonAndTitle(context,
getResources().getString(R.string.dialog_init_device_type), getResources().getString(R.string.dialog_init_device_type),
getResources().getString(R.string.dialog_init_middle) + messageBuilder.toString(),
" " +
deviceType +
" " +
getResources().getString(R.string.dialog_init_end),
getResources().getString(R.string.yes), getResources().getString(R.string.yes),
getResources().getString(R.string.no), getResources().getString(R.string.no),
dialogClickListener, dialogClickListener,
dialogClickListener); dialogClickListener);
alertDialog.show(); alertDialog.show();
} else { } else {
if (username.getText() != null && !username.getText().toString().trim().equals("")) { if (etUsername.getText() != null &&
!etUsername.getText().toString().trim().equals("")) {
Toast.makeText(context, Toast.makeText(context,
getResources().getString(R.string.toast_error_password), getResources().getString(R.string.toast_error_password),
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
@ -250,9 +251,9 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
Map<String, String> requestParametres = Map<String, String> requestParametres =
new HashMap<String, String>(); new HashMap<String, String>();
requestParametres.put("username", requestParametres.put(Constant.USERNAME,
usernameVal); usernameVal);
requestParametres.put("password", requestParametres.put(Constant.PASSWORD,
passwordVal); passwordVal);
response = response =
HTTPConnectorUtils.postData(context, HTTPConnectorUtils.postData(context,
@ -274,19 +275,26 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
@Override @Override
protected void onPostExecute(Map<String, String> result) { protected void onPostExecute(Map<String, String> result) {
JSONObject response = authenticateResponse(result);
null;
}
};
mLicenseTask.execute();
}
/**
* Handles the response received from server for the authentication request.
* @param result Received response from server.
*/
private void authenticateResponse(Map<String, String> result){
if (result != null) { if (result != null) {
String responseStatus = String responseStatus =
result.get("status"); result.get(Constant.STATUS);
try {
if (responseStatus != null) { if (responseStatus != null) {
if (responseStatus.equalsIgnoreCase(CommonUtilities.REQUEST_SUCCESSFUL)) { if (responseStatus.equalsIgnoreCase(CommonUtilities.REQUEST_SUCCESSFUL)) {
response =
new JSONObject(
result.get("response"));
senderId =
response.getString("senderId");
getLicense(); getLicense();
} else if (responseStatus.equalsIgnoreCase(CommonUtilities.UNAUTHORIZED_ACCESS)) { } else if (responseStatus.equalsIgnoreCase(CommonUtilities.UNAUTHORIZED_ACCESS)) {
CommonDialogUtils.stopProgressDialog(progressDialog); CommonDialogUtils.stopProgressDialog(progressDialog);
@ -298,47 +306,30 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
dialogClickListener); dialogClickListener);
} else if (responseStatus.trim() } else if (responseStatus.trim()
.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) { .equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
CommonDialogUtils.stopProgressDialog(progressDialog); Log.e(TAG, "Error: Internal server error");
showInternalServerErrorMessage(); showInternalServerErrorMessage();
} else { } else {
Log.e(TAG, Log.e(TAG, "Status: " + responseStatus);
"Status: " +
responseStatus);
showAuthCommonErrorMessage(); showAuthCommonErrorMessage();
} }
} else { } else {
Log.e(TAG, Log.e(TAG, "The value of status is null in authenticating");
"The value of status is null in authenticate()");
showAuthCommonErrorMessage(); showAuthCommonErrorMessage();
} }
} catch (JSONException e) {
Log.e(TAG,
e.getMessage());
showAuthCommonErrorMessage();
}
} else { } else {
Log.e(TAG, Log.e(TAG, "The result is null in authenticating");
"The result is null in authenticate()");
showAuthCommonErrorMessage(); showAuthCommonErrorMessage();
} }
}
};
mLicenseTask.execute();
} }
/** /**
* Initialize get device license agreement. Check if the user has already * Initialize get device license agreement. Check if the user has already
* agreed * agreed to license agreement
* to license agreement
*/ */
private void getLicense() { private void getLicense() {
String isAgreed = String licenseAgreedResponse =
Preference.get(context, Preference.get(context,
getResources().getString(R.string.shared_pref_isagreed)); getResources().getString(R.string.shared_pref_isagreed));
String type = String type =
@ -347,9 +338,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
// No need to display license for COPE devices // No need to display license for COPE devices
if (type.trim().equals(getResources().getString(R.string.device_enroll_type_byod))) { if (type.trim().equals(getResources().getString(R.string.device_enroll_type_byod))) {
if (isAgreed == null) { if (licenseAgreedResponse == null) {
Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put("domain", txtDomain.getText().toString().trim());
// Get License // Get License
OnCancelListener cancelListener = new OnCancelListener() { OnCancelListener cancelListener = new OnCancelListener() {
@ -361,7 +350,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
getResources().getString(R.string.error_enrollment_failed), getResources().getString(R.string.error_enrollment_failed),
getResources().getString(R.string.button_ok), getResources().getString(R.string.button_ok),
null); null);
} }
}; };
@ -433,12 +421,11 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
private void manipulateLicenseResponse(Map<String, String> result) { private void manipulateLicenseResponse(Map<String, String> result) {
String responseStatus; String responseStatus;
CommonDialogUtils.stopProgressDialog(progressDialog); CommonDialogUtils.stopProgressDialog(progressDialog);
String licenseAgreement = "";
if (result != null) { if (result != null) {
responseStatus = result.get(CommonUtilities.STATUS_KEY); responseStatus = result.get(CommonUtilities.STATUS_KEY);
if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) { if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) {
licenseAgreement = result.get("response"); String licenseAgreement = result.get(Constant.RESPONSE);
if (licenseAgreement != null) { if (licenseAgreement != null) {
Preference.put(context, getResources().getString(R.string.shared_pref_eula), Preference.put(context, getResources().getString(R.string.shared_pref_eula),
@ -488,7 +475,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
String html = "<html><body>" + message + "</body></html>"; String html = "<html><body>" + message + "</body></html>";
String mime = "text/html"; String mime = "text/html";
String encoding = "utf-8"; String encoding = "utf-8";
web.getSettings().setJavaScriptEnabled(true);
web.loadDataWithBaseURL(null, html, mime, encoding, null); web.loadDataWithBaseURL(null, html, mime, encoding, null);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
@ -545,7 +531,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
editor.putString(getResources().getString(R.string.shared_pref_registered), "0"); editor.putString(getResources().getString(R.string.shared_pref_registered), "0");
editor.putString(getResources().getString(R.string.shared_pref_ip), ""); editor.putString(getResources().getString(R.string.shared_pref_ip), "");
editor.commit(); editor.commit();
// finish();
Intent intentIP = new Intent(AuthenticationActivity.this, ServerDetails.class); Intent intentIP = new Intent(AuthenticationActivity.this, ServerDetails.class);
intentIP.putExtra(getResources().getString(R.string.intent_extra_from_activity), intentIP.putExtra(getResources().getString(R.string.intent_extra_from_activity),
@ -567,12 +552,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
dialog.cancel(); dialog.cancel();
} }
}); });
/*
* builder1.setNegativeButton("No", new
* DialogInterface.OnClickListener() { public void
* onClick(DialogInterface dialog, int id) { dialog.cancel(); } });
*/
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.show(); alert.show();
} }
@ -588,12 +567,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
dialog.dismiss(); dialog.dismiss();
} }
}); });
/*
* builder1.setNegativeButton("No", new
* DialogInterface.OnClickListener() { public void
* onClick(DialogInterface dialog, int id) { dialog.cancel(); } });
*/
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.show(); alert.show();
} }
@ -611,21 +584,21 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
String serverURL = String serverURL =
CommonUtilities.SERVER_PROTOCOL + serverIP + ":" + CommonUtilities.SERVER_PROTOCOL + serverIP + ":" +
CommonUtilities.SERVER_PORT + CommonUtilities.OAUTH_ENDPOINT; CommonUtilities.SERVER_PORT + CommonUtilities.OAUTH_ENDPOINT;
if (txtDomain.getText() != null && !txtDomain.getText().toString().trim().equals("")) { if (etDomain.getText() != null && !etDomain.getText().toString().trim().equals("")) {
usernameForRegister = usernameForRegister =
username.getText().toString().trim() + "@" + etUsername.getText().toString().trim() + "@" +
txtDomain.getText().toString().trim(); etDomain.getText().toString().trim();
IdentityProxy.getInstance().init(clientKey, clientSecret, usernameForRegister, IdentityProxy.getInstance().init(clientKey, clientSecret, usernameForRegister,
password.getText().toString().trim(), serverURL, etPassword.getText().toString().trim(), serverURL,
AuthenticationActivity.this, AuthenticationActivity.this,
this.getApplicationContext()); this.getApplicationContext());
} else { } else {
usernameForRegister = username.getText().toString().trim(); usernameForRegister = etUsername.getText().toString().trim();
IdentityProxy.getInstance().init(clientKey, clientSecret, usernameForRegister, IdentityProxy.getInstance().init(clientKey, clientSecret, usernameForRegister,
password.getText().toString().trim(), serverURL, etPassword.getText().toString().trim(), serverURL,
AuthenticationActivity.this, AuthenticationActivity.this,
this.getApplicationContext()); this.getApplicationContext());
} }
@ -635,19 +608,19 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
boolean isReady = false; boolean isReady = false;
if (username.getText().toString().length() >= 1 && if (etUsername.getText().toString().length() >= 1 &&
password.getText().toString().length() >= 1) { etPassword.getText().toString().length() >= 1) {
isReady = true; isReady = true;
} }
if (isReady) { if (isReady) {
authenticate.setBackground(getResources().getDrawable(R.drawable.btn_orange)); btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_orange));
authenticate.setTextColor(getResources().getColor(R.color.white)); btnRegister.setTextColor(getResources().getColor(R.color.white));
authenticate.setEnabled(true); btnRegister.setEnabled(true);
} else { } else {
authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey)); btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey));
authenticate.setTextColor(getResources().getColor(R.color.black)); btnRegister.setTextColor(getResources().getColor(R.color.black));
authenticate.setEnabled(false); btnRegister.setEnabled(false);
} }
} }
@ -699,12 +672,12 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
@Override @Override
public void onClick(DialogInterface dialog, public void onClick(DialogInterface dialog,
int which) { int which) {
username.setText(CommonUtilities.EMPTY_STRING); etUsername.setText(CommonUtilities.EMPTY_STRING);
password.setText(CommonUtilities.EMPTY_STRING); etPassword.setText(CommonUtilities.EMPTY_STRING);
txtDomain.setText(CommonUtilities.EMPTY_STRING); etDomain.setText(CommonUtilities.EMPTY_STRING);
authenticate.setEnabled(false); btnRegister.setEnabled(false);
authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey)); btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey));
authenticate.setTextColor(getResources().getColor(R.color.black)); btnRegister.setTextColor(getResources().getColor(R.color.black));
} }
}; };
@ -766,7 +739,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
editor.commit(); editor.commit();
Map<String, String> requestParams = new HashMap<String, String>(); Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put("domain", txtDomain.getText().toString().trim()); requestParams.put("domain", etDomain.getText().toString().trim());
// Check network connection availability before calling the API. // Check network connection availability before calling the API.
if (PhoneState.isNetworkAvailable(context)) { if (PhoneState.isNetworkAvailable(context)) {
// Call get sender ID API. // Call get sender ID API.
@ -871,7 +844,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
responseStatus = result.get(CommonUtilities.STATUS_KEY); responseStatus = result.get(CommonUtilities.STATUS_KEY);
if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) { if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) {
try { try {
response = new JSONObject(result.get("response")); response = new JSONObject(result.get(Constant.RESPONSE));
senderId = response.getString("sender_id"); senderId = response.getString("sender_id");
mode = response.getString("notifier"); mode = response.getString("notifier");
interval = (float) Float.parseFloat(response.getString("notifierInterval")); interval = (float) Float.parseFloat(response.getString("notifierInterval"));

@ -40,12 +40,12 @@ import org.wso2.cdm.agent.utils.Responce;
*/ */
public class ServerDetails extends Activity { public class ServerDetails extends Activity {
TextView serverIP; TextView evServerIP;
Button startRegistration; Button btnStartRegistration;
Context context; Context context;
DialogInterface.OnClickListener dialogClickListener; DialogInterface.OnClickListener dialogClickListener;
DeviceInfo info; DeviceInfo info;
TextView severAddressLabel; TextView tvSeverAddress;
String senderID = null; String senderID = null;
ProgressDialog progressDialog; ProgressDialog progressDialog;
@ -62,49 +62,51 @@ public class ServerDetails extends Activity {
setContentView(R.layout.activity_settings); setContentView(R.layout.activity_settings);
context = ServerDetails.this; context = ServerDetails.this;
info = new DeviceInfo(ServerDetails.this); info = new DeviceInfo(ServerDetails.this);
serverIP = (TextView) findViewById(R.id.etServerIP); evServerIP = (TextView) findViewById(R.id.evServerIP);
severAddressLabel = (TextView) findViewById(R.id.severAddressLabel); tvSeverAddress = (TextView) findViewById(R.id.tvSeverAddress);
startRegistration = (Button) findViewById(R.id.startRegistration); btnStartRegistration = (Button) findViewById(R.id.btnStartRegistration);
// Checking if the device meets minimum requirements // Checking if the device meets minimum requirements
Responce compatibility = info.isCompatible(); Responce compatibility = info.isCompatible();
if (!compatibility.getCode()) { if (!compatibility.getCode()) {
startRegistration.setVisibility(View.GONE); btnStartRegistration.setVisibility(View.GONE);
severAddressLabel.setVisibility(View.GONE); tvSeverAddress.setVisibility(View.GONE);
serverIP.setVisibility(View.GONE); evServerIP.setVisibility(View.GONE);
alertDialog = alertDialog =
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context.getApplicationContext(), CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.error_authorization_failed), getResources().getString(R.string.error_authorization_failed),
getResources().getString(compatibility.getDescriptionResourceID()), getResources().getString(compatibility.getDescriptionResourceID()),
getResources().getString(R.string.button_ok), getResources().getString(R.string.button_ok),
onRootedClickListner); onRootedClickListner);
} else { } else {
startRegistration.setVisibility(View.VISIBLE); btnStartRegistration.setVisibility(View.VISIBLE);
serverIP.setVisibility(View.VISIBLE); evServerIP.setVisibility(View.VISIBLE);
String ipSaved = String ipSaved =
Preference.get(context.getApplicationContext(), Preference.get(context.getApplicationContext(),
getResources().getString(R.string.shared_pref_ip)); getResources().getString(R.string.shared_pref_ip));
regId = Preference.get(context.getApplicationContext().getApplicationContext(), getResources().getString(R.string.shared_pref_regId)); regId = Preference.get(context.getApplicationContext(), getResources().getString(R.string.shared_pref_regId));
//heck if we have the IP saved previously. //check if we have the IP saved previously.
if (ipSaved != null) { if (ipSaved != null) {
serverIP.setText(ipSaved); evServerIP.setText(ipSaved);
CommonUtilities.setServerURL(ipSaved); CommonUtilities.setServerURL(ipSaved);
startAuthenticationActivity(); startAuthenticationActivity();
} else { } else {
serverIP.setText(CommonUtilities.SERVER_IP); evServerIP.setText(CommonUtilities.SERVER_IP);
} }
// on click handler for start registration // on click handler for start registration
startRegistration.setOnClickListener(new OnClickListener() { btnStartRegistration.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(ServerDetails.this); AlertDialog.Builder alertBuilder = new AlertDialog.Builder(ServerDetails.this);
builder.setMessage(getResources().getString(R.string.dialog_init_confirmation) + StringBuilder messageBuilder = new StringBuilder();
" " + messageBuilder.append(getResources().getString(R.string.dialog_init_confirmation));
serverIP.getText().toString() + messageBuilder.append(" ");
" " + messageBuilder.append(evServerIP.getText().toString());
getResources().getString(R.string.dialog_init_end_general)) messageBuilder.append(" ");
messageBuilder.append(getResources().getString(R.string.dialog_init_end_general));
alertBuilder.setMessage(messageBuilder.toString())
.setPositiveButton(getResources().getString(R.string.yes), .setPositiveButton(getResources().getString(R.string.yes),
dialogClickListener) dialogClickListener)
.setNegativeButton(getResources().getString(R.string.no), .setNegativeButton(getResources().getString(R.string.no),
@ -117,11 +119,11 @@ public class ServerDetails extends Activity {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which) { switch (which) {
case DialogInterface.BUTTON_POSITIVE: case DialogInterface.BUTTON_POSITIVE:
if (!serverIP.getText().toString().trim().equals("")) { if (!evServerIP.getText().toString().trim().equals("")) {
CommonUtilities.setServerURL(serverIP.getText().toString().trim()); CommonUtilities.setServerURL(evServerIP.getText().toString().trim());
Preference.put(context.getApplicationContext(), Preference.put(context.getApplicationContext(),
getResources().getString(R.string.shared_pref_ip), getResources().getString(R.string.shared_pref_ip),
serverIP.getText().toString().trim()); evServerIP.getText().toString().trim());
startAuthenticationActivity(); startAuthenticationActivity();
} else { } else {
@ -148,6 +150,9 @@ public class ServerDetails extends Activity {
} }
}; };
/**
* This method is called to open AuthenticationActivity.
*/
private void startAuthenticationActivity() { private void startAuthenticationActivity() {
Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class); Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@ -161,11 +166,14 @@ public class ServerDetails extends Activity {
*/ */
@Override @Override
protected void onDestroy() { protected void onDestroy() {
//Avoiding memory leaks by destroying context object
context = null; context = null;
super.onDestroy(); super.onDestroy();
} }
// Old API manager communication code. // Old API manager communication code.
// //
// Bundle extras = getIntent().getExtras(); // Bundle extras = getIntent().getExtras();

@ -0,0 +1,27 @@
/**
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.cdm.agent.utils;
/**
* Constant values throughout the agent
*/
public class Constant {
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String STATUS = "status";
public static final String RESPONSE = "response";
}
Loading…
Cancel
Save