Example usage for android.app Activity getWindow

List of usage examples for android.app Activity getWindow

Introduction

In this page you can find the example usage for android.app Activity getWindow.

Prototype

public Window getWindow() 

Source Link

Document

Retrieve the current android.view.Window for the activity.

Usage

From source file:Main.java

/**
 * Tries to get the available width from the (previously measured) view of the activity.
 * If if fails then calls getDisplayWidth().
 *///from w w w  . jav  a2  s  .  co m
private static int getWindowWidth(Activity activity) {
    int width = 0;

    //Doesn't work on create method, should call it from another place?
    View content = activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
    if (content != null)
        width = content.getWidth();

    if (width == 0)
        width = getDisplayWidth(activity);

    return width;
}

From source file:Main.java

public static int getStatusBarHeight(Activity activity) {

    if (statusBarHeight > 0) {
        return statusBarHeight;
    }/*ww w.  ja  va  2 s  .  c  o m*/
    Rect rectgle = new Rect();
    Window window = activity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
    statusBarHeight = rectgle.top;
    return statusBarHeight;

}

From source file:Main.java

/**
 * Hides the activity's action bar/*from   www  . ja  va2  s .c  o  m*/
 *
 * @param activity
 *     the activity
 */
public static void hideActionBar(Activity activity) {
    // Call before calling setContentView();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && activity != null) {
        activity.getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        activity.getActionBar().hide();
    }
}

From source file:Main.java

public static void setSpinnerState(Activity a) {
    if (isMediaScannerScanning(a)) {
        // start the progress spinner
        a.getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, Window.PROGRESS_INDETERMINATE_ON);

        a.getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
    } else {// w ww .j  a  v a  2  s.c o m
        // stop the progress spinner
        a.getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, Window.PROGRESS_VISIBILITY_OFF);
    }
}

From source file:song.com.android_anim.TransitionHelper.java

public static Pair<View, String>[] createSafeTransitionParticipants(@NonNull Activity activity,
        boolean includeStatusBar, @Nullable Pair... otherParticipants) {

    View decor = activity.getWindow().getDecorView();
    View statusBar = null;//from  w ww.  j av  a  2s.  c  o  m
    if (includeStatusBar) {
        statusBar = decor.findViewById(android.R.id.statusBarBackground);
    }
    View navBar = decor.findViewById(android.R.id.navigationBarBackground);

    List<Pair> participants = new ArrayList<>(3);
    addNonNullViewToTransitionParticipants(statusBar, participants);
    addNonNullViewToTransitionParticipants(navBar, participants);

    if (otherParticipants != null && !(otherParticipants.length == 1 && otherParticipants[0] == null)) {
        participants.addAll(Arrays.asList(otherParticipants));
    }
    return participants.toArray(new Pair[participants.size()]);
}

From source file:Main.java

/**
 * Sets the Android fullscreen flags. Expected to be called from {@link
 * Activity#onWindowFocusChanged(boolean hasFocus)}.
 *
 * @param activity the Activity on which the full screen mode will be set.
 * @param hasFocus the hasFocus flag passed from the {@link Activity#onWindowFocusChanged(boolean
 *                 hasFocus)} callback.// w ww.ja v a2  s . c o  m
 */
public static void setFullScreenOnWindowFocusChanged(Activity activity, boolean hasFocus) {
    if (hasFocus) {
        // https://developer.android.com/training/system-ui/immersive.html#sticky
        activity.getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
}

From source file:Main.java

public static void removeActivityBackgroundCompat(Activity activity) {
    if (activity == null) {
        throw new IllegalArgumentException("Activity is null");
    }/*ww  w. j  a v a 2 s .  c  o  m*/

    if (Build.VERSION.SDK_INT >= 16) {
        activity.getWindow().getDecorView().setBackground(null);
    } else {
        activity.getWindow().getDecorView().setBackgroundDrawable(null);
    }
}

From source file:Main.java

public static void removeSysKey(Activity context, EditText paramEditText) {
    if (Build.VERSION.SDK_INT <= 10) {
        paramEditText.setInputType(0);/*from w ww . ja  v a  2s . c o m*/
        return;
    }
    context.getWindow().setSoftInputMode(3);
    try {
        Class[] arrayOfClass = new Class[1];
        arrayOfClass[0] = Boolean.TYPE;
        Method localMethod = EditText.class.getMethod("setShowSoftInputOnFocus", arrayOfClass);
        localMethod.setAccessible(true);
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = Boolean.valueOf(false);
        localMethod.invoke(paramEditText, arrayOfObject);
        return;
    } catch (Exception localException) {
        localException.printStackTrace();
    }
}

From source file:Main.java

public static void dismissSoftKeyBoard(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
    }//w  w w. java  2  s . c  om
}

From source file:Main.java

public static float setBrightness(float brightness, Activity a) {
    if (brightness < 20.0)
        brightness = (float) 20.0;
    else if (brightness > 255.0)
        brightness = (float) 255.0;

    WindowManager.LayoutParams lp = a.getWindow().getAttributes();
    lp.screenBrightness = (float) (brightness / 255.0);
    a.getWindow().setAttributes(lp);/*from www  .  j a v a 2  s. co m*/

    return brightness;
}