Java Code Examples for android.app.Dialog#getContext()

The following examples show how to use android.app.Dialog#getContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TapTargetView.java    From styT with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: MaterialDatePicker.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: TapTargetView.java    From TapTargetView with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: AweMeHook.java    From xposed-aweme with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: TimePickerDialog.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@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;
}