android.content.Context#getMainLooper ( )源码实例Demo

下面列出了android.content.Context#getMainLooper ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bitgatt   文件: TxConcurrencyTests.java
@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());
}
 
源代码2 项目: android_9.0.0_r45   文件: BackupManager.java
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;
}
 
源代码3 项目: MiBandDecompiled   文件: TDialog.java
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;
}
 
源代码4 项目: qrcode_android   文件: CameraZoomStrategy.java
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;
}
 
源代码5 项目: aard2-android   文件: BlobListAdapter.java
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;
}
 
源代码6 项目: Noyze   文件: VolumePanel.java
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();
}
 
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());
}
 
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);
    }
}
 
源代码9 项目: MiBandDecompiled   文件: PKDialog.java
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());
}
 
源代码10 项目: NIM_Android_UIKit   文件: EmoticonPickerView.java
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);
}
 
源代码11 项目: NonViewUtils   文件: EasyToast.java
public EasyToast(Context context) {
    currDuration = DEFAULT;
    mHandler = new Handler(context.getMainLooper());
    mToast = Toast.makeText(context, "", Toast.LENGTH_LONG);
}
 
源代码12 项目: android_9.0.0_r45   文件: RecoverySystem.java
/**
 * 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");
    }
}
 
源代码13 项目: AndroidDeviceNames   文件: DeviceName.java
private Request(Context ctx) {
  context = ctx;
  handler = new Handler(ctx.getMainLooper());
}
 
源代码14 项目: travelguide   文件: DownloaderService.java
/**
 * 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));
}
 
源代码15 项目: UnityOBBDownloader   文件: DownloaderService.java
/**
 * 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));
}
 
源代码16 项目: KrGallery   文件: BaseDialog.java
public BaseDialog(Context context) {
    super(context, R.style.dialog_custom);
    mContext = context;
    handler = new Handler(context.getMainLooper());
    initView();
}
 
public RemoteService(Context context) {
    super(context.getMainLooper(), null, false);
    mContext = context;
}
 
源代码18 项目: Noyze   文件: PopupWindow.java
@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);
}
 
源代码19 项目: RxZhihuDaily   文件: Handlers.java
/**
 * get new handler for main looper
 * @param context
 * @return
 */
public static final Handler newHandler(Context context) {
	return new Handler(context.getMainLooper());
}
 
源代码20 项目: android_external_GmsLib   文件: GoogleApiClient.java
/**
 * 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();
}
 
 方法所在类
 同类方法