Home | History | Annotate | only in /developers/build/prebuilts/gradle/ElizaChat
Up to higher level directory
NameDateSize
.google/06-Dec-2016
Application/06-Dec-2016
build.gradle06-Dec-201614
CONTRIB.md06-Dec-20161.6K
CONTRIBUTING.md06-Dec-20161.5K
gradle/06-Dec-2016
gradlew06-Dec-20165K
gradlew.bat06-Dec-20162.3K
LICENSE06-Dec-201631.5K
README.md06-Dec-20164.5K
screenshots/06-Dec-2016
settings.gradle06-Dec-201622

README.md

      1 
      2 Android ElizaChat Sample
      3 ===================================
      4 
      5 A basic sample showing how to add extensions to notifications on wearable using
      6 [NotificationCompat.WearableExtender][1] API by providing a chat experience.
      7 
      8 Introduction
      9 ------------
     10 
     11 [NotificationCompat.WearableExtender][1] API offers you a functionality to
     12  add wearable extensions to notifications like [Add the Voice Input as a Notification Action][2].
     13 
     14 This example also adds the wearable notifications as a voice input by the following code:
     15 
     16 ```java
     17 NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
     18         .setContentTitle(getString(R.string.eliza))
     19         .setContentText(mLastResponse)
     20         .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
     21         .setSmallIcon(R.drawable.bg_eliza)
     22         .setPriority(NotificationCompat.PRIORITY_MIN);
     23 
     24 Intent intent = new Intent(ACTION_RESPONSE);
     25 PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
     26         PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
     27 Notification notification = builder
     28         .extend(new NotificationCompat.WearableExtender()
     29                 .addAction(new NotificationCompat.Action.Builder(
     30                         R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent)
     31                         .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY)
     32                                 .setLabel(getString(R.string.reply))
     33                                 .build())
     34                         .build()))
     35         .build();
     36 NotificationManagerCompat.from(this).notify(0, notification);
     37 ```
     38 
     39 When you issue this notification, users can swipe to the left to see the "Reply" action button.
     40 
     41 When you receive the response, you can do it by the following code:
     42 
     43 ```java
     44 @Override
     45 public int onStartCommand(Intent intent, int flags, int startId) {
     46     if (null == intent || null == intent.getAction()) {
     47         return Service.START_STICKY;
     48     }
     49     String action = intent.getAction();
     50     if (action.equals(ACTION_RESPONSE)) {
     51         Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
     52         CharSequence replyMessage = "";
     53         if (remoteInputResults != null) {
     54             replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY);
     55         }
     56         processIncoming(replyMessage.toString());
     57     } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) {
     58         broadcastMessage(mCompleteConversation.toString());
     59     }
     60     return Service.START_STICKY;
     61 }
     62 ```
     63 
     64 [1]: https://developer.android.com/reference/android/support/v4/app/NotificationCompat.WearableExtender.html
     65 [2]: https://developer.android.com/training/wearables/notifications/voice-input.html#AddAction
     66 
     67 Pre-requisites
     68 --------------
     69 
     70 - Android SDK 24
     71 - Android Build Tools v24.0.2
     72 - Android Support Repository
     73 
     74 Screenshots
     75 -------------
     76 
     77 <img src="screenshots/companion_eliza_chat_response.png" height="400" alt="Screenshot"/> <img src="screenshots/companion_eliza_chat.png" height="400" alt="Screenshot"/> <img src="screenshots/wearable_eliza_notification.png" height="400" alt="Screenshot"/> <img src="screenshots/wearable_voice_reply.png" height="400" alt="Screenshot"/> 
     78 
     79 Getting Started
     80 ---------------
     81 
     82 This sample uses the Gradle build system. To build this project, use the
     83 "gradlew build" command or use "Import Project" in Android Studio.
     84 
     85 Support
     86 -------
     87 
     88 - Google+ Community: https://plus.google.com/communities/105153134372062985968
     89 - Stack Overflow: http://stackoverflow.com/questions/tagged/android
     90 
     91 If you've found an error in this sample, please file an issue:
     92 https://github.com/googlesamples/android-ElizaChat
     93 
     94 Patches are encouraged, and may be submitted by forking this project and
     95 submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
     96 
     97 License
     98 -------
     99 
    100 Copyright 2016 The Android Open Source Project, Inc.
    101 
    102 Licensed to the Apache Software Foundation (ASF) under one or more contributor
    103 license agreements.  See the NOTICE file distributed with this work for
    104 additional information regarding copyright ownership.  The ASF licenses this
    105 file to you under the Apache License, Version 2.0 (the "License"); you may not
    106 use this file except in compliance with the License.  You may obtain a copy of
    107 the License at
    108 
    109 http://www.apache.org/licenses/LICENSE-2.0
    110 
    111 Unless required by applicable law or agreed to in writing, software
    112 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    113 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    114 License for the specific language governing permissions and limitations under
    115 the License.
    116