Example usage for android.graphics Typeface BOLD

List of usage examples for android.graphics Typeface BOLD

Introduction

In this page you can find the example usage for android.graphics Typeface BOLD.

Prototype

int BOLD

To view the source code for android.graphics Typeface BOLD.

Click Source Link

Usage

From source file:com.tengio.FloatingSearchView.java

/**
 * Sets the font in the search text field
 *
 * @param fontPath font path in the assets folder
 *///w w  w.  ja v  a2s . c  o m
public void setFont(String fontPath) {
    if (TextUtils.isEmpty(fontPath)) {
        return;
    }
    Typeface tf = Typeface.createFromAsset(getContext().getAssets(), fontPath);
    if (tf == null) {
        return;
    }
    mSearchInput.setTypeface(tf, Typeface.BOLD);
}

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

public static void createViewRunnables() {
    viewRunnables = new HashMap<>(30);
    viewRunnables.put("scaleType", new ViewParamRunnable() {
        @Override//from  w  w w.  j a v a 2s. co  m
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof ImageView) {
                ImageView.ScaleType scaleType = ((ImageView) view).getScaleType();
                switch (value.toLowerCase()) {
                case "center":
                    scaleType = ImageView.ScaleType.CENTER;
                    break;
                case "center_crop":
                    scaleType = ImageView.ScaleType.CENTER_CROP;
                    break;
                case "center_inside":
                    scaleType = ImageView.ScaleType.CENTER_INSIDE;
                    break;
                case "fit_center":
                    scaleType = ImageView.ScaleType.FIT_CENTER;
                    break;
                case "fit_end":
                    scaleType = ImageView.ScaleType.FIT_END;
                    break;
                case "fit_start":
                    scaleType = ImageView.ScaleType.FIT_START;
                    break;
                case "fit_xy":
                    scaleType = ImageView.ScaleType.FIT_XY;
                    break;
                case "matrix":
                    scaleType = ImageView.ScaleType.MATRIX;
                    break;
                }
                ((ImageView) view).setScaleType(scaleType);
            }
        }
    });
    viewRunnables.put("orientation", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof LinearLayout) {
                ((LinearLayout) view).setOrientation(
                        value.equals("vertical") ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL);
            }
        }
    });
    viewRunnables.put("text", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                ((TextView) view).setText(value);
            }
        }
    });
    viewRunnables.put("textSize", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX,
                        DimensionConverter.stringToDimension(value, view.getResources().getDisplayMetrics()));
            }
        }
    });
    viewRunnables.put("textColor", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                ((TextView) view).setTextColor(parseColor(view, value));
            }
        }
    });
    viewRunnables.put("textStyle", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                int typeFace = Typeface.NORMAL;
                if (value.contains("bold"))
                    typeFace |= Typeface.BOLD;
                else if (value.contains("italic"))
                    typeFace |= Typeface.ITALIC;
                ((TextView) view).setTypeface(null, typeFace);
            }
        }
    });
    viewRunnables.put("textAlignment", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
                int alignment = View.TEXT_ALIGNMENT_TEXT_START;
                switch (value) {
                case "center":
                    alignment = View.TEXT_ALIGNMENT_CENTER;
                    break;
                case "left":
                case "textStart":
                    break;
                case "right":
                case "textEnd":
                    alignment = View.TEXT_ALIGNMENT_TEXT_END;
                    break;
                }
                view.setTextAlignment(alignment);
            } else {
                int gravity = Gravity.LEFT;
                switch (value) {
                case "center":
                    gravity = Gravity.CENTER;
                    break;
                case "left":
                case "textStart":
                    break;
                case "right":
                case "textEnd":
                    gravity = Gravity.RIGHT;
                    break;
                }
                ((TextView) view).setGravity(gravity);
            }
        }
    });
    viewRunnables.put("ellipsize", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                TextUtils.TruncateAt where = TextUtils.TruncateAt.END;
                switch (value) {
                case "start":
                    where = TextUtils.TruncateAt.START;
                    break;
                case "middle":
                    where = TextUtils.TruncateAt.MIDDLE;
                    break;
                case "marquee":
                    where = TextUtils.TruncateAt.MARQUEE;
                    break;
                case "end":
                    break;
                }
                ((TextView) view).setEllipsize(where);
            }
        }
    });
    viewRunnables.put("singleLine", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                ((TextView) view).setSingleLine();
            }
        }
    });
    viewRunnables.put("hint", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof EditText) {
                ((EditText) view).setHint(value);
            }
        }
    });
    viewRunnables.put("inputType", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                int inputType = 0;
                switch (value) {
                case "textEmailAddress":
                    inputType |= InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
                    break;
                case "number":
                    inputType |= InputType.TYPE_CLASS_NUMBER;
                    break;
                case "phone":
                    inputType |= InputType.TYPE_CLASS_PHONE;
                    break;
                }
                if (inputType > 0)
                    ((TextView) view).setInputType(inputType);
            }
        }
    });
    viewRunnables.put("gravity", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            int gravity = parseGravity(value);
            if (view instanceof TextView) {
                ((TextView) view).setGravity(gravity);
            } else if (view instanceof LinearLayout) {
                ((LinearLayout) view).setGravity(gravity);
            } else if (view instanceof RelativeLayout) {
                ((RelativeLayout) view).setGravity(gravity);
            }
        }
    });
    viewRunnables.put("src", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof ImageView) {
                String imageName = value;
                if (imageName.startsWith("//"))
                    imageName = "http:" + imageName;
                if (imageName.startsWith("http")) {
                    if (imageLoader != null) {
                        if (attrs.containsKey("cornerRadius")) {
                            int radius = DimensionConverter.stringToDimensionPixelSize(
                                    attrs.get("cornerRadius"), view.getResources().getDisplayMetrics());
                            imageLoader.loadRoundedImage((ImageView) view, imageName, radius);
                        } else {
                            imageLoader.loadImage((ImageView) view, imageName);
                        }
                    }
                } else if (imageName.startsWith("@drawable/")) {
                    imageName = imageName.substring("@drawable/".length());
                    ((ImageView) view).setImageDrawable(getDrawableByName(view, imageName));
                }
            }
        }
    });
    viewRunnables.put("visibility", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            int visibility = View.VISIBLE;
            String visValue = value.toLowerCase();
            if (visValue.equals("gone"))
                visibility = View.GONE;
            else if (visValue.equals("invisible"))
                visibility = View.INVISIBLE;
            view.setVisibility(visibility);
        }
    });
    viewRunnables.put("clickable", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            view.setClickable(value.equals("true"));
        }
    });
    viewRunnables.put("tag", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            // Sigh, this is dangerous because we use tags for other purposes
            if (view.getTag() == null)
                view.setTag(value);
        }
    });
    viewRunnables.put("onClick", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            view.setOnClickListener(getClickListener(parent, value));
        }
    });
}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleTimetableFragment.java

void setupDaySelectionListeners(final View rootView) {

    View.OnClickListener listener = new View.OnClickListener() {
        @Override/*from ww w.j  a  v a 2  s .c om*/
        public void onClick(View view) {

            TextView text = ((TextView) view);
            int index;
            switch (text.getId()) {
            case R.id.day_mo:
                schedule.toggleSelectedDay(0);
                index = 0;
                break;
            case R.id.day_tu:
                schedule.toggleSelectedDay(1);
                index = 1;
                break;
            case R.id.day_we:
                schedule.toggleSelectedDay(2);
                index = 2;
                break;
            case R.id.day_th:
                index = 3;
                schedule.toggleSelectedDay(3);
                break;
            case R.id.day_fr:
                schedule.toggleSelectedDay(4);
                index = 4;
                break;
            case R.id.day_sa:
                schedule.toggleSelectedDay(5);
                index = 5;
                break;
            case R.id.day_su:
                schedule.toggleSelectedDay(6);
                index = 6;
                break;
            default:
                return;
            }

            boolean daySelected = schedule.days()[index];
            StateListDrawable sld = (StateListDrawable) text.getBackground();
            GradientDrawable shape = (GradientDrawable) sld.getCurrent();
            shape.setColor(daySelected ? color : Color.WHITE);
            text.setTypeface(null, daySelected ? Typeface.BOLD : Typeface.NORMAL);
            text.setTextColor(daySelected ? Color.WHITE : Color.BLACK);

            boolean allDaysSelected = schedule.allDaysSelected();

            if (schedule.type() == Schedule.SCHEDULE_TYPE_EVERYDAY && !allDaysSelected) {
                setRepeatType(Schedule.SCHEDULE_TYPE_SOMEDAYS, rootView, false);
                ignoreNextEvent = true;
                repeatTypeSpinner.setSelection(1);
            } else if (schedule.type() == Schedule.SCHEDULE_TYPE_SOMEDAYS && allDaysSelected) {
                repeatTypeSpinner.setSelection(0);
                schedule.setType(Schedule.SCHEDULE_TYPE_EVERYDAY);
            }

            Log.d(TAG, "All days selected: " + allDaysSelected + ", repeatType: " + schedule.type());
        }
    };

    rootView.findViewById(R.id.day_mo).setOnClickListener(listener);
    rootView.findViewById(R.id.day_tu).setOnClickListener(listener);
    rootView.findViewById(R.id.day_we).setOnClickListener(listener);
    rootView.findViewById(R.id.day_th).setOnClickListener(listener);
    rootView.findViewById(R.id.day_fr).setOnClickListener(listener);
    rootView.findViewById(R.id.day_sa).setOnClickListener(listener);
    rootView.findViewById(R.id.day_su).setOnClickListener(listener);
}

From source file:com.saulcintero.moveon.fragments.Statistics.java

private void paintData(int sql_option, int activity) {
    boolean isMetric = FunctionUtils.checkIfUnitsAreMetric(mContext);

    sum_distance = 0;//  w w w .j a va2s  .  c o  m
    sum_kcal = 0;
    sum_time = 0;
    sum_up_accum_altitude = 0;
    sum_down_accum_altitude = 0;
    sum_avg_speed = 0;
    sum_steps = 0;
    sum_avg_hr = 0;
    practices_counter = 0;
    hr_practices_counter = 0;

    int[] colors = { Color.rgb(111, 183, 217), Color.rgb(54, 165, 54), Color.rgb(246, 103, 88),
            Color.rgb(234, 206, 74), Color.rgb(246, 164, 83), Color.LTGRAY, Color.rgb(35, 142, 36),
            Color.rgb(0, 129, 125), Color.rgb(0, 0, 220), Color.rgb(255, 255, 0), Color.rgb(255, 215, 0),
            Color.rgb(184, 134, 11), Color.rgb(245, 245, 220), Color.rgb(139, 137, 137), Color.rgb(96, 57, 138),
            Color.rgb(176, 0, 103), Color.rgb(77, 19, 106), Color.rgb(218, 0, 0), Color.rgb(252, 115, 0),
            Color.rgb(243, 42, 0), Color.rgb(255, 202, 44), Color.rgb(176, 214, 7), Color.rgb(255, 235, 44),
            Color.rgb(255, 255, 255), Color.rgb(186, 29, 29), Color.rgb(146, 436, 20), Color.rgb(245, 175, 209),
            Color.rgb(29, 91, 139), Color.rgb(128, 128, 0), Color.rgb(128, 0, 128), Color.rgb(0, 128, 128),
            Color.rgb(246, 233, 207), Color.rgb(231, 56, 142), Color.rgb(173, 141, 193),
            Color.rgb(191, 199, 32), Color.rgb(0, 128, 0), Color.rgb(4, 136, 125), Color.rgb(140, 0, 255),
            Color.rgb(135, 0, 118), Color.rgb(2, 132, 132), Color.rgb(0, 127, 204), Color.rgb(128, 250, 255),
            Color.rgb(192, 192, 192), Color.rgb(207, 94, 97), Color.rgb(137, 189, 199),
            Color.rgb(138, 168, 161), Color.rgb(171, 166, 191), Color.rgb(199, 153, 125) };

    DBManager = null;
    cursor = null;

    distance_distribution = null;
    kcal_distribution = null;
    time_distribution = null;

    DBManager = new DataManager(mContext);
    DBManager.Open();

    cursor = DBManager.CustomQuery(getString(R.string.checking_routes), "SELECT * FROM routes");

    cursor.moveToFirst();
    if (cursor.getCount() > 0) {
        between_dates_query_part = "";

        DatesTypes whichDate = DatesTypes.values()[sql_option];
        switch (whichDate) {
        case ALL_DATES:
            removeCustomDataValues();

            if (activity > 0) {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_all_routes) + " " + getString(R.string.filter_by_activity)
                                + " " + getString(R.string.and) + " " + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE category_id = '"
                                + activity + "' " + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_all_routes) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes GROUP BY category_id");
            }

            break;
        case THIS_YEAR:
            removeCustomDataValues();

            if (activity > 0) {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_year_routes) + " "
                                + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7) = '"
                                + Calendar.getInstance().get(Calendar.YEAR) + "' " + "AND category_id = '"
                                + activity + "' " + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_year_routes) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7) = '"
                                + Calendar.getInstance().get(Calendar.YEAR) + "' " + "GROUP BY category_id");
            }

            between_dates_query_part = "substr(date,7) = '" + Calendar.getInstance().get(Calendar.YEAR) + "' ";

            break;
        case THIS_MONTH:
            removeCustomDataValues();

            int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
            String sMonth = String.valueOf(month);
            if (month < 10)
                sMonth = "0" + sMonth;

            if (activity > 0) {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_month_routes) + " "
                                + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,4,2) = '"
                                + sMonth + "' " + "AND substr(date,7) = '"
                                + Calendar.getInstance().get(Calendar.YEAR) + "' " + "AND category_id = '"
                                + activity + "' " + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_month_routes) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,4,2) = '"
                                + sMonth + "' " + "AND substr(date,7) = '"
                                + Calendar.getInstance().get(Calendar.YEAR) + "' " + "GROUP BY category_id");
            }

            between_dates_query_part = "substr(date,4,2) = '" + sMonth + "' AND substr(date,7) = '"
                    + Calendar.getInstance().get(Calendar.YEAR) + "' ";

            break;
        case THIS_WEAK:
            removeCustomDataValues();

            Calendar c1 = Calendar.getInstance();
            c1.setFirstDayOfWeek(Calendar.MONDAY);
            c1.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

            int y = c1.get(Calendar.YEAR);
            int m = c1.get(Calendar.MONTH) + 1;
            int d = c1.get(Calendar.DAY_OF_MONTH);

            String sYear1 = String.valueOf(y);
            String sMonth1 = String.valueOf(m);
            if (m < 10)
                sMonth1 = "0" + sMonth1;
            String sDay1 = String.valueOf(d);
            if (d < 10)
                sDay1 = "0" + sDay1;

            c1.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

            int y2 = c1.get(Calendar.YEAR);
            int m2 = c1.get(Calendar.MONTH) + 1;
            int d2 = c1.get(Calendar.DAY_OF_MONTH);

            String sYear2 = String.valueOf(y2);
            String sMonth2 = String.valueOf(m2);
            if (m2 < 10)
                sMonth2 = "0" + sMonth2;
            String sDay2 = String.valueOf(d2);
            if (d2 < 10)
                sDay2 = "0" + sDay2;

            if (activity > 0) {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_weak_routes) + " "
                                + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes "
                                + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                                + sYear1 + sMonth1 + sDay1 + "' AND '" + sYear2 + sMonth2 + sDay2 + "' "
                                + "AND category_id = '" + activity + "' " + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_weak_routes) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes "
                                + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                                + sYear1 + sMonth1 + sDay1 + "' AND '" + sYear2 + sMonth2 + sDay2 + "' "
                                + "GROUP BY category_id");
            }

            between_dates_query_part = "substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                    + sYear1 + sMonth1 + sDay1 + "' AND '" + sYear2 + sMonth2 + sDay2 + "' ";

            break;
        case BETWEEN_TWO_DATES:
            String mYear1 = String.valueOf(year1);
            String mMonth1 = String.valueOf(month1);
            if (month1 < 10)
                mMonth1 = "0" + mMonth1;
            String mDay1 = String.valueOf(day1);
            if (day1 < 10)
                mDay1 = "0" + mDay1;

            String mYear2 = String.valueOf(year2);
            String mMonth2 = String.valueOf(month2);
            if (month2 < 10)
                mMonth2 = "0" + mMonth2;
            String mDay2 = String.valueOf(day2);
            if (day2 < 10)
                mDay2 = "0" + mDay2;

            customDay1 = mDay1;
            customDay2 = mDay2;
            customMonth1 = mMonth1;
            customMonth2 = mMonth2;
            customYear1 = mYear1;
            customYear2 = mYear2;

            if (activity > 0) {
                cursor = DBManager.CustomQuery("Seleccionando las rutas de este mes agrupadas por actividad",
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes "
                                + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                                + customYear1 + customMonth1 + customDay1 + "' AND '" + customYear2
                                + customMonth2 + customDay2 + "' " + "AND category_id = '" + activity + "' "
                                + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery("Seleccionando las rutas de este mes agrupadas por actividad",
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes "
                                + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                                + customYear1 + customMonth1 + customDay1 + "' AND '" + customYear2
                                + customMonth2 + customDay2 + "' " + "GROUP BY category_id");
            }

            between_dates_query_part = "substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                    + customYear1 + customMonth1 + customDay1 + "' AND '" + customYear2 + customMonth2
                    + customDay2 + "' ";

            break;
        }
        cursor.moveToFirst();

        base_layout.setVisibility(View.VISIBLE);
        scrollView.setVisibility(View.VISIBLE);
        layout1.setVisibility(View.VISIBLE);
        layout2.setVisibility(View.VISIBLE);
        layout3.setVisibility(View.VISIBLE);
        layout4.setVisibility(View.VISIBLE);

        distance_distribution = new float[cursor.getCount()];
        kcal_distribution = new int[cursor.getCount()];
        time_distribution = new int[cursor.getCount()];

        int i = 0;

        mTableLayout.removeAllViews();

        while (!cursor.isAfterLast()) {
            TextView color = new TextView(mContext);
            TextView label = new TextView(mContext);
            TextView value = new TextView(mContext);
            LinearLayout.LayoutParams colorLayoutParams = new LinearLayout.LayoutParams(
                    new LayoutParams(FunctionUtils.calculateDpFromPx(mContext, 20),
                            FunctionUtils.calculateDpFromPx(mContext, 20)));
            colorLayoutParams.setMargins(0, 1, 5, 1);
            color.setLayoutParams(colorLayoutParams);
            label.setLayoutParams(
                    new LayoutParams(FunctionUtils.calculateDpFromPx(mContext, 95), LayoutParams.WRAP_CONTENT));
            label.setTypeface(null, Typeface.BOLD);
            label.setTextColor(Color.parseColor("#b5b5b5"));
            value.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            value.setTextColor(res.getColor(R.color.white));

            color.setBackgroundColor(colors[i]);

            label.setText(activities[cursor.getInt(cursor.getColumnIndex("category_id")) - 1] + ":");
            value.setText((isMetric
                    ? String.valueOf(cursor.getFloat(cursor.getColumnIndex("sum_distance"))) + " "
                            + getString(R.string.long_unit1_detail_1) + ", "
                    : String.valueOf(FunctionUtils.customizedRound(
                            ((cursor.getFloat(cursor.getColumnIndex("sum_distance")) * 1000f) / 1609f), 2))
                            + " " + getString(R.string.long_unit2_detail_1) + ", ")
                    + String.valueOf((int) cursor.getFloat(cursor.getColumnIndex("sum_kcal"))) + " "
                    + getString(R.string.tell_calories_setting_details) + ", "
                    + String.valueOf(FunctionUtils.statisticsFormatTime(mContext,
                            (long) cursor.getFloat(cursor.getColumnIndex("sum_time")))));

            LinearLayout mLinearLayout = new LinearLayout(mContext);
            mLinearLayout
                    .setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            mLinearLayout.setOrientation(0);
            mLinearLayout.addView(color);
            mLinearLayout.addView(label);
            mLinearLayout.addView(value);
            mTableLayout.addView(mLinearLayout);

            sum_distance = sum_distance + cursor.getFloat(cursor.getColumnIndex("sum_distance"));
            sum_kcal = sum_kcal + cursor.getInt(cursor.getColumnIndex("sum_kcal"));
            sum_time = sum_time + cursor.getInt(cursor.getColumnIndex("sum_time"));
            sum_up_accum_altitude = sum_up_accum_altitude
                    + cursor.getInt(cursor.getColumnIndex("sum_up_accum_altitude"));
            sum_down_accum_altitude = sum_down_accum_altitude
                    + cursor.getInt(cursor.getColumnIndex("sum_down_accum_altitude"));
            sum_avg_speed = sum_avg_speed + cursor.getFloat(cursor.getColumnIndex("sum_avg_speed"));
            sum_steps = sum_steps + cursor.getInt(cursor.getColumnIndex("sum_steps"));

            distance_distribution[i] = cursor.getFloat(cursor.getColumnIndex("sum_distance"));
            kcal_distribution[i] = cursor.getInt(cursor.getColumnIndex("sum_kcal"));
            time_distribution[i] = cursor.getInt(cursor.getColumnIndex("sum_time"));

            practices_counter = practices_counter
                    + (int) cursor.getFloat(cursor.getColumnIndex("count_practices"));

            i++;

            cursor.moveToNext();
        }

        String activity_query_part = "";
        if (activity > 0)
            activity_query_part = " AND category_id = '" + activity + "'";

        if (between_dates_query_part.length() > 0) {
            cursor = DBManager.CustomQuery(getString(R.string.routes_with_hr),
                    "SELECT avg_hr FROM routes WHERE avg_hr > 0 AND " + between_dates_query_part
                            + activity_query_part);
        } else {
            cursor = DBManager.CustomQuery(getString(R.string.routes_with_hr),
                    "SELECT avg_hr FROM routes WHERE avg_hr > 0" + activity_query_part);
        }
        cursor.moveToFirst();
        if (cursor.getCount() > 0) {
            while (!cursor.isAfterLast()) {
                sum_avg_hr = sum_avg_hr + cursor.getInt(cursor.getColumnIndex("avg_hr"));
                hr_practices_counter += 1;

                cursor.moveToNext();
            }
        }

        text8.setText("");
        if (between_dates_query_part.length() > 0) {
            if (activity > 0)
                activity_query_part = " AND category_id = '" + activity + "' ";

            cursor = DBManager.CustomQuery(getString(R.string.selecting_most_used_shoes),
                    "SELECT shoe_id, COUNT(shoe_id) AS count_shoes " + "FROM routes " + "WHERE "
                            + between_dates_query_part + activity_query_part + "GROUP BY shoe_id "
                            + "ORDER BY count_shoes DESC");
        } else {
            if (activity > 0)
                activity_query_part = "WHERE category_id = '" + activity + "' ";

            cursor = DBManager.CustomQuery(getString(R.string.selecting_most_used_shoes_in_data_range),
                    "SELECT shoe_id, COUNT(shoe_id) AS count_shoes " + "FROM routes " + activity_query_part
                            + "GROUP BY shoe_id " + "ORDER BY count_shoes DESC");
        }
        cursor.moveToFirst();
        if (cursor.getCount() > 0) {
            int shoe = cursor.getInt(cursor.getColumnIndex("shoe_id"));
            if (cursor.getCount() > 1) {
                int[] shoes = new int[cursor.getCount()];
                int m = 0;
                while (!cursor.isAfterLast()) {
                    shoes[m] = cursor.getInt(cursor.getColumnIndex("shoe_id"));
                    m++;
                    cursor.moveToNext();
                }

                if (shoe == 0 && shoes.length > 1)
                    shoe = shoes[1];
            }

            if (shoe > 0) {
                cursor = DBManager.CustomQuery(getString(R.string.shoe_name),
                        "SELECT name FROM shoes WHERE _id = '" + shoe + "'");
                cursor.moveToFirst();
                text8.setText(cursor.getString(cursor.getColumnIndex("name")));
            }

        }

        text1.setText(String.valueOf(practices_counter));
        text2.setText(String.valueOf(FunctionUtils.statisticsFormatTime(mContext, (long) sum_time)));
        text3.setText(isMetric
                ? String.valueOf(FunctionUtils.customizedRound(sum_distance, 2)) + " "
                        + getString(R.string.long_unit1_detail_1)
                : String.valueOf(FunctionUtils.customizedRound(((sum_distance * 1000f) / 1609f), 2)) + " "
                        + getString(R.string.long_unit2_detail_1));
        text4.setText(
                isMetric ? String.valueOf(sum_up_accum_altitude) + " " + getString(R.string.long_unit1_detail_4)
                        : String.valueOf((int) (sum_up_accum_altitude * 1.0936f)) + " "
                                + getString(R.string.long_unit2_detail_4));
        text5.setText(isMetric
                ? String.valueOf(sum_down_accum_altitude) + " " + getString(R.string.long_unit1_detail_4)
                : String.valueOf((int) (sum_down_accum_altitude * 1.0936f)) + " "
                        + getString(R.string.long_unit2_detail_4));
        if ((sum_avg_speed > 0) && (practices_counter > 0)) {
            text6.setText((isMetric
                    ? String.valueOf(FunctionUtils.customizedRound((sum_avg_speed / practices_counter), 2))
                            + " " + getString(R.string.long_unit1_detail_2)
                    : String.valueOf(FunctionUtils
                            .customizedRound((((sum_avg_speed * 1000f) / 1609f) / practices_counter), 2)) + " "
                            + getString(R.string.long_unit2_detail_2)));
        } else {
            text6.setText(
                    getString(R.string.zero_value) + " " + (isMetric ? getString(R.string.long_unit1_detail_2)
                            : mContext.getString(R.string.long_unit2_detail_2)));
        }
        text7.setText(String.valueOf(
                FunctionUtils.calculateRitm(mContext, sum_time, String.valueOf(sum_distance), isMetric, false))
                + " " + (isMetric ? getString(R.string.long_unit1_detail_3)
                        : mContext.getString(R.string.long_unit2_detail_3)));
        text9.setText(String.valueOf(sum_kcal) + " " + getString(R.string.tell_calories_setting_details));
        text10.setText(String.valueOf(sum_steps));
        if ((sum_avg_hr > 0) && (hr_practices_counter > 0)) {
            text11.setText(String.valueOf(sum_avg_hr / hr_practices_counter) + " "
                    + getString(R.string.beats_per_minute));
        } else {
            text11.setText(getString(R.string.zero_value) + " " + getString(R.string.beats_per_minute));
        }
        if (sum_kcal > 0) {
            text12.setText(String.valueOf(sum_kcal / Constants.CHEESE_BURGER));
        } else {
            text12.setText(getString(R.string.zero_value));
        }
        if (sum_distance > 0) {
            text13.setText(String.valueOf(
                    FunctionUtils.customizedRound((sum_distance / Constants.ALL_THE_WAY_AROUND_THE_WORLD), 3)));
        } else {
            text13.setText(getString(R.string.zero_with_three_decimal_places_value));
        }
        if (sum_distance > 0) {
            double moon_distance = ((double) sum_distance) / ((double) Constants.TO_THE_MOON);
            text14.setText(String.valueOf(
                    FunctionUtils.customizedRound(Float.parseFloat(String.valueOf(moon_distance)), 1)));
        } else {
            text14.setText(getString(R.string.zero_with_one_decimal_place_value));
        }

        layout1.removeAllViews();
        layout2.removeAllViews();
        layout3.removeAllViews();

        mChartView1 = null;
        mChartView2 = null;
        mChartView3 = null;

        for (int h = 0; h < distance_distribution.length; h++) {
            float percent = 0;

            if (distance_distribution[h] > 0)
                percent = (distance_distribution[h] * 100) / sum_distance;

            if (sum_distance == 0)
                percent = 100 / distance_distribution.length;

            distance_distribution[h] = percent;
        }

        for (int b = 0; b < kcal_distribution.length; b++) {
            int percent = 0;

            if (sum_kcal > 0)
                percent = (kcal_distribution[b] * 100) / sum_kcal;

            if (sum_kcal == 0)
                percent = 100 / kcal_distribution.length;

            kcal_distribution[b] = percent;
        }

        final CategorySeries distance_distributionSeries = new CategorySeries("");
        for (int g = 0; g < distance_distribution.length; g++) {
            if (distance_distribution.length == 1) {
                distance_distributionSeries.add("", 100);
            } else {
                distance_distributionSeries.add("", distance_distribution[g]);
            }
        }

        final CategorySeries kcal_distributionSeries = new CategorySeries("");
        for (int p = 0; p < kcal_distribution.length; p++) {
            if (kcal_distribution.length == 1) {
                kcal_distributionSeries.add("", 100);
            } else {
                kcal_distributionSeries.add("", kcal_distribution[p]);
            }
        }

        final CategorySeries time_distributionSeries = new CategorySeries("");
        for (int l = 0; l < time_distribution.length; l++) {
            if (time_distribution.length == 1) {
                time_distributionSeries.add("", 100);
            } else {
                time_distributionSeries.add("", time_distribution[l]);
            }
        }

        DefaultRenderer defaultRenderer = new DefaultRenderer();
        DefaultRenderer defaultRenderer2 = new DefaultRenderer();
        DefaultRenderer defaultRenderer3 = new DefaultRenderer();

        defaultRenderer.setShowLabels(false);
        defaultRenderer.setZoomButtonsVisible(false);
        defaultRenderer.setStartAngle(180);
        defaultRenderer.setDisplayValues(false);
        defaultRenderer.setClickEnabled(true);
        defaultRenderer.setInScroll(true);
        defaultRenderer.setShowLegend(false);

        defaultRenderer2.setShowLabels(false);
        defaultRenderer2.setZoomButtonsVisible(false);
        defaultRenderer2.setStartAngle(180);
        defaultRenderer2.setDisplayValues(false);
        defaultRenderer2.setClickEnabled(true);
        defaultRenderer2.setInScroll(true);
        defaultRenderer2.setShowLegend(false);

        defaultRenderer3.setShowLabels(false);
        defaultRenderer3.setZoomButtonsVisible(false);
        defaultRenderer3.setStartAngle(180);
        defaultRenderer3.setDisplayValues(false);
        defaultRenderer3.setClickEnabled(true);
        defaultRenderer3.setInScroll(true);
        defaultRenderer3.setShowLegend(false);

        for (int u = 0; u < distance_distribution.length; u++) {
            SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
            seriesRenderer.setColor(colors[u]);
            seriesRenderer.setDisplayChartValues(true);
            seriesRenderer.setHighlighted(false);

            defaultRenderer.addSeriesRenderer(seriesRenderer);
        }

        for (int p = 0; p < kcal_distribution.length; p++) {
            SimpleSeriesRenderer seriesRenderer2 = new SimpleSeriesRenderer();
            seriesRenderer2.setColor(colors[p]);
            seriesRenderer2.setDisplayChartValues(true);
            seriesRenderer2.setHighlighted(false);

            defaultRenderer2.addSeriesRenderer(seriesRenderer2);
        }

        for (int o = 0; o < distance_distribution.length; o++) {
            SimpleSeriesRenderer seriesRenderer3 = new SimpleSeriesRenderer();
            seriesRenderer3.setColor(colors[o]);
            seriesRenderer3.setDisplayChartValues(true);
            seriesRenderer3.setHighlighted(false);

            defaultRenderer3.addSeriesRenderer(seriesRenderer3);
        }

        mChartView1 = ChartFactory.getPieChartView(mContext, distance_distributionSeries, defaultRenderer);
        mChartView2 = ChartFactory.getPieChartView(mContext, kcal_distributionSeries, defaultRenderer2);
        mChartView3 = ChartFactory.getPieChartView(mContext, time_distributionSeries, defaultRenderer3);

        layout1.addView(mChartView1);
        layout2.addView(mChartView2);
        layout3.addView(mChartView3);
    } else {
        base_layout.setVisibility(View.INVISIBLE);
        scrollView.setVisibility(View.INVISIBLE);
        layout1.setVisibility(View.INVISIBLE);
        layout2.setVisibility(View.INVISIBLE);
        layout3.setVisibility(View.INVISIBLE);
        layout4.setVisibility(View.INVISIBLE);
    }
    cursor.close();
    DBManager.Close();
}

From source file:com.free.searcher.MainFragment.java

private void initFind() {
    container = (RelativeLayout) activity.findViewById(R.id.layoutId);
    findBox = (EditText) container.findViewById(R.id.findBox);
    findBox.setText(currentSearching);//from  w w  w .ja va2s  . co  m
    findBox.setTypeface(Typeface.DEFAULT, Typeface.BOLD);

    findBox.setOnKeyListener(new OnKeyListener() {
        @SuppressWarnings("deprecation")
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            Log.d("onKey", "keyCode=" + keyCode + ",event=" + event + ",v=" + v);
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && ((keyCode == KeyEvent.KEYCODE_ENTER))) {
                webView.findAllAsync(findBox.getText().toString());
            }
            return false;
        }
    });

    //      findBox.setOnFocusChangeListener(new OnFocusChangeListener() {
    //            @Override
    //            public void onFocusChange(View p1, boolean p2) {
    //               webView.findAllAsync(findBox.getText().toString());
    //            }
    //         });

    findRet = (TextView) container.findViewById(R.id.findRet);

    backButton = (Button) container.findViewById(R.id.backButton);
    backButton.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
    backButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (findBox.isFocused()) {
                webView.findAllAsync(findBox.getText().toString());
            }
            webView.requestFocus();
            webView.findNext(false);
        }
    });

    nextButton = (Button) container.findViewById(R.id.nextButton);
    nextButton.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
    nextButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (findBox.isFocused()) {
                webView.findAllAsync(findBox.getText().toString());
            }
            webView.requestFocus();
            webView.findNext(true);
        }
    });

    clearButton = (Button) container.findViewById(R.id.clearButton);
    clearButton.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
    clearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            findBox.setText("");
            webView.findAllAsync(findBox.getText().toString());
            findBox.requestFocus();
        }
    });

    closeButton = (Button) container.findViewById(R.id.closeButton);
    closeButton.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
    closeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showFind = false;
            container.setVisibility(View.INVISIBLE);
        }
    });

    webView.findAllAsync(findBox.getText().toString());
    webView.setFindListener(new WebView.FindListener() {
        @Override
        public void onFindResultReceived(int p1, int p2, boolean p3) {
            findRet.setText((p1 + (p2 > 0 ? 1 : 0)) + "/" + p2);
        }
    });
    if (showFind) {
        container.setVisibility(View.VISIBLE);
    } else {
        container.setVisibility(View.INVISIBLE);
    }
}

From source file:org.miaowo.miaowo.util.Html.java

private static void endHeading(Editable text) {
    // RelativeSizeSpan and StyleSpan are CharacterStyles
    // Their ranges should not include the newlines at the end
    Heading h = getLast(text, Heading.class);
    if (h != null) {
        setSpanFromMark(text, h, new RelativeSizeSpan(HEADING_SIZES[h.mLevel]), new StyleSpan(Typeface.BOLD));
    }//from   w  w  w.j a v  a 2  s.c om

    endBlockElement(text);
}

From source file:com.juick.android.JuickMessagesAdapter.java

private static void setStyleSpans(SpannableStringBuilder ssb, int ssbOffset, Object what, String styleChar) {
    String txt;/*w w  w  . java2s .  c o m*/
    txt = ssb.subSequence(ssbOffset, ssb.length()).toString();
    txt = " " + txt + " ";
    ssbOffset -= 1;
    //
    int scan = 0;
    int cnt = 0;
    while (cnt++ < 20) { // don't need bugs in production.
        int ix = txt.indexOf(styleChar, scan);
        if (ix < 0)
            break;
        if (" \n".indexOf(txt.charAt(ix - 1)) != -1) {
            int ix2 = txt.indexOf(styleChar, ix + 1);
            if (ix2 < 0)
                break;
            if (" \n".indexOf(txt.charAt(ix2 + 1)) == -1 // not ends with space
                    || txt.substring(ix, ix2).indexOf("\n") != -1) { // spans several lines
                scan = ix2; // not ok
                continue;
            } else {
                CharacterStyle span = null;
                CharacterStyle span2 = null;
                // found needed stuff
                if (what instanceof Integer && (((Integer) what) == Typeface.BOLD)) {
                    span = new StyleSpan(Typeface.BOLD);
                    if (helvNueFonts) {
                        span2 = new CustomTypefaceSpan("", JuickAdvancedApplication.helvNueBold);
                    }
                }
                if (what instanceof Integer && (((Integer) what) == Typeface.ITALIC)) {
                    span = new StyleSpan(Typeface.ITALIC);
                }
                if (what == UnderlineSpan.class) {
                    span = new UnderlineSpan();
                }
                if (span != null && ix2 - ix > 1) {
                    ssb.delete(ssbOffset + ix, ssbOffset + ix + 1); // delete styling char
                    txt = stringDelete(txt, ix, ix + 1);
                    ix2--; // moves, too
                    ssb.delete(ssbOffset + ix2, ssbOffset + ix2 + 1); // second char deleted
                    txt = stringDelete(txt, ix2, ix2 + 1);
                    ssb.setSpan(span, ssbOffset + ix, ssbOffset + ix2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    if (span2 != null) {
                        ssb.setSpan(span2, ssbOffset + ix, ssbOffset + ix2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                }
                scan = ix2;
            }
        }
    }
}

From source file:com.android.contacts.common.list.ContactListItemView.java

/**
 * Returns the text view for the phonetic name, creating it if necessary.
 *///from  w w  w  .  j a  v  a 2 s . c  o m
public TextView getPhoneticNameTextView() {
    if (mPhoneticNameTextView == null) {
        mPhoneticNameTextView = new TextView(getContext());
        mPhoneticNameTextView.setSingleLine(true);
        mPhoneticNameTextView.setEllipsize(getTextEllipsis());
        mPhoneticNameTextView.setTextAppearance(getContext(), android.R.style.TextAppearance_Small);
        mPhoneticNameTextView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
        mPhoneticNameTextView.setTypeface(mPhoneticNameTextView.getTypeface(), Typeface.BOLD);
        mPhoneticNameTextView.setActivated(isActivated());
        mPhoneticNameTextView.setId(R.id.cliv_phoneticname_textview);
        addView(mPhoneticNameTextView);
    }
    return mPhoneticNameTextView;
}

From source file:com.esri.android.mapsapp.MapFragment.java

/**
 * Shows the search result in the layout after successful geocoding and
 * reverse geocoding//from   w w w .j a v a 2s.  c o  m
 * 
 */

private void showSearchResultLayout(String address) {
    // Remove the layouts
    mMapContainer.removeView(mSearchBox);
    mMapContainer.removeView(mSearchResult);

    // Inflate the new layout from the xml file
    mSearchResult = mInflater.inflate(R.layout.search_result, null);

    // Set layout parameters
    mSearchResult.setLayoutParams(mlayoutParams);

    // Initialize the textview and set its text
    TextView tv = (TextView) mSearchResult.findViewById(R.id.textView1);
    tv.setTypeface(null, Typeface.BOLD);
    tv.setText(address);

    // Adding the search result layout to the map container
    mMapContainer.addView(mSearchResult);

    // Setup the listener for the "cancel" icon
    ImageView iv_cancel = (ImageView) mSearchResult.findViewById(R.id.imageView3);
    iv_cancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Remove the search result view
            mMapContainer.removeView(mSearchResult);

            suggestionClickFlag = false;
            // Add the search box view
            showSearchBoxLayout();

            // Remove all graphics from the map
            resetGraphicsLayers();

        }
    });

    // Set up the listener for the "Get Directions" icon
    ImageView iv_route = (ImageView) mSearchResult.findViewById(R.id.imageView2);
    iv_route.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onGetRoute(getString(R.string.my_location), mLocationLayerPointString);
        }
    });

    // Add the compass after getting the height of the layout
    mSearchResult.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            addCompass(mSearchResult.getHeight());
            mSearchResult.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }

    });

}

From source file:org.sirimangalo.meditationplus.ActivityMain.java

private void populateOnline(JSONArray onlines) {

    if (onlines.length() == 0) {
        onlineList.setVisibility(View.GONE);
        return;/*  ww w  . jav  a2 s . co  m*/
    }

    onlineList.setVisibility(View.VISIBLE);

    ArrayList<JSONObject> onlineArray = new ArrayList<JSONObject>();
    ArrayList<String> onlineNamesArray = new ArrayList<String>();

    // collect into array

    for (int i = 0; i < onlines.length(); i++) {
        try {
            JSONObject a = onlines.getJSONObject(i);
            onlineArray.add(a);
            onlineNamesArray.add(a.getString("username"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    String text = getString(R.string.online) + " ";

    // add spans

    int pos = text.length(); // start after "Online: "

    text += TextUtils.join(", ", onlineNamesArray);
    Spannable span = new SpannableString(text);

    span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: "

    Drawable android = context.getResources().getDrawable(R.drawable.android);
    android.setBounds(0, 0, 48, 32);

    for (JSONObject oneOnA : onlineArray) {
        try {
            final String oneOn = oneOnA.getString("username");

            int end = pos + oneOn.length();

            boolean isMed = false;

            for (int j = 0; j < jsonList.length(); j++) {
                JSONObject user = jsonList.getJSONObject(j);
                String username = user.getString("username");
                if (username.equals(oneOn))
                    isMed = true;
            }

            if (oneOnA.getString("source").equals("android")) {
                ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE);
                span.setSpan(image, pos - 1, pos, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            }

            ClickableSpan clickable = new ClickableSpan() {

                @Override
                public void onClick(View widget) {
                    showProfile(oneOn);
                }

            };
            span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

            span.setSpan(new UnderlineSpan() {
                public void updateDrawState(TextPaint tp) {
                    tp.setUnderlineText(false);
                }
            }, pos, end, 0);

            span.setSpan(new ForegroundColorSpan(isMed ? 0xFF009900 : 0xFFFF9900), pos, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            pos += oneOn.length() + 2;

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    onlineList.setText(span);
    onlineList.setMovementMethod(LinkMovementMethod.getInstance());

}