Commit 5a7d3502 by npadhy

change the network error alert and enter key to keypad button

parent 3f4f3b9a
package com.vsoft.uoflservicenow.ui; package com.vsoft.uoflservicenow.ui;
import android.app.Activity; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.os.Bundle; 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.support.v7.widget.Toolbar;
import android.widget.GridView; import android.widget.GridView;
...@@ -11,6 +14,8 @@ import com.google.android.gms.analytics.Tracker; ...@@ -11,6 +14,8 @@ import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R; import com.vsoft.uoflservicenow.R;
import com.vsoft.uoflservicenow.adapters.HomeScreenAdapter; 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 com.vsoft.uoflservicenow.utils.Util;
import butterknife.BindView; import butterknife.BindView;
...@@ -20,10 +25,11 @@ import butterknife.OnItemClick; ...@@ -20,10 +25,11 @@ import butterknife.OnItemClick;
/** /**
* Created by Kunj on 11/8/16. * Created by Kunj on 11/8/16.
*/ */
public class HomeScreen extends Activity { public class HomeScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) @BindView(R.id.tool_bar_view)
Toolbar mToolbar; Toolbar mToolbar;
@BindView(R.id.home_screen_grid_view) GridView mGridView; @BindView(R.id.home_screen_grid_view)
GridView mGridView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -32,7 +38,17 @@ public class HomeScreen extends Activity { ...@@ -32,7 +38,17 @@ public class HomeScreen extends Activity {
setContentView(R.layout.home_screen); setContentView(R.layout.home_screen);
ButterKnife.bind(this); ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication(); 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(); Tracker tracker = application.getDefaultTracker();
// Send initial screen view hit. // Send initial screen view hit.
Util.sendScreenName(tracker, getString(R.string.home_screen_string)); Util.sendScreenName(tracker, getString(R.string.home_screen_string));
...@@ -45,14 +61,48 @@ public class HomeScreen extends Activity { ...@@ -45,14 +61,48 @@ public class HomeScreen extends Activity {
@OnItemClick(R.id.home_screen_grid_view) @OnItemClick(R.id.home_screen_grid_view)
void gridViewItemClicked(int position) { void gridViewItemClicked(int position) {
if(position == 0) { boolean networkStatus = NetworkUtil.getConnectivityStatus(getApplicationContext());
if (position == 0) {
if (networkStatus) {
startActivity(new Intent(HomeScreen.this, ReportIncidentScreen.class)); startActivity(new Intent(HomeScreen.this, ReportIncidentScreen.class));
} else if(position == 1) { } else {
DialogUtils.showNoConnectionDialog(HomeScreen.this);
// showErrorDialog(R.string.internet_validation_string);
}
} else if (position == 1) {
if (networkStatus) {
startActivity(new Intent(HomeScreen.this, CatalogueScreen.class)); startActivity(new Intent(HomeScreen.this, CatalogueScreen.class));
} else if(position == 2) { } else {
// showErrorDialog(R.string.internet_validation_string);
DialogUtils.showNoConnectionDialog(HomeScreen.this);
}
} else if (position == 2) {
if (networkStatus) {
startActivity(new Intent(HomeScreen.this, MyIncidentScreen.class)); startActivity(new Intent(HomeScreen.this, MyIncidentScreen.class));
}else if(position == 3) { } else {
// showErrorDialog(R.string.internet_validation_string);
DialogUtils.showNoConnectionDialog(HomeScreen.this);
}
} else if (position == 3) {
if (networkStatus) {
startActivity(new Intent(HomeScreen.this, MyRequestActivity.class)); 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; ...@@ -3,11 +3,14 @@ package com.vsoft.uoflservicenow.ui;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
...@@ -25,6 +28,7 @@ import com.vsoft.uoflservicenow.api.managers.UserApiManager; ...@@ -25,6 +28,7 @@ import com.vsoft.uoflservicenow.api.managers.UserApiManager;
import com.vsoft.uoflservicenow.db.models.UserApiValues; import com.vsoft.uoflservicenow.db.models.UserApiValues;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.KeyboardUtil; import com.vsoft.uoflservicenow.utils.KeyboardUtil;
import com.vsoft.uoflservicenow.utils.NetworkUtil; import com.vsoft.uoflservicenow.utils.NetworkUtil;
import com.vsoft.uoflservicenow.utils.PrefManager; import com.vsoft.uoflservicenow.utils.PrefManager;
...@@ -48,8 +52,6 @@ public class LoginScreen extends Activity { ...@@ -48,8 +52,6 @@ public class LoginScreen extends Activity {
@BindView(R.id.login_screen_username_edit_text) @BindView(R.id.login_screen_username_edit_text)
EditText userName; EditText userName;
@BindView(R.id.errormessage)
TextView errorMessage;
@BindView(R.id.login_screen_password_edit_text) @BindView(R.id.login_screen_password_edit_text)
EditText password; EditText password;
@BindView(R.id.login_scroll) @BindView(R.id.login_scroll)
...@@ -69,6 +71,26 @@ public class LoginScreen extends Activity { ...@@ -69,6 +71,26 @@ public class LoginScreen extends Activity {
ButterKnife.bind(this); ButterKnife.bind(this);
CheckLoginValues(); 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() { KeyboardVisibilityEvent.setEventListener(LoginScreen.this, new KeyboardVisibilityEventListener() {
@Override @Override
public void onVisibilityChanged(boolean isOpen) { public void onVisibilityChanged(boolean isOpen) {
...@@ -98,9 +120,7 @@ public class LoginScreen extends Activity { ...@@ -98,9 +120,7 @@ public class LoginScreen extends Activity {
} }
} }
@OnClick(R.id.login_screen_login_text_view) private void callLoginAPI(){
void onLoginClicked() {
//startActivity(new Intent(LoginScreen.this, HomeScreen.class));
userNameStrng = userName.getText().toString().trim(); userNameStrng = userName.getText().toString().trim();
passwordStrng = password.getText().toString().trim(); passwordStrng = password.getText().toString().trim();
...@@ -116,11 +136,15 @@ public class LoginScreen extends Activity { ...@@ -116,11 +136,15 @@ public class LoginScreen extends Activity {
if (networkStatus) { if (networkStatus) {
new LoginDetailsSendToServer().execute(userName.getText().toString().trim(), password.getText().toString().trim()); new LoginDetailsSendToServer().execute(userName.getText().toString().trim(), password.getText().toString().trim());
} else { } else {
errorMessage.setVisibility(View.VISIBLE); DialogUtils.showNoConnectionDialog(LoginScreen.this);
errorMessage.setText("No NetWork Connection");
} }
} }
} }
@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 class LoginDetailsSendToServer extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog; private ProgressDialog progressDialog;
...@@ -154,9 +178,7 @@ public class LoginScreen extends Activity { ...@@ -154,9 +178,7 @@ public class LoginScreen extends Activity {
if (syncStatus == SyncStatus.SUCCESS) { if (syncStatus == SyncStatus.SUCCESS) {
new UserApiDetails().execute(userName); new UserApiDetails().execute(userName);
} else { } else {
errorMessage.setVisibility(View.VISIBLE); Toast.makeText(LoginScreen.this, "Invalid username and password", Toast.LENGTH_SHORT).show();
errorMessage.setText("Invalid username and password");
// Toast.makeText(LoginScreen.this, "Invalid username and password", Toast.LENGTH_SHORT).show();
} }
} }
...@@ -173,6 +195,7 @@ public class LoginScreen extends Activity { ...@@ -173,6 +195,7 @@ public class LoginScreen extends Activity {
} }
@Override @Override
protected SyncStatus doInBackground(String... params) { protected SyncStatus doInBackground(String... params) {
String userName = params[0]; String userName = params[0];
return UserApiManager.getUserDetailResponse(userName, new GetUserApiListener() { return UserApiManager.getUserDetailResponse(userName, new GetUserApiListener() {
...@@ -202,4 +225,16 @@ public class LoginScreen extends Activity { ...@@ -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 { ...@@ -47,17 +47,15 @@ public class MyRequestActivity extends AppCompatActivity {
ButterKnife.bind(this); ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication(); CatalogueApplication application = (CatalogueApplication) getApplication();
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setElevation(0); actionBar.setElevation(0);
actionBar.setTitle(R.string.my_reques_string); actionBar.setTitle(R.string.my_reques_string);
actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowTitleEnabled(true);
} }
Tracker tracker = application.getDefaultTracker(); Tracker tracker = application.getDefaultTracker();
// Send initial screen view hit. // Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString()); Util.sendScreenName(tracker, actionBar.getTitle().toString());
...@@ -68,7 +66,6 @@ public class MyRequestActivity extends AppCompatActivity { ...@@ -68,7 +66,6 @@ public class MyRequestActivity extends AppCompatActivity {
showErrorDialog(R.string.internet_validation_string); showErrorDialog(R.string.internet_validation_string);
} }
} }
class FetchMyRequestData extends AsyncTask<String, Void, SyncStatus> { class FetchMyRequestData extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog; 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 @@ ...@@ -35,6 +35,7 @@
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" android:layout_marginRight="20dp"
android:padding="10dp" android:padding="10dp"
android:text=""
android:drawableLeft="@mipmap/ic_user_icon" android:drawableLeft="@mipmap/ic_user_icon"
android:singleLine="true" /> android:singleLine="true" />
<EditText <EditText
...@@ -46,6 +47,7 @@ ...@@ -46,6 +47,7 @@
android:drawableLeft="@mipmap/ic_password_icon" android:drawableLeft="@mipmap/ic_password_icon"
android:inputType="textPassword" android:inputType="textPassword"
android:padding="10dp" android:padding="10dp"
android:text=""
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" android:layout_marginRight="20dp"
android:singleLine="true" /> android:singleLine="true" />
...@@ -66,19 +68,6 @@ ...@@ -66,19 +68,6 @@
android:text="@string/login_screen_login_string" android:text="@string/login_screen_login_string"
android:textAlignment="center" /> 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>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<merge <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"> android:layout_height="match_parent">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/tool_bar_view" android:id="@+id/tool_bar_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@color/white" android:background="@color/white"
android:minHeight="?attr/actionBarSize" android:minHeight="?attr/actionBarSize"
android:padding="0dp" app:titleTextColor="@color/tool_bar_title_color">
app:contentInsetEnd="0dp" <RelativeLayout
app:contentInsetLeft="0dp" android:layout_width="match_parent"
app:contentInsetRight="0dp" android:layout_height="wrap_content"
app:contentInsetStart="0dp"/> 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 <GridView
android:id="@+id/home_screen_grid_view" android:id="@+id/home_screen_grid_view"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -27,4 +46,4 @@ ...@@ -27,4 +46,4 @@
android:background="@color/home_screen_bg_color" android:background="@color/home_screen_bg_color"
android:numColumns="2"/> android:numColumns="2"/>
</merge> </LinearLayout>
\ No newline at end of file \ 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
...@@ -62,4 +62,9 @@ ...@@ -62,4 +62,9 @@
<!--My Incidents--> <!--My Incidents-->
<string name="my_incidents_text_string">My Incidents</string> <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> </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