下面列出了android.view.View#setHasTransientState ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static void addViewValues(TransitionValuesMaps transitionValuesMaps,
View view, TransitionValues transitionValues) {
transitionValuesMaps.viewValues.put(view, transitionValues);
int id = view.getId();
if (id >= 0) {
if (transitionValuesMaps.idValues.indexOfKey(id) >= 0) {
// Duplicate IDs cannot match by ID.
transitionValuesMaps.idValues.put(id, null);
} else {
transitionValuesMaps.idValues.put(id, view);
}
}
String name = view.getTransitionName();
if (name != null) {
if (transitionValuesMaps.nameValues.containsKey(name)) {
// Duplicate transitionNames: cannot match by transitionName.
transitionValuesMaps.nameValues.put(name, null);
} else {
transitionValuesMaps.nameValues.put(name, view);
}
}
if (view.getParent() instanceof ListView) {
ListView listview = (ListView) view.getParent();
if (listview.getAdapter().hasStableIds()) {
int position = listview.getPositionForView(view);
long itemId = listview.getItemIdAtPosition(position);
if (transitionValuesMaps.itemIdValues.indexOfKey(itemId) >= 0) {
// Duplicate item IDs: cannot match by item ID.
View alreadyMatched = transitionValuesMaps.itemIdValues.get(itemId);
if (alreadyMatched != null) {
alreadyMatched.setHasTransientState(false);
transitionValuesMaps.itemIdValues.put(itemId, null);
}
} else {
view.setHasTransientState(true);
transitionValuesMaps.itemIdValues.put(itemId, view);
}
}
}
}
@Test
public void
visibilityOutputs_setTransientStateFalse_parentInTransientState_processVisibilityOutputs() {
final TestComponent content = create(mContext).build();
final EventHandler<VisibleEvent> visibleEventHandler = new EventHandler<>(content, 2);
final Component root =
Column.create(mContext)
.child(
Wrapper.create(mContext)
.delegate(content)
.visibleHandler(visibleEventHandler)
.widthPx(10)
.heightPx(10))
.build();
final View view = (View) mLithoView.getParent();
view.setHasTransientState(true);
mLithoViewRule
.useComponentTree(ComponentTree.create(mContext).build())
.setRoot(root)
.attachToWindow()
.setSizeSpecs(makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY))
.measure()
.layout();
mLithoView.notifyVisibleBoundsChanged(new Rect(0, -10, 10, -5), true);
content.getDispatchedEventHandlers().clear();
mLithoView.setHasTransientState(true);
assertThat(content.getDispatchedEventHandlers()).doesNotContain(visibleEventHandler);
mLithoView.setMountStateDirty();
mLithoView.notifyVisibleBoundsChanged(new Rect(0, -10, 10, -5), true);
assertThat(content.getDispatchedEventHandlers()).doesNotContain(visibleEventHandler);
mLithoView.setHasTransientState(false);
assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler);
view.setHasTransientState(false);
}
protected Animator shuffle(View target) {
LOGI(TAG, "shuffle()");
final int duration = Resources.getSystem().getInteger(android.R.integer.config_mediumAnimTime);
ObjectAnimator rotation = ObjectAnimator.ofFloat(target, View.TRANSLATION_X, 5, 0, -5, 0, 5, 0, -5, 0, 5, 0, -5, 0, 5, 0);
rotation.setDuration(duration);
rotation.setStartDelay(duration / 4);
target.setHasTransientState(true);
return rotation;
}
protected Animator wiggle(View target) {
LOGI(TAG, "wiggle()");
final int duration = Resources.getSystem().getInteger(android.R.integer.config_mediumAnimTime);
ObjectAnimator rotation = ObjectAnimator.ofFloat(target, View.ROTATION, 5, 0, -5, 0, 5, 0, -5, 0, 5, 0, -5, 0, 5, 0);
rotation.setDuration(duration);
rotation.setStartDelay(duration / 4);
target.setHasTransientState(true);
return rotation;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public View getView(Context context, boolean swipable) {
View view = LayoutInflater.from(context).inflate(getCardLayout(), null);
mCardLayout = view;
try {
if (view != null) ((FrameLayout) view.findViewById(R.id.cardContent))
.addView(getCardContent(context));
} catch (NullPointerException e) {
e.printStackTrace();
}
// ((TextView) view.findViewById(R.id.title)).setText(this.title);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
int bottom = Utils.convertDpToPixelInt(context, 12);
lp.setMargins(0, 0, 0, bottom);
if (view != null) {
view.setLayoutParams(lp);
view.setHasTransientState(true);
}
return view;
}
@SuppressLint("NewApi")
@Override
public View getView(Context context) {
View view = LayoutInflater.from(context).inflate(getCardLayout(), null);
mCardLayout = view;
try {
if (view != null) ((FrameLayout) view.findViewById(R.id.cardContent))
.addView(getCardContent(context));
} catch (NullPointerException e) {
e.printStackTrace();
}
// ((TextView) view.findViewById(R.id.title)).setText(this.title);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
int bottom = Utils.convertDpToPixelInt(context, 12);
lp.setMargins(0, 0, 0, bottom);
if (view != null) {
view.setLayoutParams(lp);
view.setHasTransientState(true);
}
return view;
}
@SuppressLint("NewApi")
public View getViewLast(Context context) {
View view = LayoutInflater.from(context).inflate(getLastCardLayout(),
null);
mCardLayout = view;
try {
if (view != null) ((FrameLayout) view.findViewById(R.id.cardContent))
.addView(getCardContent(context));
} catch (NullPointerException e) {
e.printStackTrace();
}
// ((TextView) view.findViewById(R.id.title)).setText(this.title);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
int bottom = Utils.convertDpToPixelInt(context, 12);
lp.setMargins(0, 0, 0, bottom);
if (view != null) {
view.setLayoutParams(lp);
view.setHasTransientState(true);
}
return view;
}
@SuppressLint("NewApi")
public View getViewFirst(Context context) {
View view = LayoutInflater.from(context).inflate(getFirstCardLayout(),
null);
mCardLayout = view;
try {
if (view != null) ((FrameLayout) view.findViewById(R.id.cardContent))
.addView(getCardContent(context));
} catch (NullPointerException e) {
e.printStackTrace();
}
// ((TextView) view.findViewById(R.id.title)).setText(this.title);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
int bottom = Utils.convertDpToPixelInt(context, 12);
lp.setMargins(0, 0, 0, bottom);
if (view != null) {
view.setLayoutParams(lp);
view.setHasTransientState(true);
}
return view;
}
protected Animator shuffle(View target) {
LOGI(TAG, "shuffle()");
final int duration = Resources.getSystem().getInteger(android.R.integer.config_mediumAnimTime);
ObjectAnimator rotation = ObjectAnimator.ofFloat(target, View.TRANSLATION_X, 5, 0, -5, 0, 5, 0, -5, 0, 5, 0, -5, 0, 5, 0);
rotation.setDuration(duration);
rotation.setStartDelay(duration / 4);
target.setHasTransientState(true);
return rotation;
}
protected Animator wiggle(View target) {
LOGI(TAG, "wiggle()");
final int duration = Resources.getSystem().getInteger(android.R.integer.config_mediumAnimTime);
ObjectAnimator rotation = ObjectAnimator.ofFloat(target, View.ROTATION, 5, 0, -5, 0, 5, 0, -5, 0, 5, 0, -5, 0, 5, 0);
rotation.setDuration(duration);
rotation.setStartDelay(duration / 4);
target.setHasTransientState(true);
return rotation;
}
private void beforeDataSetChanged() {
Adapter adapter = adapterView.getAdapter();
final int firstVisiblePosition = adapterView.getFirstVisiblePosition();
for (int i = 0, childCount = adapterView.getChildCount(); i < childCount; i++) {
final int position = firstVisiblePosition + i;
final long id = adapter.getItemId(position);
final View child = adapterView.getChildAt(i);
Rect r = new Rect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
child.setHasTransientState(true);
viewBounds.put(id, r);
idToViewMap.put(id, child);
}
}
public static void setHasTransientState(View view, boolean hasTransientState) {
view.setHasTransientState(hasTransientState);
}
public static void setTransientState(List<View> views, boolean hasState) {
for (View view : views)
view.setHasTransientState(hasState);
}
public static void a(View view, boolean flag)
{
view.setHasTransientState(flag);
}
public static void setHasTransientState(View view, boolean hasTransientState) {
view.setHasTransientState(hasTransientState);
}
public static void setHasTransientState(View view, boolean hasTransientState) {
view.setHasTransientState(hasTransientState);
}
public static void setTransientState(List<View> views, boolean hasState) {
for (View view : views)
view.setHasTransientState(hasState);
}
public static void setHasTransientState(View view, boolean hasTransientState) {
view.setHasTransientState(hasTransientState);
}
public static void setHasTransientState(View view, boolean hasTransientState) {
view.setHasTransientState(hasTransientState);
}
@Override
public void setHasTransientState(@NonNull View view, boolean hasTransientState) {
view.setHasTransientState(hasTransientState);
}