Example usage for android.view ViewGroup setBackgroundResource

List of usage examples for android.view ViewGroup setBackgroundResource

Introduction

In this page you can find the example usage for android.view ViewGroup setBackgroundResource.

Prototype

@RemotableViewMethod
public void setBackgroundResource(@DrawableRes int resid) 

Source Link

Document

Set the background to a given resource.

Usage

From source file:org.chromium.chrome.browser.compositor.CompositorViewHolder.java

@Override
public void onSwapBuffersCompleted(int pendingSwapBuffersCount) {
    TraceEvent.instant("onSwapBuffersCompleted");

    // Wait until the second frame to turn off the placeholder background on
    // tablets so the tab strip has time to start drawing.
    final ViewGroup controlContainer = (ViewGroup) mControlContainer;
    if (controlContainer != null && controlContainer.getBackground() != null && mHasDrawnOnce) {
        post(new Runnable() {
            @Override//  w  w  w . j  a  v a 2  s  . co m
            public void run() {
                controlContainer.setBackgroundResource(0);
            }
        });
    }

    mHasDrawnOnce = true;

    mPendingSwapBuffersCount = pendingSwapBuffersCount;

    if (!mSkipInvalidation || pendingSwapBuffersCount == 0)
        flushInvalidation();
    mSkipInvalidation = !mSkipInvalidation;
}

From source file:com.marcohc.robotocalendar.RobotoCalendarView.java

public void updateBackgroundSelectDays() {
    if (startDay != null && endDay != null) {
        Calendar auxCalendar = Calendar.getInstance(locale);
        auxCalendar.setTime(currentCalendar.getTime());
        auxCalendar.set(Calendar.DAY_OF_MONTH, 1);
        auxCalendar.set(Calendar.HOUR_OF_DAY, 0);
        auxCalendar.set(Calendar.MINUTE, 0); // set minute in hour
        auxCalendar.set(Calendar.SECOND, 0); // set second in minute
        auxCalendar.set(Calendar.MILLISECOND, 0);
        Calendar startCalendar = getCurrentCalendar();
        startCalendar.setTime(startDay);
        Calendar endCalendar = getCurrentCalendar();
        endCalendar.setTime(endDay);/*  w w  w .  j a v  a 2  s  .c  om*/
        if (auxCalendar.compareTo(endCalendar) > 0)
            return;
        if (auxCalendar.compareTo(startCalendar) > 0) {
            startCalendar = auxCalendar;
            if (startCalendar.compareTo(endCalendar) != 0) {
                ViewGroup startDayOfMonthBackground = getDayOfMonthBackgroundContainer(startCalendar);
                startDayOfMonthBackground.setBackgroundColor(
                        ContextCompat.getColor(getContext(), R.color.roboto_calendar_select_day));
                TextView dayOfMonth = getDayOfMonthText(startCalendar);
                dayOfMonth.setTextColor(ContextCompat.getColor(getContext(), R.color.roboto_calendar_white));
            }
            int totalDaysInMonth = auxCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            Calendar endDayOnMonthCalendar = Calendar.getInstance(locale);
            endDayOnMonthCalendar.setTime(auxCalendar.getTime());
            endDayOnMonthCalendar.set(Calendar.DATE, totalDaysInMonth);
            if (endDayOnMonthCalendar.compareTo(endCalendar) < 0) {
                endCalendar = endDayOnMonthCalendar;
                ViewGroup endDayOfMonthBackground = getDayOfMonthBackgroundContainer(endCalendar);
                endDayOfMonthBackground.setBackgroundColor(
                        ContextCompat.getColor(getContext(), R.color.roboto_calendar_select_day));
                TextView dayOfMonth = getDayOfMonthText(endCalendar);
                dayOfMonth.setTextColor(ContextCompat.getColor(getContext(), R.color.roboto_calendar_white));
            } else {
                ViewGroup endDayOfMonthBackground = getDayOfMonthBackgroundContainer(endCalendar);
                endDayOfMonthBackground.setBackgroundResource(R.drawable.ic_select_right);
                TextView dayOfMonth = getDayOfMonthText(endCalendar);
                dayOfMonth
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.roboto_calendar_select_day));
                ViewGroup dayOfMonthBackground = getDayOfMonthBackground(endCalendar);
                dayOfMonthBackground.setBackgroundResource(R.drawable.circle);
            }
        } else {
            int totalDaysInMonth = auxCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            Calendar endDayOnMonthCalendar = Calendar.getInstance(locale);
            endDayOnMonthCalendar.setTime(auxCalendar.getTime());
            endDayOnMonthCalendar.set(Calendar.DATE, totalDaysInMonth);
            if (endDayOnMonthCalendar.compareTo(startCalendar) < 0)
                return;
            if (endDayOnMonthCalendar.compareTo(endCalendar) < 0) {
                endCalendar = endDayOnMonthCalendar;
                if (startCalendar.compareTo(endCalendar) != 0) {
                    ViewGroup endDayOfMonthBackground = getDayOfMonthBackgroundContainer(endCalendar);
                    endDayOfMonthBackground.setBackgroundColor(
                            ContextCompat.getColor(getContext(), R.color.roboto_calendar_select_day));
                    TextView dayOfMonth = getDayOfMonthText(endCalendar);
                    dayOfMonth
                            .setTextColor(ContextCompat.getColor(getContext(), R.color.roboto_calendar_white));
                }
                ViewGroup startDayOfMonthBackground = getDayOfMonthBackgroundContainer(startCalendar);
                startDayOfMonthBackground.setBackgroundResource(R.drawable.ic_select_left);
                ViewGroup dayOfMonthBackground = getDayOfMonthBackground(startCalendar);
                dayOfMonthBackground.setBackgroundResource(R.drawable.circle);

            } else {
                int compare = startCalendar.compareTo(endCalendar);//compare startdate and enddate, if they are equal, just draw circle not draw background startdate and enddate
                ViewGroup startDayOfMonthBackground = getDayOfMonthBackgroundContainer(startCalendar);
                if (compare != 0)
                    startDayOfMonthBackground.setBackgroundResource(R.drawable.ic_select_left);
                ViewGroup dayOfMonthBackground = getDayOfMonthBackground(startCalendar);
                dayOfMonthBackground.setBackgroundResource(R.drawable.circle);
                ViewGroup endDayOfMonthBackground = getDayOfMonthBackgroundContainer(endCalendar);
                if (compare != 0)
                    endDayOfMonthBackground.setBackgroundResource(R.drawable.ic_select_right);
                dayOfMonthBackground = getDayOfMonthBackground(endCalendar);
                dayOfMonthBackground.setBackgroundResource(R.drawable.circle);
                TextView dayOfMonth = getDayOfMonthText(endCalendar);
                dayOfMonth
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.roboto_calendar_select_day));
                dayOfMonth = getDayOfMonthText(startCalendar);
                dayOfMonth
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.roboto_calendar_select_day));
            }

        }
        String formattedDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(startCalendar.getTime());
        int days = getDays(startCalendar, endCalendar);

        for (int i = 1; i < days; i++) {
            startCalendar.add(Calendar.DAY_OF_YEAR, 1);
            ViewGroup dayOfMonthBackground = getDayOfMonthBackgroundContainer(startCalendar);
            TextView dayOfMonth = getDayOfMonthText(startCalendar);
            if (dayOfMonth.getVisibility() != View.VISIBLE)
                continue;
            dayOfMonth.setTextColor(ContextCompat.getColor(getContext(), R.color.roboto_calendar_white));
            dayOfMonthBackground.setBackgroundColor(
                    ContextCompat.getColor(getContext(), R.color.roboto_calendar_select_day));
        }
    } else {
        if (startDay != null) {
            Calendar startDayOnMonthCalendar = Calendar.getInstance(locale);
            startDayOnMonthCalendar.setTime(currentCalendar.getTime());
            startDayOnMonthCalendar.set(Calendar.DAY_OF_MONTH, 1);
            startDayOnMonthCalendar.set(Calendar.HOUR_OF_DAY, 0);
            startDayOnMonthCalendar.set(Calendar.MINUTE, 0); // set minute in hour
            startDayOnMonthCalendar.set(Calendar.SECOND, 0); // set second in minute
            startDayOnMonthCalendar.set(Calendar.MILLISECOND, 0);

            Calendar endDayOnMonthCalendar = Calendar.getInstance(locale);
            endDayOnMonthCalendar.setTime(startDayOnMonthCalendar.getTime());
            int totalDaysInMonth = startDayOnMonthCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            endDayOnMonthCalendar.set(Calendar.DATE, totalDaysInMonth);
            Calendar startCalendar = getCurrentCalendar();
            startCalendar.setTime(startDay);
            if (startCalendar.compareTo(startDayOnMonthCalendar) >= 0
                    && startCalendar.compareTo(endDayOnMonthCalendar) <= 0) {
                selectStartDay(startDay);
            }
        }
    }

}

From source file:org.onebusaway.android.ui.TripDetailsListFragment.java

private void setUpHeader() {
    ObaTripStatus status = mTripInfo.getStatus();
    ObaReferences refs = mTripInfo.getRefs();

    Context context = getActivity();

    String tripId = mTripInfo.getId();

    ObaTrip trip = refs.getTrip(tripId);
    ObaRoute route = refs.getRoute(trip.getRouteId());
    TextView shortName = (TextView) getView().findViewById(R.id.short_name);
    shortName.setText(route.getShortName());

    TextView longName = (TextView) getView().findViewById(R.id.long_name);
    longName.setText(trip.getHeadsign());

    TextView agency = (TextView) getView().findViewById(R.id.agency);
    agency.setText(refs.getAgency(route.getAgencyId()).getName());

    TextView vehicleView = (TextView) getView().findViewById(R.id.vehicle);
    TextView vehicleDeviation = (TextView) getView().findViewById(R.id.status);
    ViewGroup realtime = (ViewGroup) getView().findViewById(R.id.eta_realtime_indicator);
    realtime.setVisibility(View.GONE);
    ViewGroup statusLayout = (ViewGroup) getView().findViewById(R.id.status_layout);

    if (status == null) {
        // Show schedule info only
        vehicleView.setText(null);//w ww .j  av  a2s. c o m
        vehicleView.setVisibility(View.GONE);
        vehicleDeviation.setText(context.getString(R.string.trip_details_scheduled_data));
        return;
    }

    if (!TextUtils.isEmpty(status.getVehicleId())) {
        // Show vehicle info
        vehicleView.setText(context.getString(R.string.trip_details_vehicle, status.getVehicleId()));
        vehicleView.setVisibility(View.VISIBLE);
    } else {
        vehicleView.setVisibility(View.GONE);
    }

    // Set status color in header
    statusLayout.setBackgroundResource(R.drawable.round_corners_style_b_header_status);
    GradientDrawable d = (GradientDrawable) statusLayout.getBackground();

    int statusColor;

    if (!status.isPredicted()) {
        // We have only schedule info, but the bus position can still be interpolated
        vehicleDeviation.setText(context.getString(R.string.trip_details_scheduled_data));
        statusColor = R.color.stop_info_scheduled_time;
        d.setColor(getResources().getColor(statusColor));
        return;
    }

    /**
     * We have real-time info
     */
    realtime.setVisibility(View.VISIBLE);

    long deviation = status.getScheduleDeviation();
    long deviationMin = TimeUnit.SECONDS.toMinutes(status.getScheduleDeviation());
    long minutes = Math.abs(deviation) / 60;
    long seconds = Math.abs(deviation) % 60;
    String lastUpdate = DateUtils.formatDateTime(getActivity(), status.getLastUpdateTime(),
            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT);

    statusColor = ArrivalInfo.computeColorFromDeviation(deviationMin);
    if (statusColor != R.color.stop_info_ontime) {
        // Show early/late/scheduled color
        d.setColor(getResources().getColor(statusColor));
    } else {
        // For on-time, use header default color
        d.setColor(getResources().getColor(R.color.theme_primary));
    }

    if (deviation >= 0) {
        if (deviation < 60) {
            vehicleDeviation
                    .setText(context.getString(R.string.trip_details_real_time_sec_late, seconds, lastUpdate));
        } else {
            vehicleDeviation.setText(context.getString(R.string.trip_details_real_time_min_sec_late, minutes,
                    seconds, lastUpdate));
        }
    } else {
        if (deviation > -60) {
            vehicleDeviation
                    .setText(context.getString(R.string.trip_details_real_time_sec_early, seconds, lastUpdate));
        } else {
            vehicleDeviation.setText(context.getString(R.string.trip_details_real_time_min_sec_early, minutes,
                    seconds, lastUpdate));
        }
    }
}

From source file:com.marcohc.robotocalendar.RobotoCalendarView.java

private void setDaysInCalendar() {
    Calendar auxCalendar = Calendar.getInstance(locale);
    auxCalendar.setTime(currentCalendar.getTime());
    auxCalendar.set(Calendar.DAY_OF_MONTH, 1);
    int firstDayOfMonth = auxCalendar.get(Calendar.DAY_OF_WEEK);
    TextView dayOfMonthText;//  w ww.j a  va2s .  c om
    ViewGroup dayOfMonthContainer;

    // Calculate dayOfMonthIndex
    int dayOfMonthIndex = getWeekIndex(firstDayOfMonth, auxCalendar);

    for (int i = 1; i <= auxCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++, dayOfMonthIndex++) {
        dayOfMonthContainer = (ViewGroup) view.findViewWithTag(DAY_OF_MONTH_CONTAINER + dayOfMonthIndex);
        dayOfMonthText = (TextView) view.findViewWithTag(DAY_OF_MONTH_TEXT + dayOfMonthIndex);
        if (dayOfMonthText == null) {
            break;
        }
        dayOfMonthContainer.setOnClickListener(onDayOfMonthClickListener);
        dayOfMonthText.setVisibility(View.VISIBLE);
        dayOfMonthText.setText(String.valueOf(i));
        dayOfMonthText.setTextColor(ContextCompat.getColor(getContext(), R.color.roboto_calendar_day_of_month));
        dayOfMonthContainer.setBackgroundResource(0);
    }

    // If the last week row has no visible days, hide it or show it in case
    ViewGroup weekRow = (ViewGroup) view.findViewWithTag("weekRow6");
    dayOfMonthText = (TextView) view.findViewWithTag("dayOfMonthText36");
    if (dayOfMonthText.getVisibility() == INVISIBLE) {
        weekRow.setVisibility(GONE);
    } else {
        weekRow.setVisibility(VISIBLE);
    }
    updateBackgroundSelectDays();
}

From source file:com.marcohc.robotocalendar.RobotoCalendarView.java

private void initializeDaysOfMonthLayout() {

    TextView dayOfMonthText;//from   www .  j a  va  2 s  . c o  m
    //        View firstUnderline;
    //        View secondUnderline;
    ViewGroup dayOfMonthContainer;
    ViewGroup dayOfMonthBackground;

    for (int i = 1; i < 43; i++) {

        dayOfMonthContainer = (ViewGroup) view.findViewWithTag(DAY_OF_MONTH_CONTAINER + i);
        dayOfMonthBackground = (ViewGroup) view.findViewWithTag(DAY_OF_MONTH_BACKGROUND + i);
        dayOfMonthText = (TextView) view.findViewWithTag(DAY_OF_MONTH_TEXT + i);
        //            firstUnderline = view.findViewWithTag(FIRST_UNDERLINE + i);
        //            secondUnderline = view.findViewWithTag(SECOND_UNDERLINE + i);

        dayOfMonthText.setVisibility(View.INVISIBLE);
        //            firstUnderline.setVisibility(View.INVISIBLE);
        //            secondUnderline.setVisibility(View.INVISIBLE);

        // Apply styles
        dayOfMonthText.setBackgroundResource(android.R.color.transparent);
        dayOfMonthContainer.setBackgroundResource(android.R.color.transparent);
        dayOfMonthContainer.setOnClickListener(null);
        dayOfMonthBackground.setBackgroundResource(android.R.color.transparent);
    }
}