本文整理汇总了Java中android.app.Activity.runOnUiThread方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.runOnUiThread方法的具体用法?Java Activity.runOnUiThread怎么用?Java Activity.runOnUiThread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Activity
的用法示例。
在下文中一共展示了Activity.runOnUiThread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMoviesFromDb
import android.app.Activity; //导入方法依赖的package包/类
private static void getMoviesFromDb(Activity activity, String type, final MoviesCallback callback) {
try {
Cursor cursor = activity.getContentResolver()
.query(MovieContract.CONTENT_URI,
null,
MovieContract.TYPE + " = ?",
new String[]{type},
null
);
final List<Movie> movies = toMovies(cursor);
cursor.close();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.success(movies);
}
});
} catch (final Exception e) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.error(e);
}
});
}
}
示例2: setPlayerStatus
import android.app.Activity; //导入方法依赖的package包/类
public static void setPlayerStatus(final Activity context, final ViewGroup viewGroup, final TurnGameController<?> controller) {
context.runOnUiThread(new Runnable() {
@Override
public void run() {
int [] colors = context.getResources().getIntArray(R.array.androidcolors);
for (Iterator<Player> it = controller.getPlayers(); it.hasNext(); ) {
Player player = it.next();
View child = viewGroup.findViewWithTag(player.getName());
if (child == null) {
child = LayoutInflater.from(context).inflate(
R.layout.item_contact_simplest, null);
child.setTag(player.getName());
viewGroup.addView(child);
}
setPlayerStatus(player, child, controller);
int index = controller.getPlayerIndex(((HumanPlayer) player).getEmail());
child.findViewById(android.R.id.icon).setBackgroundColor(colors[index]);
}
}
});
}
示例3: hapticFeedbackPerform
import android.app.Activity; //导入方法依赖的package包/类
private void hapticFeedbackPerform(Map data) {
final Activity activity = QtNative.activity();
final Map messageData = data;
Runnable runnable = new Runnable () {
public void run() {
int feedbackConstant = (Integer) messageData.get("feedbackConstant");
int flags = (Integer) messageData.get("flags");
Log.d("",String.format("hapticFeedbackPerform(%d,%d)",feedbackConstant,flags));
View rootView = activity.getWindow().getDecorView().getRootView();
rootView.performHapticFeedback(feedbackConstant, flags);
// Test function. Remove it later.
SystemDispatcher.dispatch("hapticFeedbackPerformFinished");
};
};
activity.runOnUiThread(runnable);
}
示例4: setBrightnessLevel
import android.app.Activity; //导入方法依赖的package包/类
@ReactMethod
public void setBrightnessLevel(final float brightnessLevel) {
final Activity activity = getCurrentActivity();
if (activity == null) {
return;
}
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
lp.screenBrightness = brightnessLevel;
activity.getWindow().setAttributes(lp);
}
});
}
示例5: showMessage
import android.app.Activity; //导入方法依赖的package包/类
public static void showMessage(final Activity activity, final String title, final String body, final String okLabel)
{
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
new AlertDialog.Builder(activity)
.setTitle(title)
.setMessage(body)
.setCancelable(false)
.setPositiveButton(okLabel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
}
});
}
示例6: toastMessage
import android.app.Activity; //导入方法依赖的package包/类
/**
* 打印消息并且用Toast显示消息
*
* @param activity
* @param message
* @param logLevel
* 填d, w, e分别代表debug, warn, error; 默认是debug
*/
public static final void toastMessage(final Activity activity,
final String message, String logLevel) {
if ("w".equals(logLevel)) {
Log.w("sdkDemo", message);
} else if ("e".equals(logLevel)) {
Log.e("sdkDemo", message);
} else {
Log.d("sdkDemo", message);
}
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (mToast != null) {
mToast.cancel();
mToast = null;
}
mToast = Toast.makeText(activity, message, Toast.LENGTH_SHORT);
mToast.show();
}
});
}
示例7: handleButtonPress
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void handleButtonPress(int index) {
if (index == 0) {
WifiParsedResult wifiResult = (WifiParsedResult) getResult();
WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
if (wifiManager == null) {
Log.w(TAG, "No WifiManager available from device");
return;
}
final Activity activity = getActivity();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(activity.getApplicationContext(), R.string.wifi_changing_network, Toast.LENGTH_SHORT).show();
}
});
new WifiConfigManager(wifiManager).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, wifiResult);
parent.restartPreviewAfterDelay(0L);
}
}
示例8: setFullScreen
import android.app.Activity; //导入方法依赖的package包/类
static void setFullScreen(Map message) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ) {
return;
}
final Boolean value = (Boolean) message.get("value");
final Activity activity = QtNative.activity();
Runnable runnable = new Runnable () {
public void run() {
Window w = activity.getWindow(); // in Activity's onCreate() for instance
View decorView = w.getDecorView();
int config = decorView.getSystemUiVisibility();
if (value) {
config &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
} else {
config |= View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
decorView.setSystemUiVisibility(config);
}
};
activity.runOnUiThread(runnable);
}
示例9: setCurrentView
import android.app.Activity; //导入方法依赖的package包/类
public void setCurrentView(Context context, View newView) {
// finding the resID dynamically allows this class to exist outside of the TeamCode module
final int resID = context.getResources().getIdentifier("RelativeLayout", "id", context.getPackageName());
final Activity activity = (Activity) context;
final View queuedView = newView;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
ViewGroup l = (ViewGroup) activity.findViewById(resID); //R.id.RelativeLayout);
if (view != null) {
l.removeView(view);
}
l.addView(queuedView);
view = queuedView;
}
});
}
示例10: updatePreview
import android.app.Activity; //导入方法依赖的package包/类
static void updatePreview(final Activity activity, final boolean isOnCreate, final Integer fromLatest, final View previewView, final SeekBar alphaSeekBar, final SeekBar RSeekBar, final SeekBar GSeekBar, final SeekBar BSeekBar) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
int A = getColorARGB(0, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar);
int R = getColorARGB(1, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar);
int G = getColorARGB(2, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar);
int B = getColorARGB(3, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar);
int ARGB = getColorARGB(4, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar);
if (isOnCreate) {
int savedColor = fromLatest != null ? fromLatest : ColorBox.getColor(ColorBox.getTag(), activity);
A = Color.alpha(savedColor);
R = Color.red(savedColor);
G = Color.green(savedColor);
B = Color.blue(savedColor);
ARGB = savedColor;
}
alphaSeekBar.setProgress(A);
RSeekBar.setProgress(R);
GSeekBar.setProgress(G);
BSeekBar.setProgress(B);
previewView.setBackground(Utils.round(activity.getResources(), isLand(activity.getResources()), android.R.dimen.thumbnail_height, ARGB));
}
});
}
示例11: dismissProgressDialog
import android.app.Activity; //导入方法依赖的package包/类
/** 隐藏加载进度
*/
public static void dismissProgressDialog(Activity context) {
if(context == null || progressDialog == null || progressDialog.isShowing() == false){
return;
}
context.runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();
}
});
}
示例12: handleReloadJS
import android.app.Activity; //导入方法依赖的package包/类
private void handleReloadJS() {
Activity activity = getCurrentActivity();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
devManager.handleReloadJS();
}
});
}
示例13: checkException
import android.app.Activity; //导入方法依赖的package包/类
protected static void checkException(@NonNull final Exception e, @Nullable final Activity activity) {
if (e instanceof EDAMUserException) {
switch (((EDAMUserException) e).getErrorCode()) {
case AUTH_EXPIRED:
if (activity != null) {
Util.logout(activity);
}
break;
case PERMISSION_DENIED:
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
View view = activity.findViewById(android.R.id.content);
CoordinatorLayout fabCoordinator = ViewUtil.findFabCoordinator(view, R.id.coordinatorLayout);
if (fabCoordinator != null) {
view = fabCoordinator;
}
final Snackbar snackbar = Snackbar.make(view, ((EDAMUserException) e).getErrorCode().toString(), Snackbar.LENGTH_INDEFINITE);
snackbar.setActionTextColor(activity.getResources().getColor(R.color.tb_bg))
.setAction(android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
snackbar.dismiss();
}
}).show();
}
});
}
break;
}
}
}
示例14: show
import android.app.Activity; //导入方法依赖的package包/类
@ReactMethod
public void show() {
if (!useDeveloperSupport) return;
Activity activity = getCurrentActivity();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
devManager.showDevOptionsDialog();
}
});
}
示例15: showToast
import android.app.Activity; //导入方法依赖的package包/类
/**
* Shows a {@link Toast} on the UI thread.
*
* @param text The message to show
*/
private void showToast(final String text) {
final Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(
new Runnable() {
@Override
public void run() {
Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
}
});
}
}