Example usage for android.view View SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

List of usage examples for android.view View SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

Introduction

In this page you can find the example usage for android.view View SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.

Prototype

int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

To view the source code for android.view View SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.

Click Source Link

Document

Flag for #setSystemUiVisibility(int) : Requests the status bar to draw in a mode that is compatible with light status bar backgrounds.

Usage

From source file:com.irccloud.android.activity.VideoPlayerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.ImageViewerTheme);//from w  ww. j av a 2s.c  o  m
    if (savedInstanceState == null)
        overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out);
    setContentView(R.layout.activity_video_player);
    toolbar = findViewById(R.id.toolbar);
    try {
        setSupportActionBar(toolbar);
    } catch (Throwable t) {
    }
    if (Build.VERSION.SDK_INT < 21) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    } else if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.splash_logo);
        if (cloud != null) {
            setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                    cloud, getResources().getColor(android.R.color.black)));
        }
        getWindow().setStatusBarColor(getResources().getColor(android.R.color.black));
        getWindow().setNavigationBarColor(getResources().getColor(android.R.color.black));
        if (Build.VERSION.SDK_INT >= 23) {
            getWindow().getDecorView().setSystemUiVisibility(
                    getWindow().getDecorView().getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT > 16) {
        getWindow().getDecorView()
                .setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
                    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
                            toolbar.setAlpha(0);
                            toolbar.animate().alpha(1);
                            controls.setAlpha(0);
                            controls.animate().alpha(1);
                            hide_actionbar();
                        } else {
                            toolbar.setAlpha(1);
                            toolbar.animate().alpha(0);
                            controls.setAlpha(1);
                            controls.animate().alpha(0);
                        }
                    }
                });
    }

    controls = findViewById(R.id.controls);
    mProgress = findViewById(R.id.progress);

    rew = findViewById(R.id.rew);
    rew.setEnabled(false);
    rew.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                handler.removeCallbacks(mHideRunnable);
                handler.post(rewindRunnable);
            }
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                handler.removeCallbacks(rewindRunnable);
                hide_actionbar();
            }
            return false;
        }
    });
    play = findViewById(R.id.play);
    play.setEnabled(false);
    play.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            video.start();
            handler.post(mUpdateRunnable);
            hide_actionbar();
        }
    });
    pause = findViewById(R.id.pause);
    pause.setEnabled(false);
    pause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            video.pause();
            handler.post(mUpdateRunnable);
            handler.removeCallbacks(mHideRunnable);
        }
    });
    ffwd = findViewById(R.id.ffwd);
    ffwd.setEnabled(false);
    ffwd.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                handler.removeCallbacks(mHideRunnable);
                handler.post(ffwdRunnable);
            }
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                handler.removeCallbacks(ffwdRunnable);
                hide_actionbar();
            }
            return false;
        }
    });
    time_current = findViewById(R.id.time_current);
    time = findViewById(R.id.time);
    seekBar = findViewById(R.id.mediacontroller_progress);
    seekBar.setEnabled(false);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                video.seekTo(progress);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            if (video.isPlaying())
                video.pause();
            handler.removeCallbacks(mHideRunnable);
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            hide_actionbar();
        }
    });

    video = findViewById(R.id.video);
    video.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (Build.VERSION.SDK_INT > 16) {
                if ((getWindow().getDecorView().getSystemUiVisibility()
                        & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
                    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                            | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
                } else {
                    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
                    hide_actionbar();
                }
            } else {
                if (toolbar.getVisibility() == View.VISIBLE) {
                    toolbar.setVisibility(View.GONE);
                    controls.setVisibility(View.GONE);
                } else {
                    toolbar.setVisibility(View.VISIBLE);
                    controls.setVisibility(View.VISIBLE);
                    hide_actionbar();
                }
            }
            return false;
        }
    });
    video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mediaPlayer) {
            mediaPlayer.start();
            mProgress.setVisibility(View.GONE);
            rew.setEnabled(true);
            pause.setEnabled(true);
            play.setEnabled(true);
            ffwd.setEnabled(true);
            seekBar.setEnabled(true);
            handler.post(mUpdateRunnable);
            hide_actionbar();
        }
    });
    video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer) {
            video.pause();
            video.seekTo(video.getDuration());
            handler.removeCallbacks(mHideRunnable);
            if (Build.VERSION.SDK_INT > 16) {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
            } else {
                toolbar.setVisibility(View.VISIBLE);
                controls.setVisibility(View.VISIBLE);
            }
        }
    });
    video.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
            AlertDialog d = new AlertDialog.Builder(VideoPlayerActivity.this).setTitle("Playback Failed")
                    .setMessage("An error occured while trying to play this video")
                    .setPositiveButton("Download", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if (Build.VERSION.SDK_INT >= 16 && ActivityCompat.checkSelfPermission(
                                    VideoPlayerActivity.this,
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                                ActivityCompat.requestPermissions(VideoPlayerActivity.this,
                                        new String[] { Manifest.permission.READ_EXTERNAL_STORAGE,
                                                Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                        0);
                            } else {
                                DownloadManager d = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                                if (d != null) {
                                    DownloadManager.Request r = new DownloadManager.Request(
                                            Uri.parse(getIntent().getDataString().replace(
                                                    getResources().getString(R.string.VIDEO_SCHEME), "http")));
                                    r.setNotificationVisibility(
                                            DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                                    r.allowScanningByMediaScanner();
                                    d.enqueue(r);
                                }
                            }
                        }
                    }).setNegativeButton("Close", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            finish();
                        }
                    }).create();
            d.show();
            return true;
        }
    });

    if (getIntent() != null && getIntent().getDataString() != null) {
        Uri url = Uri.parse(
                getIntent().getDataString().replace(getResources().getString(R.string.VIDEO_SCHEME), "http"));
        if (url.getHost().endsWith("facebook.com")) {
            new FacebookTask().execute(url);
        } else {
            video.setVideoURI(url);
        }
        Answers.getInstance().logContentView(new ContentViewEvent().putContentType("Video"));
    } else {
        finish();
    }
}

From source file:com.heinrichreimersoftware.materialintro.app.IntroActivity.java

private void updateBackground() {
    @ColorInt//from ww w  . j a  v  a  2 s.  com
    int background;
    @ColorInt
    int backgroundNext;
    @ColorInt
    int backgroundDark;
    @ColorInt
    int backgroundDarkNext;

    if (position == getCount()) {
        background = Color.TRANSPARENT;
        backgroundNext = Color.TRANSPARENT;
        backgroundDark = Color.TRANSPARENT;
        backgroundDarkNext = Color.TRANSPARENT;
    } else {
        background = ContextCompat.getColor(IntroActivity.this, getBackground(position));
        backgroundNext = ContextCompat.getColor(IntroActivity.this,
                getBackground(Math.min(position + 1, getCount() - 1)));

        background = ColorUtils.setAlphaComponent(background, 0xFF);
        backgroundNext = ColorUtils.setAlphaComponent(backgroundNext, 0xFF);

        try {
            backgroundDark = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position));
        } catch (Resources.NotFoundException e) {
            backgroundDark = ContextCompat.getColor(IntroActivity.this, R.color.mi_status_bar_background);
        }
        try {
            backgroundDarkNext = ContextCompat.getColor(IntroActivity.this,
                    getBackgroundDark(Math.min(position + 1, getCount() - 1)));
        } catch (Resources.NotFoundException e) {
            backgroundDarkNext = ContextCompat.getColor(IntroActivity.this, R.color.mi_status_bar_background);
        }
    }

    if (position + positionOffset >= adapter.getCount() - 1) {
        backgroundNext = ColorUtils.setAlphaComponent(background, 0x00);
        backgroundDarkNext = ColorUtils.setAlphaComponent(backgroundDark, 0x00);
    }

    background = (Integer) evaluator.evaluate(positionOffset, background, backgroundNext);
    backgroundDark = (Integer) evaluator.evaluate(positionOffset, backgroundDark, backgroundDarkNext);

    miFrame.setBackgroundColor(background);

    float[] backgroundDarkHsv = new float[3];
    Color.colorToHSV(backgroundDark, backgroundDarkHsv);
    //Slightly darken the background color a bit for more contrast
    backgroundDarkHsv[2] *= 0.95;
    int backgroundDarker = Color.HSVToColor(backgroundDarkHsv);
    miPagerIndicator.setPageIndicatorColor(backgroundDarker);
    ViewCompat.setBackgroundTintList(miButtonNext, ColorStateList.valueOf(backgroundDarker));
    ViewCompat.setBackgroundTintList(miButtonBack, ColorStateList.valueOf(backgroundDarker));

    @ColorInt
    int backgroundButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT
            ? ContextCompat.getColor(this, android.R.color.white)
            : backgroundDarker;
    ViewCompat.setBackgroundTintList(miButtonCta.getChildAt(0), ColorStateList.valueOf(backgroundButtonCta));
    ViewCompat.setBackgroundTintList(miButtonCta.getChildAt(1), ColorStateList.valueOf(backgroundButtonCta));

    int iconColor;
    if (ColorUtils.calculateLuminance(backgroundDark) > 0.4) {
        //Light background
        iconColor = ContextCompat.getColor(this, R.color.mi_icon_color_light);
    } else {
        //Dark background
        iconColor = ContextCompat.getColor(this, R.color.mi_icon_color_dark);
    }
    miPagerIndicator.setCurrentPageIndicatorColor(iconColor);
    DrawableCompat.setTint(miButtonNext.getDrawable(), iconColor);
    DrawableCompat.setTint(miButtonBack.getDrawable(), iconColor);

    @ColorInt
    int textColorButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT ? backgroundDarker : iconColor;
    ((Button) miButtonCta.getChildAt(0)).setTextColor(textColorButtonCta);
    ((Button) miButtonCta.getChildAt(1)).setTextColor(textColorButtonCta);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(backgroundDark);

        if (position == adapter.getCount()) {
            getWindow().setNavigationBarColor(Color.TRANSPARENT);
        } else if (position + positionOffset >= adapter.getCount() - 1) {
            TypedValue typedValue = new TypedValue();
            TypedArray a = obtainStyledAttributes(typedValue.data,
                    new int[] { android.R.attr.navigationBarColor });

            int defaultNavigationBarColor = a.getColor(0, Color.BLACK);

            a.recycle();

            int navigationBarColor = (Integer) evaluator.evaluate(positionOffset, defaultNavigationBarColor,
                    Color.TRANSPARENT);
            getWindow().setNavigationBarColor(navigationBarColor);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            int systemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
            int flagLightStatusBar = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            if (ColorUtils.calculateLuminance(backgroundDark) > 0.4) {
                //Light background
                systemUiVisibility |= flagLightStatusBar;
            } else {
                //Dark background
                systemUiVisibility &= ~flagLightStatusBar;
            }
            getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility);
        }
    }
}

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

/**
 * Sets the status bar to be light or not. Light status bar means dark icons.
 * @param activate if true, make sure the status bar is light, otherwise base on wallpaper.
 *//* w ww  .  j a  va 2 s  .  co  m*/
public void activateLightStatusBar(boolean activate) {
    boolean lightStatusBar = activate
            || (FeatureFlags.LIGHT_STATUS_BAR && mExtractedColors.getColor(ExtractedColors.STATUS_BAR_INDEX,
                    ExtractedColors.DEFAULT_DARK) == ExtractedColors.DEFAULT_LIGHT);
    int oldSystemUiFlags = getWindow().getDecorView().getSystemUiVisibility();
    int newSystemUiFlags = oldSystemUiFlags;
    if (lightStatusBar) {
        newSystemUiFlags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    } else {
        newSystemUiFlags &= ~(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    }
    if (newSystemUiFlags != oldSystemUiFlags) {
        getWindow().getDecorView().setSystemUiVisibility(newSystemUiFlags);
    }
}

From source file:jahirfiquitiva.iconshowcase.activities.AltWallpaperViewerActivity.java

private void makeStatusBarIconsWhite() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int flags = getWindow().getDecorView().getSystemUiVisibility();
        flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        getWindow().getDecorView().setSystemUiVisibility(flags);
    }//from   www  .  ja va  2 s . c  om
}

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

/**
 * set the Current account to the one in the requested position of mAccountsCursor
 *
 * @param position/*from w w  w .ja va  2 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:xyz.klinker.blur.launcher3.Launcher.java

@Override
public void onRestoreInstanceState(Bundle state) {
    super.onRestoreInstanceState(state);
    for (int page : mSynchronouslyBoundPages) {
        mWorkspace.restoreInstanceStateForChild(page);
    }// w ww .  ja  va  2s .co  m

    if (mLauncherDrawer.isDrawerOpen(Gravity.START)) {
        if (Utilities.ATLEAST_MARSHMALLOW) {
            mLauncherDrawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        if (Utilities.ATLEAST_LOLLIPOP) {
            ValueAnimator animator = ValueAnimator.ofArgb(Color.TRANSPARENT, Color.parseColor("#22000000"));
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    int color = (Integer) valueAnimator.getAnimatedValue();
                    getWindow().setNavigationBarColor(color);
                    getWindow().setStatusBarColor(color);
                }
            });
            animator.setDuration(300);
            animator.start();
        }
    }
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

private void setupDrawer() {
    mWorkspace.setOnPageChangedListener(new Workspace.OnPageChangeListener() {
        @Override/*from w ww . j a  v a2s. c  o m*/
        public void onPageChanged(int page) {
            if (mLauncherDrawer == null) {
                return;
            }

            if (mLauncherDrawer.getDrawerLockMode(Gravity.LEFT) == LauncherDrawerLayout.LOCK_MODE_LOCKED_CLOSED
                    && !mWorkspace.isSmall()) {
                lockLauncherDrawer(false);
            }

            if (page == 0) {
                // on the first page
                mLauncherDrawer.setDrawerLeftEdgeSize(Launcher.this, 1.0f);
            } else {
                // somewhere in the middle
                mLauncherDrawer.setDrawerLeftEdgeSize(Launcher.this, .07f);
            }
        }

        @Override
        public void onScrollStart() {
            lockLauncherDrawer(true);
        }

        @Override
        public void onScrollEnd() {

        }
    });

    mDrawerPager.setPageMargin(Utils.toDP(this, 15));
    mDrawerPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            mLauncherDrawer.setCurrentDrawerPage(position);
        }
    });

    mLauncherDrawer.setDrawerListener(new LauncherDrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            mDragLayer.setTranslationX(getScreenWidth() * slideOffset);
            ((PagesFragmentAdapter) mDrawerPager.getAdapter())
                    .adjustFragmentBackgroundAlpha(mDrawerPager.getCurrentItem(), slideOffset);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            if (drawerView == mDrawerPager) {
                mDragLayer.setTranslationX(getScreenWidth());
            } else {
                mDragLayer.setTranslationX(getScreenWidth() * -1);
            }

            adapter.pagesOpened();

            if (Utilities.ATLEAST_MARSHMALLOW) {
                mLauncherDrawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            }

            if (Utilities.ATLEAST_LOLLIPOP) {
                ValueAnimator animator = ValueAnimator.ofArgb(Color.TRANSPARENT, Color.parseColor("#22000000"));
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        int color = (Integer) valueAnimator.getAnimatedValue();
                        getWindow().setNavigationBarColor(color);
                        getWindow().setStatusBarColor(color);
                    }
                });
                animator.setDuration(300);
                animator.start();
            }
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            mDragLayer.setTranslationX(0);

            adapter.pagesClosed();

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mLauncherDrawer.getWindowToken(), 0);

            if (Utilities.ATLEAST_MARSHMALLOW) {
                mLauncherDrawer.setSystemUiVisibility(
                        mLauncherDrawer.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            }

            if (Utilities.ATLEAST_LOLLIPOP) {
                ValueAnimator animator = ValueAnimator.ofArgb(Color.parseColor("#22000000"), Color.TRANSPARENT);
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        int color = (Integer) valueAnimator.getAnimatedValue();
                        getWindow().setNavigationBarColor(color);
                        getWindow().setStatusBarColor(color);
                    }
                });
                animator.setDuration(300);
                animator.start();
            }
        }

        @Override
        public void onDrawerStateChanged(int newState) {
        }

        private int screenWidth = -1;

        private int getScreenWidth() {
            if (screenWidth == -1) {
                Display display = getWindowManager().getDefaultDisplay();
                Point size = new Point();
                display.getSize(size);
                screenWidth = size.x;
            }

            return screenWidth;
        }
    });

}