|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Avkon CoreUI abstract class |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.mj.impl.coreui; |
|
19 |
|
20 import java.util.Hashtable; |
|
21 |
|
22 import com.nokia.mj.impl.utils.Uid; |
|
23 |
|
24 /** |
|
25 * A factory type of class for accessing the CoreUi implementation. |
|
26 */ |
|
27 public abstract class CoreUi |
|
28 { |
|
29 private static final String PACKAGE_END_PROPERTY_NAME = "com.nokia.coreui"; |
|
30 |
|
31 private static final String PACKAGE_PREFIX = "com.nokia.mj.impl."; |
|
32 |
|
33 private static final String CORE_UI_CLASS = ".CoreUiImpl"; |
|
34 |
|
35 private static CoreUi sInstance = null; |
|
36 |
|
37 static |
|
38 { |
|
39 //Get the system proptery defining the end of package. |
|
40 String packageEnd = |
|
41 System.getProperty(PACKAGE_END_PROPERTY_NAME); |
|
42 |
|
43 if (packageEnd != null) |
|
44 { |
|
45 //Construct the class |
|
46 String className = PACKAGE_PREFIX + packageEnd + CORE_UI_CLASS; |
|
47 try |
|
48 { |
|
49 Class clazz = Class.forName(className); |
|
50 sInstance = (CoreUi)clazz.newInstance(); |
|
51 } |
|
52 catch (Exception e) |
|
53 { |
|
54 throw new RuntimeException("Not able to instantiate class " + |
|
55 className+". Reason is: " + e); |
|
56 } |
|
57 } |
|
58 } |
|
59 |
|
60 /** |
|
61 * Connects to the already created CoreUi. |
|
62 * @return permission to start the application. There is a small time |
|
63 * window where user is able to cancel the application |
|
64 * start. In this case the CoreUi stores the request and |
|
65 * informs the caller of this method that the application |
|
66 * should not be started. |
|
67 */ |
|
68 public static boolean connectToUi() |
|
69 { |
|
70 boolean canBeStarted = true; |
|
71 if (sInstance != null) |
|
72 { |
|
73 canBeStarted = sInstance.connectToUiImpl(); |
|
74 } |
|
75 return canBeStarted; |
|
76 } |
|
77 |
|
78 /** |
|
79 * For creating the UI from Java side. This is meant for the pre-warmed |
|
80 * VM use case. Calling this method will lead creation of the CoreUI. |
|
81 * @param uid The UID of the application. |
|
82 * @param backGroundStart Should the UI be put into background. |
|
83 */ |
|
84 public static void createUi(Uid uid, boolean backGroundStart) |
|
85 { |
|
86 if (sInstance != null) |
|
87 { |
|
88 sInstance.createUiImpl(uid, backGroundStart); |
|
89 } |
|
90 } |
|
91 |
|
92 /** |
|
93 * For asking the runtime to do the shutdown of the application. |
|
94 * One user for this method is the CoreUi native implementation. |
|
95 */ |
|
96 public static void shutdownRequest() |
|
97 { |
|
98 if (sInstance != null) |
|
99 { |
|
100 sInstance.shutdownRequestImpl(); |
|
101 } |
|
102 } |
|
103 |
|
104 /** |
|
105 * For asking the runtime to bring the application to foreground. |
|
106 */ |
|
107 public static void foregroundRequest() |
|
108 { |
|
109 if (sInstance != null) |
|
110 { |
|
111 sInstance.foregroundRequestImpl(); |
|
112 } |
|
113 } |
|
114 |
|
115 /** |
|
116 * For asking if the UI is in foreground. |
|
117 */ |
|
118 public static boolean isUiInForeground() |
|
119 { |
|
120 boolean fg = true; |
|
121 if (sInstance != null) |
|
122 { |
|
123 fg = sInstance.isUiInForegroundImpl(); |
|
124 } |
|
125 return fg; |
|
126 } |
|
127 |
|
128 protected abstract boolean connectToUiImpl(); |
|
129 protected abstract void createUiImpl(Uid uid, boolean backGroundStart); |
|
130 protected abstract void shutdownRequestImpl(); |
|
131 protected abstract void foregroundRequestImpl(); |
|
132 protected abstract boolean isUiInForegroundImpl(); |
|
133 } |