List of usage examples for android.os HandlerThread HandlerThread
public HandlerThread(String name)
From source file:com.peptrack.gps.locationupdatesforegroundservice.LocationUpdatesService.java
@Override public void onCreate() { mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); mLocationCallback = new LocationCallback() { @Override//w w w. j a v a 2s. c o m public void onLocationResult(LocationResult locationResult) { super.onLocationResult(locationResult); onNewLocation(locationResult.getLastLocation()); } }; createLocationRequest(); getLastLocation(); HandlerThread handlerThread = new HandlerThread(TAG); handlerThread.start(); mServiceHandler = new Handler(handlerThread.getLooper()); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Android O requires a Notification Channel. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = getString(R.string.app_name); // Create the channel for the notification NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT); // Set the Notification Channel for the Notification Manager. mNotificationManager.createNotificationChannel(mChannel); } }
From source file:com.amaze.filemanager.ui.icons.IconHolder.java
/** * Method that returns a drawable reference of a FileSystemObject. * * @param iconView View to load the drawable into * @param fso The FileSystemObject reference * @param defaultIcon Drawable to be used in case no specific one could be found * @return Drawable The drawable reference *//*from w ww .j av a 2s . c o m*/ public void loadDrawable(ImageView iconView, final String fso, Drawable defaultIcon) { if (!mUseThumbs) { return; } // Is cached? final String filePath = fso; if (this.mAppIcons.containsKey(filePath)) { iconView.setImageBitmap(this.mAppIcons.get(filePath)); return; } mRequests.put(iconView, fso); new Thread(new Runnable() { @Override public void run() { mHandler.removeMessages(MSG_DESTROY); if (mWorkerThread == null || mWorkerHandler == null) { mWorkerThread = new HandlerThread("IconHolderLoader"); mWorkerThread.start(); mWorkerHandler = new WorkerHandler(mWorkerThread.getLooper()); } Message msg = mWorkerHandler.obtainMessage(MSG_LOAD, fso); msg.sendToTarget(); } }).start(); }
From source file:com.snda.mymarket.providers.downloads.DownloadService.java
/** * Initializes the service when it is first created *///from w ww. ja v a 2 s . c om public void onCreate() { super.onCreate(); if (Constants.LOGVV) { Log.v(Constants.TAG, "Service onCreate"); } if (mSystemFacade == null) { mSystemFacade = new RealSystemFacade(this); } mObserver = new DownloadManagerContentObserver(); getContentResolver().registerContentObserver(Downloads.ALL_DOWNLOADS_CONTENT_URI, true, mObserver); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mNotifier = new DownloadNotifier(this); mNotifier.cancelAll(); mScanner = new DownloadScanner(this); mUpdateThread = new HandlerThread(Constants.TAG + "-UpdateThread"); mUpdateThread.start(); mUpdateHandler = new Handler(mUpdateThread.getLooper(), mUpdateCallback); updateFromProvider(); }
From source file:MainActivity.java
private void startPreview(CameraCaptureSession session) { mCameraCaptureSession = session;/*from w w w . j a v a2 s . co m*/ mCaptureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); HandlerThread backgroundThread = new HandlerThread("CameraPreview"); backgroundThread.start(); Handler backgroundHandler = new Handler(backgroundThread.getLooper()); try { mCameraCaptureSession.setRepeatingRequest(mCaptureRequestBuilder.build(), null, backgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
From source file:com.cssweb.android.trade.stock.StockTrading.java
@Override public void onCreate(Bundle paramBundle) { super.onCreate(paramBundle); sc = new ServiceControl(this);//?? ////w w w . j a va 2s . c om HandlerThread mHandlerThread = new HandlerThread("CSSWEB_THREAD"); mHandlerThread.start(); priceHandler = new PriceDataHandler(mHandlerThread.getLooper()); setContentView(com.cssweb.android.main.R.layout.zr_trade_stock_trade); Bundle bundle = getIntent().getExtras(); type = bundle.getInt("type"); bsname = bundle.getString("bsname"); String stockCode = bundle.getString("stkcode"); initTitle(R.drawable.njzq_title_left_back, 0, bsname); LinearLayout localLinearLayout = (LinearLayout) findViewById(R.id.zrtradelayout); localLinearLayout.setOnFocusChangeListener(setOnEditFocusListener); this.m_vklayout = localLinearLayout; View localView1 = this.m_vklayout; localView1.setOnFocusChangeListener(setOnEditFocusListener); View localView2 = this.m_vklayout; localView2.setOnClickListener(setOnEditClickListener); viewFlipper = (ViewFlipper) this.findViewById(R.id.ViewFlipper01); preView = (ImageView) findViewById(R.id.previous_screen); leftIn = AnimationUtils.loadAnimation(this, R.anim.push_left_in_layout); leftOut = AnimationUtils.loadAnimation(this, R.anim.push_left_out_layout); rightIn = AnimationUtils.loadAnimation(this, R.anim.push_right_in_layout); rightOut = AnimationUtils.loadAnimation(this, R.anim.push_right_out_layout); priceView = (PriceMini) findViewById(R.id.zrviewprice); trendView = (TrendView) findViewById(R.id.zrviewtrend); trendView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }); klineView = (KlineMini) findViewById(R.id.zrviewkline); klineView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }); financeView = (FinanceMini) findViewById(R.id.zrviewfinance); stockHolder = (Spinner) findViewById(R.id.zrtxtaccount); queryMethod = (Spinner) findViewById(R.id.zrtxtbsflag); // availableNum = (SeekBar) findViewById(R.id.zrcanbs); // lblMaxNumber = (TextView)findViewById(R.id.txtMaxNumber); stkcode = (EditText) findViewById(R.id.zredtstockcode); stkname = (TextView) findViewById(R.id.zrtxtstockname); price = (EditText) findViewById(R.id.zredtprice); number = (EditText) findViewById(R.id.zredtcount); lblNumberUnit = (TextView) findViewById(R.id.lblNumberUnit); btn0 = (ShadowButton) findViewById(R.id.zr_surebutton); btn0.setOnClickListener(myShowProgreeBar); layoutprice0 = (LinearLayout) findViewById(R.id.LinearLayout03); layoutprice = (LinearLayout) findViewById(R.id.LinearLayout11); //layoutAvaiNumber = (LinearLayout)findViewById(R.id.LinearLayout04); //layoutAvaiAsset = (LinearLayout)findViewById(R.id.LinearLayout06); lblAvaiAsset = (TextView) findViewById(R.id.lblAvaiAsset); AvaiAsset = (TextView) findViewById(R.id.AvaiAsset); lblPrice = (TextView) findViewById(R.id.lblPrice); lblPrice1 = (TextView) findViewById(R.id.lblPrice1); lblNumber = (TextView) findViewById(R.id.lblNumber); avaiAsset = (TextView) findViewById(R.id.AvaiAsset); lblNumberUnit = (TextView) findViewById(R.id.lblNumberUnit); setDynamic(); adjustDownPrice = (ImageView) findViewById(R.id.AdjustDownPrice); adjustDownPrice.setTag(0); adjustDownPrice.setOnClickListener(adjustIconListener); adjustUpPrice = (ImageView) findViewById(R.id.AdjustUpPrice); adjustUpPrice.setTag(1); adjustUpPrice.setOnClickListener(adjustIconListener); adjustDownNumber = (ImageView) findViewById(R.id.AdjustDownNumber); adjustDownNumber.setTag(2); adjustDownNumber.setOnClickListener(adjustIconListener); adjustUpNumber = (ImageView) findViewById(R.id.AdjustUpNumber); adjustUpNumber.setTag(3); adjustUpNumber.setOnClickListener(adjustIconListener); stkcode.setText(stockCode); if (stkcode.getText().length() == 6) { showProgress(); } stkcode.setInputType(InputType.TYPE_NULL); stkcode.setFocusable(true); stkcode.setTag("STOCK"); stkcode.setOnClickListener(setOnEditClickListener); stkcode.setOnFocusChangeListener(setOnEditFocusListener); price.setInputType(InputType.TYPE_NULL); price.setFocusable(true); price.setTag("NUMDOT"); price.setOnClickListener(setOnEditClickListener); price.setOnFocusChangeListener(setOnEditFocusListener); number.setInputType(InputType.TYPE_NULL); number.setFocusable(true); number.setTag(""); number.setOnClickListener(setOnEditClickListener); number.setOnFocusChangeListener(setOnEditFocusListener); stkcode.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable arg0) { //queryStock(queryCode.getText()); OnTextChanged(arg0); } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); holder = TradeUser.getInstance().getHolder(); stockHolderAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, (String[]) holder.toArray(new String[holder.size()])); stockHolderAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); stockHolder.setAdapter(stockHolderAdapter); String[] arrayOfString = getResources().getStringArray(R.array.other_market_bs_methods); for (int i = 0; i < arrayOfString.length; i++) { Log.e("arrayOfString", arrayOfString[i]); } queryMethodAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arrayOfString); queryMethodAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); queryMethod.setAdapter(queryMethodAdapter); queryMethod.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { layoutprice0.setVisibility(View.GONE); layoutprice.setVisibility(View.VISIBLE); } else { layoutprice0.setVisibility(View.VISIBLE); layoutprice.setVisibility(View.GONE); } } public void onNothingSelected(AdapterView<?> arg0) { } }); int h = R.drawable.forminput; Resources localResources = getResources(); Drawable localDrawable = null; localDrawable = localResources.getDrawable(h); int spinnerheight = localDrawable.getIntrinsicHeight() - 4; // Log.e("<<<<<<<<<<<<<<<<<<<eeeeeeeeeeeeeeeeeeeeeeeeeee>>>>>>>>>>>>>>", String.valueOf(spinnerheight)); LinearLayout.LayoutParams linearParams1 = (LinearLayout.LayoutParams) stockHolder.getLayoutParams();//?stockHolder? linearParams1.height = spinnerheight;//?? stockHolder.setLayoutParams(linearParams1); LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) queryMethod.getLayoutParams();//?queryMethod? linearParams.height = spinnerheight;//?? queryMethod.setLayoutParams(linearParams); }
From source file:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java
/** * .// ww w . j a v a 2s . c o m * * @param context * @param cameraId Camera ID. */ public CameraOverlay(final Context context, final int cameraId) { mContext = context; mWinMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mWorkerThread = new HandlerThread(getClass().getSimpleName()); mWorkerThread.start(); mHandler = new Handler(mWorkerThread.getLooper()); mCameraId = cameraId; mMaxFps = DEFAULT_MAX_FPS; setPreviewFrameRate(mMaxFps); }
From source file:com.android.camera.manager.ThumbnailViewManager.java
@Override public void begin() { Log.i(TAG, "[begin]..."); if (mWorkerHandler == null) { HandlerThread t = new HandlerThread("thumbnail-creation-thread"); t.start();//from ww w. jav a 2s. c o m mWorkerHandler = new WorkerHandler(t.getLooper()); } }
From source file:net.hiroq.rxwsc.RxWebSocketClient.java
/** * Connect to WebSocketServer with additional Header. * When unsubscribe is called, the observable will disconnect automatically. * <p>//from w ww . j a va 2 s .c om * Caution: This method run on same thread of caller. So if you want to run on NOT UI THREAD, * you have to use subscribeOn to specify thread model. * * @param uri * @param extraHeaders * @return */ public Observable<Event> connect(Uri uri, List<Pair<String, String>> extraHeaders) { this.disconnect(false); this.mUri = uri; this.mExtraHeaders = extraHeaders; this.mParser = new HybiParser(this); this.mHandlerThread = new HandlerThread(getClass().getName()); this.mHandlerThread.start(); this.mHandler = new Handler(mHandlerThread.getLooper()); return Observable.create(new Observable.OnSubscribe<Event>() { @Override public void call(Subscriber<? super Event> subscriber) { try { mSubscriber = subscriber; String secret = createSecret(); String scheme = mUri.getScheme(); // uri have invalid scheme throw MalformedURLException if (scheme == null || !(scheme.equals("ws") || scheme.equals("wss"))) { new MalformedURLException("Url scheme has to be specified as \"ws\" or \"wss\"."); } int port = (mUri.getPort() != -1) ? mUri.getPort() : (scheme.equals("wss") ? 443 : 80); String path = TextUtils.isEmpty(mUri.getPath()) ? "/" : mUri.getPath(); if (!TextUtils.isEmpty(mUri.getQuery())) { path += "?" + mUri.getQuery(); } String originScheme = scheme.equals("wss") ? "https" : "http"; Uri origin = Uri.parse(originScheme + "://" + mUri.getHost()); SocketFactory factory = scheme.equals("wss") ? getSSLSocketFactory() : SocketFactory.getDefault(); mSocket = factory.createSocket(mUri.getHost(), port); PrintWriter out = new PrintWriter(mSocket.getOutputStream()); out.print("GET " + path + " HTTP/1.1\r\n"); out.print("Upgrade: websocket\r\n"); out.print("Connection: Upgrade\r\n"); out.print("Host: " + mUri.getHost() + "\r\n"); out.print("Origin: " + origin.toString() + "\r\n"); out.print("Sec-WebSocket-Key: " + secret + "\r\n"); out.print("Sec-WebSocket-Version: 13\r\n"); if (mExtraHeaders != null) { for (Pair<String, String> pair : mExtraHeaders) { out.print(String.format("%s: %s\r\n", pair.first, pair.second)); } } out.print("\r\n"); out.flush(); HybiParser.HappyDataInputStream stream = new HybiParser.HappyDataInputStream( mSocket.getInputStream()); // Read HTTP response status line. StatusLine statusLine = parseStatusLine(readLine(stream)); if (statusLine == null) { throw new ConnectException("Received no reply from server."); } else if (statusLine.getStatusCode() != HttpStatus.SC_SWITCHING_PROTOCOLS) { throw new ProtocolException( "Server sent invalid response code " + statusLine.getStatusCode() + ". WebSocket server must return " + HttpStatus.SC_SWITCHING_PROTOCOLS); } // Read HTTP response headers. String line; boolean validated = false; while (!TextUtils.isEmpty(line = readLine(stream))) { Header header = parseHeader(line); if (header.getName().equals("Sec-WebSocket-Accept")) { String expected = createSecretValidation(secret); String actual = header.getValue().trim(); if (!expected.equals(actual)) { throw new ProtocolException("Bad Sec-WebSocket-Accept header value."); } validated = true; } } if (!validated) { throw new ProtocolException("No Sec-WebSocket-Accept header."); } mIsConnected = true; emitterOnNext(new Event(EventType.CONNECT)); // Now decode websocket frames. mParser.start(stream); } catch (Exception e) { emitterOnError(e); } } }).doOnUnsubscribe(new Action0() { @Override public void call() { RxWebSocketClient.this.disconnect(false); } }); }
From source file:com.amaze.carbonfilemanager.ui.icons.IconHolder.java
/** * Method that returns a drawable reference of a FileSystemObject. * * @param iconView View to load the drawable into * @param fso The FileSystemObject reference * @param defaultIcon Drawable to be used in case no specific one could be found * @return Drawable The drawable reference *//*w w w. ja v a 2 s . co m*/ public void loadDrawable(final ImageView iconView, final String fso, Drawable defaultIcon) { if (!mUseThumbs) { return; } // Is cached? final String filePath = fso; if (this.mAppIcons.containsKey(filePath)) { iconView.setImageBitmap(this.mAppIcons.get(filePath)); return; } new Thread(new Runnable() { @Override public void run() { mHandler.removeMessages(MSG_DESTROY); if (mWorkerThread == null || mWorkerHandler == null) { mWorkerThread = new HandlerThread("IconHolderLoader"); mWorkerThread.start(); mWorkerHandler = new WorkerHandler(mWorkerThread.getLooper()); } mRequests.put(iconView, fso); Message msg = mWorkerHandler.obtainMessage(MSG_LOAD, fso); msg.sendToTarget(); } }).start(); }
From source file:com.unlp.tesis.steer.LocationService.java
@Override public void onCreate() { //GEOFENCES/* w w w . jav a2 s . com*/ // Empty list for storing geofences. mGeofenceList = new ArrayList<Geofence>(); // Initially set the PendingIntent used in addGeofences() and removeGeofences() to null. mGeofencePendingIntent = null; // Get the geofences used. Geofence data is hard coded in this sample. //Get Firebase database instance mDatabase = FirebaseDatabase.getInstance().getReference(); populateGeofenceList(); if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); } mGoogleApiClient.connect(); createLocationRequest(); HandlerThread handlerThread = new HandlerThread(TAG); handlerThread.start(); mServiceHandler = new Handler(handlerThread.getLooper()); }