BlackBerry OS 6 Native Menu - blackberry

Hi I am trying to create a global class for my Native Menu, but can seem to get it to load in my Screen Class, I want this to show up where ever I would like to show up.
Not sure if I am doing it right
Here is my MenuItems Class
public final class MenuItems extends MainScreen {
public void getMenuItems(){
MenuItem myItem = new MenuItem(new StringProvider("My Cards"), 0x230000, 0);
myItem.setCommandContext(new Object(){
public String toString(){
return "My Cards";
}
});
myItem.setCommand(new Command(new CommandHandler(){
public void execute(ReadOnlyCommandMetadata metadata, Object context){
// Do Something
}
}));
addMenuItem(myItem);
}
}
The Screen Class I want to add it to is this, not sure if how I would call it here, I tried creating a new instance and just fetching the get method, but no luck, but if I dump the code from the above class in to this class, it will work fine, but I don't want that.
public final class MobiScreen extends MainScreen {
ToolBar toolbar = new ToolBar();
Banner banner = new Banner("Welcome");
MenuItems myMenu = new MenuItems();
public MobiScreen()
{
setTitle(toolbar.getToolBar());
setBanner(banner.getBanner());
myMenu.getMenuItems();
}
}

Why not have MobiScreen extend your MenuItems class?
public class MobiScreen extends MenuItems { ... }

Related

Avoid refreshing of content in SplitLayout

I have a splitlayout in my vaadin application in which in the first column I should show different pages added through the addToPrimary method, while in the second column I should have a page which contains an IFrame with a videoconference. Now the problem is that when I change route in the first column, even the second is updated and this refreshes the IFrame. The implementation of the showRouterLayoyutContent is the following:
#Override
public void showRouterLayoutContent(HasElement content) {
if (this.accessControl.isAccessGranted(UI.getCurrent(), ((ContentView) content).getName()) && ((ContentView) content).getName().equals("contattaView") ) {
setLayoutCall((com.vaadin.flow.component.Component) content);
}
else if (this.accessControl.isAccessGranted(UI.getCurrent(), ((ContentView) content).getName())) {
setLayoutContent((com.vaadin.flow.component.Component) content);
}
}
And the two methods setLayoutCall and setLayoutContent are the following:
private void setLayoutContent(com.vaadin.flow.component.Component content) {
split.addToPrimary(content);
}
private void setLayoutCall(com.vaadin.flow.component.Component content) {
split.addToSecondary(content);
split.setThemeName("visible-split");
}
How can I avoid to refresh the entire content when I update the first column of the split layout through navigation?
UPDATE: I'm showing also a very simple code on which I'm testing. The following class is the main layout:
private SplitLayout split = new SplitLayout();
private HorizontalLayout hl = new HorizontalLayout();
private Div firstDiv = new Div();
private Div secondDiv = new Div();
public MainView() {
Button button = new Button("Click me",
event -> Notification.show("Clicked!"));
final VerticalLayout menuBar = new VerticalLayout();
menuBar.add(new RouterLink("first view", FirstView.class));
menuBar.add(new RouterLink("second view", SecondView.class));
menuBar.setAlignItems(Alignment.CENTER);
add(menuBar);
//split.addToPrimary(firstDiv);
//split.addToSecondary(secondDiv);
//firstDiv.setId("first");
//secondDiv.setId("second");
//hl.add(firstDiv,secondDiv);
add(split);
//add(hl);
}
#Override
public void showRouterLayoutContent(HasElement element) {
if(element!=null && element.getClass().getName().contains("FirstView")) {
split.addToPrimary((Component) element);
//firstDiv.removeAll();
//firstDiv.add((Component) element);
//firstDiv.removeAll();
//firstDiv.getElement().appendChild(new Element[]{element.getElement()});
}
else if(element!=null && element.getClass().getName().contains("SecondView") ) {
secondDiv.removeAll();
secondDiv.add((Component) element);
split.addToSecondary((Component) element);
//split.addToSecondary(element.getElement().getComponent().get());
}
}
While these are the two views added to the split:
#Route(value="v1",layout=MainView.class)
public class FirstView extends VerticalLayout implements RouterLayout {
public FirstView() {
add(new Label("First View"));
}
}
#Route(value = "v2",layout=MainView.class)
public class SecondView extends VerticalLayout implements RouterLayout {
public SecondView() {
IFrame frame = new IFrame();
frame.setSrc("https://www.youtube.com/watch?v=LoigVtPCYPk&list=RDLoigVtPCYPk&start_radio=1");
add(frame);
}
}
Your comment does indeed seem to be the issue.
I recommend creating a Div wrapper for the primary content, and instead changing the content of that.
private final Div wrapper;
public MyLayout() {
wrapper = new Div();
wrapper.setSizeFull();
split.addToPrimary(wrapper);
}
private void setLayoutContent(com.vaadin.flow.component.Component content) {
wrapper.removeAll();
wrapper.add(content);
}
You might also want to do the same for the secondary. In addition, to prevent any components from being automatically removed when navigating, you can override removeRouterLayoutContent as well (available in Vaadin 14)
#Override
public void removeRouterLayoutContent(HasElement oldContent) {
// Do nothing, we remove manually in showRouterLayoutContent
}
Edit
If you can't override removeRouterLayoutContent, you can try creating your own instance of the HasElement to add. This is a bit of a hack, but might be the simplest solution.
public void showRouterLayoutContent(HasElement content) {
if (content.getClass().getSimpleName().contains("TestView")) {
// Creating a new instance should stop it from being auto removed
content = new TestView();
firstDiv.add((Component) content);
}
...
}

How to explicitly access the Connector from Widget Side into Vaadin 7?

I create a Widget with his Server Side Class and the Client Side (Connector Class, ServerRPC Class, State Class and Widget Class).
Connector :
#Connect(Custom.class)
public class CustomConnector extends ButtonConnector {
...
public void myFunc() {
// DO Something
}
}
Widget :
public class CustomWidget extends VButton {
...
private CustomConnector conn = new CustomConnector();
public CustomWidget () {
conn.myFunc();
}
...
}
Now from the Widget Class i want to explicitly call/access the Connector Object, which are not a Singleton, so that i can access a function too. How can i solve it?
In my opinion you should not access connector directly from GWT widget. It is against Vaadin 7 architecture where GWT widgets are objects independent from vaadin at all.
However if we are talking about dirty migration from Vaadin 6 to 7 solution could be:
ComponentConnector connector = ConnectorMap.get(client).getConnector(CustomWidget.this); // client is taken from updateFromUIDL method (Vaadin6)
Better solution will be to add "state" listener to the widget
public interface CustomWidgetStateListener {
public void stateChanged();
}
public class CustomWidget extends VButton {
...
CustomWidgetStateListener listener;
public void addStateListener(CustomWidgetStateListener listener) {
this.listener = listener;
}
public void notifyStateChanged() { // You can call notifyStateChanged() whenever you want to notify connector
listener.stateChanged();
}
...
}
public class CustomConnector extends ButtonConnector {
public CustomConnector() {
getWidget().addStateListener(new CustomWidgetStateListener() {
public void stateChanged() {
myFunc();
}
});
}
...
public void myFunc() {
// DO Something
}
}

Blackberry MenuItem Deprecated

I am trying to use the MenuItem class of BlackBerry JDE 6.0 and I am encountering an error "The constructor MenuItem String(String, int, int) is deprecated". I am implementing it using a subclass under the MainScreen class. below is the sample deprecated code:
public class UiFunMainScreen extends MainScreen{
class LoginMenuItem extends MenuItem {
public LoginMenuItem() {
super("Login", 20, 10);
}
public void run() {
login();
}
}
class ClearMenuItem extends MenuItem {
public ClearMenuItem() {
super("Clear", 10, 20);
}
public void run() {
clearTextFields();
}
}
}
Use following version of code to create a MenuItem:
class MyUiScreen extends MainScreen
{
public MyUiScreen()
{
MenuItem myItem = new MenuItem(
new StringProvider("My Menu Item"),
0x230000,
0
);
// rest of codes...
from the RIM BlackBerry API 6.0 Documentation
Creating menu items by subclassing and implementing Runnable
If subclassing the extending class must implement the Runnable interface, which in turn supports abstract dispatching of menu actions on activation.
...
// setup the menu items
MenuItem item = new MyMenuItem();
menu.addItem(item);
...
class MyMenuItem extends MenuItem {
MyMenuItem() {
super(MyResourceBundle.getBundle(), MyResource.MY_MENU_ITEM, 0x230000, 0);
}
public void run() {
// do something
}
}
Explore the API.

How to configure your blackberry app works ok (works on simulator but not on smartphone)?

I wrote an app which has 2 screens. The first screen is triggered by the main class. The second screen is opened by clicking a button in the first screen.
public class MyApp extends UiApplication{
public static void main(String[] args){
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp(){
// Push a screen onto the UI stack for rendering.
pushScreen(new MyScreen());
}
}
public class MyScreen extends MainScreen implements FieldChangeListener
{
BasicEditField mEdit = null;
ButtonField mButton = null;
public MyScreen()
{
super();
mEdit = new BasicEditField("input: ", "some text");
add(mEdit);
mButton = new ButtonField("Go second screen");
mButton.setChangeListener(this);
add(mButton);
}
public void fieldChanged(Field field, int context)
{
if(mButton == field)
{
MyScreen2 scr = new MyScreen2();
scr.setTextValue(mEdit.getText());
UiApplication.getUiApplication().pushScreen(scr);
UiApplication.getUiApplication().popScreen(this);
}
}
}
public final class MyScreen2 extends MainScreen
{
String mTextValue = null;
LabelField mLabel = null;
public void setTextValue(String textValue)
{
mTextValue = textValue;
mLabel.setText(mTextValue);
}
public MyScreen2()
{
super();
mLabel = new LabelField();
add(mLabel);
}
}
It works on the 9700 simulator, but doesn't work on the smartphone. I wonder what is wrong? I wonder if the smartphone blocks loading app from my computer?
I tried signing .cod but nothing changes.
Any idea?
you need signing key to run your application on real device ... It cost near about 20 dollars
go here
you can find all the details from here
I think it might help you
cheers

How disable widget?

I use GWT Editors framework for data binding.
I have next code:
AAAView.java
public interface AAAView extends Editor<AAA> {
public interface Presenter {
}
public interface Driver extends SimpleBeanEditorDriver<AAA, AAAViewImpl> {
}
void setPresenter(Presenter presenter);
Driver initializeDriver();
Widget asWidget();
}
AAAViewImpl.java
public class AAAViewImpl extends Composite implements AAAView {
interface AAAViewImplUiBinder extends UiBinder<Widget, AAAViewImpl> {
}
private static AAAViewImplUiBinder ourUiBinder = GWT.create(AAAViewImplUiBinder.class);
private Presenter presenter;
#UiField
ValueBoxEditorDecorator<String> firstName;
public AAAViewImpl() {
Widget rootElement = ourUiBinder.createAndBindUi(this);
initWidget(rootElement);
}
#Override
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
}
#Override
public Driver initializeDriver() {
Driver driver = GWT.create(Driver.class);
driver.initialize(this);
return driver;
}
AAAViewImpl.ui.xml
<e:ValueBoxEditorDecorator ui:field="firstName">
<e:valuebox>
<g:TextBox maxLength="16" width="100%"/>
</e:valuebox>
</e:ValueBoxEditorDecorator>
How can I disable/enable firstName textbox in runtime?
Or how get access to the inner textbox of ValueBoxEditorDecorator object?
Anyone knows how to solve this problem? Thanks in advance.
Instead of setting the ui:field attribute on the ValueBoxEditorDecorator, set it on the inner TextBox. Then you can disable the TextBox by using:
firstName.setEnabled(false);

Resources