Example usage for android.view Window clearFlags

List of usage examples for android.view Window clearFlags

Introduction

In this page you can find the example usage for android.view Window clearFlags.

Prototype

public void clearFlags(int flags) 

Source Link

Document

Convenience function to clear the flag bits as specified in flags, as per #setFlags .

Usage

From source file:org.billthefarmer.tuner.MainActivity.java

@Override
public boolean onLongClick(View v) {
    // Get id//from w w  w.j a  va  2  s  .  c  o  m
    int id = v.getId();
    switch (id) {
    // Spectrum
    case R.id.spectrum:
        audio.downsample = !audio.downsample;

        if (audio.downsample)
            showToast(R.string.downsample_on);
        else
            showToast(R.string.downsample_off);
        break;

    // Display
    case R.id.display:
        audio.multiple = !audio.multiple;

        if (audio.multiple)
            showToast(R.string.multiple_on);

        else
            showToast(R.string.multiple_off);
        break;

    // Meter
    case R.id.meter:
        audio.screen = !audio.screen;

        if (audio.screen)
            showToast(R.string.screen_on);

        else
            showToast(R.string.screen_off);

        Window window = getWindow();

        if (audio.screen)
            window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        else
            window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        break;
    }
    return true;
}

From source file:org.billthefarmer.tuner.MainActivity.java

void getPreferences() {
    // Load preferences

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    // Set preferences
    if (audio != null) {
        audio.input = Integer.parseInt(preferences.getString(PREF_INPUT, "0"));
        audio.reference = preferences.getInt(PREF_REFERENCE, 440);
        audio.transpose = Integer.parseInt(preferences.getString(PREF_TRANSPOSE, "0"));

        audio.filter = preferences.getBoolean(PREF_FILTER, false);
        audio.downsample = preferences.getBoolean(PREF_DOWNSAMPLE, false);
        audio.multiple = preferences.getBoolean(PREF_MULTIPLE, false);
        audio.screen = preferences.getBoolean(PREF_SCREEN, false);
        audio.strobe = preferences.getBoolean(PREF_STROBE, false);
        audio.zoom = preferences.getBoolean(PREF_ZOOM, true);

        // Check screen
        if (audio.screen) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }/*from   ww w.  j a  va 2 s .com*/

        else {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }

        // Check for strobe before setting colours
        if (strobe != null) {
            strobe.colour = Integer.valueOf(preferences.getString(PREF_COLOUR, "0"));

            if (strobe.colour == 3) {
                JSONArray custom;

                try {
                    custom = new JSONArray(preferences.getString(PREF_CUSTOM, null));

                    strobe.foreground = custom.getInt(0);
                    strobe.background = custom.getInt(1);
                }

                catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            // Ensure the view dimensions have been set
            if (strobe.width > 0 && strobe.height > 0)
                strobe.createShaders();
        }
    }
}

From source file:org.totschnig.myexpenses.activity.MyExpenses.java

/**
 * set the Current account to the one in the requested position of mAccountsCursor
 *
 * @param position// w  w w.  j  av  a2 s  .c  o  m
 */
private void setCurrentAccount(int position) {
    mAccountsCursor.moveToPosition(position);
    long newAccountId = mAccountsCursor.getLong(columnIndexRowId);
    if (mAccountId != newAccountId) {
        PrefKey.CURRENT_ACCOUNT.putLong(newAccountId);
    }
    int color = newAccountId < 0 ? colorAggregate : mAccountsCursor.getInt(columnIndexColor);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        //noinspection InlinedApi
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //noinspection InlinedApi
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        int color700 = Utils.get700Tint(color);
        window.setStatusBarColor(color700);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //noinspection InlinedApi
            getWindow().getDecorView().setSystemUiVisibility(
                    Utils.isBrightColor(color700) ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : 0);
        }
    }
    Utils.setBackgroundTintListOnFab(floatingActionButton, color);
    mAccountId = newAccountId;
    setBalance();
    mDrawerList.setItemChecked(position, true);
    supportInvalidateOptionsMenu();
}

From source file:com.achep.acdisplay.acdisplay.AcDisplayActivity.java

@SuppressLint("NewApi")
private void populateFlags(boolean windowHasFocus) {
    Window window = getWindow();
    View decorView = window.getDecorView();

    int windowFlags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;

    if (windowHasFocus) {
        int visibilityUi = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LOW_PROFILE;

        if (mConfig.isFullScreen()) {
            // Hide status bar if fullscreen mode is enabled.
            visibilityUi = visibilityUi | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_FULLSCREEN;
        }/*www . jav a  2 s .  co  m*/

        if (Device.hasKitKatApi()) {
            // Hide navigation bar and flag sticky.
            visibilityUi = visibilityUi | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        }

        decorView.setSystemUiVisibility(visibilityUi);
        window.addFlags(windowFlags);

        mTimeout.resume();
        mTimeout.setTimeoutDelayed(mConfig.getTimeoutNormal(), true);
    } else {
        int visibilityUi = decorView.getSystemUiVisibility();
        if (Device.hasKitKatApi()) {
            // Clear immersive sticky flag.
            // Hopefully it will fix annoying Android feature: IMMERSIVE_PANIC
            visibilityUi ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }

        decorView.setSystemUiVisibility(visibilityUi);
        window.clearFlags(windowFlags);

        mTimeout.setTimeoutDelayed(mConfig.getTimeoutNormal(), true);
        mTimeout.pause();
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.app.Dialog.java

/**
 * Set the dim amount of the region outside this Dialog.
 * @param amount The dim amount in [0..1].
 * @return The Dialog for chaining methods.
 */// ww  w .java 2  s  .  c o  m
public Dialog dimAmount(float amount) {
    Window window = getWindow();
    if (amount > 0f) {
        window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.dimAmount = amount;
        window.setAttributes(lp);
    } else
        window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    return this;
}

From source file:com.github.michaelins.lightstatusbar.LightStatusBar.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action//www.j  av  a 2s . c  o m
 *            The action to execute.
 * @param args
 *            JSONArry of arguments for the plugin.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * @return True if the action was valid, false otherwise.
 */
@Override
public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {

    LOG.v(TAG, "Executing action: " + action);
    final Activity activity = this.cordova.getActivity();
    final Window window = activity.getWindow();

    if ("isSupported".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M || SystemBarTintManager.IsMiuiV6Plus()) {
                    callbackContext.success("true");
                } else {
                    callbackContext.success("false");
                }
            }
        });
        return true;
    }

    if ("setStatusBarColor".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    webView.getView().setFitsSystemWindows(true);
                    if (SystemBarTintManager.IsMiuiV6Plus()) {
                        // MIUI6+ light status bar
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                            setTranslucentStatus(window, true);
                        }
                        SystemBarTintManager tintManager = new SystemBarTintManager(activity);
                        tintManager.setStatusBarTintEnabled(true);
                        tintManager.setStatusBarTintColor(Color.parseColor(args.getString(0)));
                        tintManager.setStatusBarDarkMode(true, activity);
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        // 6.0+ light status bar
                        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                        int uiOptions = window.getDecorView().getSystemUiVisibility()
                                | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                        window.getDecorView().setSystemUiVisibility(uiOptions);
                        setStatusBarBackgroundColor(args.getString(0));
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        setStatusBarBackgroundColor(args.getString(0));
                    }
                } catch (JSONException ignore) {
                    LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'");
                }
            }
        });
        return true;
    }

    if ("enable".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
            }
        });
        return true;
    }

    if ("disable".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
            }
        });
        return true;
    }
    return false;
}

From source file:com.slushpupie.deskclock.DeskClock.java

private void setScreenLock(int keepOn, int screenBrightness, int buttonBrightness) {
    Window window = getWindow();

    LayoutParams layoutParams = window.getAttributes();
    Field fButtonBrightness = null;
    try {/*from   w  w w .  j a v  a 2s .c  om*/
        fButtonBrightness = layoutParams.getClass().getField("buttonBrightness");
    } catch (NoSuchFieldException e) {

    }

    if (keepOn > 0) {

        if (keepOn == 1) {
            // Auto-brightness
            layoutParams.screenBrightness = -1.0f;
            try {
                if (fButtonBrightness != null)
                    fButtonBrightness.set(layoutParams, -1.0f);
            } catch (IllegalAccessException e) {

            }
        } else if (keepOn == 2) {
            // Manual brightness

            // Setting to 0 turns the screen off, so dont allow that
            if (prefsScreenBrightness <= 100 && prefsScreenBrightness > 0)
                layoutParams.screenBrightness = (prefsScreenBrightness / 100.0f);
            if (prefsScreenBrightness < 1)
                layoutParams.screenBrightness = 0.01f;
            try {
                if (fButtonBrightness != null && prefsButtonBrightness <= 100 && prefsButtonBrightness >= 0)
                    fButtonBrightness.set(layoutParams, (prefsButtonBrightness / 100.0f));
            } catch (IllegalAccessException e) {

            }
        } else {
            Log.e(LOG_TAG, "Unknown keepOn value!");
            return;
        }
        window.setAttributes(layoutParams);
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    } else {
        // Disable KEEP_SCREEN_ON

        try {
            if (fButtonBrightness != null)
                fButtonBrightness.set(layoutParams, -1.0f);
        } catch (IllegalAccessException e) {

        }
        layoutParams.screenBrightness = -1.0f;
        window.setAttributes(layoutParams);
        window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    }

}

From source file:org.zywx.wbpalmstar.engine.EBrowserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
    if (!EResources.init(this)) {
        loadResError();//from www .  ja  v  a2s .  c  o m
        return;
    }
    Intent intent = new Intent(EBrowserActivity.this, TempActivity.class);
    intent.putExtra("isTemp", true);
    startActivity(intent);
    overridePendingTransition(EUExUtil.getResAnimID("platform_myspace_no_anim"),
            EUExUtil.getResAnimID("platform_myspace_no_anim"));

    mVisable = true;
    Window activityWindow = getWindow();
    ESystemInfo.getIntence().init(this);
    mBrowser = new EBrowser(this);
    mEHandler = new EHandler(Looper.getMainLooper());
    View splash = initEngineUI();
    mBrowserAround = new EBrowserAround(splash);
    //      mScreen.setVisibility(View.INVISIBLE);
    setContentView(mScreen);
    initInternalBranch();

    ACEDes.setContext(this);

    Message loadDelayMsg = mEHandler.obtainMessage(EHandler.F_MSG_LOAD_HIDE_SH);
    long delay = 3 * 1000L;
    if (mSipBranch) {
        delay = 1000L;
    }
    mEHandler.sendMessageDelayed(loadDelayMsg, delay);
    Message initAppMsg = mEHandler.obtainMessage(EHandler.F_MSG_INIT_APP);
    WidgetOneApplication app = (WidgetOneApplication) getApplication();
    app.initApp(this, initAppMsg);

    EUtil.printeBackup(savedInstanceState, "onCreate");
    // EUtil.checkAndroidProxy(getBaseContext());

    handleIntent(getIntent());
    PushRecieveMsgReceiver.setContext(this);

    globalSlidingMenu = new SlidingMenu(this);
    globalSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

    //        globalSlidingMenu.setShadowWidthRes(EUExUtil.getResDimenID("shadow_width"));
    //        globalSlidingMenu.setShadowDrawable(EUExUtil.getResDrawableID("shadow"));

    //        globalSlidingMenu.setShadowWidthRes(R.dimen.shadow_width);
    //        globalSlidingMenu.setShadowDrawable(R.drawable.shadow);
    //        globalSlidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    //        globalSlidingMenu.setFadeDegree(0.35f);
    //        globalSlidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    //        globalSlidingMenu.setMenu(R.layout.menu_frame);
    //        globalSlidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
    //
    //        globalSlidingMenu.setSecondaryMenu(R.layout.menu_frame_two);
    //        globalSlidingMenu.setSecondaryShadowDrawable(R.drawable.shadowright);
    //        globalSlidingMenu.setBehindWidthRes(R.dimen.slidingmenu_width);
    //        globalSlidingMenu.setBehindWidthRes(0);
    reflectionPluginMethod("onActivityCreate");
    try {
        activityWindow
                .clearFlags(WindowManager.LayoutParams.class.getField("FLAG_NEEDS_MENU_KEY").getInt(null));
    } catch (Exception e) {
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

/**
 * Sets up transparent navigation and status bars in LMP.
 * This method is a no-op for other platform versions.
 *//*from w  w w  .  ja  va2  s  .co  m*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setupTransparentSystemBarsForLmp() {
    if (Utilities.isLmpOrAbove()) {
        Window window = getWindow();
        window.getAttributes().systemUiVisibility |= (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.setNavigationBarColor(Color.TRANSPARENT);
    }
}