Example usage for android.os Handler sendEmptyMessage

List of usage examples for android.os Handler sendEmptyMessage

Introduction

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

Prototype

public final boolean sendEmptyMessage(int what) 

Source Link

Document

Sends a Message containing only the what value.

Usage

From source file:de.madvertise.android.sdk.MadvertiseImageView.java

public MadvertiseImageView(final Context context, final int newWidth, final int newHeight,
        final MadvertiseAd ad, final Handler loadingCompletedHandler,
        final AnimationEndListener animationListener) {
    super(context);

    mAnimationListener = animationListener;

    mImageAd = ad;/*w w w.  j  av  a 2s  . c  om*/

    // Remove the ScrollBar so that we have no padding.
    setVerticalScrollBarEnabled(false);
    setHorizontalScrollBarEnabled(false);
    setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    // No visible background
    setBackgroundColor(Color.TRANSPARENT);

    WebViewClient webViewClient = new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            if (loadingCompletedHandler != null) {
                loadingCompletedHandler.sendEmptyMessage(MadvertiseView.MAKE_VISIBLE);
            }
        }
    };
    setWebViewClient(webViewClient);

    StringBuilder content = new StringBuilder();
    content.append("<html><head><style>* {margin:0;padding:0;}</style></head><body>")
            .append("<img src=\"" + mImageAd.getBannerUrl() + "\" height=\"" + newHeight + "\" width=\""
                    + newWidth + "\"/>" + getImpressionTrackingTag())
            .append("</body></html>");
    MadvertiseUtil.logMessage(null, Log.DEBUG, "Loading ad : " + content.toString());
    loadDataWithBaseURL(null, content.toString(), "text/html", "UTF-8", null);
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.methods.MapOpen.java

@SuppressLint("HandlerLeak")
public void addHeatMap() {
    final Handler h = new Handler() {
        @Override/* w  w  w.  jav a 2  s  .c o  m*/
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (mBaiduMap != null)
                mBaiduMap.addHeatMap(mHeatMap);
        }
    };
    new Thread() {
        @Override
        public void run() {
            super.run();
            List<LatLng> data = getLocations();
            mHeatMap = new HeatMap.Builder().data(data).build();
            h.sendEmptyMessage(0);
        }
    }.start();
}

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

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    ticketid = getIntent().getStringExtra("ticketid");
    dialog = new ProgressDialog(this);
    dialog.setMessage("Loading...");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.addticketreply);

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();//from  w w  w. j  ava 2 s . c  om
            if (TicketID == 0) {
                Toast.makeText(AddTicketReply.this,
                        "Ticket Reply Failed. Please try again later or email request@Pulsant.com",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(AddTicketReply.this, "Reply added! Returning to main screen...",
                        Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    };

    final Thread submitReply = new Thread() {
        public void run() {
            try {
                TicketID = API.ReplyToTicket(ticketid, Message);
            } catch (JSONException e) {
                TicketID = 0;
            }

            handler.sendEmptyMessage(0);
        }
    };

    Button AddReplyButton = (Button) findViewById(R.id.AddReplyButton);
    AddReplyButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.show();
            EditText MessageET = (EditText) findViewById(R.id.Message);
            Message = MessageET.getText().toString();

            submitReply.start();
        }
    });
}

From source file:com.dedipower.portal.android.AddTicketReply.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    ticketid = getIntent().getStringExtra("ticketid");
    dialog = new ProgressDialog(this);
    dialog.setMessage("Loading...");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.addticketreply);

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();//www.  j a  v a 2  s  . c om
            if (TicketID == 0) {
                Toast.makeText(AddTicketReply.this,
                        "Ticket Reply Failed. Please try again later or email request@dedipower.com",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(AddTicketReply.this, "Reply added! Returning to main screen...",
                        Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    };

    final Thread submitReply = new Thread() {
        public void run() {
            try {
                TicketID = API.ReplyToTicket(ticketid, Message);
            } catch (JSONException e) {
                TicketID = 0;
            }

            handler.sendEmptyMessage(0);
        }
    };

    Button AddReplyButton = (Button) findViewById(R.id.AddReplyButton);
    AddReplyButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.show();
            EditText MessageET = (EditText) findViewById(R.id.Message);
            Message = MessageET.getText().toString();

            submitReply.start();
        }
    });
}

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

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    dialog = new ProgressDialog(this);
    dialog.setMessage("Loading...");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.createticket);

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();/* w  w w . j  a v a  2  s. c o m*/
            if (TicketID == 0) {
                Toast.makeText(CreateTicket.this,
                        "Ticket Creation Failed. Please try again later or email request@Pulsant.com",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(CreateTicket.this, "Ticket Created! Returning to main screen...",
                        Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    };

    final Thread submitTicket = new Thread() {
        public void run() {
            try {
                TicketID = API.CreateTicket(Subject, Message);
            } catch (JSONException e) {
                TicketID = 0;
            }

            handler.sendEmptyMessage(0);
        }
    };

    Button CreateTicketButton = (Button) findViewById(R.id.CreateTicketButton);
    CreateTicketButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.show();
            EditText SubjectET = (EditText) findViewById(R.id.Subject);
            EditText MessageET = (EditText) findViewById(R.id.Message);
            Subject = SubjectET.getText().toString();
            Message = MessageET.getText().toString();

            submitTicket.start();
            /*EditText Subject = (EditText) findViewById(R.id.Subject);
            EditText Message = (EditText) findViewById(R.id.Message);
                    
            try 
            {
            TicketID = API.CreateTicket(Subject.getText().toString() , Message.getText().toString());
            } 
            catch (JSONException e) 
            {
               Toast.makeText(CreateTicket.this, "Ticket Creation Failed. Please try again later or email request@Pulsant.com", Toast.LENGTH_LONG).show();
            }
                    
                    
            if(TicketID == 0)
            {
               Toast.makeText(CreateTicket.this, "Ticket Creation Failed. Please try again later or email request@Pulsant.com", Toast.LENGTH_LONG).show();
            }
            else
            {
               Toast.makeText(CreateTicket.this, "Ticket Created! Returning to main screen...", Toast.LENGTH_SHORT).show();
               finish();
            }*/
        }
    });
}

From source file:com.dedipower.portal.android.CreateTicket.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    dialog = new ProgressDialog(this);
    dialog.setMessage("Loading...");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.createticket);

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();/*from w w  w  .ja  v  a  2 s  .c  o  m*/
            if (TicketID == 0) {
                Toast.makeText(CreateTicket.this,
                        "Ticket Creation Failed. Please try again later or email request@dedipower.com",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(CreateTicket.this, "Ticket Created! Returning to main screen...",
                        Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    };

    final Thread submitTicket = new Thread() {
        public void run() {
            try {
                TicketID = API.CreateTicket(Subject, Message);
            } catch (JSONException e) {
                TicketID = 0;
            }

            handler.sendEmptyMessage(0);
        }
    };

    Button CreateTicketButton = (Button) findViewById(R.id.CreateTicketButton);
    CreateTicketButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.show();
            EditText SubjectET = (EditText) findViewById(R.id.Subject);
            EditText MessageET = (EditText) findViewById(R.id.Message);
            Subject = SubjectET.getText().toString();
            Message = MessageET.getText().toString();

            submitTicket.start();
            /*EditText Subject = (EditText) findViewById(R.id.Subject);
            EditText Message = (EditText) findViewById(R.id.Message);
                    
            try 
            {
            TicketID = API.CreateTicket(Subject.getText().toString() , Message.getText().toString());
            } 
            catch (JSONException e) 
            {
               Toast.makeText(CreateTicket.this, "Ticket Creation Failed. Please try again later or email request@dedipower.com", Toast.LENGTH_LONG).show();
            }
                    
                    
            if(TicketID == 0)
            {
               Toast.makeText(CreateTicket.this, "Ticket Creation Failed. Please try again later or email request@dedipower.com", Toast.LENGTH_LONG).show();
            }
            else
            {
               Toast.makeText(CreateTicket.this, "Ticket Created! Returning to main screen...", Toast.LENGTH_SHORT).show();
               finish();
            }*/
        }
    });
}

From source file:com.BeatYourRecord.AssignmentSyncService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final int startId_ = startId;
    if (!isRunning) {
        isRunning = true;//from w  w w  . j a v  a  2s  .  c om
    } else {
        Log.d(LOG_TAG, "sync service is already running, stop and return!!!");
        // For whatever reason, the previous onStartCommand is still running,
        // perhaps the service got
        // killed by runtime and this service is not STICKY, so it never reach end
        // to call stopSelf?
        // So just kill it and let another alarm to start it again.
        stopSelf(startId_);
        return Service.START_NOT_STICKY;
    }

    // Log.d(LOG_TAG, "incoming startId=" + startId_);
    // Log.d(LOG_TAG, "thread id=" + Thread.currentThread().getId());
    // Log.d(LOG_TAG, "thread count=" +
    // Thread.currentThread().getThreadGroup().activeCount());
    if ((flags & Service.START_FLAG_RETRY) == Service.START_FLAG_RETRY) {
        Log.d(LOG_TAG, "assignment service retry");
    }

    ytdDomain = intent.getStringExtra(DbHelper.YTD_DOMAIN);
    ytdJsonRpcUrl = "http://" + ytdDomain + "/jsonrpc";

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            stopSelf(startId_);
            Log.d(LOG_TAG, "startId=" + startId_ + " is finished.");
        }
    };

    new Thread() {
        @Override
        public void run() {
            String newAssignmentId = updateAssignmentDb();
            if (newAssignmentId != null) {
                Intent intent = new Intent();
                intent.setAction(MainActivity.NEW_ASSIGNMENT_UPDATE);
                intent.putExtra(DbHelper.YTD_DOMAIN, ytdDomain);
                intent.putExtra(DbHelper.ASSIGNMENT_ID, newAssignmentId);
                sendBroadcast(intent);
                sendNotification(ytdDomain, newAssignmentId);
            }

            handler.sendEmptyMessage(0);
        }
    }.start();

    return Service.START_NOT_STICKY;
}

From source file:com.jgkj.bxxc.fragment.IndexFragment2.java

private void scrollView() {
    SharedPreferences sp = getActivity().getSharedPreferences("PicCount", Activity.MODE_PRIVATE);
    final int count = sp.getInt("Count", -1);
    if (count != -1) {
        final ImageView[] dots = new ImageView[count];
        for (int k = 0; k < count; k++) {
            ImageView image = new ImageView(getActivity());
            image.setImageDrawable(getResources().getDrawable(R.drawable.selector));
            image.setId(k);//from  w w w.ja  va  2s . c o m
            wrapParams = new LinearLayout.LayoutParams(ViewPager.LayoutParams.WRAP_CONTENT,
                    ViewPager.LayoutParams.WRAP_CONTENT);
            wrapParams.leftMargin = 5;
            image.setLayoutParams(wrapParams);
            linearlayout.addView(image);
            dots[k] = (ImageView) linearlayout.getChildAt(k);
            dots[k].setEnabled(true);
        }
        final Handler mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (currentItem < (count - 1)) {
                    currentItem++;
                    viewpager.setCurrentItem(currentItem);
                } else if (currentItem == (count - 1)) {
                    currentItem = 0;
                    viewpager.setCurrentItem(currentItem);
                }
                for (int j = 0; j < count; j++) {
                    dots[j].setEnabled(false);
                }
                dots[currentItem].setEnabled(true);
            }
        };
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                mHandler.sendEmptyMessage(0);
            }
        };
        timer.schedule(timerTask, 1000, 3000);
    }
}

From source file:org.changhong.sync.web.SnowySyncService.java

public void remoteAuthComplete(final Uri uri, final Handler handler) {

    execInThread(new Runnable() {

        public void run() {

            try {
                // TODO: might be intelligent to show something like a
                // progress dialog
                // else the user might try to sync before the authorization
                // process
                // is complete
                OAuthConnection auth = getAuthConnection();
                boolean result = auth.getAccess(uri.getQueryParameter("oauth_verifier"));

                if (result) {
                    TLog.i(TAG, "The authorization process is complete.");
                    handler.sendEmptyMessage(AUTH_COMPLETE);
                    return;
                    //sync(true);
                } else {
                    TLog.e(TAG, "Something went wrong during the authorization process.");
                    sendMessage(AUTH_FAILED);
                }/*from  w ww. j  av a 2 s . c o  m*/
            } catch (UnknownHostException e) {
                TLog.e(TAG, "Internet connection not available");
                sendMessage(NO_INTERNET);
            }

            // We don't care what we send, just remove the dialog
            handler.sendEmptyMessage(0);
        }
    });
}

From source file:org.thialfihar.android.apg.ui.CertifyKeyActivity.java

private void showPassphraseDialog(final long secretKeyId) {
    // Message is received after passphrase is cached
    Handler returnHandler = new Handler() {
        @Override// w  w  w  .  j a  v a 2 s  . c o  m
        public void handleMessage(Message message) {
            if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
                startSigning();
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(returnHandler);

    try {
        PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance(this, messenger,
                secretKeyId);

        passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog");
    } catch (PgpGeneralException e) {
        Log.d(Constants.TAG, "No passphrase for this secret key!");
        // send message to handler to start certification directly
        returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY);
    }
}