Android Open Source - Boxee-Thumb-Remote Do Server Remote Action






From Project

Back to project page Boxee-Thumb-Remote.

License

The source code is released under:

Apache License

If you think the Android project Boxee-Thumb-Remote 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 net.evendanan.android.thumbremote.service;
//from   w ww . java  2  s. c  o  m
import org.apache.http.client.HttpResponseException;

import android.os.AsyncTask;

abstract class DoServerRemoteAction extends AsyncTask<Void, Void, Exception>
{  
  public static interface DoServerRemoteActionListener
  {
    void onRemoteActionError(String userMessage, int errorCode, boolean longMessageDelay);

    void onRemoteActionSuccess(String successMessage, boolean longDelayMessage);
  }
  /**
   * sometimes, when there is no network, or stuff, I get lots of Toast windows
   * which do not disapear for a long time. I say, if the same error happens too often
   * there is no need to show it.
   */
  private static String msLastErrorMessage = null;
  private static long msLastErrorMessageTime = 0;
  private static final long MINIMUM_ms_TIME_BETWEEN_ERRORS = 1000;
  private final DoServerRemoteActionListener mListener;
  private final boolean mLongShowMessage;
  
  protected DoServerRemoteAction(DoServerRemoteActionListener listener, boolean longShowMessage)
  {
    mListener = listener;
    mLongShowMessage =   longShowMessage;
  }
  
  @Override
  protected Exception doInBackground(Void... params) {
    try
    {
      callRemoteFunction();
      return null;
    }
    catch(Exception e)
    {
      e.printStackTrace();
      return e;
    }
  }
  
  protected String getSuccessMessage()
  {
    return null;
  }
  
  @Override
  protected void onPostExecute(Exception result) {
    super.onPostExecute(result);
    if (result == null)
    {
      mListener.onRemoteActionSuccess(getSuccessMessage(), mLongShowMessage);
      return;
    }
    
    String errorMessage = result.getMessage();
    if (errorMessage == null) errorMessage = "";
    int errorCode = 404;
    if (result instanceof HttpResponseException)
    {
      HttpResponseException httpError = (HttpResponseException)result;
      errorCode = httpError.getStatusCode();
    }
    //checking for repeating error
    final long currentTime = System.currentTimeMillis();
    if ((!errorMessage.equals(msLastErrorMessage)) || ((currentTime - msLastErrorMessageTime) > MINIMUM_ms_TIME_BETWEEN_ERRORS))
    {
      mListener.onRemoteActionError(errorMessage, errorCode, mLongShowMessage);
    }
    msLastErrorMessage = errorMessage;
    msLastErrorMessageTime = currentTime;
  }

  protected abstract void callRemoteFunction() throws Exception;
}




Java Source Code List

.HttpClientBlocking.java
com.example.android.actionbarcompat.ActionBarHelperBase.java
com.example.android.actionbarcompat.ActionBarHelperCompat.java
com.example.android.actionbarcompat.ActionBarHelperHoneycomb.java
com.example.android.actionbarcompat.ActionBarHelperICS.java
com.example.android.actionbarcompat.SimpleMenuItem.java
com.example.android.actionbarcompat.SimpleMenu.java
iharder.base64.Base64.java
net.evendanan.android.thumbremote.MediaStateListener.java
net.evendanan.android.thumbremote.RemoteApplication.java
net.evendanan.android.thumbremote.ServerAddress.java
net.evendanan.android.thumbremote.ServerConnectionListener.java
net.evendanan.android.thumbremote.ServerConnector.java
net.evendanan.android.thumbremote.ServerRemote.java
net.evendanan.android.thumbremote.ServerStatePoller.java
net.evendanan.android.thumbremote.ServerStateUrlsProvider.java
net.evendanan.android.thumbremote.ServerState.java
net.evendanan.android.thumbremote.Settings.java
net.evendanan.android.thumbremote.ShakeListener.java
net.evendanan.android.thumbremote.UiView.java
net.evendanan.android.thumbremote.boxee.BoxeeConnector.java
net.evendanan.android.thumbremote.boxee.BoxeeDiscovererThread.java
net.evendanan.android.thumbremote.network.HttpBlocking.java
net.evendanan.android.thumbremote.network.HttpRequest.java
net.evendanan.android.thumbremote.network.Response.java
net.evendanan.android.thumbremote.network.ReusableHttpClientBlocking.java
net.evendanan.android.thumbremote.service.DoServerRemoteAction.java
net.evendanan.android.thumbremote.service.ServerRemoteService.java
net.evendanan.android.thumbremote.service.State.java
net.evendanan.android.thumbremote.ui.FixedViewFlipper.java
net.evendanan.android.thumbremote.ui.FragmentAlertDialogSupport.java
net.evendanan.android.thumbremote.ui.HelpUiActivity.java
net.evendanan.android.thumbremote.ui.RemoteUiActivity.java
net.evendanan.android.thumbremote.ui.SettingsActivity.java