Search in sources :

Example 1 with AfDensity

use of com.andframe.util.android.AfDensity in project AndFrameWorks by scwang90.

the class Injecter method inject.

private static void inject(Field field, Object handler, Context context) {
    if (field.isAnnotationPresent(Inject.class)) {
        try {
            Object value = null;
            Class<?> clazz = field.getType();
            if (clazz.equals(Resources.class)) {
                value = context.getResources();
            } else if (clazz.equals(Random.class)) {
                value = new Random();
            } else if (clazz.equals(AfDialogBuilder.class)) {
                value = new AfDialogBuilder(context);
            } else if (clazz.equals(AfDensity.class)) {
                value = new AfDensity();
            } else if (clazz.equals(AfReflecter.class)) {
                value = new AfReflecter();
            // } else if (clazz.equals(AfDesHelper.class)) {
            // value = new AfDesHelper();
            // } else if (clazz.equals(AfDeviceInfo.class)) {
            // value = new AfDeviceInfo(context);
            // } else if (clazz.equals(AfDistance.class)) {
            // value = new AfDistance();
            // } else if (clazz.equals(AfGifHelper.class)) {
            // value = new AfGifHelper();
            // } else if (clazz.equals(AfImageHelper.class)) {
            // value = new AfImageHelper();
            } else if (clazz.equals(AfSharedPreference.class)) {
                value = new AfSharedPreference(context, field.getAnnotation(Inject.class).value());
            } else if (clazz.equals(Cacher.class)) {
                value = new AfDurableCacher(field.getAnnotation(Inject.class).value());
            } else if (clazz.equals(AfDurableCacher.class)) {
                value = new AfDurableCacher(field.getAnnotation(Inject.class).value());
            } else if (clazz.equals(AfPrivateCacher.class)) {
                value = new AfPrivateCacher(field.getAnnotation(Inject.class).value());
            } else if (clazz.equals(AfJsonCache.class)) {
                value = new AfJsonCache(context, field.getAnnotation(Inject.class).value());
            // } else if (clazz.equals(AfImageCaches.class)) {
            // value = AfImageCaches.getInstance();
            } else if (AfApp.class.isAssignableFrom(clazz)) {
                value = AfApp.get();
            } else if (AfAppSettings.class.isAssignableFrom(clazz)) {
                value = AfApp.get().newAppSetting();
            // } else if (AfEntityDao.class.isAssignableFrom(clazz)) {
            // value = clazz.getConstructor(Context.class).newInstance(context);
            }
            if (value != null) {
                field.setAccessible(true);
                field.set(handler, value);
            }
        } catch (Throwable e) {
            AfExceptionHandler.handle(e, TAG(handler, "doInject.Inject") + field.getName());
        }
    }
}
Also used : Inject(com.andframe.annotation.inject.Inject) AfPrivateCacher(com.andframe.caches.AfPrivateCacher) AfSharedPreference(com.andframe.caches.AfSharedPreference) AfDialogBuilder(com.andframe.feature.AfDialogBuilder) AfAppSettings(com.andframe.application.AfAppSettings) Random(java.util.Random) AfDurableCacher(com.andframe.caches.AfDurableCacher) AfDensity(com.andframe.util.android.AfDensity) AfReflecter(com.andframe.util.java.AfReflecter) AfJsonCache(com.andframe.caches.AfJsonCache)

Aggregations

Inject (com.andframe.annotation.inject.Inject)1 AfAppSettings (com.andframe.application.AfAppSettings)1 AfDurableCacher (com.andframe.caches.AfDurableCacher)1 AfJsonCache (com.andframe.caches.AfJsonCache)1 AfPrivateCacher (com.andframe.caches.AfPrivateCacher)1 AfSharedPreference (com.andframe.caches.AfSharedPreference)1 AfDialogBuilder (com.andframe.feature.AfDialogBuilder)1 AfDensity (com.andframe.util.android.AfDensity)1 AfReflecter (com.andframe.util.java.AfReflecter)1 Random (java.util.Random)1