1
0
Fork 0
mirror of https://github.com/MatomoCamp/matomocamp-companion-android.git synced 2024-09-19 16:13:46 +02:00

Improved notifications with an action button allowing to show the room

map image directly.
Event subtitle in notification BigText style is now shown in white,
before the speaker(s).
This commit is contained in:
Christophe Beyls 2014-01-25 19:28:59 +01:00
parent 151a94864b
commit 55cd420395
10 changed files with 75 additions and 7 deletions

View file

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="be.digitalia.fosdem" package="be.digitalia.fosdem"
android:versionCode="0700104" android:versionCode="0700104"
@ -58,6 +59,12 @@
android:name="android.app.searchable" android:name="android.app.searchable"
android:resource="@xml/main_searchable" /> android:resource="@xml/main_searchable" />
</activity> </activity>
<!-- Clearing the Task Affinity allows this dialog activity to be displayed without bringing to front the main application with it. -->
<activity
android:name=".activities.RoomImageDialogActivity"
android:excludeFromRecents="true"
android:taskAffinity=""
android:theme="@style/DialogTheme" />
<activity <activity
android:name=".activities.SettingsActivity" android:name=".activities.SettingsActivity"
android:label="@string/settings" /> android:label="@string/settings" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="DialogTheme" parent="@android:style/Theme.Holo.Light.Dialog" />
</resources>

View file

@ -101,6 +101,7 @@
<string name="more_info">More info</string> <string name="more_info">More info</string>
<!-- Others --> <!-- Others -->
<string name="room_map">Room map</string>
<string name="directions">Directions to ULB</string> <string name="directions">Directions to ULB</string>
<string name="no_data">No data available.</string> <string name="no_data">No data available.</string>
<string name="about">About</string> <string name="about">About</string>

View file

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="@style/Theme.AppCompat.Light"> <style name="AppTheme" parent="@style/Theme.AppCompat.Light">
@ -12,6 +13,8 @@
<item name="activatedBackgroundIndicator">@drawable/activated_background</item> <item name="activatedBackgroundIndicator">@drawable/activated_background</item>
</style> </style>
<style name="DialogTheme" parent="@android:style/Theme.Dialog" />
<style name="ActionBar.Solid.Fosdem" parent="@style/Widget.AppCompat.Light.ActionBar.Solid"> <style name="ActionBar.Solid.Fosdem" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<!-- Only override the progress bar style for modern devices with Holo theme --> <!-- Only override the progress bar style for modern devices with Holo theme -->

View file

@ -0,0 +1,30 @@
package be.digitalia.fosdem.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
/**
* A special Activity which is displayed like a dialog and shows a room image. Specify the room name and the room image id as Intent extras.
*
* @author Christophe Beyls
*
*/
public class RoomImageDialogActivity extends Activity {
public static final String EXTRA_ROOM_NAME = "roomName";
public static final String EXTRA_ROOM_IMAGE_RESOURCE_ID = "imageResId";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
setTitle(intent.getStringExtra(EXTRA_ROOM_NAME));
ImageView imageView = new ImageView(this);
imageView.setImageResource(intent.getIntExtra(EXTRA_ROOM_IMAGE_RESOURCE_ID, 0));
setContentView(imageView);
}
}

View file

@ -9,18 +9,24 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder; import android.support.v4.app.TaskStackBuilder;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import be.digitalia.fosdem.R; import be.digitalia.fosdem.R;
import be.digitalia.fosdem.activities.EventDetailsActivity; import be.digitalia.fosdem.activities.EventDetailsActivity;
import be.digitalia.fosdem.activities.MainActivity; import be.digitalia.fosdem.activities.MainActivity;
import be.digitalia.fosdem.activities.RoomImageDialogActivity;
import be.digitalia.fosdem.db.DatabaseManager; import be.digitalia.fosdem.db.DatabaseManager;
import be.digitalia.fosdem.fragments.SettingsFragment; import be.digitalia.fosdem.fragments.SettingsFragment;
import be.digitalia.fosdem.model.Event; import be.digitalia.fosdem.model.Event;
import be.digitalia.fosdem.receivers.AlarmReceiver; import be.digitalia.fosdem.receivers.AlarmReceiver;
import be.digitalia.fosdem.utils.StringUtils;
/** /**
* A service to schedule or unschedule alarms in the background, keeping the app responsive. * A service to schedule or unschedule alarms in the background, keeping the app responsive.
@ -140,7 +146,7 @@ public class AlarmIntentService extends IntentService {
String personsSummary = event.getPersonsSummary(); String personsSummary = event.getPersonsSummary();
String trackName = event.getTrack().getName(); String trackName = event.getTrack().getName();
String bigText; CharSequence bigText;
String contentText; String contentText;
if (TextUtils.isEmpty(personsSummary)) { if (TextUtils.isEmpty(personsSummary)) {
contentText = trackName; contentText = trackName;
@ -151,16 +157,31 @@ public class AlarmIntentService extends IntentService {
if (TextUtils.isEmpty(subTitle)) { if (TextUtils.isEmpty(subTitle)) {
bigText = personsSummary; bigText = personsSummary;
} else { } else {
bigText = String.format("%1s\n\n%2$s", subTitle, personsSummary); SpannableString spannableBigText = new SpannableString(String.format("%1$s\n%2$s", subTitle, personsSummary));
// Set the subtitle in white color
spannableBigText.setSpan(new ForegroundColorSpan(Color.WHITE), 0, subTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
bigText = spannableBigText;
} }
} }
Notification notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setWhen(event.getStartTime().getTime()) NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(event.getTitle()).setContentText(contentText) .setWhen(event.getStartTime().getTime()).setContentTitle(event.getTitle()).setContentText(contentText)
.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(trackName)).setContentInfo(event.getRoomName()) .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(trackName)).setContentInfo(event.getRoomName())
.setContentIntent(eventPendingIntent).setAutoCancel(true).setDefaults(defaultFlags).setPriority(NotificationCompat.PRIORITY_DEFAULT) .setContentIntent(eventPendingIntent).setAutoCancel(true).setDefaults(defaultFlags).setPriority(NotificationCompat.PRIORITY_DEFAULT);
.build();
notificationManager.notify((int) eventId, notification); // Add an optional action button to show the room map image
String roomName = event.getRoomName();
int roomImageResId = getResources().getIdentifier(StringUtils.roomNameToResourceName(roomName), "drawable", getPackageName());
if (roomImageResId != 0) {
// The room name is the unique Id of a RoomImageDialogActivity
Intent mapIntent = new Intent(this, RoomImageDialogActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setData(Uri.parse(roomName));
mapIntent.putExtra(RoomImageDialogActivity.EXTRA_ROOM_NAME, roomName);
mapIntent.putExtra(RoomImageDialogActivity.EXTRA_ROOM_IMAGE_RESOURCE_ID, roomImageResId);
PendingIntent mapPendingIntent = PendingIntent.getActivity(this, 0, mapIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_action_place, getString(R.string.room_map), mapPendingIntent);
}
notificationManager.notify((int) eventId, notificationBuilder.build());
} }
AlarmReceiver.completeWakefulIntent(intent); AlarmReceiver.completeWakefulIntent(intent);