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 com
.owncloud
.android
;
23 import org
.apache
.commons
.httpclient
.HttpClient
;
24 import org
.apache
.commons
.httpclient
.methods
.PostMethod
;
25 import org
.apache
.commons
.httpclient
.methods
.multipart
.FilePart
;
26 import org
.apache
.commons
.httpclient
.methods
.multipart
.MultipartRequestEntity
;
27 import org
.apache
.commons
.httpclient
.methods
.multipart
.Part
;
29 import android
.app
.AlertDialog
;
30 import android
.app
.Dialog
;
31 import android
.content
.DialogInterface
;
32 import android
.content
.DialogInterface
.OnCancelListener
;
33 import android
.content
.DialogInterface
.OnClickListener
;
34 import android
.os
.Bundle
;
35 import android
.util
.Log
;
37 import com
.actionbarsherlock
.app
.SherlockActivity
;
39 import com
.owncloud
.android
.R
;
41 public class CrashlogSendActivity
extends SherlockActivity
implements OnClickListener
, OnCancelListener
{
43 private static final String TAG
= "CrashlogSendActivity";
44 private static final String CRASHLOG_SUBMIT_URL
= "http://alefzero.eu/a/crashlog/";
45 private static final int DIALOG_SUBMIT
= 5;
47 private String mLogFilename
;
50 protected void onCreate(Bundle savedInstanceState
) {
51 super.onCreate(savedInstanceState
);
52 mLogFilename
= getIntent().getStringExtra(CrashHandler
.KEY_CRASH_FILENAME
);
53 if (mLogFilename
== null
) {
54 Log
.wtf(TAG
, "No file crashlog path given!");
58 Log
.i(TAG
, "crashlog file path " + mLogFilename
);
60 showDialog(DIALOG_SUBMIT
);
65 protected Dialog
onCreateDialog(int id
) {
66 if (id
== DIALOG_SUBMIT
) {
67 AlertDialog
.Builder builder
= new AlertDialog
.Builder(this);
68 builder
.setMessage(R
.string
.crashlog_message
);
69 builder
.setNegativeButton(R
.string
.crashlog_dont_send_report
, this);
70 builder
.setPositiveButton(R
.string
.crashlog_send_report
, this);
71 builder
.setCancelable(true
);
72 builder
.setOnCancelListener(this);
73 return builder
.create();
75 return super.onCreateDialog(id
);
80 public void onClick(DialogInterface dialog
, final int which
) {
81 new Thread(new Runnable() {
85 // TODO Auto-generated method stub
86 File file
= new File(mLogFilename
);
87 if (which
== Dialog
.BUTTON_POSITIVE
) {
89 HttpClient client
= new HttpClient();
90 PostMethod post
= new PostMethod(CRASHLOG_SUBMIT_URL
);
91 Part
[] parts
= {new FilePart("crashfile", file
)};
92 post
.setRequestEntity(new MultipartRequestEntity(parts
, post
.getParams()));
93 client
.executeMethod(post
);
94 post
.releaseConnection();
95 } catch (Exception e
) {
107 public void onCancel(DialogInterface dialog
) {
108 new File(mLogFilename
).delete();