|
|
@ -15,18 +15,6 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.wso2.cdm.agent;
|
|
|
|
package org.wso2.cdm.agent;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.R;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.api.DeviceInfo;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.api.PhoneState;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.proxy.APIResultCallBack;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.proxy.Token;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.proxy.TokenCallBack;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.utils.CommonDialogUtils;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.utils.CommonUtilities;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.utils.Preference;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.utils.ServerUtils;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
@ -35,34 +23,38 @@ import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
public class ServerDetails extends Activity implements APIResultCallBack, TokenCallBack {
|
|
|
|
import org.wso2.cdm.agent.api.DeviceInfo;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.utils.CommonDialogUtils;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.utils.CommonUtilities;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.utils.Preference;
|
|
|
|
|
|
|
|
import org.wso2.cdm.agent.utils.Responce;
|
|
|
|
|
|
|
|
|
|
|
|
private String TAG = ServerDetails.class.getSimpleName();
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This the the activity that is used to capture the server's host name.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class ServerDetails extends Activity {
|
|
|
|
|
|
|
|
|
|
|
|
TextView serverIP;
|
|
|
|
TextView serverIP;
|
|
|
|
Button startRegistration;
|
|
|
|
Button startRegistration;
|
|
|
|
String fromActivity;
|
|
|
|
|
|
|
|
Context context;
|
|
|
|
Context context;
|
|
|
|
|
|
|
|
DialogInterface.OnClickListener dialogClickListener;
|
|
|
|
DeviceInfo info;
|
|
|
|
DeviceInfo info;
|
|
|
|
TextView incompatibleError;
|
|
|
|
TextView severAddressLabel;
|
|
|
|
String errorMessage = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String senderID = null;
|
|
|
|
String senderID = null;
|
|
|
|
boolean accessFlag = true;
|
|
|
|
|
|
|
|
ProgressDialog progressDialog;
|
|
|
|
ProgressDialog progressDialog;
|
|
|
|
String regId;
|
|
|
|
String regId;
|
|
|
|
AlertDialog.Builder alertDialog;
|
|
|
|
AlertDialog.Builder alertDialog;
|
|
|
|
|
|
|
|
|
|
|
|
boolean alreadyRegisteredActivityFlag = false;
|
|
|
|
boolean alreadyRegisteredActivityFlag = false;
|
|
|
|
boolean authenticationActivityFlag = false;
|
|
|
|
boolean authenticationActivityFlag = false;
|
|
|
|
|
|
|
|
private String TAG = ServerDetails.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@ -70,50 +62,39 @@ public class ServerDetails extends Activity implements APIResultCallBack, TokenC
|
|
|
|
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);
|
|
|
|
incompatibleError = (TextView) findViewById(R.id.incompatibleError);
|
|
|
|
|
|
|
|
serverIP = (TextView) findViewById(R.id.etServerIP);
|
|
|
|
serverIP = (TextView) findViewById(R.id.etServerIP);
|
|
|
|
|
|
|
|
severAddressLabel = (TextView) findViewById(R.id.severAddressLabel);
|
|
|
|
startRegistration = (Button) findViewById(R.id.startRegistration);
|
|
|
|
startRegistration = (Button) findViewById(R.id.startRegistration);
|
|
|
|
Bundle extras = getIntent().getExtras();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (extras != null) {
|
|
|
|
|
|
|
|
if (extras.containsKey(getResources().getString(R.string.intent_extra_from_activity))) {
|
|
|
|
|
|
|
|
fromActivity =
|
|
|
|
|
|
|
|
extras.getString(getResources().getString(R.string.intent_extra_from_activity));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Checking if the device meets minimum requirements
|
|
|
|
// Checking if the device meets minimum requirements
|
|
|
|
if (!info.isCompatible(context).getCode()) {
|
|
|
|
Responce compatibility = info.isCompatible();
|
|
|
|
accessFlag = false;
|
|
|
|
if (!compatibility.getCode()) {
|
|
|
|
incompatibleError.setText(errorMessage);
|
|
|
|
|
|
|
|
startRegistration.setVisibility(View.GONE);
|
|
|
|
startRegistration.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
severAddressLabel.setVisibility(View.GONE);
|
|
|
|
serverIP.setVisibility(View.GONE);
|
|
|
|
serverIP.setVisibility(View.GONE);
|
|
|
|
incompatibleError.setVisibility(View.VISIBLE);
|
|
|
|
alertDialog =
|
|
|
|
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
|
|
|
|
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context.getApplicationContext(),
|
|
|
|
errorMessage,
|
|
|
|
|
|
|
|
getResources().getString(R.string.error_authorization_failed),
|
|
|
|
getResources().getString(R.string.error_authorization_failed),
|
|
|
|
|
|
|
|
getResources().getString(compatibility.getDescriptionResourceID()),
|
|
|
|
getResources().getString(R.string.button_ok),
|
|
|
|
getResources().getString(R.string.button_ok),
|
|
|
|
null);
|
|
|
|
onRootedClickListner);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
startRegistration.setVisibility(View.VISIBLE);
|
|
|
|
startRegistration.setVisibility(View.VISIBLE);
|
|
|
|
serverIP.setVisibility(View.VISIBLE);
|
|
|
|
serverIP.setVisibility(View.VISIBLE);
|
|
|
|
incompatibleError.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String ipSaved =
|
|
|
|
String ipSaved =
|
|
|
|
Preference.get(context,
|
|
|
|
Preference.get(context.getApplicationContext(),
|
|
|
|
getResources().getString(R.string.shared_pref_ip));
|
|
|
|
getResources().getString(R.string.shared_pref_ip));
|
|
|
|
regId = Preference.get(context, getResources().getString(R.string.shared_pref_regId));
|
|
|
|
regId = Preference.get(context.getApplicationContext().getApplicationContext(), getResources().getString(R.string.shared_pref_regId));
|
|
|
|
|
|
|
|
|
|
|
|
if (ipSaved != null) {
|
|
|
|
if (ipSaved != null) {
|
|
|
|
serverIP.setText(ipSaved);
|
|
|
|
serverIP.setText(ipSaved);
|
|
|
|
CommonUtilities.setServerURL(ipSaved);
|
|
|
|
CommonUtilities.setServerURL(ipSaved);
|
|
|
|
Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class);
|
|
|
|
startAuthenticationActivity();
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
serverIP.setText(CommonUtilities.SERVER_IP);
|
|
|
|
serverIP.setText(CommonUtilities.SERVER_IP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// on click handler for start registration
|
|
|
|
startRegistration.setOnClickListener(new OnClickListener() {
|
|
|
|
startRegistration.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
@ -123,56 +104,27 @@ public class ServerDetails extends Activity implements APIResultCallBack, TokenC
|
|
|
|
serverIP.getText().toString() +
|
|
|
|
serverIP.getText().toString() +
|
|
|
|
" " +
|
|
|
|
" " +
|
|
|
|
getResources().getString(R.string.dialog_init_end_general))
|
|
|
|
getResources().getString(R.string.dialog_init_end_general))
|
|
|
|
.setPositiveButton(getResources().getString(R.string.info_label_rooted_answer_yes),
|
|
|
|
.setPositiveButton(getResources().getString(R.string.yes),
|
|
|
|
dialogClickListener)
|
|
|
|
dialogClickListener)
|
|
|
|
.setNegativeButton(getResources().getString(R.string.info_label_rooted_answer_no),
|
|
|
|
.setNegativeButton(getResources().getString(R.string.no),
|
|
|
|
dialogClickListener).show();
|
|
|
|
dialogClickListener).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// String clientKey =
|
|
|
|
dialogClickListener = new DialogInterface.OnClickListener() {
|
|
|
|
// Preference.get(context,
|
|
|
|
|
|
|
|
// getResources().getString(R.string.shared_pref_client_id));
|
|
|
|
|
|
|
|
// String clientSecret =
|
|
|
|
|
|
|
|
// Preference.get(context,
|
|
|
|
|
|
|
|
// getResources().getString(R.string.shared_pref_client_secret));
|
|
|
|
|
|
|
|
// if (!clientKey.equals("") && !clientSecret.equals("")) {
|
|
|
|
|
|
|
|
// CommonUtilities.CLIENT_ID = clientKey;
|
|
|
|
|
|
|
|
// CommonUtilities.CLIENT_SECRET = clientSecret;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// if (fromActivity == null) {
|
|
|
|
|
|
|
|
// IdentityProxy.getInstance().getToken(this.getApplicationContext(),
|
|
|
|
|
|
|
|
// ServerDetails.this,
|
|
|
|
|
|
|
|
// CommonUtilities.CLIENT_ID,
|
|
|
|
|
|
|
|
// CommonUtilities.CLIENT_SECRET);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// } catch (TimeoutException e) {
|
|
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
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 (!serverIP.getText().toString().trim().equals("")) {
|
|
|
|
CommonUtilities.setServerURL(serverIP.getText().toString().trim());
|
|
|
|
CommonUtilities.setServerURL(serverIP.getText().toString().trim());
|
|
|
|
Preference.put(context, getResources().getString(R.string.shared_pref_ip),
|
|
|
|
Preference.put(context.getApplicationContext(),
|
|
|
|
|
|
|
|
getResources().getString(R.string.shared_pref_ip),
|
|
|
|
serverIP.getText().toString().trim());
|
|
|
|
serverIP.getText().toString().trim());
|
|
|
|
Intent intent =
|
|
|
|
startAuthenticationActivity();
|
|
|
|
new Intent(ServerDetails.this, AuthenticationActivity.class);
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Toast.makeText(context,
|
|
|
|
Toast.makeText(context.getApplicationContext(),
|
|
|
|
getResources().getString(R.string.toast_message_enter_server_address),
|
|
|
|
getResources().getString(R.string.toast_message_enter_server_address),
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -184,150 +136,214 @@ public class ServerDetails extends Activity implements APIResultCallBack, TokenC
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
|
|
|
Intent i = new Intent();
|
|
|
|
|
|
|
|
i.setAction(Intent.ACTION_MAIN);
|
|
|
|
|
|
|
|
i.addCategory(Intent.CATEGORY_HOME);
|
|
|
|
|
|
|
|
this.startActivity(i);
|
|
|
|
|
|
|
|
super.onBackPressed();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null &&
|
|
|
|
|
|
|
|
fromActivity.equals(AlreadyRegisteredActivity.class.getSimpleName())) {
|
|
|
|
|
|
|
|
Intent i = new Intent();
|
|
|
|
|
|
|
|
i.setAction(Intent.ACTION_MAIN);
|
|
|
|
|
|
|
|
i.addCategory(Intent.CATEGORY_HOME);
|
|
|
|
|
|
|
|
this.startActivity(i);
|
|
|
|
|
|
|
|
this.finish();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null &&
|
|
|
|
|
|
|
|
fromActivity.equals(AuthenticationActivity.class.getSimpleName())) {
|
|
|
|
|
|
|
|
int pid = android.os.Process.myPid();
|
|
|
|
|
|
|
|
android.os.Process.killProcess(pid);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
|
|
|
|
|
Intent i = new Intent();
|
|
|
|
|
|
|
|
i.setAction(Intent.ACTION_MAIN);
|
|
|
|
|
|
|
|
i.addCategory(Intent.CATEGORY_HOME);
|
|
|
|
|
|
|
|
this.startActivity(i);
|
|
|
|
|
|
|
|
this.finish();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
Log.d(TAG, "Server details activity started");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DialogInterface.OnClickListener onRootedClickListner = new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
finish();
|
|
|
|
getMenuInflater().inflate(R.menu.settings, menu);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onReceiveAPIResult(Map<String, String> result, int requestCode) {
|
|
|
|
|
|
|
|
String responseStatus = CommonUtilities.EMPTY_STRING;
|
|
|
|
|
|
|
|
if (result != null) {
|
|
|
|
|
|
|
|
responseStatus = result.get(CommonUtilities.STATUS_KEY);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL) &&
|
|
|
|
|
|
|
|
requestCode == CommonUtilities.IS_REGISTERED_REQUEST_CODE) {
|
|
|
|
|
|
|
|
Intent intent = null;
|
|
|
|
|
|
|
|
if (progressDialog != null) {
|
|
|
|
|
|
|
|
progressDialog.dismiss();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
intent = new Intent(ServerDetails.this, AlreadyRegisteredActivity.class);
|
|
|
|
};
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
|
|
|
|
|
|
|
|
Log.e(TAG, "The value of status is null in onAPIAccessRecive()");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String isRegistered =
|
|
|
|
private void startAuthenticationActivity() {
|
|
|
|
CommonUtilities.getPref(context,
|
|
|
|
Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class);
|
|
|
|
context.getResources()
|
|
|
|
|
|
|
|
.getString(R.string.shared_pref_registered));
|
|
|
|
|
|
|
|
if (isRegistered.equals("1")) {
|
|
|
|
|
|
|
|
Intent intent = null;
|
|
|
|
|
|
|
|
intent = new Intent(ServerDetails.this, AlreadyRegisteredActivity.class);
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
startActivity(intent);
|
|
|
|
startActivity(intent);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
alertDialog =
|
|
|
|
|
|
|
|
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
|
|
|
|
|
|
|
|
getResources().getString(R.string.title_head_connection_error),
|
|
|
|
|
|
|
|
getResources().getString(R.string.error_internal_server),
|
|
|
|
|
|
|
|
getResources().getString(R.string.button_ok),
|
|
|
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
Log.e("null", alertDialog.getClass().getPackage().toString());
|
|
|
|
|
|
|
|
alertDialog.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ServerUtils.clearAppData(context);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.e(TAG, "The value of status is : " + responseStatus);
|
|
|
|
|
|
|
|
ServerUtils.clearAppData(context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alertDialog =
|
|
|
|
/*
|
|
|
|
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
|
|
|
|
* (non-Javadoc)
|
|
|
|
getResources().getString(R.string.title_head_registration_error),
|
|
|
|
*
|
|
|
|
getResources().getString(R.string.error_internal_server),
|
|
|
|
* @see android.app.Activity#onDestroy()
|
|
|
|
getResources().getString(R.string.button_ok),
|
|
|
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
alertDialog.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.e(TAG, "The result is null in onReceiveAPIResult()");
|
|
|
|
|
|
|
|
ServerUtils.clearAppData(context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alertDialog =
|
|
|
|
|
|
|
|
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
|
|
|
|
|
|
|
|
getResources().getString(R.string.title_head_registration_error),
|
|
|
|
|
|
|
|
getResources().getString(R.string.error_for_all_unknown_registration_failures),
|
|
|
|
|
|
|
|
getResources().getString(R.string.button_ok),
|
|
|
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
alertDialog.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onReceiveTokenResult(Token token, String status) {
|
|
|
|
|
|
|
|
if (token != null) {
|
|
|
|
|
|
|
|
if (regId != null && !regId.equals("")) {
|
|
|
|
|
|
|
|
// Check registration.
|
|
|
|
|
|
|
|
isRegistered();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
progressDialog =
|
|
|
|
|
|
|
|
ProgressDialog.show(ServerDetails.this,
|
|
|
|
|
|
|
|
getResources().getString(R.string.dialog_sender_id),
|
|
|
|
|
|
|
|
getResources().getString(R.string.dialog_please_wait),
|
|
|
|
|
|
|
|
true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Checks whether device is registered or NOT.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void isRegistered() {
|
|
|
|
@Override
|
|
|
|
Log.e("isReg", "isReg");
|
|
|
|
protected void onDestroy() {
|
|
|
|
Map<String, String> requestParams = new HashMap<String, String>();
|
|
|
|
//Avoiding memory leaks by destroying context object
|
|
|
|
requestParams.put("regid", regId);
|
|
|
|
context = null;
|
|
|
|
Log.e("regID", regId);
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
|
|
|
|
// Check network connection availability before calling the API.
|
|
|
|
|
|
|
|
if (PhoneState.isNetworkAvailable(context)) {
|
|
|
|
|
|
|
|
// Call isRegistered API.
|
|
|
|
|
|
|
|
ServerUtils.callSecuredAPI(ServerDetails.this, CommonUtilities.IS_REGISTERED_ENDPOINT,
|
|
|
|
|
|
|
|
CommonUtilities.POST_METHOD, requestParams,
|
|
|
|
|
|
|
|
ServerDetails.this,
|
|
|
|
|
|
|
|
CommonUtilities.IS_REGISTERED_REQUEST_CODE);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
CommonDialogUtils.stopProgressDialog(progressDialog);
|
|
|
|
|
|
|
|
CommonDialogUtils.showNetworkUnavailableMessage(ServerDetails.this);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
// Old API manager communication code.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Bundle extras = getIntent().getExtras();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (extras != null) {
|
|
|
|
|
|
|
|
// if
|
|
|
|
|
|
|
|
// (extras.containsKey(getResources().getString(R.string.intent_extra_from_activity)))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// fromActivity =
|
|
|
|
|
|
|
|
// extras.getString(
|
|
|
|
|
|
|
|
// getResources().getString(R.string.intent_extra_from_activity));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// public class ServerDetails extends Activity implements APIResultCallBack,
|
|
|
|
|
|
|
|
// TokenCallBack {
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
|
|
// public void onBackPressed() {
|
|
|
|
|
|
|
|
// Intent i = new Intent();
|
|
|
|
|
|
|
|
// i.setAction(Intent.ACTION_MAIN);
|
|
|
|
|
|
|
|
// i.addCategory(Intent.CATEGORY_HOME);
|
|
|
|
|
|
|
|
// this.startActivity(i);
|
|
|
|
|
|
|
|
// super.onBackPressed();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
|
|
// public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
|
|
|
|
// if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null &&
|
|
|
|
|
|
|
|
// fromActivity.equals(AlreadyRegisteredActivity.class.getSimpleName())) {
|
|
|
|
|
|
|
|
// Intent i = new Intent();
|
|
|
|
|
|
|
|
// i.setAction(Intent.ACTION_MAIN);
|
|
|
|
|
|
|
|
// i.addCategory(Intent.CATEGORY_HOME);
|
|
|
|
|
|
|
|
// this.startActivity(i);
|
|
|
|
|
|
|
|
// this.finish();
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// } else if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null &&
|
|
|
|
|
|
|
|
// fromActivity.equals(AuthenticationActivity.class.getSimpleName())) {
|
|
|
|
|
|
|
|
// int pid = android.os.Process.myPid();
|
|
|
|
|
|
|
|
// android.os.Process.killProcess(pid);
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// } else if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
|
|
|
|
|
// Intent i = new Intent();
|
|
|
|
|
|
|
|
// i.setAction(Intent.ACTION_MAIN);
|
|
|
|
|
|
|
|
// i.addCategory(Intent.CATEGORY_HOME);
|
|
|
|
|
|
|
|
// this.startActivity(i);
|
|
|
|
|
|
|
|
// this.finish();
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return super.onKeyDown(keyCode, event);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
|
|
// public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
|
|
|
// // Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
|
|
|
|
// getMenuInflater().inflate(R.menu.settings, menu);
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// public void onReceiveAPIResult(Map<String, String> result, int
|
|
|
|
|
|
|
|
// requestCode) {
|
|
|
|
|
|
|
|
// String responseStatus = CommonUtilities.EMPTY_STRING;
|
|
|
|
|
|
|
|
// if (result != null) {
|
|
|
|
|
|
|
|
// responseStatus = result.get(CommonUtilities.STATUS_KEY);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL) &&
|
|
|
|
|
|
|
|
// requestCode == CommonUtilities.IS_REGISTERED_REQUEST_CODE) {
|
|
|
|
|
|
|
|
// Intent intent = null;
|
|
|
|
|
|
|
|
// if (progressDialog != null) {
|
|
|
|
|
|
|
|
// progressDialog.dismiss();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// intent = new Intent(ServerDetails.this, AlreadyRegisteredActivity.class);
|
|
|
|
|
|
|
|
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
// startActivity(intent);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// } else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Log.e(TAG, "The value of status is null in onAPIAccessRecive()");
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// String isRegistered =
|
|
|
|
|
|
|
|
// CommonUtilities.getPref(context,
|
|
|
|
|
|
|
|
// context.getResources()
|
|
|
|
|
|
|
|
// .getString(R.string.shared_pref_registered)
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// if (isRegistered.equals("1")) {
|
|
|
|
|
|
|
|
// Intent intent = null;
|
|
|
|
|
|
|
|
// intent = new Intent(ServerDetails.this, AlreadyRegisteredActivity.class);
|
|
|
|
|
|
|
|
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
// startActivity(intent);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// alertDialog =
|
|
|
|
|
|
|
|
// CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
|
|
|
|
|
|
|
|
// getResources()
|
|
|
|
|
|
|
|
// .getString(
|
|
|
|
|
|
|
|
// R.string.title_head_connection_error),
|
|
|
|
|
|
|
|
// getResources()
|
|
|
|
|
|
|
|
// .getString(
|
|
|
|
|
|
|
|
// R.string.error_internal_server),
|
|
|
|
|
|
|
|
// getResources()
|
|
|
|
|
|
|
|
// .getString(
|
|
|
|
|
|
|
|
// R.string.button_ok),
|
|
|
|
|
|
|
|
// null);
|
|
|
|
|
|
|
|
// Log.e("null", alertDialog.getClass().getPackage().toString());
|
|
|
|
|
|
|
|
// alertDialog.show();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // ServerUtils.clearAppData(context);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// Log.e(TAG, "The value of status is : " + responseStatus);
|
|
|
|
|
|
|
|
// ServerUtils.clearAppData(context);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// alertDialog =
|
|
|
|
|
|
|
|
// CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
|
|
|
|
|
|
|
|
// getResources()
|
|
|
|
|
|
|
|
// .getString(
|
|
|
|
|
|
|
|
// R.string.title_head_registration_error),
|
|
|
|
|
|
|
|
// getResources()
|
|
|
|
|
|
|
|
// .getString(
|
|
|
|
|
|
|
|
// R.string.error_internal_server),
|
|
|
|
|
|
|
|
// getResources()
|
|
|
|
|
|
|
|
// .getString(
|
|
|
|
|
|
|
|
// R.string.button_ok),
|
|
|
|
|
|
|
|
// null);
|
|
|
|
|
|
|
|
// alertDialog.show();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// Log.e(TAG, "The result is null in onReceiveAPIResult()");
|
|
|
|
|
|
|
|
// ServerUtils.clearAppData(context);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// alertDialog =
|
|
|
|
|
|
|
|
// CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
|
|
|
|
|
|
|
|
// getResources().getString(
|
|
|
|
|
|
|
|
// R.string.title_head_registration_error),
|
|
|
|
|
|
|
|
// getResources().getString(
|
|
|
|
|
|
|
|
// R.string.error_for_all_unknown_registration_failures),
|
|
|
|
|
|
|
|
// getResources().getString(
|
|
|
|
|
|
|
|
// R.string.button_ok),
|
|
|
|
|
|
|
|
// null);
|
|
|
|
|
|
|
|
// alertDialog.show();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
|
|
// public void onReceiveTokenResult(Token token, String status) {
|
|
|
|
|
|
|
|
// if (token != null) {
|
|
|
|
|
|
|
|
// if (regId != null && !regId.equals("")) {
|
|
|
|
|
|
|
|
// // Check registration.
|
|
|
|
|
|
|
|
// isRegistered();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// progressDialog =
|
|
|
|
|
|
|
|
// ProgressDialog.show(ServerDetails.this,
|
|
|
|
|
|
|
|
// getResources().getString(R.string.dialog_sender_id),
|
|
|
|
|
|
|
|
// getResources().getString(R.string.dialog_please_wait),
|
|
|
|
|
|
|
|
// true);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
|
|
|
// * Checks whether device is registered or NOT.
|
|
|
|
|
|
|
|
// */
|
|
|
|
|
|
|
|
// private void isRegistered() {
|
|
|
|
|
|
|
|
// Log.e("isReg", "isReg");
|
|
|
|
|
|
|
|
// Map<String, String> requestParams = new HashMap<String, String>();
|
|
|
|
|
|
|
|
// requestParams.put("regid", regId);
|
|
|
|
|
|
|
|
// Log.e("regID", regId);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Check network connection availability before calling the API.
|
|
|
|
|
|
|
|
// if (PhoneState.isNetworkAvailable(context)) {
|
|
|
|
|
|
|
|
// // Call isRegistered API.
|
|
|
|
|
|
|
|
// ServerUtils.callSecuredAPI(ServerDetails.this,
|
|
|
|
|
|
|
|
// CommonUtilities.IS_REGISTERED_ENDPOINT,
|
|
|
|
|
|
|
|
// CommonUtilities.POST_METHOD, requestParams,
|
|
|
|
|
|
|
|
// ServerDetails.this,
|
|
|
|
|
|
|
|
// CommonUtilities.IS_REGISTERED_REQUEST_CODE);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// CommonDialogUtils.stopProgressDialog(progressDialog);
|
|
|
|
|
|
|
|
// CommonDialogUtils.showNetworkUnavailableMessage(ServerDetails.this);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|