AndroidPlot PieChart Touch Event - androidplot

I want to implement a PieChart with a SelectionWidget. Upon clicking on a segment within an AndroidPlot PieChart, I would like the selection widget label text to display info about the current selected segment. There is an example to do this for an XYPlot within the AndroidPlot demo but it does not translate over well to the PieChart. Any help would be appreciated. Thank you.

I just posted a solution to a similar question here. It was necessary to add a new method to the PieRenderer class but there's a link to a build of Androidplot containing the necessary changes. It's not a production build but for whatever it's worth, its at least as stable as the current production version of Androidplot. Once you have the new build, you'll be able to do something like this:
// detect segment clicks:
pie.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
PointF click = new PointF(motionEvent.getX(), motionEvent.getY());
if(pie.getPieWidget().containsPoint(click)) {
Segment segment = pie.getRenderer(PieRenderer.class).getContainingSegment(click);
if(segment != null) {
// handle the segment click...for now, just print
// the clicked segment's title to the console:
System.out.println("Clicked Segment: " + segment.getTitle());
}
}
return false;
}
});
Just replace System.out.println(...) with your code to update the SelectionWidget.

Related

How to Scroll pdfView automatically with button click or volume buttons

I'm using barteksc pdf viewer library to load pdf in my application.
pdfView = findViewById(R.id.pdfView);
pdfView.fromAsset(getResources().getString(R.string.pdfname))
.enableDoubletap(true)
.enableSwipe(true)
.defaultPage(pageNumber)
.onPageChange(mainreading.this)
.pageFitPolicy(FitPolicy.WIDTH)
.pageFling(true)
.linkHandler(null)
.enableAnnotationRendering(true)
.swipeHorizontal(true)
.scrollHandle(new DefaultScrollHandlenew(mainreading.this))
.enableAntialiasing(true)
.load();
}
I want pdf to start scroll automatically when user click the button of volume up and down buttons to start stop. I tried with below code while wrapping it in the handler with handler.performClick(); but it shows blank screen while scrolling up and down.
scrollbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
pdfView.scrollTo(0, pdfView.getScrollY() + 24);
}
});
Example :
https://play.google.com/store/apps/details?id=com.emptysheet.pdfreader_autoscroll&hl=en&gl=US
I want to make as like this. Can anyone help please.
Also tried with this. But it shows blank page after some scrolls.
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_DOWN) {
pdfView.scrollTo(0, pdfView.getScrollY() -24);
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
pdfView.scrollTo(0, pdfView.getScrollY() + 24);
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
You can simply use this PDF viewer from github.
It's based on the same 'barsteksc' pdf viewer with the feature to jump to any pages.
It's MagicalPdfViewer and you can use 'jumpTo(pageNo)' method to simply jump to the specific page. It also gives you the option to animate to the specific page with the same method, just pass 'true' as the 2nd parameter.
Moreover, if you pass the values like '-1' and 'bigger than pageNo', It will automatically scroll to the 0 & last page respectively.
Give it a try & let me know if you got what you wanted.

jTabbedPane set active tab text properties

I have a jTabbedPane with multiple tabs in it. I am trying to make the title text of the selected/active tab bold. Is there a simple way to do this?
JTabbedPane pane = new JTabbedPane();
pane.addChangeListener(new ChangeListener(){
#Override
public void stateChanged(ChangeEvent e) {
JTabbedPane source = (JTabbedPane) e.getSource();
// Set all tabs to PLAIN font
for(int i = 0; i < source.getTabCount(); i++) {
Component c = source.getTabComponentAt(i);
c.setFont(c.getFont().deriveFont(Font.PLAIN));
}
Component selectedComp = source.getTabComponentAt(source.getSelectedIndex());
// Set selected component to BOLD
selectedComp.setFont(selectedComp.getFont().deriveFont(Font.BOLD));
}
});
Try this, i wrote it quickly, maybe you need to do some adjustments for the initial tab, don't know for sure.
Also not so sure if you need JTabbedPane.getTabComponentAt(int idx) or JTabbedPane.getComponentAt(int idx) although i suppose first version is correct.
I know that this question was asked a long time ago, but I recently wanted to do this as well. I found the answer here. The solution was one of two things:
Use tabbedPane.setTitleAt(currSelextedIdx, "<html><b>My tab title</b></html>");
Create your own UI implementation for the tabbed pane
I personally used the first option and set all the other tabs back to the regular tab title on a change. I also made the initial tab bold after initializing all the tabs (this can be done upon initialization).
The simplest solution I've found until now. In a subclass of JTabbedPane, override two methods as below. When the tab is added, the raw title is persisted as a client property of the tab component. When the selected tab changes, the current tab title is restored to the raw title and the next tab title is set to bold with HTML.
public class MyTabbedPane extends JTabbedPane {
...
#Override
public void insertTab(String title, Icon icon, Component component, String tip, int index) {
((JComponent)component).putClientProperty("title", title);
super.insertTab(title, icon, component, tip, index);
}
#Override
public void setSelectedIndex(int index) {
int currentIndex = getSelectedIndex();
if (currentIndex >= 0) {
JComponent previous = (JComponent) getComponentAt(currentIndex);
String title = (String) previous.getClientProperty("title");
setTitleAt(currentIndex, title);
}
super.setSelectedIndex(index);
JComponent current = getSelectedComponent();
String title = (String) current.getClientProperty("title");
setTitleAt(index, "<html><b>" + title + "</b></html>");
}
}

issue with lwuit right-to-left label ticker

I was trying to set ticker on a Label with lwuit 1.5, faced this issue:
if I set label.setRTL(true) and then call
label.startTicker(UIManager.getInstance().getLookAndFeel().getTickerSpeed(), true);
ticker just shows first 21 characters of the label's text and ignores the rest.
I've tried:
label.setRTL(false);
label.startTicker(UIManager.getInstance().getLookAndFeel().getTickerSpeed(), true);
it shows up OK, the text goes from left to right, but when I set this in a FocusListener (cause ticker should start when the label receive focus and stop after it loosed focus) it just change direction (goes from right to left).
here's what i do:
Label test = new Label();
Container c1 = new Container(new FlowLayout());
test.setText("1234567890ABCDEFGHIJ1234567890");
test.setFocusable(true);
test.setRTL(false);
test.addFocusListener(new FocusListener (){
public void focusGained(Component cmpnt) {
((Label)cmpnt).setRTL(false);
((Label)cmpnt).startTicker(UIManager.getInstance().getLookAndFeel().getTickerSpeed(), false);
}
public void focusLost(Component cmpnt) {
((Label)cmpnt).stopTicker();
}
});
c1.addComponent(test);
Look at setLabelFor, it will ticker the label for test when test gains focus. You should probably set RTL globally in the look and feel class.
I found the problem. wrong direction happens because I've implemented focusListener before adding the label to container (c1). so I just did this:
c1.addComponent(test);
test.addFocusListener(new FocusListener (){
public void focusGained(Component cmpnt) {
((Label)cmpnt).setRTL(false);
((Label)cmpnt).startTicker(UIManager.getInstance().getLookAndFeel().getTickerSpeed(), false);
}
public void focusLost(Component cmpnt) {
((Label)cmpnt).stopTicker();
}
});
and it simply worked.
in fact I got the idea from Label class source code (lines 149 ~ 153):
// solves the case of a user starting a ticker before adding the component
// into the container
if(isTickerEnabled() && isTickerRunning() && !isCellRenderer()) {
getComponentForm().registerAnimatedInternal(this);
}
this part does not work, but I don't know why. just hope someone fix this bug.

GXT FillToolItem

The FillToolItem , fills the toolbar width, pushing any newly added items to the right.
public FillToolItem() {
getAriaSupport().setPresentation(true);
}
#Override
protected void onRender(Element target, int index) {
setElement(DOM.createDiv(), target, index);
}
I want to create a new class LeftFillToolItem that will extend the FillToolItem , but will pushing any newly added items to the left.
how can i do that?
Hi I can't seem to understand your question can you give an example. By default(when a FillToolItem is not inserted) new items are already added to the left.

GWT Graphics - resetting the text

I am working on a project for which i am using GWT-Graphics. I have drawing Area containing ellipse and text. When i double click on them a pop-up menu appears and gives an option to enter text. Now when i save this text i want it to appear on this drawing area in the place of the previous text.
I am trying to do this but with no luck. It keeps the old text and on top of that it includes the current text. Is there a way to have only the new text to appear.
Any input will be of great help.
Thank you.
For me this sounds like that you are adding a new Text element instead of using the existing one. I wrote a quick test and it seems to work like you want:
public class GwtTest2 implements EntryPoint {
private Text text;
public void onModuleLoad() {
DrawingArea da = new DrawingArea(400, 400);
RootPanel.get().add(da);
da.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
String newTextValue = Window.prompt("", "");
text.setText(newTextValue);
}
});
Ellipse ellipse = new Ellipse(200, 200, 100, 50);
da.add(ellipse);
text = new Text(150, 200, "Hello world!");
da.add(text);
}
}

Resources