LogHistoryActivity.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. package com.owncloud.android.ui.activity;
  18. import java.io.File;
  19. import java.util.ArrayList;
  20. import android.content.Intent;
  21. import android.os.Bundle;
  22. import android.preference.Preference;
  23. import android.preference.Preference.OnPreferenceChangeListener;
  24. import android.view.View;
  25. import android.view.View.OnClickListener;
  26. import android.widget.Button;
  27. import android.widget.ListView;
  28. import com.actionbarsherlock.app.ActionBar;
  29. import com.actionbarsherlock.app.SherlockPreferenceActivity;
  30. import com.actionbarsherlock.view.MenuItem;
  31. import com.owncloud.android.R;
  32. import com.owncloud.android.ui.adapter.LogListAdapter;
  33. import com.owncloud.android.utils.DisplayUtils;
  34. import com.owncloud.android.utils.FileStorageUtils;
  35. public class LogHistoryActivity extends SherlockPreferenceActivity implements OnPreferenceChangeListener {
  36. String logpath = FileStorageUtils.getLogPath();
  37. File logDIR = null;
  38. @Override
  39. protected void onCreate(Bundle savedInstanceState) {
  40. super.onCreate(savedInstanceState);
  41. setContentView(R.layout.log_send_file);
  42. setTitle("Log History");
  43. ActionBar actionBar = getSherlock().getActionBar();
  44. actionBar.setIcon(DisplayUtils.getSeasonalIconId());
  45. actionBar.setDisplayHomeAsUpEnabled(true);
  46. ListView listView = (ListView) findViewById(android.R.id.list);
  47. Button deleteHistoryButton = (Button) findViewById(R.id.deleteLogHistoryButton);
  48. deleteHistoryButton.setOnClickListener(new OnClickListener() {
  49. @Override
  50. public void onClick(View v) {
  51. File dir = new File(logpath);
  52. if (dir != null) {
  53. File[] files = dir.listFiles();
  54. if(files!=null) {
  55. for(File f: files) {
  56. f.delete();
  57. }
  58. }
  59. dir.delete();
  60. }
  61. Intent intent = new Intent(getBaseContext(), Preferences.class);
  62. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  63. startActivity(intent);
  64. }
  65. });
  66. if(logpath != null){
  67. logDIR = new File(logpath);
  68. }
  69. if(logDIR != null && logDIR.isDirectory()) {
  70. File[] files = logDIR.listFiles();
  71. if (files != null && files.length != 0) {
  72. ArrayList<String> logfiles_name = new ArrayList<String>();
  73. for (File file : files) {
  74. logfiles_name.add(file.getName());
  75. }
  76. String[] logFiles2Array = logfiles_name.toArray(new String[logfiles_name.size()]);
  77. LogListAdapter listadapter = new LogListAdapter(this,logFiles2Array);
  78. listView.setAdapter(listadapter);
  79. }
  80. }
  81. }
  82. @Override
  83. public boolean onMenuItemSelected(int featureId, MenuItem item) {
  84. super.onMenuItemSelected(featureId, item);
  85. Intent intent;
  86. switch (item.getItemId()) {
  87. case android.R.id.home:
  88. intent = new Intent(getBaseContext(), Preferences.class);
  89. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  90. startActivity(intent);
  91. break;
  92. default:
  93. return false;
  94. }
  95. return true;
  96. }
  97. @Override
  98. public boolean onPreferenceChange(Preference arg0, Object arg1) {
  99. return false;
  100. }
  101. }