Android Open Source - probe View Class Util






From Project

Back to project page probe.

License

The source code is released under:

Apache License

If you think the Android project probe listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 Lucas Rocha// ww  w  . j  a va 2 s.com
 *
 * 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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 org.lucasr.probe;

import android.content.Context;
import android.view.View;

/**
 * Utility methods to find and load {@link View} classes. Used
 * by {@link ProbeViewFactory}.
 *
 * @see ProbeViewFactory
 */
class ViewClassUtil {
    private ViewClassUtil() {
    }

    static final String[] VIEW_CLASS_PREFIX_LIST = {
            "android.widget.",
            "android.view.",
            "android.webkit."
    };

    /**
     * Loads class for the given class name.
     */
    static Class<?> loadViewClass(Context context, String name)
            throws ClassNotFoundException {
        return context.getClassLoader().loadClass(name).asSubclass(View.class);
    }

    /*
     * Tries to load the view proxy class generated at build time for the
     * given class name.
     */
    static Class<?> findProxyViewClass(Context context, String name) {
        try {
            return loadViewClass(context, String.format("%s.probe.ProbeProxy$%s",
                    context.getPackageName(), name.replace('.', '_')));
        } catch (ClassNotFoundException e) {
            return null;
        }
    }

    /**
     * Tries to load class using a predefined list of class prefixes for
     * Android views.
     */
    static Class<?> findViewClass(Context context, String name)
            throws ClassNotFoundException {
        if (name.indexOf('.') >= 0) {
            return loadViewClass(context, name);
        }

        for (String prefix : VIEW_CLASS_PREFIX_LIST) {
            try {
                return loadViewClass(context, prefix + name);
            } catch (ClassNotFoundException e) {
                continue;
            }
        }

        throw new ClassNotFoundException("Couldn't load View class for " + name);
    }
}




Java Source Code List

org.lucasr.probe.DexProxyBuilder.java
org.lucasr.probe.Filter.java
org.lucasr.probe.Interceptor.java
org.lucasr.probe.ProbeViewFactory.java
org.lucasr.probe.Probe.java
org.lucasr.probe.ViewClassUtil.java
org.lucasr.probe.ViewProxyBuilder.java
org.lucasr.probe.ViewProxy.java
org.lucasr.probe.interceptors.LayoutBoundsInterceptor.java
org.lucasr.probe.interceptors.OvermeasureInterceptor.java
org.lucasr.probe.sample.MainActivity.java