Android Open Source - shareplay Feedback






From Project

Back to project page shareplay.

License

The source code is released under:

Copyright (c) 2014, Benjamin Damer All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project shareplay 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 com.afqa123.shareplay.common;
//  w w  w .ja v a 2 s. c  o  m
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;
import android.os.Build;

import com.afqa123.log.Logger;
import com.afqa123.log.LoggerFactory;

public abstract class Feedback {

  private static final Logger logger = LoggerFactory.getLogger(Feedback.class);
  private static final String APP_PARAM = "app";
  private static final String DATA_PARAM = "data";
  
  private Context _context;
  private String _source;
  private Exception _exception;
  
  public Feedback(final Context context, final String source, final Exception ex) {
    _context = context;
    _source = source;
    _exception = ex;
  }
  
  public void submit() {
    new Thread() {
      public void run() {                      
          HttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost(Constants.FEEDBACK_URL);
        
        try {
          logger.debug("Submitting feedback request.");
          
          // create post data
              List<NameValuePair> params = new ArrayList<NameValuePair>(2);
              params.add(new BasicNameValuePair(APP_PARAM, Constants.APP_NAME));
              params.add(new BasicNameValuePair(DATA_PARAM, prepareFeedback().toString()));
              httpPost.setEntity(new UrlEncodedFormEntity(params));

              // Execute HTTP Post Request
              httpClient.execute(httpPost);
          
        } catch (Exception ex) {
          logger.warn("Could not submit feedback.", ex);
        }
      }
    }.start();
  }
  
  protected JSONObject prepareFeedback() throws Exception {
    // assemble general information
    JSONObject root = new JSONObject();
    root.put("date", new Date().toGMTString());
    root.put("source", _source);
    root.put("appVersion", _context.getPackageManager().getPackageInfo(_context.getPackageName(), 0).versionName);

    // assemble device information
    JSONObject device = new JSONObject();
    device.put("release", Build.VERSION.RELEASE);
    device.put("sdkVersion", Build.VERSION.SDK_INT);
    device.put("brand", Build.BRAND);
    device.put("device", Build.DEVICE);
    device.put("display", Build.DISPLAY);
    device.put("manufacturer", Build.MANUFACTURER);
    device.put("model", Build.MODEL);
    device.put("product", Build.PRODUCT);
    device.put("user", Build.USER);      
    root.put("device", device);

    // assemble exception information
    JSONObject exception = new JSONObject();
    if (_exception != null) {
      exception.put("class", _exception.getClass().getCanonicalName());
      exception.put("message", _exception.getMessage());
      
      Throwable cause = _exception.getCause();
      if (cause != null) {
        exception.put("cause", cause.getMessage());
      } else {
        exception.put("cause", "none");
      }
      
      JSONArray stack = new JSONArray();
      StackTraceElement elements[] = _exception.getStackTrace();
      for (StackTraceElement el : elements) {
        stack.put("at " + el.getClassName() + "." + el.getMethodName() + "(" + el.getFileName() + ":" + el.getLineNumber() + ")");
      }
      
      exception.put("stackTrace", stack);
    }
    root.put("exception", exception);
      
    return root;
  }
}




Java Source Code List

com.afqa123.log.DefaultLogger.java
com.afqa123.log.FileLogger.java
com.afqa123.log.LoggerFactory.java
com.afqa123.log.Logger.java
com.afqa123.log.NullLogger.java
com.afqa123.shareplay.DialogFactory.java
com.afqa123.shareplay.MediaPlayerService.java
com.afqa123.shareplay.SelectionActivity.java
com.afqa123.shareplay.SharePlayActivity.java
com.afqa123.shareplay.common.AuthorizationException.java
com.afqa123.shareplay.common.Base64.java
com.afqa123.shareplay.common.Constants.java
com.afqa123.shareplay.common.CustomFeedback.java
com.afqa123.shareplay.common.DAAPException.java
com.afqa123.shareplay.common.DBHelper.java
com.afqa123.shareplay.common.Feedback.java
com.afqa123.shareplay.common.Filename.java
com.afqa123.shareplay.common.ListWrapper.java
com.afqa123.shareplay.common.StoppableThread.java
com.afqa123.shareplay.common.StreamProxy.java
com.afqa123.shareplay.data.ContentCode.java
com.afqa123.shareplay.data.Item.java
com.afqa123.shareplay.data.Playlist.java
com.afqa123.shareplay.impl.Client.java
com.afqa123.shareplay.impl.DatabaseCatalog.java
com.afqa123.shareplay.impl.ServerProvider.java
com.afqa123.shareplay.impl.Server.java
com.afqa123.shareplay.interfaces.Catalog.java
com.afqa123.shareplay.interfaces.IClient.java
com.afqa123.shareplay.interfaces.IServerProvider.java