From 95d49d216223e3431647abd79f5e376958353c95 Mon Sep 17 00:00:00 2001 From: Renato Mangini Date: Mon, 17 Nov 2014 15:14:58 -0800 Subject: Remove gearhead samples from the old location. Gearhead samples were moved from /developers/demo to developers/samples. This CL is to remove them from the old location. Change-Id: I1b8ee3f761d75767c471c11962e429c96fff4100 --- AutoMessagingDemo/app/src/main/AndroidManifest.xml | 52 ------ .../android/automessagingdemo/Conversations.java | 126 --------------- .../android/automessagingdemo/MainActivity.java | 34 ---- .../android/automessagingdemo/MessageLogger.java | 57 ------- .../automessagingdemo/MessageReadReceiver.java | 42 ----- .../automessagingdemo/MessageReplyReceiver.java | 58 ------- .../automessagingdemo/MessagingFragment.java | 170 -------------------- .../automessagingdemo/MessagingService.java | 174 --------------------- .../app/src/main/res/drawable-hdpi/ic_launcher.png | Bin 3964 -> 0 bytes .../main/res/drawable-hdpi/notification_icon.png | Bin 937 -> 0 bytes .../app/src/main/res/drawable-mdpi/ic_launcher.png | Bin 2327 -> 0 bytes .../main/res/drawable-mdpi/notification_icon.png | Bin 609 -> 0 bytes .../src/main/res/drawable-xhdpi/ic_launcher.png | Bin 5488 -> 0 bytes .../main/res/drawable-xhdpi/notification_icon.png | Bin 1233 -> 0 bytes .../main/res/drawable-xxhdpi/android_contact.png | Bin 37477 -> 0 bytes .../src/main/res/drawable-xxhdpi/ic_launcher.png | Bin 9578 -> 0 bytes .../main/res/drawable-xxhdpi/notification_icon.png | Bin 1973 -> 0 bytes .../main/res/layout-land/fragment_message_me.xml | 67 -------- .../app/src/main/res/layout/activity_main.xml | 22 --- .../src/main/res/layout/fragment_message_me.xml | 58 ------- .../app/src/main/res/values-v21/styles.xml | 22 --- .../app/src/main/res/values/colors.xml | 20 --- .../app/src/main/res/values/dimens.xml | 21 --- .../app/src/main/res/values/strings.xml | 26 --- .../app/src/main/res/values/styles.xml | 20 --- .../app/src/main/res/xml/automotive_app_desc.xml | 19 --- 26 files changed, 988 deletions(-) delete mode 100644 AutoMessagingDemo/app/src/main/AndroidManifest.xml delete mode 100644 AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/Conversations.java delete mode 100644 AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MainActivity.java delete mode 100644 AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageLogger.java delete mode 100644 AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReadReceiver.java delete mode 100644 AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java delete mode 100644 AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessagingFragment.java delete mode 100644 AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessagingService.java delete mode 100644 AutoMessagingDemo/app/src/main/res/drawable-hdpi/ic_launcher.png delete mode 100644 AutoMessagingDemo/app/src/main/res/drawable-hdpi/notification_icon.png delete mode 100644 AutoMessagingDemo/app/src/main/res/drawable-mdpi/ic_launcher.png delete mode 100644 AutoMessagingDemo/app/src/main/res/drawable-mdpi/notification_icon.png delete mode 100644 AutoMessagingDemo/app/src/main/res/drawable-xhdpi/ic_launcher.png delete mode 100644 AutoMessagingDemo/app/src/main/res/drawable-xhdpi/notification_icon.png delete mode 100644 AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/android_contact.png delete mode 100644 AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/ic_launcher.png delete mode 100644 AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/notification_icon.png delete mode 100644 AutoMessagingDemo/app/src/main/res/layout-land/fragment_message_me.xml delete mode 100644 AutoMessagingDemo/app/src/main/res/layout/activity_main.xml delete mode 100644 AutoMessagingDemo/app/src/main/res/layout/fragment_message_me.xml delete mode 100644 AutoMessagingDemo/app/src/main/res/values-v21/styles.xml delete mode 100644 AutoMessagingDemo/app/src/main/res/values/colors.xml delete mode 100644 AutoMessagingDemo/app/src/main/res/values/dimens.xml delete mode 100644 AutoMessagingDemo/app/src/main/res/values/strings.xml delete mode 100644 AutoMessagingDemo/app/src/main/res/values/styles.xml delete mode 100644 AutoMessagingDemo/app/src/main/res/xml/automotive_app_desc.xml (limited to 'AutoMessagingDemo/app/src') diff --git a/AutoMessagingDemo/app/src/main/AndroidManifest.xml b/AutoMessagingDemo/app/src/main/AndroidManifest.xml deleted file mode 100644 index b0b6f60..0000000 --- a/AutoMessagingDemo/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/Conversations.java b/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/Conversations.java deleted file mode 100644 index d92beec..0000000 --- a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/Conversations.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.automessagingdemo; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ThreadLocalRandom; - -/** - * A simple class that denotes unread conversations and messages. In a real world application, - * this would be replaced by a content provider that actually gets the unread messages to be - * shown to the user. - */ -public class Conversations { - - /** - * Set of strings used as messages by the sample. - */ - private static final String[] MESSAGES = new String[]{ - "Are you at home?", - "Can you give me a call?", - "Hey yt?", - "Don't forget to get some milk on your way back home", - "Is that project done?", - "Did you finish the Messaging app yet?" - }; - - /** - * Senders of the said messages. - */ - private static final String[] PARTICIPANTS = new String[]{ - "John Rambo", - "Han Solo", - "Rocky Balboa", - "Lara Croft" - }; - - static class Conversation { - - private final int conversationId; - - private final String participantName; - - /** - * A given conversation can have a single or multiple messages. - * Note that the messages are sorted from *newest* to *oldest* - */ - private final List messages; - - private final long timestamp; - - public Conversation(int conversationId, String participantName, - List messages) { - this.conversationId = conversationId; - this.participantName = participantName; - this.messages = messages == null ? Collections.emptyList() : messages; - this.timestamp = System.currentTimeMillis(); - } - - public int getConversationId() { - return conversationId; - } - - public String getParticipantName() { - return participantName; - } - - public List getMessages() { - return messages; - } - - public long getTimestamp() { - return timestamp; - } - - public String toString() { - return "[Conversation: conversationId=" + conversationId + - ", participantName=" + participantName + - ", messages=" + messages + - ", timestamp=" + timestamp + "]"; - } - } - - private Conversations() { - } - - public static Conversation[] getUnreadConversations(int howManyConversations, - int messagesPerConversation) { - Conversation[] conversations = new Conversation[howManyConversations]; - for (int i = 0; i < howManyConversations; i++) { - conversations[i] = new Conversation( - ThreadLocalRandom.current().nextInt(), - name(), makeMessages(messagesPerConversation)); - } - return conversations; - } - - private static List makeMessages(int messagesPerConversation) { - int maxLen = MESSAGES.length; - List messages = new ArrayList<>(messagesPerConversation); - for (int i = 0; i < messagesPerConversation; i++) { - messages.add(MESSAGES[ThreadLocalRandom.current().nextInt(0, maxLen)]); - } - return messages; - } - - private static String name() { - return PARTICIPANTS[ThreadLocalRandom.current().nextInt(0, PARTICIPANTS.length)]; - } -} diff --git a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MainActivity.java b/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MainActivity.java deleted file mode 100644 index 7236c2c..0000000 --- a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MainActivity.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.automessagingdemo; - -import android.app.Activity; -import android.os.Bundle; - -public class MainActivity extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - if (savedInstanceState == null) { - getFragmentManager().beginTransaction() - .add(R.id.container, new MessagingFragment()) - .commit(); - } - } -} diff --git a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageLogger.java b/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageLogger.java deleted file mode 100644 index e899a71..0000000 --- a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageLogger.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.automessagingdemo; - -import android.content.Context; -import android.content.SharedPreferences; - -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * A simple logger that uses shared preferences to log messages, their reads - * and replies. Don't use this in a real world application. This logger is only - * used for displaying the messages in the text view. - */ -public class MessageLogger { - - private static final String PREF_MESSAGE = "MESSAGE_LOGGER"; - private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - public static final String LOG_KEY = "message_data"; - public static final String LINE_BREAKS = "\n\n"; - - public static void logMessage(Context context, String message) { - SharedPreferences prefs = getPrefs(context); - message = DATE_FORMAT.format(new Date(System.currentTimeMillis())) + ": " + message; - prefs.edit() - .putString(LOG_KEY, prefs.getString(LOG_KEY, "") + LINE_BREAKS + message) - .apply(); - } - - public static SharedPreferences getPrefs(Context context) { - return context.getSharedPreferences(PREF_MESSAGE, Context.MODE_PRIVATE); - } - - public static String getAllMessages(Context context) { - return getPrefs(context).getString(LOG_KEY, ""); - } - - public static void clear(Context context) { - getPrefs(context).edit().remove(LOG_KEY).apply(); - } -} diff --git a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReadReceiver.java b/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReadReceiver.java deleted file mode 100644 index 1351ffc..0000000 --- a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReadReceiver.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.automessagingdemo; - -import android.app.NotificationManager; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.support.v4.app.NotificationManagerCompat; -import android.util.Log; - -public class MessageReadReceiver extends BroadcastReceiver { - private static final String TAG = MessageReadReceiver.class.getSimpleName(); - - private static final String CONVERSATION_ID = "conversation_id"; - - @Override - public void onReceive(Context context, Intent intent) { - Log.d(TAG, "onReceive"); - int conversationId = intent.getIntExtra(CONVERSATION_ID, -1); - if (conversationId != -1) { - Log.d(TAG, "Conversation " + conversationId + " was read"); - MessageLogger.logMessage(context, "Conversation " + conversationId + " was read."); - NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); - notificationManager.cancel(conversationId); - } - } -} diff --git a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java b/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java deleted file mode 100644 index c9087d2..0000000 --- a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.automessagingdemo; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.support.v4.app.RemoteInput; -import android.util.Log; - -/** - * A receiver that gets called when a reply is sent to a given conversationId - */ -public class MessageReplyReceiver extends BroadcastReceiver { - - private static final String TAG = MessageReplyReceiver.class.getSimpleName(); - - @Override - public void onReceive(Context context, Intent intent) { - if (MessagingService.REPLY_ACTION.equals(intent.getAction())) { - int conversationId = intent.getIntExtra(MessagingService.CONVERSATION_ID, -1); - CharSequence reply = getMessageText(intent); - if (conversationId != -1) { - Log.d(TAG, "Got reply (" + reply + ") for ConversationId " + conversationId); - MessageLogger.logMessage(context, "ConversationId: " + conversationId + - " received a reply: [" + reply + "]"); - } - } - } - - /** - * Get the message text from the intent. - * Note that you should call {@code RemoteInput#getResultsFromIntent(intent)} to process - * the RemoteInput. - */ - private CharSequence getMessageText(Intent intent) { - Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); - if (remoteInput != null) { - return remoteInput.getCharSequence(MessagingService.EXTRA_VOICE_REPLY); - } - return null; - } -} diff --git a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessagingFragment.java b/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessagingFragment.java deleted file mode 100644 index 2fe75c6..0000000 --- a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessagingFragment.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.automessagingdemo; - -import android.app.Fragment; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.os.IBinder; -import android.os.Message; -import android.os.Messenger; -import android.os.RemoteException; -import android.text.method.ScrollingMovementMethod; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.TextView; - -/** - * The main fragment that shows the buttons and the text view containing the log. - */ -public class MessagingFragment extends Fragment implements View.OnClickListener { - - private static final String TAG = MessagingFragment.class.getSimpleName(); - - private Button mSendSingleConversation; - private Button mSendTwoConversations; - private Button mSendConversationWithThreeMessages; - private TextView mDataPortView; - private Button mClearLogButton; - - private Messenger mService; - private boolean mBound; - - private ServiceConnection mConnection = new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName componentName, IBinder service) { - mService = new Messenger(service); - mBound = true; - setButtonsState(true); - } - - @Override - public void onServiceDisconnected(ComponentName componentName) { - mService = null; - mBound = false; - setButtonsState(false); - } - }; - - private SharedPreferences.OnSharedPreferenceChangeListener listener = - new SharedPreferences.OnSharedPreferenceChangeListener() { - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (MessageLogger.LOG_KEY.equals(key)) { - mDataPortView.setText(MessageLogger.getAllMessages(getActivity())); - } - } - }; - - public MessagingFragment() { - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_message_me, container, false); - - mSendSingleConversation = (Button) rootView.findViewById(R.id.send_1_conversation); - mSendSingleConversation.setOnClickListener(this); - - mSendTwoConversations = (Button) rootView.findViewById(R.id.send_2_conversations); - mSendTwoConversations.setOnClickListener(this); - - mSendConversationWithThreeMessages = - (Button) rootView.findViewById(R.id.send_1_conversation_3_messages); - mSendConversationWithThreeMessages.setOnClickListener(this); - - mDataPortView = (TextView) rootView.findViewById(R.id.data_port); - mDataPortView.setMovementMethod(new ScrollingMovementMethod()); - - mClearLogButton = (Button) rootView.findViewById(R.id.clear); - mClearLogButton.setOnClickListener(this); - - setButtonsState(false); - - return rootView; - } - - @Override - public void onClick(View view) { - if (view == mSendSingleConversation) { - sendMsg(1, 1); - } else if (view == mSendTwoConversations) { - sendMsg(2, 1); - } else if (view == mSendConversationWithThreeMessages) { - sendMsg(1, 3); - } else if (view == mClearLogButton) { - MessageLogger.clear(getActivity()); - mDataPortView.setText(MessageLogger.getAllMessages(getActivity())); - } - } - - @Override - public void onStart() { - super.onStart(); - getActivity().bindService(new Intent(getActivity(), MessagingService.class), mConnection, - Context.BIND_AUTO_CREATE); - } - - @Override - public void onPause() { - super.onPause(); - MessageLogger.getPrefs(getActivity()).unregisterOnSharedPreferenceChangeListener(listener); - } - - @Override - public void onResume() { - super.onResume(); - mDataPortView.setText(MessageLogger.getAllMessages(getActivity())); - MessageLogger.getPrefs(getActivity()).registerOnSharedPreferenceChangeListener(listener); - } - - @Override - public void onStop() { - super.onStop(); - if (mBound) { - getActivity().unbindService(mConnection); - mBound = false; - } - } - - private void sendMsg(int howManyConversations, int messagesPerConversation) { - if (mBound) { - Message msg = Message.obtain(null, MessagingService.MSG_SEND_NOTIFICATION, - howManyConversations, messagesPerConversation); - try { - mService.send(msg); - } catch (RemoteException e) { - Log.e(TAG, "Error sending a message", e); - MessageLogger.logMessage(getActivity(), "Error occurred while sending a message."); - } - } - } - - private void setButtonsState(boolean enable) { - mSendSingleConversation.setEnabled(enable); - mSendTwoConversations.setEnabled(enable); - mSendConversationWithThreeMessages.setEnabled(enable); - } -} diff --git a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessagingService.java b/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessagingService.java deleted file mode 100644 index d702369..0000000 --- a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessagingService.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.automessagingdemo; - -import android.app.PendingIntent; -import android.app.Service; -import android.content.Intent; -import android.graphics.BitmapFactory; -import android.os.Handler; -import android.os.IBinder; -import android.os.Message; -import android.os.Messenger; -import android.preview.support.v4.app.NotificationCompat.CarExtender; -import android.preview.support.v4.app.NotificationCompat.CarExtender.UnreadConversation; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.NotificationManagerCompat; -import android.support.v4.app.RemoteInput; -import android.util.Log; - -import java.util.Iterator; - -public class MessagingService extends Service { - private static final String TAG = MessagingService.class.getSimpleName(); - - public static final String READ_ACTION = - "com.example.messaging.messagemedemo.ACTION_MESSAGE_READ"; - public static final String REPLY_ACTION = - "com.example.messaging.messagemedemo.ACTION_MESSAGE_REPLY"; - public static final String CONVERSATION_ID = "conversation_id"; - public static final String EXTRA_VOICE_REPLY = "extra_voice_reply"; - public static final int MSG_SEND_NOTIFICATION = 1; - public static final String EOL = "\n"; - - private NotificationManagerCompat mNotificationManager; - - private final Messenger mMessenger = new Messenger(new IncomingHandler()); - - /** - * Handler of incoming messages from clients. - */ - class IncomingHandler extends Handler { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_SEND_NOTIFICATION: - int howManyConversations = msg.arg1 <= 0 ? 1 : msg.arg1; - int messagesPerConv = msg.arg2 <= 0 ? 1 : msg.arg2; - sendNotification(howManyConversations, messagesPerConv); - break; - default: - super.handleMessage(msg); - } - } - } - - @Override - public void onCreate() { - Log.d(TAG, "onCreate"); - mNotificationManager = NotificationManagerCompat.from(getApplicationContext()); - } - - @Override - public IBinder onBind(Intent intent) { - Log.d(TAG, "onBind"); - return mMessenger.getBinder(); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - Log.d(TAG, "onStartCommand"); - return START_STICKY; - } - - @Override - public void onDestroy() { - super.onDestroy(); - Log.d(TAG, "onDestroy"); - } - - // Creates an intent that will be triggered when a message is marked as read. - private Intent getMessageReadIntent(int id) { - return new Intent() - .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES) - .setAction(READ_ACTION) - .putExtra(CONVERSATION_ID, id); - } - - // Creates an Intent that will be triggered when a voice reply is received. - private Intent getMessageReplyIntent(int conversationId) { - return new Intent() - .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES) - .setAction(REPLY_ACTION) - .putExtra(CONVERSATION_ID, conversationId); - } - - private void sendNotification(int howManyConversations, int messagesPerConversation) { - Conversations.Conversation[] conversations = Conversations.getUnreadConversations( - howManyConversations, messagesPerConversation); - for (Conversations.Conversation conv : conversations) { - sendNotificationForConversation(conv); - } - } - - private void sendNotificationForConversation(Conversations.Conversation conversation) { - // A pending Intent for reads - PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), - conversation.getConversationId(), - getMessageReadIntent(conversation.getConversationId()), - PendingIntent.FLAG_UPDATE_CURRENT); - - // Build a RemoteInput for receiving voice input in a Car Notification - RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) - .setLabel(getApplicationContext().getString(R.string.notification_reply)) - .build(); - - // Building a Pending Intent for the reply action to trigger - PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), - conversation.getConversationId(), - getMessageReplyIntent(conversation.getConversationId()), - PendingIntent.FLAG_UPDATE_CURRENT); - - // Create the UnreadConversation and populate it with the participant name, - // read and reply intents. - UnreadConversation.Builder unreadConvBuilder = - new UnreadConversation.Builder(conversation.getParticipantName()) - .setLatestTimestamp(conversation.getTimestamp()) - .setReadPendingIntent(readPendingIntent) - .setReplyAction(replyIntent, remoteInput); - - // Note: Add messages from oldest to newest to the UnreadConversation.Builder - StringBuilder messageForNotification = new StringBuilder(); - for (Iterator messages = conversation.getMessages().iterator(); - messages.hasNext(); ) { - String message = messages.next(); - unreadConvBuilder.addMessage(message); - messageForNotification.append(message); - if (messages.hasNext()) { - messageForNotification.append(EOL); - } - } - - NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) - .setSmallIcon(R.drawable.notification_icon) - .setLargeIcon(BitmapFactory.decodeResource( - getApplicationContext().getResources(), R.drawable.android_contact)) - .setContentText(messageForNotification.toString()) - .setWhen(conversation.getTimestamp()) - .setContentTitle(conversation.getParticipantName()) - .setContentIntent(readPendingIntent) - .extend(new CarExtender() - .setUnreadConversation(unreadConvBuilder.build()) - .setColor(getApplicationContext() - .getResources().getColor(R.color.default_color_light))); - - MessageLogger.logMessage(getApplicationContext(), "Sending notification " - + conversation.getConversationId() + " conversation: " + conversation); - - mNotificationManager.notify(conversation.getConversationId(), builder.build()); - } -} diff --git a/AutoMessagingDemo/app/src/main/res/drawable-hdpi/ic_launcher.png b/AutoMessagingDemo/app/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index 06d85f1..0000000 Binary files a/AutoMessagingDemo/app/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/AutoMessagingDemo/app/src/main/res/drawable-hdpi/notification_icon.png b/AutoMessagingDemo/app/src/main/res/drawable-hdpi/notification_icon.png deleted file mode 100644 index 9cdfca1..0000000 Binary files a/AutoMessagingDemo/app/src/main/res/drawable-hdpi/notification_icon.png and /dev/null differ diff --git a/AutoMessagingDemo/app/src/main/res/drawable-mdpi/ic_launcher.png b/AutoMessagingDemo/app/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index 4e1cc86..0000000 Binary files a/AutoMessagingDemo/app/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/AutoMessagingDemo/app/src/main/res/drawable-mdpi/notification_icon.png b/AutoMessagingDemo/app/src/main/res/drawable-mdpi/notification_icon.png deleted file mode 100644 index d6069eb..0000000 Binary files a/AutoMessagingDemo/app/src/main/res/drawable-mdpi/notification_icon.png and /dev/null differ diff --git a/AutoMessagingDemo/app/src/main/res/drawable-xhdpi/ic_launcher.png b/AutoMessagingDemo/app/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index 92f1e2d..0000000 Binary files a/AutoMessagingDemo/app/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/AutoMessagingDemo/app/src/main/res/drawable-xhdpi/notification_icon.png b/AutoMessagingDemo/app/src/main/res/drawable-xhdpi/notification_icon.png deleted file mode 100644 index 786ed17..0000000 Binary files a/AutoMessagingDemo/app/src/main/res/drawable-xhdpi/notification_icon.png and /dev/null differ diff --git a/AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/android_contact.png b/AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/android_contact.png deleted file mode 100644 index 611d565..0000000 Binary files a/AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/android_contact.png and /dev/null differ diff --git a/AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100644 index 2476cbd..0000000 Binary files a/AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/notification_icon.png b/AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/notification_icon.png deleted file mode 100644 index 005207c..0000000 Binary files a/AutoMessagingDemo/app/src/main/res/drawable-xxhdpi/notification_icon.png and /dev/null differ diff --git a/AutoMessagingDemo/app/src/main/res/layout-land/fragment_message_me.xml b/AutoMessagingDemo/app/src/main/res/layout-land/fragment_message_me.xml deleted file mode 100644 index 8f7b60a..0000000 --- a/AutoMessagingDemo/app/src/main/res/layout-land/fragment_message_me.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - -