Example usage for android.widget TextView getTextColors

List of usage examples for android.widget TextView getTextColors

Introduction

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

Prototype

public final ColorStateList getTextColors() 

Source Link

Document

Gets the text colors for the different states (normal, selected, focused) of the TextView.

Usage

From source file:net.mceoin.cominghome.MainActivity.java

protected void showAbout() {
    // Inflate the about message contents
    @SuppressLint("InflateParams")
    View messageView = getLayoutInflater().inflate(R.layout.about, null, false);

    PackageInfo pi;/*w  w w  . j ava  2  s.  co  m*/
    String version = "";
    try {
        PackageManager pm = this.getPackageManager();
        String pn = this.getPackageName();
        if (pm == null) {
            version = "unknown";
        } else {
            pi = pm.getPackageInfo(pn, 0);
            version = pi.versionName;
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    TextView versionView = (TextView) messageView.findViewById(R.id.about_version);
    versionView.setText(version);

    // When linking text, force to always use default color. This works
    // around a pressed color state bug.
    TextView textView = (TextView) messageView.findViewById(R.id.about_credits);
    int defaultColor = textView.getTextColors().getDefaultColor();
    textView.setTextColor(defaultColor);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setIcon(R.drawable.home);
    builder.setTitle(R.string.app_name);
    builder.setView(messageView);
    builder.create();
    builder.show();
}

From source file:com.example.sam14240619331555.food_app.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();
    title.clear();/*from  w w w .j  a  v a2 s.c o  m*/
    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);

        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        textColor = tabTitleView.getTextColors();
        if (i == 2) {
            tabTitleView.setTextColor(Color.parseColor("#f5f5f5"));
        }
        title.add(tabTitleView);
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:com.mobicage.rogerthat.FriendDetailActivity.java

@SuppressWarnings("WrongConstant")
private Friend showFriend(Intent intent) {
    T.UI();/*from   ww w .  jav a  2 s  .  c om*/

    final Friend friend = loadFriend(intent);
    if (friend == null) {
        return null;
    }

    mServiceArea.setVisibility(getServiceAreaVisibility());
    mPokeArea.setVisibility(getPokeVisibility());
    mFriendArea.setVisibility(getFriendAreaVisibility());
    mHeader.setVisibility(getHeaderVisibility());

    final ImageView image = (ImageView) findViewById(R.id.friend_avatar);
    if (friend.avatar == null) {
        image.setImageBitmap(mFriendsPlugin.getMissingFriendAvatarBitmap());
    } else {
        final Bitmap avatarBitmap = BitmapFactory.decodeByteArray(friend.avatar, 0, friend.avatar.length);
        image.setImageBitmap(ImageHelper.getRoundedCornerAvatar(avatarBitmap));
    }

    final TextView nameView = (TextView) findViewById(R.id.friend_name);
    mFriendName = friend.getDisplayName();
    nameView.setText(mFriendName);
    nameView.setTextColor(ContextCompat.getColor(this, android.R.color.primary_text_light));

    final TextView emailView = (TextView) findViewById(R.id.email);
    emailView.setText(friend.getDisplayEmail());
    emailView.setTextColor(nameView.getTextColors());

    if (friend.existenceStatus == Friend.NOT_FOUND || friend.existenceStatus == Friend.INVITE_PENDING) {
        final Button pokeBtn = (Button) findViewById(R.id.poke_button);
        pokeBtn.setText(R.string.follow);
        pokeBtn.setOnClickListener(new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                if (mFriendsPlugin.inviteService(mFriend)) {
                    finish();
                }
            }
        });
    } else if (TextUtils.isEmptyOrWhitespace(friend.pokeDescription)) {
        findViewById(R.id.poke_area).setVisibility(View.GONE);
    } else {
        findViewById(R.id.poke_area).setVisibility(View.VISIBLE);
        final Button pokeBtn = (Button) findViewById(R.id.poke_button);
        pokeBtn.setText(friend.pokeDescription);
        pokeBtn.setOnClickListener(new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                T.UI();
                poke();
            }
        });
    }

    mDescriptionView.setText(friend.description);

    if (friend.descriptionBranding != null) {
        boolean available = false;
        try {
            available = mFriendsPlugin.getBrandingMgr().isBrandingAvailable(friend.descriptionBranding);
        } catch (BrandingFailureException e) {
            // ignore
        }
        if (available) {
            showBrandedDescription(friend);
        } else {
            mFriendsPlugin.getBrandingMgr().queue(friend);
        }
    } else {
        mDescriptionView.setVisibility(View.VISIBLE);
        mServiceArea.findViewById(R.id.webview).setVisibility(View.GONE);
        mTopArea.setBackgroundResource(R.color.mc_background_color);
    }

    final CheckBox iShareLocationCheckBox = (CheckBox) findViewById(R.id.share_location);
    iShareLocationCheckBox.setOnCheckedChangeListener(null);
    iShareLocationCheckBox.setChecked(friend.shareLocation);
    iShareLocationCheckBox.setText(getString(R.string.friend_share_location));

    iShareLocationCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            T.UI();
            mFriendsPlugin.updateFriendShareLocation(friend.email, isChecked);
        }
    });

    dismissDialogs();

    return friend;
}

From source file:com.morgan.sunrisealarm.MainActivity.java

private void setupClient() {
    Log.d(TAG, "setupClient()");

    mOnOffSwitchChanged = new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            WidgetId widget = new WidgetId(buttonView);

            Log.d(TAG, "OnCheckedChangeListener");

            TextView dayText = (TextView) findViewById(widget.getDayTextId());
            TextView alarmTimeText = (TextView) findViewById(widget.getAlarmTextId());

            if (isChecked) {
                dayText.setEnabled(true);
                alarmTimeText.setEnabled(true);
                alarmTimeText.setTextColor(getResources().getColor(android.R.color.black));

                AlarmTime time = new AlarmTime(alarmTimeText.getText().toString());

                Command command = new Command();
                command.setAlarm(widget.getAlarmId(), time.getHour(), time.getHour());
            } else {
                dayText.setEnabled(false);
                alarmTimeText.setEnabled(false);
                alarmTimeText.setTextColor(dayText.getTextColors());

                AlarmTime time = new AlarmTime(0, 0);
                alarmTimeText.setText(time.getString());

                Command command = new Command();
                command.setAlarm(widget.getAlarmId(), Constants.HOUR_ALARM_OFF, Constants.MIN_ALARM_OFF);
            }//from w  w w. ja  v a2s .  c  om
        }
    };

    mBluetoothClient = new BluetoothClient(getApplicationContext(), mHandler);

    BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(mAddress);
    mBluetoothClient.connect(device);
}

From source file:org.petero.droidfish.activities.EditBoard.java

private final void initUI() {
    setContentView(R.layout.editboard);//from ww  w .j a  v a2 s  .  c  om
    Util.overrideFonts(findViewById(android.R.id.content));

    View firstTitleLine = findViewById(R.id.first_title_line);
    View secondTitleLine = findViewById(R.id.second_title_line);
    cb = (ChessBoardEdit) findViewById(R.id.eb_chessboard);
    status = (TextView) findViewById(R.id.eb_status);
    okButton = (Button) findViewById(R.id.eb_ok);
    cancelButton = (Button) findViewById(R.id.eb_cancel);

    TextView whiteTitleText = (TextView) findViewById(R.id.white_clock);
    whiteTitleText.setVisibility(View.GONE);
    TextView blackTitleText = (TextView) findViewById(R.id.black_clock);
    blackTitleText.setVisibility(View.GONE);
    TextView engineTitleText = (TextView) findViewById(R.id.title_text);
    engineTitleText.setVisibility(View.GONE);
    whiteFigText = (TextView) findViewById(R.id.white_pieces);
    whiteFigText.setTypeface(figNotation);
    whiteFigText.setSelected(true);
    whiteFigText.setTextColor(whiteTitleText.getTextColors());
    blackFigText = (TextView) findViewById(R.id.black_pieces);
    blackFigText.setTypeface(figNotation);
    blackFigText.setSelected(true);
    blackFigText.setTextColor(blackTitleText.getTextColors());
    TextView summaryTitleText = (TextView) findViewById(R.id.title_text_summary);
    summaryTitleText.setText(R.string.edit_board);

    TextUtils.TruncateAt where = autoScrollTitle ? TextUtils.TruncateAt.MARQUEE : TextUtils.TruncateAt.END;
    engineTitleText.setEllipsize(where);
    whiteFigText.setEllipsize(where);
    blackFigText.setEllipsize(where);

    firstTitleLine.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            openOptionsMenu();
        }
    });
    secondTitleLine.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            openOptionsMenu();
        }
    });

    okButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            sendBackResult();
        }
    });
    cancelButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            setResult(RESULT_CANCELED);
            finish();
        }
    });

    status.setFocusable(false);
    cb.setFocusable(true);
    cb.requestFocus();
    cb.setClickable(true);
    cb.setOnTouchListener(new OnTouchListener() {
        private boolean pending = false;
        private int sq0 = -1;
        private Handler handler = new Handler();
        private Runnable runnable = new Runnable() {
            public void run() {
                pending = false;
                handler.removeCallbacks(runnable);
                ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(20);
                showDialog(EDIT_DIALOG);
            }
        };

        public boolean onTouch(View v, MotionEvent event) {
            int action = MotionEventCompat.getActionMasked(event);
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                handler.postDelayed(runnable, ViewConfiguration.getLongPressTimeout());
                sq0 = cb.eventToSquare(event);
                pending = true;
                break;
            case MotionEvent.ACTION_UP:
                if (pending) {
                    pending = false;
                    handler.removeCallbacks(runnable);
                    int sq = cb.eventToSquare(event);
                    if (sq == sq0) {
                        Move m = cb.mousePressed(sq);
                        if (m != null)
                            doMove(m);
                        setEgtbHints(cb.getSelectedSquare());
                    }
                }
                break;
            case MotionEvent.ACTION_CANCEL:
                pending = false;
                handler.removeCallbacks(runnable);
                break;
            }
            return true;
        }
    });
    cb.setOnTrackballListener(new ChessBoard.OnTrackballListener() {
        public void onTrackballEvent(MotionEvent event) {
            Move m = cb.handleTrackballEvent(event);
            if (m != null)
                doMove(m);
            setEgtbHints(cb.getSelectedSquare());
        }
    });
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

/**
 * Applies the specified text appearance resource to a paint, returning the
 * text color if one is set in the text appearance.
 *
 * @param p     the paint to modify/*from   ww w .  j a v a2 s  . c  o m*/
 * @param resId the resource ID of the text appearance
 * @return the text color, if available
 */
private ColorStateList applyTextAppearance(Paint p, int resId) {
    // Workaround for inaccessible R.styleable.TextAppearance_*
    TextView tv = new TextView(mContext);
    if (SUtils.isApi_23_OrHigher()) {
        tv.setTextAppearance(resId);
    } else {
        //noinspection deprecation
        tv.setTextAppearance(mContext, resId);
    }

    p.setTypeface(tv.getTypeface());
    p.setTextSize(tv.getTextSize());

    final ColorStateList textColor = tv.getTextColors();

    if (textColor != null) {
        final int enabledColor = textColor.getColorForState(ENABLED_STATE_SET, 0);
        p.setColor(enabledColor);
    }

    return textColor;
}

From source file:universe.constellation.orion.viewer.OrionViewerActivity.java

public void initRotationScreen() {
    //if (getDevice() instanceof EdgeDevice) {
    if (false) {//from   w  w w.j  av a 2s. c om
        final RadioGroup rotationGroup = (RadioGroup) findMyViewById(R.id.rotationGroup);

        rotationGroup.check(R.id.rotate0);

        if (Device.Info.NOOK2) {
            RadioButton r0 = (RadioButton) rotationGroup.findViewById(R.id.rotate0);
            RadioButton r90 = (RadioButton) rotationGroup.findViewById(R.id.rotate90);
            RadioButton r270 = (RadioButton) rotationGroup.findViewById(R.id.rotate270);
            TextView tv = (TextView) findMyViewById(R.id.navigation_title);
            int color = tv.getTextColors().getDefaultColor();
            r0.setTextColor(color);
            r90.setTextColor(color);
            r270.setTextColor(color);
        }

        getSubscriptionManager().addDocListeners(new DocumentViewAdapter() {
            @Override
            public void documentOpened(Controller controller) {
                updateRotation();
            }
        });

        ImageButton apply = (ImageButton) findMyViewById(R.id.rotation_apply);
        apply.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                onApplyAction(true);
                int id = rotationGroup.getCheckedRadioButtonId();
                controller.setRotation(id == R.id.rotate0 ? 0 : id == R.id.rotate90 ? -1 : 1);
            }
        });

        ListView list = (ListView) findMyViewById(R.id.rotationList);
        list.setVisibility(View.GONE);
    } else {
        RadioGroup rotationGroup = (RadioGroup) findMyViewById(R.id.rotationGroup);
        rotationGroup.setVisibility(View.GONE);

        final ListView list = (ListView) findMyViewById(R.id.rotationList);

        //set choices and replace 0 one with Application Default
        boolean isLevel9 = getOrionContext().getSdkVersion() >= 9;
        CharSequence[] values = getResources().getTextArray(
                isLevel9 ? R.array.screen_orientation_full_desc : R.array.screen_orientation_desc);
        CharSequence[] newValues = new CharSequence[values.length];
        for (int i = 0; i < values.length; i++) {
            newValues[i] = values[i];
        }
        newValues[0] = getResources().getString(R.string.orientation_default_rotation);

        list.setAdapter(Device.Info.NOOK2
                ? new Nook2ListAdapter(this, android.R.layout.simple_list_item_single_choice, newValues,
                        (TextView) findMyViewById(R.id.navigation_title))
                : new ArrayAdapter(this, android.R.layout.simple_list_item_single_choice, newValues));

        list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        list.setItemChecked(0, true);

        list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
            public void onItemClick(android.widget.AdapterView parent, View view, int position, long id) {
                CheckedTextView check = (CheckedTextView) view;
                check.setChecked(!check.isChecked());
            }
        });

        final CharSequence[] ORIENTATION_ARRAY = getResources().getTextArray(R.array.screen_orientation_full);

        list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
            public void onItemClick(android.widget.AdapterView parent, View view, int position, long id) {
                onApplyAction(true);
                String orientation = ORIENTATION_ARRAY[position].toString();
                controller.changeOrinatation(orientation);
            }
        });

        ImageButton apply = (ImageButton) findMyViewById(R.id.rotation_apply);
        apply.setVisibility(View.GONE);
        //            apply.setOnClickListener(new View.OnClickListener() {
        //                public void onClick(View view) {
        //                    onApplyAction(true);
        //                }
        //            });
    }

    ImageButton cancel = (ImageButton) findMyViewById(R.id.rotation_close);
    cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onAnimatorCancel();
            updateRotation();
        }
    });
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

private TextView makeCommonTextView(boolean header) {
    TextView textView = new TextView(context, null,
            C.API_LOLLIPOP ? android.R.attr.textAppearanceListItem : android.R.attr.textAppearance);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f);
    textView.setGravity(Gravity.CENTER_VERTICAL);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setSingleLine(true);/*w  w  w .ja  va2s.  c o  m*/
    if (C.API_LOLLIPOP) {
        textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
        int color = textView.getTextColors().getDefaultColor();
        if (header) {
            color &= 0x5effffff;
        } else {
            color &= 0xddffffff;
        }
        textView.setTextColor(color);
    }
    return textView;
}

From source file:org.openhab.habdroid.ui.OpenHABWidgetAdapter.java

@SuppressWarnings("deprecation")
@Override/*ww  w.j av a2 s.  c  om*/
public View getView(int position, View convertView, ViewGroup parent) {
    /* TODO: This definitely needs some huge refactoring */
    final RelativeLayout widgetView;
    TextView labelTextView;
    TextView valueTextView;
    int widgetLayout;
    String[] splitString;
    OpenHABWidget openHABWidget = getItem(position);
    int screenWidth = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay().getWidth();
    switch (this.getItemViewType(position)) {
    case TYPE_FRAME:
        widgetLayout = R.layout.openhabwidgetlist_frameitem;
        break;
    case TYPE_GROUP:
        widgetLayout = R.layout.openhabwidgetlist_groupitem;
        break;
    case TYPE_SECTIONSWITCH:
        widgetLayout = R.layout.openhabwidgetlist_sectionswitchitem;
        break;
    case TYPE_SWITCH:
        widgetLayout = R.layout.openhabwidgetlist_switchitem;
        break;
    case TYPE_ROLLERSHUTTER:
        widgetLayout = R.layout.openhabwidgetlist_rollershutteritem;
        break;
    case TYPE_TEXT:
        widgetLayout = R.layout.openhabwidgetlist_textitem;
        break;
    case TYPE_SLIDER:
        widgetLayout = R.layout.openhabwidgetlist_slideritem;
        break;
    case TYPE_IMAGE:
        widgetLayout = R.layout.openhabwidgetlist_imageitem;
        break;
    case TYPE_SELECTION:
        widgetLayout = R.layout.openhabwidgetlist_selectionitem;
        break;
    case TYPE_SETPOINT:
        widgetLayout = R.layout.openhabwidgetlist_setpointitem;
        break;
    case TYPE_CHART:
        widgetLayout = R.layout.openhabwidgetlist_chartitem;
        break;
    case TYPE_VIDEO:
        widgetLayout = R.layout.openhabwidgetlist_videoitem;
        break;
    case TYPE_VIDEO_MJPEG:
        widgetLayout = R.layout.openhabwidgetlist_videomjpegitem;
        break;
    case TYPE_WEB:
        widgetLayout = R.layout.openhabwidgetlist_webitem;
        break;
    case TYPE_COLOR:
        widgetLayout = R.layout.openhabwidgetlist_coloritem;
        break;
    default:
        widgetLayout = R.layout.openhabwidgetlist_genericitem;
        break;
    }
    if (convertView == null) {
        widgetView = new RelativeLayout(getContext());
        String inflater = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater vi;
        vi = (LayoutInflater) getContext().getSystemService(inflater);
        vi.inflate(widgetLayout, widgetView, true);
    } else {
        widgetView = (RelativeLayout) convertView;
    }

    // Process the colour attributes
    Integer iconColor = openHABWidget.getIconColor();
    Integer labelColor = openHABWidget.getLabelColor();
    Integer valueColor = openHABWidget.getValueColor();

    // Process widgets icon image
    MySmartImageView widgetImage = (MySmartImageView) widgetView.findViewById(R.id.widgetimage);
    // Some of widgets, for example Frame doesnt' have an icon, so...
    if (widgetImage != null) {
        if (openHABWidget.getIcon() != null) {
            // This is needed to escape possible spaces and everything according to rfc2396
            String iconUrl = openHABBaseUrl + "images/" + Uri.encode(openHABWidget.getIcon() + ".png");
            //                Log.d(TAG, "Will try to load icon from " + iconUrl);
            // Now set image URL
            widgetImage.setImageUrl(iconUrl, R.drawable.blank_icon, openHABUsername, openHABPassword);
            if (iconColor != null)
                widgetImage.setColorFilter(iconColor);
            else
                widgetImage.clearColorFilter();
        }
    }
    TextView defaultTextView = new TextView(widgetView.getContext());
    // Get TextView for widget label and set it's color
    labelTextView = (TextView) widgetView.findViewById(R.id.widgetlabel);
    // Change label color only for non-frame widgets
    if (labelColor != null && labelTextView != null && this.getItemViewType(position) != TYPE_FRAME) {
        Log.d(TAG, String.format("Setting label color to %d", labelColor));
        labelTextView.setTextColor(labelColor);
    } else if (labelTextView != null && this.getItemViewType(position) != TYPE_FRAME)
        labelTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor());
    // Get TextView for widget value and set it's color
    valueTextView = (TextView) widgetView.findViewById(R.id.widgetvalue);
    if (valueColor != null && valueTextView != null) {
        Log.d(TAG, String.format("Setting value color to %d", valueColor));
        valueTextView.setTextColor(valueColor);
    } else if (valueTextView != null)
        valueTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor());
    defaultTextView = null;
    switch (getItemViewType(position)) {
    case TYPE_FRAME:
        if (labelTextView != null) {
            labelTextView.setText(openHABWidget.getLabel());
            if (valueColor != null)
                labelTextView.setTextColor(valueColor);
        }
        widgetView.setClickable(false);
        if (openHABWidget.getLabel().length() > 0) { // hide empty frames
            widgetView.setVisibility(View.VISIBLE);
            labelTextView.setVisibility(View.VISIBLE);
        } else {
            widgetView.setVisibility(View.GONE);
            labelTextView.setVisibility(View.GONE);
        }
        break;
    case TYPE_GROUP:
        if (labelTextView != null && valueTextView != null) {
            splitString = openHABWidget.getLabel().split("\\[|\\]");
            labelTextView.setText(splitString[0]);
            if (splitString.length > 1) { // We have some value
                valueTextView.setText(splitString[1]);
            } else {
                // This is needed to clean up cached TextViews
                valueTextView.setText("");
            }
        }
        break;
    case TYPE_SECTIONSWITCH:
        splitString = openHABWidget.getLabel().split("\\[|\\]");
        if (labelTextView != null)
            labelTextView.setText(splitString[0]);
        if (splitString.length > 1 && valueTextView != null) { // We have some value
            valueTextView.setText(splitString[1]);
        } else {
            // This is needed to clean up cached TextViews
            valueTextView.setText("");
        }
        RadioGroup sectionSwitchRadioGroup = (RadioGroup) widgetView.findViewById(R.id.sectionswitchradiogroup);
        // As we create buttons in this radio in runtime, we need to remove all
        // exiting buttons first
        sectionSwitchRadioGroup.removeAllViews();
        sectionSwitchRadioGroup.setTag(openHABWidget);
        Iterator<OpenHABWidgetMapping> sectionMappingIterator = openHABWidget.getMappings().iterator();
        while (sectionMappingIterator.hasNext()) {
            OpenHABWidgetMapping widgetMapping = sectionMappingIterator.next();
            SegmentedControlButton segmentedControlButton = (SegmentedControlButton) LayoutInflater
                    .from(sectionSwitchRadioGroup.getContext())
                    .inflate(R.layout.openhabwidgetlist_sectionswitchitem_button, sectionSwitchRadioGroup,
                            false);
            segmentedControlButton.setText(widgetMapping.getLabel());
            segmentedControlButton.setTag(widgetMapping.getCommand());
            if (openHABWidget.getItem() != null && widgetMapping.getCommand() != null) {
                if (widgetMapping.getCommand().equals(openHABWidget.getItem().getState())) {
                    segmentedControlButton.setChecked(true);
                } else {
                    segmentedControlButton.setChecked(false);
                }
            } else {
                segmentedControlButton.setChecked(false);
            }
            segmentedControlButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.i(TAG, "Button clicked");
                    RadioGroup group = (RadioGroup) view.getParent();
                    if (group.getTag() != null) {
                        OpenHABWidget radioWidget = (OpenHABWidget) group.getTag();
                        SegmentedControlButton selectedButton = (SegmentedControlButton) view;
                        if (selectedButton.getTag() != null) {
                            sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag());
                        }
                    }
                }
            });
            sectionSwitchRadioGroup.addView(segmentedControlButton);
        }

        sectionSwitchRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                OpenHABWidget radioWidget = (OpenHABWidget) group.getTag();
                SegmentedControlButton selectedButton = (SegmentedControlButton) group.findViewById(checkedId);
                if (selectedButton != null) {
                    Log.d(TAG, "Selected " + selectedButton.getText());
                    Log.d(TAG, "Command = " + (String) selectedButton.getTag());
                    //                  radioWidget.getItem().sendCommand((String)selectedButton.getTag());
                    sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag());
                }
            }
        });
        break;
    case TYPE_SWITCH:
        if (labelTextView != null)
            labelTextView.setText(openHABWidget.getLabel());
        SwitchCompat switchSwitch = (SwitchCompat) widgetView.findViewById(R.id.switchswitch);
        if (openHABWidget.hasItem()) {
            if (openHABWidget.getItem().getStateAsBoolean()) {
                switchSwitch.setChecked(true);
            } else {
                switchSwitch.setChecked(false);
            }
        }
        switchSwitch.setTag(openHABWidget.getItem());
        switchSwitch.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent motionEvent) {
                SwitchCompat switchSwitch = (SwitchCompat) v;
                OpenHABItem linkedItem = (OpenHABItem) switchSwitch.getTag();
                if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP)
                    if (!switchSwitch.isChecked()) {
                        sendItemCommand(linkedItem, "ON");
                    } else {
                        sendItemCommand(linkedItem, "OFF");
                    }
                return false;
            }
        });
        break;
    case TYPE_COLOR:
        if (labelTextView != null)
            labelTextView.setText(openHABWidget.getLabel());
        ImageButton colorUpButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_up);
        ImageButton colorDownButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_down);
        ImageButton colorColorButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_color);
        colorUpButton.setTag(openHABWidget.getItem());
        colorDownButton.setTag(openHABWidget.getItem());
        colorColorButton.setTag(openHABWidget.getItem());
        colorUpButton.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent motionEvent) {
                ImageButton colorButton = (ImageButton) v;
                OpenHABItem colorItem = (OpenHABItem) colorButton.getTag();
                if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP)
                    sendItemCommand(colorItem, "ON");
                return false;
            }
        });
        colorDownButton.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent motionEvent) {
                ImageButton colorButton = (ImageButton) v;
                OpenHABItem colorItem = (OpenHABItem) colorButton.getTag();
                if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP)
                    sendItemCommand(colorItem, "OFF");
                return false;
            }
        });
        colorColorButton.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent motionEvent) {
                ImageButton colorButton = (ImageButton) v;
                OpenHABItem colorItem = (OpenHABItem) colorButton.getTag();
                if (colorItem != null) {
                    if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
                        Log.d(TAG, "Time to launch color picker!");
                        ColorPickerDialog colorDialog = new ColorPickerDialog(widgetView.getContext(),
                                new OnColorChangedListener() {
                                    public void colorChanged(float[] hsv, View v) {
                                        Log.d(TAG, "New color HSV = " + hsv[0] + ", " + hsv[1] + ", " + hsv[2]);
                                        String newColor = String.valueOf(hsv[0]) + ","
                                                + String.valueOf(hsv[1] * 100) + ","
                                                + String.valueOf(hsv[2] * 100);
                                        OpenHABItem colorItem = (OpenHABItem) v.getTag();
                                        sendItemCommand(colorItem, newColor);
                                    }
                                }, colorItem.getStateAsHSV());
                        colorDialog.setTag(colorItem);
                        colorDialog.show();
                    }
                }
                return false;
            }
        });
        break;
    case TYPE_ROLLERSHUTTER:
        if (labelTextView != null)
            labelTextView.setText(openHABWidget.getLabel());
        ImageButton rollershutterUpButton = (ImageButton) widgetView.findViewById(R.id.rollershutterbutton_up);
        ImageButton rollershutterStopButton = (ImageButton) widgetView
                .findViewById(R.id.rollershutterbutton_stop);
        ImageButton rollershutterDownButton = (ImageButton) widgetView
                .findViewById(R.id.rollershutterbutton_down);
        rollershutterUpButton.setTag(openHABWidget.getItem());
        rollershutterStopButton.setTag(openHABWidget.getItem());
        rollershutterDownButton.setTag(openHABWidget.getItem());
        rollershutterUpButton.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent motionEvent) {
                ImageButton rollershutterButton = (ImageButton) v;
                OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag();
                if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP)
                    sendItemCommand(rollershutterItem, "UP");
                return false;
            }
        });
        rollershutterStopButton.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent motionEvent) {
                ImageButton rollershutterButton = (ImageButton) v;
                OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag();
                if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP)
                    sendItemCommand(rollershutterItem, "STOP");
                return false;
            }
        });
        rollershutterDownButton.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent motionEvent) {
                ImageButton rollershutterButton = (ImageButton) v;
                OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag();
                if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP)
                    sendItemCommand(rollershutterItem, "DOWN");
                return false;
            }
        });
        break;
    case TYPE_TEXT:
        splitString = openHABWidget.getLabel().split("\\[|\\]");
        if (labelTextView != null)
            if (splitString.length > 0) {
                labelTextView.setText(splitString[0]);
            } else {
                labelTextView.setText(openHABWidget.getLabel());
            }
        if (valueTextView != null)
            if (splitString.length > 1) {
                // If value is not empty, show TextView
                valueTextView.setVisibility(View.VISIBLE);
                valueTextView.setText(splitString[1]);
            } else {
                // If value is empty, hide TextView to fix vertical alignment of label
                valueTextView.setVisibility(View.GONE);
                valueTextView.setText("");
            }
        break;
    case TYPE_SLIDER:
        splitString = openHABWidget.getLabel().split("\\[|\\]");
        if (labelTextView != null)
            labelTextView.setText(splitString[0]);
        SeekBar sliderSeekBar = (SeekBar) widgetView.findViewById(R.id.sliderseekbar);
        if (openHABWidget.hasItem()) {
            sliderSeekBar.setTag(openHABWidget.getItem());
            sliderSeekBar.setProgress(openHABWidget.getItem().getStateAsFloat().intValue());
            sliderSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                }

                public void onStartTrackingTouch(SeekBar seekBar) {
                    Log.d(TAG, "onStartTrackingTouch position = " + seekBar.getProgress());
                }

                public void onStopTrackingTouch(SeekBar seekBar) {
                    Log.d(TAG, "onStopTrackingTouch position = " + seekBar.getProgress());
                    OpenHABItem sliderItem = (OpenHABItem) seekBar.getTag();
                    //                     sliderItem.sendCommand(String.valueOf(seekBar.getProgress()));
                    if (sliderItem != null && seekBar != null)
                        sendItemCommand(sliderItem, String.valueOf(seekBar.getProgress()));
                }
            });
            if (volumeUpWidget == null) {
                volumeUpWidget = sliderSeekBar;
                volumeDownWidget = sliderSeekBar;
            }
        }
        break;
    case TYPE_IMAGE:
        MySmartImageView imageImage = (MySmartImageView) widgetView.findViewById(R.id.imageimage);
        imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl, openHABWidget.getUrl()), false,
                openHABUsername, openHABPassword);
        //          ViewGroup.LayoutParams imageLayoutParams = imageImage.getLayoutParams();
        //          float imageRatio = imageImage.getDrawable().getIntrinsicWidth()/imageImage.getDrawable().getIntrinsicHeight();
        //          imageLayoutParams.height = (int) (screenWidth/imageRatio);
        //          imageImage.setLayoutParams(imageLayoutParams);
        if (openHABWidget.getRefresh() > 0) {
            imageImage.setRefreshRate(openHABWidget.getRefresh());
            refreshImageList.add(imageImage);
        }
        break;
    case TYPE_CHART:
        MySmartImageView chartImage = (MySmartImageView) widgetView.findViewById(R.id.chartimage);
        //Always clear the drawable so no images from recycled views appear
        chartImage.setImageDrawable(null);
        OpenHABItem chartItem = openHABWidget.getItem();
        Random random = new Random();
        String chartUrl = "";
        if (chartItem != null) {
            if (chartItem.getType().equals("GroupItem")) {
                chartUrl = openHABBaseUrl + "chart?groups=" + chartItem.getName() + "&period="
                        + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt());
            } else {
                chartUrl = openHABBaseUrl + "chart?items=" + chartItem.getName() + "&period="
                        + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt());
            }
            if (openHABWidget.getService() != null && openHABWidget.getService().length() > 0) {
                chartUrl += "&service=" + openHABWidget.getService();
            }
        }
        Log.d(TAG, "Chart url = " + chartUrl);
        if (chartImage == null)
            Log.e(TAG, "chartImage == null !!!");
        ViewGroup.LayoutParams chartLayoutParams = chartImage.getLayoutParams();
        chartLayoutParams.height = (int) (screenWidth / 2);
        chartImage.setLayoutParams(chartLayoutParams);
        chartUrl += "&w=" + String.valueOf(screenWidth);
        chartUrl += "&h=" + String.valueOf(screenWidth / 2);
        chartImage.setImageUrl(chartUrl, false, openHABUsername, openHABPassword);
        // TODO: This is quite dirty fix to make charts look full screen width on all displays
        if (openHABWidget.getRefresh() > 0) {
            chartImage.setRefreshRate(openHABWidget.getRefresh());
            refreshImageList.add(chartImage);
        }
        Log.d(TAG, "chart size = " + chartLayoutParams.width + " " + chartLayoutParams.height);
        break;
    case TYPE_VIDEO:
        VideoView videoVideo = (VideoView) widgetView.findViewById(R.id.videovideo);
        Log.d(TAG, "Opening video at " + openHABWidget.getUrl());
        // TODO: This is quite dirty fix to make video look maximum available size on all screens
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        ViewGroup.LayoutParams videoLayoutParams = videoVideo.getLayoutParams();
        videoLayoutParams.height = (int) (wm.getDefaultDisplay().getWidth() / 1.77);
        videoVideo.setLayoutParams(videoLayoutParams);
        // We don't have any event handler to know if the VideoView is on the screen
        // so we manage an array of all videos to stop them when user leaves the page
        if (!videoWidgetList.contains(videoVideo))
            videoWidgetList.add(videoVideo);
        // Start video
        if (!videoVideo.isPlaying()) {
            videoVideo.setVideoURI(Uri.parse(openHABWidget.getUrl()));
            videoVideo.start();
        }
        Log.d(TAG, "Video height is " + videoVideo.getHeight());
        break;
    case TYPE_VIDEO_MJPEG:
        Log.d(TAG, "Video is mjpeg");
        ImageView mjpegImage = (ImageView) widgetView.findViewById(R.id.mjpegimage);
        MjpegStreamer mjpegStreamer = new MjpegStreamer(openHABWidget.getUrl(), this.openHABUsername,
                this.openHABPassword, this.getContext());
        mjpegStreamer.setTargetImageView(mjpegImage);
        mjpegStreamer.start();
        if (!mjpegWidgetList.contains(mjpegStreamer))
            mjpegWidgetList.add(mjpegStreamer);
        break;
    case TYPE_WEB:
        WebView webWeb = (WebView) widgetView.findViewById(R.id.webweb);
        if (openHABWidget.getHeight() > 0) {
            ViewGroup.LayoutParams webLayoutParams = webWeb.getLayoutParams();
            webLayoutParams.height = openHABWidget.getHeight() * 80;
            webWeb.setLayoutParams(webLayoutParams);
        }
        webWeb.setWebViewClient(
                new AnchorWebViewClient(openHABWidget.getUrl(), this.openHABUsername, this.openHABPassword));
        webWeb.getSettings().setJavaScriptEnabled(true);
        webWeb.loadUrl(openHABWidget.getUrl());
        break;
    case TYPE_SELECTION:
        int spinnerSelectedIndex = -1;
        if (labelTextView != null)
            labelTextView.setText(openHABWidget.getLabel());
        final Spinner selectionSpinner = (Spinner) widgetView.findViewById(R.id.selectionspinner);
        selectionSpinner.setOnItemSelectedListener(null);
        ArrayList<String> spinnerArray = new ArrayList<String>();
        Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings().iterator();
        while (mappingIterator.hasNext()) {
            OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next();
            spinnerArray.add(openHABWidgetMapping.getLabel());
            if (openHABWidgetMapping.getCommand() != null && openHABWidget.getItem() != null)
                if (openHABWidgetMapping.getCommand().equals(openHABWidget.getItem().getState())) {
                    spinnerSelectedIndex = spinnerArray.size() - 1;
                }
        }
        ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this.getContext(),
                android.R.layout.simple_spinner_item, spinnerArray);
        spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        selectionSpinner.setAdapter(spinnerAdapter);
        selectionSpinner.setTag(openHABWidget);
        if (spinnerSelectedIndex >= 0) {
            Log.d(TAG, "Setting spinner selected index to " + String.valueOf(spinnerSelectedIndex));
            selectionSpinner.setSelection(spinnerSelectedIndex);
        } else {
            Log.d(TAG, "Not setting spinner selected index");
        }
        selectionSpinner.post(new Runnable() {
            @Override
            public void run() {
                selectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
                    public void onItemSelected(AdapterView<?> parent, View view, int index, long id) {
                        Log.d(TAG, "Spinner item click on index " + index);
                        Spinner spinner = (Spinner) parent;
                        String selectedLabel = (String) spinner.getAdapter().getItem(index);
                        Log.d(TAG, "Spinner onItemSelected selected label = " + selectedLabel);
                        OpenHABWidget openHABWidget = (OpenHABWidget) parent.getTag();
                        if (openHABWidget != null) {
                            Log.d(TAG, "Label selected = " + openHABWidget.getMapping(index).getLabel());
                            Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings()
                                    .iterator();
                            while (mappingIterator.hasNext()) {
                                OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next();
                                if (openHABWidgetMapping.getLabel().equals(selectedLabel)) {
                                    Log.d(TAG, "Spinner onItemSelected found match with "
                                            + openHABWidgetMapping.getCommand());
                                    if (openHABWidget.getItem() != null
                                            && openHABWidget.getItem().getState() != null) {
                                        // Only send the command for selection of selected command will change the state
                                        if (!openHABWidget.getItem().getState()
                                                .equals(openHABWidgetMapping.getCommand())) {
                                            Log.d(TAG,
                                                    "Spinner onItemSelected selected label command != current item state");
                                            sendItemCommand(openHABWidget.getItem(),
                                                    openHABWidgetMapping.getCommand());
                                        }
                                    } else if (openHABWidget.getItem() != null
                                            && openHABWidget.getItem().getState() == null) {
                                        Log.d(TAG,
                                                "Spinner onItemSelected selected label command and state == null");
                                        sendItemCommand(openHABWidget.getItem(),
                                                openHABWidgetMapping.getCommand());
                                    }
                                }
                            }
                        }
                        //               if (!openHABWidget.getItem().getState().equals(openHABWidget.getMapping(index).getCommand()))
                        //                  sendItemCommand(openHABWidget.getItem(),
                        //                        openHABWidget.getMapping(index).getCommand());
                    }

                    public void onNothingSelected(AdapterView<?> arg0) {
                    }
                });
            }
        });
        break;
    case TYPE_SETPOINT:
        splitString = openHABWidget.getLabel().split("\\[|\\]");
        if (labelTextView != null)
            labelTextView.setText(splitString[0]);
        if (valueTextView != null)
            if (splitString.length > 1) {
                // If value is not empty, show TextView
                valueTextView.setVisibility(View.VISIBLE);
                valueTextView.setText(splitString[1]);
            }
        Button setPointMinusButton = (Button) widgetView.findViewById(R.id.setpointbutton_minus);
        Button setPointPlusButton = (Button) widgetView.findViewById(R.id.setpointbutton_plus);
        setPointMinusButton.setTag(openHABWidget);
        setPointPlusButton.setTag(openHABWidget);
        setPointMinusButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Log.d(TAG, "Minus");
                OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag();
                float currentValue = setPointWidget.getItem().getStateAsFloat();
                currentValue = currentValue - setPointWidget.getStep();
                if (currentValue < setPointWidget.getMinValue())
                    currentValue = setPointWidget.getMinValue();
                if (currentValue > setPointWidget.getMaxValue())
                    currentValue = setPointWidget.getMaxValue();
                sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue));

            }
        });
        setPointPlusButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Log.d(TAG, "Plus");
                OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag();
                float currentValue = setPointWidget.getItem().getStateAsFloat();
                currentValue = currentValue + setPointWidget.getStep();
                if (currentValue < setPointWidget.getMinValue())
                    currentValue = setPointWidget.getMinValue();
                if (currentValue > setPointWidget.getMaxValue())
                    currentValue = setPointWidget.getMaxValue();
                sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue));
            }
        });
        if (volumeUpWidget == null) {
            volumeUpWidget = setPointPlusButton;
            volumeDownWidget = setPointMinusButton;
        }
        break;
    default:
        if (labelTextView != null)
            labelTextView.setText(openHABWidget.getLabel());
        break;
    }
    LinearLayout dividerLayout = (LinearLayout) widgetView.findViewById(R.id.listdivider);
    if (dividerLayout != null) {
        if (position < this.getCount() - 1) {
            if (this.getItemViewType(position + 1) == TYPE_FRAME) {
                dividerLayout.setVisibility(View.GONE); // hide dividers before frame widgets
            } else {
                dividerLayout.setVisibility(View.VISIBLE); // show dividers for all others
            }
        } else { // last widget in the list, hide divider
            dividerLayout.setVisibility(View.GONE);
        }
    }
    return widgetView;
}

From source file:dk.bearware.gui.MainActivity.java

void createStatusTimer() {

    final TextView connection = (TextView) findViewById(R.id.connectionstat_textview);
    final TextView ping = (TextView) findViewById(R.id.pingstat_textview);
    final TextView total = (TextView) findViewById(R.id.totalstat_textview);
    final int defcolor = connection.getTextColors().getDefaultColor();

    if (stats_timer == null) {
        stats_timer = new CountDownTimer(10000, 1000) {

            ClientStatistics prev_stats;

            public void onTick(long millisUntilFinished) {

                if (ttclient == null || accessibilityAssistant.isUiUpdateDiscouraged())
                    return;
                filesAdapter.performPendingUpdate();

                int con = R.string.stat_offline;
                int con_color = Color.RED;
                int flags = ttclient.getFlags();
                if ((flags & ClientFlag.CLIENT_CONNECTED) == ClientFlag.CLIENT_CONNECTED) {
                    con = R.string.stat_online;
                    con_color = Color.GREEN;
                } else if ((flags & ClientFlag.CLIENT_CONNECTING) == ClientFlag.CLIENT_CONNECTING) {
                    con = R.string.stat_connecting;
                }/*from  w w w . ja  v a  2s  .  c  o m*/

                connection.setText(con);
                connection.setTextColor(con_color);

                ClientStatistics stats = new ClientStatistics();
                if (!ttclient.getClientStatistics(stats))
                    return;

                if (prev_stats == null)
                    prev_stats = stats;

                long totalrx = stats.nUdpBytesRecv - prev_stats.nUdpBytesRecv;
                long totaltx = stats.nUdpBytesSent - prev_stats.nUdpBytesSent;
                long voicerx = stats.nVoiceBytesRecv - prev_stats.nVoiceBytesRecv;
                long voicetx = stats.nVoiceBytesSent - prev_stats.nVoiceBytesSent;
                long deskrx = stats.nDesktopBytesRecv - prev_stats.nDesktopBytesRecv;
                long desktx = stats.nDesktopBytesSent - prev_stats.nDesktopBytesSent;
                long mfrx = (stats.nMediaFileAudioBytesRecv + stats.nMediaFileVideoBytesRecv)
                        - (prev_stats.nMediaFileAudioBytesRecv + prev_stats.nMediaFileVideoBytesRecv);
                long mftx = (stats.nMediaFileAudioBytesSent + stats.nMediaFileVideoBytesSent)
                        - (prev_stats.nMediaFileAudioBytesSent + prev_stats.nMediaFileVideoBytesSent);

                String str;
                if (stats.nUdpPingTimeMs >= 0) {
                    str = String.format("%1$d", stats.nUdpPingTimeMs);
                    ping.setText(str);

                    if (stats.nUdpPingTimeMs > 250) {
                        ping.setTextColor(Color.RED);
                    } else {
                        ping.setTextColor(defcolor);
                    }
                }

                str = String.format("%1$d/%2$d KB", totalrx / 1024, totaltx / 1024);
                total.setText(str);

                prev_stats = stats;
            }

            public void onFinish() {
                start();
            }
        }.start();
    }

}