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:
parent
151a94864b
commit
55cd420395
10 changed files with 75 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="be.digitalia.fosdem"
|
||||
android:versionCode="0700104"
|
||||
|
@ -58,6 +59,12 @@
|
|||
android:name="android.app.searchable"
|
||||
android:resource="@xml/main_searchable" />
|
||||
</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
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:label="@string/settings" />
|
||||
|
|
BIN
res/drawable-hdpi/ic_action_place.png
Normal file
BIN
res/drawable-hdpi/ic_action_place.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 336 B |
BIN
res/drawable-mdpi/ic_action_place.png
Normal file
BIN
res/drawable-mdpi/ic_action_place.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 276 B |
BIN
res/drawable-xhdpi/ic_action_place.png
Normal file
BIN
res/drawable-xhdpi/ic_action_place.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 402 B |
BIN
res/drawable-xxhdpi/ic_action_place.png
Normal file
BIN
res/drawable-xxhdpi/ic_action_place.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 526 B |
6
res/values-v11/styles.xml
Normal file
6
res/values-v11/styles.xml
Normal 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>
|
|
@ -101,6 +101,7 @@
|
|||
<string name="more_info">More info</string>
|
||||
|
||||
<!-- Others -->
|
||||
<string name="room_map">Room map</string>
|
||||
<string name="directions">Directions to ULB</string>
|
||||
<string name="no_data">No data available.</string>
|
||||
<string name="about">About</string>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
|
||||
|
@ -12,6 +13,8 @@
|
|||
<item name="activatedBackgroundIndicator">@drawable/activated_background</item>
|
||||
</style>
|
||||
|
||||
<style name="DialogTheme" parent="@android:style/Theme.Dialog" />
|
||||
|
||||
<style name="ActionBar.Solid.Fosdem" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
|
||||
|
||||
<!-- Only override the progress bar style for modern devices with Holo theme -->
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -9,18 +9,24 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import be.digitalia.fosdem.R;
|
||||
import be.digitalia.fosdem.activities.EventDetailsActivity;
|
||||
import be.digitalia.fosdem.activities.MainActivity;
|
||||
import be.digitalia.fosdem.activities.RoomImageDialogActivity;
|
||||
import be.digitalia.fosdem.db.DatabaseManager;
|
||||
import be.digitalia.fosdem.fragments.SettingsFragment;
|
||||
import be.digitalia.fosdem.model.Event;
|
||||
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.
|
||||
|
@ -140,7 +146,7 @@ public class AlarmIntentService extends IntentService {
|
|||
|
||||
String personsSummary = event.getPersonsSummary();
|
||||
String trackName = event.getTrack().getName();
|
||||
String bigText;
|
||||
CharSequence bigText;
|
||||
String contentText;
|
||||
if (TextUtils.isEmpty(personsSummary)) {
|
||||
contentText = trackName;
|
||||
|
@ -151,16 +157,31 @@ public class AlarmIntentService extends IntentService {
|
|||
if (TextUtils.isEmpty(subTitle)) {
|
||||
bigText = personsSummary;
|
||||
} 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())
|
||||
.setContentTitle(event.getTitle()).setContentText(contentText)
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
|
||||
.setWhen(event.getStartTime().getTime()).setContentTitle(event.getTitle()).setContentText(contentText)
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(trackName)).setContentInfo(event.getRoomName())
|
||||
.setContentIntent(eventPendingIntent).setAutoCancel(true).setDefaults(defaultFlags).setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
.build();
|
||||
notificationManager.notify((int) eventId, notification);
|
||||
.setContentIntent(eventPendingIntent).setAutoCancel(true).setDefaults(defaultFlags).setPriority(NotificationCompat.PRIORITY_DEFAULT);
|
||||
|
||||
// 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);
|
||||
|
|
Loading…
Reference in a new issue