下面列出了android.view.View#isInEditMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onBindView(View view) {
super.onBindView(view);
if (view.isInEditMode()) {
return;
}
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
LinkedList<ViewGroup> queue = new LinkedList<>();
queue.add(viewGroup);
while (!queue.isEmpty()) {
ViewGroup current = queue.removeFirst();
for (int i = 0; i < current.getChildCount(); i++) {
if (current.getChildAt(i) instanceof Switch) {
ATH.setTint(current.getChildAt(i), ThemeStore.accentColor(view.getContext()));
return;
} else if (current.getChildAt(i) instanceof ViewGroup) {
queue.addLast((ViewGroup) current.getChildAt(i));
}
}
}
}
}
public Resources(Context context, View v) {
final android.content.res.Resources r = context.getResources();
Theme t = null;
if(!v.isInEditMode()) {
t = Theme.getCurrentTheme(context);
}
if(t != null) {
incoming = t.getDrawableResource("ic_call_incoming");
outgoing = t.getDrawableResource("ic_call_outgoing");
missed = t.getDrawableResource("ic_call_missed");
iconMargin = t.getDimension("call_log_icon_margin");
}
if(incoming == null) {
incoming = r.getDrawable(R.drawable.ic_call_incoming_holo_dark);
}
if(outgoing == null) {
outgoing = r.getDrawable(R.drawable.ic_call_outgoing_holo_dark);
}
if(missed == null) {
missed = r.getDrawable(R.drawable.ic_call_missed_holo_dark);
}
if(iconMargin == null) {
iconMargin = r.getDimensionPixelSize(R.dimen.call_log_icon_margin);
}
}
public static boolean refreshHeight(View view, int aimHeight) {
if (view.isInEditMode()) {
return false;
}
Log.d(TAG, String.format("refresh Height %d %d", new Object[]{Integer.valueOf(view.getHeight()), Integer.valueOf(aimHeight)}));
if (view.getHeight() == aimHeight || Math.abs(view.getHeight() - aimHeight) == StatusBarHeightUtil.getStatusBarHeight(view.getContext())) {
return false;
}
int validPanelHeight = KeyboardUtil.getValidPanelHeight(view.getContext());
LayoutParams layoutParams = view.getLayoutParams();
if (layoutParams == null) {
view.setLayoutParams(new LayoutParams(-1, validPanelHeight));
} else {
layoutParams.height = validPanelHeight;
view.requestLayout();
}
return true;
}
/**
* Should be called in the construction method of view to create a RippleDrawable.
*/
public void onCreate(View v, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
if(v.isInEditMode())
return;
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RippleView, defStyleAttr, defStyleRes);
int rippleStyle = a.getResourceId(R.styleable.RippleView_rd_style, 0);
RippleDrawable drawable = null;
if(rippleStyle != 0)
drawable = new RippleDrawable.Builder(context, rippleStyle).backgroundDrawable(getBackground(v)).build();
else{
boolean rippleEnable = a.getBoolean(R.styleable.RippleView_rd_enable, false);
if(rippleEnable)
drawable = new RippleDrawable.Builder(context, attrs, defStyleAttr, defStyleRes).backgroundDrawable(getBackground(v)).build();
}
a.recycle();
if(drawable != null)
ViewUtil.setBackground(v, drawable);
}
/**
* Creates a new instance
*
* @param delegateCallback the callback
* @param keepPresenterDuringScreenOrientationChange true, if you want to keep the presenter and view state during screen
* orientation changes etc.
*/
public ViewGroupMvpViewStateDelegateImpl(@NonNull View view,
@NonNull ViewGroupMvpViewStateDelegateCallback<V, P, VS> delegateCallback,
boolean keepPresenterDuringScreenOrientationChange) {
if (view == null) {
throw new NullPointerException("View is null!");
}
if (delegateCallback == null) {
throw new NullPointerException("MvpDelegateCallback is null!");
}
this.delegateCallback = delegateCallback;
this.keepPresenterDuringScreenOrientationChange = keepPresenterDuringScreenOrientationChange;
isInEditMode = view.isInEditMode();
if (!isInEditMode) {
this.activity = PresenterManager.getActivity(delegateCallback.getContext());
this.activity.getApplication().registerActivityLifecycleCallbacks(this);
} else {
this.activity = null;
}
}
public ViewGroupMvpDelegateImpl(@NonNull View view,
@NonNull ViewGroupDelegateCallback<V, P> delegateCallback,
boolean keepPresenterDuringScreenOrientationChange) {
if (view == null) {
throw new NullPointerException("View is null!");
}
if (delegateCallback == null) {
throw new NullPointerException("MvpDelegateCallback is null!");
}
this.delegateCallback = delegateCallback;
this.keepPresenterDuringScreenOrientationChange = keepPresenterDuringScreenOrientationChange;
isInEditMode = view.isInEditMode();
if (!isInEditMode) {
this.activity = PresenterManager.getActivity(delegateCallback.getContext());
this.activity.getApplication().registerActivityLifecycleCallbacks(this);
} else {
this.activity = null;
}
}
public ViewGroupMviDelegateImpl(@NonNull View view,
@NonNull ViewGroupMviDelegateCallback<V, P> delegateCallback,
boolean keepPresenterDuringScreenOrientationChange) {
if (view == null) {
throw new NullPointerException("View is null!");
}
if (delegateCallback == null) {
throw new NullPointerException("MvpDelegateCallback is null!");
}
this.delegateCallback = delegateCallback;
this.keepPresenterDuringScreenOrientationChange = keepPresenterDuringScreenOrientationChange;
this.isInEditMode = view.isInEditMode();
if (!isInEditMode) {
this.activity = PresenterManager.getActivity(delegateCallback.getContext());
this.activity.getApplication().registerActivityLifecycleCallbacks(this);
} else {
this.activity = null;
}
}
public static void initRippleDrawable(RippleView rippleView, TypedArray a, int[] ids) {
int carbon_rippleColor = ids[0];
int carbon_rippleStyle = ids[1];
int carbon_rippleHotspot = ids[2];
int carbon_rippleRadius = ids[3];
View view = (View) rippleView;
if (view.isInEditMode())
return;
ColorStateList color = getColorStateList(view, a, carbon_rippleColor);
if (color != null) {
RippleDrawable.Style style = RippleDrawable.Style.values()[a.getInt(carbon_rippleStyle, RippleDrawable.Style.Background.ordinal())];
boolean useHotspot = a.getBoolean(carbon_rippleHotspot, true);
int radius = (int) a.getDimension(carbon_rippleRadius, -1);
rippleView.setRippleDrawable(RippleDrawable.create(color, style, view, useHotspot, radius));
}
}
public static Drawable getDrawable(View view, TypedArray a, int attr, int defaultValue) {
if (!view.isInEditMode()) {
int resId = a.getResourceId(attr, 0);
if (resId != 0) {
if (view.getContext().getResources().getResourceTypeName(resId).equals("raw")) {
return new VectorDrawable(view.getResources(), resId);
} else {
return ContextCompat.getDrawable(view.getContext(), resId);
}
}
} else {
try {
return a.getDrawable(attr);
} catch (Exception e) {
return view.getResources().getDrawable(defaultValue);
}
}
return null;
}
/**
* Should be called in the construction method of view to create a RippleDrawable.
* @param v
* @param context
* @param attrs
* @param defStyleAttr
* @param defStyleRes
*/
public void onCreate(View v, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
if(v.isInEditMode())
return;
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RippleView, defStyleAttr, defStyleRes);
int rippleStyle = a.getResourceId(R.styleable.RippleView_rd_style, 0);
RippleDrawable drawable = null;
if(rippleStyle != 0)
drawable = new RippleDrawable.Builder(context, rippleStyle).backgroundDrawable(getBackground(v)).build();
else{
boolean rippleEnable = a.getBoolean(R.styleable.RippleView_rd_enable, false);
if(rippleEnable)
drawable = new RippleDrawable.Builder(context, attrs, defStyleAttr, defStyleRes).backgroundDrawable(getBackground(v)).build();
}
a.recycle();
if(drawable != null)
ViewUtil.setBackground(v, drawable);
}
public static boolean refreshHeight(final View view, final int aimHeight) {
if (view.isInEditMode()) {
return false;
}
Log.d(TAG, String.format("refresh Height %d %d", view.getHeight(), aimHeight));
if (view.getHeight() == aimHeight) {
return false;
}
if (Math.abs(view.getHeight() - aimHeight)
== StatusBarHeightUtil.getStatusBarHeight(view.getContext())) {
return false;
}
final int validPanelHeight = KeyboardUtil.getValidPanelHeight(view.getContext());
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
if (layoutParams == null) {
layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
validPanelHeight);
view.setLayoutParams(layoutParams);
} else {
layoutParams.height = validPanelHeight;
view.requestLayout();
}
return true;
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
if (view.isInEditMode()) {
return;
}
if (view instanceof TextView) {
TextView tv = (TextView) view;
tv.setTextColor(ThemeStore.accentColor(view.getContext()));//设置title文本的颜色
}
}
public static boolean refreshHeight(final View view, final int aimHeight) {
if (view.isInEditMode()) {
return false;
}
Log.d(TAG, String.format("refresh Height %d %d", view.getHeight(), aimHeight));
if (view.getHeight() == aimHeight) {
return false;
}
if (Math.abs(view.getHeight() - aimHeight)
== StatusBarHeightUtil.getStatusBarHeight(view.getContext())) {
return false;
}
final int validPanelHeight = KeyboardUtil.getValidPanelHeight(view.getContext());
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
if (layoutParams == null) {
layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
validPanelHeight);
view.setLayoutParams(layoutParams);
} else {
layoutParams.height = validPanelHeight;
view.requestLayout();
}
return true;
}
/**
* If view is instance of ViewGroup then applies fonts to all TextView views in given
* ViewGroup.<br/>
* If view is instance of TextView then applies font to provided TextView.<br/>
* TextView tag will be used to determine the font.
*/
public static void apply(@NonNull View view) {
if (view.isInEditMode()) {
return;
}
final AssetManager assets = view.getContext().getAssets();
if (view instanceof TextView) {
setTypeface((TextView) view, getFontFromTag(assets, view, false));
} else if (view instanceof ViewGroup) {
applyAllRecursively((ViewGroup) view, assets);
}
}
@SuppressLint("NewApi")
public static void setLayerToSW(View v) {
if (!v.isInEditMode() && Build.VERSION.SDK_INT >= 11) {
v.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
@SuppressLint("NewApi")
public static void setLayerToHW(View v) {
if (!v.isInEditMode() && Build.VERSION.SDK_INT >= 11) {
v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
}
private static String getResourceEntryName(View view, @IdRes int id) {
if (view.isInEditMode()) {
return "<unavailable while editing>";
}
return view.getContext().getResources().getResourceEntryName(id);
}