com.xiemarc.marcreading.manager.ThemeManager.java Source code

Java tutorial

Introduction

Here is the source code for com.xiemarc.marcreading.manager.ThemeManager.java

Source

/**
 * Copyright 2016 JustWayward Team
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xiemarc.marcreading.manager;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.content.ContextCompat;
import android.view.View;

import com.xiemarc.marcreading.R;
import com.xiemarc.marcreading.bean.support.ReadTheme;
import com.xiemarc.marcreading.utils.ScreenUtils;
import com.xiemarc.marcreading.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * ?
 */
public class ThemeManager {

    public static final int NORMAL = 0;
    public static final int YELLOW = 1;
    public static final int GREEN = 2;
    public static final int LEATHER = 3;
    public static final int GRAY = 4;
    public static final int NIGHT = 5;

    public static void setReaderTheme(int theme, View view) {
        switch (theme) {
        case NORMAL:
            view.setBackgroundResource(R.drawable.theme_white_bg);
            break;
        case YELLOW:
            view.setBackgroundResource(R.drawable.theme_yellow_bg);
            break;
        case GREEN:
            view.setBackgroundResource(R.drawable.theme_green_bg);
            break;
        case LEATHER:
            view.setBackgroundResource(R.drawable.theme_leather_bg);
            break;
        case GRAY:
            view.setBackgroundResource(R.drawable.theme_gray_bg);
            break;
        case NIGHT:
            view.setBackgroundResource(R.drawable.theme_night_bg);
            break;
        default:
            break;
        }
    }

    public static Bitmap getThemeDrawable(int theme) {
        Bitmap bmp = Bitmap.createBitmap(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight(),
                Bitmap.Config.ARGB_8888);
        switch (theme) {
        case NORMAL:
            bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_white));
            break;
        case YELLOW:
            bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_yellow));
            break;
        case GREEN:
            bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_green));
            break;
        case LEATHER:
            bmp = BitmapFactory.decodeResource(UIUtils.getContext().getResources(), R.drawable.theme_leather_bg);
            break;
        case GRAY:
            bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_gray));
            break;
        case NIGHT:
            bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_night));
            break;
        default:
            break;
        }
        return bmp;
    }

    public static List<ReadTheme> getReaderThemeData(int curTheme) {
        int[] themes = { NORMAL, YELLOW, GREEN, LEATHER, GRAY, NIGHT };
        List<ReadTheme> list = new ArrayList<>();
        ReadTheme theme;
        for (int i = 0; i < themes.length; i++) {
            theme = new ReadTheme();
            theme.theme = themes[i];
            list.add(theme);
        }
        return list;
    }

}