Example usage for android.os Looper getMainLooper

List of usage examples for android.os Looper getMainLooper

Introduction

In this page you can find the example usage for android.os Looper getMainLooper.

Prototype

public static Looper getMainLooper() 

Source Link

Document

Returns the application's main looper, which lives in the main thread of the application.

Usage

From source file:com.uzmap.pkg.uzmodules.photoBrowser.PhotoBrowser.java

public void jsmethod_setImage(UZModuleContext uzContext) {
    int index = uzContext.optInt("index");
    String imagePath = uzContext.optString("image");

    if (!imagePath.startsWith("http")) {
        imagePath = UZUtility.makeRealPath(imagePath, getWidgetInfo());
    }//ww w.  ja va  2  s.co  m

    if (index >= 0 && index < mAdapter.getCount() && !TextUtils.isEmpty(imagePath)) {
        View view = getExistChild(index);
        if (view != null) {

            int photo_view_id = UZResourcesIDFinder.getResIdID("photoView");
            final PhotoView imageView = (PhotoView) view.findViewById(photo_view_id);

            int load_progress_id = UZResourcesIDFinder.getResIdID("loadProgress");
            final ProgressBar progress = (ProgressBar) view.findViewById(load_progress_id);

            mLoader.load(imageView, progress, imagePath);

            if (mUZContext == null) {
                return;
            }

            mLoader.setOnLoadCompleteListener(new OnLoadCompleteListener() {
                @Override
                public void onLoadComplete(ProgressBar bar) {
                    PhotoBrowser.callback(mUZContext, PhotoBrowser.EVENT_TYPE_LOADSUCCESSED,
                            (Integer) bar.getTag());
                }

                @Override
                public void onLoadFailed(final ProgressBar bar) {
                    PhotoBrowser.callback(mUZContext, PhotoBrowser.EVENT_TYPE_LOADFAILED,
                            (Integer) bar.getTag());
                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            bar.setVisibility(View.GONE);
                        }
                    });
                }
            });

        } else {
            mConfig.imagePaths.set(index, imagePath);
        }
    }
}

From source file:com.mars.framework.volley.request.Request.java

/**
 * Notifies the request queue that this request has finished (successfully or with error).
 *
 * <p>Also dumps all events from this request's event log; for debugging.</p>
 *///www. jav  a  2 s.c  om
public void finish(final String tag) {
    if (mRequestQueue != null) {
        mRequestQueue.finish(this);
    }
    if (MarkerLog.ENABLED) {
        final long threadId = Thread.currentThread().getId();
        if (Looper.myLooper() != Looper.getMainLooper()) {
            // If we finish marking off of the main thread, we need to
            // actually do it on the main thread to ensure correct ordering.
            Handler mainThread = new Handler(Looper.getMainLooper());
            mainThread.post(new Runnable() {
                @Override
                public void run() {
                    mEventLog.add(tag, threadId);
                    mEventLog.finish(this.toString());
                }
            });
            return;
        }

        mEventLog.add(tag, threadId);
        mEventLog.finish(this.toString());
    } else {
        long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime;
        if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) {
            VolleyLog.d("%d ms: %s", requestTime, this.toString());
        }
    }
}

From source file:com.mobicomkit.api.attachment.AttachmentManager.java

/**
 * Constructs the work queues and thread pools used to download and decode images.
 *//*from w  w  w .  j  a  v a2 s  . com*/
private AttachmentManager() {

    attachmentInProgress = new ArrayList<String>();
    attachmentTaskList = new ArrayList<AttachmentTask>();
    /*
     * Creates a work queue for the pool of Thread objects used for downloading, using a linked
     * list queue that blocks when the queue is empty.
     */
    mDownloadWorkQueue = new LinkedBlockingQueue<Runnable>();

    /*
     * Creates a work queue for the pool of Thread objects used for decoding, using a linked
     * list queue that blocks when the queue is empty.
     */
    mDecodeWorkQueue = new LinkedBlockingQueue<Runnable>();

    /*
     * Creates a work queue for the set of of task objects that control downloading and
     * decoding, using a linked list queue that blocks when the queue is empty.
     */
    mPhotoTaskWorkQueue = new LinkedBlockingQueue<AttachmentTask>();

    /*
     * Creates a new pool of Thread objects for the download work queue
     */
    mDownloadThreadPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, mDownloadWorkQueue);

    /*
     * Creates a new pool of Thread objects for the decoding work queue
     */
    mDecodeThreadPool = new ThreadPoolExecutor(NUMBER_OF_CORES, NUMBER_OF_CORES, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, mDecodeWorkQueue);

    // Instantiates a new cache based on the cache size estimate
    mPhotoCache = new LruCache<String, Bitmap>(IMAGE_CACHE_SIZE) {

        //            /*
        //             * This overrides the default sizeOf() implementation to return the
        //             * correct size of each cache entry.
        //             */
        //
        //            @Override
        //            protected int sizeOf(String paramURL, Bitmap image) {
        //                return image.getByteCount();
        //            }
    };
    /*
     * Instantiates a new anonymous Handler object and defines its
     * handleMessage() method. The Handler *must* run on the UI thread, because it moves photo
     * Bitmaps from the PhotoTask object to the View object.
     * To force the Handler to run on the UI thread, it's defined as part of the PhotoManager
     * constructor. The constructor is invoked when the class is first referenced, and that
     * happens when the View invokes startDownload. Since the View runs on the UI Thread, so
     * does the constructor and the Handler.
     */
    mHandler = new Handler(Looper.getMainLooper()) {

        /*
         * handleMessage() defines the operations to perform when the
         * Handler receives a new Message to process.
         */
        @Override
        public void handleMessage(Message inputMessage) {

            // Gets the image task from the incoming Message object.
            AttachmentTask attachmentTask = (AttachmentTask) inputMessage.obj;

            // Sets an PhotoView that's a weak reference to the
            // input ImageView
            AttachmentView localView = attachmentTask.getPhotoView();

            // If this input view isn't null
            if (localView != null) {

                /*
                 * Gets the URL of the *weak reference* to the input
                 * ImageView. The weak reference won't have changed, even if
                 * the input ImageView has.
                 */
                // URL localURL = localView.getLocation();

                /*
                 * Compares the URL of the input ImageView to the URL of the
                 * weak reference. Only updates the bitmap in the ImageView
                 * if this particular Thread is supposed to be serving the
                 * ImageView.
                 */
                //if (attachmentTask.getImageURL() == localURL)

                /*
                 * Chooses the action to take, based on the incoming message
                 *
                 */
                //TODO: show the status properly based on message status ...
                switch (inputMessage.what) {

                case DOWNLOAD_STARTED:
                    localView.getMessage().setAttDownloadInProgress(true);
                    localView.getProressBar().setVisibility(View.VISIBLE);
                    break;
                case DOWNLOAD_COMPLETE:
                    localView.getProressBar().setProgress(70);
                    localView.getMessage().setAttDownloadInProgress(false);
                    break;
                case DECODE_STARTED:
                    localView.getProressBar().setVisibility(View.VISIBLE);
                    localView.getProressBar().setProgress(90);
                    break;
                /*
                 * The decoding is done, so this sets the
                 * ImageView's bitmap to the bitmap in the
                 * incoming message
                 */
                case TASK_COMPLETE:

                    if (localView.getDownloadProgressLayout() != null
                            && !localView.getMessage().isAttachmentUploadInProgress()) {
                        localView.getDownloadProgressLayout().setVisibility(View.GONE);
                    } else if (localView.getProressBar() != null) {
                        localView.getProressBar().setVisibility(View.GONE);
                    }
                    localView.setImageBitmap(attachmentTask.getImage());
                    recycleTask(attachmentTask);
                    break;
                // The download failed, sets the background color to dark red
                case DOWNLOAD_FAILED:
                    //localView.setStatusResource(R.drawable.imagedownloadfailed);
                    localView.getProressBar().setProgress(0);
                    localView.getMessage().setAttDownloadInProgress(false);
                    localView.getDownloadProgressLayout().setVisibility(View.GONE);
                    localView.setVisibility(View.INVISIBLE);
                    Toast.makeText(localView.getContext(), "Download failed.", Toast.LENGTH_SHORT).show();
                    // Attempts to re-use the Task object
                    recycleTask(attachmentTask);
                    break;
                default:
                    // Otherwise, calls the super method
                    super.handleMessage(inputMessage);
                }
            }
        }
    };
}

From source file:com.libreteam.taxi.Customer_Fragment_Activity.java

public void didReceiveCode(int code, String string) throws JSONException {
    switch (code) {
    case 0:/* w  w  w  .  j  a v a2  s. com*/
        break;
    case 1:
        try {
            ride_id = new JSONObject(string).getJSONObject("info").getString("ride_id").toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case 2:
    case 3:
        didCancelRide();
        break;
    case 4:
        Taxi_System.testLog(new JSONObject(string).getJSONObject("userinfo"));
        customer_token = new JSONObject(string).getJSONObject("info").getString("token").toString();
        latlng = new JSONObject(string).getJSONObject("userinfo").getString("latlng").toString();
        address = new JSONObject(new JSONObject(string).getString("userinfo")).getString("address");
        Taxi_System.addSystem(context, Customer_Constants.PICK_UP, address + "");
        didReceiveRide(
                new String[] { new JSONObject(string).getJSONObject("info").getString("ride_id").toString(),
                        new JSONObject(string).getJSONObject("info").getString("token").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("address").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("latlng").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("car_model").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("time").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("username").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("taxi_company").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("license_plate").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("avatar").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("des_lat").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("des").toString(),
                        new JSONObject(string).getJSONObject("userinfo").getString("start_lat").toString() });
        break;
    case 7:
        didGetCall(new String[] { new JSONObject(string).getJSONObject("userinfo").getString("name").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("taxi_company").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("car_model").toString(), ride_id,
                customer_token, latlng,
                new JSONObject(string).getJSONObject("userinfo").getString("des_lat").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("des_address").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("start_lat").toString(),
                new JSONObject(string).getJSONObject("userinfo").getString("latlng").toString() });
        break;
    case 11:
        driverLatLng = new LatLng(Double.valueOf(new JSONObject(string).getJSONObject("info").getString("lat")),
                Double.valueOf(new JSONObject(string).getJSONObject("info").getString("lng")));
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                new Customer_Boarding().didGetPosition(driverLatLng);
                new Customer_Finish_Rating().didGetPosition(driverLatLng);
            }
        });
        break;
    }
}

From source file:com.digium.respokesdk.RespokeGroup.java

/**
 *  Get an array containing the members of the group.
 *
 *  @param completionListener  A listener to receive a notification on the success of the asynchronous operation
 **/// w  ww  .  ja  v a2  s.  c  o  m
public void getMembers(final GetGroupMembersCompletionListener completionListener) {
    if (isJoined()) {
        if ((null != groupID) && (groupID.length() > 0)) {
            String urlEndpoint = "/v1/channels/" + groupID + "/subscribers/";

            signalingChannel.sendRESTMessage("get", urlEndpoint, null,
                    new RespokeSignalingChannel.RESTListener() {
                        @Override
                        public void onSuccess(Object response) {
                            JSONArray responseArray = null;

                            if (response != null) {
                                if (response instanceof JSONArray) {
                                    responseArray = (JSONArray) response;
                                } else if (response instanceof String) {
                                    try {
                                        responseArray = new JSONArray((String) response);
                                    } catch (JSONException e) {
                                        // An exception will trigger the error handler
                                    }
                                }
                            }

                            if (null != responseArray) {
                                final ArrayList<RespokeConnection> nameList = new ArrayList<RespokeConnection>();
                                RespokeClient client = clientReference.get();
                                if (null != client) {
                                    for (int ii = 0; ii < responseArray.length(); ii++) {
                                        try {
                                            JSONObject eachEntry = (JSONObject) responseArray.get(ii);
                                            String newEndpointID = eachEntry.getString("endpointId");
                                            String newConnectionID = eachEntry.getString("connectionId");

                                            // Do not include ourselves in this list
                                            if (!newEndpointID.equals(client.getEndpointID())) {
                                                // Get the existing instance for this connection, or create a new one if necessary
                                                RespokeConnection connection = client
                                                        .getConnection(newConnectionID, newEndpointID, false);

                                                if (null != connection) {
                                                    nameList.add(connection);
                                                }
                                            }
                                        } catch (JSONException e) {
                                            // Skip unintelligible records
                                        }
                                    }
                                }

                                // If certain connections present in the members array prior to this method are somehow no longer in the list received from the server, it's assumed a pending onLeave message will handle flushing it out of the client cache after this method completes
                                members.clear();
                                members.addAll(nameList);

                                new Handler(Looper.getMainLooper()).post(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (null != completionListener) {
                                            completionListener.onSuccess(nameList);
                                        }
                                    }
                                });
                            } else {
                                postGetGroupMembersError(completionListener, "Invalid response from server");
                            }
                        }

                        @Override
                        public void onError(final String errorMessage) {
                            postGetGroupMembersError(completionListener, errorMessage);
                        }
                    });
        } else {
            postGetGroupMembersError(completionListener, "Group name must be specified");
        }
    } else {
        postGetGroupMembersError(completionListener, "Not a member of this group anymore.");
    }
}

From source file:com.improvelectronics.sync.android.SyncStreamingService.java

@Override
public void onCreate() {
    super.onCreate();
    if (DEBUG)/*from w w  w  . j av  a2 s . c o m*/
        Log.d(TAG, "onCreate");

    // Set the default properties.
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    mMessageHandler = new MessageHandler(Looper.getMainLooper());
    mPairedDevices = new ArrayList<BluetoothDevice>();
    mPaths = new ArrayList<SyncPath>();
    mListeners = new ArrayList<SyncStreamingListener>();
    mState = STATE_DISCONNECTED;
    mMode = MODE_NONE;
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationBuilder = new NotificationCompat.Builder(this);
    mNotificationBuilder.setSmallIcon(R.drawable.ic_stat_notify_default);
    removeNotification();
    setupIntentFilter();

    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        // Bluetooth adapter isn't available.  The client of the service is supposed to
        // verify that it is available and activate before invoking this service.
        Log.e(TAG,
                "stopping sync streaming service, device does not have Bluetooth or Bluetooth is turned off");
        stopSelf();
    } else {
        updatePairedDevices();
        start();
    }
}

From source file:com.applozic.mobicomkit.api.attachment.AttachmentManager.java

/**
 * Constructs the work queues and thread pools used to download and decode images.
 *///  w w  w  .j a  va2 s.  co m
private AttachmentManager() {

    attachmentInProgress = new ArrayList<String>();
    attachmentTaskList = new ArrayList<AttachmentTask>();
    /*
     * Creates a work queue for the pool of Thread objects used for downloading, using a linked
     * list queue that blocks when the queue is empty.
     */
    mDownloadWorkQueue = new LinkedBlockingQueue<Runnable>();

    /*
     * Creates a work queue for the pool of Thread objects used for decoding, using a linked
     * list queue that blocks when the queue is empty.
     */
    mDecodeWorkQueue = new LinkedBlockingQueue<Runnable>();

    /*
     * Creates a work queue for the set of of task objects that control downloading and
     * decoding, using a linked list queue that blocks when the queue is empty.
     */
    mPhotoTaskWorkQueue = new LinkedBlockingQueue<AttachmentTask>();

    /*
     * Creates a new pool of Thread objects for the download work queue
     */
    mDownloadThreadPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, mDownloadWorkQueue);

    /*
     * Creates a new pool of Thread objects for the decoding work queue
     */
    mDecodeThreadPool = new ThreadPoolExecutor(NUMBER_OF_CORES, NUMBER_OF_CORES, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, mDecodeWorkQueue);

    // Instantiates a new cache based on the cache size estimate
    mPhotoCache = new LruCache<String, Bitmap>(IMAGE_CACHE_SIZE) {

        //            /*
        //             * This overrides the default sizeOf() implementation to return the
        //             * correct size of each cache entry.
        //             */
        //
        //            @Override
        //            protected int sizeOf(String paramURL, Bitmap image) {
        //                return image.getByteCount();
        //            }
    };
    /*
     * Instantiates a new anonymous Handler object and defines its
     * handleMessage() method. The Handler *must* run on the UI thread, because it moves photo
     * Bitmaps from the PhotoTask object to the View object.
     * To force the Handler to run on the UI thread, it's defined as part of the PhotoManager
     * constructor. The constructor is invoked when the class is first referenced, and that
     * happens when the View invokes startDownload. Since the View runs on the UI Thread, so
     * does the constructor and the Handler.
     */
    mHandler = new Handler(Looper.getMainLooper()) {

        /*
         * handleMessage() defines the operations to perform when the
         * Handler receives a new Message to process.
         */
        @Override
        public void handleMessage(Message inputMessage) {

            // Gets the image task from the incoming Message object.
            AttachmentTask attachmentTask = (AttachmentTask) inputMessage.obj;

            // Sets an PhotoView that's a weak reference to the
            // input ImageView
            AttachmentView localView = attachmentTask.getPhotoView();

            // If this input view isn't null
            if (localView != null) {

                /*
                 * Gets the URL of the *weak reference* to the input
                 * ImageView. The weak reference won't have changed, even if
                 * the input ImageView has.
                 */
                // URL localURL = localView.getLocation();

                /*
                 * Compares the URL of the input ImageView to the URL of the
                 * weak reference. Only updates the bitmap in the ImageView
                 * if this particular Thread is supposed to be serving the
                 * ImageView.
                 */
                //if (attachmentTask.getImageURL() == localURL)

                /*
                 * Chooses the action to take, based on the incoming message
                 *
                 */
                //TODO: show the status properly based on message status ...
                switch (inputMessage.what) {

                case DOWNLOAD_STARTED:
                    localView.getMessage().setAttDownloadInProgress(true);
                    localView.getProressBar().setVisibility(View.VISIBLE);
                    break;
                case DOWNLOAD_COMPLETE:
                    localView.getProressBar().setProgress(70);
                    localView.getMessage().setAttDownloadInProgress(false);
                    break;
                case DECODE_STARTED:
                    localView.getProressBar().setVisibility(View.VISIBLE);
                    localView.getProressBar().setProgress(90);
                    break;
                /*
                 * The decoding is done, so this sets the
                 * ImageView's bitmap to the bitmap in the
                 * incoming message
                 */
                case TASK_COMPLETE:

                    if (localView.getDownloadProgressLayout() != null
                            && !localView.getMessage().isAttachmentUploadInProgress()) {
                        localView.getDownloadProgressLayout().setVisibility(View.GONE);
                    } else if (localView.getProressBar() != null) {
                        localView.getProressBar().setVisibility(View.GONE);
                    }
                    BroadcastService.sendMessageUpdateBroadcast(localView.getContext(),
                            BroadcastService.INTENT_ACTIONS.MESSAGE_ATTACHMENT_DOWNLOAD_DONE.toString(),
                            localView.getMessage());
                    localView.setImageBitmap(attachmentTask.getImage());
                    recycleTask(attachmentTask);
                    break;
                // The download failed, sets the background color to dark red
                case DOWNLOAD_FAILED:
                    //localView.setStatusResource(R.drawable.imagedownloadfailed);
                    localView.getProressBar().setProgress(0);
                    localView.getMessage().setAttDownloadInProgress(false);
                    localView.getDownloadProgressLayout().setVisibility(View.GONE);
                    localView.setVisibility(View.INVISIBLE);
                    localView.cancelDownload();
                    BroadcastService.sendMessageUpdateBroadcast(localView.getContext(),
                            BroadcastService.INTENT_ACTIONS.MESSAGE_ATTACHMENT_DOWNLOAD_FAILD.toString(),
                            localView.getMessage());
                    Toast.makeText(localView.getContext(), "Download failed.", Toast.LENGTH_SHORT).show();
                    // Attempts to re-use the Task object
                    recycleTask(attachmentTask);
                    break;
                default:
                    // Otherwise, calls the super method
                    super.handleMessage(inputMessage);
                }
            }
        }
    };
}

From source file:com.frostwire.android.gui.activities.internal.NavigationMenu.java

private void refreshMenuRemoveAdsItem() {
    // only visible for basic or debug build and if ads have not been disabled.
    int visibility = ((Constants.IS_GOOGLE_PLAY_DISTRIBUTION || Constants.IS_BASIC_AND_DEBUG)
            && !Offers.disabledAds()) ? View.VISIBLE : View.GONE;
    Handler handler = new Handler(Looper.getMainLooper());
    // TODO: review why calling this directly was causing ANR
    // there is some lifecycle issue here
    handler.post(() -> menuRemoveAdsItem.setVisibility(visibility));
}

From source file:com.firefly.sample.castcompanionlibrary.cast.BaseCastManager.java

/************************************************************************/

protected BaseCastManager(Context context, String applicationId) {
    CCL_VERSION = context.getString(R.string.ccl_version);
    LOGD(TAG, "BaseCastManager is instantiated");
    mContext = context;/*from  w ww  . jav a2  s .  c o m*/
    mHandler = new Handler(Looper.getMainLooper());
    mApplicationId = applicationId;
    Utils.saveStringToPreference(mContext, PREFS_KEY_APPLICATION_ID, applicationId);

    LOGD(TAG, "Application ID is: " + mApplicationId);
    mMediaRouter = MediaRouter.getInstance(context);
    mMediaRouteSelector = new MediaRouteSelector.Builder()
            .addControlCategory(FlintMediaControlIntent.categoryForFlint(mApplicationId)).build();

    mMediaRouterCallback = new CastMediaRouterCallback(this, context);
    mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
            MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
}

From source file:eu.musesproject.client.usercontexteventhandler.UserContextEventHandler.java

/**
 *  Method to first check the local decision maker for a decision to the corresponding
 *      {@link eu.musesproject.client.contextmonitoring.service.aidl.Action}
 *
 *  Sends request to the server if there is no local stored decision /
 *      perform default procedure if the server is not reachable
 *
 * @param action {@link Action}//  w w w. j  a v a  2s .c  o  m
 * @param properties {@link Map}<String, String>
 * @param contextEvents {@link ContextEvent}
 */
public void send(Action action, Map<String, String> properties, List<ContextEvent> contextEvents) {
    Log.d(MusesUtils.TEST_TAG, "UCEH - send(action, prop, context_events)");
    Log.d(APP_TAG, "Action: " + action.getActionType());
    Log.d(TAG, "called: send(Action action, Map<String, String> properties, List<ContextEvent> contextEvents)");
    boolean onlineDecisionRequested = false;

    Decision decision = retrieveDecision(action, properties, contextEvents);

    if (decision != null) { // local decision found
        Log.d(APP_TAG, "Info DC, Local decision found, now calling actuator to showFeedback");
        Log.d(APP_TAG, "showFeedback1");
        ActuatorController.getInstance().showFeedback(decision);
    } else { // if there is no local decision, send a request to the server
        if (serverStatus == Statuses.ONLINE && isUserAuthenticated) { // if the server is online, request a decision
            // flag that an online decision is requested
            onlineDecisionRequested = true;

            // temporary store the information so that the decision can be made after the server responded with
            // an database update (new policies are sent from the server to the client and stored in the database)
            // In addition, add a timeout to every request
            final RequestHolder requestHolder = new RequestHolder(action, properties, contextEvents);
            Log.d(TAG_RQT, "1. send: request_id: " + requestHolder.getId());
            Handler handler = new Handler(Looper.getMainLooper());
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    requestHolder.setRequestTimeoutTimer(
                            new RequestTimeoutTimer(UserContextEventHandler.this, requestHolder.getId()));
                    requestHolder.getRequestTimeoutTimer().start();
                }
            }, 0);
            mapOfPendingRequests.put(requestHolder.getId(), requestHolder);

            // create the JSON request and send it to the server
            JSONObject requestObject = JSONManager.createJSON(getImei(), getUserName(), requestHolder.getId(),
                    RequestType.ONLINE_DECISION, action, properties, contextEvents);
            Log.d(APP_TAG,
                    "Info DC, No Local decision found, Sever is ONLINE, sending user data JSON(actions,properties,contextevnts) to server");
            sendRequestToServer(requestObject);
        } else if (serverStatus == Statuses.ONLINE && !isUserAuthenticated) {
            storeContextEvent(action, properties, contextEvents);
        } else if (serverStatus == Statuses.OFFLINE && isUserAuthenticated) {
            Log.d(APP_TAG, "showFeedback2");
            ActuatorController.getInstance().showFeedback(new DecisionMaker().getDefaultDecision());
            storeContextEvent(action, properties, contextEvents);
        } else if (serverStatus == Statuses.OFFLINE && !isUserAuthenticated) {
            storeContextEvent(action, properties, contextEvents);
        }
    }
    // update context events even if a local decision was found.
    // Prevent sending context events again if they are already sent for a online decision
    if ((!onlineDecisionRequested) && (serverStatus == Statuses.ONLINE) && isUserAuthenticated) {
        Log.d(APP_TAG, "Info DB, update context events even if a local decision was found.");

        RequestHolder requestHolder = new RequestHolder(action, properties, contextEvents);
        JSONObject requestObject = JSONManager.createJSON(getImei(), getUserName(), requestHolder.getId(),
                RequestType.LOCAL_DECISION, action, properties, contextEvents);
        sendRequestToServer(requestObject);
    }
}