Java Code Examples for android.content.res.Configuration#UI_MODE_NIGHT_YES

The following examples show how to use android.content.res.Configuration#UI_MODE_NIGHT_YES . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreTabWidgetsGridRecyclerFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
public Observable<List<Displayable>> parseDisplayables(GetStoreWidgets getStoreWidgets) {
  int currentNightMode = getContext().getResources()
      .getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;

  boolean isDarkTheme = currentNightMode == Configuration.UI_MODE_NIGHT_YES;

  return Observable.from(getStoreWidgets.getDataList()
      .getList())
      .concatMapEager(wsWidget -> {
        AptoideApplication application =
            (AptoideApplication) getContext().getApplicationContext();
        return DisplayablesFactory.parse(marketName, wsWidget, storeTheme, storeRepository,
            storeCredentialsProvider, storeContext, getContext(), accountManager, storeUtilsProxy,
            (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE),
            getContext().getResources(), installedRepository, storeAnalytics, storeTabNavigator,
            navigationTracker, new BadgeDialogFactory(getActivity(), themeManager),
            ((ActivityResultNavigator) getContext()).getFragmentNavigator(),
            application.getBodyInterceptorPoolV7(), application.getDefaultClient(),
            WebService.getDefaultConverter(), application.getTokenInvalidator(),
            application.getDefaultSharedPreferences(), themeManager);
      })
      .toList()
      .first();
}
 
Example 2
Source File: MainActivity.java    From SkinSprite with MIT License 6 votes vote down vote up
@Override
public void onClick(View view) {
    int currentNightMode = getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    switch (currentNightMode) {
        case Configuration.UI_MODE_NIGHT_NO: {
            setDayNightMode(AppCompatDelegate.MODE_NIGHT_YES);
            // Night mode is not active, we're in day time
            break;
        }
        case Configuration.UI_MODE_NIGHT_YES:{
            setDayNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            // Night mode is active, we're at night!
            break;
        }
        case Configuration.UI_MODE_NIGHT_UNDEFINED: {
            // We don't know what mode we're in, assume notnight
        }
    }
}
 
Example 3
Source File: MainActivity.java    From Markdown with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() != 0x1
            && item.getItemId() != 0x2) {
        setText(item.getItemId());
        return true;
    } else if (item.getItemId() == 0x1) {
        getResources().getConfiguration().uiMode |= Configuration.UI_MODE_NIGHT_YES;
        getResources().getConfiguration().uiMode &= ~Configuration.UI_MODE_NIGHT_NO;
        getResources().updateConfiguration(getResources().getConfiguration(), getResources().getDisplayMetrics());
        recreate();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}
 
Example 4
Source File: PostTypeBottomSheetFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_post_type_bottom_sheet, container, false);
    ButterKnife.bind(this, rootView);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
            && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
        rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
    }

    textTypeTextView.setOnClickListener(view -> {
        ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_TEXT);
        dismiss();
    });

    linkTypeTextView.setOnClickListener(view -> {
        ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_LINK);
        dismiss();
    });

    imageTypeTextView.setOnClickListener(view -> {
        ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_IMAGE);
        dismiss();
    });

    videoTypeTextView.setOnClickListener(view -> {
        ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_VIDEO);
        dismiss();
    });

    return rootView;
}
 
Example 5
Source File: FragmentTracklist.java    From GPSLogger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.fragment_tracklist, container, false);

    TVTracklistEmpty    = view.findViewById(R.id.id_textView_TracklistEmpty);
    recyclerView        = view.findViewById(R.id.my_recycler_view);

    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.getItemAnimator().setChangeDuration(0);
    adapter = new TrackAdapter(data);

    switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
        case Configuration.UI_MODE_NIGHT_NO:
            // Night mode is not active, we're in day time
            adapter.isLightTheme = true;
            break;
        case Configuration.UI_MODE_NIGHT_YES:
            // Night mode is active, we're at night!
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
            // We don't know what mode we're in, assume notnight
            adapter.isLightTheme = false;
            break;
    }

    recyclerView.setAdapter(adapter);

    return view;
}
 
Example 6
Source File: AuthActivity.java    From Aegis with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void setPreferredTheme(Theme theme) {
    if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
        // set the theme based on the system theme
        int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
        switch (currentNightMode) {
            case Configuration.UI_MODE_NIGHT_NO:
                theme = Theme.LIGHT;
                break;
            case Configuration.UI_MODE_NIGHT_YES:
                theme = theme == Theme.SYSTEM_AMOLED ? Theme.AMOLED : Theme.DARK;
                break;
        }
    }

    switch (theme) {
        case LIGHT:
            setTheme(R.style.AppTheme_Light_NoActionBar);
            break;
        case DARK:
            setTheme(R.style.AppTheme_Dark_NoActionBar);
            break;
        case AMOLED:
            setTheme(R.style.AppTheme_TrueBlack_NoActionBar);
            break;
    }
}
 
Example 7
Source File: SearchUserAndSubredditSortTypeBottomSheetFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_search_user_and_subreddit_sort_type_bottom_sheet, container, false);
    ButterKnife.bind(this, rootView);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
            && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
        rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
    }

    int position = getArguments() != null ? getArguments().getInt(EXTRA_FRAGMENT_POSITION) : -1;
    if(position < 0) {
        dismiss();
        return rootView;
    }

    relevanceTypeTextView.setOnClickListener(view -> {
        ((SortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(new SortType(SortType.Type.RELEVANCE), position);
        dismiss();
    });

    activityTypeTextView.setOnClickListener(view -> {
        ((SortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(new SortType(SortType.Type.ACTIVITY), position);
        dismiss();
    });

    return rootView;
}
 
Example 8
Source File: AegisActivity.java    From Aegis with GNU General Public License v3.0 5 votes vote down vote up
protected void setPreferredTheme(Theme theme) {
    if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
        // set the theme based on the system theme
        int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
        switch (currentNightMode) {
            case Configuration.UI_MODE_NIGHT_NO:
                theme = Theme.LIGHT;
                break;
            case Configuration.UI_MODE_NIGHT_YES:
                theme = theme == Theme.SYSTEM_AMOLED ? Theme.AMOLED : Theme.DARK;
                break;
        }
    }

    _currentTheme = theme;

    switch (theme) {
        case LIGHT:
            setTheme(R.style.AppTheme);
            break;
        case DARK:
            setTheme(R.style.AppTheme_Dark);
            break;
        case AMOLED:
            setTheme(R.style.AppTheme_TrueBlack);
            break;
    }
}
 
Example 9
Source File: SystemBarColorPredictor.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
private static int getExpectedColorScheme(Context context, TrustedWebActivityIntentBuilder builder) {
    Intent intent = builder.buildCustomTabsIntent().intent;
    Bundle extras = intent.getExtras();
    Integer scheme = extras == null ? null :
            (Integer) extras.get(CustomTabsIntent.EXTRA_COLOR_SCHEME);
    if (scheme != null && scheme != CustomTabsIntent.COLOR_SCHEME_SYSTEM) {
        return scheme;
    }
    boolean systemIsInDarkMode = (context.getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
    return systemIsInDarkMode ? CustomTabsIntent.COLOR_SCHEME_DARK :
            CustomTabsIntent.COLOR_SCHEME_LIGHT;
}
 
Example 10
Source File: CommonUtils.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
public static boolean isNightModeOn(@NonNull Context context, boolean fallback) {
    int mode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (mode) {
        case Configuration.UI_MODE_NIGHT_YES:
            return true;
        case Configuration.UI_MODE_NIGHT_NO:
            return false;
        default:
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
            return fallback;
    }
}
 
Example 11
Source File: UiUtils.java    From STUer-client with MIT License 5 votes vote down vote up
public static boolean isNightMode(AppCompatActivity activity) {
    int uiMode = activity.getResources().getConfiguration().uiMode;
    int dayNightUiMode = uiMode & Configuration.UI_MODE_NIGHT_MASK;
    if (SPUtils.getBoolean(MainActivity.CURRENT_NIGHT_MODE) && dayNightUiMode != Configuration.UI_MODE_NIGHT_YES) {
        activity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        activity.recreate();
        return true;
    }
    return false;
}
 
Example 12
Source File: ThemeHelper.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private static boolean isDark(final SharedPreferences sharedPreferences, final Resources resources) {
	final String setting = sharedPreferences.getString(SettingsActivity.THEME, resources.getString(R.string.theme));
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && "automatic".equals(setting)) {
		return (resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
	} else {
		return "dark".equals(setting);
	}
}
 
Example 13
Source File: ActivityBase.java    From ghwatch with Apache License 2.0 4 votes vote down vote up
/**
 * Init navigation drawer for activity. Layout xml file must be appropriate!
 *
 * @param selectedItem in drawer main menu which represents this activity, see <code>NAV_DRAWER_ITEM_xx</code> constants.
 */
protected void initNavigationDrawer(final int selectedItem) {
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  // initialization of navigation drawer
  mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
  if (mDrawerLayout != null) {

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.string.drawer_open, R.string.drawer_close) {

      /** Called when a drawer has settled in a completely closed state. */
      public void onDrawerClosed(View view) {
        super.onDrawerClosed(view);
        invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
      }

      /** Called when a drawer has settled in a completely open state. */
      public void onDrawerOpened(View drawerView) {
        super.onDrawerOpened(drawerView);
        invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
      }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();


    mDrawerNavigationView = (NavigationView) findViewById(R.id.navigation_drawer_view);
    mDrawerNavigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(MenuItem item) {
                onDrawerMenuItemSelected(item);
                navigationDrawerClose();
                return true;
              }
            });

    if ((getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
      ColorStateList ndcl = ColorStateList.valueOf(getResources().getColor(R.color.light_grey));
      mDrawerNavigationView.setItemTextColor(ndcl);
      mDrawerNavigationView.setItemIconTintList(ndcl);
    }
    navDrawerMenuSelectedItem = selectedItem;
    if (getSupportActionBar() != null) {
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setHomeButtonEnabled(true);
    }
    navigationDrawerShowUserInfo();
  }
}
 
Example 14
Source File: NightModeHelper.java    From shortyz with GNU General Public License v3.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public boolean isNightMode(){
    return getUiNightMode() == Configuration.UI_MODE_NIGHT_YES;
}
 
Example 15
Source File: DisplayUtils.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean isDarkMode(Context context) {
    return (context.getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
 
Example 16
Source File: LottieCompositionFactory.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
/**
 * It is important to include day/night in the cache key so that if it changes, the cache won't return an animation from the wrong bucket.
 */
private static boolean isNightMode(Context context) {
  int nightModeMasked = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
  return nightModeMasked == Configuration.UI_MODE_NIGHT_YES;
}
 
Example 17
Source File: ThemeManager.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean isSystemNight(Context context) {
    int currentNightMode = context.getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
}
 
Example 18
Source File: Theme.java    From SAI with GNU General Public License v3.0 4 votes vote down vote up
private boolean shouldUseDarkThemeForAutoMode() {
    return (mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
 
Example 19
Source File: NotesApplication.java    From nextcloud-notes with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isDarkThemeActive(Context context) {
    int uiMode = context.getResources().getConfiguration().uiMode;
    return (uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
 
Example 20
Source File: MiscUtils.java    From BottomBar with Apache License 2.0 2 votes vote down vote up
/**
 * Determine if the current UI Mode is Night Mode.
 *
 * @param context Context to get the configuration.
 * @return true if the night mode is enabled, otherwise false.
 */
protected static boolean isNightMode(@NonNull Context context) {
    int currentNightMode = context.getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
}