1 /* Copyright 2019 Braden Farmer
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 package com.farmerbb.taskbar.ui;
18 import android.graphics.PixelFormat;
19 import android.view.WindowManager;
21 import com.farmerbb.taskbar.util.U;
23 import java.lang.reflect.Field;
25 public class ViewParams {
30 public int bottomMargin;
32 public ViewParams(int width, int height, int gravity, int flags, int bottomMargin) {
35 this.gravity = gravity;
37 this.bottomMargin = bottomMargin;
40 public WindowManager.LayoutParams toWindowManagerParams() {
41 final WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams(
46 PixelFormat.TRANSLUCENT
50 wmParams.gravity = gravity;
53 wmParams.y = bottomMargin;
57 Class<?> layoutParamsClass = Class.forName("android.view.WindowManager$LayoutParams");
59 Field privateFlags = layoutParamsClass.getField("privateFlags");
60 Field noAnim = layoutParamsClass.getField("PRIVATE_FLAG_NO_MOVE_ANIMATION");
62 int privateFlagsValue = privateFlags.getInt(wmParams);
63 int noAnimFlag = noAnim.getInt(wmParams);
64 privateFlagsValue |= noAnimFlag;
66 privateFlags.setInt(wmParams, privateFlagsValue);
67 } catch (Exception ignored) {}
72 public ViewParams updateWidth(int width) {
73 return new ViewParams(width, height, gravity, flags, bottomMargin);
76 public ViewParams updateHeight(int height) {
77 return new ViewParams(width, height, gravity, flags, bottomMargin);
80 public ViewParams updateBottomMargin(int bottomMargin) {
81 return new ViewParams(width, height, gravity, flags, bottomMargin);