// Path: nightowllib/src/main/java/com/asha/nightowllib/observer/impls/AdditionThemeObserver.java
// public class AdditionThemeObserver implements IOwlObserverWithId {
// 
//     private static final String TAG = "AdditionThemeObserver";
//     private int mThemeDay;
//     private int mThemeNight;
//     public AdditionThemeObserver(int themeDay, int themeNight) {
//         mThemeDay = themeDay;
//         mThemeNight = themeNight;
//     }
// 
//     @Override
//     public int getObserverId() {
//         return AdditionThemeObserver.this.hashCode();
//     }
// 
//     @Override
//     public void onSkinChange(int mode, Activity activity) {
//         int theme = mode == 0 ? mThemeDay : mThemeNight;
//         activity.getTheme().applyStyle(theme, true);
// 
//         //Log.e(TAG, String.format("%s %d", activity.getTheme(), theme));
//     }
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/observer/impls/NavBarObserver.java
// public class NavBarObserver implements IOwlObserverWithId {
//     int mNavigationBarColor;
//     int mNavigationBarColorNight;
//     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
//     public NavBarObserver(Activity activity, TypedArray a, int attr) {
//         Window window = activity.getWindow();
//         mNavigationBarColor = window.getNavigationBarColor();
//         mNavigationBarColorNight = a.getColor(attr,mNavigationBarColor);
//     }
// 
//     @Override
//     public int getObserverId() {
//         return NavBarObserver.this.hashCode();
//     }
// 
//     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
//     @Override
//     public void onSkinChange(int mode, Activity activity) {
//         activity.getWindow().setNavigationBarColor( mode == 0 ? mNavigationBarColor : mNavigationBarColorNight);
//     }
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/observer/impls/StatusBarObserver.java
// public class StatusBarObserver implements IOwlObserverWithId {
//     int mStatusBarColor;
//     int mStatusBarColorNight;
//     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
//     public StatusBarObserver(Activity activity, TypedArray a, int attr) {
//         Window window = activity.getWindow();
//         mStatusBarColor = window.getStatusBarColor();
//         mStatusBarColorNight = a.getColor(attr,mStatusBarColorNight);
//     }
// 
//     @Override
//     public int getObserverId() {
//         return StatusBarObserver.this.hashCode();
//     }
// 
//     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
//     @Override
//     public void onSkinChange(int mode, Activity activity) {
//         activity.getWindow().setStatusBarColor( mode == 0 ? mStatusBarColor : mStatusBarColorNight);
//     }
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/NightOwlUtil.java
// public static boolean checkBeforeLollipop(){
//     if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) return true;
//     else return false;
// }


import android.app.Activity;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.SparseArray;
import com.asha.nightowllib.R;
import com.asha.nightowllib.observer.impls.AdditionThemeObserver;
import com.asha.nightowllib.observer.impls.NavBarObserver;
import com.asha.nightowllib.observer.impls.StatusBarObserver;
import static com.asha.nightowllib.NightOwlUtil.checkBeforeLollipop;
package com.asha.nightowllib.observer;




/**
 * Created by hzqiujiadi on 15/11/9.
 * hzqiujiadi ashqalcn@gmail.com
 */
public class OwlViewContext {
    private int mLastMode = -1;
    private SparseArray<IOwlObserverWithId> observers;
    public OwlViewContext() {
        observers = new SparseArray<>();
    }

    public void registerObserver( IOwlObserverWithId owlObserver ){
        observers.put(owlObserver.getObserverId(), owlObserver);
    }

    public void unregisterObserver( IOwlObserverWithId owlObserver ){
        observers.delete(owlObserver.getObserverId());
    }

    public void notifyObserver(int mode, Activity activity){
        if ( mode == mLastMode ) return;
        mLastMode = mode;
        int size = observers.size();
        for (int i = 0; i < size; i++) {
            IOwlObserverWithId owlObserver = observers.valueAt(i);
            owlObserver.onSkinChange(mode, activity);
        }
    }

    public void setupWithCurrentActivity(Activity activity){
        Resources.Theme theme = activity.getTheme();
        TypedArray a = theme.obtainStyledAttributes(R.styleable.NightOwl_Theme);
        if (a != null) {
            if ( !checkBeforeLollipop() ){
                if ( a.hasValue(R.styleable.NightOwl_Theme_night_navigationBarColor) )
// Path: nightowllib/src/main/java/com/asha/nightowllib/observer/impls/AdditionThemeObserver.java
// public class AdditionThemeObserver implements IOwlObserverWithId {
// 
//     private static final String TAG = "AdditionThemeObserver";
//     private int mThemeDay;
//     private int mThemeNight;
//     public AdditionThemeObserver(int themeDay, int themeNight) {
//         mThemeDay = themeDay;
//         mThemeNight = themeNight;
//     }
// 
//     @Override
//     public int getObserverId() {
//         return AdditionThemeObserver.this.hashCode();
//     }
// 
//     @Override
//     public void onSkinChange(int mode, Activity activity) {
//         int theme = mode == 0 ? mThemeDay : mThemeNight;
//         activity.getTheme().applyStyle(theme, true);
// 
//         //Log.e(TAG, String.format("%s %d", activity.getTheme(), theme));
//     }
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/observer/impls/NavBarObserver.java
// public class NavBarObserver implements IOwlObserverWithId {
//     int mNavigationBarColor;
//     int mNavigationBarColorNight;
//     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
//     public NavBarObserver(Activity activity, TypedArray a, int attr) {
//         Window window = activity.getWindow();
//         mNavigationBarColor = window.getNavigationBarColor();
//         mNavigationBarColorNight = a.getColor(attr,mNavigationBarColor);
//     }
// 
//     @Override
//     public int getObserverId() {
//         return NavBarObserver.this.hashCode();
//     }
// 
//     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
//     @Override
//     public void onSkinChange(int mode, Activity activity) {
//         activity.getWindow().setNavigationBarColor( mode == 0 ? mNavigationBarColor : mNavigationBarColorNight);
//     }
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/observer/impls/StatusBarObserver.java
// public class StatusBarObserver implements IOwlObserverWithId {
//     int mStatusBarColor;
//     int mStatusBarColorNight;
//     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
//     public StatusBarObserver(Activity activity, TypedArray a, int attr) {
//         Window window = activity.getWindow();
//         mStatusBarColor = window.getStatusBarColor();
//         mStatusBarColorNight = a.getColor(attr,mStatusBarColorNight);
//     }
// 
//     @Override
//     public int getObserverId() {
//         return StatusBarObserver.this.hashCode();
//     }
// 
//     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
//     @Override
//     public void onSkinChange(int mode, Activity activity) {
//         activity.getWindow().setStatusBarColor( mode == 0 ? mStatusBarColor : mStatusBarColorNight);
//     }
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/NightOwlUtil.java
// public static boolean checkBeforeLollipop(){
//     if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) return true;
//     else return false;
// }


// Path: nightowllib/src/main/java/com/asha/nightowllib/observer/OwlViewContext.java
import android.app.Activity;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.SparseArray;
import com.asha.nightowllib.R;
import com.asha.nightowllib.observer.impls.AdditionThemeObserver;
import com.asha.nightowllib.observer.impls.NavBarObserver;
import com.asha.nightowllib.observer.impls.StatusBarObserver;
import static com.asha.nightowllib.NightOwlUtil.checkBeforeLollipop;

package com.asha.nightowllib.observer;




/**
 * Created by hzqiujiadi on 15/11/9.
 * hzqiujiadi ashqalcn@gmail.com
 */
public class OwlViewContext {
    private int mLastMode = -1;
    private SparseArray<IOwlObserverWithId> observers;
    public OwlViewContext() {
        observers = new SparseArray<>();
    }

    public void registerObserver( IOwlObserverWithId owlObserver ){
        observers.put(owlObserver.getObserverId(), owlObserver);
    }

    public void unregisterObserver( IOwlObserverWithId owlObserver ){
        observers.delete(owlObserver.getObserverId());
    }

    public void notifyObserver(int mode, Activity activity){
        if ( mode == mLastMode ) return;
        mLastMode = mode;
        int size = observers.size();
        for (int i = 0; i < size; i++) {
            IOwlObserverWithId owlObserver = observers.valueAt(i);
            owlObserver.onSkinChange(mode, activity);
        }
    }

    public void setupWithCurrentActivity(Activity activity){
        Resources.Theme theme = activity.getTheme();
        TypedArray a = theme.obtainStyledAttributes(R.styleable.NightOwl_Theme);
        if (a != null) {
            if ( !checkBeforeLollipop() ){
                if ( a.hasValue(R.styleable.NightOwl_Theme_night_navigationBarColor) )
                    registerObserver(new NavBarObserver(activity, a, R.styleable.NightOwl_Theme_night_navigationBarColor));