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
.view
.View
;
30 import android
.view
.View
.OnClickListener
;
31 import android
.widget
.Button
;
32 import android
.widget
.TextView
;
34 import com
.actionbarsherlock
.app
.ActionBar
;
35 import com
.actionbarsherlock
.app
.SherlockActivity
;
36 import com
.actionbarsherlock
.view
.MenuItem
;
37 import com
.owncloud
.android
.R
;
38 import com
.owncloud
.android
.utils
.DisplayUtils
;
39 import com
.owncloud
.android
.utils
.FileStorageUtils
;
40 import com
.owncloud
.android
.utils
.Log_OC
;
43 public class LogHistoryActivity
extends SherlockActivity
{
44 String mLogPath
= FileStorageUtils
.getLogPath();
46 private static final String MAIL_ATTACHMENT_TYPE
= "plain/text";
47 private static final String LOGGER_FILE_NAME
= "log.txt";
53 protected void onCreate(Bundle savedInstanceState
) {
54 super.onCreate(savedInstanceState
);
56 setContentView(R
.layout
.log_send_file
);
57 setTitle(getText(R
.string
.actionbar_logger
));
58 ActionBar actionBar
= getSherlock().getActionBar();
59 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
60 actionBar
.setDisplayHomeAsUpEnabled(true
);
61 Button deleteHistoryButton
= (Button
) findViewById(R
.id
.deleteLogHistoryButton
);
62 Button sendHistoryButton
= (Button
) findViewById(R
.id
.sendLogHistoryButton
);
64 deleteHistoryButton
.setOnClickListener(new OnClickListener() {
67 public void onClick(View v
) {
68 // File dir = new File(mLogPath);
70 // File[] files = dir.listFiles();
72 // for(File f: files) {
86 sendHistoryButton
.setOnClickListener(new OnClickListener() {
89 public void onClick(View v
) {
97 logDIR
= new File(mLogPath
);
100 if(logDIR
!= null
&& logDIR
.isDirectory()) {
101 // File[] files = logDIR.listFiles();
103 // if (files != null && files.length != 0) {
104 // ArrayList<String> logfiles_name = new ArrayList<String>();
105 // for (File file : files) {
106 // logfiles_name.add(file.getName());
108 // String[] logFiles2Array = logfiles_name.toArray(new String[logfiles_name.size()]);
109 // LogListAdapter listadapter = new LogListAdapter(this,logFiles2Array);
110 // listView.setAdapter(listadapter);
120 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
121 super.onMenuItemSelected(featureId
, item
);
123 switch (item
.getItemId()) {
124 case android
.R
.id
.home
:
135 * Start activity for sending email with logs attached
137 private void sendMail() {
139 String emailAddresses
[] = { getText(R
.string
.mail_logger
).toString() };
141 Uri uri
= Uri
.parse("file://" + mLogPath
+ File
.separator
+ LOGGER_FILE_NAME
);
142 Intent intent
= new Intent(Intent
.ACTION_SEND
);
144 // Explicitly only use Gmail to send
145 intent
.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
147 intent
.putExtra(Intent
.EXTRA_EMAIL
, emailAddresses
);
148 intent
.putExtra(Intent
.EXTRA_SUBJECT
, getText(R
.string
.log_mail_subject
));
149 intent
.setFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
150 intent
.setType(MAIL_ATTACHMENT_TYPE
);
152 intent
.putExtra(Intent
.EXTRA_STREAM
, uri
);
153 if (intent
.resolveActivity(getPackageManager()) != null
) {
154 startActivity(intent
);
160 * Read and show log file info
162 private void readLogFile() {
165 File file
= new File(mLogPath
,LOGGER_FILE_NAME
);
167 //Read text from file
168 StringBuilder text
= new StringBuilder();
171 BufferedReader br
= new BufferedReader(new FileReader(file
));
174 while ((line
= br
.readLine()) != null
) {
179 catch (IOException e
) {
184 TextView logTV
= (TextView
) findViewById(R
.id
.logTV
);