當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。