Example usage for android.widget TextView setBackgroundColor

List of usage examples for android.widget TextView setBackgroundColor

Introduction

In this page you can find the example usage for android.widget TextView setBackgroundColor.

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:com.customdatepicker.time.TimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    int viewRes = mVersion == Version.VERSION_1 ? R.layout.mdtp_time_picker_dialog
            : R.layout.mdtp_time_picker_dialog_v2;
    View view = inflater.inflate(viewRes, container, false);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.mdtp_time_picker_dialog).setOnKeyListener(keyboardListener);

    // If an accent color has not been set manually, get it from the context
    if (mAccentColor == -1) {
        mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
    }/*from   w  w  w.  ja v a 2 s  .  c o m*/

    // if theme mode has not been set by java code, check if it is specified in Style.xml
    if (!mThemeDarkChanged) {
        mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
    }

    Resources res = getResources();
    Context context = getActivity();
    mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description);
    mSelectHours = res.getString(R.string.mdtp_select_hours);
    mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description);
    mSelectMinutes = res.getString(R.string.mdtp_select_minutes);
    mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description);
    mSelectSeconds = res.getString(R.string.mdtp_select_seconds);
    mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused);

    mHourView = (TextView) view.findViewById(R.id.mdtp_hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.mdtp_hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.mdtp_minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.mdtp_minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mSecondSpaceView = (TextView) view.findViewById(R.id.mdtp_seconds_space);
    mSecondView = (TextView) view.findViewById(R.id.mdtp_seconds);
    mSecondView.setOnKeyListener(keyboardListener);
    mAmTextView = (TextView) view.findViewById(R.id.mdtp_am_label);
    mAmTextView.setOnKeyListener(keyboardListener);
    mPmTextView = (TextView) view.findViewById(R.id.mdtp_pm_label);
    mPmTextView.setOnKeyListener(keyboardListener);
    mAmPmLayout = view.findViewById(R.id.mdtp_ampm_layout);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());

    if (mTimePicker != null) {
        mInitialTime = new Timepoint(mTimePicker.getHours(), mTimePicker.getMinutes(),
                mTimePicker.getSeconds());
    }

    mInitialTime = roundToNearest(mInitialTime);

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.mdtp_time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), this, mInitialTime, mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mSecondView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            setCurrentItemShowing(SECOND_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mOkButton = (Button) view.findViewById(R.id.mdtp_ok);
    mOkButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            notifyOnDateListener();
            dismiss();
        }
    });
    mOkButton.setOnKeyListener(keyboardListener);
    mOkButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mOkString != null)
        mOkButton.setText(mOkString);
    else
        mOkButton.setText(mOkResid);

    mCancelButton = (Button) view.findViewById(R.id.mdtp_cancel);
    mCancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryVibrate();
            if (getDialog() != null)
                getDialog().cancel();
        }
    });
    mCancelButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mCancelString != null)
        mCancelButton.setText(mCancelString);
    else
        mCancelButton.setText(mCancelResid);
    mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);

    // Enable or disable the AM/PM view.
    if (mIs24HourMode) {
        mAmPmLayout.setVisibility(View.GONE);
    } else {
        OnClickListener listener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Don't do anything if either AM or PM are disabled
                if (isAmDisabled() || isPmDisabled())
                    return;

                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                mTimePicker.setAmOrPm(amOrPm);
            }
        };
        mAmTextView.setVisibility(View.GONE);
        mPmTextView.setVisibility(View.VISIBLE);
        mAmPmLayout.setOnClickListener(listener);
        if (mVersion == Version.VERSION_2) {
            mAmTextView.setText(mAmText);
            mPmTextView.setText(mPmText);
            mAmTextView.setVisibility(View.VISIBLE);
        }
        updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);

    }

    // Disable seconds picker
    if (!mEnableSeconds) {
        mSecondView.setVisibility(View.GONE);
        view.findViewById(R.id.mdtp_separator_seconds).setVisibility(View.GONE);
    }

    // Disable minutes picker
    if (!mEnableMinutes) {
        mMinuteSpaceView.setVisibility(View.GONE);
        view.findViewById(R.id.mdtp_separator).setVisibility(View.GONE);
    }

    // Center stuff depending on what's visible
    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    // Landscape layout is radically different
    if (isLandscape) {
        if (!mEnableMinutes && !mEnableSeconds) {
            // Just the hour
            // Put the hour above the center
            RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsHour.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
            paramsHour.addRule(RelativeLayout.CENTER_HORIZONTAL);
            mHourSpaceView.setLayoutParams(paramsHour);
            if (mIs24HourMode) {
                // Hour + Am/Pm indicator
                // Put the am / pm indicator next to the hour
                RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space);
                mAmPmLayout.setLayoutParams(paramsAmPm);
            }
        } else if (!mEnableSeconds && mIs24HourMode) {
            // Hour + Minutes
            // Put the separator above the center
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
        } else if (!mEnableSeconds) {
            // Hour + Minutes + Am/Pm indicator
            // Put separator above the center
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
            // Put the am/pm indicator below the separator
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.CENTER_IN_PARENT);
            paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_center_view);
            mAmPmLayout.setLayoutParams(paramsAmPm);
        } else if (mIs24HourMode) {
            // Hour + Minutes + Seconds
            // Put the separator above the center
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
            // Center the seconds
            RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT);
            mSecondSpaceView.setLayoutParams(paramsSeconds);
        } else {
            // Hour + Minutes + Seconds + Am/Pm Indicator
            // Put the seconds on the center
            RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT);
            mSecondSpaceView.setLayoutParams(paramsSeconds);
            // Put the separator above the seconds
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
            // Put the Am/Pm indicator below the seconds
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_seconds_space);
            mAmPmLayout.setLayoutParams(paramsAmPm);
        }
    } else if (mIs24HourMode && !mEnableSeconds && mEnableMinutes) {
        // center first separator
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else if (!mEnableMinutes && !mEnableSeconds) {
        // center the hour
        RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsHour.addRule(RelativeLayout.CENTER_IN_PARENT);
        mHourSpaceView.setLayoutParams(paramsHour);

        if (!mIs24HourMode) {
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space);
            paramsAmPm.addRule(RelativeLayout.ALIGN_BASELINE, R.id.mdtp_hour_space);
            mAmPmLayout.setLayoutParams(paramsAmPm);
        }
    } else if (mEnableSeconds) {
        // link separator to minutes
        final View separator = view.findViewById(R.id.mdtp_separator);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.mdtp_minutes_space);
        paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        separator.setLayoutParams(paramsSeparator);

        if (!mIs24HourMode) {
            // center minutes
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        } else {
            // move minutes to right of center
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_center_view);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        }
    }

    mAllowAutoAdvance = true;
    setHour(mInitialTime.getHour(), true);
    setMinute(mInitialTime.getMinute());
    setSecond(mInitialTime.getSecond());

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.mdtp_deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<>();
    }

    // Set the title (if any)
    TextView timePickerHeader = (TextView) view.findViewById(R.id.mdtp_time_picker_header);
    if (!mTitle.isEmpty()) {
        timePickerHeader.setVisibility(TextView.VISIBLE);
        timePickerHeader.setText(mTitle.toUpperCase(Locale.getDefault()));
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor));
    view.findViewById(R.id.mdtp_time_display_background).setBackgroundColor(mAccentColor);
    view.findViewById(R.id.mdtp_time_display).setBackgroundColor(mAccentColor);

    // Button text can have a different color
    if (mOkColor != -1)
        mOkButton.setTextColor(mOkColor);
    else
        mOkButton.setTextColor(mAccentColor);
    if (mCancelColor != -1)
        mCancelButton.setTextColor(mCancelColor);
    else
        mCancelButton.setTextColor(mAccentColor);

    if (getDialog() == null) {
        view.findViewById(R.id.mdtp_done_background).setVisibility(View.GONE);
    }

    int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background);
    int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color);
    int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray);
    int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray);

    mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground);
    view.findViewById(R.id.mdtp_time_picker_dialog)
            .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor);
    return view;
}

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 av  a2s.  c om
    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.juick.android.ThreadActivity.java

private void previewAndSendReply(final String msg) {
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    if (sp.getBoolean("previewReplies", false)) {
        final TextView tv = new TextView(this);
        JuickMessage jm = new JuickMessage();
        jm.User = new JuickUser();
        jm.User.UName = "You";
        jm.Text = msg;/*from ww  w .  j a v a2 s  . com*/
        jm.tags = new Vector<String>();
        if (rid != 0) {
            // insert destination user name
            JuickMessage reply = tf.findReply(tf.getListView(), rid);
            if (reply != null) {
                jm.Text = "@" + reply.User.UName + " " + jm.Text;
            }
        }
        JuickMessagesAdapter.ParsedMessage parsedMessage = JuickMessagesAdapter.formatMessageText(this, jm,
                true);
        tv.setText(parsedMessage.textContent);
        tv.setPadding(10, 10, 10, 10);
        MainActivity.restyleChildrenOrWidget(tv);
        final AlertDialog dialog = new AlertDialog.Builder(
                new ContextThemeWrapper(this, R.style.Theme_Sherlock_Light)).setTitle("Post reply - preview")
                        .setView(tv).setCancelable(true)
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        }).setPositiveButton("Post reply", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                                sendReplyMain(msg);
                            }
                        }).create();
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface i) {
                tv.setBackgroundColor(JuickMessagesAdapter.getColorTheme(dialog.getContext()).getBackground());
                MainActivity.restyleChildrenOrWidget(tv);
            }
        });
        dialog.show();
    } else {
        sendReplyMain(msg);
    }
}

From source file:com.hardcopy.retroband.MainActivity.java

public void procesarSum(int[] vector) {
    // vector es un arreglo de 3 [x_#,y_#,z_#]
    TextView textLimiteView = (TextView) findViewById(R.id.text_limite);
    textLimiteView.setText("Sumando...");

    EditText editLimiteView = (EditText) findViewById(R.id.edit_limite);

    double sum = this.magnitudSum(vector);
    double pendiente = sumAnterior - sum;
    // si no est definido, se usa el predeterminado de int limite=25000
    textLimiteView.setText("Pend: " + String.valueOf(Math.abs(pendiente)));
    int limite = 7000;
    String valor = (String) editLimiteView.getText().toString();
    if (!valor.equals("")) {
        try {/*from   w w  w . ja  va2 s . co  m*/
            limite = Integer.parseInt(valor);
        } catch (Exception ex) {
            Log.e("Cast", "Valor : " + valor);
        }
    }
    Date actualDate = new Date();
    long secondsBetween = (actualDate.getTime() - lastDatePendiente.getTime()) / 1000;

    if (sumAnterior != -1 && Math.abs(pendiente) > limite && secondsBetween > 2) {// Se cayo la persona
        if (estadoSendMail) {
            String mensaje = "Alerta valor absoluto pendiente: " + String.valueOf(Math.abs(pendiente));
            mensaje += "\r\nEnergia X: " + String.valueOf(this.getEnergy(this.getXRecord()));
            mensaje += "\r\nEnergia Y: " + String.valueOf(this.getEnergy(this.getYRecord()));
            mensaje += "\r\nEnergia Z: " + String.valueOf(this.getEnergy(this.getZRecord()));
            mensaje += "\r\nEnergia VecSum: " + String.valueOf(this.getEnergy(this.getVsumRecord()));
            // probando con transformada wavelet haar
            double[] muestraVsum = getVsumRecord();
            double[] coeficientes = getCoef(muestraVsum);
            mensaje += "\r\nCoeficientes:\r\n" + arrayToString(coeficientes);
            enviarEmailPersonalizado("Alerta Caida (Umbral de la Derivada del Vector Suma).", mensaje);

        }
        textLimiteView.setBackgroundColor(Color.parseColor("#FF0000"));//Rojo
        lastDatePendiente = new Date();
        estadoPendiente = true;
    } else if (secondsBetween > 2) {// Todo esta bien
        textLimiteView.setBackgroundColor(Color.parseColor("#00FF00"));//Verde
        estadoPendiente = false;
    }
    sumAnterior = sum;
}

From source file:es.upv.riromu.arbre.main.MainActivity.java

private void rangeSeekBarChanged(int minValue, int maxValue) {
    {//  ww  w  .jav a2s  . c  o m

        TextView imc = (TextView) findViewById(R.id.textView);
        imc.setVisibility(View.VISIBLE);
        ImageButton cropButton = (ImageButton) findViewById(R.id.button_crop);
        cropButton.setVisibility(View.GONE);
        ImageButton sendButton = (ImageButton) findViewById(R.id.button_send);
        sendButton.setVisibility(View.VISIBLE);
        ImageButton histButton = (ImageButton) findViewById(R.id.button_histogram);
        histButton.setVisibility(View.VISIBLE);
        ImageButton revertButton = (ImageButton) findViewById(R.id.button_revert);
        revertButton.setVisibility(View.VISIBLE);
        ImageView imagePalette = (ImageView) findViewById(R.id.palette);
        imagePalette.setVisibility(View.GONE);
        ImageWrapper imw = new ImageWrapper();
        if (image_uri == null)
            image = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.platanus_hispanica,
                    MAX_SIZE, MAX_SIZE);
        if (image_uri != null)
            image = Util.decodeSampledBitmapFromUri(image_uri, MAX_SIZE, MAX_SIZE, this);
        // handle changed range values
        try {
            Log.i(TAG, "User selected new range values: MIN=" + minValue + ", MAX=" + maxValue);
            ImageView imv = (ImageView) findViewById(R.id.image_intro);
            if (state[CROP_IMAGE])
                imw.setBitmap(croppedimage);
            else
                imw.setBitmap(image);
            imw.setMinV(minValue);
            imw.setMaxV(maxValue);

            ProcessImageTask pit = new ProcessImageTask();
            imw = (ImageWrapper) pit.execute(imw).get();
            treatedimage = imw.getBitmap();
            imv.setImageBitmap(treatedimage);
            histogram = imw.getHistogram();
            histograma = imw.getHist();
            mascara = imw.getMask();
            imc.setBackgroundColor(
                    Color.rgb(imw.getR().intValue(), imw.getG().intValue(), imw.getB().intValue()));
            state[TREAT_IMAGE] = true;

        } catch (Exception e) {
            Log.e(TAG, "Error " + e.getMessage());

        }
    }
}

From source file:com.liberorignanese.android.stepindicatorview.Step.java

public void setUpView(View stepView, Step previous, Step next, int orientation, boolean useSecondaryStepColor) {
    ImageView iconView = (ImageView) stepView.findViewById(R.id.icon_step_layout);
    ImageView lineStartView = (ImageView) stepView.findViewById(R.id.linestart_step_layout);
    ImageView lineEndView = (ImageView) stepView.findViewById(R.id.lineend_step_layout);
    TextView textView = (TextView) stepView.findViewById(R.id.text_step_layout);

    int line_completed = orientation == LinearLayout.HORIZONTAL
            ? (useSecondaryStepColor ? R.drawable.line_completed_horizontal_secondary
                    : R.drawable.line_completed_horizontal)
            : (useSecondaryStepColor ? R.drawable.line_completed_vertical_secondary
                    : R.drawable.line_completed_vertical);
    int line_uncompleted = orientation == LinearLayout.HORIZONTAL
            ? (useSecondaryStepColor ? R.drawable.line_uncompleted_horizontal_secondary
                    : R.drawable.line_uncompleted_horizontal)
            : (useSecondaryStepColor ? R.drawable.line_uncompleted_vertical_secondary
                    : R.drawable.line_uncompleted_vertical);
    int icon_completed = useSecondaryStepColor ? R.drawable.icon_check_secondary : R.drawable.icon_check;
    int icon_uncompleted = useSecondaryStepColor ? R.drawable.icon_circle_secondary : R.drawable.icon_circle;
    int icon_completed_current = useSecondaryStepColor ? R.drawable.icon_check_secondary_current
            : R.drawable.icon_check_current;
    int step_backgroundcolor = Color.TRANSPARENT;
    int step_textcolor = useSecondaryStepColor ? R.color.stepviewindicator_maincolor_secondary
            : R.color.stepviewindicator_maincolor;
    int step_iscurrent_backgroundcolor = useSecondaryStepColor ? R.color.stepviewindicator_maincolor_secondary
            : R.color.stepviewindicator_maincolor;
    int step_iscurrent_textcolor = useSecondaryStepColor ? R.color.stepviewindicator_checkcolor_secondary
            : R.color.stepviewindicator_checkcolor;

    /*/*  ww w. j  a  v  a  2 s  .  com*/
            if(useSecondaryStepColor){
            
            }
    */

    if (previous == null) {
        lineStartView.setVisibility(View.INVISIBLE);
    } else {
        lineStartView.setVisibility(View.VISIBLE);
        if (previous.isCompleted()) {
            lineStartView.setImageResource(line_completed);
            lineStartView.setImageAlpha(255);
        } else {
            lineStartView.setImageResource(line_uncompleted);
            lineStartView.setImageAlpha(alpha);
        }
    }
    if (next == null) {
        lineEndView.setVisibility(View.INVISIBLE);
    } else {
        lineEndView.setVisibility(View.VISIBLE);
        if (isCompleted()) {
            lineEndView.setImageResource(line_completed);
            lineEndView.setImageAlpha(255);
        } else {
            lineEndView.setImageResource(line_uncompleted);
            lineEndView.setImageAlpha(alpha);
        }
    }
    textView.setText(getText());
    if (isCompleted()) {
        iconView.setImageResource(current ? icon_completed_current : icon_completed);
        iconView.setImageAlpha(255);
    } else {
        iconView.setImageResource(icon_uncompleted);
        if (isCurrent()) {
            iconView.setImageAlpha(255);
        } else {
            iconView.setImageAlpha(alpha);
        }
    }

    if (isCurrent()) {
        textView.setTypeface(null, Typeface.BOLD);
        textView.setTextColor(ContextCompat.getColor(stepView.getContext(), step_iscurrent_textcolor));
        textView.setBackgroundColor(
                ContextCompat.getColor(stepView.getContext(), step_iscurrent_backgroundcolor));
    } else {
        textView.setTypeface(null, Typeface.NORMAL);
        textView.setTextColor(ContextCompat.getColor(stepView.getContext(), step_textcolor));
        textView.setBackgroundColor(step_backgroundcolor);
    }
    /*
            if(useSecondaryStepColor){
    textView.setTextColor(ContextCompat.getColor(stepView.getContext(), R.color.stepviewindicator_maincolor_secondary));
            }else{
    textView.setTextColor(ContextCompat.getColor(stepView.getContext(), R.color.stepviewindicator_maincolor));
            }
    */
    stepView.setOnClickListener(onClickListener);

}

From source file:com.hardcopy.retroband.MainActivity.java

public void procesarMuestra() {
    TextView textIndicadorView = (TextView) findViewById(R.id.text_indicador);
    textIndicadorView.setText("Procesando...");

    int[] muestraX = getXRecord();
    int[] muestraY = getYRecord();
    if (muestraX.length > 0 && muestraY.length > 0) {
        int maxX = getMax(muestraX);
        int minY = getMin(muestraY);
        //double varX = getVariance(muestraX);
        //double varY = getVariance(muestraY);

        textIndicadorView.setText("Terminado!");
        boolean fallout = false;

        //         if (varY < 4449) {
        //            if (varY >= 59) {
        //               fallout = false;
        //            } else {
        //               if (varX < 76) {
        //                  fallout = false;
        //               } else {
        //                  fallout = true;
        //               }
        //            }
        //         } else {
        //            fallout = true;
        //         }

        if (minY >= 1184) {
            if (minY < 16000) {
                fallout = false;// ww  w.  j a v  a2 s  .c  o m
            } else {
                if (maxX >= 562) {
                    fallout = false;
                } else {
                    fallout = true;
                }
            }
        } else {
            fallout = true;
        }

        textIndicadorView.setText("MaxX:" + String.valueOf(maxX) + ", MinY:" + String.valueOf(minY));
        if (fallout == true) { // se cay
            Date actualDate = new Date();
            long secondsBetween = (actualDate.getTime() - lastDateArbol.getTime()) / 1000;
            if (secondsBetween > 5) { // mayor a 5 seg
                if (estadoSendMail) {
                    String mensaje = "Alerta variables: " + "MaxX:" + String.valueOf(maxX) + ", MinY:"
                            + String.valueOf(minY);
                    mensaje += "\r\nEnergia X: " + String.valueOf(this.getEnergy(this.getXRecord()));
                    mensaje += "\r\nEnergia Y: " + String.valueOf(this.getEnergy(this.getYRecord()));
                    mensaje += "\r\nEnergia Z: " + String.valueOf(this.getEnergy(this.getZRecord()));
                    mensaje += "\r\nEnergia VecSum: " + String.valueOf(this.getEnergy(this.getVsumRecord()));
                    // probando con transformada wavelet haar
                    double[] muestraVsum = getVsumRecord();
                    double[] coeficientes = getCoef(muestraVsum);
                    mensaje += "\r\nCoeficientes:\r\n" + arrayToString(coeficientes);
                    enviarEmailPersonalizado("Alerta Caida (Arbol de Decisiones con Varianza).", mensaje);
                }
                lastDateArbol = new Date(); // hora actual
            }
            textIndicadorView.setBackgroundColor(Color.parseColor("#FF0000")); // Rojo
            estadoArbol = true;
        } else {
            textIndicadorView.setBackgroundColor(Color.parseColor("#00FF00")); // Verde
            estadoArbol = false;
        }
    }
}

From source file:org.shaastra.helper.SuperAwesomeCardFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/* w  ww  . j  a v  a2s.co m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setLayoutParams(params);
    v.setGravity(Gravity.CENTER);
    //v.setBackgroundResource(R.drawable.background_card);
    v.setText("CARD " + (position + 1));

    if (position == 0) {
        View v1 = inflater.inflate(R.layout.event_info, container, false);
        v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        TextView t1 = (TextView) v1.findViewById(R.id.infotext);
        t1.setText(eintroduction);
        return v1;
    } else if (position == 1)

    {

        String Venue = new String();
        Venue = evenue;

        final String SAC = elatlong;
        //String start=String.valueOf(l.getLatitude())+String.valueOf(l.getLongitude());
        /*
        View v1=inflater.inflate(R.layout.map, container,false);
        v1.setLayoutParams(params);
        WebView wv=(WebView)v1.findViewById(R.id.wv1);
        wv.setWebChromeClient(new WebChromeClient());
        //wv.loadUrl("https://maps.google.com/maps?saddr=13,80&daddr=13,80.02");
        //wv.loadUrl("http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false");
        wv.loadUrl("http://maps.google.com/maps?f=d&daddr=51.448,-0.972");
        wv.getSettings().getBuiltInZoomControls();
        */
        View v1 = inflater.inflate(R.layout.map, container, false);
        v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        TextView location = (TextView) v1.findViewById(R.id.locationText);
        Button mapButton = (Button) v1.findViewById(R.id.mapButton);
        if (evenue.equalsIgnoreCase("NONE")) {
            mapButton.setAlpha(0);
        } else {
            mapButton.setAlpha(1);
        }

        location.setText(Venue);
        mapButton.setOnTouchListener(new View.OnTouchListener() {

            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @SuppressLint("NewApi")
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    v.setAlpha((float) 0.4);
                    v.animate().setInterpolator(new DecelerateInterpolator()).scaleX(0.9f).scaleY(0.9f);

                }
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    v.setAlpha((float) 0.75);
                    v.animate().setInterpolator(new OvershootInterpolator()).scaleX(1f).scaleY(1f);

                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://maps.google.com/maps?f=d&daddr=" + SAC));
                    intent.setComponent(new ComponentName("com.google.android.apps.maps",
                            "com.google.android.maps.MapsActivity"));
                    startActivity(intent);
                }

                return false;
            }
        });

        return v1;
    } else if (position == 2) {
        View v1 = inflater.inflate(R.layout.event_info, container, false);
        v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        TextView t1 = (TextView) v1.findViewById(R.id.infotext);
        t1.setText(eformat);
        return v1;

    } else if (position == 3) {
        View v1 = inflater.inflate(R.layout.prize, container, false);
        v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        TextView t1 = (TextView) v1.findViewById(R.id.prizeText);
        t1.setText(eprize);
        return v1;

    } else if (position == 4) {
        v.setBackgroundColor(Color.GREEN);

    } else if (position == 5) {

        v.setBackgroundColor(Color.MAGENTA);

    } else if (position == 6) {
        v.setBackgroundColor(Color.MAGENTA);

    }
    fl.addView(v);
    return fl;

}

From source file:com.skytree.epubtest.BookViewActivity.java

public TextView makeLabel(int id, String text, int gravity, float textSize, int textColor) {
    TextView label = new TextView(this);
    label.setId(id);/*from w  w  w. j av  a  2s .  c  om*/
    label.setGravity(gravity);
    label.setBackgroundColor(Color.TRANSPARENT);
    label.setText(text);
    label.setTextColor(textColor);
    label.setTextSize(textSize);
    return label;
}

From source file:self.philbrown.droidQuery.$.java

/**
 * Include the html string the selected views. If a view has a setText method, it is used. Otherwise,
 * a new TextView is created. This html can also handle image tags for both urls and local files.
 * Local files should be the name (for example, for R.id.ic_launcher, just use ic_launcher).
 * @param html the HTML String to include
 *///from   www . j a  v a 2 s .  com
public $ html(String html) {
    for (int i = 0; i < this.views.size(); i++) {
        View view = this.views.get(i);
        try {
            Method m = view.getClass().getMethod("setText", new Class<?>[] { CharSequence.class });
            m.invoke(view, (CharSequence) Html.fromHtml(html));
        } catch (Throwable t) {
            if (view instanceof ViewGroup) {
                try {
                    //no setText method. Try a TextView
                    TextView tv = new TextView(this.context);
                    tv.setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
                    tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                            ViewGroup.LayoutParams.FILL_PARENT));
                    ((ViewGroup) view).addView(tv);
                    tv.setText(Html.fromHtml(html, new AsyncImageGetter(tv), null));
                } catch (Throwable t2) {
                    //unable to set content
                    Log.w("droidQuery", "unable to set HTML content");
                }
            } else {
                //unable to set content
                Log.w("droidQuery", "unable to set textual content");
            }
        }
    }

    return this;
}