List of usage examples for android.os Message Message
public Message()
From source file:com.continuesvoicerecognition.MainActivity.java
@Override public void onClick(View v) { if (PermissionHandler.checkPermission(this, PermissionHandler.RECORD_AUDIO)) { Message msg = new Message(); switch (v.getId()) { case R.id.start_listen_btn: msg.what = SpeechRecognizerService.MSG_RECOGNIZER_START_LISTENING; try { mServiceMessenger.send(msg); } catch (RemoteException e) { e.printStackTrace();/*from w w w. jav a2 s . co m*/ } result_tv.setText(getString(R.string.you_may_speak)); break; case R.id.stop_listen_btn: msg.what = SpeechRecognizerService.MSG_RECOGNIZER_STOP_LISTENING; try { mServiceMessenger.send(msg); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.mute: msg.what = SpeechRecognizerService.MSG_RECOGNIZER_TOGGLE_MUTE; try { mServiceMessenger.send(msg); } catch (RemoteException e) { e.printStackTrace(); } break; } } else { PermissionHandler.askForPermission(PermissionHandler.RECORD_AUDIO, this); } }
From source file:com.xmobileapp.rockplayer.LastFmEventImporter.java
/********************************* * //from w ww .j a v a2s. co m * Constructor * @param context * *********************************/ public LastFmEventImporter(Context context) { this.context = context; Log.i("LASTFMEVENT", "creating-------------------------"); /* * Check for Internet Connection (Through whichever interface) */ ConnectivityManager connManager = (ConnectivityManager) ((RockPlayer) context) .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connManager.getActiveNetworkInfo(); /******* EMULATOR HACK - false condition needs to be removed *****/ //if (false && (netInfo == null || !netInfo.isConnected())){ if ((netInfo == null || !netInfo.isConnected())) { Bundle data = new Bundle(); data.putString("info", "No Internet Connection"); Message msg = new Message(); msg.setData(data); ((RockPlayer) context).analyseConcertInfoHandler.sendMessage(msg); return; } /* * Get location */ MIN_UPDATE_INTVL = 5 * 24 * 60 * 60 * 1000; // 5 days SPREAD_INTVL = 21 * 24 * 60 * 60 * 1000; // 21 days; Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locManager.getBestProvider(criteria, true) != null) myLocation = locManager.getLastKnownLocation(locManager.getBestProvider(criteria, true)); else { myLocation = new Location("gps"); myLocation.setLatitude(47.100301); myLocation.setLongitude(-119.982465); } /* * Get preferred distance */ // SharedPreferences prefs = ((Filex) context).getSharedPreferences(((Filex) context).PREFS_NAME, 0); RockOnPreferenceManager prefs = new RockOnPreferenceManager(((RockPlayer) context).FILEX_PREFERENCES_PATH); concertRadius = prefs.getLong("ConcertRadius", (long) (((RockPlayer) context).CONCERT_RADIUS_DEFAULT)); //myLocation = locManager.getLastKnownLocation(locManager.getBestProvider(Criteria.POWER_LOW, true)); // try { // getArtistEvents(); // } catch (SAXException e) { // e.printStackTrace(); // } catch (ParserConfigurationException e) { // e.printStackTrace(); // } }
From source file:com.example.parking.InputLicenseActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mDBAdapter = new DBAdapter(this); Intent intent = getIntent();//w ww . j a v a 2s .com Bundle bundle = intent.getExtras(); if (bundle.getInt("type") == ARRIVING_TYPE) { mType = ARRIVING_TYPE; } else if (bundle.getInt("type") == LEAVING_TYPE) { mType = LEAVING_TYPE; } setContentView(R.layout.activity_input_license); mLicensePlateET = (EditText) findViewById(R.id.et_license_plate); mLetterTV = (TextView) findViewById(R.id.tv_letter); mNumberTV = (TextView) findViewById(R.id.tv_number); mLocationTV = (TextView) findViewById(R.id.tv_location); mScanBT = (Button) findViewById(R.id.bt_scan); mNextBT = (Button) findViewById(R.id.bt_next); mLetterTV.setOnClickListener(mTabClickListener); mNumberTV.setOnClickListener(mTabClickListener); mLocationTV.setOnClickListener(mTabClickListener); changeSelect(R.id.tv_location); changeFragment(R.id.tv_location); mLicensePlateET.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // et.getCompoundDrawables()4? Drawable drawable = mLicensePlateET.getCompoundDrawables()[2]; //???? if (drawable == null) return false; //???? if (event.getAction() != MotionEvent.ACTION_UP) return false; if (event.getX() > mLicensePlateET.getWidth() - mLicensePlateET.getPaddingRight() - drawable.getIntrinsicWidth()) { mLicensePlateET.setText(""); } return false; } }); mScanBT.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { Message msg = new Message(); msg.what = EVENT_SCAN_STATE_NOTIFY; mHandler.sendMessage(msg); } }); mLicensePlateET.setInputType(InputType.TYPE_NULL); mLicensePlateET.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (mLicensePlateET.getText() != null && mLicensePlateET.getText().length() > LICENSE_PLATE_NUMBER_SIZE) { Message msg = new Message(); msg.what = EVENT_INVALID_LICENSE_PLATE; mHandler.sendMessage(msg); } } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); mNextBT.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { if (mLicensePlateET.getText().length() != LICENSE_PLATE_NUMBER_SIZE) { Message msg = new Message(); msg.what = EVENT_INVALID_LICENSE_PLATE; mHandler.sendMessage(msg); return; } new SQLThread().start(); } }); getActionBar().setDisplayHomeAsUpEnabled(true); IntentFilter filter = new IntentFilter(); filter.addAction("ExitApp"); filter.addAction("BackMain"); registerReceiver(mReceiver, filter); }
From source file:com.mk4droid.IMC_Activities.Fragment_List.java
/** on create this fragment view */ @Override/*from w w w.j a v a 2 s . co m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { FActivity_TabHost.IndexGroup = 1; if (vFragment_List != null) { ViewGroup parent = (ViewGroup) vFragment_List.getParent(); if (parent != null) parent.removeView(vFragment_List); } try { if (vFragment_List == null) vFragment_List = inflater.inflate(R.layout.fragment_list, container, false); } catch (InflateException e) { /* map is already there, just return view as it is */ } mFragment_List = this; ctx = mFragment_List.getActivity(); lvIssues = (ListView) vFragment_List.findViewById(R.id.lvIssues); //--------------- Receiver for Data change ------------ HandlersAndReceivers(); resources = setResources(); handlerBroadcastListRefresh.sendMessage(new Message()); //---------- Buttons ----------- ll_listissues_MyIssues = (LinearLayout) vFragment_List.findViewById(R.id.ll_listissues_MyIssues); btListMyIss = (Button) vFragment_List.findViewById(R.id.bt_listissues_MyIssues); btListAllIss = (Button) vFragment_List.findViewById(R.id.bt_listissues_AllIssues); // onclick listeners btListMyIss.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SetComplementaryButtons(); } }); btListAllIss.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SetComplementaryButtons(); } }); //----------------------- if (Fragment_Issue_Details.mfrag_issue_details != null) if (Fragment_Issue_Details.mfrag_issue_details.isVisible()) getChildFragmentManager().beginTransaction().hide(mFragment_List).commit(); return vFragment_List; }
From source file:org.cocos2dx.lib.Cocos2dxActivity.java
@Override public void showEditTextDialog(final String pTitle, final String pContent, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength) { Message msg = new Message(); msg.what = Cocos2dxHandler.HANDLER_SHOW_EDITBOX_DIALOG; msg.obj = new Cocos2dxHandler.EditBoxMessage(pTitle, pContent, pInputMode, pInputFlag, pReturnType, pMaxLength);// w w w .j ava2s . c om this.mHandler.sendMessage(msg); }
From source file:com.geekandroid.sdk.pay.impl.CHWeiXinPay.java
public void doRealPay(final Map<String, Object> parameters) { if (TextUtils.isEmpty(APP_ID) || TextUtils.isEmpty(MCH_ID) || TextUtils.isEmpty(API_KEY)) { Log.e("doRealPay", "APP_ID MCH_IDAPI_KEY"); return;/*w w w . ja v a2 s .c o m*/ } //check request if (isEmpty(parameters.get("body")) || isEmpty(parameters.get("out_trade_no")) || isEmpty(parameters.get("total_fee")) || isEmpty(parameters.get("spbill_create_ip")) || isEmpty(parameters.get("notify_url"))) { Log.e("doRealPay", "?[ detail, out_trade_no, spbill_create_ip, total_fee, notify_url]"); return; } if (parameters.get("out_trade_no").toString().length() > 32) { Log.e("doRealPay", "?? 32 ?"); return; } //??? ? ? double ???? if (parameters.get("total_fee") instanceof Double) { String totalfee = parameters.get("total_fee").toString(); int realMoney = (int) mul(Double.parseDouble(totalfee), 100); parameters.put("total_fee", realMoney); } Runnable payRunnable = new Runnable() { @Override public void run() { boolean isSuccess = pay(parameters); Message msg = new Message(); msg.what = WX_SDK_PAY_FLAG; msg.obj = isSuccess; handler.sendMessage(msg); } }; // Thread payThread = new Thread(payRunnable); payThread.start(); }
From source file:com.nextgis.metroaccess.MetaDownloader.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(moContext)) { try {// ww w. j a v a2s . com String sURL = urls[0]; moHTTPGet = new HttpGet(sURL); Log.d(TAG, "HTTPGet URL " + sURL); HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 1500; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpClient Client = new DefaultHttpClient(httpParameters); HttpResponse response = Client.execute(moHTTPGet); if (response == null) return null; HttpEntity entity = response.getEntity(); if (moEventReceiver != null) { if (entity != null) { Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean(BUNDLE_ERRORMARK_KEY, false); msContent = EntityUtils.toString(entity, HTTP.UTF_8); bundle.putString(BUNDLE_PAYLOAD_KEY, msContent); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); } else { bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true); bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkGetErr)); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); } Message oMsg = new Message(); oMsg.setData(bundle); moEventReceiver.sendMessage(oMsg); } else { msError = moContext.getString(R.string.sNetworkUnreachErr); } } } catch (ClientProtocolException e) { msError = e.getMessage(); //cancel(true); } catch (IOException e) { msError = e.getMessage(); //cancel(true); } } else { if (moEventReceiver != null) { Bundle bundle = new Bundle(); bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true); bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkUnreachErr)); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); Message oMsg = new Message(); oMsg.setData(bundle); moEventReceiver.sendMessage(oMsg); } } return null; }
From source file:com.spoiledmilk.ibikecph.login.HTTPAccountHandler.java
public static Message performDeleteUser(UserData userData) { Message message = new Message(); JsonNode result = null;/*from w w w. j ava2s. co m*/ JSONObject jsonPOST = new JSONObject(); try { jsonPOST.put("auth_token", userData.getAuth_token()); LOG.d("fb auth token = " + userData.getAuth_token()); result = HttpUtils.deleteFromServer(Config.API_SERVER_REGISTER + "/" + userData.getId(), jsonPOST); message = HttpUtils.JSONtoMessage(result); message.getData().putInt("type", DELETE_USER); } catch (JSONException e) { LOG.e(e.getLocalizedMessage()); message.getData().putInt("type", ERROR); } return message; }
From source file:com.oneguy.recognize.engine.GoogleStreamingEngine.java
@Override public void takeAudioChunk(byte[] chunk) { if (mHandler == null) { Log.e(TAG, "can not transmit,run engine in a thread first!"); return;/*w w w .j av a 2s . co m*/ } if (chunk == null) { return; } Message msg = new Message(); msg.what = EVENT_AUDIO_CHUNK; msg.obj = chunk; mHandler.sendMessage(msg); }
From source file:com.nextgis.firereporter.HttpGetter.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(mContext)) { try {//w w w . jav a 2 s . c o m String sURL = urls[0]; httpget = new HttpGet(sURL); Log.d("MainActivity", "HTTPGet URL " + sURL); if (urls.length > 1) { httpget.setHeader("Cookie", urls[1]); } //TODO: move timeouts to parameters HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 1500; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpClient Client = new DefaultHttpClient(httpParameters); HttpResponse response = Client.execute(httpget); //ResponseHandler<String> responseHandler = new BasicResponseHandler(); //mContent = Client.execute(httpget, responseHandler); HttpEntity entity = response.getEntity(); Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean(GetFiresService.ERROR, false); mContent = EntityUtils.toString(entity); bundle.putString(GetFiresService.JSON, mContent); } else { bundle.putBoolean(GetFiresService.ERROR, true); bundle.putString(GetFiresService.ERR_MSG, response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase()); } bundle.putInt(GetFiresService.SOURCE, mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } catch (ClientProtocolException e) { mError = e.getMessage(); cancel(true); } catch (IOException e) { mError = e.getMessage(); cancel(true); } } else { Bundle bundle = new Bundle(); bundle.putBoolean(GetFiresService.ERROR, true); bundle.putString(GetFiresService.ERR_MSG, mContext.getString(R.string.noNetwork)); bundle.putInt(GetFiresService.SOURCE, mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } return null; }