Example usage for java.util Timer schedule

List of usage examples for java.util Timer schedule

Introduction

In this page you can find the example usage for java.util Timer schedule.

Prototype

public void schedule(TimerTask task, Date firstTime, long period) 

Source Link

Document

Schedules the specified task for repeated fixed-delay execution, beginning at the specified time.

Usage

From source file:com.easemob.chatui.adapter.MessageAdapter.java

/**
 * ?/*w ww  .j a v  a 2  s. co  m*/
 *
 * @param message
 * @param holder
 * @param position
 * @param convertView
 */
private void handleVideoMessage(final EMMessage message, final ViewHolder holder, final int position,
        View convertView) {

    VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
    // final File image=new File(PathUtil.getInstance().getVideoPath(),
    // videoBody.getFileName());
    String localThumb = videoBody.getLocalThumb();

    holder.iv.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult(new Intent(activity, ContextMenu.class)
                    .putExtra("position", position).putExtra("type", EMMessage.Type.VIDEO.ordinal()),
                    ChatActivity.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });

    if (localThumb != null) {

        showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
    }
    if (videoBody.getLength() > 0) {
        String time = DateUtils.toTimeBySecond(videoBody.getLength());
        holder.timeLength.setText(time);
    }
    holder.playBtn.setImageResource(R.drawable.video_download_btn_nor);

    if (message.direct == Direct.RECEIVE) {
        if (videoBody.getVideoFileLength() > 0) {
            String size = TextFormater.getDataSize(videoBody.getVideoFileLength());
            holder.size.setText(size);
        }
    } else {
        if (videoBody.getLocalUrl() != null && new File(videoBody.getLocalUrl()).exists()) {
            String size = TextFormater.getDataSize(new File(videoBody.getLocalUrl()).length());
            holder.size.setText(size);
        }
    }

    if (message.direct == Direct.RECEIVE) {

        // System.err.println("it is receive msg");
        if (message.status == EMMessage.Status.INPROGRESS) {
            // System.err.println("!!!! back receive");
            holder.iv.setImageResource(R.drawable.default_image);
            showDownloadImageProgress(message, holder);

        } else {
            // System.err.println("!!!! not back receive, show image directly");
            holder.iv.setImageResource(R.drawable.default_image);
            if (localThumb != null) {
                showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
            }

        }

        return;
    }
    holder.pb.setTag(position);

    // until here ,deal with send video msg
    switch (message.status) {
    case SUCCESS:
        holder.pb.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        break;
    case FAIL:
        holder.pb.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.VISIBLE);
        break;
    case INPROGRESS:
        if (timers.containsKey(message.getMsgId()))
            return;
        // set a timer
        final Timer timer = new Timer();
        timers.put(message.getMsgId(), timer);
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        holder.pb.setVisibility(View.VISIBLE);
                        holder.tv.setVisibility(View.VISIBLE);
                        holder.tv.setText(message.progress + "%");
                        if (message.status == EMMessage.Status.SUCCESS) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS);
                            timer.cancel();
                        } else if (message.status == EMMessage.Status.FAIL) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                            // message.setProgress(0);
                            holder.staus_iv.setVisibility(View.VISIBLE);
                            Toast.makeText(activity, activity.getString(R.string.send_fail)
                                    + activity.getString(R.string.connect_failuer_toast), 0).show();
                            timer.cancel();
                        }

                    }
                });

            }
        }, 0, 500);
        break;
    default:
        // sendMsgInBackground(message, holder);
        sendPictureMessage(message, holder);

    }

}

From source file:org.mule.modules.wechat.WechatConnector.java

/**
 * Constructor// w  w  w .j av  a  2 s .c  om
 */
public WechatConnector() {
    Timer t = new Timer();
    t.schedule(new TimerTask() {
        @Override
        public void run() {
            while (config == null) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    logger.error(e);
                }
            }

            if (!config.getSelfManageAccessToken()) {
                String httpsURL = "https://api.wechat.com/cgi-bin/token?grant_type=client_credential&appid="
                        + config.getAppId() + "&secret=" + config.getAppSecret();
                System.out.println(httpsURL);
                HttpsConnection con = new HttpsConnection();
                Map<String, Object> map = null;
                try {
                    map = con.get(httpsURL);
                } catch (Exception e) {
                    logger.error(e);
                }

                if (map.containsKey("access_token")) {
                    WechatConnector.accessToken = map.get("access_token").toString();
                }
            }
        }
    }, 0, 6600000);
}

From source file:com.shengtao.chat.chatUI.adapter.MessageAdapter.java

/**
 * ?/*from   w w  w  .  j a v a 2 s  . c  o  m*/
 *
 * @param message
 * @param holder
 * @param position
 * @param convertView
 */
private void handleFileMessage(final EMMessage message, final ViewHolder holder, int position,
        View convertView) {
    final NormalFileMessageBody fileMessageBody = (NormalFileMessageBody) message.getBody();
    final String filePath = fileMessageBody.getLocalUrl();
    holder.tv_file_name.setText(fileMessageBody.getFileName());
    holder.tv_file_size.setText(TextFormater.getDataSize(fileMessageBody.getFileSize()));
    holder.ll_container.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            File file = new File(filePath);
            if (file != null && file.exists()) {
                // 
                FileUtils.openFile(file, (Activity) context);
            } else {
                // 
                context.startActivity(
                        new Intent(context, ShowNormalFileActivity.class).putExtra("msgbody", fileMessageBody));
            }
            if (message.direct == Direct.RECEIVE && !message.isAcked
                    && message.getChatType() != ChatType.GroupChat
                    && message.getChatType() != ChatType.ChatRoom) {
                try {
                    EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    message.isAcked = true;
                } catch (EaseMobException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });
    String st1 = context.getResources().getString(string.Have_downloaded);
    String st2 = context.getResources().getString(string.Did_not_download);
    if (message.direct == Direct.RECEIVE) { // ?
        EMLog.d(TAG, "it is receive msg");
        File file = new File(filePath);
        if (file != null && file.exists()) {
            holder.tv_file_download_state.setText(st1);
        } else {
            holder.tv_file_download_state.setText(st2);
        }
        return;
    }

    // until here, deal with send voice msg
    switch (message.status) {
    case SUCCESS:
        holder.pb.setVisibility(View.INVISIBLE);
        holder.tv.setVisibility(View.INVISIBLE);
        holder.staus_iv.setVisibility(View.INVISIBLE);
        break;
    case FAIL:
        holder.pb.setVisibility(View.INVISIBLE);
        holder.tv.setVisibility(View.INVISIBLE);
        holder.staus_iv.setVisibility(View.VISIBLE);
        break;
    case INPROGRESS:
        if (timers.containsKey(message.getMsgId()))
            return;
        // set a timer
        final Timer timer = new Timer();
        timers.put(message.getMsgId(), timer);
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        holder.pb.setVisibility(View.VISIBLE);
                        holder.tv.setVisibility(View.VISIBLE);
                        holder.tv.setText(message.progress + "%");
                        if (message.status == EMMessage.Status.SUCCESS) {
                            holder.pb.setVisibility(View.INVISIBLE);
                            holder.tv.setVisibility(View.INVISIBLE);
                            timer.cancel();
                        } else if (message.status == EMMessage.Status.FAIL) {
                            holder.pb.setVisibility(View.INVISIBLE);
                            holder.tv.setVisibility(View.INVISIBLE);
                            holder.staus_iv.setVisibility(View.VISIBLE);
                            Toast.makeText(activity, activity.getString(string.send_fail)
                                    + activity.getString(string.connect_failuer_toast), 0).show();
                            timer.cancel();
                        }

                    }
                });

            }
        }, 0, 500);
        break;
    default:
        // ???
        sendMsgInBackground(message, holder);
    }

}

From source file:com.shengtao.chat.chatUI.adapter.MessageAdapter.java

/**
 * ?//from  w w  w  .j a  va2  s  . c  o  m
 *
 * @param message
 * @param holder
 * @param position
 * @param convertView
 */
private void handleImageMessage(final EMMessage message, final ViewHolder holder, final int position,
        View convertView) {
    holder.pb.setTag(position);
    holder.iv.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult((new Intent(activity, ContextMenu.class))
                    .putExtra("position", position).putExtra("type", Type.IMAGE.ordinal()),
                    ChatActivity.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });

    // ??
    if (message.direct == Direct.RECEIVE) {
        // "it is receive msg";
        if (message.status == EMMessage.Status.INPROGRESS) {
            // "!!!! back receive";
            holder.iv.setImageResource(drawable.default_image);
            showDownloadImageProgress(message, holder);
            // downloadImage(message, holder);
        } else {
            // "!!!! not back receive, show image directly");
            holder.pb.setVisibility(View.GONE);
            holder.tv.setVisibility(View.GONE);
            holder.iv.setImageResource(drawable.default_image);
            ImageMessageBody imgBody = (ImageMessageBody) message.getBody();
            if (imgBody.getLocalUrl() != null) {
                // String filePath = imgBody.getLocalUrl();
                String remotePath = imgBody.getRemoteUrl();
                String filePath = ImageUtils.getImagePath(remotePath);
                String thumbRemoteUrl = imgBody.getThumbnailUrl();
                if (TextUtils.isEmpty(thumbRemoteUrl) && !TextUtils.isEmpty(remotePath)) {
                    thumbRemoteUrl = remotePath;
                }
                String thumbnailPath = ImageUtils.getThumbnailImagePath(thumbRemoteUrl);
                showImageView(thumbnailPath, holder.iv, filePath, imgBody.getRemoteUrl(), message);
            }
        }
        return;
    }

    // ???
    // process send message
    // send pic, show the pic directly
    ImageMessageBody imgBody = (ImageMessageBody) message.getBody();
    String filePath = imgBody.getLocalUrl();
    if (filePath != null && new File(filePath).exists()) {
        showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, null, message);
    } else {
        showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, IMAGE_DIR, message);
    }

    switch (message.status) {
    case SUCCESS:
        holder.pb.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.GONE);
        break;
    case FAIL:
        holder.pb.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.VISIBLE);
        break;
    case INPROGRESS:
        holder.staus_iv.setVisibility(View.GONE);
        holder.pb.setVisibility(View.VISIBLE);
        holder.tv.setVisibility(View.VISIBLE);
        if (timers.containsKey(message.getMsgId()))
            return;
        // set a timer
        final Timer timer = new Timer();
        timers.put(message.getMsgId(), timer);
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        holder.pb.setVisibility(View.VISIBLE);
                        holder.tv.setVisibility(View.VISIBLE);
                        holder.tv.setText(message.progress + "%");
                        if (message.status == EMMessage.Status.SUCCESS) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS);
                            timer.cancel();
                        } else if (message.status == EMMessage.Status.FAIL) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                            // message.setProgress(0);
                            holder.staus_iv.setVisibility(View.VISIBLE);
                            Toast.makeText(activity, activity.getString(string.send_fail)
                                    + activity.getString(string.connect_failuer_toast), 0).show();
                            timer.cancel();
                        }

                    }
                });

            }
        }, 0, 500);
        break;
    default:
        sendPictureMessage(message, holder);
    }
}

From source file:com.shengtao.chat.chatUI.adapter.MessageAdapter.java

/**
 * ?// ww  w . j a v a 2  s .  com
 *
 * @param message
 * @param holder
 * @param position
 * @param convertView
 */
private void handleVideoMessage(final EMMessage message, final ViewHolder holder, final int position,
        View convertView) {

    VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
    // final File image=new File(PathUtil.getInstance().getVideoPath(),
    // videoBody.getFileName());
    String localThumb = videoBody.getLocalThumb();

    holder.iv.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult(new Intent(activity, ContextMenu.class)
                    .putExtra("position", position).putExtra("type", Type.VIDEO.ordinal()),
                    ChatActivity.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });

    if (localThumb != null) {

        showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
    }
    if (videoBody.getLength() > 0) {
        String time = DateUtils.toTimeBySecond(videoBody.getLength());
        holder.timeLength.setText(time);
    }
    holder.playBtn.setImageResource(drawable.video_download_btn_nor);

    if (message.direct == Direct.RECEIVE) {
        if (videoBody.getVideoFileLength() > 0) {
            String size = TextFormater.getDataSize(videoBody.getVideoFileLength());
            holder.size.setText(size);
        }
    } else {
        if (videoBody.getLocalUrl() != null && new File(videoBody.getLocalUrl()).exists()) {
            String size = TextFormater.getDataSize(new File(videoBody.getLocalUrl()).length());
            holder.size.setText(size);
        }
    }

    if (message.direct == Direct.RECEIVE) {

        // System.err.println("it is receive msg");
        if (message.status == EMMessage.Status.INPROGRESS) {
            // System.err.println("!!!! back receive");
            holder.iv.setImageResource(drawable.default_image);
            showDownloadImageProgress(message, holder);

        } else {
            // System.err.println("!!!! not back receive, show image directly");
            holder.iv.setImageResource(drawable.default_image);
            if (localThumb != null) {
                showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
            }

        }

        return;
    }
    holder.pb.setTag(position);

    // until here ,deal with send video msg
    switch (message.status) {
    case SUCCESS:
        holder.pb.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        break;
    case FAIL:
        holder.pb.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.VISIBLE);
        break;
    case INPROGRESS:
        if (timers.containsKey(message.getMsgId()))
            return;
        // set a timer
        final Timer timer = new Timer();
        timers.put(message.getMsgId(), timer);
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        holder.pb.setVisibility(View.VISIBLE);
                        holder.tv.setVisibility(View.VISIBLE);
                        holder.tv.setText(message.progress + "%");
                        if (message.status == EMMessage.Status.SUCCESS) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS);
                            timer.cancel();
                        } else if (message.status == EMMessage.Status.FAIL) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                            // message.setProgress(0);
                            holder.staus_iv.setVisibility(View.VISIBLE);
                            Toast.makeText(activity, activity.getString(string.send_fail)
                                    + activity.getString(string.connect_failuer_toast), 0).show();
                            timer.cancel();
                        }

                    }
                });

            }
        }, 0, 500);
        break;
    default:
        // sendMsgInBackground(message, holder);
        sendPictureMessage(message, holder);

    }

}

From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java

/**
 * ?//from  w ww.j a v  a 2  s  .  c o m
 *
 * @param message
 * @param holder
 * @param position
 * @param convertView
 */
private void handleFileMessage(final EMMessage message, final ViewHolder holder, int position,
        View convertView) {
    final NormalFileMessageBody fileMessageBody = (NormalFileMessageBody) message.getBody();
    final String filePath = fileMessageBody.getLocalUrl();
    holder.tv_file_name.setText(fileMessageBody.getFileName());
    holder.tv_file_size.setText(TextFormater.getDataSize(fileMessageBody.getFileSize()));
    holder.ll_container.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            File file = new File(filePath);
            if (file != null && file.exists()) {
                // 
                FileUtils.openFile(file, (Activity) context);
            } else {
                // 
                context.startActivity(
                        new Intent(context, ShowNormalFileActivity.class).putExtra("msgbody", fileMessageBody));
            }
            if (message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
                    && message.getChatType() != ChatType.GroupChat
                    && message.getChatType() != ChatType.ChatRoom) {
                try {
                    EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    message.isAcked = true;
                } catch (EaseMobException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });
    String st1 = context.getResources().getString(R.string.Have_downloaded);
    String st2 = context.getResources().getString(R.string.Did_not_download);
    if (message.direct == EMMessage.Direct.RECEIVE) { // ?
        EMLog.d(TAG, "it is receive msg");
        File file = new File(filePath);
        if (file != null && file.exists()) {
            holder.tv_file_download_state.setText(st1);
        } else {
            holder.tv_file_download_state.setText(st2);
        }
        return;
    }

    // until here, deal with send voice msg
    switch (message.status) {
    case SUCCESS:
        holder.pb.setVisibility(View.INVISIBLE);
        holder.tv.setVisibility(View.INVISIBLE);
        holder.staus_iv.setVisibility(View.INVISIBLE);
        break;
    case FAIL:
        holder.pb.setVisibility(View.INVISIBLE);
        holder.tv.setVisibility(View.INVISIBLE);
        holder.staus_iv.setVisibility(View.VISIBLE);
        break;
    case INPROGRESS:
        if (timers.containsKey(message.getMsgId()))
            return;
        // set a timer
        final Timer timer = new Timer();
        timers.put(message.getMsgId(), timer);
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        holder.pb.setVisibility(View.VISIBLE);
                        holder.tv.setVisibility(View.VISIBLE);
                        holder.tv.setText(message.progress + "%");
                        if (message.status == EMMessage.Status.SUCCESS) {
                            holder.pb.setVisibility(View.INVISIBLE);
                            holder.tv.setVisibility(View.INVISIBLE);
                            timer.cancel();
                        } else if (message.status == EMMessage.Status.FAIL) {
                            holder.pb.setVisibility(View.INVISIBLE);
                            holder.tv.setVisibility(View.INVISIBLE);
                            holder.staus_iv.setVisibility(View.VISIBLE);
                            Toast.makeText(activity,
                                    activity.getString(R.string.send_fail)
                                            + activity.getString(R.string.connect_failuer_toast),
                                    Toast.LENGTH_LONG).show();
                            timer.cancel();
                        }

                    }
                });

            }
        }, 0, 500);
        break;
    default:
        // ???
        sendMsgInBackground(message, holder);
    }

}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

/** Called when the activity is first created. */
@Override/*  ww w  . ja  v  a2 s . c  o m*/
public void onCreate(Bundle savedInstanceState) {
    /* this was just a test      if(mLocationManager==null) {
             mLocationManager=(android.location.LocationManager) getSystemService(Context.LOCATION_SERVICE);
          }
    */
    //      TabHost host=this.getTabHost();
    //      host.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
    //         
    //         @Override
    //         public void onTabChanged(String tabId) {
    //            if(INeedToo.this._doingCreatingTabs==false) {
    //               if(tabId.equals("tab1")) {
    //                  INeedToo.this._forceNonCompany=true;
    //               }
    //            }
    //         }
    //      });
    super.onCreate(savedInstanceState);
    mLocationClient = new LocationClient(this, this, this);
    mLocationClient.connect();
    try {
        if (getIntent().getAction() != null && getIntent().getAction().equals("doPrimitiveDeletedNeed")) {
            transmitNetwork(getIntent().getStringExtra("phoneid"));
            return;
        }
    } catch (Exception eieio) {
        return;
    }
    try {
        /*
                    putExtra("needId",needId).
          putExtra("foreignNeedId",foreignNeedId).
          putExtra("phoneid",phoneid).
          putExtra("foreignLocationId",foreignLocationId)
                
         */
        if (getIntent().getAction() != null
                && getIntent().getAction().equals("transmitNetworkDeletedThisNeedByOnBehalfOf")) {
            long needId = getIntent().getLongExtra("needId", -11);
            long foreignNeedId = getIntent().getLongExtra("foreignNeedId", -11);
            String phoneId = getIntent().getStringExtra("phoneid");
            long foreignLocationId = getIntent().getLongExtra("foreignLocationId", -11);
            if (needId != -11 && foreignNeedId != -11 && foreignLocationId != -11 && isNothingNot(phoneId))
                transmitNetworkDeletedThisNeedByOnBehalfOf(needId, foreignNeedId, phoneId, foreignLocationId);
            return;
        }
    } catch (Exception ei3) {
        return;
    }

    /*bbhbb 2011-03-26*/ /*bbhbb2013_05_01 isn't this being done below?
                         *    Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler("")); */

    mHandler = new Handler();

    doBindService();
    mSingleton = this;
    ///////////mSingleton.log("onCreating_INeedToo", 1);

    if (getPackageName().toLowerCase().indexOf("trial") != -1 && !isSpecialPhone()) {
        if (!iveCheckedAuthorizationStatusForThisPhone) {
            doViewCount = true;
            iveCheckedAuthorizationStatusForThisPhone = true;
            final Timer jdTimer = new Timer("Registering");
            jdTimer.schedule(new TimerTask() {
                public void run() {
                    Thread thread = new Thread(new Runnable() {
                        public void run() {
                            Intent intent = new Intent(INeedToo.this, INeedWebService.class)
                                    .setAction("CheckStatus");
                            startService(intent);
                            jdTimer.cancel();
                        }
                    });
                    thread.setPriority(Thread.MIN_PRIORITY);
                    thread.run();
                }
            }, 3000, 1000 * 60 * 10);

        }
    } else {
        if (IS_ANDROID_VERSION) {
            if (!isSpecialPhone()
                    || INeedToo.mSingleton.getPhoneId().toLowerCase().equals("20013fc135cd6097xx")) {

                final Timer jdTimer = new Timer("Licensing");
                jdTimer.schedule(new TimerTask() {
                    public void run() {
                        Thread thread = new Thread(new Runnable() {
                            public void run() {
                                // Construct the LicenseCheckerCallback. The library calls this when done.        
                                mLicenseCheckerCallback = new MyLicenseCheckerCallback();
                                // Construct the LicenseChecker with a Policy.        
                                mChecker = new LicenseChecker(INeedToo.this,
                                        new ServerManagedPolicy(INeedToo.this,
                                                new AESObfuscator(SALT, getPackageName(),
                                                        //                           "com.mibr.android.intelligentreminder",
                                                        getDeviceId())),
                                        BASE64_PUBLIC_KEY // Your public licensing key.
                                );
                                mChecker.checkAccess(mLicenseCheckerCallback);
                            }
                        });
                        thread.setPriority(Thread.MIN_PRIORITY);
                        thread.run();
                    }
                }, 3000, 1000 * 60 * 10);
            }
        }
    }

    try {
        _logFilter = Integer
                .valueOf(getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE)
                        .getString("LoggingLevel", "3"));
    } catch (Exception e) {
    }

    if (!INeedLocationService.USING_LOCATION_SERVICES) {

        int logFilter = 3;
        try {
            logFilter = Integer
                    .valueOf(getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE)
                            .getString("LoggingLevel", "3"));
        } catch (Exception e) {
        }
        Intent jdIntent = new Intent(this, INeedTimerServices.class).putExtra("logFilter", logFilter);

        getApplicationContext().startService(jdIntent);
    }
    Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(""));
    if (INeedToo.mSingleton.getPhoneId().toLowerCase().equals("22a100000d9f25c5")) {
        DELAYPOSTTTS = 100;
    }

    // I don't need this because IHaveNeeds.onresume does it      getApplicationContext().startService(new Intent(this, INeedLocationService.class));
    if (!_doneSplashy) {
        _doneSplashy = true;
        if (!getVersionFile()) {
            stampVersion();
            showDialog(DIALOG_SPLASH);
        } else {
            //showDialog(DIALOG_SPLASH);
        }
    }
    if (allItems != null) {
        whereImAtInAllItems++;
        if (whereImAtInAllItems < allItems.size()) {
            showDialog(DOING_SAMPLE_NEEDS_DIALOG);
        } else {
            allItems = null;
        }
    }

    setTitle(getHeading());
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        _initialTabIndex = bundle.getInt("initialtabindex", 0);
        _didContact = bundle.getBoolean("iscontact", false);
        if (_initialTabIndex == 1) {
            _doingLocationCompany = bundle.getString("doingcompany");
        } else {
            _doingLocationCompany = null;
        }
    } else {
        _doingLocationCompany = null;
    }
    final TabHost tabHost = getTabHost();
    tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Need",

            getResources().getDrawable(R.drawable.status_bar2_blackwhite))
            .setContent(new Intent(this, IHaveNeeds.class).putExtra("iscontact", this._didContact)));

    tabHost.addTab(tabHost.newTabSpec("tab2")
            .setIndicator("Location",
                    (BitmapDrawable) getResources().getDrawable(android.R.drawable.ic_menu_mapmode))
            .setContent(
                    new Intent(this, IHaveLocations.class).putExtra("doingcompany", _doingLocationCompany)));
    Intent intent = new Intent(this, NeedMap.class).putExtra("doingcompany", _doingLocationCompany);
    tabHost.addTab(tabHost.newTabSpec("tab2a")
            .setIndicator("Map", (BitmapDrawable) getResources().getDrawable(R.drawable.ic_dialog_map))
            .setContent(intent));
    /*
    tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator(
    "History",(BitmapDrawable) getResources().getDrawable(
          R.drawable.chart)).setContent(
                new Intent(this, IHaveHistory.class)));
    */
    tabHost.addTab(tabHost.newTabSpec("tab4")
            .setIndicator("System",
                    (BitmapDrawable) getResources().getDrawable(R.drawable.status_bar1_blackwhite))
            .setContent(new Intent(this, ListPlus.class)));
    /*      tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(
    "Need",
    scaleTo((BitmapDrawable) getResources().getDrawable(
          R.drawable.status_bar2_blackwhite), 36f)).setContent(
                new Intent(this, IHaveNeeds.class).putExtra("iscontact", this._didContact)));
            
    tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator(
       "Location",
       scaleTo((BitmapDrawable) getResources().getDrawable(
             android.R.drawable.ic_menu_mapmode), 36f)).setContent(
                   new Intent(this, IHaveLocations.class).putExtra("doingcompany", _doingLocationCompany)));
    tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator(
    "History",
    scaleTo((BitmapDrawable) getResources().getDrawable(
          R.drawable.chart), 36f)).setContent(
                new Intent(this, IHaveHistory.class)));
    tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator(
    "System",
    scaleTo((BitmapDrawable) getResources().getDrawable(
          R.drawable.status_bar1_blackwhite), 31f)).setContent(
                new Intent(this, ListPlus.class)));
    */
    tabHost.setCurrentTab(_initialTabIndex);
    boolean networkingOutbound = getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE)
            .getBoolean("Networking_Outbound_Enabled", false);
    if (INeedWebService.mSingleton == null) {

        if (networkingOutbound) {
            enableTransmitting();
        }
        if (getSharedPreferences(INeedToo.PREFERENCES_LOCATION, Preferences.MODE_PRIVATE)
                .getBoolean("Networking_Inbound_Enabled", false)) {
            enableReceiving();
        }
    }
}

From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java

/**
 * ?//from   w ww .j a v a2 s  .  c  o m
 *
 * @param message
 * @param holder
 * @param position
 * @param convertView
 */
private void handleImageMessage(final EMMessage message, final ViewHolder holder, final int position,
        View convertView) {
    holder.pb.setTag(position);
    holder.iv.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult((new Intent(activity, ContextMenu.class))
                    .putExtra("position", position).putExtra("type", EMMessage.Type.IMAGE.ordinal()),
                    ChatMessage.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });

    // ??
    if (message.direct == EMMessage.Direct.RECEIVE) {
        // "it is receive msg";
        if (message.status == EMMessage.Status.INPROGRESS) {
            // "!!!! back receive";
            holder.iv.setImageResource(R.drawable.default_image);
            showDownloadImageProgress(message, holder);
            // downloadImage(message, holder);
        } else {
            // "!!!! not back receive, show image directly");
            holder.pb.setVisibility(View.GONE);
            holder.tv.setVisibility(View.GONE);
            holder.iv.setImageResource(R.drawable.default_image);
            ImageMessageBody imgBody = (ImageMessageBody) message.getBody();
            if (imgBody.getLocalUrl() != null) {
                // String filePath = imgBody.getLocalUrl();
                String remotePath = imgBody.getRemoteUrl();
                String filePath = ImageUtils.getImagePath(remotePath);
                String thumbRemoteUrl = imgBody.getThumbnailUrl();
                if (TextUtils.isEmpty(thumbRemoteUrl) && !TextUtils.isEmpty(remotePath)) {
                    thumbRemoteUrl = remotePath;
                }
                String thumbnailPath = ImageUtils.getThumbnailImagePath(thumbRemoteUrl);
                showImageView(thumbnailPath, holder.iv, filePath, imgBody.getRemoteUrl(), message);
            }
        }
        return;
    }

    // ???
    // process send message
    // send pic, show the pic directly
    ImageMessageBody imgBody = (ImageMessageBody) message.getBody();
    String filePath = imgBody.getLocalUrl();
    if (filePath != null && new File(filePath).exists()) {
        showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, null, message);
    } else {
        showImageView(ImageUtils.getThumbnailImagePath(filePath), holder.iv, filePath, IMAGE_DIR, message);
    }

    switch (message.status) {
    case SUCCESS:
        holder.pb.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.GONE);
        break;
    case FAIL:
        holder.pb.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.VISIBLE);
        break;
    case INPROGRESS:
        holder.staus_iv.setVisibility(View.GONE);
        holder.pb.setVisibility(View.VISIBLE);
        holder.tv.setVisibility(View.VISIBLE);
        if (timers.containsKey(message.getMsgId()))
            return;
        // set a timer
        final Timer timer = new Timer();
        timers.put(message.getMsgId(), timer);
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        holder.pb.setVisibility(View.VISIBLE);
                        holder.tv.setVisibility(View.VISIBLE);
                        holder.tv.setText(message.progress + "%");
                        if (message.status == EMMessage.Status.SUCCESS) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS);
                            timer.cancel();
                        } else if (message.status == EMMessage.Status.FAIL) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                            // message.setProgress(0);
                            holder.staus_iv.setVisibility(View.VISIBLE);
                            Toast.makeText(activity, activity.getString(R.string.send_fail)
                                    + activity.getString(R.string.connect_failuer_toast), 0).show();
                            timer.cancel();
                        }

                    }
                });

            }
        }, 0, 500);
        break;
    default:
        sendPictureMessage(message, holder);
    }
}

From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java

/**
 * ?/*from www.  j a  v a  2 s.  c  o  m*/
 *
 * @param message
 * @param holder
 * @param position
 * @param convertView
 */
private void handleVideoMessage(final EMMessage message, final ViewHolder holder, final int position,
        View convertView) {

    VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
    // final File image=new File(PathUtil.getInstance().getVideoPath(),
    // videoBody.getFileName());
    String localThumb = videoBody.getLocalThumb();

    holder.iv.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult(new Intent(activity, ContextMenu.class)
                    .putExtra("position", position).putExtra("type", EMMessage.Type.VIDEO.ordinal()),
                    ChatMessage.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });

    if (localThumb != null) {

        showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
    }
    if (videoBody.getLength() > 0) {
        String time = DateUtils.toTimeBySecond(videoBody.getLength());
        holder.timeLength.setText(time);
    }
    holder.playBtn.setImageResource(R.drawable.video_download_btn_nor);

    if (message.direct == EMMessage.Direct.RECEIVE) {
        if (videoBody.getVideoFileLength() > 0) {
            String size = TextFormater.getDataSize(videoBody.getVideoFileLength());
            holder.size.setText(size);
        }
    } else {
        if (videoBody.getLocalUrl() != null && new File(videoBody.getLocalUrl()).exists()) {
            String size = TextFormater.getDataSize(new File(videoBody.getLocalUrl()).length());
            holder.size.setText(size);
        }
    }

    if (message.direct == EMMessage.Direct.RECEIVE) {

        // System.err.println("it is receive msg");
        if (message.status == EMMessage.Status.INPROGRESS) {
            // System.err.println("!!!! back receive");
            holder.iv.setImageResource(R.drawable.default_image);
            showDownloadImageProgress(message, holder);

        } else {
            // System.err.println("!!!! not back receive, show image directly");
            holder.iv.setImageResource(R.drawable.default_image);
            if (localThumb != null) {
                showVideoThumbView(localThumb, holder.iv, videoBody.getThumbnailUrl(), message);
            }

        }

        return;
    }
    holder.pb.setTag(position);

    // until here ,deal with send video msg
    switch (message.status) {
    case SUCCESS:
        holder.pb.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        break;
    case FAIL:
        holder.pb.setVisibility(View.GONE);
        holder.tv.setVisibility(View.GONE);
        holder.staus_iv.setVisibility(View.VISIBLE);
        break;
    case INPROGRESS:
        if (timers.containsKey(message.getMsgId()))
            return;
        // set a timer
        final Timer timer = new Timer();
        timers.put(message.getMsgId(), timer);
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        holder.pb.setVisibility(View.VISIBLE);
                        holder.tv.setVisibility(View.VISIBLE);
                        holder.tv.setText(message.progress + "%");
                        if (message.status == EMMessage.Status.SUCCESS) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_SUCCESS);
                            timer.cancel();
                        } else if (message.status == EMMessage.Status.FAIL) {
                            holder.pb.setVisibility(View.GONE);
                            holder.tv.setVisibility(View.GONE);
                            // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                            // message.setProgress(0);
                            holder.staus_iv.setVisibility(View.VISIBLE);
                            Toast.makeText(activity,
                                    activity.getString(R.string.send_fail)
                                            + activity.getString(R.string.connect_failuer_toast),
                                    Toast.LENGTH_LONG).show();
                            timer.cancel();
                        }

                    }
                });

            }
        }, 0, 500);
        break;
    default:
        // sendMsgInBackground(message, holder);
        sendPictureMessage(message, holder);

    }

}

From source file:org.sakaiproject.evaluation.logic.EvalEvaluationSetupServiceImpl.java

protected void initiateUpdateStateTimer() {
    // timer repeats every 60 minutes
    final long repeatInterval = 1000 * 60 * 60;
    // start up a timer after 2 mins + random(10 mins)
    long startDelay = (1000 * 60 * 2) + (1000 * 60 * new Random().nextInt(10));

    TimerTask runStateUpdateTask = new TimerTask() {
        @Override/*from  w  w w .ja va2  s  .  co  m*/
        public void run() {
            String serverId = commonLogic.getConfigurationSetting(EvalExternalLogic.SETTING_SERVER_ID,
                    "UNKNOWN_SERVER_ID");
            Boolean lockObtained = dao.obtainLock(EVAL_UPDATE_TIMER, serverId, repeatInterval);
            // only execute the code if we have an exclusive lock
            if (lockObtained != null && lockObtained) {
                // get all evals that are not viewable (i.e. completely done with) or deleted 
                List<EvalEvaluation> evals = dao.findBySearch(EvalEvaluation.class,
                        new Search(new Restriction[] {
                                new Restriction("state", EvalConstants.EVALUATION_STATE_VIEWABLE,
                                        Restriction.NOT_EQUALS),
                                new Restriction("state", EvalConstants.EVALUATION_STATE_DELETED,
                                        Restriction.NOT_EQUALS) }));
                if (evals.size() > 0) {
                    LOG.info("Checking the state of " + evals.size()
                            + " evaluations to ensure they are all up to date...");
                    // only do partial purge if constant > 0
                    long partialPurgeTime = -1;
                    if (EvalConstants.EVALUATION_PARTIAL_CLEANUP_DAYS > 0) {
                        // set the partial purge number of days to the constant (15)
                        partialPurgeTime = System.currentTimeMillis()
                                - (EvalConstants.EVALUATION_PARTIAL_CLEANUP_DAYS * 24l * 60l * 60l * 1000l);
                    }

                    // loop through and update the state of the evals if needed
                    int count = 0;
                    for (EvalEvaluation evaluation : evals) {
                        String evalState = evaluationService.returnAndFixEvalState(evaluation, false);
                        if (EvalConstants.EVALUATION_STATE_PARTIAL.equals(evalState) && partialPurgeTime > -1) {
                            // purge out partial evaluations older than the partial purge time
                            if (evaluation.getLastModified().getTime() < partialPurgeTime) {
                                LOG.info("Purging partial evaluation (" + evaluation.getId() + ") from "
                                        + evaluation.getLastModified());
                                deleteEvaluation(evaluation.getId(), commonLogic.getAdminUserId());
                                continue;
                            }
                        }
                        // fix up the state if needed
                        String currentEvalState = evaluation.getState();
                        if (!currentEvalState.equals(evalState)) {
                            evaluationService.returnAndFixEvalState(evaluation, true); // update the state
                            count++;
                            // trigger the jobs logic to look at this since the state changed
                            evalJobLogic.processEvaluationStateChange(evaluation.getId(),
                                    EvalJobLogic.ACTION_UPDATE);
                        }
                    }
                    if (count > 0) {
                        LOG.info("Updated the state of " + count + " evaluations...");
                    }
                }

                // finally we will reset the system config cache
                settings.resetCache(null);
            }
        }
    };

    // now we need to obtain a lock and then run the task if we have it
    Timer timer = new Timer(true);
    LOG.info("Initializing the repeating timer task for evaluation, first run in " + (startDelay / 1000)
            + " seconds " + "and subsequent runs will happen every " + (repeatInterval / 1000)
            + " seconds after that");
    timer.schedule(runStateUpdateTask, startDelay, repeatInterval);
}