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.nhn.android.archetype.base.AABaseApplication.java

protected void initM2base() {

    // m2base code
    workExecutor = Executors.newCachedThreadPool();
    handler = new Handler(Looper.getMainLooper());
    backgroundHandlerThread = new HandlerThread("BandBackgroundHandlerThread");
    backgroundHandlerThread.start();// ww w.  j a  va  2s .co m
    backgroundHandler = new Handler(backgroundHandlerThread.getLooper());

    JsonWorker.init();

    logger.d("Application init completed.....");
}

From source file:com.samsung.msca.samsungvr.sdk.APIClientImpl.java

APIClientImpl(Context context, String endPoint, String apiKey, HttpPlugin.RequestFactory httpRequestFactory) {
    super(true);//from w  w  w.java 2s. c o  m

    mContext = context;
    mEndPoint = endPoint;
    mApiKey = apiKey;
    mHttpRequestFactory = httpRequestFactory;
    mMainHandler = new Handler(Looper.getMainLooper());

    if (DEBUG) {
        Log.d(TAG, "Created api client endpoint: " + mEndPoint + " apiKey: " + mApiKey + " obj: "
                + Util.getHashCode(this));
    }
}

From source file:com.appnexus.opensdk.mediatednativead.InMobiNativeAdResponse.java

public InMobiNativeAdResponse() {
    runnable = new Runnable() {
        @Override//  w ww. jav  a 2s.co m
        public void run() {
            if (coverImage != null) {
                coverImage.recycle();
                ;
                coverImage = null;
            }
            if (icon != null) {
                icon.recycle();
                icon = null;
            }
            nativeAdEventlistener = null;
            expired = true;
            if (imNative != null) {
                InMobiNative.unbind(registeredView);
                imNative = null;
            }
            if (nativeElements != null && !nativeElements.isEmpty()) {
                nativeElements.clear();
            }
            registeredView = null;
            registeredClickables = null;
        }
    };
    Handler handler = new Handler(Looper.getMainLooper());
    handler.postDelayed(runnable, Settings.NATIVE_AD_RESPONSE_EXPIRATION_TIME);

}

From source file:com.shivshankar.MyFirebaseMessagingService.java

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Log.d("TAGRK", "From: " + remoteMessage.getFrom());
    String message = "", title = "", strImageURL = "";
    if (remoteMessage.getData() != null && remoteMessage.getData().size() > 0) {
        Log.d("TAGRK", "Message data payload: " + remoteMessage.getData());

        message = "" + remoteMessage.getData().get(Config.MESSAGE_KEY);
        title = "" + remoteMessage.getData().get(Config.TITLE_KEY);
        strImageURL = "" + remoteMessage.getData().get(Config.IMAGE_KEY);
    } else if (remoteMessage.getNotification() != null) {
        Log.d("TAGRK", "Message Notification Body: " + remoteMessage.getNotification().getBody());
        message = "" + remoteMessage.getNotification().getBody();
        title = "" + remoteMessage.getNotification().getTitle();
        strImageURL = "" + remoteMessage.getNotification().getIcon();
    }/* w  ww .  j  a va2  s.  com*/

    if (strImageURL != null && !strImageURL.equals("") && !strImageURL.equals("null")) {
        Handler handler = new Handler(Looper.getMainLooper());
        final String finalTitle = title;
        final String finalMessage = message;
        final String finalStrImageURL = strImageURL;
        handler.post(new Runnable() {
            public void run() {
                new ServerAPICallImageBitmap(finalTitle, finalMessage, finalStrImageURL, "").execute();
            }
        });
    } else if (title.equalsIgnoreCase("Logout")) {
        try {
            SharedPreferences.Editor editor = AppPreferences.getPrefs().edit();
            editor.putString(commonVariables.KEY_LOGIN_ID, "0");
            editor.putBoolean(commonVariables.KEY_IS_LOG_IN, false);
            editor.putString(commonVariables.KEY_SELLER_PROFILE, "");
            editor.putString(commonVariables.KEY_BUYER_PROFILE, "");
            editor.putString(commonVariables.KEY_BRAND, "");
            editor.putBoolean(commonVariables.KEY_IS_BRAND, false);
            editor.putBoolean(commonVariables.KEY_IS_SELLER, false);
            editor.putBoolean(commonVariables.KEY_IS_SKIPPED_LOGIN_BUYER, false);
            editor.commit();
            android.os.Process.killProcess(android.os.Process.myPid());
            List<ApplicationInfo> packages;
            PackageManager pm;
            pm = getPackageManager();
            packages = pm.getInstalledApplications(0);

            ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            String myPackage = getApplicationContext().getPackageName();
            for (ApplicationInfo packageInfo : packages) {
                if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
                    continue;
                if (packageInfo.packageName.equals(myPackage))
                    continue;
                mActivityManager.killBackgroundProcesses(packageInfo.packageName);
            }
            mActivityManager.restartPackage(myPackage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else
        sendNotification(title, message);
    Log.i("TAGRK", "Received: " + remoteMessage.toString());
}

From source file:com.phonegap.plugins.speech.XSpeechRecognizer.java

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    this.callbackContext = callbackContext;
    Boolean isValidAction = true;

    if (ACTION_SPEECH_RECOGNIZE_START.equals(action)) {
        Handler loopHandler = new Handler(Looper.getMainLooper());
        loopHandler.post(new Runnable() {
            @Override//from   ww  w. ja  v  a2 s  .  com
            public void run() {
                recognizer = SpeechRecognizer.createSpeechRecognizer(cordova.getActivity().getBaseContext());
                recognizer.setRecognitionListener(new listener());
            }

        });
        startSpeechRecognitionActivity(args);
    } else if (ACTION_GET_SUPPORTED_LANGUAGES.equals(action)) {
        getSupportedLanguages();
    } else if (ACTION_SPEECH_RECOGNIZE_STOP.equals(action)) {
        stopSpeechRecognitionActivity();
    } else {
        this.callbackContext.error("Unknown action: " + action);
        isValidAction = false;
    }

    return isValidAction;
}

From source file:com.github.chenxiaolong.dualbootpatcher.appsharing.AppSharingService.java

private void onPackageRemoved(final String pkg) {
    RomInformation info;/*w  ww  . java2s .  c  o  m*/

    MbtoolConnection conn = null;

    try {
        conn = new MbtoolConnection(this);
        MbtoolInterface iface = conn.getInterface();

        info = RomUtils.getCurrentRom(this, iface);
    } catch (Exception e) {
        Log.e(TAG, "Failed to determine current ROM. App sharing status was NOT updated", e);
        return;
    } finally {
        IOUtils.closeQuietly(conn);
    }

    if (info == null) {
        Log.e(TAG, "Failed to determine current ROM. App sharing status was NOT updated");
        return;
    }

    // Unshare package if explicitly removed. This only exists to keep the config file clean.
    // Mbtool will not touch any app that's not listed in the package database.
    RomConfig config = RomConfig.getConfig(info.getConfigPath());
    HashMap<String, SharedItems> sharedPkgs = config.getIndivAppSharingPackages();
    if (sharedPkgs.containsKey(pkg)) {
        sharedPkgs.remove(pkg);
        config.setIndivAppSharingPackages(sharedPkgs);
        config.apply();

        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                String message = getString(R.string.indiv_app_sharing_app_no_longer_shared);
                Toast.makeText(AppSharingService.this, String.format(message, pkg), Toast.LENGTH_LONG).show();
            }
        });
    }
}

From source file:com.google.appinventor.components.runtime.util.ClientLoginHelper.java

private boolean isUiThread() {
    return Looper.getMainLooper().getThread().equals(Thread.currentThread());
}

From source file:Main.java

private static Handler getUiThreadHandler() {
    synchronized (sLock) {
        if (sUiThreadHandler == null) {
            if (sWillOverride) {
                throw new RuntimeException("Did not yet override the UI thread");
            }/*from  w w w. j  a v a 2  s  . c  om*/
            sUiThreadHandler = new Handler(Looper.getMainLooper());
        }
        return sUiThreadHandler;
    }
}

From source file:com.miz.service.MakeAvailableOffline.java

@Override
public void onCreate() {
    super.onCreate();

    mHandler = new Handler(Looper.getMainLooper());
}

From source file:android.support.test.espresso.base.ThreadPoolExecutorExtractor.java

private <T> FutureTask<T> runOnMainThread(final FutureTask<T> futureToRun) {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        final CountDownLatch latch = new CountDownLatch(1);
        mainHandler.post(new Runnable() {
            @Override/*from  w  ww .j av a  2s.  c o m*/
            public void run() {
                try {
                    futureToRun.run();
                } finally {
                    latch.countDown();
                }
            }
        });
        try {
            latch.await();
        } catch (InterruptedException ie) {
            if (!futureToRun.isDone()) {
                throw new RuntimeException("Interrupted while waiting for task to complete.");
            }
        }
    } else {
        futureToRun.run();
    }

    return futureToRun;
}