Merge branch 'develop' into loggingtool
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / LogHistoryActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 package com.owncloud.android.ui.activity;
20
21 import java.io.File;
22 import java.util.ArrayList;
23
24 import android.content.Intent;
25 import android.os.Bundle;
26 import android.os.Environment;
27 import android.preference.Preference;
28 import android.preference.Preference.OnPreferenceChangeListener;
29 import android.view.View;
30 import android.view.View.OnClickListener;
31 import android.widget.Button;
32 import android.widget.ListView;
33
34 import com.actionbarsherlock.app.ActionBar;
35 import com.actionbarsherlock.app.SherlockPreferenceActivity;
36 import com.actionbarsherlock.view.MenuItem;
37 import com.owncloud.android.R;
38 import com.owncloud.android.ui.adapter.LogListAdapter;
39
40
41
42 public class LogHistoryActivity extends SherlockPreferenceActivity implements OnPreferenceChangeListener {
43 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
44 File logDIR = null;
45
46 @Override
47 protected void onCreate(Bundle savedInstanceState) {
48 super.onCreate(savedInstanceState);
49
50 setContentView(R.layout.log_send_file);
51 setTitle("Log History");
52 ActionBar actionBar = getSherlock().getActionBar();
53 actionBar.setDisplayHomeAsUpEnabled(true);
54 ListView listView = (ListView) findViewById(android.R.id.list);
55 Button deleteHistoryButton = (Button) findViewById(R.id.deleteLogHistoryButton);
56 deleteHistoryButton.setOnClickListener(new OnClickListener() {
57
58 @Override
59 public void onClick(View v) {
60 File dir = new File(logpath);
61 if (dir != null) {
62 File[] files = dir.listFiles();
63 if(files!=null) {
64 for(File f: files) {
65 f.delete();
66 }
67 }
68 dir.delete();
69 }
70 Intent intent = new Intent(getBaseContext(), Preferences.class);
71 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
72 startActivity(intent);
73 }
74
75 });
76
77
78 if(logpath != null){
79 logDIR = new File(logpath);
80 }
81
82 if(logDIR != null && logDIR.isDirectory()) {
83 File[] files = logDIR.listFiles();
84
85 if (files != null && files.length != 0) {
86 ArrayList<String> logfiles_name = new ArrayList<String>();
87 for (File file : files) {
88 logfiles_name.add(file.getName());
89 }
90 String[] logFiles2Array = logfiles_name.toArray(new String[logfiles_name.size()]);
91 LogListAdapter listadapter = new LogListAdapter(this,logFiles2Array);
92 listView.setAdapter(listadapter);
93 }
94 }
95 }
96
97
98 @Override
99 public boolean onMenuItemSelected(int featureId, MenuItem item) {
100 super.onMenuItemSelected(featureId, item);
101 Intent intent;
102
103 switch (item.getItemId()) {
104
105 case android.R.id.home:
106 intent = new Intent(getBaseContext(), Preferences.class);
107 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
108 startActivity(intent);
109 break;
110 default:
111 return false;
112 }
113 return true;
114 }
115 @Override
116 public boolean onPreferenceChange(Preference arg0, Object arg1) {
117 return false;
118 }
119 }