-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionaryChildFragment.java
More file actions
211 lines (166 loc) · 6.17 KB
/
Copy pathdictionaryChildFragment.java
File metadata and controls
211 lines (166 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package com.example.Fazlay_Rabbi.banglaSignLanguage;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.example.Fazlay_Rabbi.camerawork_signlanguage.R;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
/**
* Created by Fazlay_Rabbi on 11/14/2017.
*/
public class dictionaryChildFragment extends Fragment
{
ListView dictionaryListView;
TextView wordName;
ArrayList<Content> listOfSystemDefinedContent;
@Override
public void onCreate(Bundle savedData) {
super.onCreate(savedData);
listOfSystemDefinedContent = getContent("/MyDataSet/systemContent","/systemContentMapper.txt");
ArrayList<Content> listOfUserDefinedContent = getContent("/MyDataSet","/mapper.txt");
listOfSystemDefinedContent.addAll(listOfUserDefinedContent);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.dictionary_child_fragment_1, container, false);
dictionaryListView = v.findViewById(R.id.dictionaryListView);
wordName = v.findViewById(R.id.wordName);
dictionaryListView.setAdapter(new ListAdapter1(getActivity(), listOfSystemDefinedContent));
dictionaryListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
{
int itemposition =position;
Content content = (Content) dictionaryListView.getItemAtPosition(position);
wordName.setText(content.getGestureMeaning());
}
});
return v;
}
private ArrayList<Content> getContent(String directory, String mapperFileName)
{
HashMap<String, String> gestureAndWordMapper = getMapperOfGesturefileAndWord(directory,mapperFileName);
ArrayList<Content> listOfContent = new ArrayList<Content>();
Content content;
File path =new File(Environment.getExternalStorageDirectory() + directory);
for ( String key : gestureAndWordMapper.keySet() )
{
String filename = key+".jpg";
File file = new File(path, filename);
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
content = new Content();
content.setGestureImage(bitmap);
String meaning= gestureAndWordMapper.get(key);
content.setGestureMeaning(meaning);
listOfContent.add(content);
}
return listOfContent;
}
private HashMap<String, String> getMapperOfGesturefileAndWord(String directory,String fileName)
{
HashMap<String, String> gestureAndWordMapper = new HashMap<String, String>();
Scanner scanner = null;
try
{
String storeFolderName = Environment.getExternalStorageDirectory() + directory;
scanner = new Scanner(new File(storeFolderName+fileName));
}
catch (FileNotFoundException e){}
scanner.useDelimiter(",");
while(scanner.hasNext())
{
String imageFileName = scanner.next();
String word = scanner.next();
gestureAndWordMapper.put(imageFileName,word);
}
scanner.close();
return gestureAndWordMapper;
}
public static dictionaryChildFragment newInstance(String text)
{
dictionaryChildFragment f = new dictionaryChildFragment();
Bundle b = new Bundle();
b.putString("msg", text);
f.setArguments(b);
return f;
}
}
class Content
{
private Bitmap gestureImage;
private String gestureMeaning;
public Bitmap getGestureImage() {
return gestureImage;
}
public String getGestureMeaning() {
return gestureMeaning;
}
public void setGestureImage(Bitmap gestureImage) {
this.gestureImage = gestureImage;
}
public void setGestureMeaning(String gestureMeaning) {
this.gestureMeaning = gestureMeaning;
}
}
class ListAdapter1 extends BaseAdapter
{
private static ArrayList<Content> contentList;
private LayoutInflater mInflater;
public ListAdapter1(Context photosFragment, ArrayList<Content> results){
contentList = results;
mInflater = LayoutInflater.from(photosFragment);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return contentList.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return contentList.get(arg0);
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
public View getView(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView == null){
convertView = mInflater.inflate(R.layout.dictionary_child_fragment_1_listcontent, null);
holder = new ViewHolder();
holder.gestureImage = (ImageView) convertView.findViewById(R.id.gestureImage);
holder.gestureMeaning = (TextView) convertView.findViewById(R.id.gestureMeaning);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.gestureMeaning.setText(contentList.get(position).getGestureMeaning());
holder.gestureImage.setImageBitmap(contentList.get(position).getGestureImage());
return convertView;
}
static class ViewHolder{
TextView gestureMeaning;
ImageView gestureImage;
}
}