1 |
|
package com.choibean.android.hangeulider; |
2 |
|
|
3 |
|
import java.util.Iterator; |
4 |
|
import java.util.Set; |
5 |
|
|
6 |
|
import android.app.Activity; |
7 |
|
import android.app.Notification; |
8 |
|
import android.app.NotificationManager; |
9 |
|
import android.app.PendingIntent; |
10 |
|
import android.content.ComponentName; |
11 |
|
import android.content.Context; |
12 |
|
import android.content.Intent; |
13 |
|
import android.content.SharedPreferences; |
14 |
|
import android.os.Bundle; |
15 |
|
import android.util.Log; |
16 |
|
import android.view.Display; |
17 |
|
import android.view.Menu; |
18 |
|
import android.view.MenuInflater; |
19 |
|
import android.view.MenuItem; |
20 |
|
import android.view.View; |
21 |
|
import android.view.Window; |
22 |
|
import android.view.WindowManager; |
23 |
|
import android.widget.EditText; |
24 |
|
import android.widget.ImageView; |
25 |
|
import android.widget.TextView; |
26 |
|
|
|
|
| 87,8% |
Uncovered Elements: 16 (131) |
Complexity: 32 |
Complexity Density: 0,38 |
|
27 |
|
public class Hangeulider extends Activity { |
28 |
|
|
29 |
|
protected static HangeulParser parser; |
30 |
|
protected static final int modeDubeolshik = 0; |
31 |
|
protected static final int modeKonglish = 1; |
32 |
|
protected static int inputMode = 1; |
33 |
|
protected NotificationManager mNotificationManager; |
34 |
|
protected Menu mMenu = null; |
35 |
|
private int YOURAPP_NOTIFICATION_ID = 0; |
36 |
|
|
37 |
|
private static Hangeulider mInstance; |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
39 |
7
|
public static Hangeulider getInstance() {... |
40 |
7
|
return mInstance; |
41 |
|
} |
42 |
|
|
43 |
|
|
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 3 |
Complexity Density: 0,27 |
|
44 |
1
|
@Override... |
45 |
|
public void onCreate(Bundle savedInstanceState) { |
46 |
1
|
super.onCreate(savedInstanceState); |
47 |
1
|
mInstance = this; |
48 |
1
|
Window window = getWindow(); |
49 |
1
|
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, |
50 |
|
WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
51 |
1
|
setContentView(isWide() ? R.layout.wide : R.layout.tall); |
52 |
|
|
53 |
|
|
54 |
1
|
mSaved = (EditText) findViewById(R.id.outputEdit); |
55 |
1
|
parser = new HangeulParser(this); |
56 |
1
|
setDubeolshikMode(false); |
57 |
|
|
58 |
1
|
if (savedInstanceState == null) { |
59 |
1
|
logD("State", "onCreate(null)"); |
60 |
|
} else { |
61 |
0
|
logD("State", "onCreate(**something**)"); |
62 |
|
} |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
65 |
4
|
@Override... |
66 |
|
protected void onSaveInstanceState(Bundle outState) { |
67 |
4
|
super.onSaveInstanceState(outState); |
68 |
4
|
logD("State", "onSIS: got to Child"); |
69 |
4
|
Set<String> set = outState.keySet(); |
70 |
4
|
Iterator<String> iterator = set.iterator(); |
71 |
8
|
while (iterator.hasNext()) { |
72 |
4
|
logD("State", outState.get(iterator.next()).getClass().getName()); |
73 |
|
} |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
76 |
5
|
@Override... |
77 |
|
protected void onStart() { |
78 |
5
|
super.onStart(); |
79 |
5
|
toggleNotification(true); |
80 |
5
|
logD("status", "start"); |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
83 |
5
|
@Override... |
84 |
|
protected void onResume() { |
85 |
5
|
super.onResume(); |
86 |
|
|
87 |
5
|
SharedPreferences prefs = getPreferences(0); |
88 |
5
|
String restoredText = prefs.getString("text", null); |
89 |
5
|
if (restoredText != null) { |
90 |
4
|
mSaved.setText(restoredText, TextView.BufferType.EDITABLE); |
91 |
|
} |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
94 |
5
|
@Override... |
95 |
|
protected void onPause() { |
96 |
5
|
super.onPause(); |
97 |
|
|
98 |
5
|
SharedPreferences.Editor editor = getPreferences(0).edit(); |
99 |
5
|
editor.putString("text", mSaved.getText().toString()); |
100 |
5
|
editor.commit(); |
101 |
|
} |
102 |
|
|
103 |
|
private EditText mSaved; |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0,18 |
|
105 |
6
|
protected void sendNotification(Context context) {... |
106 |
6
|
mNotificationManager = (NotificationManager) context |
107 |
|
.getSystemService(Context.NOTIFICATION_SERVICE); |
108 |
6
|
ComponentName comp = new ComponentName(context.getPackageName(), |
109 |
|
getClass().getName()); |
110 |
6
|
Intent intent = new Intent().setComponent(comp); |
111 |
6
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, |
112 |
|
intent, Intent.FLAG_ACTIVITY_NEW_TASK); |
113 |
6
|
Notification n = new Notification(R.drawable.flag, |
114 |
|
getString(R.string.app_name), System.currentTimeMillis()); |
115 |
6
|
n.setLatestEventInfo(context, getString(R.string.notification_title), |
116 |
|
getString(R.string.notification_motto), pendingIntent); |
117 |
6
|
n.flags = Notification.FLAG_ONGOING_EVENT; |
118 |
6
|
mNotificationManager.notify(YOURAPP_NOTIFICATION_ID, n); |
119 |
6
|
if (mMenu != null) { |
120 |
4
|
MenuItem notiMode = mMenu.findItem(R.id.notificationMenuItem); |
121 |
4
|
notiMode.setChecked(true); |
122 |
|
} |
123 |
|
} |
124 |
|
|
|
|
| 83,3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
125 |
1
|
protected void cancelNotification() {... |
126 |
1
|
mNotificationManager.cancel(YOURAPP_NOTIFICATION_ID); |
127 |
1
|
if (mMenu != null) { |
128 |
1
|
MenuItem notiMode = mMenu.findItem(R.id.notificationMenuItem); |
129 |
1
|
notiMode.setChecked(false); |
130 |
|
} |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
133 |
1
|
@Override... |
134 |
|
public boolean onCreateOptionsMenu(Menu menu) { |
135 |
1
|
MenuInflater inflater = getMenuInflater(); |
136 |
1
|
inflater.inflate(R.menu.main_menu, menu); |
137 |
1
|
mMenu = menu; |
138 |
1
|
return true; |
139 |
|
} |
140 |
|
|
|
|
| 85,7% |
Uncovered Elements: 2 (14) |
Complexity: 3 |
Complexity Density: 0,3 |
|
141 |
3
|
@Override... |
142 |
|
public boolean onMenuOpened(int featureId, Menu menu) { |
143 |
3
|
logD("mode", String.valueOf(getDubeolshikMode())); |
144 |
3
|
mMenu = menu; |
145 |
3
|
if (mMenu == null) { |
146 |
0
|
return false; |
147 |
|
} |
148 |
3
|
MenuItem notification = mMenu.findItem(R.id.notificationMenuItem); |
149 |
3
|
boolean nMode = notification.isChecked(); |
150 |
3
|
int iconId = nMode ? android.R.drawable.checkbox_on_background |
151 |
|
: android.R.drawable.checkbox_off_background; |
152 |
3
|
notification.setIcon(iconId); |
153 |
3
|
notification.setChecked(nMode); |
154 |
|
|
155 |
3
|
return super.onMenuOpened(featureId, menu); |
156 |
|
} |
157 |
|
|
|
|
| 93,3% |
Uncovered Elements: 1 (15) |
Complexity: 4 |
Complexity Density: 0,44 |
|
158 |
3
|
@Override... |
159 |
|
public boolean onOptionsItemSelected(MenuItem item) { |
160 |
3
|
int id = item.getItemId(); |
161 |
3
|
logD("menu ", String.valueOf(id)); |
162 |
3
|
if (id == R.id.notificationMenuItem) { |
163 |
2
|
if (item.isChecked()) { |
164 |
1
|
toggleNotification(false); |
165 |
|
} else { |
166 |
1
|
toggleNotification(true); |
167 |
|
} |
168 |
1
|
} else if (id == R.id.exitMenuItem) { |
169 |
1
|
this.finish(); |
170 |
|
} |
171 |
|
|
172 |
3
|
return false; |
173 |
|
} |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
175 |
7
|
public void toggleNotification(boolean toggle) {... |
176 |
7
|
if (toggle) { |
177 |
6
|
sendNotification(this); |
178 |
|
} else { |
179 |
1
|
cancelNotification(); |
180 |
|
} |
181 |
|
|
182 |
|
} |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
0
|
public void toggleDubeolshikMode() {... |
185 |
0
|
setDubeolshikMode(!getDubeolshikMode()); |
186 |
|
} |
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
284
|
public boolean getDubeolshikMode() {... |
189 |
|
|
190 |
284
|
return (Hangeulider.inputMode == modeDubeolshik) && isWide(); |
191 |
|
} |
192 |
|
|
|
|
| 50% |
Uncovered Elements: 7 (14) |
Complexity: 4 |
Complexity Density: 0,5 |
|
193 |
1
|
public void setDubeolshikMode(boolean dubeolshik) {... |
194 |
1
|
logD("mode", String.valueOf(dubeolshik)); |
195 |
1
|
Hangeulider.inputMode = dubeolshik ? modeDubeolshik : modeKonglish; |
196 |
1
|
ImageView dbs = (ImageView) findViewById(R.id.dbs); |
197 |
1
|
if (dbs != null) { |
198 |
0
|
if (dubeolshik) { |
199 |
0
|
dbs.setVisibility(View.VISIBLE); |
200 |
|
} else { |
201 |
0
|
dbs.setVisibility(View.INVISIBLE); |
202 |
|
} |
203 |
|
} |
204 |
1
|
parser.setModeText(); |
205 |
|
} |
206 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
207 |
2
|
public boolean isWide() {... |
208 |
2
|
Display display = getWindowManager().getDefaultDisplay(); |
209 |
2
|
return display.getWidth() > display.getHeight(); |
210 |
|
} |
211 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
212 |
460
|
public static void logD(String tag, String msg) {... |
213 |
460
|
Log.d(tag, msg); |
214 |
|
} |
215 |
|
} |