1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
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 3 of the License, or
7 * (at your option) any later version.
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.
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/>.
19 package eu
.alefzero
.owncloud
;
22 import java
.io
.IOException
;
24 import org
.apache
.commons
.httpclient
.HttpClient
;
25 import org
.apache
.commons
.httpclient
.HttpException
;
26 import org
.apache
.commons
.httpclient
.methods
.PostMethod
;
27 import org
.apache
.commons
.httpclient
.methods
.multipart
.FilePart
;
28 import org
.apache
.commons
.httpclient
.methods
.multipart
.MultipartRequestEntity
;
29 import org
.apache
.commons
.httpclient
.methods
.multipart
.Part
;
31 import android
.app
.AlertDialog
;
32 import android
.app
.Dialog
;
33 import android
.content
.DialogInterface
;
34 import android
.content
.DialogInterface
.OnCancelListener
;
35 import android
.content
.DialogInterface
.OnClickListener
;
36 import android
.os
.Bundle
;
37 import android
.util
.Log
;
39 import com
.actionbarsherlock
.app
.SherlockActivity
;
41 import eu
.alefzero
.webdav
.FileRequestEntity
;
43 public class CrashlogSendActivity
extends SherlockActivity
implements OnClickListener
, OnCancelListener
{
45 private static final String TAG
= "CrashlogSendActivity";
46 private static final String CRASHLOG_SUBMIT_URL
= "http://alefzero.eu/a/crashlog/";
47 private static final int DIALOG_SUBMIT
= 5;
49 private String mLogFilename
;
52 protected void onCreate(Bundle savedInstanceState
) {
53 super.onCreate(savedInstanceState
);
54 mLogFilename
= getIntent().getStringExtra(CrashHandler
.KEY_CRASH_FILENAME
);
55 if (mLogFilename
== null
) {
56 Log
.wtf(TAG
, "No file crashlog path given!");
60 Log
.i(TAG
, "crashlog file path " + mLogFilename
);
62 showDialog(DIALOG_SUBMIT
);
67 protected Dialog
onCreateDialog(int id
) {
68 if (id
== DIALOG_SUBMIT
) {
69 AlertDialog
.Builder builder
= new AlertDialog
.Builder(this);
70 builder
.setMessage(R
.string
.crashlog_message
);
71 builder
.setNegativeButton(R
.string
.crashlog_dont_send_report
, this);
72 builder
.setPositiveButton(R
.string
.crashlog_send_report
, this);
73 builder
.setCancelable(true
);
74 builder
.setOnCancelListener(this);
75 return builder
.create();
77 return super.onCreateDialog(id
);
82 public void onClick(DialogInterface dialog
, final int which
) {
83 new Thread(new Runnable() {
87 // TODO Auto-generated method stub
88 File file
= new File(mLogFilename
);
89 if (which
== Dialog
.BUTTON_POSITIVE
) {
91 HttpClient client
= new HttpClient();
92 PostMethod post
= new PostMethod(CRASHLOG_SUBMIT_URL
);
93 Part
[] parts
= {new FilePart("crashfile", file
)};
94 post
.setRequestEntity(new MultipartRequestEntity(parts
, post
.getParams()));
95 client
.executeMethod(post
);
96 post
.releaseConnection();
97 } catch (Exception e
) {
109 public void onCancel(DialogInterface dialog
) {
110 new File(mLogFilename
).delete();