blob: c9c23cb87ccbc4a373cd0a5cd04cb7e45238a2f2 [file] [log] [blame]
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -05001/*
2 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
32package org.sflphone.account;
33
34import java.io.File;
35import java.util.ArrayList;
36import java.util.Arrays;
37import java.util.Comparator;
38import java.util.List;
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050039import java.util.Locale;
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050040
41import org.sflphone.R;
42import org.sflphone.model.Account;
43
44import android.app.Activity;
45import android.app.AlertDialog;
46import android.app.DialogFragment;
47import android.os.Bundle;
48import android.os.Environment;
49import android.preference.EditTextPreference;
50import android.preference.Preference;
51import android.preference.Preference.OnPreferenceChangeListener;
52import android.preference.Preference.OnPreferenceClickListener;
53import android.preference.PreferenceScreen;
54import android.util.Log;
55import android.view.LayoutInflater;
56import android.view.View;
57import android.view.View.OnClickListener;
58import android.view.ViewGroup;
59import android.widget.AdapterView;
60import android.widget.AdapterView.OnItemClickListener;
61import android.widget.ArrayAdapter;
62import android.widget.Button;
63import android.widget.ListView;
64import android.widget.TextView;
65
66public class TLSManager {
67 PreferenceScreen mScreen;
68 private Account mAccount;
69 static Activity mContext;
70
71 public void onCreate(Activity con, PreferenceScreen preferenceScreen, Account acc) {
72 mContext = con;
73 mScreen = preferenceScreen;
74 mAccount = acc;
75
76 setDetails();
77 }
78
79 private void setDetails() {
80 for (int i = 0; i < mScreen.getPreferenceCount(); ++i) {
81
82 if (mScreen.getPreference(i) instanceof EditTextPreference) {
83
84 } else {
85
86 }
87
88 // ((CheckBoxPreference)
89 // mScreen.getPreference(i)).setChecked(mAccount.getSrtpDetails().getDetailBoolean(mScreen.getPreference(i).getKey()));
90 mScreen.getPreference(i).setOnPreferenceClickListener(new OnPreferenceClickListener() {
91
92 @Override
93 public boolean onPreferenceClick(Preference preference) {
94 if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)) {
95 Dialogo dialog = Dialogo.newInstance();
96 dialog.show(mContext.getFragmentManager(), "dialog");
97 } else if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE)) {
98
99 } else if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)) {
100
101 }
102 return false;
103 }
104 });
105 }
106 }
107
108 public void setTLSListener() {
109 for (int i = 0; i < mScreen.getPreferenceCount(); ++i) {
110 mScreen.getPreference(i).setOnPreferenceChangeListener(tlsListener);
111 }
112 }
113
114 private OnPreferenceChangeListener tlsListener = new OnPreferenceChangeListener() {
115
116 @Override
117 public boolean onPreferenceChange(Preference preference, Object newValue) {
118 Log.i("TLS", "Setting " + preference.getKey() + " to" + (Boolean) newValue);
119 mAccount.getTlsDetails().setDetailString(preference.getKey(), Boolean.toString((Boolean) newValue));
120 mAccount.notifyObservers();
121 return true;
122 }
123 };
124
125 public static class Dialogo extends DialogFragment implements OnItemClickListener {
126
127 /**
128 * Create a new instance of CallActionsDFragment
129 */
130 public static Dialogo newInstance() {
131 Dialogo f = new Dialogo();
132 return f;
133 }
134
135 private List<String> item = null;
136 private List<String> path = null;
137 private String root;
138 private TextView myPath;
139
140 private String currentPath;
141 Comparator<? super File> comparator;
142
143 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
144 super.onCreateView(inflater, container, savedInstanceState);
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500145 View rootView = inflater.inflate(R.layout.file_explorer_dfrag, container);
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -0500146 myPath = (TextView) rootView.findViewById(R.id.path);
147
148 comparator = filecomparatorByAlphabetically;
149 root = Environment.getExternalStorageDirectory().getPath();
150 getDir(root, rootView);
151
152 Button btnAlphabetically = (Button) rootView.findViewById(R.id.button_alphabetically);
153 btnAlphabetically.setOnClickListener(new OnClickListener() {
154
155 @Override
156 public void onClick(View arg0) {
157 comparator = filecomparatorByAlphabetically;
158 getDir(currentPath, getView());
159
160 }
161 });
162
163 Button btnLastDateModified = (Button) rootView.findViewById(R.id.button_lastDateModified);
164 btnLastDateModified.setOnClickListener(new OnClickListener() {
165
166 @Override
167 public void onClick(View arg0) {
168 comparator = filecomparatorByLastModified;
169 getDir(currentPath, getView());
170
171 }
172 });
173 return rootView;
174 }
175
176 private void getDir(String dirPath, View parent) {
177 currentPath = dirPath;
178
179 myPath.setText("Location: " + dirPath);
180 item = new ArrayList<String>();
181 path = new ArrayList<String>();
182 File f = new File(dirPath);
183 File[] files = f.listFiles();
184
185 if (!dirPath.equals(root)) {
186 item.add(root);
187 path.add(root);
188 item.add("../");
189 path.add(f.getParent());
190 }
191
192 Arrays.sort(files, comparator);
193
194 for (int i = 0; i < files.length; i++) {
195 File file = files[i];
196
197 if (!file.isHidden() && file.canRead()) {
198 path.add(file.getPath());
199 if (file.isDirectory()) {
200 item.add(file.getName() + "/");
201 } else {
202 item.add(file.getName());
203 }
204 }
205 }
206
207 ArrayAdapter<String> fileList = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1, item);
208
209 ((ListView) parent.findViewById(android.R.id.list)).setAdapter(fileList);
210 ((ListView) parent.findViewById(android.R.id.list)).setOnItemClickListener(this);
211 }
212
213 Comparator<? super File> filecomparatorByLastModified = new Comparator<File>() {
214
215 public int compare(File file1, File file2) {
216
217 if (file1.isDirectory()) {
218 if (file2.isDirectory()) {
219 return Long.valueOf(file1.lastModified()).compareTo(file2.lastModified());
220 } else {
221 return -1;
222 }
223 } else {
224 if (file2.isDirectory()) {
225 return 1;
226 } else {
227 return Long.valueOf(file1.lastModified()).compareTo(file2.lastModified());
228 }
229 }
230
231 }
232 };
233
234 Comparator<? super File> filecomparatorByAlphabetically = new Comparator<File>() {
235
236 public int compare(File file1, File file2) {
237
238 if (file1.isDirectory()) {
239 if (file2.isDirectory()) {
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500240 return String.valueOf(file1.getName().toLowerCase(Locale.getDefault())).compareTo(file2.getName().toLowerCase());
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -0500241 } else {
242 return -1;
243 }
244 } else {
245 if (file2.isDirectory()) {
246 return 1;
247 } else {
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500248 return String.valueOf(file1.getName().toLowerCase(Locale.getDefault())).compareTo(file2.getName().toLowerCase());
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -0500249 }
250 }
251
252 }
253 };
254
255 @Override
256 public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
257
258 // TODO Auto-generated method stub
259 File file = new File(path.get(position));
260
261 if (file.isDirectory()) {
262 if (file.canRead()) {
263 getDir(path.get(position), getView());
264 } else {
265 new AlertDialog.Builder(mContext).setIcon(R.drawable.ic_launcher).setTitle("[" + file.getName() + "] folder can't be read!")
266 .setPositiveButton("OK", null).show();
267 }
268 } else {
269 new AlertDialog.Builder(mContext).setIcon(R.drawable.ic_launcher).setTitle("[" + file.getName() + "]").setPositiveButton("OK", null)
270 .show();
271
272 }
273 }
274
275 }
276}