android.app.Dialog#getContext ( )源码实例Demo

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

源代码1 项目: styT   文件: TapTargetView.java
public static TapTargetView showFor(Dialog dialog, TapTarget target, Listener listener) {
    if (dialog == null) throw new IllegalArgumentException("Dialog is null");

    final Context context = dialog.getContext();
    final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    params.type = WindowManager.LayoutParams.TYPE_APPLICATION;
    params.format = PixelFormat.RGBA_8888;
    params.flags = 0;
    params.gravity = Gravity.START | Gravity.TOP;
    params.x = 0;
    params.y = 0;
    params.width = WindowManager.LayoutParams.MATCH_PARENT;
    params.height = WindowManager.LayoutParams.MATCH_PARENT;

    final TapTargetView tapTargetView = new TapTargetView(context, windowManager, null, target, listener);
    windowManager.addView(tapTargetView, params);

    return tapTargetView;
}
 
@NonNull
@Override
public final Dialog onCreateDialog(@Nullable Bundle bundle) {
  Dialog dialog = new Dialog(requireContext(), getThemeResId(requireContext()));
  Context context = dialog.getContext();
  fullscreen = isFullscreen(context);
  int surfaceColor =
      MaterialAttributes.resolveOrThrow(
          context, R.attr.colorSurface, MaterialDatePicker.class.getCanonicalName());
  background =
      new MaterialShapeDrawable(
          context,
          null,
          R.attr.materialCalendarStyle,
          R.style.Widget_MaterialComponents_MaterialCalendar);
  background.initializeElevationOverlay(context);
  background.setFillColor(ColorStateList.valueOf(surfaceColor));
  background.setElevation(ViewCompat.getElevation(dialog.getWindow().getDecorView()));
  return dialog;
}
 
源代码3 项目: TapTargetView   文件: TapTargetView.java
public static TapTargetView showFor(Dialog dialog, TapTarget target, Listener listener) {
  if (dialog == null) throw new IllegalArgumentException("Dialog is null");

  final Context context = dialog.getContext();
  final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
  params.type = WindowManager.LayoutParams.TYPE_APPLICATION;
  params.format = PixelFormat.RGBA_8888;
  params.flags = 0;
  params.gravity = Gravity.START | Gravity.TOP;
  params.x = 0;
  params.y = 0;
  params.width = WindowManager.LayoutParams.MATCH_PARENT;
  params.height = WindowManager.LayoutParams.MATCH_PARENT;

  final TapTargetView tapTargetView = new TapTargetView(context, windowManager, null, target, listener);
  windowManager.addView(tapTargetView, params);

  return tapTargetView;
}
 
源代码4 项目: xposed-aweme   文件: AweMeHook.java
private LinearLayout newButtonView(final Dialog dialog,
                                   int imageRes, String desc, View.OnClickListener listener) {

    ImageView imageView = new ImageView(dialog.getContext());
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    Picasso.get().load(ResourceUtil.resourceIdToUri(
            BuildConfig.APPLICATION_ID, imageRes)).into(imageView);

    TextView textView = new TextView(dialog.getContext());
    textView.setText(desc);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(12);

    LinearLayout layout = new LinearLayout(dialog.getContext());
    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    layout.setOrientation(LinearLayout.VERTICAL);

    int width = DisplayUtil.dip2px(dialog.getContext(), 48);
    int left = DisplayUtil.dip2px(dialog.getContext(), 6);
    int bottom = DisplayUtil.dip2px(dialog.getContext(), 15);
    int top = DisplayUtil.dip2px(dialog.getContext(), 6);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, width);
    params.setMargins(0, top, 0, bottom);

    layout.setPadding(left, 0, 0, 0);
    layout.addView(imageView, params);
    layout.addView(textView, LayoutUtil.newWrapLinearLayoutParams());

    layout.setOnClickListener(listener);

    return layout;
}
 
@NonNull
@Override
public final Dialog onCreateDialog(@Nullable Bundle bundle) {
  Dialog dialog = super.onCreateDialog(bundle);
  Context context = dialog.getContext();
  int surfaceColor =
      MaterialAttributes.resolveOrThrow(
          context, R.attr.colorSurface, TimePickerDialog.class.getCanonicalName());

  MaterialShapeDrawable background =
      new MaterialShapeDrawable(
          context,
          null,
          0,
          R.style.Widget_MaterialComponents_TimePicker);

  background.initializeElevationOverlay(context);
  background.setFillColor(ColorStateList.valueOf(surfaceColor));
  Window window = dialog.getWindow();
  window.setBackgroundDrawable(background);
  window.requestFeature(Window.FEATURE_NO_TITLE);
  // On some Android APIs the dialog won't wrap content by default. Explicitly update here.
  window.setLayout(
      ViewGroup.LayoutParams.WRAP_CONTENT,
      ViewGroup.LayoutParams.WRAP_CONTENT);
  return dialog;
}