LogHistoryActivity.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.BufferedReader;
  19. import java.io.File;
  20. import java.io.FileReader;
  21. import java.io.IOException;
  22. import android.content.Intent;
  23. import android.net.Uri;
  24. import android.os.Bundle;
  25. import android.view.View;
  26. import android.view.View.OnClickListener;
  27. import android.widget.Button;
  28. import android.widget.TextView;
  29. import com.actionbarsherlock.app.ActionBar;
  30. import com.actionbarsherlock.app.SherlockActivity;
  31. import com.actionbarsherlock.view.MenuItem;
  32. import com.owncloud.android.R;
  33. import com.owncloud.android.utils.DisplayUtils;
  34. import com.owncloud.android.utils.FileStorageUtils;
  35. public class LogHistoryActivity extends SherlockActivity {
  36. String mLogPath = FileStorageUtils.getLogPath();
  37. private static final String MAIL_ATTACHMENT_TYPE = "plain/text";
  38. private static final String LOGGER_FILE_NAME = "log.txt";
  39. File logDIR = null;
  40. @Override
  41. protected void onCreate(Bundle savedInstanceState) {
  42. super.onCreate(savedInstanceState);
  43. setContentView(R.layout.log_send_file);
  44. setTitle(getText(R.string.actionbar_logger));
  45. ActionBar actionBar = getSherlock().getActionBar();
  46. actionBar.setIcon(DisplayUtils.getSeasonalIconId());
  47. actionBar.setDisplayHomeAsUpEnabled(true);
  48. Button deleteHistoryButton = (Button) findViewById(R.id.deleteLogHistoryButton);
  49. Button sendHistoryButton = (Button) findViewById(R.id.sendLogHistoryButton);
  50. deleteHistoryButton.setOnClickListener(new OnClickListener() {
  51. @Override
  52. public void onClick(View v) {
  53. File dir = new File(mLogPath);
  54. if (dir != null) {
  55. File[] files = dir.listFiles();
  56. if(files!=null) {
  57. for(File f: files) {
  58. f.delete();
  59. }
  60. }
  61. dir.delete();
  62. }
  63. finish();
  64. }
  65. });
  66. sendHistoryButton.setOnClickListener(new OnClickListener() {
  67. @Override
  68. public void onClick(View v) {
  69. sendMail();
  70. }
  71. });
  72. if(mLogPath != null){
  73. logDIR = new File(mLogPath);
  74. }
  75. if(logDIR != null && logDIR.isDirectory()) {
  76. // File[] files = logDIR.listFiles();
  77. //
  78. // if (files != null && files.length != 0) {
  79. // ArrayList<String> logfiles_name = new ArrayList<String>();
  80. // for (File file : files) {
  81. // logfiles_name.add(file.getName());
  82. // }
  83. // String[] logFiles2Array = logfiles_name.toArray(new String[logfiles_name.size()]);
  84. // LogListAdapter listadapter = new LogListAdapter(this,logFiles2Array);
  85. // listView.setAdapter(listadapter);
  86. // }
  87. readLogFile();
  88. }
  89. }
  90. @Override
  91. public boolean onMenuItemSelected(int featureId, MenuItem item) {
  92. super.onMenuItemSelected(featureId, item);
  93. switch (item.getItemId()) {
  94. case android.R.id.home:
  95. finish();
  96. break;
  97. default:
  98. return false;
  99. }
  100. return true;
  101. }
  102. /**
  103. * Start activity for sending email with logs attached
  104. */
  105. private void sendMail() {
  106. String emailAddresses[] = { getText(R.string.mail_logger).toString() };
  107. Uri uri = Uri.parse("file://" + mLogPath + File.separator + LOGGER_FILE_NAME);
  108. Intent intent = new Intent(Intent.ACTION_SEND);
  109. // Explicitly only use Gmail to send
  110. intent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
  111. intent.putExtra(Intent.EXTRA_EMAIL, emailAddresses);
  112. intent.putExtra(Intent.EXTRA_SUBJECT, getText(R.string.log_mail_subject));
  113. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  114. intent.setType(MAIL_ATTACHMENT_TYPE);
  115. intent.putExtra(Intent.EXTRA_STREAM, uri);
  116. if (intent.resolveActivity(getPackageManager()) != null) {
  117. startActivity(intent);
  118. }
  119. }
  120. /**
  121. * Read and show log file info
  122. */
  123. private void readLogFile() {
  124. //Get the text file
  125. File file = new File(mLogPath,LOGGER_FILE_NAME);
  126. //Read text from file
  127. StringBuilder text = new StringBuilder();
  128. try {
  129. BufferedReader br = new BufferedReader(new FileReader(file));
  130. String line;
  131. while ((line = br.readLine()) != null) {
  132. text.append(line);
  133. text.append('\n');
  134. }
  135. }
  136. catch (IOException e) {
  137. }
  138. TextView logTV = (TextView) findViewById(R.id.logTV);
  139. logTV.setText(text);
  140. }
  141. }