Java Code Examples for android.view.Window#setType()

The following examples show how to use android.view.Window#setType() . 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: OverlaySpecialOperation.java    From PermissionAgent with Apache License 2.0 6 votes vote down vote up
private boolean tryDisplayDialog(Context context) {
    Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
    int windowType;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        windowType = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    } else {
        windowType = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }
    Window window = dialog.getWindow();
    if (window != null) {
        window.setType(windowType);
    }
    try {
        dialog.show();
    } catch (Exception e) {
        return false;
    } finally {
        if (dialog.isShowing()) dialog.dismiss();
    }
    return true;
}
 
Example 2
Source File: OverlaySpecialOperation.java    From PermissionAgent with Apache License 2.0 6 votes vote down vote up
private boolean tryDisplayDialog(Context context) {
    Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
    int windowType;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        windowType = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    } else {
        windowType = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }
    Window window = dialog.getWindow();
    if (window != null) {
        window.setType(windowType);
    }
    try {
        dialog.show();
    } catch (Exception e) {
        return false;
    } finally {
        if (dialog.isShowing()) dialog.dismiss();
    }
    return true;
}
 
Example 3
Source File: DynamicDialogUtils.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * Bind the dialog with a window token.
 * <p>Useful to display it from a service.
 *
 * @param view The view to bind the dialog.
 * @param dialog The dialog to be displayed.
 * @param type The dialog type.
 * @param windowAnimations The custom animation used for the window.
 *
 * @return The bound dialog with the supplied view.
 */
public static Dialog bindDialog(@Nullable View view,
        @NonNull Dialog dialog, int type, @StyleRes int windowAnimations) {
    Window window = dialog.getWindow();

    if (window != null) {
        if (view != null && view.getWindowToken() != null) {
            window.getAttributes().token = view.getWindowToken();
        }

        window.setType(type);
        window.setWindowAnimations(windowAnimations);
        window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    }

    return dialog;
}
 
Example 4
Source File: BaseRequest.java    From AndPermission with Apache License 2.0 6 votes vote down vote up
static boolean tryDisplayDialog(Context context) {
    Dialog dialog = new Dialog(context, R.style.Permission_Theme_Dialog_Transparent);
    Window window = dialog.getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        window.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
    } else {
        window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    }
    try {
        dialog.show();
    } catch (Exception e) {
        return false;
    } finally {
        if (dialog.isShowing()) dialog.dismiss();
    }
    return true;
}
 
Example 5
Source File: UnsupportedDisplaySizeDialog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public UnsupportedDisplaySizeDialog(final AppWarnings manager, Context context,
        ApplicationInfo appInfo) {
    mPackageName = appInfo.packageName;

    final PackageManager pm = context.getPackageManager();
    final CharSequence label = appInfo.loadSafeLabel(pm);
    final CharSequence message = context.getString(
            R.string.unsupported_display_size_message, label);

    mDialog = new AlertDialog.Builder(context)
            .setPositiveButton(R.string.ok, null)
            .setMessage(message)
            .setView(R.layout.unsupported_display_size_dialog_content)
            .create();

    // Ensure the content view is prepared.
    mDialog.create();

    final Window window = mDialog.getWindow();
    window.setType(WindowManager.LayoutParams.TYPE_PHONE);

    // DO NOT MODIFY. Used by CTS to verify the dialog is displayed.
    window.getAttributes().setTitle("UnsupportedDisplaySizeDialog");

    final CheckBox alwaysShow = mDialog.findViewById(R.id.ask_checkbox);
    alwaysShow.setChecked(true);
    alwaysShow.setOnCheckedChangeListener((buttonView, isChecked) -> manager.setPackageFlag(
            mPackageName, AppWarnings.FLAG_HIDE_DISPLAY_SIZE, !isChecked));
}
 
Example 6
Source File: UnsupportedCompileSdkDialog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public UnsupportedCompileSdkDialog(final AppWarnings manager, Context context,
        ApplicationInfo appInfo) {
    mPackageName = appInfo.packageName;

    final PackageManager pm = context.getPackageManager();
    final CharSequence label = appInfo.loadSafeLabel(pm);
    final CharSequence message = context.getString(R.string.unsupported_compile_sdk_message,
            label);

    final AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setPositiveButton(R.string.ok, null)
            .setMessage(message)
            .setView(R.layout.unsupported_compile_sdk_dialog_content);

    // If we might be able to update the app, show a button.
    final Intent installerIntent = AppInstallerUtil.createIntent(context, appInfo.packageName);
    if (installerIntent != null) {
            builder.setNeutralButton(R.string.unsupported_compile_sdk_check_update,
                    (dialog, which) -> context.startActivity(installerIntent));
    }

    // Ensure the content view is prepared.
    mDialog = builder.create();
    mDialog.create();

    final Window window = mDialog.getWindow();
    window.setType(WindowManager.LayoutParams.TYPE_PHONE);

    // DO NOT MODIFY. Used by CTS to verify the dialog is displayed.
    window.getAttributes().setTitle("UnsupportedCompileSdkDialog");

    final CheckBox alwaysShow = mDialog.findViewById(R.id.ask_checkbox);
    alwaysShow.setChecked(true);
    alwaysShow.setOnCheckedChangeListener((buttonView, isChecked) -> manager.setPackageFlag(
            mPackageName, AppWarnings.FLAG_HIDE_COMPILE_SDK, !isChecked));
}
 
Example 7
Source File: DeprecatedTargetSdkVersionDialog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public DeprecatedTargetSdkVersionDialog(final AppWarnings manager, Context context,
        ApplicationInfo appInfo) {
    mPackageName = appInfo.packageName;

    final PackageManager pm = context.getPackageManager();
    final CharSequence label = appInfo.loadSafeLabel(pm);
    final CharSequence message = context.getString(R.string.deprecated_target_sdk_message);

    final AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setPositiveButton(R.string.ok, (dialog, which) ->
                manager.setPackageFlag(
                        mPackageName, AppWarnings.FLAG_HIDE_DEPRECATED_SDK, true))
            .setMessage(message)
            .setTitle(label);

    // If we might be able to update the app, show a button.
    final Intent installerIntent = AppInstallerUtil.createIntent(context, appInfo.packageName);
    if (installerIntent != null) {
        builder.setNeutralButton(R.string.deprecated_target_sdk_app_store,
                (dialog, which) -> {
                    context.startActivity(installerIntent);
                });
    }

    // Ensure the content view is prepared.
    mDialog = builder.create();
    mDialog.create();

    final Window window = mDialog.getWindow();
    window.setType(WindowManager.LayoutParams.TYPE_PHONE);

    // DO NOT MODIFY. Used by CTS to verify the dialog is displayed.
    window.getAttributes().setTitle("DeprecatedTargetSdkVersionDialog");
}
 
Example 8
Source File: Presentation.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new presentation that is attached to the specified display
 * using the optionally specified theme.
 *
 * @param outerContext The context of the application that is showing the presentation.
 * The presentation will create its own context (see {@link #getContext()}) based
 * on this context and information about the associated display.
 * @param display The display to which the presentation should be attached.
 * @param theme A style resource describing the theme to use for the window.
 * See <a href="{@docRoot}guide/topics/resources/available-resources.html#stylesandthemes">
 * Style and Theme Resources</a> for more information about defining and using
 * styles.  This theme is applied on top of the current theme in
 * <var>outerContext</var>.  If 0, the default presentation theme will be used.
 */
public Presentation(Context outerContext, Display display, int theme) {
    super(createPresentationContext(outerContext, display, theme), theme, false);

    mDisplay = display;
    mDisplayManager = (DisplayManager)getContext().getSystemService(DISPLAY_SERVICE);

    final Window w = getWindow();
    final WindowManager.LayoutParams attr = w.getAttributes();
    attr.token = mToken;
    w.setAttributes(attr);
    w.setGravity(Gravity.FILL);
    w.setType(TYPE_PRESENTATION);
    setCanceledOnTouchOutside(false);
}
 
Example 9
Source File: AbstractAlertView.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
private void initView() {
    Window window = getWindow();
    if (window == null) {
        return;
    }
    window.requestFeature(Window.FEATURE_NO_TITLE);

    int layoutId = getLayoutResId();
    if(layoutId != 0){
        setContentView(layoutId);
    }else{
        View contentView = onCreateView();
        if(contentView != null){
            setContentView(contentView);
        }else{
            throw new IllegalArgumentException("initialize failed.check if you have call onCreateView or getLayoutResId");
        }
    }

    setCancelable(true);
    setCanceledOnTouchOutside(true);

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
        window.setType(WindowManager.LayoutParams.TYPE_APPLICATION_PANEL);
    }

    window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

    onInitView(window);
}
 
Example 10
Source File: CandidateView.java    From sinovoice-pathfinder with MIT License 5 votes vote down vote up
/**
     * ��ʼ��¼��dialog
     */
    private void initAsrDialog() {
        mRecorderDialog = new JTAsrRecorderDialog(mService, asrListener);
        Window window = mRecorderDialog.getWindow();
        window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
//        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        mRecorderDialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                if(TextUtils.isEmpty(mAsrResult)){
                    return;
                }
                
                Message msg = mHandler.obtainMessage(Pathfinder.MSG_WHAT_ASR_RESULT, mAsrResult);
                mHandler.sendMessage(msg);
                mAsrResult = "";
            }
        });

        JTAsrRecogParams asrRecogParams = new JTAsrRecogParams();
        asrRecogParams.setCapKey(SysConfig.CAPKEY_ASR);
        asrRecogParams
                .setAudioFormat(HciCloudAsr.HCI_ASR_AUDIO_FORMAT_PCM_16K16BIT);
        asrRecogParams.setMaxSeconds("60");
        asrRecogParams.setAddPunc("yes");

        // ��ȡ�ֻ�������,�����ֻ�����������ѹ����ʽ
        int cpuCoreNum = getNumCores();
        if (cpuCoreNum > 1) {
            asrRecogParams.setEncode(HciCloudAsr.HCI_ASR_ENCODE_SPEEX);
        } else {
            asrRecogParams.setEncode(HciCloudAsr.HCI_ASR_ENCODE_ALAW);
        }
        
        mRecorderDialog.setParams(asrRecogParams);
    }
 
Example 11
Source File: Tool.java    From DialogUtil with Apache License 2.0 4 votes vote down vote up
public static void adjustStyle(final ConfigBean bean) {
    /*if (bean.alertDialog!= null){
        //setMdBtnStytle(bean);
        //setListItemsStyle(bean);
       // adjustStyle(bean.context,bean.dialog,bean.viewHeight,bean);

    }else {
        adjustWH(bean.context,bean.dialog,bean.viewHeight,bean);
    }*/

    setBg(bean);
   // bean.isTransparentBehind = true;
    setDim(bean);
    Dialog dialog = bean.dialog ==null ? bean.alertDialog : bean.dialog;
    Window window = dialog.getWindow();
    window.setGravity(bean.gravity);
    if(bean.context instanceof Activity){
        //setHomeKeyListener(window,bean);
    }else {
        window.setType(WindowManager.LayoutParams.TYPE_TOAST);
        WindowManager.LayoutParams params = window.getAttributes();
        if(params==null){
            params = new WindowManager.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        params.format = PixelFormat.RGBA_8888;
        params.flags =
           // WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL  |
            WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE  |
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
        params.dimAmount = 0.2f;
        //params.alpha = 0.5f;//the alpha of window

        window.setAttributes(params);

        // back key pressed
        window.getDecorView().setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_SETTINGS) {
                    StyledDialog.dismiss(bean.alertDialog,bean.dialog);
                    return true;
                }
                return false;
            }
        });
        // home key pressed
        setHomeKeyListener(window,bean);

        //todo outside not touchable

        //todo dim behind
        window.setDimAmount(0.2f);

    }

}
 
Example 12
Source File: DialogUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
public static void setWindowTypeToDialog(Window window) {
  window.setType(getDialogType());
}