@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 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; }
/** * 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; }
@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 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; }
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 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; }
@Override protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); if (positiveResult) { String alphaTag = mPhone.getLine1AlphaTag(); if (TextUtils.isEmpty(alphaTag)) { // No tag, set it. alphaTag = getContext().getString(R.string.msisdn_alpha_tag); } mPhone.setLine1Number( alphaTag, getText(), mHandler.obtainMessage(MyHandler.MESSAGE_SET_MSISDN)); if (mTcpListener != null) { mTcpListener.onStarted(this, false); } // Save the number SharedPreferences prefs = getSharedPreferences(); Editor editor = prefs.edit(); String phoneNum = getText().trim(); String savedNum = prefs.getString(PHONE_NUMBER, null); // If there is no string, treat it as null if (phoneNum.length() == 0) { phoneNum = null; } if (phoneNum == null && savedNum == null) { Log.d(LOG_TAG, "No phone number set yet"); } else if (TextUtils.equals(phoneNum, savedNum)) { /* Save phone number only if there is some number set and it is not equal to the already saved one */ if (DBG) { Log.d(LOG_TAG, "Saving phone number: " + phoneNum); } editor.putString(PHONE_NUMBER, phoneNum); editor.commit(); } else if (phoneNum == null && savedNum != null) { /* Remove saved number only if there is some saved and there is no number set */ if (DBG) { Log.d(LOG_TAG, "Removing phone number"); } editor.remove(PHONE_NUMBER); editor.commit(); } else if (DBG) { Log.d(LOG_TAG, "No change"); } } }
/** * 开始模拟定位数据 * * @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 onResume() { super.onResume(); // upon resumption from the sub-activity, make sure we re-enable the // preferences. getPreferenceScreen().setEnabled(true); if (mGsmUmtsOptions != null) mGsmUmtsOptions.enableScreen(); if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null) { mPhone.getPreferredNetworkType( mHandler.obtainMessage(MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE)); } }
@Override public void call(Session session, SessionState state, Exception exception) { Log.v("SessionStatusCallback", "call cbIndex:" + mCallbackIndex); Log.v("SessionStatusCallback", "state:" + state.toString()); if (exception != null) Log.v("SessionStatusCallback", "exception:" + exception.toString()); switch (mCallByMode) { case CallByLogin: if (session.isOpened()) { mCallByMode = CallByNull; // Date curDate = new Date(); // Log.v(Tag,"getExpirationDate:"+(session.getExpirationDate().getTime()-curDate.getTime())); if (mCallbackIndex != -1) nativeCallback( mCallbackIndex, "{\"authResponse\":{\"accessToken\":\"" + session.getAccessToken() + "\"},\"status\":\"connected\"}"); } else if (state == SessionState.CLOSED_LOGIN_FAILED) { mCallByMode = CallByNull; if (mCallbackIndex != -1) nativeCallback( mCallbackIndex, "{\"authResponse\":null,\"status\":\"not_authorized\"}"); } break; case CallByLogout: if (session.isClosed()) { mCallByMode = CallByNull; if (mCallbackIndex != -1) nativeCallback(mCallbackIndex, "{\"authResponse\":{},\"status\":\"unknown\"}"); } break; case CallByFBUI: { if (session.isOpened()) { mCallByMode = CallByNull; Message message = myHandler.obtainMessage(MyHandler.EXECUTE_WEBDIALOG, params); message.arg1 = mCallbackIndex; message.sendToTarget(); } else if (state == SessionState.CLOSED_LOGIN_FAILED) { mCallByMode = CallByNull; if (mCallbackIndex != -1) nativeCallback(mCallbackIndex, "null"); } break; } default: break; } }
public static void ui(String params, int cbIndex) { Session session = Session.getActiveSession(); if (session == null) { session = new Session(mContext); Session.setActiveSession(session); } if (session.isOpened()) { Message message = myHandler.obtainMessage(MyHandler.EXECUTE_WEBDIALOG, params); message.arg1 = cbIndex; message.sendToTarget(); } else { mStatusCallback.mCallByMode = SessionStatusCallback.CallByFBUI; mStatusCallback.mCallbackIndex = cbIndex; mStatusCallback.params = params; if (!session.isClosed()) { session.openForRead(new Session.OpenRequest(mActivity).setCallback(mStatusCallback)); } else { Session.openActiveSession(mActivity, true, mStatusCallback); } } }
public void hideSkylight(boolean isGotoUnlock) { Message msg = mHandler.obtainMessage(MSG_HIDE_SKYLIGHT, isGotoUnlock); mHandler.sendMessage(msg); }
@Override public void OnRspError(CThostFtdcRspInfoField pRspInfo, int nRequestID, boolean bIsLast) { Message msg = myhandler.obtainMessage(myhandler.getMD_RSP_ERROR(), 1, 1, "行情处理有误\n"); myhandler.sendMessage(msg); // 发送消息 }
@Override public void OnFrontDisconnected(int nReason) { Message msg = myhandler.obtainMessage(myhandler.getMD_FRONT_CONNFAILD(), 1, 1, nReason); myhandler.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 }
public void stop() { mHandler.sendMessage(mHandler.obtainMessage(2)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) { turnOffTestProvider(mTestProvider); } }