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

public Handler() 

Source Link

Document

Default constructor associates this handler with the Looper for the current thread.

Usage

From source file:com.recursivepenguin.android.liveview.reddit.RedditService.java

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    // Create handler.
    if (mHandler == null) {
        mHandler = new Handler();
    }//  w w  w  . j  a v a 2  s .c  o  m

    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}

From source file:com.att.ads.sample.SpeechAuth.java

/**
 * Begin fetching the credentials asynchronously.
 * This must be invoked on a thread with a Looper,
 * and the client will be called back on this thread.
**///  w  ww .  j av a2s  .co m
public void fetchTo(Client client) {
    this.client = client;
    // TODO: prevent starting twice
    final Handler callingThread = new Handler();
    Thread reader = new Thread(connection.getURL().toString()) {
        @Override
        public void run() {
            performFetch(callingThread);
        }
    };
    reader.start();
}

From source file:es.wolfi.app.passman.CredentialDisplay.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        Vault v = (Vault) SingleTon.getTon().getExtra(SettingValues.ACTIVE_VAULT.toString());
        credential = v.findCredentialByGUID(getArguments().getString(CREDENTIAL));
    }//from  w  w  w  .  j a  v a  2s. c om

    handler = new Handler();
    otp_refresh = new Runnable() {
        @Override
        public void run() {
            int progress = (int) (System.currentTimeMillis() / 1000) % 30;
            otp_progress.setProgress(progress * 100);

            ObjectAnimator animation = ObjectAnimator.ofInt(otp_progress, "progress", (progress + 1) * 100);
            animation.setDuration(1000);
            animation.setInterpolator(new LinearInterpolator());
            animation.start();

            otp.setText(TOTPHelper.generate(new Base32().decode(credential.getOtp())));
            handler.postDelayed(this, 1000);
        }
    };
}

From source file:com.neudesic.mobile.pulse.ui.drawable.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {

    final Handler handler = new Handler() {
        @Override//w w w . jav  a2  s  . c o  m
        public void handleMessage(Message message) {
            try {
                imageView.setImageDrawable((Drawable) message.obj);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };

    Thread thread = new Thread() {

        @Override
        public void run() {
            // TODO : set imageView to a "pending" image
            try {
                Drawable drawable;
                if (drawableMap.containsKey(urlString)) {
                    // imageView.setImageDrawable(drawableMap.get(urlString));
                    drawable = drawableMap.get(urlString);

                } else {

                    drawable = fetchDrawable(urlString);
                }
                Message message = handler.obtainMessage(1, drawable);
                handler.sendMessage(message);
            } catch (Exception e) {
                Log.w(getClass().getPackage().getName(), "Unable to fetch drawable, using default instead", e);
                Message message = handler.obtainMessage(1, emptyAvatar);
                handler.sendMessage(message);
            }
        }
    };
    thread.start();
}

From source file:it.fdev.utils.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    }//  ww  w .jav a  2 s .co m
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            imageView.setImageDrawable((Drawable) message.obj);
        }
    };
    Thread thread = new Thread() {
        @Override
        public void run() {
            //TODO : set imageView to a "pending" image
            Drawable drawable = fetchDrawable(urlString);
            if (drawable != null) {
                Message message = handler.obtainMessage(1, drawable);
                handler.sendMessage(message);
            }
        }
    };
    thread.start();
}

From source file:com.applift.api.tester.activity.RenderedResponseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    confirmHandler = new Handler();
    try {//from   w ww . j  ava 2  s  . c  o  m
        ads = Ad.parseAds(this, format, json);
    } catch (Exception e) {
        L.wtf(e);
        return;
    }
    if (format == AdFormat.NATIVE) {
        adapter = new NativeFormatResponseAdapter(this, (List<NativeAd>) ads);
    } else {
        adapter = new ImageFormatResponseAdapter(this, (List<ImageAd>) ads);
    }
    backgroundRedirectRB.setChecked(true);
    listView.setAdapter(adapter);
    listView.setOnScrollListener(this);
    listView.setOnItemClickListener(this);
}

From source file:eu.andlabs.studiolounge.gcp.GCPService.java

@Override
public void onCreate() {
    super.onCreate();
    // mName = "LUKAS";
    mHandler = new Handler();
    log("starting GCP Service");
    connect();//from   w ww .  j  a v  a2s. c  o  m
}

From source file:com.jaguarlandrover.auto.remote.vehicleentry.LockActivityFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_lock, container, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    Typeface fontawesome = Typeface.createFromAsset(getActivity().getAssets(), "fonts/fontawesome-webfont.ttf");

    lock = (ImageButton) view.findViewById(R.id.lock);
    unlock = (ImageButton) view.findViewById(R.id.unlock);
    trunk = (ImageButton) view.findViewById(R.id.trunk);
    find = (ImageButton) view.findViewById(R.id.find);
    start = (ImageButton) view.findViewById(R.id.start);
    stop = (ImageButton) view.findViewById(R.id.stop);
    panic = (ImageButton) view.findViewById(R.id.panic);
    share = (ImageButton) view.findViewById(R.id.share);
    change = (ImageButton) view.findViewById(R.id.change);
    keylbl = (TextView) view.findViewById(R.id.keysharelbl);
    validDate = (TextView) view.findViewById(R.id.guestvalidDate);
    validTime = (TextView) view.findViewById(R.id.guestvalidTime);
    userHeader = (TextView) view.findViewById(R.id.user_header);
    vehicleHeader = (TextView) view.findViewById(R.id.vehicle_header);
    keyManagementLayout = (LinearLayout) view.findViewById(R.id.key_management_layout);
    //        panicOn = (Button) view.findViewById(R.id.panicOn);

    UserCredentials userCredentials = ServerNode.getUserCredentials();

    if (userCredentials == null) {
        setButtons(new UserCredentials());
    } else {/*ww w  . jav  a  2  s. c om*/
        setButtons(userCredentials);
    }

    buttonSet = new Handler();
    startRepeatingTask();

    lock.setOnClickListener(l);
    unlock.setOnClickListener(l);
    trunk.setOnClickListener(l);
    find.setOnClickListener(l);
    start.setOnClickListener(l);
    stop.setOnClickListener(l);
    panic.setOnClickListener(l);
    share.setOnClickListener(l);
    change.setOnClickListener(l);
    //        panicOn.setOnClickListener(l);

    buttonListener = (LockFragmentButtonListener) getActivity();
    return view;
}

From source file:gxu.software_engineering.market.android.ui.LoginBoxFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final View loginForm = getActivity().getLayoutInflater().inflate(R.layout.login, null);
    return new AlertDialog.Builder(getActivity(), android.R.style.Theme_Holo_Dialog)
            .setIcon(R.drawable.social_person).setTitle(R.string.login).setView(loginForm)
            .setNegativeButton(R.string.no, null).setPositiveButton(R.string.ok, new OnClickListener() {
                @Override/*from w w w  .  ja  v a  2s .  com*/
                public void onClick(DialogInterface dialog, int which) {
                    app = MarketApp.marketApp();

                    EditText e1 = (EditText) loginForm.findViewById(R.id.account);
                    final String account = e1.getEditableText().toString();
                    EditText e2 = (EditText) loginForm.findViewById(R.id.password);
                    final String password = e2.getEditableText().toString();

                    new Handler().post(new Runnable() {
                        @Override
                        public void run() {
                            Long uid = Long.MIN_VALUE;
                            try {
                                uid = new Login().execute(account, password).get();
                            } catch (Exception e) {
                                Toast.makeText(getActivity(), R.string.login_fail, Toast.LENGTH_SHORT).show();
                                return;
                            }

                            if (uid > 0) {
                                Log.i("login pwd!!!", password);
                                app.setLoginInfo(uid, account, password);
                            }

                            if (app.hasLogedIn()) {
                                Toast.makeText(getActivity(), R.string.login_ok, Toast.LENGTH_SHORT).show();
                                getActivity()
                                        .startActivity(new Intent(getActivity(), UserServiceActivity.class));
                            } else {
                                Toast.makeText(getActivity(), R.string.wrong_login_info, Toast.LENGTH_SHORT)
                                        .show();
                            }
                        }
                    });
                }
            }).create();
}

From source file:com.hybris.mobile.activity.LoginActivity.java

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

    setContentView(R.layout.activity_login);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    Fragment[] frags = { new LoginFragment(), new RegistrationFragment() };
    FragmentPagerAdapter adapter = new TabsAdapter(getFragmentManager(), frags);
    mViewPager.setAdapter(adapter);/*from  w ww  .  j  av  a  2 s .com*/
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    MyTabListener tabListener = new MyTabListener(mViewPager, actionBar);
    Tab tab = actionBar.newTab().setText(R.string.tab_login).setTabListener(tabListener);
    actionBar.addTab(tab);

    tab = actionBar.newTab().setText(R.string.tab_register).setTabListener(tabListener);
    actionBar.addTab(tab);
    actionBar.setSelectedNavigationItem(0);

    // Handler to handle different asynchronous cases:
    // - When the user arrives from the scanning activity and scan a barcode that needs the user to be logged in, 
    mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            // Error retrieving the data of the scanned value, we finish the activity and display a error message
            case BarCodeScannerActivity.MSG_DATA_ERROR:
                showMessage((String) msg.obj);
                finish();
                break;

            // Data available, we can start the activity associated with the intent
            case BarCodeScannerActivity.MSG_DATA_AVAILABLE:
                if (mIntentBarcodeAfterLogin != null) {
                    mIntentBarcodeAfterLogin.startActivity();
                    finish();
                }
                break;

            }

        }

    };

}