Java Code Examples for android.view.WindowManager.LayoutParams

The following are Jave code examples for showing how to use LayoutParams of the android.view.WindowManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: KUtils-master   File: ToolUtils.java   View Source Code Vote up 5 votes
public static void setDialogStyle(Context context, Dialog dialog, int measuredHeight, BuildBean bean) {
    if (dialog == null) {
        return;
    }
    Window window = dialog.getWindow();
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    window.setGravity(bean.gravity);
    WindowManager.LayoutParams wl = window.getAttributes();
    // 以下这两句是为了保证按钮可以水平满屏
    int width = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
    int height = (int) (((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight() * 0.9);
    if (bean.type != CommonConfig.TYPE_MD_LOADING_VERTICAL) {
        wl.width = (int) (width * 0.94);  // todo keycode to keep gap
    } else {
        wl.width = ViewGroup.LayoutParams.WRAP_CONTENT;
    }
    wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;  //TODO  一般情况下为wrapcontent,最大值为height*0.9
    if (measuredHeight > height) {
        wl.height = height;
    }
    if (context instanceof Activity) {
        Activity activity1 = (Activity) context;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if (activity1.isDestroyed()) {
                context = DialogUIUtils.appContext;
            }
        }
    } else {
        wl.type = WindowManager.LayoutParams.TYPE_TOAST;
        //todo keycode to improve window level,同时要让它的后面半透明背景也拦截事件,不要传递到下面去
        //todo 单例化,不然连续弹出两次,只能关掉第二次的
    }
    dialog.onWindowAttributesChanged(wl);

}
 
Example 2
Project: TvSoftKeyboard   File: GlobalSoftKeyboard.java   View Source Code Vote up 5 votes
public GlobalSoftKeyboard(Context context, String text, int maxLen, int iType,
                          WindowManager.LayoutParams params, boolean bUrl) {
    super(context, R.style.ThemeKeyboard);
    this.context = context;
    if (text == null) {
        this.text = "";
    }
    this.text = text;
    this.iMaxLength = maxLen;
    if (params != null) {
        this.layoutParams = params;
    }

    assert text != null;
    iCurTextCursor = text.length();

    this.bUrl = bUrl;
    keyLanguageList = context.getResources().getStringArray(R.array.menu_language);

    btnList = new ArrayList<>();
    imageBtnList = new ArrayList<>();

    bCapSwitch = false;
    if (iType <= SYMBOL_KEYBOARD || iType >= ALPHABET_KEYBOARD) {
        keyboardType = iType;
    } else {
        keyboardType = ALPHABET_KEYBOARD;
    }

    initKeyboard();
    setKeyGroupListener();
}
 
Example 3
Project: sao   File: MainActivity.java   View Source Code Vote up 5 votes
private void showWindow() {

        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
//        layoutParams.type = WindowManager.LayoutParams.TYPE_TOAST;
        layoutParams.type = TYPE_SYSTEM_OVERLAY;
        layoutParams.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCHABLE | FLAG_NOT_TOUCH_MODAL;
        layoutParams.format = PixelFormat.RGBA_8888;
        try {
            windowManagermanager.addView(marquee, layoutParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
Example 4
Project: ProgressManager   File: a.java   View Source Code Vote up 5 votes
public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
    // Update window manager if: we have a view, that view is
    // attached to its parent (which will be a RootView), and
    // this activity is not embedded.
    if (mParent == null) {
        View decor = mDecor;
        if (decor != null && decor.getParent() != null) {
            getWindowManager().updateViewLayout(decor, params);
        }
    }
}
 
Example 5
Project: easyShopping   File: BaseActivity.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	ActivityCollector.addActivity(this);
	// 这句很关键,注意是调用父类的方法
       super.setContentView(R.layout.activity_base);
       // 经测试在代码里直接声明透明状态栏更有效
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
           WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
           localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
       }
       initToolbar();
}
 
Example 6
Project: meipai-Android   File: RoundProgressDialog.java   View Source Code Vote up 5 votes
public RoundProgressDialog(Context context) {
    super(context, R.style.normal_dialog_white);
    setContentView(R.layout.dialog_progress);
    ButterKnife.bind(this);
    progressBar.setMax(100);

    Window window = getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = DensityUtil.getScreenWidth(context) * 8 / 10;//宽高可设置具体大小
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    window.setAttributes(lp);
}
 
Example 7
Project: ProgressManager   File: a.java   View Source Code Vote up 5 votes
public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
    // Update window manager if: we have a view, that view is
    // attached to its parent (which will be a RootView), and
    // this activity is not embedded.
    if (mParent == null) {
        View decor = mDecor;
        if (decor != null && decor.getParent() != null) {
            getWindowManager().updateViewLayout(decor, params);
        }
    }
}
 
Example 8
Project: UShareDemo   File: ShareCustomPopupWindow.java   View Source Code Vote up 5 votes
private void setWindowAlpha(float alpha) {
    Window window = activity.getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    params.alpha = alpha;
    window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    window.setAttributes(params);
}
 
Example 9
Project: Cluttr   File: AlbumPickerDialog.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.dialog_album_picker);
    ButterKnife.bind(this);

    realm = Realm.getDefaultInstance();

    setCancelable(false);

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    Window window = getWindow();
    lp.copyFrom(window.getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    window.setAttributes(lp);

    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_48px);
    toolbar.setNavigationOnClickListener(this);
    toolbar.setTitle(R.string.select_album);



    adapter = new AlbumAdapter(getContext(), getResults());
    recycler.setLayoutManager(new GridLayoutManager(getContext(),2));
    recycler.setAdapter(adapter);

    adapter.getOnClickObservable().subscribe(this);
}
 
Example 10
Project: QuranAndroid   File: TranslationReadActivity.java   View Source Code Vote up 5 votes
@Override
public void onSensorChanged(SensorEvent sensorEvent) {

    try {

        Log.i("Sensor Changed", "Accuracy :" + sensorEvent.values[0]);

        float s = sensorEvent.values[0];
        String ss = String.valueOf(s);
        if (ss.equals("0.0") ) { //even reduce

            //refreshes the screen
            int br = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.screenBrightness = (float) 10 / 255;
            getWindow().setAttributes(lp);


        } else{

            //refreshes the screen

            WindowManager.LayoutParams lp1 = getWindow().getAttributes();
            lp1.screenBrightness = (float) 255 / 255;
            getWindow().setAttributes(lp1);

        }


    } catch (Exception e)
    {
        //Throw an error case it couldn't be retrieved
        Log.e("Error", "Cannot access system brightness");
        e.printStackTrace();
    }
}
 
Example 11
Project: FriendBook   File: SystemBarUtils.java   View Source Code Vote up 5 votes
public static void transparentStatusBar(Activity activity){
    if (Build.VERSION.SDK_INT >= 21){
        expandStatusBar(activity);
        activity.getWindow()
                .setStatusBarColor(activity.getResources().getColor(android.R.color.transparent));
    }
    else if (Build.VERSION.SDK_INT >= 19){
        WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
        attrs.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | attrs.flags);
        activity.getWindow().setAttributes(attrs);
    }
}
 
Example 12
Project: EazyBaseMVP   File: UIUtils.java   View Source Code Vote up 5 votes
public static void statuInScreen(Activity activity) {
    WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
    attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    activity.getWindow().setAttributes(attrs);
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
 
Example 13
Project: FloatingNew   File: CameraPreviewService.java   View Source Code Vote up 5 votes
@Override
    public void onCreate() {
        super.onCreate();

        //   positionPreference = getSharedPreferences("Position", Context.MODE_PRIVATE);
      /*  windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);*/

        p = new Point();
        Display d = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        d.getSize(p);
        mFloatingView = LayoutInflater.from(this).inflate(R.layout.camera_preview, null);
        textureView = (TextureView) mFloatingView.findViewById(R.id.texture);

        params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);


        params.gravity = Gravity.TOP | Gravity.START;        //Initially view will be added to top-left corner
        params.x = 0; //-60;
        params.y = 100;


        setPreview();

        //Add the view to the window
        mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

        mWindowManager.addView(mFloatingView, params);

        mFloatingView.findViewById(R.id.root_container).setOnTouchListener(new Movement());
        mFloatingView.findViewById(R.id.root_container).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (movmentFlag) {
                    if (!cameraFlag) {
                        textureView.setVisibility(View.INVISIBLE);
                      //  closeCamera();
                       // stopBackgroundThread();
                        cameraFlag = true;
                    } else {
                        textureView.setVisibility(View.VISIBLE);
                       // setPreview();
                        cameraFlag = false;
                    }

                }
            }
        });

/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

    }
 
Example 14
Project: LQRWeChat   File: PopupWindowUtils.java   View Source Code Vote up 4 votes
public static void makeWindowDark(Activity activity, float alpha) {
    WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
    lp.alpha = alpha;
    activity.getWindow().setAttributes(lp);
}
 
Example 15
Project: GitHub   File: ImagePreviewActivity.java   View Source Code Vote up 4 votes
private void showStatusBar() {
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    getWindow().setAttributes(attrs);
}
 
Example 16
Project: live_master   File: SystemBarTintManager.java   View Source Code Vote up 4 votes
/**
 * Constructor. Call this in the host activity onCreate method after its
 * content view has been set. You should always create new instances when
 * the host activity is recreated.
 *
 * @param activity The host activity.
 */
@TargetApi(19)
public SystemBarTintManager(Activity activity) {

    Window win = activity.getWindow();
    ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // check theme attrs
        int[] attrs = {android.R.attr.windowTranslucentStatus,
                android.R.attr.windowTranslucentNavigation};
        TypedArray a = activity.obtainStyledAttributes(attrs);
        try {
            mStatusBarAvailable = a.getBoolean(0, false);
            mNavBarAvailable = a.getBoolean(1, false);
        } finally {
            a.recycle();
        }

        // check window flags
        WindowManager.LayoutParams winParams = win.getAttributes();
        int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if ((winParams.flags & bits) != 0) {
            mStatusBarAvailable = true;
        }
        bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
        if ((winParams.flags & bits) != 0) {
            mNavBarAvailable = true;
        }
    }

    mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable);
    // device might not have virtual navigation keys
    if (!mConfig.hasNavigtionBar()) {
        mNavBarAvailable = false;
    }

    if (mStatusBarAvailable) {
        setupStatusBarView(activity, decorViewGroup);
    }
    if (mNavBarAvailable) {
        setupNavBarView(activity, decorViewGroup);
    }

}
 
Example 17
Project: simple-share-android   File: SystemBarTintManager.java   View Source Code Vote up 4 votes
/**
 * Constructor. Call this in the host activity onCreate method after its
 * content view has been set. You should always create new instances when
 * the host activity is recreated.
 *
 * @param activity The host activity.
 */
@TargetApi(19)
public SystemBarTintManager(Activity activity) {

    Window win = activity.getWindow();
    ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // check theme attrs
        int[] attrs = {android.R.attr.windowTranslucentStatus,
                android.R.attr.windowTranslucentNavigation};
        TypedArray a = activity.obtainStyledAttributes(attrs);
        try {
            mStatusBarAvailable = a.getBoolean(0, false);
            //mNavBarAvailable = a.getBoolean(1, false);
        } finally {
            a.recycle();
        }

        // check window flags
        WindowManager.LayoutParams winParams = win.getAttributes();
        int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if ((winParams.flags & bits) != 0) {
            mStatusBarAvailable = true;
        }
        bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
        if ((winParams.flags & bits) != 0) {
            mNavBarAvailable = true;
        }
    }

    mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable);
    // device might not have virtual navigation keys
    if (!mConfig.hasNavigtionBar()) {
        mNavBarAvailable = false;
    }

    if (mStatusBarAvailable) {
        setupStatusBarView(activity, decorViewGroup);
    }
    if (mNavBarAvailable) {
        setupNavBarView(activity, decorViewGroup);
    }

}
 
Example 18
Project: WhatsAppStatusSaver   File: MainActivity.java   View Source Code Vote up 4 votes
public void showImagePopup(Point p, final String uri) {
        Activity context = MainActivity.this;
        //COMPLETED solving video problem

        final Dialog dialog = new Dialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.image_popup_layout);
        dialog.show();
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.copyFrom(dialog.getWindow().getAttributes());
        dialog.getWindow().setAttributes(lp);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.getWindow().setDimAmount(0);


        // Getting a reference to Close button, and close the popup when clicked.
        FloatingActionButton close = (FloatingActionButton) dialog.findViewById(R.id.close_image_popup_button);
        ImageView statusImage = (ImageView) dialog.findViewById(R.id.full_status_image_view);
        final SimpleExoPlayerView simpleExoPlayerView = dialog.findViewById(R.id.full_status_video_view);
        final SimpleExoPlayer player;
        if (uri.endsWith(".jpg")) {
            GlideApp.with(context).load(uri).fitCenter().into(statusImage);
        } else if (uri.endsWith(".mp4")) {
            statusImage.setVisibility(View.GONE);
            simpleExoPlayerView.setVisibility(View.VISIBLE);
            Uri myUri = Uri.parse(uri); // initialize Uri here

            // 1. Create a default TrackSelector
            BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
            TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
            TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

// 2. Create a default LoadControl
            LoadControl loadControl = new DefaultLoadControl();

// 3. Create the player
            player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

//Set media controller
            simpleExoPlayerView.setUseController(true);
            simpleExoPlayerView.requestFocus();

// Bind the player to the view.
            simpleExoPlayerView.setPlayer(player);

            //Measures bandwidth during playback. Can be null if not required.
            DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter();
//Produces DataSource instances through which media data is loaded.
            DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.
                    getUserAgent(this, "exoplayer2example"), bandwidthMeterA);
//Produces Extractor instances for parsing the media data.
            ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();

            MediaSource videoSource = new ExtractorMediaSource(myUri, dataSourceFactory, extractorsFactory, null, null);
            player.prepare(videoSource);
            player.setPlayWhenReady(true); //run file/link when ready to play.
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    player.release();
                }
            });

        }
        close.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
//                popup.dismiss();
                dialog.cancel();
            }
        });
    }
 
Example 19
Project: FLFloatingButton   File: FloatingView.java   View Source Code Vote up 4 votes
/**
 * WindowManager.LayoutParamsを取得します。
 */
WindowManager.LayoutParams getWindowLayoutParams() {
    return mParams;
}
 
Example 20
Project: PreAPP   File: FloatWindowSmallView.java   View Source Code Vote up 2 votes
/**
 * 将小悬浮窗的参数传入,用于更新小悬浮窗的位置。
 *
 * @param params 小悬浮窗的参数
 */
public void setParams(WindowManager.LayoutParams params) {
    mParams = params;
}