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:com.google.android.exoplayer2.demo.MediaPlayerFragment.java

private void initBrightnessTouch() {

    //        if (!(getContext() instanceof Activity)) {
    //            return;
    //        }/*from   ww w . j ava2 s  . c om*/
    Activity activity = fragActivity;//(Activity) getContext();

    WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
    float brightnesstemp = lp.screenBrightness != -1f ? lp.screenBrightness : 0.6f;
    // Initialize the layoutParams screen brightness
    try {
        if (Settings.System.getInt(activity.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
            if (!Permissions.canWriteSettings(activity)) {
                return;
            }
            Settings.System.putInt(activity.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE,
                    Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
            //                restoreAutoBrightness = android.provider.Settings.System.getInt(activity.getContentResolver(),
            //                        android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f;
        } else if (brightnesstemp == 0.6f) {
            brightnesstemp = android.provider.Settings.System.getInt(activity.getContentResolver(),
                    android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f;
        }
    } catch (Settings.SettingNotFoundException e) {
        e.printStackTrace();
    }
    lp.screenBrightness = brightnesstemp;
    activity.getWindow().setAttributes(lp);
    mIsFirstBrightnessGesture = false;
}

From source file:fr.cph.chicago.util.Util.java

public static void setWindowsColor(@NonNull final Activity activity, @NonNull final Toolbar toolbar,
        @NonNull final TrainLine trainLine) {
    int backgroundColor = 0;
    int statusBarColor = 0;
    //int navigationBarColor = 0;
    int textTitleColor = R.color.white;
    switch (trainLine) {
    case BLUE://w ww  .  j  a va  2 s . co  m
        backgroundColor = R.color.blueLine;
        statusBarColor = R.color.blueLineDark;
        break;
    case BROWN:
        backgroundColor = R.color.brownLine;
        statusBarColor = R.color.brownLineDark;
        break;
    case GREEN:
        backgroundColor = R.color.greenLine;
        statusBarColor = R.color.greenLineDark;
        break;
    case ORANGE:
        backgroundColor = R.color.orangeLine;
        statusBarColor = R.color.orangeLineDarker;
        break;
    case PINK:
        backgroundColor = R.color.pinkLine;
        statusBarColor = R.color.pinkLineDark;
        break;
    case PURPLE:
        backgroundColor = R.color.purpleLine;
        statusBarColor = R.color.purpleLineDark;
        break;
    case RED:
        backgroundColor = R.color.redLine;
        statusBarColor = R.color.redLineDark;
        break;
    case YELLOW:
        backgroundColor = R.color.yellowLine;
        statusBarColor = R.color.yellowLineDark;
        break;
    case NA:
        backgroundColor = R.color.primaryColor;
        statusBarColor = R.color.primaryColorDark;
        break;
    }
    toolbar.setBackgroundColor(ContextCompat.getColor(activity.getApplicationContext(), backgroundColor));
    toolbar.setTitleTextColor(ContextCompat.getColor(activity.getApplicationContext(), textTitleColor));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, statusBarColor));
        activity.getWindow()
                .setNavigationBarColor(ContextCompat.getColor(activity, R.color.primaryColorDarker));
    }
}

From source file:android.support.v7.app.WindowDecorActionBar.java

public WindowDecorActionBar(Activity activity, boolean overlayMode) {
    mActivity = activity;/*from   www.  j av  a 2  s. c o  m*/
    Window window = activity.getWindow();
    View decor = window.getDecorView();
    init(decor);
    if (!overlayMode) {
        mContentView = decor.findViewById(android.R.id.content);
    }
}

From source file:net.tjado.passwdsafe.PasswdSafeOpenFileFragment.java

public void resetOverflowButton(final Activity activity) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override/*w  w  w .j  a  v  a2  s. c  o  m*/
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);

            overflow.setImageDrawable(itsOriginalDrawable);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}

From source file:net.tjado.passwdsafe.PasswdSafeOpenFileFragment.java

public void setOverflowButton(final Activity activity) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override//from w  ww .  ja  va 2s . c  om
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);

            itsOriginalDrawable = overflow.getDrawable();

            overflow.setImageDrawable(PasswdSafeUtil.scaleImage(
                    activity.getResources().getDrawable(R.drawable.icon_yubico), 0.09f, getResources()));
            overflow.setColorFilter(activity.getResources().getColor(R.color.menu_icon_color));
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}

From source file:im.ene.lab.toro.ext.layeredvideo.PlaybackControlLayer.java

/**
 * Fullscreen mode will rotate to landscape mode, hide the action bar, hide the navigation bar,
 * hide the system tray, and make the video player take up the full size of the display.
 * The developer who is using this function must ensure the following:
 *
 * <p>1) Inside the android manifest, the activity that uses the video player has the attribute
 * android:configChanges="orientation"./*from  www.  j a v a2  s . c  om*/
 *
 * <p>2) Other views in the activity (or fragment) are
 * hidden (or made visible) when this method is called.
 */
public void doToggleFullscreen() {
    // If there is no callback for handling fullscreen, don't do anything.
    if (fullscreenCallback == null) {
        return;
    }

    ObservablePlayerControl playerControl = layerManager.getControl();
    if (playerControl == null) {
        return;
    }

    Activity activity = layerManager.getActivity();
    FrameLayout container = layerManager.getContainer();

    if (isFullscreen) {
        activity.setRequestedOrientation(savedOrientation);

        // Make the status bar and navigation bar visible again.
        activity.getWindow().getDecorView().setSystemUiVisibility(0);

        container.setLayoutParams(originalContainerLayoutParams);

        fullscreenButton.setImageResource(R.drawable.toro_ext_ic_fullscreen_enter);

        fullscreenCallback.onReturnFromFullscreen();
        isFullscreen = false;
    } else {
        savedOrientation = activity.getResources().getConfiguration().orientation;
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        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);

        container.setLayoutParams(PlayerUtil.getLayoutParamsBasedOnParent(container,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        fullscreenButton.setImageResource(R.drawable.toro_ext_ic_fullscreen_exit);
        fullscreenCallback.onGoToFullscreen();
        isFullscreen = true;
    }
}

From source file:com.juick.android.ThreadFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*  ww w  . ja  va2s  . c  o m*/
        parentActivity = (ThreadFragmentListener) activity;
        navMenu = (MyImageView) activity.findViewById(R.id.navmenu);
        if (navMenu != null) {
            navMenu.setVisibility(View.GONE);
            initNavMenuTranslationX = navMenu.initialTranslationX;
            FlyingItem top = new FlyingItem(activity.getWindow().getDecorView(), R.id.navbar_top);
            FlyingItem bottom = new FlyingItem(activity.getWindow().getDecorView(), R.id.navbar_bottom);
            flyingItems = new FlyingItem[] { top, bottom };
        }
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement ThreadFragmentListener");
    }
}

From source file:org.cryptsecure.Utility.java

/**
 * Hide soft keys in full screen. This only applies to HONECOMB+ Android
 * versions. Older versions rely on hardware keys and do not have soft keys
 * that might get annoying in a full screen application.
 * /*from  ww  w  . j ava  2  s  .  c  o m*/
 * @param activity
 *            the activity
 */
@SuppressLint("InlinedApi")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void hideSoftkeys(Activity activity) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    }
}

From source file:org.cryptsecure.Utility.java

/**
 * Hide the soft keyboard. Consider also using hideKeyboardExplicit() if
 * there is a text input field./*from w ww  .j av a  2s. c o  m*/
 * 
 * @param activity
 *            the activity
 */
public static void hideKeyboard(Activity activity) {
    // This can be used to suppress the keyboard until the user actually
    // touches the edittext view.
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:com.kenmeidearu.materialdatetimepicker.date.DatePickerDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Activity activity = getActivity();
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mCurrentView = UNINITIALIZED;//from   w w w. j a v  a2s .c  o  m
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_INITIAL_TIME)
            && savedInstanceState.containsKey(KEY_IS_24_HOUR_VIEW)) {
        mCalendar.set(Calendar.YEAR, savedInstanceState.getInt(KEY_SELECTED_YEAR));
        mCalendar.set(Calendar.MONTH, savedInstanceState.getInt(KEY_SELECTED_MONTH));
        mCalendar.set(Calendar.DAY_OF_MONTH, savedInstanceState.getInt(KEY_SELECTED_DAY));
        mDefaultView = savedInstanceState.getInt(KEY_DEFAULT_VIEW);
        //time
        mInitialTime = savedInstanceState.getParcelable(KEY_INITIAL_TIME);
        mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
        mEnableSeconds = savedInstanceState.getBoolean(KEY_ENABLE_SECONDS);
        mEnableMinutes = savedInstanceState.getBoolean(KEY_ENABLE_MINUTES);

    }
}