I have a var in Swift like this :
#Published var textFieldSize = UIDevice.current.userInterfaceIdiom == .pad ? 20.0 : 12.0
How can i get the same device type (phone or tablet) but in Jetpack Compose Android ??
You can do this:
val configuration = LocalConfiguration.current
val expanded = configuration.screenWidthDp > 840
This corresponds to 97.22% of tablets in landscape. For sizes corresponding to phones or tablets there is more info here.
This works well but if you want to check if the display is a tablet in the portal mode you must enter a smaller number like 600, not 840.
Related
We are using ExoPlayer to play m3u8 files (stream) on Android TV. The streaming is working fine, but the video plays in portrait mode (even if the video is shot in landscape).
Looks like some issue with orientation of the android TV instead of aspect ratio.
private fun initializePlayer() {
if(mPlayer == null) {
playerView = activity!!.findViewById<SimpleExoPlayerView>(R.id.texture_view)
// playerView!!.setControllerVisibilityListener(this)
playerView!!.requestFocus()
val bandwidthMeter = DefaultBandwidthMeter()
val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeter)
mTrackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
mPlayer = ExoPlayerFactory.newSimpleInstance(activity, mTrackSelector)
playerView!!.player= mPlayer
mPlayerAdapter = LeanbackPlayerAdapter(activity, mPlayer, UPDATE_DELAY)
mPlayerGlue = VideoPlayerGlue(activity!!, mPlayerAdapter!!)
mPlayerGlue!!.host = VideoSupportFragmentGlueHost(this)
mPlayerGlue!!.playWhenPrepared()
play(s1)
}
}
Commenting these lines :
mPlayerAdapter = LeanbackPlayerAdapter(activity, mPlayer, UPDATE_DELAY)
mPlayerGlue = VideoPlayerGlue(activity!!, mPlayerAdapter!!)
mPlayerGlue!!.host = VideoSupportFragmentGlueHost(this)
mPlayerGlue!!.playWhenPrepared()
Plays the video in landscape but the player controls are hidden and it only plays the lowest quality of the video. Please help us with this.
Metadata of the MP4 video contains a property called Rotation=90° but it's ignored by the ExoPlayer. To fix it you need to inject this Java function into your code:
void onVideoSizeChanged(int width,
int height,
int unappliedRotationDegrees, // 90° or 270°
float pixelWidthHeightRatio);
This allows an application using TextureView to easily apply the rotation by making the appropriate call to TextureView.setTransform. Note that on Lollypop+ unappliedRotationDegrees will always be equal to 0.
You can find this function on a line #74 at MediaCodecVideoTrackRenderer page of GitHub.
If the above-mentioned method doesn't work for you, you may find another remedy in Rotation Issue #91 post on a GitHub.
As far i know, exoplayer will generate its size based on texture view size. So try to programmatically resize your texture view by
playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
and also try to resize your player programmatically
mPlayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
Hope this will help.
I'm a newbie to React Native so if I'm asking a very dumb question. Please forgive me for wasting your time.
I need to apply multiple devices layout in my React Native app. Let's say my application screens have completely different appearances but the same business processes on mobile and tablet devices.
How do I achieve that in React Native? Where do I start digging?
EDIT 2020:
Ok, I was a newbie...! Sorry!
Like #Hariks says, you could try to use something like this module
and put something like:
import Device from 'react-native-device-detection';
// Mobile Styles
let imageSize = 60;
// Tablet Styles
if(Device.isTablet) {
imageSize = 120;
}
Old answer: (if you want to detect OS)
I'm newbie too, and, from what I've understood, and extracted from here, there are two methods:
By naming files (recommended) Platform specific files can be named as “[filename].android.js” and “[filename].ios.js” for Android
and iOS respectively. If we import or require [filename], it picks up
the file depending on the host platform.
By adding conditionals in the source code For example, if you want the background of the navbar in different colors for iOS and
Android we can write the following code:
Code: backgroundColor: (Platform.OS === ‘ios’ ) ? ‘gray’ : ‘blue’
Of course, you should take a look at the official documentation.
If you are styling based on the OS, you could use Platform as mentioned by #anfuca. If you need to style based on devices ie tabs and phone, there is a handy module react-native-device-detection
You could do something like this in your style file
import Device from 'react-native-device-detection';
// Mobile Styles
let imageSize = 60;
// Tablet Styles
if(Device.isTablet) {
imageSize = 120;
}
Also you could create a global style file where you could define fontsizes and all based on the device/pixel ratios.
commonstyle.js
import Device from 'react-native-device-detection';
let h1 = 20;
let h2 = 18;
let h3 = 16;
if(Device.isTablet) {
h1 = 25;
h2 = 22;
h3 = 20;
}
module.exports = {
h1,
h2,
h3
};
You can use device detection for detecting mobile or tablet and use separate styling for mobile and tablet accordingly
https://www.npmjs.com/package/react-native-device-detection
how to open native calendar from titanium app for android and iOS? As in, on the click of a button, i want to open the native calendar on the ipad.
In android you can open it using a native intent, as explained here
There's a difference between versions lower and greater than Gingerbread. There's also a difference in HTC devices because of the HTC Sense Software, as explained at the end of this question.
Here is my tested code for Titanium:
if (Titanium.Platform.osname=="android"){
//Params needed to create the android intent.
var packageStr = "com.google.android.calendar";
var classStr = "com.android.calendar.LaunchActivity";
var actionStr = Ti.Android.ACTION_VIEW;
var model = Ti.Platform.model;
if ((model.indexOf("HTC") != -1) || (model.indexOf("htc") != -1)){
//If it's a HTC device
packageStr = "com.htc.calendar";
classStr = "com.htc.calendar.MonthActivity";
actionStr = Ti.Android.ACTION_MAIN;
}
else {
//For android versions before Gingerbread (2.3)
var version = parseFloat(Ti.Platform.version);
if (version < 2.4) packageStr = "com.android.calendar";
}
//Launch native calendar
var intent = Ti.Android.createIntent({
action: actionStr,
packageName: packageStr,
className: classStr
});
Ti.Android.currentActivity.startActivity(intent);
}
You can also open the "create event" screen of the native calendar by adapting this for Titanium in the same way as the code above
Just use:
Titanium.Platform.openURL('CALSHOW://');
I am trying to send key codes to a samsung smart tv using UPnP. I found the list of available key codes here. But How can i represent the same in integer, because samsung wants to receive this as integer values in the UPnP services.
Thanks
You can use the emulator to get a list of the key codes:
tvKey = new Common.API.TVKeyValue()
for(key in tvKey) {
alert(key+": "+tvKey[key]);
}
Not a great solution, but might work for your purposes.
Here you have manual way. So pressing any button on remote give you info what int value it has:
$('body').keydown(function(event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
alert("You pressed: " + keyCode);
}
In my application i need to scan the bar code. for that i am using Linea pro bar code scanning device attached with my iPhone. i need to know the presence of device through code. is it possible? I am new to objective C . Help me to fix this issue.
Thank you.
Yes, it is possible.
All you have to do is this:
int lineaStatus = [[Linea sharedDevice] connstate];
Them just compare them to the different connection states like this.
if(lineaStatus == CONN_DISCONNECTED) {
//Device is connected
} else if(status == CONN_CONNECTED) {
//Device is disconnected.
}