下面列出了android.view.View#hashCode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 设置监听
*/
private void setListener(View child) {
if (child instanceof RadioButton) {
int id = child.getId();
// generates an id if it's missing
if (id == View.NO_ID) {
id = child.hashCode();
child.setId(id);
}
((RadioButton) child).setOnCheckedChangeListener(
mChildOnCheckedChangeListener);
} else if (child instanceof ViewGroup) {
ViewGroup view = (ViewGroup) child;
for (int i = 0; i < view.getChildCount(); i++) {
setListener(view.getChildAt(i));
}
}
}
/**
* 设置监听
*
* @param child
*/
private void setListener(View child) {
if (child instanceof NestedRadioLayout) {
int id = child.getId();
// generates an id if it's missing
if (id == View.NO_ID) {
id = child.hashCode();
child.setId(id);
}
((NestedRadioLayout) child).setOnCheckedChangeWidgetListener(
mChildOnCheckedChangeListener);
} else if (child instanceof ViewGroup) {
ViewGroup view = (ViewGroup) child;
for (int i = 0; i < view.getChildCount(); i++) {
setListener(view.getChildAt(i));
}
}
}
/**
* {@inheritDoc}
*/
public void onChildViewAdded(View parent, View child) {
if (parent == RadioGroup.this && child instanceof RadioButton) {
int id = child.getId();
// generates an id if it's missing
if (id == View.NO_ID) {
id = child.hashCode();
child.setId(id);
}
((RadioButton) child).setOnCheckedChangeListener(
mChildOnCheckedChangeListener);
}
if (mOnHierarchyChangeListener != null) {
mOnHierarchyChangeListener.onChildViewAdded(parent, child);
}
}
/**
* {@inheritDoc}
*/
public void onChildViewAdded(View parent, View child) {
if (parent == ToggleGroup.this && child instanceof CompoundButton) {
int id = child.getId();
// generates an id if it's missing
if (id == View.NO_ID) {
if (Build.VERSION.SDK_INT < 17)
id = child.hashCode();
else
id = View.generateViewId();
child.setId(id);
}
((CompoundButton) child).setOnCheckedChangeListener(mChildOnCheckedChangeListener);
}
if (mOnHierarchyChangeListener != null) {
mOnHierarchyChangeListener.onChildViewAdded(parent, child);
}
}
/**
* {@inheritDoc}
*/
public void onChildViewAdded(View parent, View child) {
if (parent == RadioGroup.this && child instanceof RadioButton) {
int id = child.getId();
// generates an id if it's missing
if (id == View.NO_ID) {
id = child.hashCode();
child.setId(id);
}
((RadioButton) child).setOnCheckedChangeWidgetListener(
mChildOnCheckedChangeListener);
}
if (mOnHierarchyChangeListener != null) {
mOnHierarchyChangeListener.onChildViewAdded(parent, child);
}
}
/**
* {@inheritDoc}
*/
public void onChildViewAdded(View parent, View child) {
if (parent == ToggleGroup.this && child instanceof CompoundButton) {
int id = child.getId();
// generates an id if it's missing
if (id == View.NO_ID) {
if (Build.VERSION.SDK_INT < 17)
id = child.hashCode();
else
id = View.generateViewId();
child.setId(id);
}
((CompoundButton) child).setOnCheckedChangeListener(mChildOnCheckedChangeListener);
}
if (mOnHierarchyChangeListener != null) {
mOnHierarchyChangeListener.onChildViewAdded(parent, child);
}
}
/**
* Generate the modified url.
*
* @param baseUrl A url to be used as a base to the responsive transformation. This url can
* contain any configurations and transformations. The generated responsive
* transformation will be chained as the last transformation in the url.
* Important: When generating using a base url, it's preferable to not include
* any cropping/scaling in the original transformations.
* @param view The view to adapt the resource dimensions to.
* @param callback Callback to called when the modified Url is ready.
*/
public void generate(final Url baseUrl, final View view, final Callback callback) {
assertViewValidForResponsive(view);
final int key = view.hashCode();
int width = view.getWidth();
int height = view.getHeight();
if (conditionsAreMet(width, height)) {
// The required dimensions are already known, build url:
callback.onUrlReady(buildUrl(view, baseUrl));
viewsInProgress.remove(key);
} else {
// save the link between the requested url and the specific view, so that
// if in the meantime the view is assigned a new item (e.g. recycling views in a list)
// it won't override the correct data.
viewsInProgress.put(key, baseUrl);
view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
view.getViewTreeObserver().removeOnPreDrawListener(this);
if (baseUrl.equals(viewsInProgress.get(key))) {
callback.onUrlReady(buildUrl(view, baseUrl));
viewsInProgress.remove(key);
}
return true;
}
});
}
}
public int compare(View lhs, View rhs) {
int lhsHashCode = lhs.hashCode();
int rhsHashCode = rhs.hashCode();
int currentHashCode = AppStateManager.getInstance().getCurrentRootWindowsHashCode();
if (lhsHashCode == currentHashCode) {
return -1;
} else {
return rhsHashCode == currentHashCode ? 1 : rhs.getWidth() * rhs.getHeight() - lhs.getWidth() * lhs.getHeight();
}
}
private void cancelExistingAnimation(final View convertView) {
int hashCode = convertView.hashCode();
Animator animator = mAnimators.get(hashCode);
if (animator != null) {
animator.end();
mAnimators.remove(hashCode);
}
}
public int getId()
{
View view = (View)viewRef.get();
if (view == null)
{
return super.hashCode();
} else
{
return view.hashCode();
}
}
/**
* Cancels any existing animations for given View.
*/
void cancelExistingAnimation(@NonNull final View view) {
int hashCode = view.hashCode();
Animator animator = mAnimators.get(hashCode);
if (animator != null) {
animator.end();
mAnimators.remove(hashCode);
}
}
/**
* Cancels any existing animations for given View.
*/
public void cancelExistingAnimation(@NonNull final View view) {
int hashCode = view.hashCode();
Animator animator = mAnimators.get(hashCode);
if (animator != null) {
animator.end();
mAnimators.remove(hashCode);
}
}
private void cancelExistingAnimation(final View convertView) {
int hashCode = convertView.hashCode();
Animator animator = mAnimators.get(hashCode);
if (animator != null) {
animator.end();
mAnimators.remove(hashCode);
}
}
private int getViewTypeByView(@NonNull View view) {
return view.hashCode() + getClass().hashCode();
}
private int getViewTypeByView(@NonNull View view) {
return view.hashCode() + getClass().hashCode();
}
@Override
public int getId() {
View view = viewRef.get();
return view == null ? super.hashCode() : view.hashCode();
}
public int getId() {
View view = mViewRef.get();
return view == null ? super.hashCode() : view.hashCode();
}
public ImageReference(View view) {
this.view = view;
this.contentId = "view_" + view.hashCode();
this.type = SourceType.VIEW;
}
@Override
public int getId() {
View view = viewRef.get();
return view == null ? super.hashCode() : view.hashCode();
}
@Override
public final View getView(int position, View convertView, ViewGroup parent)
{
boolean alreadyStarted = false;
if (!mHasParentAnimationAdapter)
{
if (getListView() == null)
{
throw new IllegalStateException("Call setListView() on this AnimationAdapter before setAdapter()!");
}
if (convertView != null)
{
int hashCode = convertView.hashCode();
AnimationInfo animationInfo = mAnimators.get(hashCode);
if (animationInfo != null)
{
if (animationInfo.position != position)
{
animationInfo.animator.end();
mAnimators.remove(hashCode);
}
else
{
alreadyStarted = true;
}
}
}
}
View itemView = super.getView(position, convertView, parent);
if (nextDeactivated <= 0)
{
if (!mHasParentAnimationAdapter && !alreadyStarted && animationsEnabled)
{
animateViewIfNecessary(position, itemView, parent);
}
}
else
{
nextDeactivated--;
}
return itemView;
}