1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
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.
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.
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/>.
18 package com
.owncloud
.android
.ui
.activity
;
20 import java
.io
.BufferedReader
;
22 import java
.io
.FileReader
;
23 import java
.io
.IOException
;
25 import android
.content
.Intent
;
26 import android
.net
.Uri
;
27 import android
.os
.Bundle
;
29 import android
.util
.Log
;
30 import android
.view
.View
;
31 import android
.view
.View
.OnClickListener
;
32 import android
.widget
.Button
;
33 import android
.widget
.TextView
;
35 import com
.actionbarsherlock
.app
.ActionBar
;
36 import com
.actionbarsherlock
.app
.SherlockActivity
;
37 import com
.actionbarsherlock
.view
.MenuItem
;
38 import com
.owncloud
.android
.R
;
39 import com
.owncloud
.android
.utils
.DisplayUtils
;
40 import com
.owncloud
.android
.utils
.FileStorageUtils
;
41 import com
.owncloud
.android
.utils
.Log_OC
;
44 public class LogHistoryActivity
extends SherlockActivity
{
45 String mLogPath
= FileStorageUtils
.getLogPath();
47 private static final String MAIL_ATTACHMENT_TYPE
= "plain/text";
48 private static final String LOGGER_FILE_NAME
= "log.txt";
54 protected void onCreate(Bundle savedInstanceState
) {
55 super.onCreate(savedInstanceState
);
57 setContentView(R
.layout
.log_send_file
);
58 setTitle(getText(R
.string
.actionbar_logger
));
59 ActionBar actionBar
= getSherlock().getActionBar();
60 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
61 actionBar
.setDisplayHomeAsUpEnabled(true
);
62 Button deleteHistoryButton
= (Button
) findViewById(R
.id
.deleteLogHistoryButton
);
63 Button sendHistoryButton
= (Button
) findViewById(R
.id
.sendLogHistoryButton
);
65 deleteHistoryButton
.setOnClickListener(new OnClickListener() {
68 public void onClick(View v
) {
75 sendHistoryButton
.setOnClickListener(new OnClickListener() {
78 public void onClick(View v
) {
84 logDIR
= new File(mLogPath
);
87 if(logDIR
!= null
&& logDIR
.isDirectory()) {
94 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
95 super.onMenuItemSelected(featureId
, item
);
96 switch (item
.getItemId()) {
97 case android
.R
.id
.home
:
108 * Start activity for sending email with logs attached
110 private void sendMail() {
112 String emailAddresses
[] = { getText(R
.string
.mail_logger
).toString() };
114 Uri uri
= Uri
.parse("file://" + mLogPath
+ File
.separator
+ LOGGER_FILE_NAME
);
115 Intent intent
= new Intent(Intent
.ACTION_SEND
);
117 // Explicitly only use Gmail to send
118 intent
.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
120 intent
.putExtra(Intent
.EXTRA_EMAIL
, emailAddresses
);
121 intent
.putExtra(Intent
.EXTRA_SUBJECT
, getText(R
.string
.log_mail_subject
));
122 intent
.setFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
123 intent
.setType(MAIL_ATTACHMENT_TYPE
);
125 intent
.putExtra(Intent
.EXTRA_STREAM
, uri
);
126 if (intent
.resolveActivity(getPackageManager()) != null
) {
127 startActivity(intent
);
133 * Read and show log file info
135 private void readLogFile() {
138 File file
= new File(mLogPath
,LOGGER_FILE_NAME
);
140 //Read text from file
141 StringBuilder text
= new StringBuilder();
144 BufferedReader br
= new BufferedReader(new FileReader(file
));
147 while ((line
= br
.readLine()) != null
) {
152 catch (IOException e
) {
157 TextView logTV
= (TextView
) findViewById(R
.id
.logTV
);