當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。