本文整理匯總了Java中android.content.Context.getMainLooper方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.getMainLooper方法的具體用法?Java Context.getMainLooper怎麽用?Java Context.getMainLooper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.Context
的用法示例。
在下文中一共展示了Context.getMainLooper方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: PluginLocalBroadcastManager
import android.content.Context; //導入方法依賴的package包/類
private PluginLocalBroadcastManager(Context context) {
mAppContext = context;
mHandler = new Handler(context.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_EXEC_PENDING_BROADCASTS:
executePendingBroadcasts();
break;
default:
super.handleMessage(msg);
}
}
};
}
示例2: MiniDrone
import android.content.Context; //導入方法依賴的package包/類
public MiniDrone(Context context, @NonNull ARDiscoveryDeviceService deviceService) {
mContext = context;
mListeners = new ArrayList<>();
// needed because some callbacks will be called on the main thread
mHandler = new Handler(context.getMainLooper());
mState = ARCONTROLLER_DEVICE_STATE_ENUM.ARCONTROLLER_DEVICE_STATE_STOPPED;
// if the product type of the deviceService match with the types supported
mProductType = ARDiscoveryService.getProductFromProductID(deviceService.getProductID());
ARDISCOVERY_PRODUCT_FAMILY_ENUM family = ARDiscoveryService.getProductFamily(mProductType);
if (ARDISCOVERY_PRODUCT_FAMILY_ENUM.ARDISCOVERY_PRODUCT_FAMILY_MINIDRONE.equals(family)) {
ARDiscoveryDevice discoveryDevice = createDiscoveryDevice(context, deviceService, mProductType);
if (discoveryDevice != null) {
mDeviceController = createDeviceController(discoveryDevice);
}
} else {
Log.e(TAG, "DeviceService type is not supported by MiniDrone");
}
}
示例3: showToast
import android.content.Context; //導入方法依賴的package包/類
private static void showToast(@NonNull final String message, final Context context, final int duration) {
if (null == message) {
throw new NullPointerException("message");
}
if (null == mAppName) {
throw new NullPointerException("mAppName");
}
if (Looper.myLooper() == context.getMainLooper()) {
Toast.makeText(context, mAppName + ": " + message, duration).show();
} else {
new Handler(context.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, mAppName + ": " + message, duration).show();
}
});
}
}
示例4: init
import android.content.Context; //導入方法依賴的package包/類
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);
}
示例5: PKDialog
import android.content.Context; //導入方法依賴的package包/類
public PKDialog(Context context, String str, String str2, IUiListener iUiListener, QQToken
qQToken) {
super(context, 16973840);
this.mWeakContext = new WeakReference(context);
this.mUrl = str2;
this.mListener = new OnTimeListener(context, str, str2, qQToken.getAppId(), iUiListener);
this.mHandler = new THandler(this.mListener, context.getMainLooper());
this.listener = iUiListener;
this.mWebviewHeight = Math.round(185.0f * context.getResources().getDisplayMetrics()
.density);
f.e(TAG, "density=" + context.getResources().getDisplayMetrics().density + "; " +
"webviewHeight=" + this.mWebviewHeight);
}
示例6: ensureNotOnMainThread
import android.content.Context; //導入方法依賴的package包/類
private static void ensureNotOnMainThread(Context context) {
Looper looper = Looper.myLooper();
if (looper != null && looper == context.getMainLooper()) {
throw new IllegalStateException("calling this from your main thread can lead to " +
"deadlock");
}
}
示例7: init
import android.content.Context; //導入方法依賴的package包/類
public void init(Context context) {
if (inited) {
return;
}
// init thread pool
executor = new NimTaskExecutor("NIM_HTTP_TASK_EXECUTOR", new NimTaskExecutor.Config(1, 3, 10 * 1000, true));
uiHandler = new Handler(context.getMainLooper());
inited = true;
}
示例8: PKDialog
import android.content.Context; //導入方法依賴的package包/類
public PKDialog(Context context, String str, String str2, IUiListener iUiListener, QQToken qQToken) {
super(context, 16973840);
this.mWeakContext = new WeakReference(context);
this.mUrl = str2;
this.mListener = new OnTimeListener(context, str, str2, qQToken.getAppId(), iUiListener);
this.mHandler = new THandler(this.mListener, context.getMainLooper());
this.listener = iUiListener;
this.mWebviewHeight = Math.round(185.0f * context.getResources().getDisplayMetrics().density);
f.e(TAG, "density=" + context.getResources().getDisplayMetrics().density + "; webviewHeight=" + this.mWebviewHeight);
}
示例9: TDialog
import android.content.Context; //導入方法依賴的package包/類
public TDialog(Context context, String str, String str2, IUiListener iUiListener, QQToken qQToken) {
super(context, 16973840);
this.c = new WeakReference(context);
this.e = str2;
this.f = new OnTimeListener(context, str, str2, qQToken.getAppId(), iUiListener);
this.j = new THandler(this.f, context.getMainLooper());
this.g = iUiListener;
this.l = qQToken;
}
示例10: LocalBroadcastManager
import android.content.Context; //導入方法依賴的package包/類
private LocalBroadcastManager(Context context) {
this.mAppContext = context;
this.mHandler = new Handler(context.getMainLooper()) {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
LocalBroadcastManager.this.executePendingBroadcasts();
return;
default:
super.handleMessage(msg);
return;
}
}
};
}
示例11: CountDownUtils
import android.content.Context; //導入方法依賴的package包/類
public CountDownUtils(final Context context, final TextView v) {
this.context = context;
this.v = v;
countdownHandler = new Handler(context.getMainLooper()) {
public void handleMessage(android.os.Message msg) {
String s = String.format(context.getString(R.string.code_txt), String.valueOf(iTime));
v.setText(s);
countdownHandler.postDelayed(countdownRunnable, 1000);
}
};
}
示例12: MyHander
import android.content.Context; //導入方法依賴的package包/類
public MyHander(Context context) {
super(context.getMainLooper());
}
示例13: updateLVL
import android.content.Context; //導入方法依賴的package包/類
/**
* 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));
}
示例14: BaseDialog
import android.content.Context; //導入方法依賴的package包/類
public BaseDialog(Context context) {
super(context, R.style.dialog_custom);
mContext = context;
handler = new Handler(context.getMainLooper());
initView();
}
示例15: BlocklyController
import android.content.Context; //導入方法依賴的package包/類
/**
* Creates a new Controller with Workspace and WorkspaceHelper. Most controllers will require
* a {@link BlockViewFactory}, but headless (i.e. viewless) controllers are allowed, where it
* could be null.
*
* @param context Android context, such as an Activity.
* @param blockModelFactory Factory used to create new Blocks.
* @param workspaceHelper Helper functions for workspace views and device resolution.
* @param blockViewFactory Factory used to construct block views for this app.
*/
private BlocklyController(Context context, BlockFactory blockModelFactory,
WorkspaceHelper workspaceHelper, BlockClipDataHelper clipHelper,
@Nullable BlockViewFactory blockViewFactory) {
if (context == null) {
throw new IllegalArgumentException("Context may not be null.");
}
if (blockModelFactory == null) {
throw new IllegalArgumentException("BlockFactory may not be null.");
}
if (workspaceHelper == null) {
throw new IllegalArgumentException("WorkspaceHelper may not be null.");
}
if (clipHelper == null) {
throw new IllegalArgumentException("BlockClipDataHelper may not be null.");
}
mContext = context;
mMainLooper = context.getMainLooper();
mModelFactory = blockModelFactory;
mModelFactory.setController(this);
mHelper = workspaceHelper;
mViewFactory = blockViewFactory;
// mHelper, mModelFactory, and mViewFactory must be initialized before mClipHelper.
mClipHelper = clipHelper;
mWorkspace = new Workspace(mContext, this, mModelFactory);
mConnectionManager = mWorkspace.getConnectionManager();
if (mViewFactory != null) {
// TODO(#81): Check if variables are enabled/disabled
mViewFactory.setVariableNameManager(mWorkspace.getVariableNameManager());
mViewFactory.setVariableRequestCallback(new VariableRequestCallback() {
@Override
public void onVariableRequest(int request, String variable) {
if (request == VariableRequestCallback.REQUEST_RENAME) {
requestRenameVariable(variable, variable);
} else if (request == VariableRequestCallback.REQUEST_DELETE) {
requestDeleteVariable(variable);
}
}
});
}
mDragger = new Dragger(this);
mTouchHandler = mDragger.buildSloppyBlockTouchHandler(mWorkspaceDragHandler);
mFlyoutController = new FlyoutController(this);
}