user name and password was change to as per requirement

parent 5a7d3502
......@@ -50,182 +50,182 @@ import butterknife.internal.Utils;
public class LoginScreen extends Activity {
@BindView(R.id.login_screen_username_edit_text)
EditText userName;
@BindView(R.id.login_screen_password_edit_text)
EditText password;
@BindView(R.id.login_scroll)
ScrollView loginScrollview;
private List<UserApiValues> mUserDetails;
private PrefManager prefManager;
private String userNameStrng, passwordStrng;
private String sysId;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
prefManager = PrefManager.getInstance();
prefManager.init(LoginScreen.this);
ButterKnife.bind(this);
CheckLoginValues();
password.setOnKeyListener(new View.OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
callLoginAPI();
return true;
default:
break;
}
}
return false;
}
});
KeyboardVisibilityEvent.setEventListener(LoginScreen.this, new KeyboardVisibilityEventListener() {
@Override
public void onVisibilityChanged(boolean isOpen) {
if (isOpen) {
loginScrollview.post(new Runnable() {
@Override
public void run() {
loginScrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
}
});
CatalogueApplication application = (CatalogueApplication) getApplication();
Tracker tracker = application.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, getString(R.string.login_screen_string));
}
private void CheckLoginValues() {
SharedPreferences sharedPreferences = getSharedPreferences(PrefManager.PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE);
sysId = sharedPreferences.getString(PrefManager.PREFERENCE_SYS_ID, "");
if (!TextUtils.isEmpty(sysId)) {
startActivity(new Intent(LoginScreen.this, HomeScreen.class));
finish();
}
}
private void callLoginAPI(){
userNameStrng = userName.getText().toString().trim();
passwordStrng = password.getText().toString().trim();
if (TextUtils.isEmpty(userNameStrng)) {
userName.setError(getResources().getString(R.string.user_error));
}
if (TextUtils.isEmpty(passwordStrng)) {
password.setError(getResources().getString(R.string.pasw_error));
}
if (!TextUtils.isEmpty(userNameStrng) && !TextUtils.isEmpty(passwordStrng)) {
KeyboardUtil.hideKeyboard(LoginScreen.this);
boolean networkStatus = NetworkUtil.getConnectivityStatus(getApplicationContext());
if (networkStatus) {
new LoginDetailsSendToServer().execute(userName.getText().toString().trim(), password.getText().toString().trim());
} else {
DialogUtils.showNoConnectionDialog(LoginScreen.this);
}
}
}
@OnClick(R.id.login_screen_login_text_view)
void onLoginClicked() {
//startActivity(new Intent(LoginScreen.this, HomeScreen.class));
callLoginAPI();
}
private class LoginDetailsSendToServer extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private String userName;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(LoginScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
}
@Override
protected SyncStatus doInBackground(String... params) {
userName = params[0];//"a0kuma18";
String password = params[1];//"v$0ftA$win";
return LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants
.CLIENT_SECRET, userName,
password);
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (syncStatus == SyncStatus.SUCCESS) {
new UserApiDetails().execute(userName);
} else {
Toast.makeText(LoginScreen.this, "Invalid username and password", Toast.LENGTH_SHORT).show();
}
}
private class UserApiDetails extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(LoginScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
}
@Override
protected SyncStatus doInBackground(String... params) {
String userName = params[0];
return UserApiManager.getUserDetailResponse(userName, new GetUserApiListener() {
@Override
public void onDoneApiCall(List<UserApiValues> userValues) {
mUserDetails = userValues;
}
});
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (syncStatus == SyncStatus.SUCCESS) {
if (mUserDetails != null) {
String firstname = mUserDetails.get(0).getFirstName();
String lasrname = mUserDetails.get(0).getLastName();
String sysid = mUserDetails.get(0).getSysId();
PrefManager.saveUserDetailsInPreferences(LoginScreen.this, firstname, lasrname, sysid);
startActivity(new Intent(LoginScreen.this, HomeScreen.class));
finish();
}
}
}
}
}
/*private void showErrorDialog(int message) {
@BindView(R.id.login_screen_username_edit_text)
EditText userName;
@BindView(R.id.errormessage)
TextView errorMessage;
@BindView(R.id.login_screen_password_edit_text)
EditText password;
@BindView(R.id.login_scroll)
ScrollView loginScrollview;
private List<UserApiValues> mUserDetails;
private PrefManager prefManager;
private String userNameStrng, passwordStrng;
private String sysId;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
prefManager = PrefManager.getInstance();
prefManager.init(LoginScreen.this);
ButterKnife.bind(this);
CheckLoginValues();
password.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
callLoginAPI();
return true;
default:
break;
}
}
return false;
}
});
KeyboardVisibilityEvent.setEventListener(LoginScreen.this, new KeyboardVisibilityEventListener() {
@Override
public void onVisibilityChanged(boolean isOpen) {
if (isOpen) {
loginScrollview.post(new Runnable() {
@Override
public void run() {
loginScrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
}
});
CatalogueApplication application = (CatalogueApplication) getApplication();
Tracker tracker = application.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, getString(R.string.login_screen_string));
}
private void CheckLoginValues() {
SharedPreferences sharedPreferences = getSharedPreferences(PrefManager.PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE);
sysId = sharedPreferences.getString(PrefManager.PREFERENCE_SYS_ID, "");
if (!TextUtils.isEmpty(sysId)) {
startActivity(new Intent(LoginScreen.this, HomeScreen.class));
finish();
}
}
private void callLoginAPI() {
userNameStrng = userName.getText().toString().trim();
passwordStrng = password.getText().toString().trim();
if (TextUtils.isEmpty(userNameStrng)) {
userName.setError(getResources().getString(R.string.user_error));
}
if (TextUtils.isEmpty(passwordStrng)) {
password.setError(getResources().getString(R.string.pasw_error));
}
if (!TextUtils.isEmpty(userNameStrng) && !TextUtils.isEmpty(passwordStrng)) {
KeyboardUtil.hideKeyboard(LoginScreen.this);
boolean networkStatus = NetworkUtil.getConnectivityStatus(getApplicationContext());
if (networkStatus) {
new LoginDetailsSendToServer().execute(userName.getText().toString().trim(), password.getText().toString().trim());
} else {
DialogUtils.showNoConnectionDialog(LoginScreen.this);
}
}
}
@OnClick(R.id.login_screen_login_text_view)
void onLoginClicked() {
callLoginAPI();
}
private class LoginDetailsSendToServer extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private String userName;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(LoginScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
}
@Override
protected SyncStatus doInBackground(String... params) {
userName = params[0];//"a0kuma18";
String password = params[1];//"v$0ftA$win";
return LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants
.CLIENT_SECRET, userName,
password);
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (syncStatus == SyncStatus.SUCCESS) {
new UserApiDetails().execute(userName);
} else {
errorMessage.setVisibility(View.VISIBLE);
errorMessage.setText("Invalid username and password");
//Toast.makeText(LoginScreen.this, "Invalid username and password", Toast.LENGTH_SHORT).show();
}
}
private class UserApiDetails extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(LoginScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
}
@Override
protected SyncStatus doInBackground(String... params) {
String userName = params[0];
return UserApiManager.getUserDetailResponse(userName, new GetUserApiListener() {
@Override
public void onDoneApiCall(List<UserApiValues> userValues) {
mUserDetails = userValues;
}
});
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (syncStatus == SyncStatus.SUCCESS) {
if (mUserDetails != null) {
String firstname = mUserDetails.get(0).getFirstName();
String lasrname = mUserDetails.get(0).getLastName();
String sysid = mUserDetails.get(0).getSysId();
PrefManager.saveUserDetailsInPreferences(LoginScreen.this, firstname, lasrname, sysid);
startActivity(new Intent(LoginScreen.this, HomeScreen.class));
finish();
}
}
}
}
}
/*private void showErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
......
package com.vsoft.uoflservicenow.utils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.view.ContextThemeWrapper;
import com.vsoft.uoflservicenow.R;
/**
* Created by npadhy on 9/7/2016.
* Created by krishna on 9/7/2016.
*/
public class DialogUtils {
private static AlertDialog alertDialog;
public static void showNoConnectionDialog(final Activity activity) {
try {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (alertDialog == null) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
new ContextThemeWrapper(activity,
android.R.style.Theme_Holo));
alertDialogBuilder.setTitle(activity
.getString(R.string.connection_alert_dialog_title));
alertDialogBuilder
.setMessage(R.string.connection_alert_dialog_message)
.setCancelable(true)
.setPositiveButton(
activity.getString(R.string.settings),
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int id) {
activity
.startActivity(new Intent(
android.provider.Settings.ACTION_SETTINGS));
alertDialog = null;
}
})
.setNegativeButton(
activity.getString(R.string.cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
alertDialog = null;
}
});
alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
});
} catch (Exception e) {
}
}
public static void showNoConnectionDialog(final Activity activity) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
new ContextThemeWrapper(activity,
android.R.style.Theme_Holo));
alertDialogBuilder.setTitle(activity
.getString(R.string.connection_alert_dialog_title));
alertDialogBuilder
.setMessage(R.string.connection_alert_dialog_message)
.setCancelable(true)
.setPositiveButton(
activity.getString(R.string.settings),
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int id) {
activity.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
}
})
.setNegativeButton(
activity.getString(R.string.cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
......@@ -35,7 +35,6 @@
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:padding="10dp"
android:text=""
android:drawableLeft="@mipmap/ic_user_icon"
android:singleLine="true" />
<EditText
......@@ -47,7 +46,6 @@
android:drawableLeft="@mipmap/ic_password_icon"
android:inputType="textPassword"
android:padding="10dp"
android:text=""
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:singleLine="true" />
......@@ -68,6 +66,19 @@
android:text="@string/login_screen_login_string"
android:textAlignment="center" />
<TextView
android:id="@+id/errormessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="@color/error_color"
android:textSize="@dimen/small_text_size"
android:text=""
android:gravity="center"
android:visibility="gone"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
......
......@@ -7,8 +7,10 @@
android:layout_marginBottom="10dp"
card_view:cardBackgroundColor="@color/item_gb_color"
card_view:cardCornerRadius="8dp"
card_view:cardElevation="3sp"
card_view:cardUseCompatPadding="true">
card_view:cardElevation="10dp"
card_view:cardUseCompatPadding="true"
>
<RelativeLayout
android:layout_width="match_parent"
......
......@@ -25,8 +25,8 @@
<string name="rejected">Rejected</string>
<string name="user_error">Please Enter UserName</string>
<string name="pasw_error">Please Enter Password</string>
<string name="user_error">Please enter username</string>
<string name="pasw_error">Please enter password</string>
<string name="date_string">%1$s %2$s, %3$s</string>
<string name="date_and_time_string"> %1$s:%2$s</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment