Java Code Examples for android.view.View#isInEditMode()

The following examples show how to use android.view.View#isInEditMode() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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));
                }
            }
        }
    }

}
 
Example 2
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);
    }
}
 
Example 3
Source Project: letv   File: ViewUtil.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source Project: MDPreference   File: RippleManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
    * 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);
}
 
Example 5
/**
 * 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;
  }
}
 
Example 6
Source Project: mosby   File: ViewGroupMvpDelegateImpl.java    License: Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example 7
Source Project: mosby   File: ViewGroupMviDelegateImpl.java    License: Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example 8
Source Project: Carbon   File: Carbon.java    License: Apache License 2.0 6 votes vote down vote up
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));
    }
}
 
Example 9
Source Project: Carbon   File: Carbon.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 10
Source Project: material   File: RippleManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
    * 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);
}
 
Example 11
Source Project: imsdk-android   File: ViewUtil.java    License: MIT License 5 votes vote down vote up
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;
}
 
Example 12
@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文本的颜色
    }
}
 
Example 13
Source Project: JKeyboardPanelSwitch   File: ViewUtil.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source Project: AndroidCommons   File: Fonts.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 15
Source Project: EazeGraph   File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressLint("NewApi")
public static void setLayerToSW(View v) {
    if (!v.isInEditMode() && Build.VERSION.SDK_INT >= 11) {
        v.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
}
 
Example 16
Source Project: EazeGraph   File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressLint("NewApi")
public static void setLayerToHW(View v) {
    if (!v.isInEditMode() && Build.VERSION.SDK_INT >= 11) {
        v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
}
 
Example 17
Source Project: butterknife   File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
private static String getResourceEntryName(View view, @IdRes int id) {
  if (view.isInEditMode()) {
    return "<unavailable while editing>";
  }
  return view.getContext().getResources().getResourceEntryName(id);
}