当前位置: 首页>>代码示例>>Java>>正文


Java Activity.runOnUiThread方法代码示例

本文整理汇总了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);
            }
        });
    }
}
 
开发者ID:brenopolanski,项目名称:android-movies-app,代码行数:27,代码来源:MoviesUtil.java

示例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]);
            }
        }
    });
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:22,代码来源:PlayerViewUtils.java

示例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);
            }
 
开发者ID:benlau,项目名称:androidnative.pri,代码行数:21,代码来源:ExampleService.java

示例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);
    }
  });
}
 
开发者ID:Calvin-Huang,项目名称:react-native-device-brightness,代码行数:17,代码来源:RNDeviceBrightnessModule.java

示例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();
		}
	});
}
 
开发者ID:ArtifexSoftware,项目名称:mupdf-android-viewer-nui,代码行数:19,代码来源:Utilities.java

示例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();
		}
	});
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:31,代码来源:Util.java

示例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);
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:21,代码来源:WifiResultHandler.java

示例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);

}
 
开发者ID:benlau,项目名称:androidnative.pri,代码行数:28,代码来源:Util.java

示例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;

        }
    });
}
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:19,代码来源:CameraViewDisplay.java

示例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));

            }
        });
    }
 
开发者ID:enricocid,项目名称:ColorBox-library,代码行数:34,代码来源:ColorPickerFragment.java

示例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();
		}
	});
}
 
开发者ID:TommyLemon,项目名称:APIJSON-Android-RxJava,代码行数:14,代码来源:CommonUtil.java

示例12: handleReloadJS

import android.app.Activity; //导入方法依赖的package包/类
private void handleReloadJS() {
    Activity activity = getCurrentActivity();
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            devManager.handleReloadJS();
        }
    });
}
 
开发者ID:jhen0409,项目名称:react-native-devsettings-android,代码行数:10,代码来源:DevSettingsModule.java

示例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;
        }
    }
}
 
开发者ID:fivef,项目名称:add_to_evernote_note,代码行数:36,代码来源:BaseTask.java

示例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();
        }
    });
}
 
开发者ID:jhen0409,项目名称:react-native-devsettings-android,代码行数:12,代码来源:DevSettingsModule.java

示例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();
          }
        });
  }
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:18,代码来源:CameraConnectionFragment.java


注:本文中的android.app.Activity.runOnUiThread方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。