LogHistoryActivity.java 4.1 KB

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