Android - scrollTo() on ScrollView doesn't work properly - appcelerator

I'm using Titanium SDK 5.1.2.GA. I have a bar like TabGroup on Android and iOS. I move the scroll when a tab is not completely visible in the view and you click that tab.
On iOS works perfectly but on Android doesn't work fine.
This is my code to move the scroll view:
if((view.rect.x + view.rect.width) > (toolbarX + $.toolbar.rect.width)){
$.toolbar.scrollTo(((view.rect.x + view.rect.width) - $.toolbar.rect.width) + 10, 0);
}else if(view.rect.x < toolbarX){
$.toolbar.scrollTo(view.rect.x - 10, 0);
}
$.toolbar -> ScrollView
view -> tab
This photo explain my problem:
I've seen this JIRA ticket on Internet
https://jira.appcelerator.org/browse/TIMOB-17954
This will be the problem??
EDIT
This problem is caused by the new unit system on Appcelerator.
I have this line on my tiapp.xml
<property name="ti.ui.defaultunit" type="string">dp</property>
but other functions on Titanium return their values on px, so that's a problem.
My question now is:
What units return the event listeners like 'scroll'?? (px or dp)
Because my toolbarX = e.x from scroll event
What units need scrollTo(x,y)????

THE SOLUTION:
if(Alloy.Globals.isAndroid){
var measure = require('alloy/measurement');
//Vemos si tenemos que mover la toolbar
if((view.rect.x + view.rect.width) > (toolbarX + $.toolbar.rect.width)){
$.toolbar.scrollTo(((measure.dpToPX(view.rect.x) + measure.dpToPX(view.rect.width)) - measure.dpToPX($.toolbar.rect.width)) + 10, 0);
}else if(view.rect.x < toolbarX){
$.toolbar.scrollTo(measure.dpToPX(view.rect.x) - 10, 0);
}
}else{
//Vemos si tenemos que mover la toolbar
if((view.rect.x + view.rect.width) > (toolbarX + $.toolbar.rect.width)){
$.toolbar.scrollTo(((view.rect.x + view.rect.width) - $.toolbar.rect.width) + 10, 0);
}else if(view.rect.x < toolbarX){
$.toolbar.scrollTo(view.rect.x - 10, 0);
}
}
}
$.toolbar.addEventListener('scroll', function(e){
Ti.API.info("-- toolbarX: " + e.x + " / " + Alloy.Globals.measure.pxToDP(e.x));
if(Alloy.Globals.isAndroid){
toolbarX = Alloy.Globals.measure.pxToDP(e.x);
}else{
toolbarX = e.x;
}
});
This problem is new because that:
<property name="ti.ui.defaultunit" type="string">dp</property>
Now, you have to GUESS in what units (px or dp) you have to pass the values on Android, because some functions return px and need px and the others dp.

this works for me
if (OS_ANDROID) {
$.tabbar.scrollTo(Util.DPUnitsToPixels(x), 0);
} else {
$.tabbar.scrollTo(x, 0);
}
on android convert dp to pixel

Related

Xamarin Forms Adaptive Banner Ad Won't Load in Landscape

I recently upgraded from a Galaxy S6 to a Galaxy S21 Ultra and now the AdMob adaptive banner advert will not load in landscape. On the S6 it is fine, but on the S21 I get the error:
[Ads] Ad failed to load : 1
The code I use to create the advert is here:
private void NewAdaptiveBannerAd()
{
try
{
adAdaptiveBannerView = new AdAdaptiveBannerView();
adAdaptiveBannerView.Padding = new Thickness(0);
adAdaptiveBannerView.BackgroundColor = (Color)Application.Current.Resources["baseBackground_Light"];
AdGrid.Children.Add(adAdaptiveBannerView, 0, 1);
adAdaptiveBannerView.HeightRequest = getCurrentOrientationAnchoredAdaptiveBannerAdSize(Android.App.Application.Context, (int)(DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density));
static int getCurrentOrientationAnchoredAdaptiveBannerAdSize(Context context, int adWidth)
{
int var3 = 0;
if (context == null)
{
return 0;
}
else
{
int var7 = 2;
switch (DeviceDisplay.MainDisplayInfo.Orientation)
{
case DisplayOrientation.Unknown: var7 = 0; break;
case DisplayOrientation.Portrait: var7 = 1; break;
case DisplayOrientation.Landscape: var7 = 2; break;
default: return 0;
}
if (var3 == 0)
{
var3 = var7;
}
int var8 = var3 == var7 ? (int)Math.Round((float)DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density) : (int)Math.Round((float)DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density);
int var9 = (int)Math.Min(90, Math.Round((float)var8 * 0.15F));
int var10;
if (adWidth > 655)
{
var10 = (int)Math.Round((float)adWidth / 728.0F * 90.0F);
}
else if (adWidth > 632)
{
var10 = 81;
}
else if (adWidth > 526)
{
var10 = (int)Math.Round((float)adWidth / 468.0F * 60.0F);
}
else if (adWidth > 432)
{
var10 = 68;
}
else
{
var10 = (int)Math.Round((float)adWidth / 320.0F * 50.0F);
}
var10 = Math.Max(Math.Min(var10, var9), 50);
return var10;
}
}
}
catch (Exception)
{
Console.WriteLine("Creation of banner ad in SavedCharts failed.");
}
}
adAdaptiveBannerView is declared at the top of the pages class. The getCurrentOrientationAnchoredAdaptiveBannerAdSize function is from another post on here that I can't find now.
I can't find anything that would explain this, or why it would behave differently between these two 'phones (is it the difference in Android versions, the different aspect ratio or what?). Testing on the emulator is difficult because it doesn't report orientation correctly.
Does anyone have any idea what's going on?
My app will, by it's nature, mostly be used in landscape mode, so this problem means there's a chance many people won't see the adverts.
PS I'm using Xamarin.GooglePlayServices.Ads version 119.8.0. I haven't been able to implement version 120 because there's no documentation or anything that would help me do it.
Edit 1: I've tried conditionally adding an adaptive banner ad when in portrait, and a standard banner ad using MarcTron.Admob. It doesn't work.
I wondered if it's because the S21 Ultra's display is 1440 x 3200 pixels with an aspect ration of 20:9, and Google Ad Mob can't cope with it. It's rather stupid if that's the case ('adaptive'?!). So I tried giving it a screen width of 2560 on the basis that it worked on the S6 (1440x3200), and 1600 (i.e. half), but neither worked.
Edit 2: I realised I'd made a mistake when I tried limiting the screen width to 2560px, which was that I only did that for the height request of the view, whereas I also needed to do it for the AdSize property of the AdMob class itself. Anyway, that is the problem - adaptive banner ads can't cope with a display 3200px wide.
Google AdMab adaptive banner adverts cannot cope with a screen width of 3200px. I don't know what the actual limit is but since it works on my other device that has a screen width of 2560px I've limited it to that, like so:
adView.AdSize = AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSize(Android.App.Application.Context, (int)(Math.Min(2560,DeviceDisplay.MainDisplayInfo.Width) / DeviceDisplay.MainDisplayInfo.Density));
and applied the same Math.Min() limiter to the code in my question.
The has the slightly unfortunate side-effect of a gap either side of the banner ad (3200-2560)/2=320 pixels wide. This doesn't violate Google's policies though (https://developers.google.com/admob/android/banner/adaptive).
I suggest this is a bug in Google's API (or at least the NuGet package), as an 'adaptive' ad that can't cope with all screen resolutions in real devices doesn't live up to its name.

Xamarin -- Set zoom in AVCapture not working

Hello I am trying to increase the zoom of the camera to its max level in my application.
However after setting the AvCapture to its max value it remains at its lowest zoom level on the screen. Below is my code.
void Initialize()
{
var videoDevices = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video);
var cameraPosition = (cameraOptions == CameraOptions.Front) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back;
var device = videoDevices.FirstOrDefault(d => d.Position == cameraPosition);
device.LockForConfiguration(out error);
if (error == null)
{
Console.WriteLine("Supports Preset");
var test = device.RampingVideoZoom;
var d = device.VideoZoomFactor;
device.VideoZoomFactor = device.ActiveFormat.VideoMaxZoomFactor;
}
device.UnlockForConfiguration();
while(device.RampingVideoZoom == true)
{
Console.WriteLine("Zooming camera"); //This line is never written
}
//See below for value this returns in Console
Console.WriteLine("Current Format");
Console.WriteLine(device.ActiveFormat);
}
Current Format
<AVCaptureDeviceFormat: 0x1c48049a0 'vide'/'420v' 1920x1080, { 3- 30 fps}, HRSI:4096x2304, fov:59.680, supports vis, max zoom:16.00 (upscales #1.94), AF System:2, ISO:22.0-704.0, SS:0.000005-0.333333>
This code does not affect the zoom of the camera AT ALL.
What am I doing wrong?
videoMaxZoomFactor Definition
A maximum factor of 1.0 indicates that the format is not capable of zooming.
There is no mistake in your code.
As the Documentation said ,if device.ActiveFormat.VideoMaxZoomFactor == 1 ,the zoom is not available.
You can debug the value of device.ActiveFormat.VideoMaxZoomFactor to see if it euqals to 1.

how to draw a line in windows store apps

I am trying to create an application which should consist of a line drawn when keyboard key is pressed. When the left arrow in the keyboard is pressed then the line should move in left direction. When right arrow in the keyboard is pressed then the respective line should move in right direction.
I think it is possible with Path class but I don't know how to implement. Even I don't know how to start the code. Can you please guide me how to draw the line in windows store apps.
private PathGeometry DrawGeometry()
{
bool largeArc = WedgeAngle > 180.0;
Size outerArcSize = new Size(Radius, Radius);
Size innerArcSize = new Size(InnerRadius, InnerRadius);
Point innerArcStartPoint = Utilities.ComputeCartesianCoordinate(RotationAngle, InnerRadius);
Point ButtomLineEndPoint = Utilities.ComputeCartesianCoordinate(RotationAngle, Radius);
Point OuterArcEndPoint = Utilities.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius);
Point EndLineEndPoint = Utilities.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius);
innerArcStartPoint.X += CentreX;
innerArcStartPoint.Y += CentreY;
ButtomLineEndPoint.X += CentreX;
ButtomLineEndPoint.Y += CentreY;
OuterArcEndPoint.X += CentreX;
OuterArcEndPoint.Y += CentreY;
EndLineEndPoint.X += CentreX;
EndLineEndPoint.Y += CentreY;
PathFigure path = new PathFigure();
path.StartPoint = innerArcStartPoint;
ArcSegment InnerArc = new ArcSegment();
InnerArc.Size = innerArcSize;
InnerArc.SweepDirection = SweepDirection.Counterclockwise;
InnerArc.Point = innerArcStartPoint;
InnerArc.IsLargeArc = largeArc;
LineSegment ButtomLine = new LineSegment();
ButtomLine.Point = ButtomLineEndPoint;
ArcSegment OuterArc = new ArcSegment();
OuterArc.SweepDirection = SweepDirection.Clockwise;
OuterArc.Point = OuterArcEndPoint;
OuterArc.Size = outerArcSize;
OuterArc.IsLargeArc = largeArc;
LineSegment EndLine = new LineSegment();
EndLine.Point = EndLineEndPoint;
path.Segments.Add(ButtomLine);
path.Segments.Add(OuterArc);
path.Segments.Add(EndLine);
path.Segments.Add(InnerArc);
PathGeometry myPath = new PathGeometry();
myPath.Figures.Add(path);
return myPath;
}
This code will Draw a Pie slice for you as I was building a PieChart it Containsn Lines Curves etc. It will save lots of your time

How to access urls of images and xy coordinates from the DOM. dragging related also pure js please

How to access urls of images and xy coordinates from the DOM.
I have a div with multiple image gifs in it.
The gifs represent electronic components on stripboard or protoboard.
The img gifs are generated using this code.
function createDiv(img)//img here original code was for creating new divs
{
alert(divnumber);//an incrementing or decrementing image array position counter
{
var divTag = document.createElement("img");
divTag.id ='part'+divnumber;
imageArray[divnumber+1]=200;//arbitrary inital x placement
imageArray[divnumber+2]=200;//arbitrary initial y placment
divTag.className ="dragme";
divTag.src = imageArray[divnumber];//gif;//imageArray[i];
document.body.appendChild(divTag);
}
divnumber=divnumber+3;//offset between gif url in image array
}
The gifs are draggable using this code. I don't fully understand drag code but it was the simplest I could find and make work.
//<script language="JavaScript1.2">
<!--
var ie=document.all;//if using explorer
var nn6=document.getElementById&&!document.all;//if using netscape
var isdrag=false;//are we dragging??
var x,y;
var dobj;//drag object
function movemouse(e)
{
if (isdrag) //if drag istrue
{
dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
//alert(dobj.style.left);
dobj.style.top = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
return false;
}
}
function selectmouse(e)
{
var fobj = nn6 ? e.target : event.srcElement;
var topelement = nn6 ? "HTML" : "BODY";
while (fobj.tagName != topelement && fobj.className != "dragme")
{
fobj = nn6 ? fobj.parentNode : fobj.parentElement;
}
if (fobj.className=="dragme")
{
isdrag = true;
dobj = fobj;
tx = parseInt(dobj.style.left+0);
//alert(tx);
ty = parseInt(dobj.style.top+0);
x = nn6 ? e.clientX : event.clientX;
//alert(x +' "=y);
y = nn6 ? e.clientY : event.clientY;
document.onmousemove=movemouse;
return false;
}
}
document.onmousedown=selectmouse;//go to selectmouse when mouse down in document
document.onmouseup=new Function("isdrag=false");
//-->
I need to put all the gifs and x y coordinates into an array that I can save with html5 local storage.
I can save an array and recall it ok.
But I need to fill the array with urls and xy coords of draggable items.
I can't figure how to get that info from either the dragging code or the DOM.
I think I can get that info from the dom image list but I still cant get up to speeds on all the dom details.
Can anyone tell me how to identify the gif url and xy coordinates from either the drag code or the DOM.
This is basically my last hurdle before I can comnplete the prrogram.
Many Thanks. I am mainly a cut and paste and hacking found scripts in my programming level.
Oh!! I am almost 70 and this IS NOT a homework problem!!
Thanks markE for last help.
TiMathis
After further thought I can probably dig the xy's out of the drag code but how can I determine which gif is being dragged?
OK I can get the objects id ...alert(dobj.id)
I should be able to use that to get other info for immage array info I need.
if (fobj.className=="dragme")
{
isdrag = true;
dobj = fobj;
alert(dobj.id);
tx = parseInt(dobj.style.left+0);
//alert(tx);
ty = parseInt(dobj.style.top+0);
x = nn6 ? e.clientX : event.clientX;
//alert(x +' "=y);
y = nn6 ? e.clientY : event.clientY;
document.onmousemove=movemouse;
return false;
}
}

intercept the object from click as2

in ActionScript2 there is a way to intercept the click on a movieClip?
I'll explain; I've this code:
planGroup.createEmptyMovieClip("textObject", 90);
if (textArray != "")
{
for (tn = 0; tn < textArray.length; tn++)
{
textFormat = new TextFormat();
textFormat.size = 100 * 0.35;
var lbl = planGroup.textObject.createTextField("My_Instance_Name", tn,xt - minPlanX, yt - minPlanY,150,90);
lbl.text = textArray[tn].attributes.text;
xt = textArray[tn].attributes.x * multFactor;
yt = -textArray[tn].attributes.y * multFactor;
planGroup.textObject.createEmptyMovieClip("invis", getNextHighestDepth());
with (planGroup.textObject.invis) {
beginFill(0x22ffff, 50);
moveTo(xt - minPlanX, yt - minPlanY);
lineTo(xt - minPlanX + 150, yt - minPlanY);
lineTo(xt - minPlanX + 150, yt - minPlanY + 90);
lineTo(xt - minPlanX, yt - minPlanY + 90);
lineTo(xt - minPlanX, yt - minPlanY);
endFill();
}
planGroup.textObject.onRelease = function() {
trace("click");
}
that is I want to make the text clickable..and with this code it is, but i want the onRelease() makes different things on different text..so, how can I understand where the click come from?
Furthermore i noticed that the shape is drawn only on the last item of the 'for'.
Any ideas? Thanks in advance!

Resources