Example usage for android.os Handler Handler

List of usage examples for android.os Handler Handler

Introduction

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

Prototype

@UnsupportedAppUsage
public Handler(boolean async) 

Source Link

Document

Use the Looper for the current thread and set whether the handler should be asynchronous.

Usage

From source file:com.chess.genesis.activity.MsgBoxFrag.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    initBaseContentFrag(container);/*from   w  w  w  . j a  v a  2 s.  c om*/

    final View view = inflater.inflate(R.layout.fragment_msgbox, container, false);

    net = new NetworkClient(act, new Handler(this));
    progress = new ProgressMsg(act);

    // restore settings
    settings = (savedInstanceState != null) ? savedInstanceState : getArguments();
    gameid = settings.getString("gameid");

    final View btn = view.findViewById(R.id.submit_msg);
    btn.setOnClickListener(this);

    // disable touch on tabtext
    view.findViewById(R.id.tabtxt).setOnTouchListener(null);

    // set list adapters
    msglist_adapter = new MsgListAdapter(act, gameid);

    msglist_view = (ListView) view.findViewById(R.id.msg_list);
    msglist_view.setAdapter(msglist_adapter);

    // set empty view item
    final View empty = MsgListAdapter.getEmptyView(act);
    ((ViewGroup) msglist_view.getParent()).addView(empty);
    msglist_view.setEmptyView(empty);

    // scroll to bottom
    msglist_view.setSelection(msglist_view.getCount() - 1);

    return view;
}

From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferStatusUpdater.java

/**
 * This class is instantiated by TransferService.
 *//* w w  w.  j  a v  a  2 s.c o  m*/
TransferStatusUpdater(TransferDBUtil dbUtil) {
    this.dbUtil = dbUtil;
    mainHandler = new Handler(Looper.getMainLooper());
    transfers = new HashMap<Integer, TransferRecord>();
    lastUpdateTime = new HashMap<Integer, Long>();
}

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();/*from w  w w .j  a v a  2  s.  c  o  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 .j  a va 2 s .  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:ai.api.unityhelper.RecognitionHelper.java

public void initialize(Context context) {
    this.context = context;
    handler = new Handler(context.getMainLooper());
}

From source file:com.netdoers.utils.ApplicationLoader.java

@Override
public void onCreate() {
    super.onCreate();
    applicationContext = getApplicationContext();
    applicationHandler = new Handler(applicationContext.getMainLooper());
    applicationLoader = this;
    imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(applicationContext).build();
    preferences = new AppPreferences(this);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    ExceptionHandler.register(applicationLoader);
    //       initPlayServices();
    //       setUpFacebookSampler();
    //        startPushService();
}

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

public InMobiNativeAdResponse() {
    runnable = new Runnable() {
        @Override/*from w w w  .ja  va 2  s .c  o  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.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   w  w  w .  ja  v  a  2 s  . co  m*/
            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;//from ww  w  .j  av a  2  s.co  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: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 . ja va 2  s  .c  o  m
            sUiThreadHandler = new Handler(Looper.getMainLooper());
        }
        return sUiThreadHandler;
    }
}