当前位置: 首页>>代码示例>>Java>>正文


Java Configuration.UI_MODE_NIGHT_YES属性代码示例

本文整理汇总了Java中android.content.res.Configuration.UI_MODE_NIGHT_YES属性的典型用法代码示例。如果您正苦于以下问题:Java Configuration.UI_MODE_NIGHT_YES属性的具体用法?Java Configuration.UI_MODE_NIGHT_YES怎么用?Java Configuration.UI_MODE_NIGHT_YES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.content.res.Configuration的用法示例。


在下文中一共展示了Configuration.UI_MODE_NIGHT_YES属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTheme

/**
 * Called in onCreate() to check the UI Mode (day or night)
 * and set the theme colors accordingly.
 *
 * @param context {@link NavigationView} where the theme will be set
 * @param attrs   holding custom styles if any are set
 */
static void setTheme(Context context, AttributeSet attrs) {
  int uiMode = context.getResources().getConfiguration().uiMode
    & Configuration.UI_MODE_NIGHT_MASK;
  boolean darkThemeEnabled = uiMode == Configuration.UI_MODE_NIGHT_YES;
  updatePreferencesDarkEnabled(context, darkThemeEnabled);

  // Check for custom theme from NavigationLauncher
  if (shouldSetThemeFromPreferences(context)) {
    int prefLightTheme = retrieveThemeResIdFromPreferences(context, NavigationConstants.NAVIGATION_VIEW_LIGHT_THEME);
    int prefDarkTheme = retrieveThemeResIdFromPreferences(context, NavigationConstants.NAVIGATION_VIEW_DARK_THEME);
    prefLightTheme = prefLightTheme == 0 ?  R.style.NavigationViewLight : prefLightTheme;
    prefDarkTheme = prefLightTheme == 0 ?  R.style.NavigationViewDark : prefDarkTheme;
    context.setTheme(darkThemeEnabled ? prefDarkTheme : prefLightTheme);
    return;
  }

  TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.NavigationView);
  int lightTheme = styledAttributes.getResourceId(R.styleable.NavigationView_navigationLightTheme,
    R.style.NavigationViewLight);
  int darkTheme = styledAttributes.getResourceId(R.styleable.NavigationView_navigationDarkTheme,
    R.style.NavigationViewDark);
  styledAttributes.recycle();

  context.setTheme(darkThemeEnabled ? darkTheme : lightTheme);
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:32,代码来源:ThemeSwitcher.java

示例2: simulateDayNight

void simulateDayNight(int currentSetting) {
    final int DAY = 0;
    final int NIGHT = 1;
    final int FOLLOW_SYSTEM = 3;

    int currentNightMode = getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    if (currentSetting == DAY && currentNightMode != Configuration.UI_MODE_NIGHT_NO) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_NO);
    } else if (currentSetting == NIGHT && currentNightMode != Configuration.UI_MODE_NIGHT_YES) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_YES);
    } else if (currentSetting == FOLLOW_SYSTEM) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
    }
}
 
开发者ID:doljko,项目名称:youth-health,代码行数:18,代码来源:AboutUsActivity.java

示例3: convertDoubanContent

private String convertDoubanContent() {

        if (doubanMomentStory.getContent() == null) {
            return null;
        }
        String css;
        if ((context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
                == Configuration.UI_MODE_NIGHT_YES) {
            css = "<link rel=\"stylesheet\" href=\"file:///android_asset/douban_dark.css\" type=\"text/css\">";
        } else {
            css = "<link rel=\"stylesheet\" href=\"file:///android_asset/douban_light.css\" type=\"text/css\">";
        }
        String content = doubanMomentStory.getContent();
        ArrayList<DoubanMomentNews.posts.thumbs> imageList = doubanMomentStory.getPhotos();
        for (int i = 0; i < imageList.size(); i++) {
            String old = "<img id=\"" + imageList.get(i).getTag_name() + "\" />";
            String newStr = "<img id=\"" + imageList.get(i).getTag_name() + "\" "
                    + "src=\"" + imageList.get(i).getMedium().getUrl() + "\"/>";
            content = content.replace(old, newStr);
        }
        StringBuilder builder = new StringBuilder();
        builder.append( "<!DOCTYPE html>\n");
        builder.append("<html lang=\"ZH-CN\" xmlns=\"http://www.w3.org/1999/xhtml\">\n");
        builder.append("<head>\n<meta charset=\"utf-8\" />\n");
        builder.append(css);
        builder.append("\n</head>\n<body>\n");
        builder.append("<div class=\"container bs-docs-container\">\n");
        builder.append("<div class=\"post-container\">\n");
        builder.append(content);
        builder.append("</div>\n</div>\n</body>\n</html>");

        return builder.toString();
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:DetailPresenter.java

示例4: convertZhihuContent

private String convertZhihuContent(String preResult) {

        preResult = preResult.replace("<div class=\"img-place-holder\">", "");
        preResult = preResult.replace("<div class=\"headline\">", "");

        // 在api中,css的地址是以一个数组的形式给出,这里需要设置
        // in fact,in api,css addresses are given as an array
        // api中还有js的部分,这里不再解析js
        // javascript is included,but here I don't use it
        // 不再选择加载网络css,而是加载本地assets文件夹中的css
        // use the css file from local assets folder,not from network
        String css = "<link rel=\"stylesheet\" href=\"file:///android_asset/zhihu_daily.css\" type=\"text/css\">";


        // 根据主题的不同确定不同的加载内容
        // load content judging by different theme
        String theme = "<body className=\"\" onload=\"onLoaded()\">";
        if ((context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
                == Configuration.UI_MODE_NIGHT_YES){
            theme = "<body className=\"\" onload=\"onLoaded()\" class=\"night\">";
        }

        return new StringBuilder()
                .append("<!DOCTYPE html>\n")
                .append("<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">\n")
                .append("<head>\n")
                .append("\t<meta charset=\"utf-8\" />")
                .append(css)
                .append("\n</head>\n")
                .append(theme)
                .append(preResult)
                .append("</body></html>").toString();
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:DetailPresenter.java

示例5: convertGuokrContent

private void convertGuokrContent(String content) {
    // 简单粗暴的去掉下载的div部分
    this.guokrStory = content.replace("<div class=\"down\" id=\"down-footer\">\n" +
            "        <img src=\"http://static.guokr.com/apps/handpick/images/c324536d.jingxuan-logo.png\" class=\"jingxuan-img\">\n" +
            "        <p class=\"jingxuan-txt\">\n" +
            "            <span class=\"jingxuan-title\">果壳精选</span>\n" +
            "            <span class=\"jingxuan-label\">早晚给你好看</span>\n" +
            "        </p>\n" +
            "        <a href=\"\" class=\"app-down\" id=\"app-down-footer\">下载</a>\n" +
            "    </div>\n" +
            "\n" +
            "    <div class=\"down-pc\" id=\"down-pc\">\n" +
            "        <img src=\"http://static.guokr.com/apps/handpick/images/c324536d.jingxuan-logo.png\" class=\"jingxuan-img\">\n" +
            "        <p class=\"jingxuan-txt\">\n" +
            "            <span class=\"jingxuan-title\">果壳精选</span>\n" +
            "            <span class=\"jingxuan-label\">早晚给你好看</span>\n" +
            "        </p>\n" +
            "        <a href=\"http://www.guokr.com/mobile/\" class=\"app-down\">下载</a>\n" +
            "    </div>", "");

    // 替换css文件为本地文件
    guokrStory = guokrStory.replace("<link rel=\"stylesheet\" href=\"http://static.guokr.com/apps/handpick/styles/d48b771f.article.css\" />",
            "<link rel=\"stylesheet\" href=\"file:///android_asset/guokr.article.css\" />");

    // 替换js文件为本地文件
    guokrStory = guokrStory.replace("<script src=\"http://static.guokr.com/apps/handpick/scripts/9c661fc7.base.js\"></script>",
            "<script src=\"file:///android_asset/guokr.base.js\"></script>");
    if ((context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
            == Configuration.UI_MODE_NIGHT_YES){
        guokrStory = guokrStory.replace("<div class=\"article\" id=\"contentMain\">",
                "<div class=\"article \" id=\"contentMain\" style=\"background-color:#212b30; color:#878787\">");
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:DetailPresenter.java

示例6: updateNightMode

public static Resources updateNightMode(Resources resource, boolean on) {
    DisplayMetrics dm = resource.getDisplayMetrics();
    Configuration config = resource.getConfiguration();
    final int uiModeNightMaskOrigin = config.uiMode &= ~Configuration.UI_MODE_TYPE_MASK;
    final int uiModeNightMaskNew = on ? Configuration.UI_MODE_NIGHT_YES : Configuration.UI_MODE_NIGHT_NO;
    if (uiModeNightMaskOrigin != uiModeNightMaskNew) {
        config.uiMode &= ~Configuration.UI_MODE_NIGHT_MASK;
        config.uiMode |= uiModeNightMaskNew;
        resource.updateConfiguration(config, dm);
    }
    return resource;
}
 
开发者ID:Pingsh,项目名称:Mix,代码行数:12,代码来源:ThemeUtils.java

示例7: isNightMode

/**
 * 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(Context context) {
    int currentNightMode = context.getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:11,代码来源:MiscUtils.java


注:本文中的android.content.res.Configuration.UI_MODE_NIGHT_YES属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。