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:cn.com.lowe.android.tools.net.response.HttpResponseHandler.java

/**
 * Creates a new AsyncHttpResponseHandler
 *//*from  ww w. j  a v  a2  s  .co m*/
public HttpResponseHandler() {
    if (Looper.myLooper() != null) {
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                HttpResponseHandler.this.handleMessage(msg);
            }
        };
    }
}

From source file:com.tundem.alternativefindr.SplashscreenActivity.java

/** Called when the activity is first created. */
@Override/*from   w  ww  .j  a v a 2s.  c  o  m*/
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.act_splashscreen);

    init_actionbar();

    View v = this.findViewById(R.id.layout);
    animate(v).setDuration(0).alpha(0).start();
    animate(v).setDuration(1000).alpha(1).start();

    //Check if there's an internet connection
    if (!CheckNetworkStatus.haveNetworkConnection(this)) {
        CustomToast.makeCustomToast(this, getString(R.string.nointernet), 3000);
        SplashscreenActivity.this.finish();
    } else {
        LicenseTask lTask = new LicenseTask();
        lTask.execute();
        PlatformsTask pTask = new PlatformsTask();
        pTask.execute();

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (!SplashscreenActivity.this.isFinishing() && isLicenseReady && isPlatformsReady) {
                    finishiing();
                } else {
                    timeOver = true;
                }
            }
        }, SPLASHTIME);
    }
}

From source file:com.github.volley_examples.Act_JsonRequest.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.act__json_request);

    lvWeather = (ListView) findViewById(R.id.lvWeather);

    mQueue = Volley.newRequestQueue(this);
    //getWeatherInfo();
    //{"weatherinfo":{"city":"","cityid":"101280101","temp":"12","WD":"","WS":"2","SD":"95%",
    //"WSE":"2","time":"21:05","isRadar":"1","Radar":"JC_RADAR_AZ9200_JB"}}

    final Handler handler = new Handler() {
        @Override/*  w  w w  . j  av  a 2s  . com*/
        public void handleMessage(Message msg) {
            // super.handleMessage(msg);
            init();
        }
    };

    Runnable update_thread = new Runnable() {
        public void run() {
            getWeatherInfo();
            handler.sendEmptyMessageDelayed(99, 2000);

        }
    };

    handler.postDelayed(update_thread, 300);

}

From source file:net.networksaremadeofstring.pulsant.portal.ViewTicket.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewticket);
    list = (ListView) findViewById(R.id.TicketUpdatesList);

    final ProgressDialog dialog = ProgressDialog.show(this, "Pulsant Portal", "Please wait: loading data....",
            true);//  ww w.  jav  a  2s  .  c  om
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                TicketUpdatesAdaptor adapter = new TicketUpdatesAdaptor(ViewTicket.this, listOfUpdates,
                        API.SessionID);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                TicketAPI = API.PortalQuery("updates", getIntent().getStringExtra("ticketID"));
                Success = TicketAPI.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occured. Error Code: 1";
                Log.e("APIFuncs", e.getMessage());
            }

            if (Success.equals("false")) {
                try {
                    Log.i("APIFuncs", TicketAPI.toString(3));
                    ErrorMessage = TicketAPI.getString("msg");
                } catch (JSONException e) {
                    ErrorMessage = e.getMessage();
                    Log.e("APIFuncs", e.getMessage());
                }
                handler.sendEmptyMessage(0);
            } else {
                Log.i("APIFuncs", TicketAPI.toString());
                try {
                    Updates = TicketAPI.getJSONArray("updates");
                    ErrorMessage = "";
                } catch (JSONException e) {
                    ErrorMessage = "There are no updates for this ticket. (Strange!)";
                }

                int TicketCount = Updates.length();

                if (TicketCount == 0) {
                    ErrorMessage = "There are no updates for this ticket.";
                    return;
                }

                for (int i = 0; i < TicketCount; i++) {
                    try {
                        CurrentTicket = Updates.getJSONObject(i);

                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }

                    if (CurrentTicket != null) {
                        listOfUpdates.add(new TicketUpdates(GetString("type"), GetString("name"),
                                GetInt("time"), GetString("content")));
                    }
                }
                handler.sendEmptyMessage(0);
            }

        }
    };

    dataPreload.start();

    Button AddReply = (Button) findViewById(R.id.AddReplyButton);
    AddReply.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent CreateTicketReplyIntent = new Intent(ViewTicket.this, AddTicketReply.class);
            CreateTicketReplyIntent.putExtra("sessionid", API.SessionID);
            CreateTicketReplyIntent.putExtra("ticketid", getIntent().getStringExtra("ticketID"));
            ViewTicket.this.startActivity(CreateTicketReplyIntent);
        }
    });

    /*
    try 
    {
       TicketAPI = API.PortalQuery("updates", getIntent().getStringExtra("ticketID"));
      Success = TicketAPI.getString("success");   
    } 
    catch (JSONException e) 
    {
       UpdateErrorMessage("An unrecoverable JSON Exception occured. Error Code: 1");
       Log.e("APIFuncs",e.getMessage());
       //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show();
    }
            
    if(Success == "false")
    {
       try 
       {
     Log.i("APIFuncs",TicketAPI.toString(3));
    UpdateErrorMessage(TicketAPI.getString("msg"));
      } 
       catch (JSONException e) 
       {
     Log.e("APIFuncs",e.getMessage());
     UpdateErrorMessage("An unrecoverable JSON Exception occured.  Error Code: 2");
      }
    }
    else
    {
       Log.i("APIFuncs",TicketAPI.toString());
       try
        {
     Updates = TicketAPI.getJSONArray("updates");
      UpdateErrorMessage("");
        }
        catch (JSONException e) 
        {
      UpdateErrorMessage("There are no updates for this ticket. (Strange!)");
        }
                
        //OK lets actually do something useful
        List<TicketUpdates> listOfUpdates = new ArrayList<TicketUpdates>();
        int TicketCount = Updates.length();
                
        if(TicketCount == 0)
        {
      UpdateErrorMessage("There are no updates for this ticket.");
      return;
        }
                
        for(int i = 0; i < TicketCount; i++)
        {
    try 
    {
       CurrentTicket = Updates.getJSONObject(i);
            
    } 
    catch (JSONException e1) 
    {
       Log.e("APIFuncs",e1.getMessage());
    }
            
    if(CurrentTicket != null)
    {
       listOfUpdates.add(new TicketUpdates(GetString("type"),
            GetString("name"), 
            GetInt("time"), 
            GetString("content")));
    }
        }
        TicketUpdatesAdaptor adapter = new TicketUpdatesAdaptor(this, listOfUpdates, API.SessionID);
                
        list.setAdapter(adapter);
    }*/
}

From source file:be.vbsteven.bmtodesk.SendAllCurrentBookmarksActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    setTheme(android.R.style.Theme_Light_NoTitleBar);
    super.onCreate(savedInstanceState);
    handler = new Handler();

    setContentView(R.layout.sendallcurrent);

    final Button button = (Button) findViewById(R.id.but_sendall);
    button.setOnClickListener(new OnClickListener() {

        @Override//w ww. j  av  a 2s .  c  o  m
        public void onClick(final View v) {
            sendAllBookmarks();
        }
    });
}

From source file:com.fabbychat.utils.DrawableManager.java

public void fetchDrawableOnThread(final DrawableProducer dp, final ImageView imageView) {

    String key = dp.getKey();/*w w w  .ja v  a  2s  .  com*/
    if (drawableMap.containsKey(key)) {
        Drawable d = drawableMap.get(key);
        if (d != null) {
            imageView.setImageDrawable(drawableMap.get(key));
        }
        return;
    }

    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(dp);
            if (drawable != null) {
                Message message = handler.obtainMessage(1, drawable);
                handler.sendMessage(message);
            }
        }
    };
    thread.start();
}

From source file:com.google.blockly.android.codegen.CodeGeneratorService.java

@Override
public void onCreate() {
    mHandler = new Handler();
    mWebview = new WebView(this);
    mWebview.getSettings().setJavaScriptEnabled(true);
    mWebview.setWebChromeClient(new WebChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }/*from   w w  w. j a  v  a  2  s. co m*/
    mWebview.addJavascriptInterface(new BlocklyJavascriptInterface(), "BlocklyJavascriptInterface");

    mWebview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            synchronized (this) {
                mReady = true;
            }
            handleRequest();
        }
    });
    mWebview.loadUrl(BLOCKLY_COMPILER_PAGE);
}

From source file:org.liberty.android.fantastischmemo.utils.AMGUIUtility.java

public static void doProgressTask(final Activity activity, final String progressTitle,
        final String progressMessage, final ProgressTask task) {
    final ProgressDialog mProgressDialog = ProgressDialog.show(activity, progressTitle, progressMessage, true);
    final Handler handler = new Handler();
    new Thread() {
        public void run() {
            try {
                task.doHeavyTask();/*from   w  ww.  ja v  a2 s  .  c  o m*/
                handler.post(new Runnable() {
                    public void run() {
                        task.doUITask();
                        mProgressDialog.dismiss();
                    }
                });
            } catch (final Exception e) {
                handler.post(new Runnable() {
                    public void run() {
                        mProgressDialog.dismiss();
                        displayException(activity, activity.getString(R.string.exception_text),
                                activity.getString(R.string.exception_message), e);
                        Log.e(TAG, "Error running progress task", e);
                    }
                });
            }
        }
    }.start();
}

From source file:be.vbsteven.bmtodesk.ShareActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(android.R.style.Theme_Light_NoTitleBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.share);/* w w w  .j a va 2 s .c  om*/

    handler = new Handler();

    // if the user has not configured his credentials yet, show registration wizard
    if (!Global.hasUserCredentials(this)) {
        startActivity(new Intent(this, RegistrationActivity.class));
        finish();
    }

    // check if we are called with a share intent
    if (getIntent().getAction() != null && getIntent().getAction().equals("android.intent.action.SEND")) {
        if (getIntent().hasExtra(Intent.EXTRA_TEXT)) {
            String value = getIntent().getStringExtra(Intent.EXTRA_TEXT);
            value = sanitizeValue(value);

            EditText titleText = (EditText) findViewById(R.id.et_title);
            EditText urlText = (EditText) findViewById(R.id.et_url);

            titleText.setText(value);
            urlText.setText(stripFromTweet(value));
        }
    }

    Button button = (Button) findViewById(R.id.but_send);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String title = ((EditText) findViewById(R.id.et_title)).getText().toString();
            String url = ((EditText) findViewById(R.id.et_url)).getText().toString();
            if (validateInput(title, url)) {
                sendToServer(title, url);
            }
        }

    });

    // if fastsharing is on don't bother asking the user for a title
    if (Global.isFastSharing(this)) {
        String url = ((EditText) findViewById(R.id.et_url)).getText().toString();
        if (validateInput(url, url)) {
            sendToServer(url, url);
        }
    }
}