Commit ab925e59 by Kunj Gupta

Added push notification in Arrow.

parent b4ea5dd4
......@@ -88,4 +88,8 @@ dependencies {
compile 'com.android.support:animated-vector-drawable:27.0.2'
compile 'com.android.support:support-media-compat:27.0.2'
compile 'com.android.support:support-v4:27.0.2'
compile 'com.google.firebase:firebase-messaging:11.8.0'
}
apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
{
"project_info": {
"project_number": "593992849158",
"project_id": "uofl-servicenow-android"
"project_number": "222593508124",
"firebase_url": "https://v-soft-poc-apps.firebaseio.com",
"project_id": "v-soft-poc-apps",
"storage_bucket": "v-soft-poc-apps.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:593992849158:android:84f481659dc7e412",
"mobilesdk_app_id": "1:222593508124:android:d77c1b70d2a38b4d",
"android_client_info": {
"package_name": "com.vsoft.uoflservicenow"
"package_name": "com.vsoft.servicenow.arrow.debug"
}
},
"oauth_client": [],
"oauth_client": [
{
"client_id": "222593508124-1jq94gaia4oahk321cd8ud74jv6tqgr3.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBEzc7fo12bQLx8CkogSGIb2j-vivdbJNg"
"current_key": "AIzaSyALtTZoenaAEMfqvBLlHRsAU4P_aoOYBLg"
}
],
"services": {
"analytics_service": {
"status": 2,
"analytics_property": {
"tracking_id": "UA-83545030-1"
}
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 1
"status": 2
}
}
}
......
......@@ -100,6 +100,25 @@
</intent-filter>
</receiver>
<service android:name=".service.NotificationInstanceIdService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service
android:name=".service.NotificationMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="2b0a6e9db28d607fbcf71b8b25f1a0795e3f5b22" />
......
package com.vsoft.servicenow.adapters;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.db.managers.NotificationsManager;
import com.vsoft.servicenow.db.models.Notifications;
import com.vsoft.servicenow.ui.NotificationScreen;
import com.vsoft.servicenow.utils.Util;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* NotificationAdapter: This is Notification list view adapter.
*
* @author Kunj on 5/12/16.
*/
public class NotificationAdapter extends RecyclerView.Adapter<NotificationAdapter.NotificationHolder> {
private List<Notifications> mNotificationsList = new ArrayList<>(0);
private Context mContext;
/**
* Provide a suitable constructor.
*/
public NotificationAdapter(Context context) {
mContext = context;
}
/**
* setNotificationList: This method will set the list of notifications.
*/
public void setNotificationList(List<Notifications> notificationList) {
mNotificationsList.clear();
if (notificationList != null) {
mNotificationsList.addAll(notificationList);
}
notifyDataSetChanged();
}
@Override
public NotificationHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.notification_adapter, parent, false);
return new NotificationHolder(view);
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(NotificationHolder holder, final int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
final Notifications notifications = mNotificationsList.get(position);
holder.titleTextView.setText(notifications.getTitle());
holder.messageTextView.setText(notifications.getMessage());
holder.dateTextView.setText(Util.getDateTimeStringForDisplay(notifications.getTime()));
// holder.deleteImageView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// showSuccessfulLogoutDialog(notifications);
// }
// });
}
/**
* NotificationHolder: This is view holder class, which is hold all views reference.
*/
public class NotificationHolder extends RecyclerView.ViewHolder {
/**
* titleTextView: This is title text view.
*/
@BindView(R.id.notification_adapter_title_text_view)
TextView titleTextView;
/**
* messageTextView: This is message text view.
*/
@BindView(R.id.notification_adapter_message_text_view)
TextView messageTextView;
/**
* dateTextView: This is date text view.
*/
@BindView(R.id.notification_adapter_date_text_view)
TextView dateTextView;
/**
* deleteImageView: This is delete icon image view.
*/
// @BindView(R.id.notification_adapter_delete_image_view)
// ImageView deleteImageView;
/**
* Constructor of NotificationHolder class.
*/
public NotificationHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
/**
* getItemId: This method will return item id.
*/
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return mNotificationsList.size();
}
// private void showSuccessfulLogoutDialog(final Notifications notifications) {
// AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
// builder.setMessage(R.string.notification_screen_delete_msg_string)
// .setTitle(R.string.confirm_string)
// .setCancelable(false)
// .setPositiveButton(R.string.yes_string, new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int id) {
// if (notifications != null) {
// mNotificationsList.remove(notifications);
// NotificationsManager.delete(notifications);
// }
// ((NotificationScreen) mContext).updateNotificationList();
// dialog.dismiss();
// }
// })
// .setNegativeButton(R.string.no_string, new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int id) {
// dialog.dismiss();
// }
// });
//
// // Create the AlertDialog object and return it
// AlertDialog alertDialog = builder.create();
// alertDialog.show();
// }
}
......@@ -41,6 +41,8 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
createCatalogueItemInputTable(db);
createAttachmentTable(db);
createIncidentInputTable(db);
createNotificationsTable(db);
}
@Override
......@@ -200,4 +202,13 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
+ INCIDENT_INPUT_SHORT_DESCRIPTION + " text, "
+ INCIDENT_INPUT_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createNotificationsTable(SQLiteDatabase db) {
db.execSQL("create table IF NOT EXISTS " + TABLE_NOTIFICATIONS + "("
+ NOTIFICATIONS_ID + " integer primary key autoincrement, "
+ NOTIFICATIONS_TITLE + " text, "
+ NOTIFICATIONS_MESSAGE + " text, "
+ NOTIFICATIONS_TIME + " DATETIME"
+ ");");
}
}
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.Notifications;
import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList;
import java.util.List;
/**
* NotificationsManager: This is database manager class of notification,
* it will handle all the operation of database for notification.
* @author Kunj on 16-01-2017.
*/
public final class NotificationsManager implements DBConstants {
/**
* Default Constructor.
* */
private NotificationsManager() {
}
/**
* save: With the help of this method, we can save notification row in db.
* */
public static long save(Notifications notifications) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
long id = db.insert(TABLE_NOTIFICATIONS, null, getContentValues(notifications));
notifications.setId(id);
return id;
} else {
return -1;
}
}
/**
* delete: With the help of this method, we can delete notification row from db.
* */
public static int delete(Notifications notifications) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_NOTIFICATIONS, NOTIFICATIONS_ID + "=" + notifications.getId(), null);
}
return -1;
}
/**
* getAllNotifications: This method will return all notifications data.
* */
public static List<Notifications> getAllNotifications() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_NOTIFICATIONS
+ " ORDER BY "
+ DBConstants.NOTIFICATIONS_TIME
+ " DESC", null);
ArrayList<Notifications> notificationsList;
if (c.getCount() > 0) {
notificationsList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
Notifications.NotificationsBuilder builder
= Notifications.NotificationsBuilder.aNotification();
fillAllNotificationDetails(c, builder);
notificationsList.add(builder.build());
}
} else {
notificationsList = new ArrayList<>(0);
}
c.close();
return notificationsList;
} else {
return new ArrayList<>(0);
}
}
/**
* get: This method will fetch notification data with respect to notification id and return it.
* */
public static Notifications get(long notificationId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
Notifications notifications = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_NOTIFICATIONS
+ " where " + NOTIFICATIONS_ID + "=" + notificationId, null);
if (c.moveToFirst()) {
Notifications.NotificationsBuilder builder
= Notifications.NotificationsBuilder.aNotification();
fillAllNotificationDetails(c, builder);
notifications = builder.build();
}
c.close();
}
return notifications;
}
private static void fillAllNotificationDetails(Cursor c, Notifications.NotificationsBuilder builder) {
builder.setId(c.getLong(INDEX_NOTIFICATIONS_ID));
builder.setTitle(c.getString(INDEX_NOTIFICATIONS_TITLE));
builder.setMessage(c.getString(INDEX_NOTIFICATIONS_MESSAGE));
builder.setTime(c.getLong(INDEX_NOTIFICATIONS_TIME));
}
private static ContentValues getContentValues(Notifications notifications) {
ContentValues cv = new ContentValues(NOTIFICATIONS_COLUMN_COUNT - 1);
cv.put(NOTIFICATIONS_TITLE, notifications.getTitle());
cv.put(NOTIFICATIONS_MESSAGE, notifications.getMessage());
cv.put(NOTIFICATIONS_TIME, notifications.getTime());
return cv;
}
}
package com.vsoft.servicenow.db.models;
/**
* DB Notifications Params Class.
*
* @author Kunj on 16-01-2017.
*/
public final class Notifications {
private long id = -1;
private String title;
private String message;
private long time;
/**
* Default constructor.
* */
public Notifications() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
@Override
public String toString() {
return "Notifications{"
+ "id=" + id
+ ", title='" + title + '\''
+ ", message='" + message + '\''
+ ", time=" + time
+ '}';
}
/**
* NotificationsBuilder: This is inner static builder class of Notification.
*/
public static final class NotificationsBuilder {
private long id = -1;
private String title;
private String message;
private long time;
private NotificationsBuilder() {
}
/**
* aNotification: This method will set the NotificationsBuilder object reference.
*/
public static NotificationsBuilder aNotification() {
return new NotificationsBuilder();
}
/**
* setId: This method will set the notification local db id.
*/
public NotificationsBuilder setId(long notificationId) {
this.id = notificationId;
return this;
}
/**
* setTitle: This method will set the notification title.
*/
public NotificationsBuilder setTitle(String notificationTitle) {
this.title = notificationTitle;
return this;
}
/**
* setTime: This method will set the notification time.
*/
public NotificationsBuilder setTime(long notificationTime) {
this.time = notificationTime;
return this;
}
/**
* setMessage: This method will set the notification message.
*/
public NotificationsBuilder setMessage(String notificationMessage) {
this.message = notificationMessage;
return this;
}
/**
* but: This method will return NotificationBuilder reference.
*/
public NotificationsBuilder but() {
return aNotification().setId(id).setTitle(title).setMessage(message).setTime(time);
}
/**
* build: This method will return Notification class object with data.
*/
public Notifications build() {
Notifications notifications = new Notifications();
notifications.setId(id);
notifications.setTitle(title);
notifications.setMessage(message);
notifications.setTime(time);
return notifications;
}
}
}
package com.vsoft.servicenow.service;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
import com.google.gson.JsonObject;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
/**
* NotificationInstanceIdService: This is service class to get refresh token.
* @author kunj on 16/01/17.
*/
public class NotificationInstanceIdService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
CatalogueLog.d("Refreshed token: " + refreshedToken);
PrefManager.setSharedPref(CatalogueApplication.getContext(), Constants.PREFS_NOTIFICATION_TOKEN, refreshedToken);
// sendRegistrationToServer(refreshedToken);
}
// private void sendRegistrationToServer(String refreshedToken) {
// long userId = SharedPreferencesStore.getSharedPrefLong(Constants.PREFS_LOGGED_IN_USER_ID);
// if (userId == -1) {
// OklahomaLog.e("NotificationInstanceIdService: sendRegistrationToServer: userId is -1.");
// return;
// }
//
// JsonObject deviceJsonObject = new JsonObject();
// deviceJsonObject.addProperty(Constants.POST_JSON_USER_ID, userId);
// deviceJsonObject.addProperty(Constants.POST_JSON_PUSH_NOTIFY_KEY, refreshedToken);
// deviceJsonObject.addProperty(Constants.POST_JSON_DEVICE_TYPE, Constants.DEVICE_TYPE);
// deviceJsonObject.addProperty(Constants.POST_JSON_TEMP_DEVICE_ID, "");
// DeviceRegistrationApiManager.postDeviceRegistration(deviceJsonObject);
// }
}
package com.vsoft.servicenow.service;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.db.managers.NotificationsManager;
import com.vsoft.servicenow.db.models.Notifications;
import com.vsoft.servicenow.ui.NotificationScreen;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import java.util.Map;
/**
* NotificationMessagingService: This is service class to receive notification message.
*
* @author kunj on 16/01/17.
*/
public class NotificationMessagingService extends FirebaseMessagingService {
private static final String FCM_KEY_TITLE = "title";
private static final String FCM_KEY_MESSAGE = "body";
/**
* This is default constructor of NotificationMessagingService.
*/
public NotificationMessagingService() {
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// long userId = SharedPreferences
// .getSharedPrefLong(Constants.PREFS_LOGGED_IN_USER_ID);
// if (userId != -1) {
CatalogueLog.e("RemoteMessage: "+remoteMessage.toString());
Map<String, String> dataMap = remoteMessage.getData();
CatalogueLog.e("data: "+dataMap.toString());
String title = dataMap.get(FCM_KEY_TITLE);
String message = dataMap.get(FCM_KEY_MESSAGE);
Notifications newNotification = new Notifications();
newNotification.setTitle(title == null ? "" : title);
newNotification.setMessage(message);
newNotification.setTime(System.currentTimeMillis());
NotificationsManager.save(newNotification);
sendNotification(newNotification);
sendLocalMessage(NotificationMessagingService.this, newNotification);
// }
}
private void sendLocalMessage(Context context, Notifications notifications) {
Intent intent = new Intent(Constants.BROADCAST_NOTIFICATION);
intent.putExtra(Constants.DATA_KEY_NOTIFICATION_TITLE, notifications.getTitle());
intent.putExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE, notifications.getMessage());
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
private void sendNotification(Notifications notification) {
Intent newIntent = new Intent(this, NotificationScreen.class);
newIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, newIntent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(notification.getTitle())
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setSound(defaultSoundUri);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notificationBuilder.build());
}
}
package com.vsoft.servicenow.ui;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.adapters.NotificationAdapter;
import com.vsoft.servicenow.db.managers.NotificationsManager;
import com.vsoft.servicenow.db.models.Notifications;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.Util;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* NotificationScreen: This class will use for handle all the functionality of Notification.
*
* @author Kunj on 2/12/16.
*/
public class NotificationScreen extends AppCompatActivity {
/**
* mNotificationRecyclerView: Listview for showing all notifications.
*/
@BindView(R.id.notification_recycle_view)
RecyclerView mNotificationRecyclerView;
/**
* mEmptyTextView: Empty textview.
*/
@BindView(R.id.notification_screen_empty_text_view)
TextView mEmptyTextView;
private NotificationAdapter mAdapter;
private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Cancel received notifications
final NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
//Play notification sound because Above we already cancel notifications.
// That's why we need to play explicitly
Util.playNotificationSound(NotificationScreen.this);
AlertDialog.Builder builder = new AlertDialog.Builder(NotificationScreen.this);
builder.setMessage(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE))
.setTitle(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_TITLE))
.setCancelable(false)
.setPositiveButton(R.string.go_to_notification_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
updateNotificationList();
}
})
.setNegativeButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
updateNotificationList();
}
});
AlertDialog alert = builder.create();
alert.show();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.notification_screen);
ButterKnife.bind(this);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getResources()
.getString(R.string.notification_screen_action_bar_title_string));
actionBar.setElevation(0);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mNotificationRecyclerView.setHasFixedSize(true);
// use a linear layout manager
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
mNotificationRecyclerView.setLayoutManager(layoutManager);
DividerItemDecoration dividerItemDecoration
= new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
mNotificationRecyclerView.addItemDecoration(dividerItemDecoration);
}
@Override
public void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(NotificationScreen.this)
.registerReceiver(mMessageReceiver,
new IntentFilter(Constants.BROADCAST_NOTIFICATION));
updateNotificationList();
}
@Override
public void onPause() {
LocalBroadcastManager.getInstance(NotificationScreen.this)
.unregisterReceiver(mMessageReceiver);
super.onPause();
}
/**
* updateNotificationList: This method use for update list after deletion of notifications.
*/
public void updateNotificationList() {
List<Notifications> notificationsList = NotificationsManager.getAllNotifications();
if (notificationsList.isEmpty()) {
mEmptyTextView.setVisibility(View.VISIBLE);
mNotificationRecyclerView.setVisibility(View.GONE);
} else {
mEmptyTextView.setVisibility(View.GONE);
mNotificationRecyclerView.setVisibility(View.VISIBLE);
if (mAdapter == null) {
mAdapter = new NotificationAdapter(NotificationScreen.this);
mAdapter.setNotificationList(notificationsList);
mNotificationRecyclerView.setAdapter(mAdapter);
} else {
mAdapter.setNotificationList(notificationsList);
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
......@@ -36,7 +36,7 @@ public class Constants {
*/
public static final String ACTION_SYNC = "action_sync";
/**
/**
* Broadcast custom intent
*/
public static final String APPLICATION_BROADCAST_INTENT = "application_broadcast";
......@@ -56,6 +56,11 @@ public class Constants {
public static final String URL_PARAM_SYS_ID = "sys_id";
/**
* Preference Notification token.
*/
public static final String PREFS_NOTIFICATION_TOKEN = "notification_token";
/**
* Debug logs
*/
public static final boolean DEBUG = true;
......@@ -166,4 +171,18 @@ public class Constants {
/*Chat Activity*/
public static final String CHAT_USER_API_URL = DOMAIN + URL_GET_USERDETAILS.substring(1);
/**
* Broadcast String: broadcast notification.
*/
public static final String BROADCAST_NOTIFICATION = "broadcast_notification";
/**
* Intent String: Notification title.
*/
public static final String DATA_KEY_NOTIFICATION_TITLE = "notification_title";
/**
* Intent String: Notification message.
*/
public static final String DATA_KEY_NOTIFICATION_MESSAGE = "notification_message";
}
......@@ -343,4 +343,47 @@ public interface DBConstants {
int INDEX_ATTACHMENT_SYNC_DIRTY = 5;
int ATTACHMENT_COLUMN_COUNT = 6;
/**
* Notification table name.
*/
String TABLE_NOTIFICATIONS = "notifications";
/**
* NOTIFICATIONS_ID: Id column name for Notification table.
*/
String NOTIFICATIONS_ID = ID;
/**
* NOTIFICATIONS_TITLE: Time column name for Notification table.
*/
String NOTIFICATIONS_TITLE = "title";
/**
* NOTIFICATIONS_MESSAGE: Message column name for Notification table.
*/
String NOTIFICATIONS_MESSAGE = "message";
/**
* NOTIFICATIONS_TIME: Time column name for Notification table.
*/
String NOTIFICATIONS_TIME = "time";
/**
* INDEX_NOTIFICATIONS_ID: Id indices for Notification table.
*/
int INDEX_NOTIFICATIONS_ID = 0;
/**
* INDEX_NOTIFICATIONS_TITLE: Title indices for Notification table.
*/
int INDEX_NOTIFICATIONS_TITLE = 1;
/**
* INDEX_NOTIFICATIONS_MESSAGE: Message indices for Notification table.
*/
int INDEX_NOTIFICATIONS_MESSAGE = 2;
/**
* INDEX_NOTIFICATIONS_TIME: Time indices for Notification table.
*/
int INDEX_NOTIFICATIONS_TIME = 3;
/**
* NOTIFICATIONS_COLUMN_COUNT: Total column count for notification table.
*/
int NOTIFICATIONS_COLUMN_COUNT = 4;
}
\ No newline at end of file
......@@ -3,6 +3,10 @@ package com.vsoft.servicenow.utils;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Typeface;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.InputType;
......@@ -33,6 +37,7 @@ import com.vsoft.servicenow.db.models.VariableChoice;
import com.vsoft.servicenow.db.models.VariableViewContainer;
import com.vsoft.servicenow.enums.ViewType;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
......@@ -634,4 +639,43 @@ public class Util {
}
return result;
}
/**
* getDateTimeStringForDisplay: This method will convert long value to define date format string.
* */
public static String getDateTimeStringForDisplay(long dateTime) {
SimpleDateFormat format = new SimpleDateFormat("MMMM dd 'at' hh:mm aa");
return format.format(dateTime);
}
/**
* playNotificationSound: This method will play default notification sound.
* */
public static void playNotificationSound(Context context) {
Uri defaultRingtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(context, defaultRingtoneUri);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayer.prepare();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
mediaPlayer.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/normal_margin"
android:paddingLeft="@dimen/normal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/extra_large_margin">
<!--<ImageView
android:id="@+id/notification_adapter_delete_image_view"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/notification_delete"/>-->
<TextView
android:id="@+id/notification_adapter_title_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:layout_marginRight="@dimen/small_margin"
android:textSize="@dimen/extra_normal_text_size" />
<TextView
android:id="@+id/notification_adapter_message_text_view"
android:layout_below="@id/notification_adapter_title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/small_margin"
android:textSize="@dimen/normal_text_size" />
<TextView
android:id="@+id/notification_adapter_date_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/notification_adapter_message_text_view"
android:layout_alignParentRight="true"
android:layout_marginTop="@dimen/small_margin"
android:layout_centerVertical="true"
android:textSize="@dimen/normal_text_size" />
</RelativeLayout>
\ No newline at end of file
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/notification_recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:divider="@color/list_divider_color"
android:dividerHeight="@dimen/list_divider_height"
android:scrollbars="vertical"/>
<TextView
android:id="@+id/notification_screen_empty_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:text="@string/notification_screen_empty_text_string"
android:textSize="@dimen/normal_text_size"
android:gravity="center"
android:visibility="gone"/>
</merge>
\ No newline at end of file
......@@ -5,6 +5,7 @@
<color name="colorAccent">#6F9A3E</color>
<color name="item_gb_color">#000000</color>
<color name="error_color">#6F9A3E</color>
<color name="light_gray">#BCBABA</color>
<color name="name_null_view_color">#88FFA500</color>
<color name="view_not_implemented_color">@color/colorPrimaryDark</color>
......@@ -22,4 +23,7 @@
<!--Login Screen-->
<color name="login_screen_login_button_background_color">@color/colorPrimaryDark</color>
<color name="login_screen_edit_text_background_color">@color/colorPrimaryDark</color>
<!--Setting screen-->
<color name="list_divider_color">@color/light_gray</color>
</resources>
......@@ -43,4 +43,7 @@
<dimen name="progress_bar_padding_size">13dp</dimen>
<dimen name="uofl_tool_bar_refresh_button_width">35dp</dimen>
<dimen name="uofl_tool_bar_refresh_button_height">35dp</dimen>
<!--Setting screen-->
<dimen name="list_divider_height">0.5dp</dimen>
</resources>
\ No newline at end of file
......@@ -104,4 +104,9 @@
<!--Home Screen-->
<string name="home_screen_logout_confirmation_msg_string">Are you sure you want to logout?</string>
<!--Notifications-->
<string name="notification_screen_action_bar_title_string">Notifications</string>
<string name="notification_screen_empty_text_string">No Notifications</string>
<string name="notification_screen_delete_msg_string">Are you sure you want to delete?</string>
<string name="go_to_notification_string">Go to Notification</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