Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

In this page you can find the example usage for android.widget LinearLayout addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.activiti.android.ui.fragments.task.TaskDetailsFoundationFragment.java

protected void displayCheckList(List<TaskRepresentation> taskRepresentations) {
    if (getVersionNumber() < ActivitiVersionNumber.VERSION_1_3_0) {
        hide(R.id.task_details_checklist_card);
        return;/*  ww  w .j  a va 2 s  .  c om*/
    }

    show(R.id.task_details_checklist_card);
    if (taskRepresentations == null || taskRepresentations.isEmpty() || isEnded) {
        hide(R.id.task_details_checklist_card);
        return;
    }

    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // TASKS
    LinearLayout activeTaskContainer = (LinearLayout) viewById(R.id.task_details_checklist_container);
    activeTaskContainer.removeAllViews();
    View v;
    if (taskRepresentations == null || taskRepresentations.isEmpty()) {
        v = inflater.inflate(R.layout.row_single_line, activeTaskContainer, false);
        ((TextView) v.findViewById(R.id.toptext)).setText(R.string.task_help_add_first_checklist);
        HolderUtils.makeMultiLine(((TextView) v.findViewById(R.id.toptext)), 4);
        v.findViewById(R.id.icon).setVisibility(View.GONE);
        activeTaskContainer.addView(v);
    } else {
        TaskRepresentation taskCheckList;
        TwoLinesViewHolder vh;
        int max = (taskRepresentations.size() > TASKS_MAX_ITEMS) ? TASKS_MAX_ITEMS : taskRepresentations.size();
        for (int i = 0; i < max; i++) {
            taskCheckList = taskRepresentations.get(i);
            v = inflater.inflate(R.layout.row_three_lines_caption_borderless, activeTaskContainer, false);
            v.setTag(taskCheckList);

            vh = HolderUtils.configure(v, taskCheckList.getName(), null,
                    TaskAdapter.createAssigneeInfo(getActivity(), taskCheckList),
                    TaskAdapter.createRelativeDateInfo(getActivity(), taskCheckList),
                    R.drawable.ic_account_circle_grey);

            if (taskCheckList.getEndDate() != null) {
                vh.choose.setImageResource(R.drawable.ic_done_grey);
            } else {
                vh.choose.setImageResource(android.R.color.transparent);
            }
            vh.choose.setVisibility(View.VISIBLE);

            activeTaskContainer.addView(v);

            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    TaskDetailsFragment.with(getActivity()).task((TaskRepresentation) v.getTag())
                            .bindFragmentTag(getTag()).back(true).display();
                }
            });
        }
    }
}

From source file:info.semanticsoftware.semassist.android.activity.SemanticAssistantsActivity.java

/** Presents additional information about a specific assistant.
 * @return a dynamically generated linear layout
 *//*from   www  .ja  v a  2 s .  c  o  m*/
private LinearLayout getServiceDescLayout() {
    final LinearLayout output = new LinearLayout(this);
    final RelativeLayout topButtonsLayout = new RelativeLayout(this);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    final Button btnBack = new Button(this);
    btnBack.setText(R.string.btnAllServices);
    btnBack.setId(5);
    btnBack.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            output.setVisibility(View.GONE);
            getListView().setVisibility(View.VISIBLE);
            lblAvAssist.setVisibility(View.VISIBLE);
        }
    });

    topButtonsLayout.addView(btnBack);

    final Button btnInvoke = new Button(this);
    btnInvoke.setText(R.string.btnInvokeLabel);
    btnInvoke.setId(6);

    btnInvoke.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new InvocationTask().execute();
        }
    });

    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, btnInvoke.getId());
    btnInvoke.setLayoutParams(layoutParams);
    topButtonsLayout.addView(btnInvoke);

    output.addView(topButtonsLayout);

    TableLayout serviceInfoTbl = new TableLayout(this);
    output.addView(serviceInfoTbl);

    serviceInfoTbl.setColumnShrinkable(1, true);

    /* FIRST ROW */
    TableRow rowServiceName = new TableRow(this);

    TextView lblServiceName = new TextView(this);
    lblServiceName.setText(R.string.lblServiceName);
    lblServiceName.setTextAppearance(getApplicationContext(), R.style.titleText);

    TextView txtServiceName = new TextView(this);
    txtServiceName.setText(selectedService);
    txtServiceName.setTextAppearance(getApplicationContext(), R.style.normalText);
    txtServiceName.setPadding(10, 0, 0, 0);

    rowServiceName.addView(lblServiceName);
    rowServiceName.addView(txtServiceName);

    /* SECOND ROW */
    TableRow rowServiceDesc = new TableRow(this);

    TextView lblServiceDesc = new TextView(this);
    lblServiceDesc.setText(R.string.lblServiceDesc);
    lblServiceDesc.setTextAppearance(getApplicationContext(), R.style.titleText);

    TextView txtServiceDesc = new TextView(this);
    txtServiceDesc.setTextAppearance(getApplicationContext(), R.style.normalText);
    txtServiceDesc.setPadding(10, 0, 0, 0);
    List<GateRuntimeParameter> params = null;
    ServiceInfoForClientArray list = getServices();
    for (int i = 0; i < list.getItem().size(); i++) {
        if (list.getItem().get(i).getServiceName().equals(selectedService)) {
            txtServiceDesc.setText(list.getItem().get(i).getServiceDescription());
            params = list.getItem().get(i).getParams();
            break;
        }
    }

    TextView lblParams = new TextView(this);
    lblParams.setText(R.string.lblServiceParams);
    lblParams.setTextAppearance(getApplicationContext(), R.style.titleText);
    output.addView(lblParams);

    LayoutParams txtParamsAttrbs = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    LinearLayout paramsLayout = new LinearLayout(this);
    paramsLayout.setId(0);

    if (params.size() > 0) {
        ScrollView scroll = new ScrollView(this);
        scroll.setLayoutParams(txtParamsAttrbs);
        paramsLayout.setOrientation(LinearLayout.VERTICAL);
        scroll.addView(paramsLayout);
        for (int j = 0; j < params.size(); j++) {
            TextView lblParamName = new TextView(this);
            lblParamName.setText(params.get(j).getParamName());
            EditText tview = new EditText(this);
            tview.setId(1);
            tview.setText(params.get(j).getDefaultValueString());
            LayoutParams txtViewLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT);
            tview.setLayoutParams(txtViewLayoutParams);
            paramsLayout.addView(lblParamName);
            paramsLayout.addView(tview);
        }
        output.addView(scroll);
    } else {
        TextView lblParamName = new TextView(this);
        lblParamName.setText(R.string.lblRTParams);
        output.addView(lblParamName);
    }

    rowServiceDesc.addView(lblServiceDesc);
    rowServiceDesc.addView(txtServiceDesc);

    serviceInfoTbl.addView(rowServiceName);
    serviceInfoTbl.addView(rowServiceDesc);

    output.setOrientation(LinearLayout.VERTICAL);
    output.setGravity(Gravity.TOP);

    return output;
}

From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java

private void createMapLayerSelectionDialog() {
    if (layersAndVisibility == null) {
        getLayersAndVisibility();//from  www .j a va 2s .  c o m
    }

    final Dialog dialog = dialogInterface.getDialog(getActivity(), R.layout.dialog_select_map_layers,
            R.string.choose_map_layers);
    Button okButton = (Button) dialog.findViewById(R.id.select_map_layers_update_map_button);
    final List<CheckBoxRow> rows = new ArrayList<>();
    final LinearLayout mapLayerLayout = (LinearLayout) dialog.findViewById(R.id.map_layers_checkbox_layout);
    final Button cancelButton = (Button) dialog.findViewById(R.id.select_map_layers_cancel_button);
    LayerAndVisibility[] layers = new Gson().fromJson(layersAndVisibility.toString(),
            LayerAndVisibility[].class);
    for (LayerAndVisibility layer : layers) {
        if (layer.name.equals("Grunnkart") || layer.name.contains("OpenLayers_Control")) {
            continue;
        }
        boolean isActive;
        isActive = layer.isVisible;

        CheckBoxRow row = rowsInterface.getCheckBoxRow(getActivity(), layer.name, false, isActive);
        rows.add(row);
        View mapLayerRow = row.getView();
        mapLayerLayout.addView(mapLayerRow);
    }

    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            List<String> layersList = new ArrayList<>();
            layersList.add("Grunnkart");

            for (int i = 0; i < mapLayerLayout.getChildCount(); i++) {
                if (rows.get(i).isChecked()) {
                    layersList.add(rows.get(i).getText());
                }
            }

            user.setActiveLayers(layersList);
            user.writeToSharedPref(getActivity());
            dialog.dismiss();

            if (layersList.contains(getString(R.string.fishing_facility_name))
                    && !user.getIsFishingFacilityAuthenticated()) {
                dialogInterface.getHyperlinkAlertDialog(getActivity(),
                        getString(R.string.about_fishing_facility_title),
                        getString(R.string.about_fishing_facility_details)).show();
            }

            JSONArray json = new JSONArray(layersList);
            browser.loadUrl("javascript:toggleLayers(" + json + ")");

            getLayersAndVisibility();
        }
    });

    cancelButton.setOnClickListener(onClickListenerInterface.getDismissDialogListener(dialog));

    dialog.show();
}

From source file:com.android.nsboc.ComposeFragment.java

public CompoundButton.OnCheckedChangeListener getNextToggleListener(final LinearLayout complianceLayout) {
    return new CompoundButton.OnCheckedChangeListener() {
        @Override/*from   ww w . jav a2s.  c  o  m*/
        public void onCheckedChanged(CompoundButton toggleButton, boolean isChecked) {
            if (isChecked) {

                mAnotherComplianceLayout = (LinearLayout) View.inflate(getActivity(),
                        R.layout.compliance_layout, null);

                TextView imagePickerLabel = (TextView) mAnotherComplianceLayout
                        .findViewById(R.id.violation_image_picker);
                imagePickerLabel.setText(imagePickerLabel.getText().toString().replace(" " + mSectionsCount,
                        " " + (mSectionsCount + 1)));

                EditText commentEditText = (EditText) mAnotherComplianceLayout
                        .findViewById(R.id.comment_edittext);
                commentEditText.setHint(commentEditText.getText().toString().replace(" " + mSectionsCount,
                        " " + (mSectionsCount + 1)));

                TextView isAnotherLabel = (TextView) mAnotherComplianceLayout
                        .findViewById(R.id.is_another_label);
                isAnotherLabel.setText(isAnotherLabel.getText().toString().replace((mSectionsCount + 1) + "?",
                        (mSectionsCount + 2) + "?"));

                ToggleButton anotherToggle = (ToggleButton) mAnotherComplianceLayout
                        .findViewById(R.id.compliance_toggle);
                anotherToggle.setOnCheckedChangeListener(getNextToggleListener(mAnotherComplianceLayout));

                complianceLayout.addView(mAnotherComplianceLayout);
                mSectionsCount++;
            } else {
                mSectionsCount--;
                mAnotherComplianceLayout.setVisibility(View.GONE);
            }
        }
    };
}

From source file:ca.appvelopers.mcgillmobile.ui.ScheduleActivity.java

/**
 * Fills the schedule based on given data
 *
 * @param timetableContainer Container for the timetable
 * @param scheduleContainer  Container for the schedule
 * @param date               Date to fill the schedule for
 * @param clickable          True if the user can click on the courses (portrait),
 *                           false otherwise (landscape)
 *//*from  w  w w . j  a va  2  s  .  co m*/
private void fillSchedule(LinearLayout timetableContainer, LinearLayout scheduleContainer, LocalDate date,
        boolean clickable) {
    //Go through the list of courses, find which ones are for the given date
    List<Course> courses = new ArrayList<>();
    for (Course course : this.courses) {
        if (course.isForDate(date)) {
            courses.add(course);
        }
    }

    //Set up the DateTimeFormatter we're going to use for the hours
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(twentyFourHourPref.get() ? "HH:mm" : "hh a");

    //This will be used of an end time of a course when it is added to the schedule container
    LocalTime currentCourseEndTime = null;

    //Cycle through the hours
    for (int hour = 8; hour < 22; hour++) {
        //Start inflating a timetable cell
        View timetableCell = View.inflate(this, R.layout.item_day_timetable, null);

        //Put the correct time
        TextView time = (TextView) timetableCell.findViewById(R.id.cell_time);
        time.setText(LocalTime.MIDNIGHT.withHour(hour).format(formatter));

        //Add it to the right container
        timetableContainer.addView(timetableCell);

        //Cycle through the half hours
        for (int min = 0; min < 31; min += 30) {
            //Initialize the current course to null
            Course currentCourse = null;

            //Get the current time
            LocalTime currentTime = LocalTime.of(hour, min);

            //if currentCourseEndTime = null (no course is being added) or it is equal to
            //the current time in min (end of a course being added) we need to add a new view
            if (currentCourseEndTime == null || currentCourseEndTime.equals(currentTime)) {
                //Reset currentCourseEndTime
                currentCourseEndTime = null;

                //Check if there is a course at this time
                for (Course course : courses) {
                    //If there is, set the current course to that time, and calculate the
                    //ending time of this course
                    if (course.getRoundedStartTime().equals(currentTime)) {
                        currentCourse = course;
                        currentCourseEndTime = course.getRoundedEndTime();
                        break;
                    }
                }

                View scheduleCell;

                //There is a course at this time
                if (currentCourse != null) {
                    //Inflate the right view
                    scheduleCell = View.inflate(this, R.layout.item_day_class, null);

                    //Set up all of the info
                    TextView code = (TextView) scheduleCell.findViewById(R.id.course_code);
                    code.setText(currentCourse.getCode());

                    TextView type = (TextView) scheduleCell.findViewById(R.id.course_type);
                    type.setText(currentCourse.getType());

                    TextView courseTime = (TextView) scheduleCell.findViewById(R.id.course_time);
                    courseTime.setText(currentCourse.getTimeString());

                    TextView location = (TextView) scheduleCell.findViewById(R.id.course_location);
                    location.setText(currentCourse.getLocation());

                    //Find out how long this course is in terms of blocks of 30 min
                    int length = (int) ChronoUnit.MINUTES.between(currentCourse.getRoundedStartTime(),
                            currentCourse.getRoundedEndTime()) / 30;

                    //Set the height of the view depending on this height
                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.MATCH_PARENT,
                            (int) getResources().getDimension(R.dimen.cell_30min_height) * length);
                    scheduleCell.setLayoutParams(lp);

                    //Check if we need to make the course clickable
                    if (clickable) {
                        //We need a final variable for the onClick listener
                        final Course course = currentCourse;
                        //OnClick: CourseActivity (for a detailed description of the course)
                        scheduleCell.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                showCourseDialog(course);
                            }
                        });
                    } else {
                        scheduleCell.setClickable(false);
                    }

                } else {
                    //Inflate the empty view
                    scheduleCell = View.inflate(this, R.layout.item_day_empty, null);
                }

                //Add the given view to the schedule container
                scheduleContainer.addView(scheduleCell);
            }
        }
    }
}

From source file:com.farmerbb.taskbar.service.DashboardService.java

@SuppressLint("RtlHardcoded")
private void drawDashboard() {
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            PixelFormat.TRANSLUCENT);/*from  w  w w .j a va2  s. c  o m*/

    // Initialize views
    layout = new LinearLayout(this);
    layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    layout.setVisibility(View.GONE);
    layout.setAlpha(0);

    SharedPreferences pref = U.getSharedPreferences(this);
    int width = pref.getInt("dashboard_width",
            getApplicationContext().getResources().getInteger(R.integer.dashboard_width));
    int height = pref.getInt("dashboard_height",
            getApplicationContext().getResources().getInteger(R.integer.dashboard_height));

    boolean isPortrait = getApplicationContext().getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    boolean isLandscape = getApplicationContext().getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

    if (isPortrait) {
        columns = height;
        rows = width;
    }

    if (isLandscape) {
        columns = width;
        rows = height;
    }

    maxSize = columns * rows;

    int backgroundTint = U.getBackgroundTint(this);
    int accentColor = U.getAccentColor(this);
    int accentColorAlt = accentColor;
    accentColorAlt = ColorUtils.setAlphaComponent(accentColorAlt, Color.alpha(accentColorAlt) / 2);

    int cellCount = 0;

    for (int i = 0; i < columns; i++) {
        LinearLayout layout2 = new LinearLayout(this);
        layout2.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, 1));
        layout2.setOrientation(LinearLayout.VERTICAL);

        for (int j = 0; j < rows; j++) {
            DashboardCell cellLayout = (DashboardCell) View.inflate(this, R.layout.dashboard, null);
            cellLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT, 1));
            cellLayout.setBackgroundColor(backgroundTint);
            cellLayout.setOnClickListener(cellOcl);
            cellLayout.setOnHoverListener(cellOhl);

            TextView empty = (TextView) cellLayout.findViewById(R.id.empty);
            empty.setBackgroundColor(accentColorAlt);
            empty.setTextColor(accentColor);

            Bundle bundle = new Bundle();
            bundle.putInt("cellId", cellCount);

            cellLayout.setTag(bundle);
            cells.put(cellCount, cellLayout);
            cellCount++;

            layout2.addView(cellLayout);
        }

        layout.addView(layout2);
    }

    mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetHost = new AppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    for (int i = 0; i < maxSize; i++) {
        int appWidgetId = pref.getInt("dashboard_widget_" + Integer.toString(i), -1);
        if (appWidgetId != -1)
            addWidget(appWidgetId, i, false);
        else if (pref.getBoolean("dashboard_widget_" + Integer.toString(i) + "_placeholder", false))
            addPlaceholder(i);
    }

    mAppWidgetHost.stopListening();

    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(addWidgetReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(removeWidgetReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver);

    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiver,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_DASHBOARD"));
    LocalBroadcastManager.getInstance(this).registerReceiver(addWidgetReceiver,
            new IntentFilter("com.farmerbb.taskbar.ADD_WIDGET_COMPLETED"));
    LocalBroadcastManager.getInstance(this).registerReceiver(removeWidgetReceiver,
            new IntentFilter("com.farmerbb.taskbar.REMOVE_WIDGET_COMPLETED"));
    LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver,
            new IntentFilter("com.farmerbb.taskbar.HIDE_DASHBOARD"));

    windowManager.addView(layout, params);

    new Handler().postDelayed(() -> {
        int paddingSize = getResources().getDimensionPixelSize(R.dimen.icon_size);

        switch (U.getTaskbarPosition(DashboardService.this)) {
        case "top_vertical_left":
        case "bottom_vertical_left":
            layout.setPadding(paddingSize, 0, 0, 0);
            break;
        case "top_left":
        case "top_right":
            layout.setPadding(0, paddingSize, 0, 0);
            break;
        case "top_vertical_right":
        case "bottom_vertical_right":
            layout.setPadding(0, 0, paddingSize, 0);
            break;
        case "bottom_left":
        case "bottom_right":
            layout.setPadding(0, 0, 0, paddingSize);
            break;
        }
    }, 100);
}

From source file:com.gh4a.IssueActivity.java

private void fillData() {
    new LoadCommentsTask(this).execute();

    Typeface boldCondensed = getApplicationContext().boldCondensed;

    ListView lvComments = (ListView) findViewById(R.id.list_view);
    // set details inside listview header
    LayoutInflater infalter = getLayoutInflater();
    LinearLayout mHeader = (LinearLayout) infalter.inflate(R.layout.issue_header, lvComments, false);
    mHeader.setClickable(false);//from w  w w.j av a2 s.c  o m

    lvComments.addHeaderView(mHeader, null, false);

    RelativeLayout rlComment = (RelativeLayout) findViewById(R.id.rl_comment);
    if (!isAuthorized()) {
        rlComment.setVisibility(View.GONE);
    }

    TextView tvCommentTitle = (TextView) mHeader.findViewById(R.id.comment_title);
    mCommentAdapter = new CommentAdapter(IssueActivity.this, new ArrayList<Comment>(), mIssue.getNumber(),
            mIssue.getState(), mRepoOwner, mRepoName);
    lvComments.setAdapter(mCommentAdapter);

    ImageView ivGravatar = (ImageView) mHeader.findViewById(R.id.iv_gravatar);
    aq.id(R.id.iv_gravatar).image(GravatarUtils.getGravatarUrl(mIssue.getUser().getGravatarId()), true, false,
            0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN);

    ivGravatar.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getUser().getLogin(), null);
        }
    });

    TextView tvExtra = (TextView) mHeader.findViewById(R.id.tv_extra);
    TextView tvState = (TextView) mHeader.findViewById(R.id.tv_state);
    TextView tvTitle = (TextView) mHeader.findViewById(R.id.tv_title);
    TextView tvDescTitle = (TextView) mHeader.findViewById(R.id.desc_title);
    tvDescTitle.setTypeface(getApplicationContext().boldCondensed);
    tvDescTitle.setTextColor(Color.parseColor("#0099cc"));

    tvCommentTitle.setTypeface(getApplicationContext().boldCondensed);
    tvCommentTitle.setTextColor(Color.parseColor("#0099cc"));
    tvCommentTitle
            .setText(getResources().getString(R.string.issue_comments) + " (" + mIssue.getComments() + ")");

    TextView tvDesc = (TextView) mHeader.findViewById(R.id.tv_desc);
    tvDesc.setMovementMethod(LinkMovementMethod.getInstance());

    TextView tvMilestone = (TextView) mHeader.findViewById(R.id.tv_milestone);

    ImageView ivComment = (ImageView) findViewById(R.id.iv_comment);
    if (Gh4Application.THEME == R.style.DefaultTheme) {
        ivComment.setImageResource(R.drawable.social_send_now_dark);
    }
    ivComment.setBackgroundResource(R.drawable.abs__list_selector_holo_dark);
    ivComment.setPadding(5, 2, 5, 2);
    ivComment.setOnClickListener(this);

    tvExtra.setText(mIssue.getUser().getLogin() + "\n" + pt.format(mIssue.getCreatedAt()));
    tvState.setTextColor(Color.WHITE);
    if ("closed".equals(mIssue.getState())) {
        tvState.setBackgroundResource(R.drawable.default_red_box);
        tvState.setText("C\nL\nO\nS\nE\nD");
    } else {
        tvState.setBackgroundResource(R.drawable.default_green_box);
        tvState.setText("O\nP\nE\nN");
    }
    tvTitle.setText(mIssue.getTitle());
    tvTitle.setTypeface(boldCondensed);

    boolean showInfoBox = false;
    if (mIssue.getAssignee() != null) {
        showInfoBox = true;
        TextView tvAssignee = (TextView) mHeader.findViewById(R.id.tv_assignee);
        tvAssignee.setText(mIssue.getAssignee().getLogin() + " is assigned");
        tvAssignee.setVisibility(View.VISIBLE);
        tvAssignee.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                getApplicationContext().openUserInfoActivity(IssueActivity.this,
                        mIssue.getAssignee().getLogin(), null);
            }
        });

        ImageView ivAssignee = (ImageView) mHeader.findViewById(R.id.iv_assignee);

        aq.id(R.id.iv_assignee).image(GravatarUtils.getGravatarUrl(mIssue.getAssignee().getGravatarId()), true,
                false, 0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN);

        ivAssignee.setVisibility(View.VISIBLE);
        ivAssignee.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                getApplicationContext().openUserInfoActivity(IssueActivity.this,
                        mIssue.getAssignee().getLogin(), null);
            }
        });
    }

    if (mIssue.getMilestone() != null) {
        showInfoBox = true;
        tvMilestone.setText(
                getResources().getString(R.string.issue_milestone) + ": " + mIssue.getMilestone().getTitle());
    } else {
        tvMilestone.setVisibility(View.GONE);
    }

    String body = mIssue.getBodyHtml();
    if (!StringUtils.isBlank(body)) {
        HttpImageGetter imageGetter = new HttpImageGetter(this);
        body = HtmlUtils.format(body).toString();
        imageGetter.bind(tvDesc, body, mIssue.getNumber());
    }

    LinearLayout llLabels = (LinearLayout) findViewById(R.id.ll_labels);
    List<Label> labels = mIssue.getLabels();

    if (labels != null && !labels.isEmpty()) {
        showInfoBox = true;
        for (Label label : labels) {
            TextView tvLabel = new TextView(this);
            tvLabel.setSingleLine(true);
            tvLabel.setText(label.getName());
            tvLabel.setTextAppearance(this, R.style.default_text_small);
            tvLabel.setBackgroundColor(Color.parseColor("#" + label.getColor()));
            tvLabel.setPadding(5, 2, 5, 2);
            int r = Color.red(Color.parseColor("#" + label.getColor()));
            int g = Color.green(Color.parseColor("#" + label.getColor()));
            int b = Color.blue(Color.parseColor("#" + label.getColor()));
            if (r + g + b < 383) {
                tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_dark));
            } else {
                tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_light));
            }
            llLabels.addView(tvLabel);

            View v = new View(this);
            v.setLayoutParams(new LayoutParams(5, LayoutParams.WRAP_CONTENT));
            llLabels.addView(v);
        }
    } else {
        llLabels.setVisibility(View.GONE);
    }

    TextView tvPull = (TextView) mHeader.findViewById(R.id.tv_pull);
    if (mIssue.getPullRequest() != null && mIssue.getPullRequest().getDiffUrl() != null) {
        showInfoBox = true;
        tvPull.setVisibility(View.VISIBLE);
        tvPull.setOnClickListener(this);
    }

    if (!showInfoBox) {
        RelativeLayout rl = (RelativeLayout) mHeader.findViewById(R.id.info_box);
        rl.setVisibility(View.GONE);
    }
}

From source file:com.flipzu.flipzu.Recorder.java

public void showFlipzuTipsOffline(LinearLayout cc, LayoutParams params, String msg) {
    final float scale = getResources().getDisplayMetrics().density;
    final int pixel_5 = 5 / (int) (scale + 0.5f);

    LinearLayout cl = new LinearLayout(Recorder.this);
    cl.setOrientation(LinearLayout.HORIZONTAL);
    cl.setPadding(0, 0, 0, pixel_5);/*from   w  ww . j a  v a  2  s.  c om*/

    /* comment */
    String tips_username = "Flipzu Tips";

    TextView comment_tv = new TextView(Recorder.this);
    comment_tv.setLayoutParams(params);
    comment_tv.setText(tips_username + ": " + msg, TextView.BufferType.SPANNABLE);
    comment_tv.setTextColor(Color.parseColor("#656565"));
    Spannable comment_span = (Spannable) comment_tv.getText();
    comment_span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, comment_tv.getText().length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    comment_span.setSpan(new ForegroundColorSpan(Color.parseColor("#182e5b")), 0, tips_username.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    comment_tv.setText(comment_span);
    cl.addView(comment_tv);

    cc.addView(cl);
}

From source file:com.brodev.socialapp.view.MarketPlaceDetail.java

private void initView() {

    ImageView userImage = (ImageView) this.findViewById(R.id.image_user);

    if (!"".equals(marketPlace.getUser_image_path())) {
        networkUntil.drawImageUrl(userImage, marketPlace.getUser_image_path(), R.drawable.loading);
    }/*  ww w . ja  v a  2s . c om*/

    userImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    // set title
    TextView title = (TextView) this.findViewById(R.id.title);
    title.setText(marketPlace.getTitle());
    colorView.changeColorText(title, user.getColor());

    // set content
    TextView content = (TextView) this.findViewById(R.id.content);

    // interesting part starts from here here:
    Html.ImageGetter ig = imageGetter.create(0, marketPlace.getText(), content);

    content.setTag(0);
    content.setText(Html.fromHtml(marketPlace.getText(), ig, null));

    TextView timestampTxt = (TextView) findViewById(R.id.txtTimestamp);
    timestampTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_on"));
    TextView timestamp = (TextView) findViewById(R.id.time_stamp);
    timestamp.setText(marketPlace.getTime_stamp());
    TextView price = (TextView) this.findViewById(R.id.price);

    if (marketPlace.getPrice() == 0) {
        price.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.free"));
    } else {
        price.setText(marketPlace.getCurrency() + " " + marketPlace.getPrice());
    }

    TextView locationTxt = (TextView) findViewById(R.id.txtLocation);
    locationTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.location"));
    TextView txtLocation = (TextView) this.findViewById(R.id.location);
    String location = marketPlace.getCountry_name();

    if (!marketPlace.getCountry_child_name().equals("")) {
        location += " > " + marketPlace.getCountry_child_name();
    }
    if (!marketPlace.getCity_name().equals("")) {
        location += " > " + marketPlace.getCity_name();
    }

    txtLocation.setText(location);
    // set short text
    TextView fullnameTxt = (TextView) findViewById(R.id.txtFullname);
    fullnameTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_by"));

    TextView shortText = (TextView) findViewById(R.id.fullName);
    shortText.setText(marketPlace.getFull_name());
    colorView.changeColorText(shortText, user.getColor());

    shortText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    TextView total_like = (TextView) findViewById(R.id.total_like);
    total_like.setText(String.valueOf(marketPlace.getTotal_like()));
    colorView.changeColorText(total_like, user.getColor());

    TextView total_comment = (TextView) findViewById(R.id.total_comment);
    total_comment.setText(String.valueOf(marketPlace.getTotal_comment()));
    colorView.changeColorText(total_comment, user.getColor());

    ImageView likeImg = (ImageView) this.findViewById(R.id.likes_feed_txt);
    ImageView commentImg = (ImageView) this.findViewById(R.id.comments_feed_txt);
    colorView.changeColorLikeCommnent(likeImg, commentImg, user.getColor());

    //get list images
    if (!marketPlace.getImages().equals("")) {
        LinearLayout listImages = (LinearLayout) findViewById(R.id.listImages);
        JSONObject objOutputImage = null;
        try {
            JSONArray objImages = new JSONArray(marketPlace.getImages());
            for (int i = 0; i < objImages.length(); i++) {
                objOutputImage = objImages.getJSONObject(i);
                ImageView imageView = new ImageView(getApplicationContext());

                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        (int) getResources().getDimension(R.dimen.marketplace_image),
                        (int) getResources().getDimension(R.dimen.marketplace_image));

                lp.setMargins(5, 5, 5, 0);

                imageView.setLayoutParams(lp);

                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                final String imagePath = objOutputImage.getString("image_path");
                networkUntil.drawImageUrl(imageView, imagePath, R.drawable.loading);

                imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getApplicationContext(), ImageActivity.class);
                        intent.putExtra("image", imagePath);
                        intent.putExtra("title", marketPlace.getTitle());
                        startActivity(intent);
                    }
                });

                listImages.addView(imageView);

            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        this.findViewById(R.id.horizontalScrollView1).setVisibility(View.GONE);
        this.findViewById(R.id.marketplace_list_image_view).setVisibility(View.GONE);
    }

}