Issue
@ColeX - MSFT helped in the implementation of SpotLight in Xamarin Project.
Now, I want that when for the first time the app opens up, this spotlight should start automatically (android page).
And when it went off, the forms page should appear. I mean, how can I detect if all (3) spotlights are disappeared? so then I can navigate to the forms page, which will have the actual UI I want to show.
Custom renderer for Page.
[assembly: ExportRenderer(typeof(Page1), typeof(MainPageRenderer))]
namespace CustomRenderer.Droid
{
class MainPageRenderer : PageRenderer
{
private Android.Views.View view;
private Android.Widget.Button button1;
private Android.Widget.Button button2;
private Android.Widget.Button button3;
public MainPageRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
view = MainActivity.Instance.LayoutInflater.Inflate(Resource.Layout.MyPage, this, false);
AddView(view);
view.Click += View_Click;
button1 = view.FindViewById<Android.Widget.Button>(Resource.Id.firstButton);
button2 = view.FindViewById<Android.Widget.Button>(Resource.Id.secondButton);
button3 = view.FindViewById<Android.Widget.Button>(Resource.Id.thirdButton);
}
bool isShown_FirstButton_SpotLight = false;
bool isShown_SecondButton_SpotLight = false;
bool isShown_ThirdButton_SpotLight = false;
private void View_Click(object sender, EventArgs e)
{
if (!isShown_FirstButton_SpotLight)
{
show(button1 ,"First Button" ,"Lorem ipsum dolor sit amet, consectetur adipiscing elit", "FirstButton");
isShown_FirstButton_SpotLight = true;
return;
}
if (!isShown_SecondButton_SpotLight)
{
show(button2,"Second Button", "Sed do eiusmod tempor incididunt ut labore eta", "SecondButton");
isShown_SecondButton_SpotLight = true;
return;
}
if (!isShown_ThirdButton_SpotLight)
{
show(button3,"Third Button", "Ut enim ad minim veniam, quis nostrud exercitation", "ThirdButton");
isShown_ThirdButton_SpotLight = true;
return;
}
}
void show(Android.Views.View view, string title, string subTitle, string usageId)
{
new SpotlightView.Builder(MainActivity.Instance)
.IntroAnimationDuration(400)
.EnableRevealAnimation(true)
.PerformClick(true)
.FadeinTextDuration(400)
.HeadingTvColor(Android.Graphics.Color.ParseColor("#eb273f"))
.HeadingTvSize(32)
.HeadingTvText(title)
.SubHeadingTvColor(Android.Graphics.Color.ParseColor("#eb273f"))
.SubHeadingTvSize(16)
.SubHeadingTvText(subTitle)
.MaskColor(Android.Graphics.Color.ParseColor("#dc000000"))
.Target(view)
.LineAnimDuration(400)
.LineAndArcColor(Android.Graphics.Color.ParseColor("#eb273f"))
.DismissOnTouch(true)
.DismissOnBackPress(true)
.EnableDismissAfterShown(true)
.UsageId(usageId)
.ShowTargetArc(true)
.Show();
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);
view.Measure(msw, msh);
view.Layout(0, 0, r - l, b - t);
}
}
}
Resources/layout/MyPage
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/firstButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:text="First"
android:background="#00ff00"/>
<Button
android:id="@+id/secondButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="100dp"
android:text="Second"
android:background="#ff0000"/>
<Button
android:id="@+id/thirdButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="150dp"
android:layout_marginTop="150dp"
android:text="Third"
android:background="#0000ff"/>
</LinearLayout>
Solution
You just need to proactively call the start animation method, and then call one of the methods defined in the page after all animations.
for example :
define a FinishAnim
method in your page.cs:
public partial class YourPage: ContentPage
{
public YourPage()
{
InitializeComponent();
}
public void FinishAnim(){
//navigate to other form page
}
}
then start the animation in your renderer:
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
view = MainActivity.Instance.LayoutInflater.Inflate(Resource.Layout.MyPage, this, false);
AddView(view);
button1 = view.FindViewById<Android.Widget.Button>(Resource.Id.firstButton);
button2 = view.FindViewById<Android.Widget.Button>(Resource.Id.secondButton);
button3 = view.FindViewById<Android.Widget.Button>(Resource.Id.thirdButton);
//start the three animations
show(button1 ,"First Button" ,"Lorem ipsum dolor sit amet, consectetur adipiscing elit", "FirstButton");
show(button2,"Second Button", "Sed do eiusmod tempor incididunt ut labore eta", "SecondButton");
show(button3,"Third Button", "Ut enim ad minim veniam, quis nostrud exercitation", "ThirdButton");
//if you want play the animation one by one,you could set some delay time for them or check the SpotlightSequence.getInstance(this, null).AddSpotlight(...).AddSpotlight(...)....StartSequence();method.
//after animations
YourPage page = (YourPage)Element;
page.FinishAnim();
}
Answered By - Leo Zhu - MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.