Beispiel #1
0
  @Override
  public void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField pDepthMarketData) {

    // 直接在这里赋值,省去跳转的过程,优化
    DepthMarketDataField md_row;
    int md_index = myhandler.getInstrumentMap().get(pDepthMarketData.getInstrumentID());
    md_row = (DepthMarketDataField) MainActivity.mdList.get(md_index);
    md_row.setLastPrice(pDepthMarketData.getLastPrice());
    md_row.setUp_down(pDepthMarketData.getLastPrice() - pDepthMarketData.getPreSettlementPrice());
    md_row.setOpenInterest(pDepthMarketData.getOpenInterest());
    md_row.setAskPrice1(pDepthMarketData.getAskPrice1());
    md_row.setAskVolume1(pDepthMarketData.getAskVolume1());
    md_row.setBidPrice1(pDepthMarketData.getBidPrice1());
    md_row.setBidVolume1(pDepthMarketData.getBidVolume1());
    md_row.setUpperLimitPrice(pDepthMarketData.getUpperLimitPrice());

    Message msg = myhandler.obtainMessage(myhandler.getMD_SUB(), 1, 1, 0);
    myhandler.sendMessage(msg); // 发送消息

    if (TraderSpi.positionIndexMap.size() != 0) {

      String longPosition = (md_row.getInstrumentID() + "0").toString();
      String shortPosition = (md_row.getInstrumentID() + "1").toString();

      // 多头持仓合约的行情来了
      if (TraderSpi.positionIndexMap.get(longPosition) != null) {
        int positioIndex = TraderSpi.positionIndexMap.get(longPosition);
        PositionDetailField positionDetail = TraderSpi.positionsDetails_show.get(positioIndex);
        InstrumentField instrumentField = TraderSpi.pInstrumentMap.get(md_row.getInstrumentID());
        double positionProfitByTrade =
            (md_row.getLastPrice() - positionDetail.getOpenPrice())
                * positionDetail.getVolume()
                * instrumentField.getVolumeMultiple();

        positionDetail.setPositionProfitByTrade(positionProfitByTrade);
        Message msg1 = myhandler.obtainMessage(myhandler.getTRADE_UPDATE_POSITION_BY_MD(), 1, 1, 0);
        myhandler.sendMessage(msg1); // 发送消息
      }
      // 空头持仓合约的行情来了
      if (TraderSpi.positionIndexMap.get(shortPosition) != null) {
        int positioIndex_short = TraderSpi.positionIndexMap.get(shortPosition);
        PositionDetailField positionDetail_short =
            TraderSpi.positionsDetails_show.get(positioIndex_short);
        InstrumentField instrumentField_short =
            TraderSpi.pInstrumentMap.get(md_row.getInstrumentID());
        double positionProfitByTrade =
            (positionDetail_short.getOpenPrice() - md_row.getLastPrice())
                * positionDetail_short.getVolume()
                * instrumentField_short.getVolumeMultiple();

        positionDetail_short.setPositionProfitByTrade(positionProfitByTrade);

        Message msg2 = myhandler.obtainMessage(myhandler.getTRADE_UPDATE_POSITION_BY_MD(), 1, 1, 0);
        myhandler.sendMessage(msg2); // 发送消息
      }
    }
  }
Beispiel #2
0
 /* (non-Javadoc)
  * @see java.lang.Runnable#run()
  *****************************************************************************************
  */
 @Override
 public void run() {
   Constant.isTaskRunning = true;
   if (saveDir != null && !saveDir.exists()) {
     Intent intent = new Intent("SYSTEMUPDATE_DOWNLOAD_NOSAVEDIR");
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
     mContext.sendBroadcast(intent);
     Log.e(TAG, "存储路径不存在!!!广播已发送");
   }
   try {
     loader = new FileDownloader(mContext, path, saveDir, threadnum); // 初始化下载
     Log.i(TAG, "进度条最大值(文件大小):" + loader.getFileSize());
     filesize = loader.getFileSize();
     loader.downLoad(
         new DownloadProgressListener() {
           @Override
           public void onDownloadSize(int downloadSize) {
             Message msg = new Message(); // 用于向主线程发送下载进度的Messageduixia
             msg.what = Processing; // 设置为1
             msg.getData().putInt("size", downloadSize); // 把文件下载的长度放到Message对象
             mHandler.sendMessage(msg); // 发送消息到消息队列
           }
         });
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     Message msg = new Message(); // 用于向主线程发送下载进度的Messageduixia
     msg.what = Failure; // 设置为1
     Constant.isTaskRunning = false;
     mHandler.sendMessage(msg);
   }
 }
Beispiel #3
0
  @SuppressWarnings("deprecation")
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notification = new Notification();
    notification.icon = android.R.drawable.stat_sys_download;
    // notification.icon=android.R.drawable.stat_sys_download_done;
    notification.tickerText = getString(R.string.app_name) + "下载";
    notification.when = System.currentTimeMillis();
    notification.defaults = Notification.DEFAULT_LIGHTS;
    // 设置任务栏中下载进程显示的views
    views = new RemoteViews(getPackageName(), R.layout.version_update);
    notification.contentView = views;
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    notification.setLatestEventInfo(this, "", "", contentIntent);
    // 将下载任务添加到任务栏中
    nm.notify(notificationId, notification);

    myHandler = new MyHandler(Looper.myLooper(), this);

    // 初始化下载任务内容views
    Message message = myHandler.obtainMessage(3, 0);
    myHandler.sendMessage(message);

    // 启动线程�?��执行下载任务
    downFile(intent.getStringExtra("url"));
    return super.onStartCommand(intent, flags, startId);
  }
 public void sendMessage() {
   nameValuePairs.clear();
   Looper mainLooper = Looper.getMainLooper(); // �õ����߳�loop
   mHandler = new MyHandler(mainLooper); // �������̵߳�handler
   mHandler.removeMessages(0); // �Ƴ����ж����е���Ϣ
   Message m = mHandler.obtainMessage(1, 1, 1, s); // ����Ϣ����message
   mHandler.sendMessage(m); // ����message
 }
  public void updateView() {
    if (downloadId != 0L) {
      int[] bytesAndStatus = downloadManagerPro.getBytesAndStatus(downloadId);
      Log.v("updateView", bytesAndStatus[0] + " " + bytesAndStatus[1] + " " + bytesAndStatus[2]);

      handler.sendMessage(
          handler.obtainMessage(0, bytesAndStatus[0], bytesAndStatus[1], bytesAndStatus[2]));
    }
  }
 public static boolean sendMessageRemoved(Message msg) {
   boolean result = false;
   if (null != mHandler) {
     mHandler.removeMessages(msg.what);
     result = mHandler.sendMessage(msg);
   }
   Log.i(TAG, "LL sendMessageRemoved>>msg = " + msg.what);
   return result;
 }
  public static boolean sendMessage(Message msg) {
    boolean result = false;

    if (null != mHandler) {
      result = mHandler.sendMessage(msg);
    }
    Log.i(TAG, "LL sendMessage>>result = " + result);

    return result;
  }
  /**
   * 开始模拟定位数据
   *
   * @param provider 你的 provider 的名称
   */
  private void start(String provider) {
    this.mTargetProvider = provider;

    // 增加 test provider 之前必须先尝试关闭一下,因为可能已经增加过了。
    turnOffTestProvider(mTestProvider);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
      // 开启 test provider
      turnOnTestProvider(mTestProvider);
      // 在 handler 中真正开始模拟 location 数据
      mHandler.sendMessage(mHandler.obtainMessage(1));
    }
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_message);
   Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
   setSupportActionBar(toolbar);
   TextView textView = (TextView) findViewById(R.id.tv_msg);
   /*ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "translationX", 1080, 0);
   objectAnimator.setDuration(5000);
   objectAnimator.start();*/
   MyHandler myHandler = new MyHandler();
   MyBundle myBundle = new MyBundle();
   myBundle.setName("lily");
   Message message = Message.obtain();
   message.what = 0;
   message.obj = myBundle;
   myHandler.sendMessage(message);
   MyBundle myBundle1 = new MyBundle();
   myBundle1.setName("hah");
   message.obj = myBundle1;
   // message.what=1;
   myHandler.sendMessage(message);
 }
 public void hideSkylight(boolean isGotoUnlock) {
   Message msg = mHandler.obtainMessage(MSG_HIDE_SKYLIGHT, isGotoUnlock);
   mHandler.sendMessage(msg);
 }
Beispiel #11
0
 @Override
 public void OnRspError(CThostFtdcRspInfoField pRspInfo, int nRequestID, boolean bIsLast) {
   Message msg = myhandler.obtainMessage(myhandler.getMD_RSP_ERROR(), 1, 1, "行情处理有误\n");
   myhandler.sendMessage(msg); // 发送消息
 }
Beispiel #12
0
 @Override
 public void OnFrontDisconnected(int nReason) {
   Message msg = myhandler.obtainMessage(myhandler.getMD_FRONT_CONNFAILD(), 1, 1, nReason);
   myhandler.sendMessage(msg); // 发送消息
 }
 public void stop() {
   mHandler.sendMessage(mHandler.obtainMessage(2));
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
     turnOffTestProvider(mTestProvider);
   }
 }
Beispiel #14
0
 public static void message(Message msg) {
   if (sHandler != null) {
     sHandler.sendMessage(msg);
   }
 }
 public void sendMessage(Bitmap bitmap, int i) { // �̼߳���ݴ���
   mHandler.removeMessages(0); // �Ƴ����ж����е���Ϣ
   Message m = mHandler.obtainMessage(1, 1, i, bitmap); // ����Ϣ����message
   mHandler.sendMessage(m); // ����message
 }