Commit 5a7d3502 by npadhy

change the network error alert and enter key to keypad button

parent 3f4f3b9a
package com.vsoft.uoflservicenow.ui;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.GridView;
......@@ -11,6 +14,8 @@ import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R;
import com.vsoft.uoflservicenow.adapters.HomeScreenAdapter;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.NetworkUtil;
import com.vsoft.uoflservicenow.utils.Util;
import butterknife.BindView;
......@@ -20,39 +25,84 @@ import butterknife.OnItemClick;
/**
* Created by Kunj on 11/8/16.
*/
public class HomeScreen extends Activity {
@BindView(R.id.tool_bar_view)
Toolbar mToolbar;
@BindView(R.id.home_screen_grid_view) GridView mGridView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.home_screen);
ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication();
Tracker tracker = application.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, getString(R.string.home_screen_string));
String[] gridValuesArray = getResources().getStringArray(R.array.home_screen_array);
TypedArray gridViewIcons = getResources().obtainTypedArray(R.array.home_screen_icon_array);
HomeScreenAdapter adapter = new HomeScreenAdapter(this, gridValuesArray, gridViewIcons);
mGridView.setAdapter(adapter);
}
@OnItemClick(R.id.home_screen_grid_view)
void gridViewItemClicked(int position) {
if(position == 0) {
startActivity(new Intent(HomeScreen.this, ReportIncidentScreen.class));
} else if(position == 1) {
startActivity(new Intent(HomeScreen.this, CatalogueScreen.class));
} else if(position == 2) {
startActivity(new Intent(HomeScreen.this, MyIncidentScreen.class));
}else if(position == 3) {
startActivity(new Intent(HomeScreen.this, MyRequestActivity.class));
}
}
public class HomeScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view)
Toolbar mToolbar;
@BindView(R.id.home_screen_grid_view)
GridView mGridView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.home_screen);
ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication();
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setElevation(0);
actionBar.setTitle("");
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
}
Tracker tracker = application.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, getString(R.string.home_screen_string));
String[] gridValuesArray = getResources().getStringArray(R.array.home_screen_array);
TypedArray gridViewIcons = getResources().obtainTypedArray(R.array.home_screen_icon_array);
HomeScreenAdapter adapter = new HomeScreenAdapter(this, gridValuesArray, gridViewIcons);
mGridView.setAdapter(adapter);
}
@OnItemClick(R.id.home_screen_grid_view)
void gridViewItemClicked(int position) {
boolean networkStatus = NetworkUtil.getConnectivityStatus(getApplicationContext());
if (position == 0) {
if (networkStatus) {
startActivity(new Intent(HomeScreen.this, ReportIncidentScreen.class));
} else {
DialogUtils.showNoConnectionDialog(HomeScreen.this);
// showErrorDialog(R.string.internet_validation_string);
}
} else if (position == 1) {
if (networkStatus) {
startActivity(new Intent(HomeScreen.this, CatalogueScreen.class));
} else {
// showErrorDialog(R.string.internet_validation_string);
DialogUtils.showNoConnectionDialog(HomeScreen.this);
}
} else if (position == 2) {
if (networkStatus) {
startActivity(new Intent(HomeScreen.this, MyIncidentScreen.class));
} else {
// showErrorDialog(R.string.internet_validation_string);
DialogUtils.showNoConnectionDialog(HomeScreen.this);
}
} else if (position == 3) {
if (networkStatus) {
startActivity(new Intent(HomeScreen.this, MyRequestActivity.class));
} else {
// showErrorDialog(R.string.internet_validation_string);
DialogUtils.showNoConnectionDialog(HomeScreen.this);
}
}
}
// private void showErrorDialog(int message) {
// AlertDialog.Builder builder = new AlertDialog.Builder(this);
// builder.setMessage(message)
// .setCancelable(false)
// .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int id) {
// dialog.dismiss();
// }
// });
// AlertDialog alert = builder.create();
// alert.show();
// }
}
......@@ -3,11 +3,14 @@ package com.vsoft.uoflservicenow.ui;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
......@@ -25,6 +28,7 @@ import com.vsoft.uoflservicenow.api.managers.UserApiManager;
import com.vsoft.uoflservicenow.db.models.UserApiValues;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.KeyboardUtil;
import com.vsoft.uoflservicenow.utils.NetworkUtil;
import com.vsoft.uoflservicenow.utils.PrefManager;
......@@ -48,8 +52,6 @@ public class LoginScreen extends Activity {
@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)
......@@ -69,6 +71,26 @@ public class LoginScreen extends Activity {
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) {
......@@ -98,9 +120,7 @@ public class LoginScreen extends Activity {
}
}
@OnClick(R.id.login_screen_login_text_view)
void onLoginClicked() {
//startActivity(new Intent(LoginScreen.this, HomeScreen.class));
private void callLoginAPI(){
userNameStrng = userName.getText().toString().trim();
passwordStrng = password.getText().toString().trim();
......@@ -116,10 +136,14 @@ public class LoginScreen extends Activity {
if (networkStatus) {
new LoginDetailsSendToServer().execute(userName.getText().toString().trim(), password.getText().toString().trim());
} else {
errorMessage.setVisibility(View.VISIBLE);
errorMessage.setText("No NetWork Connection");
}
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> {
......@@ -154,9 +178,7 @@ public class LoginScreen extends Activity {
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();
Toast.makeText(LoginScreen.this, "Invalid username and password", Toast.LENGTH_SHORT).show();
}
}
......@@ -173,6 +195,7 @@ public class LoginScreen extends Activity {
}
@Override
protected SyncStatus doInBackground(String... params) {
String userName = params[0];
return UserApiManager.getUserDetailResponse(userName, new GetUserApiListener() {
......@@ -202,4 +225,16 @@ public class LoginScreen extends Activity {
}
}
}
/*private void showErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}*/
}
......@@ -47,17 +47,15 @@ public class MyRequestActivity extends AppCompatActivity {
ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication();
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setElevation(0);
actionBar.setTitle(R.string.my_reques_string);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
}
Tracker tracker = application.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString());
......@@ -68,7 +66,6 @@ public class MyRequestActivity extends AppCompatActivity {
showErrorDialog(R.string.internet_validation_string);
}
}
class FetchMyRequestData extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
......
package com.vsoft.uoflservicenow.utils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.ContextThemeWrapper;
import com.vsoft.uoflservicenow.R;
/**
* Created by npadhy 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) {
}
}
}
......@@ -35,6 +35,7 @@
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:padding="10dp"
android:text=""
android:drawableLeft="@mipmap/ic_user_icon"
android:singleLine="true" />
<EditText
......@@ -46,6 +47,7 @@
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" />
......@@ -66,19 +68,6 @@
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>
......
<?xml version="1.0" encoding="utf-8"?>
<merge
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@color/white"
android:minHeight="?attr/actionBarSize"
android:padding="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"/>
app:titleTextColor="@color/tool_bar_title_color">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
<ImageView
android:id="@+id/nav_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="@mipmap/ic_home_icon"
android:layout_alignParentLeft="true"
/>
<TextView
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="@string/app_name"
android:textColor="@color/tool_bar_title_color" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<GridView
android:id="@+id/home_screen_grid_view"
android:layout_width="match_parent"
......@@ -27,4 +46,4 @@
android:background="@color/home_screen_bg_color"
android:numColumns="2"/>
</merge>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tool_bar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:minHeight="?attr/actionBarSize"
app:titleTextColor="@color/tool_bar_title_color">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
<ImageView
android:id="@+id/nav_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="@drawable/ic_arrow_back_black_24dp"
android:layout_alignParentLeft="true"
/>
<TextView
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="@string/my_reques_string"
android:textColor="@color/tool_bar_title_color" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
\ No newline at end of file
<resources>
<string name="app_name">UofL ServiceNow</string>
<string name="app_name">UofL ServiceNow</string>
<string name="set_string">Set</string>
<string name="submit_string">Submit</string>
<string name="back_string">Back</string>
<string name="error_string">* Required</string>
<string name="none_string">-None-</string>
<string name="search_for_reference_string">Reference</string>
<string name="internet_validation_string">Please connect to internet and try again.</string>
<string name="home_screen_string">Home Screen</string>
<string name="login_screen_string">Login Screen</string>
<string name="set_string">Set</string>
<string name="submit_string">Submit</string>
<string name="back_string">Back</string>
<string name="error_string">* Required</string>
<string name="none_string">-None-</string>
<string name="search_for_reference_string">Reference</string>
<string name="internet_validation_string">Please connect to internet and try again.</string>
<string name="home_screen_string">Home Screen</string>
<string name="login_screen_string">Login Screen</string>
<string name="loading_string">Loading&#8230;</string>
<string name="select_date_string">Select Date</string>
<string name="select_date_and_time_string">Select Date &#038; Time</string>
<string name="loading_string">Loading&#8230;</string>
<string name="select_date_string">Select Date</string>
<string name="select_date_and_time_string">Select Date &#038; Time</string>
<string name="name_null_view_string">Not rendering (name not available)</string>
<string name="view_not_implemented_string">Not Implemented: %s</string>
<string name="no_variables_string">No Variables&#8230;</string>
<string name="name_null_view_string">Not rendering (name not available)</string>
<string name="view_not_implemented_string">Not Implemented: %s</string>
<string name="no_variables_string">No Variables&#8230;</string>
<string name="approved">Approved</string>
<string name="notrequest">Not Yet Requested</string>
<string name="requested">Requested</string>
<string name="rejected">Rejected</string>
<string name="approved">Approved</string>
<string name="notrequest">Not Yet Requested</string>
<string name="requested">Requested</string>
<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>
<string name="date_string">%1$s %2$s, %3$s</string>
<string name="date_and_time_string"> %1$s:%2$s</string>
<!--Failed to fetch-->
<string name="failed_to_fetch_catalogue_category_string">Failed to fetch Catalogue Category.</string>
<string name="failed_to_fetch_catalogue_category_items_string">Failed to fetch Catalogue Category Items.</string>
<string name="failed_to_fetch_catalogue_form_string">Failed to fetch Form.</string>
<string name="failed_to_fetch_reference_string">Failed to fetch References.</string>
<string name="failed_to_submit_form_string">Failed to submit form.</string>
<string name="failed_to_fetch_incident_string">Failed to fetch Incident.</string>
<!--Failed to fetch-->
<string name="failed_to_fetch_catalogue_category_string">Failed to fetch Catalogue Category.</string>
<string name="failed_to_fetch_catalogue_category_items_string">Failed to fetch Catalogue Category Items.</string>
<string name="failed_to_fetch_catalogue_form_string">Failed to fetch Form.</string>
<string name="failed_to_fetch_reference_string">Failed to fetch References.</string>
<string name="failed_to_submit_form_string">Failed to submit form.</string>
<string name="failed_to_fetch_incident_string">Failed to fetch Incident.</string>
<!--Login Screen-->
<string name="login_screen_user_name_string">Username</string>
<string name="login_screen_password_string">Password</string>
<string name="login_screen_login_string">Login</string>
<!--Login Screen-->
<string name="login_screen_user_name_string">Username</string>
<string name="login_screen_password_string">Password</string>
<string name="login_screen_login_string">Login</string>
<string name="variable_form_misc_info_string">%1$s [add %2$s]</string>
<string name="variable_form_misc_info_string">%1$s [add %2$s]</string>
<!--Catalogue Item Screen-->
<string name="no_catalogue_item_string">No Catalogue Items&#8230;</string>
<!--Catalogue Item Screen-->
<string name="no_catalogue_item_string">No Catalogue Items&#8230;</string>
<!--Catalogue Screen-->
<string name="catalogue_category_string">Catalogue Category</string>
<string name="my_reques_string">My Requests</string>
<!--Catalogue Screen-->
<string name="catalogue_category_string">Catalogue Category</string>
<string name="my_reques_string">My Requests</string>
<!--Incident screen-->
<string name="incident_form_report_incident_text_string">Report Incident</string>
<string name="incident_form_top_text_string">Create an Incident record to report and request assistance with an issue you are having\n\nRequest assistance with an issue you are having. An incident record will be created and managed through to successful resolution. You will also be notified of progress.</string>
<string name="incident_form_impact_text_string">Impact</string>
<string name="incident_form_incident_successful_submission_string">Your Incident has been reported successfully</string>
<string name="incident_form_describe_your_issue_text_string">Please Describe Your Issue below</string>
<!--Incident screen-->
<string name="incident_form_report_incident_text_string">Report Incident</string>
<string name="incident_form_top_text_string">Create an Incident record to report and request assistance with an issue you are having\n\nRequest assistance with an issue you are having. An incident record will be created and managed through to successful resolution. You will also be notified of progress.</string>
<string name="incident_form_impact_text_string">Impact</string>
<string name="incident_form_incident_successful_submission_string">Your Incident has been reported successfully</string>
<string name="incident_form_describe_your_issue_text_string">Please Describe Your Issue below</string>
<!--My Incidents-->
<string name="my_incidents_text_string">My Incidents</string>
<!--My Incidents-->
<string name="my_incidents_text_string">My Incidents</string>
<string name="connection_alert_dialog_title">No Connection Available</string>
<string name="connection_alert_dialog_message">Please check your device settings to ensure you have a working internet connection.</string>
<string name="cancel">Cancel</string>
<string name="settings">Settings</string>
</resources>
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