• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.android.car.obd2app;
18 
19 import java.io.PrintWriter;
20 import java.io.StringWriter;
21 import java.time.LocalDateTime;
22 import java.time.format.DateTimeFormatter;
23 
24 interface StatusNotification {
notify(String status)25     void notify(String status);
26 
notifyNoDongle()27     default void notifyNoDongle() {
28         notify("No OBD2 dongle paired. Go to Settings.");
29     }
30 
notifyPaired(String deviceAddress)31     default void notifyPaired(String deviceAddress) {
32         notify("Paired to " + deviceAddress + ". Ready to capture data.");
33     }
34 
notifyConnectionFailed()35     default void notifyConnectionFailed() {
36         notify("Unable to connect.");
37     }
38 
notifyConnected(String deviceAddress)39     default void notifyConnected(String deviceAddress) {
40         notify("Connected to " + deviceAddress + ". Starting data capture.");
41     }
42 
notifyDataCapture()43     default void notifyDataCapture() {
44         LocalDateTime now = LocalDateTime.now();
45         DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MMMM dd yyyy hh:mm:ssa");
46         notify("Successfully captured data at " + now.format(dateTimeFormatter));
47     }
48 
notifyException(Exception e)49     default void notifyException(Exception e) {
50         StringWriter stringWriter = new StringWriter(1024);
51         e.printStackTrace(new PrintWriter(stringWriter));
52         notify("Exception occurred.\n" + stringWriter.toString());
53     }
54 
notifyDisconnected()55     default void notifyDisconnected() {
56         notify("Lost connection to remote end. Will try to reconnect.");
57     }
58 }
59