Blackberry Keyboard with Action keys on BB 10 using Android runtime - blackberry-eclipse-plugin

I have an android app with certain keyboard layouts and some defined actions for the enter key on some textviews. For e.g., the textviews are defined with
android:imeOptions="actionGo"
android:inputType="text"
and i have an EditText with onEditorActionListener defined as
txtView.setOnEditorActionListener(this);
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
// do something
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
This works fine in the android version, but when the same is ported to BB 10 device, the enter key is not reflected with the specified action (in this case 'Go') and also, when the enter button is tapped, nothing happens even thought the action listener is defined.
Is there a way to resolve this or make it work? Or am i missing something here?
I am running on Z10 with 10.0.9.422.

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.

How to read Android switch widget

I added an andriod switch widget to my graphic.xml file in andriod, and it moves and changes color so the widget works, but I dont know how to read the value, it is on/off switch so I would expect off=0 and on=1 however when I look at the switch.java file I do not see and GetSwitchValue or SetSwitchValue type method in this library. how do I actually read the value?
You can set setOnCheckedChangeListener as following:
((Switch)findViewById(R.id.switchId)).setOnCheckedChangeListener(
new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});
Everytime switch is toggled, isChecked parameter contains the updated value.Based on the isChecked boolean 0/1 can be returned.

Keyboard is not shown up after came from android default contact page in my app

I have one button called "Invite Paricipants". When i tap on it, my app will goes to android default contact page. After selecting contact, i am calculating the emails in it. If i found no email then, showing edit text to enter email. There i am using following code
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
editText.post(new Runnable() {
#Override
public void run() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
});
}
});
editText.requestFocus();
but keyboard is not showing up. How can i resolve my problem?
Yes he is right, after coming back the focus to EditText has been lost and by using requestFocus for EditText allows you to have focus and obviously pops up the Keyboard
You have to request input focus for editText.
To do this go to your interface definition xml and add:
<requestFocus />
Inside the definition for editText.

SmartWatch 2 change menu icon on runtime

I would like to change the Icon of a menu item after its clicked. (I am talking about the action menu which deploys on the Action key press)
This is what I have so far:
#Override
public void onMenuItemSelected(final int menuItem) {
if (menuItem == MENU_ITEM_START) {
if(!Started){
Started=true;
**Intent intent = new Intent(Control.Intents.CONTROL_MENU_SHOW);
intent.putExtra(Control.Intents.EXTRA_MENU_ITEM_ID,MENU_ITEM_START);
intent.putExtra(Control.Intents.EXTRA_MENU_ITEM_ICON, ExtensionUtils.getUriString(mContext, R.drawable.menu_item_stop));
sendToHostApp(intent);**
mHandler.postDelayed(RunnableObject, 1000);
}
else{
Started=false;
mHandler.removeCallbacks(RunnableObject);
}
}
}
So, I added the bolded code (between ** and **), to start an intent to "change" the icon in the same way I create the menu the first time, however, that wont work.
Maybe wrong intent: CONTROL_MENU_SHOW?? That is the one I found in the Control Class when initializing the menu.
Any help is appreciated, thanks!!
Nope, there's no way to do it directly. The way you are doing it is the only way.

How to open the VirtualKeyboard associated to a TextField when the field is edited?

I initialized the VKBImplementationFactory in startApp() :
public void startApp() {
VKBImplementationFactory.init();
Display.init(this);
new MenuPrincipalForm(this).show();
}
I created also a VirtualKeyboard in a Form :
...
private VirtualKeyboard vkNombre = new VirtualKeyboard();
...
vkNombre.setInputModeOrder(new String[]{VirtualKeyboard.NUMBERS_SYMBOLS_MODE});
And I bound this VirtualKeyboard to a TextField :
cintxt=new TextField();
VirtualKeyboard.bindVirtualKeyboard(cintxt, vkNombre);
I registered dataChangeListener to this TextField :
public class ModifierFicheClient extends Form implements ActionListener, DataChangedListener
{
...
cintxt.addDataChangeListener(this);
...
}
In the dataChanged(int type, int index) method I want to open the vkNombre VirtualKeyBoard. I know that when clicking the TextField then the VirtualKeyboard is shown automatically. But there is a case when navigating to the TextField through the phone mobile scroll softbuttons then I can navigate to the TextField without clicking it and I can type any letters ! So how to call the VirtualKeyboard when typing a letter on the phone mobile ?
NB : I wrote System.out.println("zzzz"); in the dataChanged(int type, int index) method and the output writes two lines "zzzz" when I type one character ! So why the dataChanged method is called two times when I type only one letter ?
No need to use VKBImplementationFactory.init(); in startApp(). Because LWUIT automatically detect whether that mobile is touch screen or not. And numeric constraint not working on VKB when you use LWUIT 1.5 or before versions. It is bug on that versions. But it will be fixed on current repository version of LWUIT (Revision: 1605). So you can checkout from repository and use the latest LWUIT jar.
Update:
See the sample code for showing VKB while focusing on TextField,
TextField textField = new TextField();
final VirtualKeyboard keyboard = new VirtualKeyboard();
textField.addFocusListener(new FocusListener() {
public void focusGained(Component cmp)
keyboard.show();
}
public void focusLost(Component cmp) {
keyboard.dispose();
}
});
keyboard.setTextField(textField);

Resources