Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8224483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:05:21+00:00 2026-06-07T15:05:21+00:00

I got the seek bar so can slide. When I slide, I will get

  • 0

I got the seek bar so can slide. When I slide, I will get the current value. The values is between 10-35. When I get the value, I need to apply on font size of the label field and change the font size instantly. I called the invalidate() after get the value but it does not change the font size.

public class Custom_FontField extends Field {
private final static int STATE_NORMAL = 0;
private final static int STATE_FOCUSED = 1;
private final static int STATE_PRESSED = 2;

private final static int NUM_STATES = 3;

private Bitmap[] _thumb = new Bitmap[NUM_STATES];
private Bitmap[] _progress = new Bitmap[NUM_STATES];
private Bitmap[] _base = new Bitmap[NUM_STATES];
private Bitmap[] _progressTile = new Bitmap[NUM_STATES];
private Bitmap[] _baseTile = new Bitmap[NUM_STATES];

private int _thumbWidth;
private int _thumbHeight;
private int _progressHeight;
private int _baseWidth;
private int _baseHeight;

private int _leftCapWidth;
private int _rightCapWidth;

private boolean _focused;
private boolean _pressed;

private int _numValues;
private int _currentValue;

private int _preferredHeight;

private int _baseY;
private int _progressY;
private int _thumbY;
private int _trackWidth;

private int _rop;

public Custom_FontField(Bitmap normalThumb, Bitmap normalProgress,
        Bitmap normalBase, Bitmap focusedThumb, Bitmap focusedProgress,
        Bitmap focusedBase, int numValues, int initialValue,
        int leftCapWidth, int rightCapWidth) {
    this(normalThumb, normalProgress, normalBase, focusedThumb,
            focusedProgress, focusedBase, null, null, null, numValues,
            initialValue, leftCapWidth, rightCapWidth, 0);
}

public Custom_FontField(Bitmap normalThumb, Bitmap normalProgress,
        Bitmap normalBase, Bitmap focusedThumb, Bitmap focusedProgress,
        Bitmap focusedBase, int numValues, int initialValue,
        int leftCapWidth, int rightCapWidth, long style) {
    this(normalThumb, normalProgress, normalBase, focusedThumb,
            focusedProgress, focusedBase, null, null, null, numValues,
            initialValue, leftCapWidth, rightCapWidth, style);
}

public Custom_FontField(Bitmap normalThumb, Bitmap normalProgress,
        Bitmap normalBase, Bitmap focusedThumb, Bitmap focusedProgress,
        Bitmap focusedBase, Bitmap pressedThumb, Bitmap pressedProgress,
        Bitmap pressedBase, int numValues, int initialValue,
        int leftCapWidth, int rightCapWidth) {
    this(normalThumb, normalProgress, normalBase, focusedThumb,
            focusedProgress, focusedBase, pressedThumb, pressedProgress,
            pressedBase, numValues, initialValue, leftCapWidth,
            rightCapWidth, 0);
}

public Custom_FontField(Bitmap normalThumb, Bitmap normalProgress,
        Bitmap normalBase, Bitmap focusedThumb, Bitmap focusedProgress,
        Bitmap focusedBase, Bitmap pressedThumb, Bitmap pressedProgress,
        Bitmap pressedBase, int numValues, int initialValue,
        int leftCapWidth, int rightCapWidth, long style) {
    super(style);

    if (numValues < 2 || initialValue >= numValues) {
        throw new IllegalArgumentException("invalid value parameters");
    }
    if (normalThumb == null || normalProgress == null || normalBase == null
            || focusedThumb == null || focusedProgress == null
            || focusedBase == null) {
        throw new IllegalArgumentException(
                "thumb, normal, focused  are required");
    }

    _thumbWidth = normalThumb.getWidth();
    _thumbHeight = normalThumb.getHeight();
    _progressHeight = normalProgress.getHeight();
    _baseWidth = normalBase.getWidth();
    _baseHeight = normalBase.getHeight();

    if (focusedThumb.getWidth() != _thumbWidth
            || focusedThumb.getHeight() != _thumbHeight
            || focusedProgress.getHeight() != _progressHeight
            || focusedBase.getHeight() != _baseHeight) {
        throw new IllegalArgumentException(
                "all base bitmaps and all progress bitmaps must be the same height");
    }
    if (pressedThumb != null && pressedProgress != null
            && pressedBase != null) {
        if (pressedThumb.getWidth() != _thumbWidth
                || pressedThumb.getHeight() != _thumbHeight
                || pressedProgress.getHeight() != _progressHeight
                || pressedBase.getHeight() != _baseHeight) {
            throw new IllegalArgumentException(
                    "all base bitmaps and all progress bitmaps must be the same height");
        }
    }

    _leftCapWidth = leftCapWidth;
    _rightCapWidth = rightCapWidth;

    _rop = Graphics.ROP_SRC_COPY;

    initBitmaps(normalThumb, normalProgress, normalBase, STATE_NORMAL);
    initBitmaps(focusedThumb, focusedProgress, focusedBase, STATE_FOCUSED);

    if (pressedThumb != null && pressedProgress != null
            && pressedBase != null) {
        initBitmaps(pressedThumb, pressedProgress, pressedBase,
                STATE_PRESSED);
    } else {
        _thumb[STATE_PRESSED] = _thumb[STATE_FOCUSED];
        _progress[STATE_PRESSED] = _progress[STATE_FOCUSED];
        _base[STATE_PRESSED] = _base[STATE_FOCUSED];
        _progressTile[STATE_PRESSED] = _progressTile[STATE_FOCUSED];
        _baseTile[STATE_PRESSED] = _baseTile[STATE_FOCUSED];
    }

    _preferredHeight = Math.max(_thumbHeight,
            Math.max(_progressHeight, _baseHeight));

    _numValues = numValues;
    setValue(initialValue);
}

public void initBitmaps(Bitmap thumb, Bitmap progress, Bitmap base,
        int state) {
    if (progress.getWidth() <= _leftCapWidth
            || base.getWidth() <= _rightCapWidth) {
        throw new IllegalArgumentException();
    }

    if (thumb.hasAlpha() || progress.hasAlpha() || base.hasAlpha()) {
        _rop = Graphics.ROP_SRC_ALPHA;
    }

    _thumb[state] = thumb;
    _progress[state] = progress;
    _base[state] = base;

    int[] argbCopyBuffer;

    int progressTileWidth = progress.getWidth() - _leftCapWidth;
    int progressTileHeight = progress.getHeight();

    Bitmap progressTile = new Bitmap(progressTileWidth, progressTileHeight);

    argbCopyBuffer = new int[progressTileWidth * progressTileHeight];
    progress.getARGB(argbCopyBuffer, 0, progressTileWidth, _leftCapWidth,
            0, progressTileWidth, progressTileHeight);
    progressTile.setARGB(argbCopyBuffer, 0, progressTileWidth, 0, 0,
            progressTileWidth, progressTileHeight);

    int baseTileWidth = base.getWidth() - _rightCapWidth;
    int baseTileHeight = base.getHeight();

    Bitmap baseTile = new Bitmap(baseTileWidth, baseTileHeight);

    argbCopyBuffer = new int[baseTileWidth * baseTileHeight];
    base.getARGB(argbCopyBuffer, 0, baseTileWidth, 0, 0, baseTileWidth,
            baseTileHeight);
    baseTile.setARGB(argbCopyBuffer, 0, baseTileWidth, 0, 0, baseTileWidth,
            baseTileHeight);

    _progressTile[state] = progressTile;
    _baseTile[state] = baseTile;
}

public void setValue(int newValue) {
    if (newValue < 0 || newValue >= _numValues) {
        throw new IllegalArgumentException();
    }
    _currentValue = newValue;
    fieldChangeNotify(FieldChangeListener.PROGRAMMATIC);
    invalidate();
}

public int getValue() {
    return _currentValue;
}

public int getNumValues() {
    return _numValues;
}

public int getPreferredWidth() {
    return Integer.MAX_VALUE;
}

public int getPreferredHeight() {
    return _preferredHeight;
}

protected void layout(int width, int height) {
    width = Math.min(width, getPreferredWidth());
    height = Math.min(height, getPreferredHeight());

    _progressY = (height - _progressHeight) / 2;
    _baseY = (height - _baseHeight) / 2;
    _thumbY = (height - _thumbHeight) / 2;

    _trackWidth = width - _leftCapWidth - _rightCapWidth;

    setExtent(width, height);
}

public void paint(Graphics g) {
    int contentWidth = getContentWidth();

    int thumbX = _leftCapWidth + (_trackWidth - _thumbWidth)
            * _currentValue / (_numValues - 1);
    int transitionX = thumbX + _thumbWidth / 2;

    int currentState = _pressed ? STATE_PRESSED : (_focused ? STATE_FOCUSED
            : STATE_NORMAL);

    Bitmap thumb = _thumb[currentState];
    Bitmap progress = _progress[currentState];
    Bitmap base = _base[currentState];
    Bitmap progressTile = _progressTile[currentState];
    Bitmap baseTile = _baseTile[currentState];

    g.drawBitmap(0, _progressY, _leftCapWidth, _progressHeight, progress,
            0, 0);
    g.tileRop(_rop, _leftCapWidth, _progressY, transitionX - _leftCapWidth,
            _progressHeight, progressTile, 0, 0);

    g.drawBitmap(contentWidth - _rightCapWidth, _baseY, _rightCapWidth,
            _baseHeight, base, _baseWidth - _rightCapWidth, 0);
    g.tileRop(_rop, transitionX, _baseY, contentWidth - transitionX
            - _rightCapWidth, _baseHeight, baseTile, 0, 0);

    g.drawBitmap(thumbX, _thumbY, _thumbWidth, _thumbHeight, thumb, 0, 0);
}

protected void drawFocus(Graphics g, boolean on) {

}

protected void onFocus(int direction) {
    _focused = true;
    invalidate();
    super.onFocus(direction);
}

protected void onUnfocus() {
    _focused = false;
    invalidate();
    super.onUnfocus();
}

protected boolean touchEvent(TouchEvent message) {
    int event = message.getEvent();
    switch (event) {

    case TouchEvent.CLICK:
    case TouchEvent.DOWN:
        if (touchEventOutOfBounds(message)) {
            return false;
        }

    case TouchEvent.MOVE:
        _pressed = true;
        setValueByTouchPosition(message.getX(1));
        fieldChangeNotify(0);
        return true;

    case TouchEvent.UNCLICK:
    case TouchEvent.UP:
        _pressed = false;
        invalidate();
        return true;

    default:
        return false;
    }
}

private boolean touchEventOutOfBounds(TouchEvent message) {
    int x = message.getX(1);
    int y = message.getY(1);
    return (x < 0 || y < 0 || x > getWidth() || y > getHeight());
}

private void setValueByTouchPosition(int x) {
    _currentValue = MathUtilities.clamp(0, (x - _leftCapWidth) * _numValues
            / _trackWidth, _numValues - 1);
    invalidate();
}

protected boolean navigationMovement(int dx, int dy, int status, int time) {
    if (_pressed) {
        if (dx > 0 || dy > 0) {
            incrementValue();
        } else {
            decrementValue();
        }
        fieldChangeNotify(0);
        return true;
    }
    return super.navigationMovement(dx, dy, status, time);
}

private void incrementValue() {
    if (_currentValue + 1 < _numValues) {
        _currentValue++;
        invalidate();
    }
}

private void decrementValue() {
    if (_currentValue > 0) {
        _currentValue--;
        invalidate();
    }
}

protected boolean invokeAction(int action) {
    if (action == ACTION_INVOKE) {
        togglePressed();
        return true;
    }
    return false;
}

protected boolean keyChar(char key, int status, int time) {
    if (key == Characters.SPACE || key == Characters.ENTER) {
        togglePressed();
        return true;
    }
    return false;
}

protected boolean trackwheelClick(int status, int time) {
    togglePressed();
    return true;
}

private void togglePressed() {
    _pressed = !_pressed;
    invalidate();
}

}

public class Main_NewsDetail extends MainScreen {
private Custom_FontField slider;
private boolean isSliderVisible = false;
private int dynamicfont = 10;

public Main_NewsDetail() {
    super(USE_ALL_WIDTH);
    add(new Custom_TopField(this, 2, 0));
    add(new Custom_NewsDetailBottom());
    add(new Custom_HeaderField(""));
    add(new Custom_NewsDetailField(  <-- the font size set inside this field
            "aaaaaaaaaaaaaa",
            "bbb",
            "ccc",
            "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
            "eeeeeeeeee", "fffff"));
    slider = new Custom_FontField(
            Bitmap.getBitmapResource("slider_thumb_normal.png"),
            Bitmap.getBitmapResource("slider_progress_normal.png"),
            Bitmap.getBitmapResource("slider_base_normal.png"),
            Bitmap.getBitmapResource("slider_thumb_focused.png"),
            Bitmap.getBitmapResource("slider_progress_focused.png"),
            Bitmap.getBitmapResource("slider_base_focused.png"),
            Bitmap.getBitmapResource("slider_thumb_pressed.png"),
            Bitmap.getBitmapResource("slider_progress_pressed.png"),
            Bitmap.getBitmapResource("slider_base_pressed.png"), 35, 10, 5,
            5, FOCUSABLE);
    dynamicfont = slider.getValue(); <-- get the value
    invalidate(); <-- refresh it but did not set the fontsize instantly.
}

public class Custom_NewsDetailField extends Manager {
    ...
    ...
    contentlabel = new Custom_LabelField(content,
                LabelField.USE_ALL_WIDTH | DrawStyle.LEFT | Field.FOCUSABLE);
        contentlabel.setFont(Font.getDefault().derive(Font.BOLD,
                dynamicfont));
        contentlabel.setFontColor(Color.BLACK);
        add(contentlabel);
}

I can invalidate() the field visible of slider to control appear in display but not the fontsize of contentlabel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:05:25+00:00Added an answer on June 7, 2026 at 3:05 pm
    protected boolean navigationMovement(int dx, int dy, int status,
                int time) {
            if (_pressed) {
                if (dx > 0 || dy > 0) {
                    incrementValue();
                } else {
                    decrementValue();
                }
                fieldChangeNotify(0);
                contentlabel.setFont(Font.getDefault().derive(Font.BOLD,
                        getValue()));
                return true;
            }
            return super.navigationMovement(dx, dy, status, time);
        }
    

    This will do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

got a problem, can't get my head around this jquery and would appreciate your
Got a seg fault from my memcpy that gdb can't give me anything else
I got two objects from the same class and I need to compare them
Got Phonegap working, but not seeing the staticmap.png image for your current location <div
I've got a strange problem with SQL Server 2000, and I just can't think
I've got a third-party component that does PDF file manipulation. Whenever I need to
I've got an archive file containing multiple audio files in .mp3 format. I can
I seek your help in storing awk returning values in an array for my
Got a problem with Apache and PHP-files of Wordpress. When I go to any
Got a programm with 2 threads. one thread is writing some stuff into the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.