package com.wingjay.jayandroid.skin;

import java.lang.reflect.Field;

import android.os.Bundle;
import android.view.LayoutInflater;
import com.wingjay.jayandroid.BaseActivity;
import com.wingjay.wingjay_skin_loader.OkSkin;
import com.wingjay.wingjay_skin_loader.SkinInflaterFactory;
import com.wingjay.wingjay_skin_loader.listener.OnSkinUpdateListener;

/**
 * BaseSkinActivity
 *
 * @author wingjay
 * @date 2017/08/04
 */
public class BaseSkinActivity extends BaseActivity implements OnSkinUpdateListener {

    private SkinInflaterFactory skinInflaterFactory;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        skinInflaterFactory = new SkinInflaterFactory(this);
        LayoutInflater inflater = LayoutInflater.from(this); // shouldn't use LayoutInflater.from(applicationContext)
        try {
            Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
            field.setAccessible(true);
            field.setBoolean(inflater, false);
            inflater.setFactory(skinInflaterFactory);
        } catch (Exception e) {
            e.printStackTrace();
        }
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        OkSkin.getInstance().listenSkinUpdate(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkSkin.getInstance().removeSkinUpdateListener(this);
        skinInflaterFactory.clean();
    }

    @Override
    public void onSkinUpdate() {
        skinInflaterFactory.updateSkin();
    }
}

@@ -126,16 +126,47 @@
 flater;%0A
+import android.view.ViewGroup;%0A
 import c
@@ -201,16 +201,16 @@
 tivity;%0A
-
 import c
@@ -656,24 +656,515 @@
 nceState) %7B%0A
+        /**%0A         * this setFactory must before super.onCreate%0A         * 1. super.onCreate will put Factory1 inside -%3E mFactorySet=true -%3E deny more Factory1%0A         * 2. super.onCreate will put Factory2 inside -%3E even you put a Factory1 inside,%0A         * the Factory2 will execute inflate Before your Factory1.%0A         *%0A         * refer to %7B@link AppCompatDelegateImplV9#installViewFactory()%7D%0A         * refer to %7B@link LayoutInflater#createViewFromTag(int, ViewGroup)%7D%0A         */%0A
         skin
@@ -1625,24 +1625,24 @@
 ackTrace();%0A
-
         %7D%0A  
@@ -1639,16 +1639,17 @@
       %7D%0A
+%0A
         

add note for LayoutInflater setFactory function timing