Android Open Source - Broadsheet.ie-Android Submit Tip Request






From Project

Back to project page Broadsheet.ie-Android.

License

The source code is released under:

Copyright (c) 2013 Karl Monaghan (http://karlmonaghan.com/) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Soft...

If you think the Android project Broadsheet.ie-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ie.broadsheet.app.requests;
/*  w  w w .  j a v  a2 s  .com*/
import ie.broadsheet.app.BroadsheetApplication;
import ie.broadsheet.app.R;
import ie.broadsheet.app.client.http.MultipartFormDataContent;
import ie.broadsheet.app.client.http.MultipartFormDataContent.Part;
import ie.broadsheet.app.model.json.SubmitTipResponse;

import java.io.File;
import java.io.IOException;

import android.util.Log;
import android.webkit.MimeTypeMap;

import com.google.api.client.http.FileContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.json.jackson.JacksonFactory;
import com.octo.android.robospice.request.googlehttpclient.GoogleHttpClientSpiceRequest;

public class SubmitTipRequest extends GoogleHttpClientSpiceRequest<SubmitTipResponse> {
    private static final String TAG = "SubmitTipRequest";

    private String name;

    private String email;

    private String message;

    private String filename;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public SubmitTipRequest() {
        super(SubmitTipResponse.class);
    }

    @Override
    public SubmitTipResponse loadDataFromNetwork() throws Exception {
        MultipartFormDataContent content = new MultipartFormDataContent();

        if (filename != null) {
            Log.d(TAG, "we have a file: " + filename);

            File file = new File(filename);

            MimeTypeMap mime = MimeTypeMap.getSingleton();
            String extension = MimeTypeMap.getFileExtensionFromUrl(file.getName());
            String mimeType = mime.getMimeTypeFromExtension(extension);

            Part part = new Part();
            part.setName("file");
            part.setFilename(file.getName());
            part.setContent(new FileContent(mimeType, file));
            content.addPart(part);

        }

        content.addUrlEncodedContent("name", name);
        content.addUrlEncodedContent("email", email);
        content.addUrlEncodedContent("message", message);
        content.addUrlEncodedContent("android", "android");

        Log.d(TAG, BroadsheetApplication.context().getString(R.string.apiURL) + "/iphone_tip.php");
        HttpRequest request = null;
        try {
            request = getHttpRequestFactory().buildPostRequest(
                    new GenericUrl(BroadsheetApplication.context().getString(R.string.apiURL) + "/iphone_tip.php"),
                    content);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.setParser(new JacksonFactory().createJsonObjectParser());

        return request.execute().parseAs(getResultType());
    }
}




Java Source Code List

ie.broadsheet.app.BaseFragmentActivity.java
ie.broadsheet.app.BroadsheetApplication.java
ie.broadsheet.app.CommentListActivity.java
ie.broadsheet.app.PostDetailActivity.java
ie.broadsheet.app.PostListActivity.java
ie.broadsheet.app.adapters.CommentAdapter.java
ie.broadsheet.app.adapters.PostListAdapter.java
ie.broadsheet.app.adapters.PostListEndlessAdapter.java
ie.broadsheet.app.client.http.MultipartFormDataContent.java
ie.broadsheet.app.dialog.AboutDialog.java
ie.broadsheet.app.dialog.MakeCommentDialog.java
ie.broadsheet.app.dialog.TipDialog.java
ie.broadsheet.app.dialog.WebViewDialog.java
ie.broadsheet.app.fragments.PostDetailFragment.java
ie.broadsheet.app.fragments.PostListFragment.java
ie.broadsheet.app.model.json.AttachmentItem.java
ie.broadsheet.app.model.json.Attachments.java
ie.broadsheet.app.model.json.Author.java
ie.broadsheet.app.model.json.Category.java
ie.broadsheet.app.model.json.Comment.java
ie.broadsheet.app.model.json.Image.java
ie.broadsheet.app.model.json.PostList.java
ie.broadsheet.app.model.json.Post.java
ie.broadsheet.app.model.json.ResponseData.java
ie.broadsheet.app.model.json.SinglePost.java
ie.broadsheet.app.model.json.SubmitTipResponse.java
ie.broadsheet.app.model.json.Tag.java
ie.broadsheet.app.requests.DownloadFileRequest.java
ie.broadsheet.app.requests.MakeCommentRequest.java
ie.broadsheet.app.requests.PostListRequest.java
ie.broadsheet.app.requests.PostRequest.java
ie.broadsheet.app.requests.SubmitTipRequest.java
ie.broadsheet.app.services.BroadsheetServices.java