Example usage for android.os Looper prepare

List of usage examples for android.os Looper prepare

Introduction

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

Prototype

public static void prepare() 

Source Link

Document

Initialize the current thread as a looper.

Usage

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
* initialize the OpenAdaptxt core//from  w w w .j  a  v  a2 s .  c  om
*/
public void initializeCore() {

    if (coreEngine == null) {
        //Log.w("Initialize Core","Starting...");
        new Thread(new Runnable() {
            public void run() {
                Looper.prepare();

                if (CoreEngineInitialize.initializeCore(getApplicationContext())) {
                    coreEngine = CoreEngineInitialize.getCoreInstance();
                    updateCorePrefs();
                    //Log.i("KPT Engine core","core initialized");
                } else {
                    //Log.e("KPT Engine core","core NOT initialized");
                }
            }
        }).start();
    }
}

From source file:io.realm.RealmTests.java

@Test
public void processLocalListenersAfterRefresh() throws InterruptedException {
    // Used to validate the result
    final AtomicBoolean listenerWasCalled = new AtomicBoolean(false);
    final AtomicBoolean typeListenerWasCalled = new AtomicBoolean(false);

    // Used by the background thread to wait for the main thread to do the write operation
    final CountDownLatch bgThreadLatch = new CountDownLatch(1);
    final CountDownLatch bgClosedLatch = new CountDownLatch(1);
    final CountDownLatch bgThreadReadyLatch = new CountDownLatch(1);

    Thread backgroundThread = new Thread() {
        @Override/*from ww w  .  ja v a2 s .  c o  m*/
        public void run() {
            // this will allow to register a listener.
            // we don't start looping to prevent the callback to be invoked via
            // the handler mechanism, the purpose of this test is to make sure refresh calls
            // the listeners.
            Looper.prepare();

            Realm bgRealm = Realm.getInstance(realmConfig);
            RealmResults<Dog> dogs = bgRealm.where(Dog.class).findAll();
            try {
                bgRealm.addChangeListener(new RealmChangeListener() {
                    @Override
                    public void onChange() {
                        listenerWasCalled.set(true);
                    }
                });
                dogs.addChangeListener(new RealmChangeListener() {
                    @Override
                    public void onChange() {
                        typeListenerWasCalled.set(true);
                    }
                });

                bgThreadReadyLatch.countDown();
                bgThreadLatch.await(); // Wait for the main thread to do a write operation
                bgRealm.refresh(); // This should call the listener
                assertTrue(listenerWasCalled.get());
                assertTrue(typeListenerWasCalled.get());
                bgRealm.close();
                bgRealm = null;
                // DON'T count down in the final block! The test will fail silently!!!
                bgClosedLatch.countDown();
            } catch (InterruptedException e) {
                fail(e.getMessage());
            } finally {
                if (bgRealm != null) {
                    bgRealm.close();
                }
            }
        }
    };
    backgroundThread.start();

    // Wait until bgThread finishes adding listener to the RealmResults. Otherwise same TableView version won't
    // trigger the listener.
    bgThreadReadyLatch.await();
    realm.beginTransaction();
    realm.createObject(Dog.class);
    realm.commitTransaction();
    bgThreadLatch.countDown();
    bgClosedLatch.await();
}

From source file:dentex.youtube.downloader.DashboardActivity.java

public void ffmpegJob(final File fileToConvert, final String bitrateType, final String bitrateValue) {
    BugSenseHandler.leaveBreadcrumb("ffmpegJob");
    isFfmpegRunning = true;//from  w  w  w .jav a2  s. c  om

    vfilename = currentItem.getFilename();

    // audio job notification init
    aBuilder = new NotificationCompat.Builder(this);
    aNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    aBuilder.setSmallIcon(R.drawable.ic_stat_ytd);
    aBuilder.setContentTitle(vfilename);

    String aExt = currentItem.getAudioExt();
    basename = currentItem.getBasename();

    final String audioFileName;
    // "compose" the audio file
    if (bitrateValue != null) {
        extrTypeIsMp3Conv = true;
        audioFileName = basename + "_" + bitrateType + "-" + bitrateValue + ".mp3";
    } else {
        extrTypeIsMp3Conv = false;
        audioFileName = basename + aExt;

    }

    audioFile = new File(fileToConvert.getParent(), audioFileName);

    if (!audioFile.exists()) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Looper.prepare();

                FfmpegController ffmpeg = null;
                try {
                    ffmpeg = new FfmpegController(DashboardActivity.this);

                    // Toast + Notification + Log ::: Audio job in progress...
                    String text = null;
                    if (!extrTypeIsMp3Conv) {
                        text = getString(R.string.audio_extr_progress);
                        type = YTD.JSON_DATA_TYPE_A_E;
                    } else {
                        text = getString(R.string.audio_conv_progress);
                        type = YTD.JSON_DATA_TYPE_A_M;
                    }
                    Toast.makeText(DashboardActivity.this, "YTD: " + text, Toast.LENGTH_LONG).show();

                    aBuilder.setContentTitle(audioFileName);
                    aBuilder.setContentText(text);
                    aBuilder.setOngoing(true);
                    aNotificationManager.notify(2, aBuilder.build());
                    Utils.logger("i", vfilename + " " + text, DEBUG_TAG);
                } catch (IOException ioe) {
                    Log.e(DEBUG_TAG, "Error loading ffmpeg. " + ioe.getMessage());
                }

                ShellDummy shell = new ShellDummy();

                try {
                    ffmpeg.extractAudio(fileToConvert, audioFile, bitrateType, bitrateValue, shell);
                } catch (IOException e) {
                    Log.e(DEBUG_TAG, "IOException running ffmpeg" + e.getMessage());
                } catch (InterruptedException e) {
                    Log.e(DEBUG_TAG, "InterruptedException running ffmpeg" + e.getMessage());
                }
                Looper.loop();
            }
        }).start();
    } else {
        PopUps.showPopUp(getString(R.string.long_press_warning_title),
                getString(R.string.audio_extr_warning_msg), "info", DashboardActivity.this);
        isFfmpegRunning = false;
    }
}

From source file:com.rener.sea.DBHelper.java

public void syncDB() {
    if (Looper.myLooper() == null)
        Looper.prepare();
    new ServerCalls().execute("SYNC");
    //        String device_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    ///*from  w  w w.  j  av a2 s  . c  o  m*/
    //        Log.i(this.toString(), "HTTP Sync called ");
    //        //Create AsycHttpClient object
    //        AsyncHttpClient client = new AsyncHttpClient();
    //        RequestParams params = new RequestParams();
    //        params.put(DBSchema.POST_DEVICE_ID, device_id);
    //
    //        if (!isEmpty() || userSW) { // initial sync is FULL
    //            params.put(DBSchema.POST_SYNC_TYPE, DBSchema.SYNC_FULL);
    //            client.post(DBSchema.SYNC_URL, params, new JsonHttpResponseHandler() {
    //                @Override
    //                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
    //
    //                    Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONObject = " + response.toString());
    //                    SQLiteDatabase db = getWritableDatabase();
    //                    try {
    //
    //                        JSONObject status = response.getJSONObject(DBSchema.POST_SYNC_INF);
    //                        if (status.getInt(DBSchema.SYNC_STATUS) == DBSchema.STATUS_SUCCESS) {
    //                            setLocalData(response.getJSONObject(DBSchema.POST_SERVER_DATA_NEW));
    //                        } else {
    //
    //                            Log.i(this.toString(), "HTTP Sync success Transaction fail FULL");
    //                        }
    //
    //                    } catch (JSONException e) {
    //
    //                        e.printStackTrace();
    //                    }
    //                    try {
    //                        JSONObject localJSONObject = response.getJSONObject(DBSchema.POST_SYNC_INF);
    //                        Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", localJSON = " + localJSONObject.toString());
    //                    } catch (JSONException e) {
    //                        e.printStackTrace();
    //                    }
    //                    Intent intent = new Intent();
    //                    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                    intent.setAction("SYNC");
    //                    intent.putExtra("SYNC_RESULT", DBSchema.SYNC_SUCCESS);
    //                    context.sendBroadcast(intent);
    //
    //                }
    //
    //                @Override
    //                public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
    //                    Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONArray = " + response.toString());
    //
    //                }
    //
    //                @Override
    //                public void onFailure(int statusCode, Header[] headers, String response, Throwable error) {
    //                    Log.i(this.toString(), "HTTP Sync failure : statusCode = " + statusCode + ", Header = " + headers.toString() + ", response = " + response);
    //                    switch (statusCode) {
    //                        case 404:
    //                            Intent intent404 = new Intent();
    //                            intent404.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent404.setAction("SYNC");
    //                            intent404.putExtra("SYNC_RESULT", 404);
    //                            context.sendBroadcast(intent404);
    //                            Toast.makeText(context, "Requested resource not found", Toast.LENGTH_LONG).show();// resource Not Found
    //                            break;
    //                        case 500:
    //                            Intent intent500 = new Intent();
    //                            intent500.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent500.setAction("SYNC");
    //                            intent500.putExtra("SYNC_RESULT", 500);
    //                            context.sendBroadcast(intent500);
    //                            Toast.makeText(context, "Internal server error", Toast.LENGTH_LONG).show();// Internal Server Error
    //                            break;
    //                        default:
    //                            Intent intent = new Intent();
    //                            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent.setAction("SYNC");
    //                            intent.putExtra("SYNC_RESULT", DBSchema.STATUS_ERROR);
    //                            context.sendBroadcast(intent);
    //                            Toast.makeText(context, "NPI", Toast.LENGTH_LONG).show();// no se que paso
    //                            break;
    //
    //
    //                    }
    //                }
    //
    //
    //            });
    //
    ////            result.isFinished();
    ////            setSyncDone(data);
    //
    //        } else { // database incremental
    //            String prefKey = context.getResources().getString(R.string.preference_file_key);
    //            String usernameKey = context.getResources().getString(R.string.key_saved_username);
    //            SharedPreferences sharedPref = context.getSharedPreferences(prefKey, Context.MODE_PRIVATE);
    //            String sUsername = sharedPref.getString(usernameKey, null);
    //            User currentUser = findUserByUsername(sUsername);
    //            long userID = currentUser.getId();
    //            String type = currentUser.getType();
    //            Log.i(this.toString(), "DEVICE ID = " + String.valueOf(device_id));
    //            params.put(DBSchema.POST_SYNC_TYPE, DBSchema.SYNC_INC);
    //            params.put(DBSchema.POST_USER_ID, userID);
    //            params.put(DBSchema.POST_USER_TYPE, type);
    //
    //            dataSync = getData();
    //
    //            params.put(DBSchema.POST_LOCAL_DATA, dataSync);
    //
    //            client.post(DBSchema.SYNC_URL, params, new JsonHttpResponseHandler() {
    //                @Override
    //                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
    //
    //                    Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONObject = " + response.toString());
    //                    SQLiteDatabase db = getWritableDatabase();
    //
    //                    try {
    //
    //
    //                        JSONObject status = response.getJSONObject(DBSchema.POST_SYNC_INF);
    //                        if (status.getInt(DBSchema.SYNC_STATUS) == DBSchema.STATUS_SUCCESS) {
    //
    //                            setLocalData(response.getJSONObject(DBSchema.POST_SERVER_DATA_NEW));
    //                            if (!userSW)
    //                                deleteLocalData(response.getJSONObject(DBSchema.POST_SERVER_DATA_DELETED));
    //
    //                        } else {
    //
    //                            Log.i(this.toString(), "HTTP Sync success Transaction fail INCREMENTAL");
    //                        }
    //
    //
    //                    } catch (JSONException e) {
    //
    //                        e.printStackTrace();
    //                    }
    //
    //                    Intent intent = new Intent();
    //                    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                    intent.setAction("SYNC");
    //                    intent.putExtra("SYNC_RESULT", DBSchema.SYNC_SUCCESS);
    //                    context.sendBroadcast(intent);
    //                    try {
    //                        JSONObject syncInf = response.getJSONObject(DBSchema.POST_SYNC_INF);
    //                        long status = syncInf.getLong(DBSchema.SYNC_STATUS);
    //                        Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + "server sync status response = " + status);
    //                        String local_data = syncInf.getString("local_data");
    //                        Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + "JSON of local data from server = " + local_data);
    //                        if (status == DBSchema.STATUS_SUCCESS) {
    //                            setSyncDone();
    //                        }
    //                    } catch (JSONException e) {
    //                        e.printStackTrace();
    //                    }
    //                    try {
    //                        JSONObject syncJSONObject = response.getJSONObject(DBSchema.POST_SYNC_INF);
    //                        Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", sysncJSON = " + syncJSONObject.toString());
    //                    } catch (JSONException e) {
    //
    //                        e.printStackTrace();
    //                    }
    //
    //                }
    //
    //                @Override
    //                public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
    //                    Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONArray = " + response.toString());
    //
    //                }
    //
    //                @Override
    //                public void onFailure(int statusCode, Header[] headers, String response, Throwable error) {
    //                    Log.i(this.toString(), "HTTP Sync failure : statusCode = " + statusCode + ", Header = " + headers.toString() + ", response = " + response);
    //                    switch (statusCode) {
    //                        case 404:
    //                            Intent intent404 = new Intent();
    //                            intent404.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent404.setAction("SYNC");
    //                            intent404.putExtra("SYNC_RESULT", 404);
    //                            context.sendBroadcast(intent404);
    //                            Toast.makeText(context, "Requested resource not found", Toast.LENGTH_LONG).show();// resource Not Found
    //                            break;
    //                        case 500:
    //                            Intent intent500 = new Intent();
    //                            intent500.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent500.setAction("SYNC");
    //                            intent500.putExtra("SYNC_RESULT", 500);
    //                            context.sendBroadcast(intent500);
    //                            Toast.makeText(context, "Internal server error", Toast.LENGTH_LONG).show();// Internal Server Error
    //                            break;
    //                        default:
    //                            Intent intent = new Intent();
    //                            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent.setAction("SYNC");
    //                            intent.putExtra("SYNC_RESULT", DBSchema.STATUS_ERROR);
    //                            context.sendBroadcast(intent);
    //                            Toast.makeText(context, "NPI", Toast.LENGTH_LONG).show();// no se que paso
    //                            break;
    //
    //
    //                    }
    //                }
    //
    //
    //            });
    //
    //        }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

private String getUserAgent() {
    try {//from   w ww .  j  a v a 2s  .com
        String userAgent = System.getProperty("http.agent");
        if (userAgent != null) {
            return userAgent;
        }
    } catch (Exception e) {
    }
    if (getActivity() == null) {
        return "Android-CN1";
    }
    try {
        Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class,
                WebView.class);
        constructor.setAccessible(true);
        try {
            WebSettings settings = constructor.newInstance(getActivity(), null);
            return settings.getUserAgentString();
        } finally {
            constructor.setAccessible(false);
        }
    } catch (Exception e) {
        final StringBuffer ua = new StringBuffer();
        if (Thread.currentThread().getName().equalsIgnoreCase("main")) {
            WebView m_webview = new WebView(getActivity());
            ua.append(m_webview.getSettings().getUserAgentString());
            m_webview.destroy();
        } else {
            final boolean[] flag = new boolean[1];
            Thread thread = new Thread() {
                public void run() {
                    Looper.prepare();
                    WebView m_webview = new WebView(getActivity());
                    ua.append(m_webview.getSettings().getUserAgentString());
                    m_webview.destroy();
                    Looper.loop();
                    flag[0] = true;
                    synchronized (flag) {
                        flag.notify();
                    }
                }
            };
            thread.setUncaughtExceptionHandler(AndroidImplementation.exceptionHandler);
            thread.start();
            while (!flag[0]) {
                synchronized (flag) {
                    try {
                        flag.wait(100);
                    } catch (InterruptedException ex) {
                    }
                }
            }
        }
        return ua.toString();
    }
}

From source file:com.rener.sea.DBHelper.java

public void syncDBFull() {

    deleteDB();// w w w  .j  a v a  2s  . co m
    getDummy();
    if (Looper.myLooper() == null)
        Looper.prepare();
    new ServerCalls().execute("SYNC_FULL");
    //        String device_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    //        String prefKey = context.getResources().getString(R.string.preference_file_key);
    //        String usernameKey = context.getResources().getString(R.string.key_saved_username);
    //        SharedPreferences sharedPref = context.getSharedPreferences(prefKey, Context.MODE_PRIVATE);
    //        String sUsername = sharedPref.getString(usernameKey, null);
    //        long userID = findUserByUsername(sUsername).getId();
    //        Log.i(this.toString(), "HTTP Sync called ");
    //
    //        AsyncHttpClient client = new AsyncHttpClient();
    //        RequestParams params = new RequestParams();
    //
    //        params.put(DBSchema.POST_SYNC_TYPE, DBSchema.SYNC_FULL);
    //        params.put(DBSchema.POST_DEVICE_ID, device_id);
    //
    //        client.post(DBSchema.SYNC_URL, params, new JsonHttpResponseHandler() {
    //            @Override
    //            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
    //
    //                Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONObject = " + response.toString());
    //
    //
    //                try {
    //                    setUsers(response.getJSONObject(DBSchema.POST_SERVER_DATA_NEW).getJSONArray(DBSchema.TABLE_USERS));
    //                } catch (JSONException e) {
    //                    e.printStackTrace();
    //                }
    //                // initialize sequences
    //                try {
    //                    JSONObject status = response.getJSONObject(DBSchema.POST_SYNC_INF);
    //                    if (status.getInt(DBSchema.SYNC_STATUS) == DBSchema.STATUS_SUCCESS) {
    //
    //                        setLocalData(response.getJSONObject(DBSchema.POST_SERVER_DATA_NEW));
    //
    //                    } else {
    //
    //                        Log.i(this.toString(), "HTTP Sync success Transaction fail syncDBFull");
    //                    }
    //
    //                } catch (JSONException e) {
    //
    //                    e.printStackTrace();
    //                }
    //
    //                Intent intent = new Intent();
    //                intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                intent.setAction("SYNC_FULL");
    //                intent.putExtra("SYNC_RESULT", DBSchema.SYNC_SUCCESS);
    //                context.sendBroadcast(intent);
    //
    //            }
    //
    //            @Override
    //            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
    //                Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONArray = " + response.toString());
    //
    //            }
    //
    //            @Override
    //            public void onFailure(int statusCode, Header[] headers, String response, Throwable error) {
    ////                Log.i(this.toString(), "HTTP Sync failure : statusCode = " + statusCode + ", Header = " + headers.toString() + ", response = " + response);
    //                switch (statusCode) {
    //                    case 404:
    //                        Intent intent404 = new Intent();
    //                        intent404.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                        intent404.setAction("SYNC_FULL");
    //                        intent404.putExtra("SYNC_RESULT", 404);
    //                        context.sendBroadcast(intent404);
    //                        Toast.makeText(context, "Requested resource not found", Toast.LENGTH_LONG).show();// resource Not Found
    //                        break;
    //                    case 500:
    //                        Intent intent500 = new Intent();
    //                        intent500.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                        intent500.setAction("SYNC_FULL");
    //                        intent500.putExtra("SYNC_RESULT", 500);
    //                        context.sendBroadcast(intent500);
    //                        Toast.makeText(context, "Internal server error", Toast.LENGTH_LONG).show();// Internal Server Error
    //                        break;
    //                    default:
    //                        Intent intent = new Intent();
    //                        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                        intent.setAction("SYNC_FULL");
    //                        intent.putExtra("SYNC_RESULT", DBSchema.STATUS_ERROR);
    //                        context.sendBroadcast(intent);
    //                        Toast.makeText(context, "NPI", Toast.LENGTH_LONG).show();// no se que paso
    //                        break;
    //
    //
    //                }
    //            }
    //
    //
    //        });

}

From source file:com.rener.sea.DBHelper.java

public void loginAuthentication(String username, String password) {
    if (Looper.myLooper() == null)
        Looper.prepare();
    new ServerCalls().execute("LOGIN", username, password);
    //        final String device_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    ///*from ww w. j  av  a 2  s  .  c  om*/
    //        Log.i(this.toString(), "HTTP Login call");
    //
    //        AsyncHttpClient client = new AsyncHttpClient();
    //        RequestParams params = new RequestParams();
    //
    //        params.put(DBSchema.AUTH_USER, username);
    //        params.put(DBSchema.AUTH_PASS, password);
    //        params.put(DBSchema.AUTH_DEVICE, device_id);
    //
    //        client.post(DBSchema.AUTH_URL, params, new JsonHttpResponseHandler() {
    //            @Override
    //            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
    //
    //                Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONObject = " + response.toString());
    //                //'device' => 0, 'user' => 0, 'hash' => 0, 'id' => $device, 'seq' => -1
    //                try {
    //                    boolean device = response.getBoolean("device");
    //                    boolean user = response.getBoolean("user");
    //                    boolean switchUser = response.getBoolean("flag");
    //                    String hash = response.getString("hash");
    //                    String deviceID = response.getString("id");
    //                    long seq = response.getLong("seq");
    //
    //                    if (device_id.equals(deviceID) && device && user) { // the responce come fro the server, user and passw corect
    //                        SharedPreferences sharedPref = context.getSharedPreferences(
    //                                context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    //                        SharedPreferences.Editor editor = sharedPref.edit();
    //                        editor.putString(context.getString(R.string.key_saved_passhash), hash);
    //                        editor.apply();
    //                        // sync db
    //                        if (switchUser) {
    ////                            syncDB();
    ////                            syncDBFull();
    //                            Intent intent = new Intent();
    //                            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent.setAction("AUTH");
    //                            intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_SUCCESS_NEW_USER);
    //                            context.sendBroadcast(intent);
    //
    //                        } else {
    //                            Intent intent = new Intent();
    //                            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent.setAction("AUTH");
    //                            intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_SUCCESS);
    //                            context.sendBroadcast(intent);
    //                        }
    //
    //                    }
    //                    if (device_id.equals(deviceID) && device && !user) { // the response come fro the server, the device exist but wrong credentials
    //
    //                        Intent intent = new Intent();
    //                        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                        intent.setAction("AUTH");
    //                        intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_FAIL);
    //                        context.sendBroadcast(intent);
    //
    //                    } else if (!device) { // new device
    //                        getDummy();
    //                        setSequence(seq);
    //                        if (user) { // user credentials are ok
    //                            SharedPreferences sharedPref = context.getSharedPreferences(
    //                                    context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    //                            SharedPreferences.Editor editor = sharedPref.edit();
    //                            editor.putString(context.getString(R.string.key_saved_passhash), hash);
    //                            editor.apply();
    //                            Intent intent = new Intent();
    //                            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent.setAction("AUTH");
    //                            intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_SUCCESS_NEW_USER);
    //                            context.sendBroadcast(intent);
    ////                            syncDBFull();
    //
    //                        } else { // user credentials are wrong
    //                            Intent intent = new Intent();
    //                            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                            intent.setAction("AUTH");
    //                            intent.putExtra("AUTH_RESULT", DBSchema.LOGIN_FAIL);
    //                            context.sendBroadcast(intent);
    //                        }
    //                    } else {
    //                        Intent intent = new Intent();
    //                        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                        intent.setAction("AUTH");
    //                        intent.putExtra("AUTH_RESULT", DBSchema.STATUS_ERROR);
    //                        context.sendBroadcast(intent);
    //                    }
    //
    //
    //                } catch (JSONException e) {
    //                    e.printStackTrace();
    //                }
    //
    ////                Intent intent = new Intent();
    ////                intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    ////                intent.setAction("SYNC");
    ////                intent.putExtra("SYNC_RESULT", 200);
    ////                context.sendBroadcast(intent);
    //
    //            }
    //
    //            @Override
    //            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
    //                Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONArray = " + response.toString());
    //
    //            }
    //
    //            @Override
    //            public void onFailure(int statusCode, Header[] headers, String response, Throwable error) {
    //                Log.i(this.toString(), "HTTP Sync failure : statusCode = " + statusCode + ", Header = " + headers.toString() + ", response = " + response);
    //                switch (statusCode) {
    //                    case 404:
    //                        Intent intent404 = new Intent();
    //                        intent404.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                        intent404.setAction("AUTH");
    //                        intent404.putExtra("AUTH_RESULT", 404);
    //                        context.sendBroadcast(intent404);
    //                        Toast.makeText(context, "Requested resource not found", Toast.LENGTH_LONG).show();// resource Not Found
    //                        break;
    //                    case 500:
    //                        Intent intent500 = new Intent();
    //                        intent500.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                        intent500.setAction("AUTH");
    //                        intent500.putExtra("AUTH_RESULT", 500);
    //                        context.sendBroadcast(intent500);
    //                        Toast.makeText(context, "Internal server error", Toast.LENGTH_LONG).show();// Internal Server Error
    //                        break;
    //                    default:
    //                        Intent intent = new Intent();
    //                        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    //                        intent.setAction("AUTH");
    //                        intent.putExtra("AUTH_RESULT", DBSchema.STATUS_ERROR);
    //                        context.sendBroadcast(intent);
    //                        Toast.makeText(context, "NPI", Toast.LENGTH_LONG).show();// no se que paso
    //                        break;
    //
    //
    //                }
    //            }
    //
    //
    //        });

}