Skip to content

Commit 1e14ba2

Browse files
author
Paul Ruiz
committed
added android auto messenger app
1 parent eed790e commit 1e14ba2

File tree

27 files changed

+598
-0
lines changed

27 files changed

+598
-0
lines changed

AndroidAutoMessenger/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.gradle
2+
/local.properties
3+
/.idea/workspace.xml
4+
/.idea/libraries
5+
.DS_Store
6+
/build

AndroidAutoMessenger/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

AndroidAutoMessenger/app/build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 21
5+
buildToolsVersion "21.1.2"
6+
7+
defaultConfig {
8+
applicationId "com.ptrprograms.androidautomessenger"
9+
minSdkVersion 21
10+
targetSdkVersion 21
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
compile 'com.android.support:support-v4:21.0.+'
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/paulruiz/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ptrprograms.androidautomessenger;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.ptrprograms.androidautomessenger" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@drawable/ic_launcher"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme" >
10+
11+
<meta-data android:name="com.google.android.gms.car.application"
12+
android:resource="@xml/automotive_app_desc" />
13+
14+
15+
<receiver android:name="com.ptrprograms.androidautomessenger.AutoMessageReadReceiver"
16+
android:exported="false">
17+
<intent-filter>
18+
<action android:name="com.ptrprograms.androidautomessenger.ACTION_MESSAGE_READ"/>
19+
</intent-filter>
20+
</receiver>
21+
22+
<receiver android:name="com.ptrprograms.androidautomessenger.AutoMessageReplyReceiver"
23+
android:exported="false">
24+
<intent-filter>
25+
<action android:name="com.ptrprograms.androidautomessenger.ACTION_MESSAGE_REPLY"/>
26+
</intent-filter>
27+
</receiver>
28+
29+
<activity
30+
android:name=".MainActivity"
31+
android:label="@string/app_name" >
32+
<intent-filter>
33+
<action android:name="android.intent.action.MAIN" />
34+
35+
<category android:name="android.intent.category.LAUNCHER" />
36+
</intent-filter>
37+
</activity>
38+
39+
</application>
40+
41+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.ptrprograms.androidautomessenger;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.support.v4.app.NotificationManagerCompat;
7+
import android.util.Log;
8+
9+
/**
10+
* Created by paulruiz on 2/18/15.
11+
*/
12+
public class AutoMessageReadReceiver extends BroadcastReceiver {
13+
@Override
14+
public void onReceive(Context context, Intent intent) {
15+
int conversationId = intent.getIntExtra(MainActivity.MESSAGE_CONVERSATION_ID_KEY, -1);
16+
Log.d( "Message", "id: " + conversationId );
17+
NotificationManagerCompat.from( context ).cancel( conversationId );
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.ptrprograms.androidautomessenger;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.os.Bundle;
7+
import android.support.v4.app.NotificationManagerCompat;
8+
import android.support.v4.app.RemoteInput;
9+
import android.util.Log;
10+
import android.widget.Toast;
11+
12+
/**
13+
* Created by paulruiz on 2/19/15.
14+
*/
15+
public class AutoMessageReplyReceiver extends BroadcastReceiver {
16+
@Override
17+
public void onReceive(Context context, Intent intent) {
18+
Toast.makeText( context, "Message Received", Toast.LENGTH_LONG ).show();
19+
20+
int conversationId = intent.getIntExtra( MainActivity.MESSAGE_CONVERSATION_ID_KEY, -1 );
21+
Log.d( "Message", "id: " + conversationId );
22+
NotificationManagerCompat.from(context).cancel( conversationId );
23+
24+
String message = getMessageFromIntent( intent );
25+
}
26+
27+
private String getMessageFromIntent( Intent intent ) {
28+
//Note that Android Auto does not currently allow voice responses in their simulator
29+
Bundle remoteInput = RemoteInput.getResultsFromIntent( intent );
30+
if( remoteInput != null && remoteInput.containsKey( "extra_voice_reply" ) ) {
31+
return remoteInput.getCharSequence( "extra_voice_reply" ).toString();
32+
}
33+
34+
return null;
35+
}
36+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.ptrprograms.androidautomessenger;
2+
3+
import android.app.Activity;
4+
import android.app.PendingIntent;
5+
import android.content.Intent;
6+
import android.graphics.BitmapFactory;
7+
import android.os.Bundle;
8+
import android.support.v4.app.NotificationCompat;
9+
import android.support.v4.app.NotificationManagerCompat;
10+
import android.support.v4.app.RemoteInput;
11+
12+
import java.util.Calendar;
13+
14+
15+
public class MainActivity extends Activity {
16+
17+
private static final String MESSAGE_READ_ACTION = "com.ptrprograms.androidautomessenger.ACTION_MESSAGE_READ";
18+
private static final String MESSAGE_REPLY_ACTION = "com.ptrprograms.androidautomessenger.ACTION_MESSAGE_REPLY";
19+
public static final String MESSAGE_CONVERSATION_ID_KEY = "conversaton_key";
20+
public static final String VOICE_REPLY_KEY = "voice_reply_key";
21+
private static final String UNREAD_CONVERSATION_BUILDER_NAME = "Android Auto Messenger Demo";
22+
23+
@Override
24+
protected void onCreate(Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
setContentView( R.layout.activity_main );
27+
28+
NotificationCompat.Builder notificationBuilder =
29+
new NotificationCompat.Builder( getApplicationContext() )
30+
.setSmallIcon( R.drawable.ic_launcher )
31+
.setLargeIcon( BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher ) )
32+
.setContentText( "content text" )
33+
.setWhen( Calendar.getInstance().get( Calendar.SECOND ) )
34+
.setContentTitle( "content title" );
35+
36+
notificationBuilder.extend( new NotificationCompat.CarExtender()
37+
.setUnreadConversation( getUnreadConversation() ) )
38+
.setColor(getResources().getColor( android.R.color.holo_blue_bright ) );
39+
40+
NotificationManagerCompat.from( this ).notify( 1, notificationBuilder.build() );
41+
}
42+
43+
private Intent getMessageReadIntent() {
44+
return new Intent()
45+
.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
46+
.setAction(MESSAGE_READ_ACTION)
47+
.putExtra(MESSAGE_CONVERSATION_ID_KEY, 1);
48+
}
49+
50+
private PendingIntent getMessageReadPendingIntent() {
51+
return PendingIntent.getBroadcast( getApplicationContext(),
52+
1,
53+
getMessageReadIntent(),
54+
PendingIntent.FLAG_UPDATE_CURRENT );
55+
}
56+
57+
private Intent getMessageReplyIntent() {
58+
return new Intent()
59+
.addFlags( Intent.FLAG_INCLUDE_STOPPED_PACKAGES )
60+
.setAction( MESSAGE_REPLY_ACTION )
61+
.putExtra( MESSAGE_CONVERSATION_ID_KEY, 1 );
62+
}
63+
64+
private PendingIntent getMessageReplyPendingIntent() {
65+
return PendingIntent.getBroadcast( getApplicationContext(),
66+
1,
67+
getMessageReplyIntent(),
68+
PendingIntent.FLAG_UPDATE_CURRENT );
69+
}
70+
71+
private RemoteInput getVoiceReplyRemoteInput() {
72+
return new RemoteInput.Builder( VOICE_REPLY_KEY )
73+
.setLabel( "Reply" )
74+
.build();
75+
}
76+
77+
private NotificationCompat.CarExtender.UnreadConversation getUnreadConversation() {
78+
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder =
79+
new NotificationCompat.CarExtender.UnreadConversation.Builder( UNREAD_CONVERSATION_BUILDER_NAME );
80+
81+
82+
unreadConversationBuilder.setReadPendingIntent( getMessageReadPendingIntent() );
83+
unreadConversationBuilder.setReplyAction( getMessageReplyPendingIntent(), getVoiceReplyRemoteInput() );
84+
unreadConversationBuilder.addMessage( "Okay I'm home now. Give me a buzz when you get in. I'll be here pretty much all night. Bye.");
85+
unreadConversationBuilder.addMessage( "Hey Steven. Quick question, give me a call when you get a chance." );
86+
unreadConversationBuilder.addMessage( "Hey man. It's me again. I was just taking a whizz. Thought you might have called. Okay, later." );
87+
unreadConversationBuilder.addMessage( "Sorry, I had call waiting, didn't get to it, thought it might have been you. All right, bye." );
88+
unreadConversationBuilder.addMessage( "We're having ourselves quite a little game of phone tag here. You're it!" );
89+
unreadConversationBuilder.addMessage( "I was just blow drying my hair, thought I heard the phone ring. Ah... has that ever happened to you? Anyway... call me, we'll talk about it." );
90+
unreadConversationBuilder.addMessage( "you're a tough man to reach." );
91+
unreadConversationBuilder.addMessage( "I guess you're too busy to call your friends." )
92+
.setLatestTimestamp(Calendar.getInstance().get( Calendar.SECOND ) );
93+
94+
return unreadConversationBuilder.build();
95+
}
96+
}
Loading
Loading
Loading
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
3+
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
4+
android:paddingRight="@dimen/activity_horizontal_margin"
5+
android:paddingTop="@dimen/activity_vertical_margin"
6+
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
7+
8+
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
9+
android:layout_height="wrap_content" />
10+
11+
</RelativeLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<style name="AppTheme" parent="android:Theme.Material.Light">
4+
</style>
5+
</resources>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
3+
(such as screen margins) for screens with more than 820dp of available width. This
4+
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
5+
<dimen name="activity_horizontal_margin">64dp</dimen>
6+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
<!-- Default screen margins, per the Android Design guidelines. -->
3+
<dimen name="activity_horizontal_margin">16dp</dimen>
4+
<dimen name="activity_vertical_margin">16dp</dimen>
5+
</resources>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">Android Auto Messenger</string>
5+
<string name="hello_world">Android Auto Messenger Demo - This activity generates a notification
6+
for the Android Auto message console messenger</string>
7+
8+
</resources>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
5+
<!-- Customize your theme here. -->
6+
</style>
7+
8+
</resources>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<automotiveApp>
2+
<uses name="notification"/>
3+
</automotiveApp>

AndroidAutoMessenger/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:1.0.0'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
jcenter()
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE (e.g. Android Studio) users:
4+
# Gradle settings configured through the IDE *will override*
5+
# any settings specified in this file.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
# Default value: -Xmx10248m -XX:MaxPermSize=256m
13+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14+
15+
# When configured, Gradle will run in incubating parallel mode.
16+
# This option should only be used with decoupled projects. More details, visit
17+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18+
# org.gradle.parallel=true
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Wed Apr 10 15:27:10 PDT 2013
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip

0 commit comments

Comments
 (0)