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