当前位置: 首页>>代码示例>>Java>>正文


Java WindowManager类代码示例

本文整理汇总了Java中android.view.WindowManager的典型用法代码示例。如果您正苦于以下问题:Java WindowManager类的具体用法?Java WindowManager怎么用?Java WindowManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WindowManager类属于android.view包,在下文中一共展示了WindowManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.view.WindowManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
  mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
      PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "AlarmActivity");
  mWakeLock.acquire(2 * 60 * 1000L);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getWindow();
    window.getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    window.setStatusBarColor(Color.TRANSPARENT);
  }

  setContentView(R.layout.activity_alarm);
  if (getActivityComponent() != null) {
    getActivityComponent().inject(this);
    alarmPresenter.onAttach(this);
  }
  initViews();
  bindEvents();
  processIntent();
}
 
开发者ID:Arjun-sna,项目名称:LocationAware,代码行数:27,代码来源:AlarmActivity.java

示例2: show

import android.view.WindowManager; //导入依赖的package包/类
@Override
public void show() {
    if (!SettingsCompat.canDrawOverlays(mUiHandler.getContext())) {
        SettingsCompat.manageDrawOverlays(mUiHandler.getContext());
        mUiHandler.toast(R.string.text_no_floating_window_permission);
        return;
    }
    startFloatyService();
    mUiHandler.post(new Runnable() {
        @Override
        public void run() {
            try {
                FloatyService.addWindow(mFloatyWindow);
                // SecurityException: https://github.com/hyb1996-guest/AutoJsIssueReport/issues/4781
            } catch (WindowManager.BadTokenException | SecurityException e) {
                e.printStackTrace();
                mUiHandler.toast(R.string.text_no_floating_window_permission);
            }
        }
    });
    mShown = true;
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:23,代码来源:StardustConsole.java

示例3: showTopRightMenu

import android.view.WindowManager; //导入依赖的package包/类
/**
 * 显示一个右上角弹出的menu
 *
 * @param activity
 * @param contentView
 * @param width
 * @param x
 * @param y
 * @return
 */
public static Dialog showTopRightMenu(Context activity, View contentView, int width, int x, int y) {
    Dialog dialog = new Dialog(activity, R.style.FullScreenDialog);
    dialog.setContentView(contentView);
    Window window = dialog.getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = width == 0 ? UIUtils.dip2px(120) : width;
    lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    lp.x = x == 0 ? UIUtils.dip2px(5) : x;
    lp.y = y == 0 ? UIUtils.dip2px(48) : y;
    lp.verticalMargin = 0;
    lp.horizontalMargin = 0;
    lp.dimAmount = 0.15f;
    window.setAttributes(lp);
    window.setWindowAnimations(R.style.topright_dialog);
    window.setGravity(Gravity.TOP | Gravity.RIGHT); // 此处可以设置dialog显示的位置
    dialog.show();
    return dialog;
}
 
开发者ID:Pingsh,项目名称:Mix,代码行数:29,代码来源:UIUtils.java

示例4: setColor

import android.view.WindowManager; //导入依赖的package包/类
/**
 * 设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */

public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
        View fakeStatusBarView = decorView.findViewWithTag(FAKE_STATUS_BAR_VIEW_TAG);
        if (fakeStatusBarView != null) {
            if (fakeStatusBarView.getVisibility() == View.GONE) {
                fakeStatusBarView.setVisibility(View.VISIBLE);
            }
            fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        } else {
            decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
        }
        setRootView(activity);
    }
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:29,代码来源:BarUtils.java

示例5: fixLayout

import android.view.WindowManager; //导入依赖的package包/类
private void fixLayout() {
    ViewTreeObserver obs = fragmentView.getViewTreeObserver();
    obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (fragmentView == null) {
                return true;
            }
            fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
            LinearLayout layout = (LinearLayout) fragmentView;
            WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
            int rotation = manager.getDefaultDisplay().getRotation();

            if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
                layout.setOrientation(LinearLayout.HORIZONTAL);
            } else {
                layout.setOrientation(LinearLayout.VERTICAL);
            }

            fragmentView.setPadding(fragmentView.getPaddingLeft(), 0, fragmentView.getPaddingRight(), fragmentView.getPaddingBottom());
            return true;
        }
    });
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:25,代码来源:IdenticonActivity.java

示例6: SDLSurface

import android.view.WindowManager; //导入依赖的package包/类
public SDLSurface(Context context) {
    super(context);
    getHolder().addCallback(this);

    setFocusable(true);
    setFocusableInTouchMode(true);
    requestFocus();
    setOnKeyListener(this);
    setOnTouchListener(this);

    mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);

    if(Build.VERSION.SDK_INT >= 12) {
        setOnGenericMotionListener(new SDLGenericMotionListener_API12());
    }

    // Some arbitrary defaults to avoid a potential division by zero
    mWidth = 1.0f;
    mHeight = 1.0f;
}
 
开发者ID:jomof,项目名称:cdep-android-studio-freetype-sample,代码行数:22,代码来源:SDLActivity.java

示例7: setColorForDrawerLayoutDiff

import android.view.WindowManager; //导入依赖的package包/类
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 * @param color        状态栏颜色值
 */
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // 生成一个状态栏大小的矩形
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
            contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
        } else {
            // 添加 statusBarView 到布局中
            StatusBarView statusBarView = createStatusBarView(activity, color);
            contentLayout.addView(statusBarView, 0);
        }
        // 内容布局不是 LinearLayout 时,设置padding top
        if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        // 设置属性
        ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
        drawerLayout.setFitsSystemWindows(false);
        contentLayout.setFitsSystemWindows(false);
        contentLayout.setClipToPadding(true);
        drawer.setFitsSystemWindows(false);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:StatusBarUtil.java

示例8: initFromCameraParameters

import android.view.WindowManager; //导入依赖的package包/类
public void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point theScreenResolution = new Point();
    theScreenResolution = getDisplaySize(display);

    screenResolution = theScreenResolution;
    Log.i(TAG, "Screen resolution: " + screenResolution);

    /** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */
    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = screenResolution.x;
    screenResolutionForCamera.y = screenResolution.y;

    if (screenResolution.x < screenResolution.y) {
        screenResolutionForCamera.x = screenResolution.y;
        screenResolutionForCamera.y = screenResolution.x;
    }

    cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera);
    Log.i(TAG, "Camera resolution x: " + cameraResolution.x);
    Log.i(TAG, "Camera resolution y: " + cameraResolution.y);
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:25,代码来源:CameraConfigurationManager.java

示例9: onCreate

import android.view.WindowManager; //导入依赖的package包/类
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) { // <3>
  super.onCreate(savedInstanceState);

  // Set full screen view <4>
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN);
  requestWindowFeature(Window.FEATURE_NO_TITLE);

  // Create new instance of custom Rose and set it on the screen
  rose = new Rose(this); // <5>
  setContentView(rose); // <6>

  // Get sensor and sensor manager
  sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); // <7>
  sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); // <8>

  Log.d("Compass", "onCreated");
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:21,代码来源:Compass.java

示例10: getDeviceOrientation

import android.view.WindowManager; //导入依赖的package包/类
private int getDeviceOrientation() {
  int orientation = 0;

  WindowManager wm = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE);
  switch (wm.getDefaultDisplay().getRotation()) {
    case Surface.ROTATION_90:
      orientation = 90;
      break;
    case Surface.ROTATION_180:
      orientation = 180;
      break;
    case Surface.ROTATION_270:
      orientation = 270;
      break;
    case Surface.ROTATION_0:
    default:
      orientation = 0;
      break;
  }
  return orientation;
}
 
开发者ID:lgyjg,项目名称:AndroidRTC,代码行数:22,代码来源:Camera1Session.java

示例11: initFromCameraParameters

import android.view.WindowManager; //导入依赖的package包/类
public void initFromCameraParameters(Camera camera) {
	Camera.Parameters parameters = camera.getParameters();
	WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
	Display display = manager.getDefaultDisplay();
	Point theScreenResolution = new Point();
	theScreenResolution = getDisplaySize(display);

	screenResolution = theScreenResolution;
	Log.i(TAG, "Screen resolution: " + screenResolution);

	/** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */
	Point screenResolutionForCamera = new Point();
	screenResolutionForCamera.x = screenResolution.x;
	screenResolutionForCamera.y = screenResolution.y;

	if (screenResolution.x < screenResolution.y) {
		screenResolutionForCamera.x = screenResolution.y;
		screenResolutionForCamera.y = screenResolution.x;
	}

	cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera);
	Log.i(TAG, "Camera resolution x: " + cameraResolution.x);
	Log.i(TAG, "Camera resolution y: " + cameraResolution.y);
}
 
开发者ID:TonnyL,项目名称:Espresso,代码行数:25,代码来源:CameraConfigurationManager.java

示例12: applyGravity

import android.view.WindowManager; //导入依赖的package包/类
/**
 * apply the gravity for window params.
 *
 * @param expectGravity the expect gravity
 * @param applyWlp      the window layout params.
 */
private static void applyGravity(Context context,int expectGravity, WindowManager.LayoutParams applyWlp) {
    if (Build.VERSION.SDK_INT >= 17) {
        final Configuration configuration = context.getResources().getConfiguration();
        final int gravity = Gravity.getAbsoluteGravity(expectGravity, configuration.getLayoutDirection());
        applyWlp.gravity = gravity;
        if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
            applyWlp.horizontalWeight = 1.0f;
        }
        if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
            applyWlp.verticalWeight = 1.0f;
        }
    } else {
        applyWlp.gravity = expectGravity;
    }
}
 
开发者ID:LightSun,项目名称:android-util2,代码行数:22,代码来源:BaseWindow.java

示例13: onLayout

import android.view.WindowManager; //导入依赖的package包/类
@SuppressLint("DrawAllocation")
private void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (changed) {
        scale = 1;
        translationX = 0;
        translationY = 0;
        updateMinMax(scale);

        if (checkImageView != null) {
            checkImageView.post(new Runnable() {
                @Override
                public void run() {
                    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) checkImageView.getLayoutParams();
                    WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
                    int rotation = manager.getDefaultDisplay().getRotation();
                    layoutParams.topMargin = AndroidUtilities.dp(rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58 : 68);
                    checkImageView.setLayoutParams(layoutParams);
                }
            });
        }
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:23,代码来源:PhotoViewer.java

示例14: onCreate

import android.view.WindowManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_question2);


    et[0]= (EditText) findViewById(R.id.dogEt);
    et[1]= (EditText) findViewById(R.id.catEt);
    et[2]= (EditText) findViewById(R.id.ratEt);
    et[3]= (EditText) findViewById(R.id.coffeeEt);
    et[4]= (EditText) findViewById(R.id.seaEt);
    Button resetB= (Button) findViewById(R.id.resetB1);
    Button nextB= (Button) findViewById(R.id.nextB1);

    Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
    toolbar.setTitle(getResources().getString(R.string.question_2));
    setSupportActionBar(toolbar);

    int pColor= Color.parseColor("#00c853");
    resetB.getBackground().setColorFilter(pColor, PorterDuff.Mode.MULTIPLY);
    nextB.getBackground().setColorFilter(pColor, PorterDuff.Mode.MULTIPLY);

}
 
开发者ID:shivam301296,项目名称:TibetanPersonalityTest,代码行数:27,代码来源:Question2.java

示例15: onActivityResult

import android.view.WindowManager; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_EDITITEM:
        if (resultCode == RESULT_OK) {
            remoteNotifyAll();
            updateItemList();
            getWindow()
                    .setSoftInputMode(
                            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        }
    case REQUEST_PREFS:
        readPrefs();
        break;
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:17,代码来源:TallyphantActivity.java


注:本文中的android.view.WindowManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。