0066bc13a378760c7af415eec46a0bb5869c0ded
[pub/Android/ownCloud.git] / src / de / mobilcom / debitel / cloud / 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 de.mobilcom.debitel.cloud.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
36 import de.mobilcom.debitel.cloud.android.R;
37 import de.mobilcom.debitel.cloud.android.ui.adapter.LogListAdapter;
38 import de.mobilcom.debitel.cloud.android.utils.FileStorageUtils;
39
40
41
42 public class LogHistoryActivity extends SherlockPreferenceActivity implements OnPreferenceChangeListener {
43 String logpath = FileStorageUtils.getLogPath();
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
57 // Set background of 'deleteHistory' button
58 boolean customButtons = getResources().getBoolean(R.bool.custom_buttons);
59 if (customButtons)
60 deleteHistoryButton.setBackgroundResource(R.drawable.btn_default);
61
62 deleteHistoryButton.setOnClickListener(new OnClickListener() {
63
64 @Override
65 public void onClick(View v) {
66 File dir = new File(logpath);
67 if (dir != null) {
68 File[] files = dir.listFiles();
69 if(files!=null) {
70 for(File f: files) {
71 f.delete();
72 }
73 }
74 dir.delete();
75 }
76 Intent intent = new Intent(getBaseContext(), Preferences.class);
77 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
78 startActivity(intent);
79 }
80
81 });
82
83
84 if(logpath != null){
85 logDIR = new File(logpath);
86 }
87
88 if(logDIR != null && logDIR.isDirectory()) {
89 File[] files = logDIR.listFiles();
90
91 if (files != null && files.length != 0) {
92 ArrayList<String> logfiles_name = new ArrayList<String>();
93 for (File file : files) {
94 logfiles_name.add(file.getName());
95 }
96 String[] logFiles2Array = logfiles_name.toArray(new String[logfiles_name.size()]);
97 LogListAdapter listadapter = new LogListAdapter(this,logFiles2Array);
98 listView.setAdapter(listadapter);
99 }
100 }
101 }
102
103
104 @Override
105 public boolean onMenuItemSelected(int featureId, MenuItem item) {
106 super.onMenuItemSelected(featureId, item);
107 Intent intent;
108
109 switch (item.getItemId()) {
110
111 case android.R.id.home:
112 intent = new Intent(getBaseContext(), Preferences.class);
113 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
114 startActivity(intent);
115 break;
116 default:
117 return false;
118 }
119 return true;
120 }
121 @Override
122 public boolean onPreferenceChange(Preference arg0, Object arg1) {
123 return false;
124 }
125 }