/**
   * Test that encrypts using EncryptedKeySHA1, where it uses a symmetric key, rather than a
   * generated session key which is then encrypted using a public key. The request is generated
   * using WSHandler, instead of coding it.
   *
   * @throws java.lang.Exception Thrown when there is any problem in encryption or decryption
   */
  public void testEncryptionSHA1SymmetricBytesHandler() throws Exception {
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    java.util.Map messageContext = new java.util.TreeMap();
    messageContext.put(WSHandlerConstants.ENC_SYM_ENC_KEY, "false");
    messageContext.put(WSHandlerConstants.ENC_KEY_ID, "EncryptedKeySHA1");
    messageContext.put(WSHandlerConstants.PW_CALLBACK_REF, this);
    reqData.setMsgContext(messageContext);
    reqData.setUsername("");

    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.ENCR));

    Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.send(WSConstants.ENCR, doc, reqData, actions, true);

    String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
    if (LOG.isDebugEnabled()) {
      LOG.debug(outputString);
    }

    verify(doc);
  }
 /** 开始记录Log */
 public static void startLogOut() {
   Log.i(TAG, "start startLogOut");
   if (null != mHandler) {
     mHandler.removeMessages(ConstMessageType.DTV_LOG_OUT_MESSAGE);
     mHandler.sendEmptyMessage(ConstMessageType.DTV_LOG_OUT_MESSAGE);
   }
 }
Example #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 go(final FilePath rootPath, final SVNDepth depth) throws SVNException {
    final MyItem root =
        new MyItem(myProject, rootPath, depth, myPartner.createStatusClient(), false);
    myQueue.add(root);

    while (!myQueue.isEmpty()) {
      myPartner.checkCanceled();

      final MyItem item = myQueue.removeFirst();
      final FilePath path = item.getPath();
      final File ioFile = path.getIOFile();

      if (path.isDirectory()) {
        myHandler.setCurrentItem(item);
        try {
          item.getClient(ioFile)
              .doStatus(
                  ioFile,
                  SVNRevision.WORKING,
                  item.getDepth(),
                  false,
                  false,
                  true,
                  false,
                  myHandler,
                  null);
          myHandler.checkIfCopyRootWasReported();
        } catch (SVNException e) {
          if (e.getErrorMessage().getErrorCode() == SVNErrorCode.WC_NOT_DIRECTORY) {
            final VirtualFile virtualFile = path.getVirtualFile();
            if (virtualFile != null) {
              if (myPartner.isExcluded(virtualFile)) return;
              // self is unversioned
              myReceiver.processUnversioned(virtualFile);

              processRecursively(virtualFile, item.getDepth());
            }
          } else {
            throw e;
          }
        }
      } else {
        if (item.isIsInnerCopyRoot()) {
          // this means that the status of parent directory had already been checked and is
          // unversioned;
          // to avoid SVN exception on status query to unversioned directory; and since we already
          // know then that the file
          // status is "unversioned" -> just register the unversioned file
          if (path.getVirtualFile() != null) {
            myReceiver.processUnversioned(path.getVirtualFile());
          }
        } else {
          // just file
          final SVNStatus status = item.getClient().doStatus(ioFile, false, false);
          myReceiver.process(path, status);
        }
      }
    }
  }
 public int parseLyricId(InputStream is) throws Exception {
   SAXParserFactory factory = SAXParserFactory.newInstance(); // 取得SAXParserFactory实例
   SAXParser parser = factory.newSAXParser(); // 从factory获取SAXParser实例
   MyHandler handler = new MyHandler(); // 实例化自定义Handler
   parser.parse(is, handler); // 根据自定义Handler规则解析输入流
   is.close();
   return handler.getFirstLyricId();
 }
 @Override
 public List<ChatEmoji> parse(InputStream is) throws Exception {
   SAXParserFactory factory = SAXParserFactory.newInstance(); // 取得SAXParserFactory实例
   SAXParser parser = factory.newSAXParser(); // 从factory获取SAXParser实例
   MyHandler handler = new MyHandler(); // 实例化自定义Handler
   parser.parse(is, handler); // 根据自定义Handler规则解析输入流
   return handler.getEmojis();
 }
Example #7
0
 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
 }
Example #8
0
  @Test
  public void testAMINoException() {
    MyHandler handler = new MyHandler();

    ((_BugJac560ServiceStub) server).sendc_exc(handler._this(setup.getClientOrb()), false);

    assertTrue(handler.isDone(TestUtils.getMediumTimeout()));
    assertNull(handler.getException(0));
  }
Example #9
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); // 发送消息
      }
    }
  }
  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 sendEmptyMessageRemoved(int what) {
   boolean result = false;
   if (null != mHandler) {
     mHandler.removeMessages(what);
     result = mHandler.sendEmptyMessage(what);
   }
   Log.i(TAG, "LL sendMessageRemoved>>msg = " + what);
   return result;
 }
 /**
  * sendMessage的不同方法
  *
  * @param what
  * @param delayMillis
  * @return
  */
 public static boolean sendEmptyMessageRemovedDelayed(int what, long delayMillis) {
   boolean result = false;
   if (null != mHandler) {
     mHandler.removeMessages(what);
     result = mHandler.sendEmptyMessageDelayed(what, delayMillis);
   }
   Log.i(TAG, "LL sendEmptyMessageRemovedDelayed>>msg = " + what);
   return result;
 }
  public static void main(String[] args) {
    MyHandler h1 = new MyHandler("h1");
    MyHandler h2 = new MyHandler("h2");
    MyHandler h3 = new MyHandler("h3");

    h1.setHandler(h2);
    h2.setHandler(h3);

    h1.operator();
  }
Example #15
0
  @Test
  public void testAMIWithException() {
    MyHandler handler = new MyHandler();

    ((_BugJac560ServiceStub) server).sendc_exc(handler._this(setup.getClientOrb()), true);

    assertTrue(handler.isDone(TestUtils.getMediumTimeout()));
    final Exception exception = handler.getException(0);
    assertEquals(xNoSuchDefault.class, exception.getClass());
  }
    @Override
    public void handleMessage(Message msg) {
      Log.i(
          TAG,
          "LL inThread:"
              + Thread.currentThread()
              + " handleMessage>>msg:"
              + msg.what
              + " DtvRoot.isWaitingService ="
              + DtvRoot.isWaitingService);

      switch (msg.what) {
        case ConstMessageType.DTV_SCREEN_SAVER_MESSAGE: // 退出屏保
          if (!DtvRoot.isWaitingService) {
            if (null == mDtvCommonManager) {
              mDtvCommonManager = DtvCommonManager.getInstance();
            }
            mDtvCommonManager.enterScreenSaver();
          }
          break;

        case ConstMessageType.DTV_LOG_OUT_MESSAGE: // 记录Log信息
          if (!DtvRoot.isWaitingService) {
            if (DtvDebugManager.getInstance().isDebug()) {
              WriteLogInfo();
              mHandler.sendEmptyMessageDelayed(ConstMessageType.DTV_LOG_OUT_MESSAGE, 5000);
            }
          }
          break;

        case TIME_OUT: // 定时器到时
          curTime--;
          counter++;
          if (null != mTimer) {
            mTimer.onTimeCallBack(counter);
          } else {
            Log.i(TAG, "mTimer is null");
          }
          if (curTime > 0) {
            mHandler.sendEmptyMessageDelayed(TIME_OUT, 1000); // 每隔1s,执行回调onTimeCallBack(counter)
          } else {
            mHandler.removeMessages(TIME_OUT);
          }
          Log.i(TAG, "counter: " + counter + " LL inThread:" + Thread.currentThread());
          break;

        case COPY_SYSTEM_INFO: // 复制系统信息
          CopySystemInfo();
          break;

        default:
          break;
      }
    }
  public static Message obtainMessage(int what, Object obj) {
    Message msg = null;
    if (null != mHandler) {

      if (null == obj) {
        msg = mHandler.obtainMessage(what);
      } else {
        msg = mHandler.obtainMessage(what, obj);
      }
    }
    Log.i(TAG, "LL obtainMessage>>mHandler = " + mHandler + ",msg = " + msg + ",obj = " + obj);
    return msg;
  }
Example #18
0
  /**
   * 开始模拟定位数据
   *
   * @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));
    }
  }
Example #19
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);
   }
 }
  /**
   * Implemented to support onPreferenceChangeListener to look for preference changes specifically
   * on CLIR.
   *
   * @param preference is the preference to be changed, should be mButtonCLIR.
   * @param objValue should be the value of the selection, NOT its localized display value.
   */
  public boolean onPreferenceChange(Preference preference, Object objValue) {
    if (preference == mButtonPreferredNetworkMode) {
      // NOTE onPreferenceChange seems to be called even if there is no change
      // Check if the button value is changed from the System.Setting
      mButtonPreferredNetworkMode.setValue((String) objValue);
      int buttonNetworkMode;
      buttonNetworkMode = Integer.valueOf((String) objValue).intValue();
      int settingsNetworkMode = getPreferredNetworkMode();
      if (buttonNetworkMode != settingsNetworkMode) {
        int modemNetworkMode = buttonNetworkMode;
        // if new mode is invalid set mode to default preferred
        if ((modemNetworkMode < Phone.NT_MODE_WCDMA_PREF)
            || (modemNetworkMode > Phone.NT_MODE_LTE_ONLY)) {
          modemNetworkMode = Phone.PREFERRED_NT_MODE;
        }

        // If button has no valid selection && setting is LTE ONLY
        // mode, let the setting stay in LTE ONLY mode. UI is not
        // supported but LTE ONLY mode could be used in testing.
        if ((modemNetworkMode == Phone.PREFERRED_NT_MODE)
            && (settingsNetworkMode == Phone.NT_MODE_LTE_ONLY)) {
          return true;
        }

        UpdatePreferredNetworkModeSummary(buttonNetworkMode);
        setPreferredNetworkMode(buttonNetworkMode);
        // Set the modem network mode
        mPhone.setPreferredNetworkType(
            modemNetworkMode, mHandler.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
      }
    }

    // always let the preference setting proceed.
    return true;
  }
 public void animateWave() {
   if (!isWaving) {
     mWaveFactor = 0L;
     isWaving = true;
     mHandler.sendEmptyMessage(0);
   }
 }
  public static void removeMessages(int what) {
    boolean result = false;

    if (null != mHandler) {
      mHandler.removeMessages(what);
    }
    Log.i(TAG, "LL removeMessages>>result = " + result);
  }
  public static boolean sendMessageDelayed(Message msg, long delayMillis) {
    boolean result = false;

    if (null != mHandler) {
      result = mHandler.sendMessageDelayed(msg, delayMillis);
    }
    Log.i(TAG, "LL sendMessageDelayed>>msg = " + msg + ",delayMillis = " + delayMillis);
    return result;
  }
  public static Message obtainMessage(int what) {
    Message msg = null;

    if (null != mHandler) {
      msg = mHandler.obtainMessage(what);
    }
    Log.i(TAG, "LL obtainMessage>>mHandler = " + mHandler + ",msg = " + msg);
    return msg;
  }
 /**
  * 设置时间并开始定时器
  *
  * @param seconds
  * @return
  */
 public static boolean setTimer(int seconds) {
   removeTimer();
   if (null != mHandler) {
     curTime = seconds;
     mHandler.sendEmptyMessageDelayed(TIME_OUT, 1000);
     return true;
   }
   return false;
 }
  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;
  }
 public void updateSKylight() {
   mHandler.post(
       new Runnable() {
         @Override
         public void run() {
           mSkylightHost.updateSkylightLocation();
           showSkylight();
         }
       });
 }
 @Override
 public void onTaskFinish(ITask task, InputStream is) {
   // TODO Auto-generated method stub
   Utility.saveFile(is, AppConstants.AVATOR_PATH);
   Bitmap temp = BitmapFactory.decodeFile(AppConstants.AVATOR_PATH);
   mAvator = Utility.toRoundBitmap(temp);
   temp.recycle();
   temp = null;
   mHandler.sendEmptyMessage(AppConstants.MsgType.LOGIN_SUCCESS);
 }
 public static void stopLogOut() {
   Log.i(TAG, "stop LogOut");
   if (null != mHandler) {
     mHandler.removeMessages(ConstMessageType.DTV_LOG_OUT_MESSAGE);
   }
   if (null != ps) {
     ps.destroy();
     ps = null;
   }
 }
  public static String api(String graphPath, String method, String params, int cbIndex) {
    Log.v(TAG, "api-graphPath:" + graphPath);

    Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
      HttpMethod httpMethod = HttpMethod.GET;
      if (method != null) {
        if (method.compareTo("post") == 0) httpMethod = HttpMethod.POST;
        else if (method.compareTo("delete") == 0) httpMethod = HttpMethod.DELETE;
      }

      Bundle parameters = new Bundle();
      try {
        if (params != null) {
          JSONObject jsonObject = new JSONObject(params);
          Iterator<String> iterator = jsonObject.keys();
          String key = null;
          String value = null;
          while (iterator.hasNext()) {
            key = iterator.next();
            Object object = jsonObject.get(key);
            if (object instanceof String) {
              value = (String) object;
              if (key.compareTo("method") != 0) parameters.putString(key, value);
            } else if (object instanceof Integer) {
              parameters.putInt(key, ((Integer) object).intValue());
            } else if (object instanceof Boolean) {
              parameters.putBoolean(key, ((Boolean) object).booleanValue());
            } else if (object instanceof Double) {
              parameters.putDouble(key, ((Double) object).doubleValue());
            } else {
              Log.w(TAG, "other type:" + object.toString());
            }
          }
        }
      } catch (JSONException e) {
        e.printStackTrace();
      }

      Request request =
          new Request(
              session,
              graphPath,
              parameters,
              httpMethod,
              new FacebookConnectPlugin.RequestCallback(cbIndex));
      Message message = myHandler.obtainMessage(MyHandler.EXECUTE_REQUEST, request);

      message.sendToTarget();
    } else {
      return "{\"message\":\"An active access token must be used to query information about the current user.\""
          + ",\"type\":\"OAuthException\",\"code\": 2500}";
    }
    return null;
  }