Android Open Source - shareplay Custom 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;
//from   ww w. ja va 2s. c  o  m
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

import android.content.Context;

import com.afqa123.shareplay.impl.Client;
import com.afqa123.shareplay.impl.Server;
import com.afqa123.shareplay.interfaces.IClient;

public class CustomFeedback extends Feedback {

  private IClient client;
  private Server server;

  public CustomFeedback(final Context context, final String source, final Exception ex) {
    super(context, source, ex);
  }
  
  public void setServer(final Server server) {
    this.server = server;
  }
  
  public void setClient(final IClient client) {
    this.client = client;
  }

  @Override
  protected JSONObject prepareFeedback() throws Exception {
    JSONObject root = super.prepareFeedback();
    // assemble client data
    JSONObject jsonClient = new JSONObject();
    if (client != null) {
      jsonClient.put("catalog", client.getCatalog() == null ? "null" : "object");
      jsonClient.put("connected", client.isConnected());
      jsonClient.put("sessionId", ((Client)client).getSessionId());

      // assemble connection information
      URLConnection conn = ((Client)client).getConnection();
      JSONObject jsonConn = new JSONObject();
      if (conn != null) {
        jsonConn.put("url", conn.getURL());
        
        // assemble header information
        Map<String,List<String>> headers = conn.getHeaderFields();
        JSONObject jsonHeaders = new JSONObject();
        if (headers != null) {
          for (String key : headers.keySet()) {
            jsonHeaders.put(key, headers.get(key));
          }
        }          
        jsonConn.put("headers", jsonHeaders);
        
        if (conn instanceof HttpURLConnection) {
          HttpURLConnection httpConn = (HttpURLConnection)conn;
          jsonConn.put("request-method", httpConn.getRequestMethod());
          jsonConn.put("response-code", httpConn.getResponseCode());
          jsonConn.put("response-message", httpConn.getResponseMessage());
        }
      }
      jsonClient.put("connection", jsonConn);
    }
    root.put("client", jsonClient);
    
    // assemble server data
    JSONObject jsonServer = new JSONObject();
    if (server != null) {
      jsonServer.put("address", server.getAddress());
      jsonServer.put("databaseCount", server.getDatabaseCount());
      jsonServer.put("host", server.getHost());
      jsonServer.put("lastDiscovered", server.getLastDiscovered());
      jsonServer.put("name", server.getName());
      jsonServer.put("isOnline", server.isOnline());
      jsonServer.put("port", server.getPort());
      jsonServer.put("revision", server.getRevision());
      
      // assemble server flags
      Map<String,Object> flags = server.getFlags();
      JSONObject jsonFlags = new JSONObject();
      if (flags != null) {
        for (String key : flags.keySet()) {
          jsonFlags.put(key, flags.get(key));
        }
      }
      jsonServer.put("flags", jsonFlags);
    }
    root.put("server", jsonServer);

    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