Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / components / devtools_bridge / android / java / src / org / chromium / components / devtools_bridge / ui / ServiceUIFactory.java
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.components.devtools_bridge.ui;
6
7 import android.app.Notification;
8 import android.app.PendingIntent;
9 import android.app.Service;
10 import android.content.Intent;
11
12 /**
13  * UI factory for DevToolsBridgeServer.
14  */
15 public abstract class ServiceUIFactory {
16     public Notification newForegroundNotification(Service host, String disconnectAction) {
17         // TODO(serya): move strings to a string grid.
18
19         Intent disconnectIntent = new Intent(host, host.getClass());
20         disconnectIntent.setAction(disconnectAction);
21         PendingIntent disconnectPendingIntent =
22                 PendingIntent.getService(host, 0, disconnectIntent, 0);
23
24         Notification.Builder builder = new Notification.Builder(host)
25                 // Mandatory fields
26                 .setSmallIcon(notificationSmallIcon())
27                 .setContentTitle(productName())
28                 .setContentText("Remote debugger connected")
29
30                 // Optional
31                 .addAction(android.R.drawable.ic_delete,
32                         "Disconnect", disconnectPendingIntent)
33                 .setOngoing(true)
34                 .setWhen(System.currentTimeMillis());
35
36         setupContentIntent(builder);
37         return builder.build();
38     }
39
40     protected abstract String productName();
41     protected abstract int notificationSmallIcon();
42     protected void setupContentIntent(Notification.Builder builder) {}
43 }