Java Code Examples for android.content.Context#getMainLooper()
The following examples show how to use
android.content.Context#getMainLooper() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackupManager.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
BackupObserverWrapper(Context context, BackupObserver observer) { mHandler = new Handler(context.getMainLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_UPDATE: Pair<String, BackupProgress> obj = (Pair<String, BackupProgress>) msg.obj; mObserver.onUpdate(obj.first, obj.second); break; case MSG_RESULT: mObserver.onResult((String)msg.obj, msg.arg1); break; case MSG_FINISHED: mObserver.backupFinished(msg.arg1); break; default: Log.w(TAG, "Unknown message: " + msg); break; } } }; mObserver = observer; }
Example 2
Source File: TxConcurrencyTests.java From bitgatt with Mozilla Public License 2.0 | 6 votes |
@Before public void before() { Context appContext = InstrumentationRegistry.getInstrumentation().getContext(); FitbitGatt.getInstance().startGattClient(appContext); // started FitbitBluetoothDevice device = new FitbitBluetoothDevice(MOCK_ADDRESS, "fooDevice"); fakeData = new byte[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}; characteristic = new BluetoothGattCharacteristic(CHAR_NAME, PROPERTY_WRITE, BluetoothGattCharacteristic.PERMISSION_WRITE); descriptor = new BluetoothGattDescriptor(DESCRIPTOR_NAME, BluetoothGattDescriptor.PERMISSION_WRITE); connection = FitbitGatt.getInstance().getConnection(device); if (connection == null) { connection = new GattConnection(device, appContext.getMainLooper()); FitbitGatt.getInstance().getConnectionMap().put(device, connection); } connection.setMockMode(true); connection.setState(GattState.CONNECTED); handler = new Handler(handlerThread.getLooper()); }
Example 3
Source File: CameraZoomStrategy.java From qrcode_android with GNU Lesser General Public License v3.0 | 5 votes |
public void init(Camera camera, Context context) { clearState(); if (camera == null || context == null) { return; } handler = new InnerHandler(context.getMainLooper()); this.camera = camera; Camera.Parameters parameters = camera.getParameters(); if (parameters == null) { return; } isSupportZoom = parameters.isZoomSupported(); maxZoom = parameters.getMaxZoom(); minTryZoomOut = maxZoom / 10; maxTryZoomIn = maxZoom * 5 / 10; currentZoom = minTryZoomOut; Log.v(TAG, "isSupportZoom:" + isSupportZoom + ", maxZoom:" + maxZoom + ", currentZoom:" + currentZoom + ", maxTryZoomIn:" + maxTryZoomIn + ", minTryZoomOut:" + minTryZoomOut); //降低maxZoom对应值,摄像头一旦放到最大,会出现抖动 maxZoom = maxZoom * 9 / 10; if (isSupportZoom) { parameters.setZoom(currentZoom); lastZoom = currentZoom; camera.setParameters(parameters); } DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); manager.getDefaultDisplay().getMetrics(displayMetrics); screenWidth = displayMetrics.widthPixels; hasInit = true; }
Example 4
Source File: EmoticonPickerView.java From NIM_Android_UIKit with MIT License | 5 votes |
private void init(Context context) { this.context = context; this.uiHandler = new Handler(context.getMainLooper()); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.nim_emoji_layout, this); }
Example 5
Source File: PKDialog.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public PKDialog(Context context, String s, String s1, IUiListener iuilistener, QQToken qqtoken) { super(context, 0x1030010); o = new WeakReference(context); i = s1; k = new g(context, s, s1, qqtoken.getAppId(), iuilistener); l = new h(k, context.getMainLooper()); j = iuilistener; p = Math.round(185F * context.getResources().getDisplayMetrics().density); Log.e(b, (new StringBuilder()).append("density=").append(context.getResources().getDisplayMetrics().density).append("; webviewHeight=").append(p).toString()); }
Example 6
Source File: PrinterDiscoverySession.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
PrinterDiscoverySession(IPrintManager printManager, Context context, int userId) { mPrintManager = printManager; mUserId = userId; mHandler = new SessionHandler(context.getMainLooper()); mObserver = new PrinterDiscoveryObserver(this); try { mPrintManager.createPrinterDiscoverySession(mObserver, mUserId); } catch (RemoteException re) { Log.e(LOG_TAG, "Error creating printer discovery session", re); } }
Example 7
Source File: WearableServiceImpl.java From android_packages_apps_GmsCore with Apache License 2.0 | 5 votes |
public WearableServiceImpl(Context context, WearableImpl wearable, String packageName) { this.context = context; this.wearable = wearable; this.packageName = packageName; this.capabilities = new CapabilityManager(context, wearable, packageName); this.mainHandler = new Handler(context.getMainLooper()); }
Example 8
Source File: VolumePanel.java From Noyze with Apache License 2.0 | 5 votes |
public VolumePanel(PopupWindowManager manager) { super(manager); Context context = manager.getContext(); app = (NoyzeApp) context.getApplicationContext(); mStreamControls = new SparseArray<StreamControl>(StreamResources.STREAMS.length); mHandler = new VolumeMediaHandler(context.getMainLooper()); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); mVolumeManager = new VolumeManager(mAudioManager); mAudioHelper = AudioHelper.getHelper(context, mAudioManager); // mAudioFlingerProxy = new AudioFlingerProxy(); mAudioHelper.setHandler(mHandler); mLongPressTimeout = ViewConfiguration.getLongPressTimeout(); if (MediaProviderDelegate.IS_V18) mMediaProviderDelegate = MediaProviderDelegate.getDelegate(context); // Register here: be SURE that the handler is not null. if (null == mVolumeMediaReceiver) { mVolumeMediaReceiver = new VolumeMediaReceiver(mHandler); IntentFilter events = Utils.merge(VOLUME_MUSIC_EVENTS(), Constants.MEDIA_ACTION_FILTER()); context.registerReceiver(mVolumeMediaReceiver, events); mVolumeMediaReceiver.setHandler(mHandler); } // Register for events related to the call state. if (null == mCallStateListener) { mCallState = mTelephonyManager.getCallState(); mCallStateListener = new CallStateListener(mHandler); mTelephonyManager.listen(mCallStateListener, PhoneStateListener.LISTEN_CALL_STATE); } initState(); }
Example 9
Source File: BlobListAdapter.java From aard2-android with GNU General Public License v3.0 | 5 votes |
public BlobListAdapter(Context context, int chunkSize, int loadMoreThreashold) { this.mainHandler = new Handler(context.getMainLooper()); this.executor = Executors.newSingleThreadExecutor(); this.list = new ArrayList<Slob.Blob>(chunkSize); this.chunkSize = chunkSize; this.loadMoreThreashold = loadMoreThreashold; }
Example 10
Source File: TDialog.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public TDialog(Context context, String s, String s1, IUiListener iuilistener, QQToken qqtoken) { super(context, 0x1030010); n = false; o = null; c = new WeakReference(context); f = s1; g = new o(context, s, s1, qqtoken.getAppId(), iuilistener); m = new p(g, context.getMainLooper()); h = iuilistener; o = qqtoken; }
Example 11
Source File: EasyToast.java From NonViewUtils with Apache License 2.0 | 4 votes |
public EasyToast(Context context) { currDuration = DEFAULT; mHandler = new Handler(context.getMainLooper()); mToast = Toast.makeText(context, "", Toast.LENGTH_LONG); }
Example 12
Source File: RecoverySystem.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Process a given package with uncrypt. No-op if the package is not on the * /data partition. * * @param Context the Context to use * @param packageFile the package to be processed * @param listener an object to receive periodic progress updates as * processing proceeds. May be null. * @param handler the Handler upon which the callbacks will be * executed. * * @throws IOException if there were any errors processing the package file. * * @hide */ @SystemApi @RequiresPermission(android.Manifest.permission.RECOVERY) public static void processPackage(Context context, File packageFile, final ProgressListener listener, final Handler handler) throws IOException { String filename = packageFile.getCanonicalPath(); if (!filename.startsWith("/data/")) { return; } RecoverySystem rs = (RecoverySystem) context.getSystemService(Context.RECOVERY_SERVICE); IRecoverySystemProgressListener progressListener = null; if (listener != null) { final Handler progressHandler; if (handler != null) { progressHandler = handler; } else { progressHandler = new Handler(context.getMainLooper()); } progressListener = new IRecoverySystemProgressListener.Stub() { int lastProgress = 0; long lastPublishTime = System.currentTimeMillis(); @Override public void onProgress(final int progress) { final long now = System.currentTimeMillis(); progressHandler.post(new Runnable() { @Override public void run() { if (progress > lastProgress && now - lastPublishTime > PUBLISH_PROGRESS_INTERVAL_MS) { lastProgress = progress; lastPublishTime = now; listener.onProgress(progress); } } }); } }; } if (!rs.uncrypt(filename, progressListener)) { throw new IOException("process package failed"); } }
Example 13
Source File: DeviceName.java From AndroidDeviceNames with Apache License 2.0 | 4 votes |
private Request(Context ctx) { context = ctx; handler = new Handler(ctx.getMainLooper()); }
Example 14
Source File: DownloaderService.java From travelguide with Apache License 2.0 | 4 votes |
/** * Updates the LVL information from the server. * * @param context */ public void updateLVL(final Context context) { Context c = context.getApplicationContext(); Handler h = new Handler(c.getMainLooper()); h.post(new LVLRunnable(c, mPendingIntent)); }
Example 15
Source File: DownloaderService.java From UnityOBBDownloader with Apache License 2.0 | 4 votes |
/** * Updates the LVL information from the server. * * @param context */ public void updateLVL(final Context context) { Context c = context.getApplicationContext(); Handler h = new Handler(c.getMainLooper()); h.post(new LVLRunnable(c, mPendingIntent)); }
Example 16
Source File: BaseDialog.java From KrGallery with GNU General Public License v2.0 | 4 votes |
public BaseDialog(Context context) { super(context, R.style.dialog_custom); mContext = context; handler = new Handler(context.getMainLooper()); initView(); }
Example 17
Source File: RuntimePermissionPresenter.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public RemoteService(Context context) { super(context.getMainLooper(), null, false); mContext = context; }
Example 18
Source File: PopupWindow.java From Noyze with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public PopupWindow(PopupWindowManager windowManager) { pWindowManager = windowManager; // Obtain height & barHeight once, then determine which is which // based on the orientation/ rotation of the device. DisplayMetrics dm = new DisplayMetrics(); Display mDisplay = pWindowManager.getWindowManager().getDefaultDisplay(); mRotation = PopupWindowManager.getRotation(mDisplay); mDisplay.getMetrics(dm); widthPixels = ((isLandscape()) ? dm.heightPixels : dm.widthPixels); heightPixels = ((isLandscape()) ? dm.widthPixels : dm.heightPixels); Context context = pWindowManager.getContext(); mStatusBarHeight = SystemInfo.getStatusBarHeight(context); mViewConfiguration = ViewConfiguration.get(context); mUiHandler = new HideHandler(context.getMainLooper()); onCreate(); // If a layout was made, initialize the PopupWindow and handle // system-wide events. A layout MUST be supplied at initialization // or the PopupWindow cannot be displayed. if (mLayout != null) { SilentFrameLayout layout = new SilentFrameLayout(context); layout.setId(generateId()); layout.setOnTouchListener(this); layout.setOnDispatchKeyListener(this); layout.setOnSystemUiVisibilityChangeListener(this); layout.getViewTreeObserver().addOnScrollChangedListener(gScrollListener); layout.setOnLongClickListener(this); // Place the designated layout in a container. layout.addView(mLayout); mDecor = layout; created = true; attach(); } // Become managed by PopupWindowManager. It's already been created, so we // might as well become managed by it. pWindowManager.add(this); }
Example 19
Source File: Handlers.java From RxZhihuDaily with MIT License | 2 votes |
/** * get new handler for main looper * @param context * @return */ public static final Handler newHandler(Context context) { return new Handler(context.getMainLooper()); }
Example 20
Source File: GoogleApiClient.java From android_external_GmsLib with Apache License 2.0 | 2 votes |
/** * Builder to help construct the {@link GoogleApiClient} object. * * @param context The context to use for the connection. */ public Builder(Context context) { this.context = context; this.looper = context.getMainLooper(); }