android.content.res.Configuration#UI_MODE_NIGHT_YES源码实例Demo

下面列出了android.content.res.Configuration#UI_MODE_NIGHT_YES 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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();
}
 
源代码2 项目: Markdown   文件: MainActivity.java
@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);
    }
}
 
源代码3 项目: SkinSprite   文件: MainActivity.java
@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
        }
    }
}
 
源代码4 项目: GPSLogger   文件: FragmentTracklist.java
@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;
}
 
源代码5 项目: Aegis   文件: AuthActivity.java
@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;
    }
}
 
源代码6 项目: Conversations   文件: ThemeHelper.java
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);
	}
}
 
源代码7 项目: STUer-client   文件: UiUtils.java
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;
}
 
源代码8 项目: CommonUtils   文件: CommonUtils.java
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;
    }
}
 
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;
}
 
@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;
}
 
源代码11 项目: Aegis   文件: AegisActivity.java
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;
    }
}
 
@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;
}
 
源代码13 项目: GeometricWeather   文件: DisplayUtils.java
public static boolean isDarkMode(Context context) {
    return (context.getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
 
源代码14 项目: lottie-android   文件: LottieCompositionFactory.java
/**
 * 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;
}
 
源代码15 项目: shortyz   文件: NightModeHelper.java
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public boolean isNightMode(){
    return getUiNightMode() == Configuration.UI_MODE_NIGHT_YES;
}
 
源代码16 项目: ghwatch   文件: ActivityBase.java
/**
 * 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();
  }
}
 
源代码17 项目: Mysplash   文件: ThemeManager.java
public static boolean isSystemNight(Context context) {
    int currentNightMode = context.getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
}
 
源代码18 项目: SAI   文件: Theme.java
private boolean shouldUseDarkThemeForAutoMode() {
    return (mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
 
源代码19 项目: nextcloud-notes   文件: NotesApplication.java
public static boolean isDarkThemeActive(Context context) {
    int uiMode = context.getResources().getConfiguration().uiMode;
    return (uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
 
源代码20 项目: BottomBar   文件: MiscUtils.java
/**
 * 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;
}