Force blackberry game to always use landscape mode - blackberry

I am porting a game from j2me to blackberry. In j2me there is a way to change orientation. but I don't know how to do it in blackberry. If I am using
net.rim.device.api.ui.Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);
Its giving error. Please guide me.
Thanks in advance

I think you shouldn't call the setAcceptableDirections method before you enter the event dispatcher. Here's what i did in my Screen and it works:
protected void onUiEngineAttached(boolean attached) {
super.onUiEngineAttached(attached);
Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);
}

Related

React native orientation is not working || locking on IOS

I created an app with React-native. All pages I made are designed for portrait mode except 1 page. The page accessibility comes from a button onPress then navigates to the page, so I can't lock orientation on Xcode
I installed this package and I can run it on android perfectly
import Orientation from 'react-native-orientation';
When I tried it on IOS simulator on every page it can turns orientation to landscape.
I put this line in every pages componentdidmount but nothing changes.
componentDidMount() {
Orientation.lockToPortrait()
...
}
What should I do?
Hey again #masterAvatarr,
I believe that this is what you're looking for, if you need something else please explain it to me :) We can make it happen.
I made a simple example for you.
https://github.com/WrathChaos/react-native-portrait-locker-example
I use React Native Orientation Locker Library
The important parts are:
Make sure that you linked the library manually (check AppDelegate.m)
You need to make a logic for unlocking and lock the portrait mode depends on your use-case
Please take a look at HomeScreen and DetailScreen
import Orientation from "react-native-orientation-locker";
React.useEffect(() => {
const unsubscribe = navigation.addListener("focus", () => {
// The screen is focused
// Call any action
Orientation.unlockAllOrientations();
Orientation.lockToPortrait();
});
// Return the function to unsubscribe from the event so it gets removed on unmount
return unsubscribe;
}, [navigation]);
Note: There is a little GIF Demo on the Github Repo

BlackBerry wallpaper setting via code

I need help regarding changing the wallpaper programmatically in BlackBerry. Is there any code available for this?
There is a class HomeScreen
Use it and its method setBackgroundImage(String path2ImageFile).

PhoneScreen problems with incoming call

I want to add a field to the Phone Screen when a screen is received. I successfully made this using the following code:
public void callIncoming(int callId) {
PhoneScreen ps = new PhoneScreen(Call, UiApplication.getApplication());
PhoneScreenHorizontalManager manager = new PhoneScreenHorizontalManager();
LabelField label = new LabelField("Call Received");
manager.add(label);
ps.add(manager);
ps.setScreenBackground(Color.RED);
ps.sendDataToScreen();
}
I tried this code on the following devices:
BB Mini Curve, Bold 4, Bold 2 and Curve and this works like a charm with all the functionality I want. A background colored red is appearing in the area where I can draw fields
I tried it on these phones and the label field did not appear: Torch, Bold3
On these phones, When I add data to the screen, I guess that these fields are appearing below the ringer off notification. With these devices, no Background is appearing... So this is a main issue.
How to solve this and make the fields appear on these phones too?
Thanks in advance
I don't have the answer, but have started a thread here:
http://supportforums.blackberry.com/t5/Java-Development/PhoneScreenDemo-not-displaying-information-on-os6/m-p/1450769#M184811
I've opened a RIM ticket and will share info as I get it.
As far as I can see PhoneScreen has big issues and is not consistently supported across devices.
Using isSupported() will only determine if the device screen type supports the API, (SVG is required according to RIM Jira ticket), not if it will actually work.

Is there focus and lost-focus event on black berry sdk?

I am very new developer for black berry environment. Is there a focus and lost-focus event for the controls which are currently selected or deselected?
Please give me some like or example.
Thank you.
If you are writing your own custom field, or want to catch the events of your Screen class(es), then you would override the virtual Field.onFocus() and Field.onUnfocus() methods.
If you want to catch focus events of other fields, then you have to implement the FocusChangeListener interface and then call the Field.setFocusChangeListener() method of those fields.
Yes, these are Field.onFocus(int direction) and Field.onUnfocus(). Check the API for details.

My Webview Reloads When I Change From Portrait To Landscape

I have a simple WebView that runs a web application on an Android. The problem is when I rotate the phone to change it to landscape the webview reloads and goes back to the beginning.
How can I prevent this action?
Ron
Beginning with Android 3.2 (API level 13), the "screen size" also
changes when the device switches between portrait and landscape
orientation. Thus, if you want to prevent runtime restarts due to
orientation change when developing for API level 13 or higher (as
declared by the minSdkVersion and targetSdkVersion attributes), you
must include the "screenSize" value in addition to the "orientation"
value. That is, you must decalare
<activity android:configChanges="orientation|screenSize">
Excerpt from Handle configuration changes (webarchive to original page)
This can be resolved by overriding onSaveInstanceState(Bundle outState) in your activity and calling saveState from the Webview:
This blog post may be of help to you.
Add the following to your AndroidManifest:
android:configChanges="orientation|keyboard|keyboardHidden"
So it should look something like this:
<activity android:name=".MyActivity"
android:label="#string/app_name"
android:configChanges="orientation|keyboard|keyboardHidden">
Obviously, if your WebView needs keyboard support then don't include the keyboard options.
Add this before the oncreate
#Override
protected void onSaveInstanceState(Bundle outState) {
webview.saveState(outState);
}
Write the oncreate this way. put final
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layoutname);
if (savedInstanceState != null)
{
((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
}
else
{
webview.loadUrl("http://www.playbuzz.org/");
}
}
In Androidmanifest insert under the activity
android:configChanges="keyboardHidden|orientation"
#Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
}
Add above method in your activity.. and
android:configChanges="keyboard|keyboardHidden|orientation"
in your manifest file
The problem with the above solution is that it renders the screen white for some time before the webview redraws the contents.
Try using
android:configChanges="orientation|keyboardHidden" inside your AndroidManifest.xml file for the activity that displays the webview. That should help.
Add in Activity
android:configChanges="keyboardHidden|orientation"

Resources