Java Code Examples for android.view.View.getClass()

The following are Jave code examples for showing how to use getClass() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: SkinFramework   File: SkinUtils.java   Source Code and License Vote up 7 votes
/**
 * Tell if two layout view is from the same skin.
 *
 * @param currentView View from <code>ResourceManager.getView() </code> used currently.
 * @param newView     View from <code>ResourceManager.getView() </code> after change skin.
 * @return true if same layout, false otherwise.
 */
public static boolean isSameLayout(View currentView, View newView) {
    if (currentView == newView) {
        return true;
    }
    if (currentView == null || newView == null) {
        return false;
    }
    if (currentView.getClass() != newView.getClass()) {
        return false;
    }
    Object currentTag = currentView.getTag(LAYOUT_TAG_ID);
    Object newTag = newView.getTag(LAYOUT_TAG_ID);
    if (currentTag == newTag) {
        return true;
    }
    if (currentTag == null || newTag == null) {
        return false;
    }
    return currentTag.equals(newTag);
}
 
Example 2
Project: windowmanager   File: SDWindowManager.java   Source Code and License Vote up 7 votes
/**
 * 返回等于指定class的所有view
 *
 * @param clazz
 * @return
 */
public List<View> getView(Class clazz)
{
    if (clazz == null || mMapView.isEmpty())
    {
        return null;
    }

    List<View> list = new ArrayList<>();
    for (Map.Entry<View, Integer> item : mMapView.entrySet())
    {
        View view = item.getKey();
        if (view != null && view.getClass() == clazz)
        {
            list.add(view);
        }
    }
    return list;
}
 
Example 3
Project: windowmanager   File: SDWindowManager.java   Source Code and License Vote up 7 votes
/**
 * 返回等于指定class的第一个view
 *
 * @param clazz
 * @return
 */
public View getFirstView(Class clazz)
{
    if (clazz == null || mMapView.isEmpty())
    {
        return null;
    }

    for (Map.Entry<View, Integer> item : mMapView.entrySet())
    {
        View view = item.getKey();
        if (view != null && view.getClass() == clazz)
        {
            return view;
        }
    }
    return null;
}
 
Example 4
Project: cwac-crossport   File: CoordinatorLayout.java   Source Code and License Vote up 7 votes
LayoutParams getResolvedLayoutParams(View child) {
  final LayoutParams result = (LayoutParams) child.getLayoutParams();
  if (!result.mBehaviorResolved) {
    Class<?> childClass = child.getClass();
    DefaultBehavior defaultBehavior = null;
          while (childClass != null &&
                  (defaultBehavior = childClass.getAnnotation(DefaultBehavior.class)) == null) {
      childClass = childClass.getSuperclass();
    }
    if (defaultBehavior != null) {
      try {
                  result.setBehavior(
                          defaultBehavior.value().getDeclaredConstructor().newInstance());
      } catch (Exception e) {
                  Log.e(TAG, "Default behavior class " + defaultBehavior.value().getName() +
                          " could not be instantiated. Did you forget a default constructor?", e);
      }
    }
    result.mBehaviorResolved = true;
  }
  return result;
}
 
Example 5
Project: boohee_v5.6   File: CoordinatorLayout.java   Source Code and License Vote up 7 votes
LayoutParams getResolvedLayoutParams(View child) {
    LayoutParams result = (LayoutParams) child.getLayoutParams();
    if (!result.mBehaviorResolved) {
        DefaultBehavior defaultBehavior = null;
        for (Class<?> childClass = child.getClass(); childClass != null; childClass = childClass.getSuperclass()) {
            defaultBehavior = (DefaultBehavior) childClass.getAnnotation(DefaultBehavior.class);
            if (defaultBehavior != null) {
                break;
            }
        }
        if (defaultBehavior != null) {
            try {
                result.setBehavior((Behavior) defaultBehavior.value().newInstance());
            } catch (Exception e) {
                Log.e(TAG, "Default behavior class " + defaultBehavior.value().getName() + " could not be instantiated. Did you forget a default constructor?", e);
            }
        }
        result.mBehaviorResolved = true;
    }
    return result;
}
 
Example 6
Project: AndelaTrackChallenge   File: Easel.java   Source Code and License Vote up 7 votes
/**
 * Tint the edge effect when you reach the end of a scroll view. API 21+ only
 *
 * @param scrollableView the scrollable view, such as a {@link android.widget.ScrollView}
 * @param color          the color
 * @return true if it worked, false if it did not
 */
@TargetApi(21)
public static boolean tintEdgeEffect(@NonNull View scrollableView, @ColorInt int color) {
    //http://stackoverflow.com/questions/27104521/android-lollipop-scrollview-edge-effect-color
    boolean outcome = false;
    final String[] edgeGlows = {"mEdgeGlowTop", "mEdgeGlowBottom", "mEdgeGlowLeft", "mEdgeGlowRight"};
    for (String edgeGlow : edgeGlows) {
        Class<?> clazz = scrollableView.getClass();
        while (clazz != null) {
            try {
                final Field edgeGlowField = clazz.getDeclaredField(edgeGlow);
                edgeGlowField.setAccessible(true);
                final EdgeEffect edgeEffect = (EdgeEffect) edgeGlowField.get(scrollableView);
                edgeEffect.setColor(color);
                outcome = true;
                break;
            } catch (Exception e) {
                clazz = clazz.getSuperclass();
            }
        }
    }
    return outcome;
}
 
Example 7
Project: MusicX-music-player   File: ToolbarProcessor.java   Source Code and License Vote up 7 votes
public static void setSearchViewContentColor(View searchView, final @ColorInt int color) {
    if (searchView == null) return;
    final Class<?> cls = searchView.getClass();
    try {
        final Field mSearchSrcTextViewField = cls.getDeclaredField("mSearchSrcTextView");
        mSearchSrcTextViewField.setAccessible(true);
        final EditText mSearchSrcTextView = (EditText) mSearchSrcTextViewField.get(searchView);
        mSearchSrcTextView.setTextColor(color);
        mSearchSrcTextView.setHintTextColor(ATEUtil.adjustAlpha(color, 0.5f));
        TintHelper.setCursorTint(mSearchSrcTextView, color);

        Field field = cls.getDeclaredField("mSearchButton");
        tintImageView(searchView, field, color);
        field = cls.getDeclaredField("mGoButton");
        tintImageView(searchView, field, color);
        field = cls.getDeclaredField("mCloseButton");
        tintImageView(searchView, field, color);
        field = cls.getDeclaredField("mVoiceButton");
        tintImageView(searchView, field, color);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 8
Project: show-case-card-view   File: ViewUtils.java   Source Code and License Vote up 6 votes
@SuppressWarnings("unchecked")
public static <T extends View> T findViewWithType(ViewGroup viewGroup, Class<T> clazz) {
    for (int i = 0; i < viewGroup.getChildCount() - 1; i++) {
        View view = viewGroup.getChildAt(i);

        if (view.getClass() == clazz) {
            return (T) view;
        }
    }

    return null;
}
 
Example 9
Project: HtmlNative   File: StyleHandlerFactory.java   Source Code and License Vote up 6 votes
@Nullable
public static StyleHandler get(View view) {
    Class<? extends View> vClazz = view.getClass();
    StyleHandler styleHandler = sAttrHandlerCache.get(vClazz);
    if (styleHandler == null) {
        styleHandler = byClass(vClazz);
        if (styleHandler != null) {
            sAttrHandlerCache.put(vClazz, styleHandler);
        }
    }

    return styleHandler;

}
 
Example 10
Project: MusicX-music-player   File: SearchViewProcessor.java   Source Code and License Vote up 6 votes
@Override
public void process(@NonNull Context context, @Nullable String key, @Nullable View target, @Nullable Integer tintColor) {
    if (target == null)
        return;
    if (tintColor == null) {
        // TODO pass a toolbar here?
        final int toolbarColor = Config.toolbarColor(context, key, null);
        tintColor = Config.getToolbarTitleColor(context, null, key, toolbarColor);
    }
    final Class<?> cls = target.getClass();
    try {
        final Field mSearchSrcTextViewField = cls.getDeclaredField("mSearchSrcTextView");
        mSearchSrcTextViewField.setAccessible(true);
        final EditText mSearchSrcTextView = (EditText) mSearchSrcTextViewField.get(target);
        mSearchSrcTextView.setTextColor(tintColor);
        mSearchSrcTextView.setHintTextColor(ContextCompat.getColor(context, ATEUtil.isColorLight(tintColor) ? R.color.ate_text_disabled_dark : R.color.ate_text_disabled_light));
        TintHelper.setCursorTint(mSearchSrcTextView, tintColor);

        Field field = cls.getDeclaredField("mSearchButton");
        tintImageView(target, field, tintColor);
        field = cls.getDeclaredField("mGoButton");
        tintImageView(target, field, tintColor);
        field = cls.getDeclaredField("mCloseButton");
        tintImageView(target, field, tintColor);
        field = cls.getDeclaredField("mVoiceButton");
        tintImageView(target, field, tintColor);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 11
Project: GitHub   File: BaseViewPager.java   Source Code and License Vote up 5 votes
private static boolean isDecorView(@NonNull View view) {
    Class<?> clazz = view.getClass();
    return clazz.getAnnotation(DecorView.class) != null;
}
 
Example 12
Project: YViewPagerDemo   File: YViewPager.java   Source Code and License Vote up 5 votes
private static boolean isDecorView(View view) {
    Class<?> clazz = view.getClass();
    return clazz.getAnnotation(DecorView.class) != null;
}
 
Example 13
Project: YViewPagerDemo   File: YViewPagerNew.java   Source Code and License Vote up 5 votes
private static boolean isDecorView(View view) {
    Class<?> clazz = view.getClass();
    return clazz.getAnnotation(YViewPagerNew.DecorView.class) != null;
}
 
Example 14
Project: YViewPagerDemo   File: YViewPagerOrigin.java   Source Code and License Vote up 5 votes
private static boolean isDecorView(@NonNull View view) {
    Class<?> clazz = view.getClass();
    return clazz.getAnnotation(YViewPagerOrigin.DecorView.class) != null;
}
 
Example 15
Project: JewelryUI   File: ViewPager.java   Source Code and License Vote up 5 votes
private static boolean isDecorView(@NonNull View view) {
    Class<?> clazz = view.getClass();
    return clazz.getAnnotation(ViewPager.DecorView.class) != null;
}
 
Example 16
Project: ChangeTabLayout   File: VerticalViewPager.java   Source Code and License Vote up 5 votes
private static boolean isDecorView(@NonNull View view) {
    Class<?> clazz = view.getClass();
    return clazz.getAnnotation(DecorView.class) != null;
}