Change log messages for using our logger in all logs
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / LogHistoryActivity.java
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
18 package com.owncloud.android.ui.activity;
19
20 import java.io.BufferedReader;
21 import java.io.File;
22 import java.io.FileReader;
23 import java.io.IOException;
24
25 import android.content.Intent;
26 import android.net.Uri;
27 import android.os.Bundle;
28
29 import android.view.View;
30 import android.view.View.OnClickListener;
31 import android.widget.Button;
32 import android.widget.TextView;
33
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;
41
42
43 public class LogHistoryActivity extends SherlockActivity {
44 String mLogPath = FileStorageUtils.getLogPath();
45
46 private static final String MAIL_ATTACHMENT_TYPE = "plain/text";
47 private static final String LOGGER_FILE_NAME = "log.txt";
48
49 File logDIR = null;
50
51
52 @Override
53 protected void onCreate(Bundle savedInstanceState) {
54 super.onCreate(savedInstanceState);
55
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);
63
64 deleteHistoryButton.setOnClickListener(new OnClickListener() {
65
66 @Override
67 public void onClick(View v) {
68
69 Log_OC.stopLogging();
70 finish();
71 }
72 });
73
74 sendHistoryButton.setOnClickListener(new OnClickListener() {
75
76 @Override
77 public void onClick(View v) {
78 sendMail();
79 }
80 });
81
82 if(mLogPath != null){
83 logDIR = new File(mLogPath);
84 }
85
86 if(logDIR != null && logDIR.isDirectory()) {
87 readLogFile();
88 }
89 }
90
91
92 @Override
93 public boolean onMenuItemSelected(int featureId, MenuItem item) {
94 super.onMenuItemSelected(featureId, item);
95 switch (item.getItemId()) {
96 case android.R.id.home:
97 finish();
98 break;
99 default:
100 return false;
101 }
102 return true;
103 }
104
105
106 /**
107 * Start activity for sending email with logs attached
108 */
109 private void sendMail() {
110
111 String emailAddresses[] = { getText(R.string.mail_logger).toString() };
112
113 Uri uri = Uri.parse("file://" + mLogPath + File.separator + LOGGER_FILE_NAME);
114 Intent intent = new Intent(Intent.ACTION_SEND);
115
116 // Explicitly only use Gmail to send
117 intent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
118
119 intent.putExtra(Intent.EXTRA_EMAIL, emailAddresses);
120 intent.putExtra(Intent.EXTRA_SUBJECT, getText(R.string.log_mail_subject));
121 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
122 intent.setType(MAIL_ATTACHMENT_TYPE);
123
124 intent.putExtra(Intent.EXTRA_STREAM, uri);
125 if (intent.resolveActivity(getPackageManager()) != null) {
126 startActivity(intent);
127 }
128 }
129
130
131 /**
132 * Read and show log file info
133 */
134 private void readLogFile() {
135
136 //Get the text file
137 File file = new File(mLogPath,LOGGER_FILE_NAME);
138
139 //Read text from file
140 StringBuilder text = new StringBuilder();
141
142 try {
143 BufferedReader br = new BufferedReader(new FileReader(file));
144 String line;
145
146 while ((line = br.readLine()) != null) {
147 text.append(line);
148 text.append('\n');
149 }
150 }
151 catch (IOException e) {
152
153 }
154
155 TextView logTV = (TextView) findViewById(R.id.logTV);
156 logTV.setText(text);
157 }
158 }