CuneiPainter  Version 1.2
CuneiPainter Class Reference

Main activity enabling the drawing of cuneiform characters. More...

Inheritance diagram for CuneiPainter:
Collaboration diagram for CuneiPainter:

Public Member Functions

boolean onCreateOptionsMenu (Menu menu)
 
boolean onOptionsItemSelected (MenuItem item)
 
boolean onKeyLongPress (int keyCode, KeyEvent event)
 
void onBackPressed ()
 

Protected Member Functions

void onCreate (Bundle savedInstanceState)
 

Package Functions

void setStatusText ()
 Sets the status text indicating the four strokes. More...
 
void lookUp ()
 Looks up corresponding characters after canvas input. More...
 

Private Member Functions

void clear ()
 Clears the canvas and resets search parameters. More...
 
String loadJSONFromAsset ()
 Loads character descriptions from the JSON set. More...
 
void jsonToMap (String t) throws JSONException
 Maps the character json representation to an internal data structure. More...
 

Private Attributes

Map< String, List< Tuple
< String, String > > > 
lookUpMap
 
TextView statusText
 
DrawingCanvas mv
 
ListView resultList
 

Detailed Description

Main activity enabling the drawing of cuneiform characters.

Member Function Documentation

void clear ( )
private

Clears the canvas and resets search parameters.

107  {
108  this.mv.a=0;
109  this.mv.b=0;
110  this.mv.c=0;
111  this.mv.d=0;
112  this.mv.s=0;
113  this.mv.down=0;
114  this.mv.up=0;
115  this.mv.left=0;
116  this.mv.right=0;
117  this.mv.paleocodage="";
118  this.resultList.setAdapter(new ResultAdapter(this,new LinkedList<Tuple<String,String>>()));
119  this.setStatusText();
120  }
void jsonToMap ( String  t) throws JSONException
private

Maps the character json representation to an internal data structure.

Parameters
tthe json string
Exceptions
JSONExceptionif the JSON file is errornous
188  {
189  System.out.println("T: "+t);
190  JSONObject jObject = new JSONObject(t);
191  Iterator<?> keys = jObject.keys();
192 
193  while( keys.hasNext() ){
194  String key = (String)keys.next();
195  String value = jObject.getString(key);
196  JSONArray jvalue = new JSONArray(value);
197  this.lookUpMap.put(key,new LinkedList<Tuple<String, String>>());
198  for (int i = 0; i < jvalue.length(); i++) {
199  JSONArray row = jvalue.getJSONArray(i);
200  this.lookUpMap.get(key).add(new Tuple<>(row.get(0).toString(),row.get(1).toString()));
201  }
202  }
203  }
String loadJSONFromAsset ( )
private

Loads character descriptions from the JSON set.

Returns
the json to be returned.
158  {
159  String json = null;
160  try {
161 
162  InputStream is = getAssets().open("strokes_gott.json");
163 
164  int size = is.available();
165 
166  byte[] buffer = new byte[size];
167 
168  is.read(buffer);
169 
170  is.close();
171 
172  json = new String(buffer, "UTF-8");
173 
174 
175  } catch (IOException ex) {
176  ex.printStackTrace();
177  return null;
178  }
179  return json;
180 
181  }
void lookUp ( )
package

Looks up corresponding characters after canvas input.

References DrawingCanvas.a, DrawingCanvas.b, DrawingCanvas.c, DrawingCanvas.d, CuneiPainter.lookUpMap, and CuneiPainter.mv.

132  {
133  StringBuilder queryStr=new StringBuilder();
134  if(this.mv.a==0 && this.mv.b==0 && this.mv.c==0 && this.mv.d==0){
135  this.resultList.setAdapter(new ResultAdapter(this,new LinkedList<Tuple<String,String>>()));
136  }else {
137  if (this.mv.a > 0) {
138  queryStr.append("a").append(this.mv.a);
139  }
140  if (this.mv.b > 0) {
141  queryStr.append("b").append(this.mv.b);
142  }
143  if (this.mv.c > 0) {
144  queryStr.append("c").append(this.mv.c);
145  }
146  if (this.mv.d > 0) {
147  queryStr.append("d").append(this.mv.d);
148  }
149  this.resultList.setAdapter(new ResultAdapter(this, this.lookUpMap.get(queryStr.toString()
150  )));
151  }
152  }
Map< String, List< Tuple< String, String > > > lookUpMap
Definition: CuneiPainter.java:24
DrawingCanvas mv
Definition: CuneiPainter.java:26
Integer b
Definition: DrawingCanvas.java:20
Integer c
Definition: DrawingCanvas.java:20
Integer a
Definition: DrawingCanvas.java:20
Integer d
Definition: DrawingCanvas.java:20
void onBackPressed ( )
99  {
100  this.mv.undoPath();
101 
102  }
void onCreate ( Bundle  savedInstanceState)
protected

References CuneiPainter.statusText.

31  {
32  super.onCreate(savedInstanceState);
33  setContentView(R.layout.main);
34  this.lookUpMap=new TreeMap<>();
35  statusText = findViewById(R.id.startView);
36  this.mv = findViewById(R.id.imageView);
37  this.resultList = findViewById(R.id.groupListView);
38  try {
39  this.jsonToMap(this.loadJSONFromAsset());
40  } catch (JSONException e) {
41  e.printStackTrace();
42  }
43  this.setStatusText();
44 
45  mv.setDrawingCacheEnabled(true);
46  }
TextView statusText
Definition: CuneiPainter.java:25
boolean onCreateOptionsMenu ( Menu  menu)
51  {
52  MenuInflater menuInflater = getMenuInflater();
53  menuInflater.inflate(R.menu.menu, menu);
54  return true;
55  }
boolean onKeyLongPress ( int  keyCode,
KeyEvent  event 
)
88  {
89  switch(keyCode){
90  case KeyEvent.KEYCODE_BACK:
91  this.mv.clearCanvas();
92  this.clear();
93  break;
94  }
95  return true;
96  }
boolean onOptionsItemSelected ( MenuItem  item)
59  {
60 
61  switch (item.getItemId())
62  {
63  case R.id.menu_exit:
64  this.finish();
65  return true;
66  case R.id.menu_about:
67 
68  final Dialog dialog = new Dialog(this); // context, this etc.
69  dialog.setContentView(R.layout.dialog);
70  dialog.setTitle("About CuneiPainter...");
71  TextView viewText = dialog.findViewById(R.id.dialog_info);
72  viewText.setText(Html.fromHtml("<html>Written by Timo Homburg<br>Licensed under GPLv3<br>Includes the Akkadian Font provided by <a href=\"http://users.teilar.gr/~g1951d/\">George Douros</a></html>"));
73  Button button=dialog.findViewById(R.id.dialog_ok);
74  button.setOnClickListener(new View.OnClickListener() {
75  @Override
76  public void onClick(final View view) {
77  dialog.cancel();
78  }
79  });
80  dialog.show();
81  break;
82 
83  }
84  return true;
85  }
void setStatusText ( )
package

Sets the status text indicating the four strokes.

125  {
126  this.statusText.setText("A: "+this.mv.a+" B: "+this.mv.b+" C: "+this.mv.c+" D: "+this.mv.d+" Strokes: "+this.mv.s+" Paleocodage: "+this.mv.paleocodage);
127  }

Member Data Documentation

Map<String,List<Tuple<String,String> > > lookUpMap
private

Referenced by CuneiPainter.lookUp().

DrawingCanvas mv
private

Referenced by CuneiPainter.lookUp().

ListView resultList
private
TextView statusText
private

Referenced by CuneiPainter.onCreate().