Example usage for android.view View setId

List of usage examples for android.view View setId

Introduction

In this page you can find the example usage for android.view View setId.

Prototype

public void setId(@IdRes int id) 

Source Link

Document

Sets the identifier for this view.

Usage

From source file:widgets.QuizWidget.java

@SuppressWarnings("unchecked")
@Override//  w w w.ja va 2 s.  c om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    prefs = PreferenceManager.getDefaultSharedPreferences(super.getActivity());
    View vv = super.getLayoutInflater(savedInstanceState).inflate(R.layout.widget_quiz, null);
    this.container = container;
    course = (Course) getArguments().getSerializable(Course.TAG);
    activity = ((Activity) getArguments().getSerializable(Activity.TAG));
    this.setIsBaseline(getArguments().getBoolean(CourseActivity.BASELINE_TAG));
    quizContent = ((Activity) getArguments().getSerializable(Activity.TAG)).getContents(prefs.getString(
            super.getActivity().getString(R.string.prefs_language), Locale.getDefault().getLanguage()));

    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    vv.setLayoutParams(lp);
    vv.setId(activity.getActId());
    if ((savedInstanceState != null) && (savedInstanceState.getSerializable("widget_config") != null)) {
        setWidgetConfig((HashMap<String, Object>) savedInstanceState.getSerializable("widget_config"));
    }
    return vv;
}

From source file:com.achep.acdisplay.ui.widgets.notification.NotificationActions.java

/**
 * Sets new actions.//from  ww  w . ja  va  2  s .  c  o  m
 *
 * @param notification the host notification
 * @param actions      the actions to set
 */
public void setActions(@Nullable OpenNotification notification, @Nullable Action[] actions) {
    Check.getInstance().isInMainThread();

    mRemoteInputsMap.clear();
    mActionsMap.clear();
    hideRii();

    if (actions == null) {
        // Free actions' container.
        removeAllViews();
        return;
    } else {
        assert notification != null;
    }

    int count = actions.length;
    View[] views = new View[count];

    // Find available views.
    int childCount = getChildCount();
    int a = Math.min(childCount, count);
    for (int i = 0; i < a; i++) {
        views[i] = getChildAt(i);
    }

    // Remove redundant views.
    for (int i = childCount - 1; i >= count; i--) {
        removeViewAt(i);
    }

    LayoutInflater inflater = null;
    for (int i = 0; i < count; i++) {
        final Action action = actions[i];
        View root = views[i];

        if (root == null) {
            // Initialize layout inflater only when we really need it.
            if (inflater == null) {
                inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                assert inflater != null;
            }

            root = inflater.inflate(getActionLayoutResource(), this, false);
            root = onCreateActionView(root);
            // We need to keep all IDs unique to make
            // TransitionManager.beginDelayedTransition(viewGroup, null)
            // work correctly!
            root.setId(getChildCount() + 1);
            addView(root);
        }

        mActionsMap.put(root, action);

        int style = Typeface.NORMAL;
        root.setOnLongClickListener(null);
        if (action.intent != null) {
            root.setEnabled(true);
            root.setOnClickListener(mActionsOnClick);

            RemoteInput remoteInput = getRemoteInput(action);
            if (remoteInput != null) {
                mRemoteInputsMap.put(action, remoteInput);
                root.setOnLongClickListener(mActionsOnLongClick);

                // Highlight the action
                style = Typeface.ITALIC;
            }
        } else {
            root.setEnabled(false);
            root.setOnClickListener(null);
        }

        // Get message view and apply the content.
        TextView textView = root instanceof TextView ? (TextView) root
                : (TextView) root.findViewById(android.R.id.title);
        textView.setText(action.title);
        if (mTypeface == null)
            mTypeface = textView.getTypeface();
        textView.setTypeface(mTypeface, style);

        Drawable icon = NotificationUtils.getDrawable(getContext(), notification, action.icon);
        if (icon != null)
            icon = onCreateActionIcon(icon);

        if (Device.hasJellyBeanMR1Api()) {
            textView.setCompoundDrawablesRelative(icon, null, null, null);
        } else {
            textView.setCompoundDrawables(icon, null, null, null);
        }
    }
}

From source file:org.odk.collect.android.widgets.SelectMultiWidget.java

@SuppressWarnings("unchecked")
public SelectMultiWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);
    mPrompt = prompt;/*from w w  w  .java 2 s.  c o m*/
    mCheckboxes = new ArrayList<CheckBox>();

    // SurveyCTO-added support for dynamic select content (from .csv files)
    XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint());
    if (xPathFuncExpr != null) {
        mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr);
    } else {
        mItems = prompt.getSelectChoices();
    }

    setOrientation(LinearLayout.VERTICAL);

    String fieldElementReference = prompt.getFormElement().getBind().getReference().toString();
    fieldName = getFieldID(fieldElementReference);

    if (fieldName.equalsIgnoreCase("typedirt")) {
        if (PropertiesUtils.getiAnswer32() == 1) {
            setVisibility(VISIBLE);
        } else
            setVisibility(INVISIBLE);
        PropertiesUtils.setLayoutQuestion321(this);
    }
    if (fieldName.equalsIgnoreCase("taste1")) {
        if (PropertiesUtils.getiAns33() == 0) {
            setVisibility(INVISIBLE);
        } else {
            if (PropertiesUtils.getiAns332() == 0) {
                setVisibility(INVISIBLE);
            } else
                setVisibility(VISIBLE);
        }
        PropertiesUtils.setLayoutQues333(this);
    }
    Vector<Selection> ve = new Vector<Selection>();
    if (prompt.getAnswerValue() != null) {
        ve = (Vector<Selection>) prompt.getAnswerValue().getValue();
    }

    //       int row_index       = 0 ;
    //       int col_index       = 0 ;
    Boolean isNewRow = false;
    Boolean isAddDirect = false;
    Boolean isTextView = false;
    Boolean isAddDivider = false;
    int itemCount = 0;

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    if (mItems != null) {
        for (int i = 0; i < mItems.size(); i++) {
            // no checkbox group so id by answer + offset
            View c;
            //Check text of the Choice Start With ($), i must be category
            if (prompt.getSelectChoiceText(mItems.get(i)).startsWith("$")) {
                StringBuilder sb = new StringBuilder(prompt.getSelectChoiceText(mItems.get(i)));
                String str = sb.deleteCharAt(0).toString();

                c = new TextView(getContext());
                ((TextView) c).setText(str);
                ((TextView) c).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mQuestionFontsize + 1);
                ((TextView) c).setTypeface(null, Typeface.BOLD_ITALIC);
                c.setPadding(70, 10, 10, 10);
                c.setId(QuestionWidget.newUniqueId()); // assign random id
                isNewRow = true;
                itemCount = 0;
                isTextView = true;
                mCheckboxes.add(new CheckBox(context));
            } else { //  checkbox 
                isNewRow = true;
                isTextView = false;
                itemCount++;
                c = new CheckBox(getContext());
                c.setTag(Integer.valueOf(i));
                c.setId(QuestionWidget.newUniqueId());
                ((CheckBox) c).setText(prompt.getSelectChoiceText(mItems.get(i)));
                ((CheckBox) c).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
                c.setFocusable(!prompt.isReadOnly());
                c.setEnabled(!prompt.isReadOnly());
                c.setPadding(10, 10, 10, 10);
                ((CheckBox) c).setLineSpacing(1, 1.15f);
                mCheckboxes.add((CheckBox) c);

            }

            if (!isTextView)
                for (int vi = 0; vi < ve.size(); vi++) {
                    // match based on value, not key
                    if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) {
                        ((CheckBox) c).setChecked(true);
                        break;
                    }

                }

            if (!prompt.getSelectChoiceText(mItems.get(i)).startsWith("$")) {
                // when clicked, check for readonly before toggling

                ((CheckBox) c).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                        try {
                            if (fieldName.equalsIgnoreCase("typedirt")) {

                                if (mItems.get((Integer) buttonView.getTag()).getValue()
                                        .equalsIgnoreCase("other")) {
                                    if (isChecked) {
                                        PropertiesUtils.getTvQuestion321Other().setVisibility(VISIBLE);
                                        PropertiesUtils.getEdQuestion321Other().setVisibility(VISIBLE);
                                        PropertiesUtils.setiAnswer321(1);
                                        PropertiesUtils.setIsOther321Checked(true);

                                    } else {
                                        PropertiesUtils.getTvQuestion321Other().setVisibility(INVISIBLE);
                                        PropertiesUtils.getEdQuestion321Other().setVisibility(INVISIBLE);
                                        PropertiesUtils.setiAnswer321(0);
                                        PropertiesUtils.setIsOther321Checked(false);
                                    }
                                } else {
                                    PropertiesUtils.getTvQuestion321Other().setVisibility(INVISIBLE);
                                    PropertiesUtils.getEdQuestion321Other().setVisibility(INVISIBLE);
                                    if (PropertiesUtils.isIsOther321Checked() == true) {
                                        PropertiesUtils.getTvQuestion321Other().setVisibility(VISIBLE);
                                        PropertiesUtils.getEdQuestion321Other().setVisibility(VISIBLE);
                                        PropertiesUtils.setiAnswer321(1);
                                    }
                                }

                            }
                            if (fieldName.equalsIgnoreCase("taste1")) {
                                if (mItems.get((Integer) buttonView.getTag()).getValue()
                                        .equalsIgnoreCase("other_taste")) {
                                    if (isChecked) {
                                        PropertiesUtils.setiAns333(1);
                                        PropertiesUtils.getTvQues333Other().setVisibility(VISIBLE);
                                        PropertiesUtils.getEdQues333Other().setVisibility(VISIBLE);
                                        PropertiesUtils.setIsOther333Checked(true);
                                    } else {
                                        PropertiesUtils.setiAns333(0);
                                        PropertiesUtils.getTvQues333Other().setVisibility(INVISIBLE);
                                        PropertiesUtils.getEdQues333Other().setVisibility(INVISIBLE);
                                        PropertiesUtils.setIsOther333Checked(false);
                                    }
                                } else {
                                    PropertiesUtils.getTvQues333Other().setVisibility(INVISIBLE);
                                    PropertiesUtils.getEdQues333Other().setVisibility(INVISIBLE);
                                    if (PropertiesUtils.isIsOther333Checked() == true) {
                                        PropertiesUtils.getTvQues333Other().setVisibility(VISIBLE);
                                        PropertiesUtils.getEdQues333Other().setVisibility(VISIBLE);
                                        PropertiesUtils.setiAns333(1);
                                    }
                                }

                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (!mCheckboxInit && mPrompt.isReadOnly()) {
                            if (buttonView.isChecked()) {
                                buttonView.setChecked(false);
                                Collect.getInstance().getActivityLogger().logInstanceAction(this,
                                        "onItemClick.deselect",
                                        mItems.get((Integer) buttonView.getTag()).getValue(),
                                        mPrompt.getIndex());
                            } else {
                                buttonView.setChecked(true);
                                Collect.getInstance().getActivityLogger().logInstanceAction(this,
                                        "onItemClick.select",
                                        mItems.get((Integer) buttonView.getTag()).getValue(),
                                        mPrompt.getIndex());
                            }
                        }
                    }
                });
            }

            String audioURI = null;
            audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO);

            String imageURI;
            if (mItems.get(i) instanceof ExternalSelectChoice) {
                imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage();
            } else {
                imageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                        FormEntryCaption.TEXT_FORM_IMAGE);
            }

            String videoURI = null;
            videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video");

            String bigImageURI = null;
            bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image");

            MediaLayout mediaLayout = new MediaLayout(getContext());
            if (isTextView) {
                mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), (TextView) c, audioURI,
                        imageURI, videoURI, bigImageURI);
            } else {
                mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), (CheckBox) c, audioURI,
                        imageURI, videoURI, bigImageURI);
            }
            mediaLayout.setLayoutParams(params);

            //                row_index = i/2 +1;
            //                col_index = i%2;

            if (itemCount == 2) {
                isNewRow = false;
                itemCount = 0;
            }

            if (isNewRow) {
                ll = null;
                ll = new LinearLayout(getContext());
                ll.setOrientation(LinearLayout.HORIZONTAL);
                ll.addView(mediaLayout);
                isNewRow = false;
                isAddDirect = false;
                isAddDivider = false;

                try {
                    //if textview (category in choices) or the next element is textView , so must add direct
                    if (isTextView || prompt.getSelectChoiceText(mItems.get(i + 1)).startsWith("$"))
                        isAddDirect = true;
                } catch (Exception e) {
                    isAddDirect = true;

                }

                if (isAddDirect) {
                    addView(ll);
                    isAddDivider = true;
                }
            } else {
                ll.addView(mediaLayout);
                addView(ll);
                isAddDivider = true;
            }

            // add the dividing line between elements (except for the last element) but not last
            ImageView divider = new ImageView(getContext());
            divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
            int size = mItems.size() / 2;
            // if ( (i+1)/2< size && (i+1)%2==0) {
            if (isAddDivider && i < mItems.size() - 1)
                addView(divider);

            // }

        }
    }

    mCheckboxInit = false;

}

From source file:org.digitalcampus.oppia.widgets.QuizWidget.java

@SuppressWarnings("unchecked")
@Override//from w  w w .  jav  a  2s  .c o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    prefs = PreferenceManager.getDefaultSharedPreferences(super.getActivity());
    View vv = super.getLayoutInflater(savedInstanceState).inflate(R.layout.widget_quiz, null);
    this.container = container;
    course = (Course) getArguments().getSerializable(Course.TAG);
    activity = ((Activity) getArguments().getSerializable(Activity.TAG));
    this.setIsBaseline(getArguments().getBoolean(CourseActivity.BASELINE_TAG));
    quizContent = ((Activity) getArguments().getSerializable(Activity.TAG))
            .getContents(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()));

    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    vv.setLayoutParams(lp);
    vv.setId(activity.getActId());
    if ((savedInstanceState != null) && (savedInstanceState.getSerializable("widget_config") != null)) {
        setWidgetConfig((HashMap<String, Object>) savedInstanceState.getSerializable("widget_config"));
    }

    return vv;
}

From source file:org.videolan.vlc.gui.MyFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*  w w  w. j  av  a  2 s .  c  o  m*/
public boolean onKeyUp(int keyCode, KeyEvent event) {
    //Filter for LG devices, see https://code.google.com/p/android/issues/detail?id=78154
    if ((keyCode == KeyEvent.KEYCODE_MENU) && (Build.VERSION.SDK_INT <= 16)
            && (Build.MANUFACTURER.compareTo("LGE") == 0)) {
        openOptionsMenu();
        return true;
    }
    View v = getCurrentFocus();
    if (v == null)
        return super.onKeyUp(keyCode, event);
    if ((mActionBarIconId == -1) && (v.getId() == -1) && (v.getNextFocusDownId() == -1)
            && (v.getNextFocusUpId() == -1) && (v.getNextFocusLeftId() == -1)
            && (v.getNextFocusRightId() == -1)) {
        mActionBarIconId = Util.generateViewId();
        v.setId(mActionBarIconId);
        v.setNextFocusUpId(mActionBarIconId);
        v.setNextFocusDownId(mActionBarIconId);
        v.setNextFocusLeftId(mActionBarIconId);
        v.setNextFocusRightId(R.id.ml_menu_search);
        if (AndroidUtil.isHoneycombOrLater())
            v.setNextFocusForwardId(mActionBarIconId);
        if (findViewById(R.id.ml_menu_search) != null)
            findViewById(R.id.ml_menu_search).setNextFocusLeftId(mActionBarIconId);
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

@SuppressLint("NewApi")
private static void applyAttributes(View view, Map<String, String> attrs, ViewGroup parent) {
    if (viewRunnables == null)
        createViewRunnables();//from  w w  w . ja v a  2 s  .com
    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    int layoutRule;
    int marginLeft = 0, marginRight = 0, marginTop = 0, marginBottom = 0, paddingLeft = 0, paddingRight = 0,
            paddingTop = 0, paddingBottom = 0;
    boolean hasCornerRadius = false, hasCornerRadii = false;
    for (Map.Entry<String, String> entry : attrs.entrySet()) {
        String attr = entry.getKey();
        if (viewRunnables.containsKey(attr)) {
            viewRunnables.get(attr).apply(view, entry.getValue(), parent, attrs);
            continue;
        }
        if (attr.startsWith("cornerRadius")) {
            hasCornerRadius = true;
            hasCornerRadii = !attr.equals("cornerRadius");
            continue;
        }
        layoutRule = NO_LAYOUT_RULE;
        boolean layoutTarget = false;
        switch (attr) {
        case "id":
            String idValue = parseId(entry.getValue());
            if (parent != null) {
                DynamicLayoutInfo info = getDynamicLayoutInfo(parent);
                int newId = highestIdNumberUsed++;
                view.setId(newId);
                info.nameToIdNumber.put(idValue, newId);
            }
            break;
        case "width":
        case "layout_width":
            switch (entry.getValue()) {
            case "wrap_content":
                layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
                break;
            case "fill_parent":
            case "match_parent":
                layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
                break;
            default:
                layoutParams.width = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                        view.getResources().getDisplayMetrics(), parent, true);
                break;
            }
            break;
        case "height":
        case "layout_height":
            switch (entry.getValue()) {
            case "wrap_content":
                layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                break;
            case "fill_parent":
            case "match_parent":
                layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
                break;
            default:
                layoutParams.height = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                        view.getResources().getDisplayMetrics(), parent, false);
                break;
            }
            break;
        case "layout_gravity":
            if (parent != null && parent instanceof LinearLayout) {
                ((LinearLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue());
            } else if (parent != null && parent instanceof FrameLayout) {
                ((FrameLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue());
            }
            break;
        case "layout_weight":
            if (parent != null && parent instanceof LinearLayout) {
                ((LinearLayout.LayoutParams) layoutParams).weight = Float.parseFloat(entry.getValue());
            }
            break;
        case "layout_below":
            layoutRule = RelativeLayout.BELOW;
            layoutTarget = true;
            break;
        case "layout_above":
            layoutRule = RelativeLayout.ABOVE;
            layoutTarget = true;
            break;
        case "layout_toLeftOf":
            layoutRule = RelativeLayout.LEFT_OF;
            layoutTarget = true;
            break;
        case "layout_toRightOf":
            layoutRule = RelativeLayout.RIGHT_OF;
            layoutTarget = true;
            break;
        case "layout_alignBottom":
            layoutRule = RelativeLayout.ALIGN_BOTTOM;
            layoutTarget = true;
            break;
        case "layout_alignTop":
            layoutRule = RelativeLayout.ALIGN_TOP;
            layoutTarget = true;
            break;
        case "layout_alignLeft":
        case "layout_alignStart":
            layoutRule = RelativeLayout.ALIGN_LEFT;
            layoutTarget = true;
            break;
        case "layout_alignRight":
        case "layout_alignEnd":
            layoutRule = RelativeLayout.ALIGN_RIGHT;
            layoutTarget = true;
            break;
        case "layout_alignParentBottom":
            layoutRule = RelativeLayout.ALIGN_PARENT_BOTTOM;
            break;
        case "layout_alignParentTop":
            layoutRule = RelativeLayout.ALIGN_PARENT_TOP;
            break;
        case "layout_alignParentLeft":
        case "layout_alignParentStart":
            layoutRule = RelativeLayout.ALIGN_PARENT_LEFT;
            break;
        case "layout_alignParentRight":
        case "layout_alignParentEnd":
            layoutRule = RelativeLayout.ALIGN_PARENT_RIGHT;
            break;
        case "layout_centerHorizontal":
            layoutRule = RelativeLayout.CENTER_HORIZONTAL;
            break;
        case "layout_centerVertical":
            layoutRule = RelativeLayout.CENTER_VERTICAL;
            break;
        case "layout_centerInParent":
            layoutRule = RelativeLayout.CENTER_IN_PARENT;
            break;
        case "layout_margin":
            marginLeft = marginRight = marginTop = marginBottom = DimensionConverter
                    .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics());
            break;
        case "layout_marginLeft":
            marginLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, true);
            break;
        case "layout_marginTop":
            marginTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, false);
            break;
        case "layout_marginRight":
            marginRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, true);
            break;
        case "layout_marginBottom":
            marginBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, false);
            break;
        case "padding":
            paddingBottom = paddingLeft = paddingRight = paddingTop = DimensionConverter
                    .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics());
            break;
        case "paddingLeft":
            paddingLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingTop":
            paddingTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingRight":
            paddingRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingBottom":
            paddingBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;

        }
        if (layoutRule != NO_LAYOUT_RULE && parent instanceof RelativeLayout) {
            if (layoutTarget) {
                int anchor = idNumFromIdString(parent, parseId(entry.getValue()));
                ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule, anchor);
            } else if (entry.getValue().equals("true")) {
                ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule);
            }
        }
    }
    // TODO: this is a giant mess; come up with a simpler way of deciding what to draw for the background
    if (attrs.containsKey("background") || attrs.containsKey("borderColor")) {
        String bgValue = attrs.containsKey("background") ? attrs.get("background") : null;
        if (bgValue != null && bgValue.startsWith("@drawable/")) {
            view.setBackground(getDrawableByName(view, bgValue));
        } else if (bgValue == null || bgValue.startsWith("#") || bgValue.startsWith("@color")) {
            if (view instanceof Button || attrs.containsKey("pressedColor")) {
                int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue);
                int pressedColor;
                if (attrs.containsKey("pressedColor")) {
                    pressedColor = parseColor(view, attrs.get("pressedColor"));
                } else {
                    pressedColor = adjustBrightness(bgColor, 0.9f);
                }
                GradientDrawable gd = new GradientDrawable();
                gd.setColor(bgColor);
                GradientDrawable pressedGd = new GradientDrawable();
                pressedGd.setColor(pressedColor);
                if (hasCornerRadii) {
                    float radii[] = new float[8];
                    for (int i = 0; i < CORNERS.length; i++) {
                        String corner = CORNERS[i];
                        if (attrs.containsKey("cornerRadius" + corner)) {
                            radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension(
                                    attrs.get("cornerRadius" + corner),
                                    view.getResources().getDisplayMetrics());
                        }
                        gd.setCornerRadii(radii);
                        pressedGd.setCornerRadii(radii);
                    }
                } else if (hasCornerRadius) {
                    float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"),
                            view.getResources().getDisplayMetrics());
                    gd.setCornerRadius(cornerRadius);
                    pressedGd.setCornerRadius(cornerRadius);
                }
                if (attrs.containsKey("borderColor")) {
                    String borderWidth = "1dp";
                    if (attrs.containsKey("borderWidth")) {
                        borderWidth = attrs.get("borderWidth");
                    }
                    int borderWidthPx = DimensionConverter.stringToDimensionPixelSize(borderWidth,
                            view.getResources().getDisplayMetrics());
                    gd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor")));
                    pressedGd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor")));
                }
                StateListDrawable selector = new StateListDrawable();
                selector.addState(new int[] { android.R.attr.state_pressed }, pressedGd);
                selector.addState(new int[] {}, gd);
                view.setBackground(selector);
                getDynamicLayoutInfo(view).bgDrawable = gd;
            } else if (hasCornerRadius || attrs.containsKey("borderColor")) {
                GradientDrawable gd = new GradientDrawable();
                int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue);
                gd.setColor(bgColor);
                if (hasCornerRadii) {
                    float radii[] = new float[8];
                    for (int i = 0; i < CORNERS.length; i++) {
                        String corner = CORNERS[i];
                        if (attrs.containsKey("cornerRadius" + corner)) {
                            radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension(
                                    attrs.get("cornerRadius" + corner),
                                    view.getResources().getDisplayMetrics());
                        }
                        gd.setCornerRadii(radii);
                    }
                } else if (hasCornerRadius) {
                    float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"),
                            view.getResources().getDisplayMetrics());
                    gd.setCornerRadius(cornerRadius);
                }
                if (attrs.containsKey("borderColor")) {
                    String borderWidth = "1dp";
                    if (attrs.containsKey("borderWidth")) {
                        borderWidth = attrs.get("borderWidth");
                    }
                    gd.setStroke(
                            DimensionConverter.stringToDimensionPixelSize(borderWidth,
                                    view.getResources().getDisplayMetrics()),
                            parseColor(view, attrs.get("borderColor")));
                }
                view.setBackground(gd);
                getDynamicLayoutInfo(view).bgDrawable = gd;
            } else {
                view.setBackgroundColor(parseColor(view, bgValue));
            }
        }
    }

    if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
        ((ViewGroup.MarginLayoutParams) layoutParams).setMargins(marginLeft, marginTop, marginRight,
                marginBottom);
    }
    view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    view.setLayoutParams(layoutParams);
}

From source file:org.appcelerator.titanium.view.TiUIView.java

/**
 * Sets the nativeView to view.//from   w  w w .ja  v a2s.co  m
 * @param view the view to set
 * @module.api
 */
protected void setNativeView(View view) {
    if (view.getId() == View.NO_ID) {
        view.setId(idGenerator.incrementAndGet());
    }
    this.nativeView = view;
    boolean clickable = true;

    if (proxy.hasProperty(TiC.PROPERTY_TOUCH_ENABLED)) {
        clickable = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_TOUCH_ENABLED));
    }
    doSetClickable(nativeView, clickable);
    nativeView.setOnFocusChangeListener(this);

    applyAccessibilityProperties();
}

From source file:com.wit.and.dialog.internal.BaseDialog.java

/**
 *///from   w  w  w  .jav  a  2  s  . com
@Override
public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the dialog main view.
    View dialogView = onCreateDialogView(inflater, container, savedInstanceState);

    // Check valid dialog view.
    if (dialogView == null) {
        Log.e(TAG, "Dialog layout or dialog view not inflated correctly.");

        return super.onCreateView(inflater, container, savedInstanceState);
    } else {
        // Save inflater for later usage.
        this.mInflater = inflater;

        // Build dialog view.
        this.buildDialogView(dialogView, inflater, savedInstanceState);

        // Mark our created view.
        if (dialogView.getId() != View.NO_ID) {
            this.mDialogViewID = dialogView.getId();
        } else {
            dialogView.setId(mDialogViewID);
        }

        // Return inflated dialog view.
        return dialogView;
    }
}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

private void updateItems(final BottomBarItemBase[] bottomBarItems) {
    if (mItemContainer == null) {
        initializeViews();// ww w . j  a va 2 s  .c  o  m
    }

    int index = 0;
    int biggestWidth = 0;

    mIsShiftingMode = MAX_FIXED_TAB_COUNT < bottomBarItems.length;

    if (!mIsDarkTheme && !mIgnoreNightMode && MiscUtils.isNightMode(mContext)) {
        mIsDarkTheme = true;
    }

    if (!mIsTabletMode && mIsShiftingMode) {
        mDefaultBackgroundColor = mCurrentBackgroundColor = mPrimaryColor;
        mBackgroundView.setBackgroundColor(mDefaultBackgroundColor);

        if (mContext instanceof Activity) {
            navBarMagic((Activity) mContext, this);
        }
    } else if (mIsDarkTheme) {
        darkThemeMagic();
    }

    View[] viewsToAdd = new View[bottomBarItems.length];

    for (BottomBarItemBase bottomBarItemBase : bottomBarItems) {
        int layoutResource;

        if (mIsShiftingMode && !mIsTabletMode) {
            layoutResource = R.layout.bb_bottom_bar_item_shifting;
        } else {
            layoutResource = mIsTabletMode ? R.layout.bb_bottom_bar_item_fixed_tablet
                    : R.layout.bb_bottom_bar_item_fixed;
        }

        View bottomBarTab = View.inflate(mContext, layoutResource, null);
        ImageView icon = (ImageView) bottomBarTab.findViewById(R.id.bb_bottom_bar_icon);

        icon.setImageDrawable(bottomBarItemBase.getIcon(mContext));

        if (!mIsTabletMode) {
            TextView title = (TextView) bottomBarTab.findViewById(R.id.bb_bottom_bar_title);
            title.setText(bottomBarItemBase.getTitle(mContext));

            if (mPendingTextAppearance != -1) {
                MiscUtils.setTextAppearance(title, mPendingTextAppearance);
            }

            if (mPendingTypeface != null) {
                title.setTypeface(mPendingTypeface);
            }
        }

        if (mIsDarkTheme || (!mIsTabletMode && mIsShiftingMode)) {
            icon.setColorFilter(mWhiteColor);
        }

        if (bottomBarItemBase instanceof BottomBarTab) {
            bottomBarTab.setId(((BottomBarTab) bottomBarItemBase).id);
        }

        if (index == mCurrentTabPosition) {
            selectTab(bottomBarTab, false);
        } else {
            unselectTab(bottomBarTab, false);
        }

        if (!mIsTabletMode) {
            if (bottomBarTab.getWidth() > biggestWidth) {
                biggestWidth = bottomBarTab.getWidth();
            }

            viewsToAdd[index] = bottomBarTab;
        } else {
            mItemContainer.addView(bottomBarTab);
        }

        bottomBarTab.setOnClickListener(this);
        bottomBarTab.setOnLongClickListener(this);
        index++;
    }

    if (!mIsTabletMode) {
        int proposedItemWidth = Math.min(MiscUtils.dpToPixel(mContext, mScreenWidth / bottomBarItems.length),
                mMaxFixedItemWidth);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(proposedItemWidth,
                LinearLayout.LayoutParams.WRAP_CONTENT);

        for (View bottomBarView : viewsToAdd) {
            bottomBarView.setLayoutParams(params);
            mItemContainer.addView(bottomBarView);
        }
    }

    if (mPendingTextAppearance != -1) {
        mPendingTextAppearance = -1;
    }

    if (mPendingTypeface != null) {
        mPendingTypeface = null;
    }
}