From 76a100911cefbe54415ed59d27314556d9593fac Mon Sep 17 00:00:00 2001 From: SuryanshSangwan <32640058+suryanshsangwan@users.noreply.github.com> Date: Thu, 19 May 2022 15:00:51 +0530 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ab026a0..83a49bc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ SlidingMenuSharp ================ -A direct port of [SlidingMenu](https://github.com/jfeinstein10/SlidingMenu) to C# to work with [Xamarin.Android](http://xamarin.com/monoforandroid) +A direct port of [SlidingMenu](https://github.com/jfeinstein10/SlidingMenu) to C# to work with [Xamarin.Android](http://xamarin.com/monoforandroid) **upgraded to support AndroidX** TODO ---- From d775c3a94af7fe93d94c187b15355bc3678f5808 Mon Sep 17 00:00:00 2001 From: Suryansh Date: Thu, 19 May 2022 16:11:20 +0530 Subject: [PATCH 2/2] upgraded to support android X --- SlidingMenuSharp/App/ISlidingActivity.cs | 66 +- SlidingMenuSharp/App/SlidingActivity.cs | 242 +-- SlidingMenuSharp/App/SlidingActivityHelper.cs | 326 +-- .../App/SlidingFragmentActivity.cs | 242 +-- SlidingMenuSharp/App/SlidingListActivity.cs | 254 +-- .../App/SlidingPreferenceActivity.cs | 242 +-- SlidingMenuSharp/CanvasTransformer.cs | 134 +- SlidingMenuSharp/CustomViewAbove.cs | 1740 ++++++++--------- SlidingMenuSharp/CustomViewBehind.cs | 1002 +++++----- SlidingMenuSharp/Enums.cs | 74 +- SlidingMenuSharp/Properties/AssemblyInfo.cs | 58 +- SlidingMenuSharp/ResourceIdFix.cs | 92 +- .../Resources/Resource.Designer.cs | 843 +++++++- .../Resources/layout/slidingmenumain.xml | 10 +- SlidingMenuSharp/Resources/values/attrs.xml | 54 +- SlidingMenuSharp/Resources/values/ids.xml | 6 +- SlidingMenuSharp/SlidingMenu.cs | 1158 +++++------ SlidingMenuSharp/SlidingMenuEventArgs.cs | 70 +- SlidingMenuSharp/SlidingMenuSharp.csproj | 173 +- SlidingMenuSharp/packages.config | 32 + 20 files changed, 3847 insertions(+), 2971 deletions(-) create mode 100644 SlidingMenuSharp/packages.config diff --git a/SlidingMenuSharp/App/ISlidingActivity.cs b/SlidingMenuSharp/App/ISlidingActivity.cs index 0b5afb9..c32eef4 100644 --- a/SlidingMenuSharp/App/ISlidingActivity.cs +++ b/SlidingMenuSharp/App/ISlidingActivity.cs @@ -1,34 +1,34 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using Android.Views; - -namespace SlidingMenuSharp.App -{ - public interface ISlidingActivity - { - void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams); - void SetBehindContentView(View view); - void SetBehindContentView(int layoutResId); - SlidingMenu SlidingMenu { get; } - void Toggle(); - void ShowContent(); - void ShowMenu(); - void ShowSecondaryMenu(); - void SetSlidingActionBarEnabled(bool enabled); - } +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using Android.Views; + +namespace SlidingMenuSharp.App +{ + public interface ISlidingActivity + { + void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams); + void SetBehindContentView(View view); + void SetBehindContentView(int layoutResId); + SlidingMenu SlidingMenu { get; } + void Toggle(); + void ShowContent(); + void ShowMenu(); + void ShowSecondaryMenu(); + void SetSlidingActionBarEnabled(bool enabled); + } } \ No newline at end of file diff --git a/SlidingMenuSharp/App/SlidingActivity.cs b/SlidingMenuSharp/App/SlidingActivity.cs index 537a520..0603990 100644 --- a/SlidingMenuSharp/App/SlidingActivity.cs +++ b/SlidingMenuSharp/App/SlidingActivity.cs @@ -1,122 +1,122 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using Android.App; -using Android.OS; -using Android.Views; - -namespace SlidingMenuSharp.App -{ - public class SlidingActivity : Activity, ISlidingActivity - { - private SlidingActivityHelper _helper; - - protected override void OnCreate(Bundle savedInstanceState) - { - base.OnCreate(savedInstanceState); - _helper = new SlidingActivityHelper(this); - _helper.OnCreate(savedInstanceState); - } - - protected override void OnPostCreate(Bundle savedInstanceState) - { - base.OnPostCreate(savedInstanceState); - _helper.OnPostCreate(savedInstanceState); - } - - public override View FindViewById(int id) - { - var v = base.FindViewById(id); - return v ?? _helper.FindViewById(id); - } - - protected override void OnSaveInstanceState(Bundle outState) - { - base.OnSaveInstanceState(outState); - _helper.OnSaveInstanceState(outState); - } - - public override void SetContentView(int layoutResId) - { - SetContentView(LayoutInflater.Inflate(layoutResId, null)); - } - - public override void SetContentView(View view) - { - SetContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, - ViewGroup.LayoutParams.MatchParent)); - } - - public override void SetContentView(View view, ViewGroup.LayoutParams @params) - { - base.SetContentView(view, @params); - _helper.RegisterAboveContentView(view, @params); - } - - public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) - { - _helper.SetBehindContentView(view, layoutParams); - } - - public void SetBehindContentView(View view) - { - SetBehindContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, - ViewGroup.LayoutParams.MatchParent)); - } - - public void SetBehindContentView(int layoutResId) - { - SetBehindContentView(LayoutInflater.Inflate(layoutResId, null)); - } - - public SlidingMenu SlidingMenu - { - get { return _helper.SlidingMenu; } - } - - public void Toggle() - { - _helper.Toggle(); - } - - public void ShowContent() - { - _helper.ShowContent(); - } - - public void ShowMenu() - { - _helper.ShowMenu(); - } - - public void ShowSecondaryMenu() - { - _helper.ShowSecondaryMenu(); - } - - public void SetSlidingActionBarEnabled(bool enabled) - { - _helper.SlidingActionBarEnabled = enabled; - } - - public override bool OnKeyUp(Keycode keyCode, KeyEvent e) - { - var b = _helper.OnKeyUp(keyCode, e); - return b ? b : base.OnKeyUp(keyCode, e); - } - } +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using Android.App; +using Android.OS; +using Android.Views; + +namespace SlidingMenuSharp.App +{ + public class SlidingActivity : Activity, ISlidingActivity + { + private SlidingActivityHelper _helper; + + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + _helper = new SlidingActivityHelper(this); + _helper.OnCreate(savedInstanceState); + } + + protected override void OnPostCreate(Bundle savedInstanceState) + { + base.OnPostCreate(savedInstanceState); + _helper.OnPostCreate(savedInstanceState); + } + + public override View FindViewById(int id) + { + var v = base.FindViewById(id); + return v ?? _helper.FindViewById(id); + } + + protected override void OnSaveInstanceState(Bundle outState) + { + base.OnSaveInstanceState(outState); + _helper.OnSaveInstanceState(outState); + } + + public override void SetContentView(int layoutResId) + { + SetContentView(LayoutInflater.Inflate(layoutResId, null)); + } + + public override void SetContentView(View view) + { + SetContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, + ViewGroup.LayoutParams.MatchParent)); + } + + public override void SetContentView(View view, ViewGroup.LayoutParams @params) + { + base.SetContentView(view, @params); + _helper.RegisterAboveContentView(view, @params); + } + + public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) + { + _helper.SetBehindContentView(view, layoutParams); + } + + public void SetBehindContentView(View view) + { + SetBehindContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, + ViewGroup.LayoutParams.MatchParent)); + } + + public void SetBehindContentView(int layoutResId) + { + SetBehindContentView(LayoutInflater.Inflate(layoutResId, null)); + } + + public SlidingMenu SlidingMenu + { + get { return _helper.SlidingMenu; } + } + + public void Toggle() + { + _helper.Toggle(); + } + + public void ShowContent() + { + _helper.ShowContent(); + } + + public void ShowMenu() + { + _helper.ShowMenu(); + } + + public void ShowSecondaryMenu() + { + _helper.ShowSecondaryMenu(); + } + + public void SetSlidingActionBarEnabled(bool enabled) + { + _helper.SlidingActionBarEnabled = enabled; + } + + public override bool OnKeyUp(Keycode keyCode, KeyEvent e) + { + var b = _helper.OnKeyUp(keyCode, e); + return b ? b : base.OnKeyUp(keyCode, e); + } + } } \ No newline at end of file diff --git a/SlidingMenuSharp/App/SlidingActivityHelper.cs b/SlidingMenuSharp/App/SlidingActivityHelper.cs index cafca34..621c0ad 100644 --- a/SlidingMenuSharp/App/SlidingActivityHelper.cs +++ b/SlidingMenuSharp/App/SlidingActivityHelper.cs @@ -1,164 +1,164 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using System; -using Android.App; -using Android.OS; -using Android.Views; - -namespace SlidingMenuSharp.App -{ - public class SlidingActivityHelper - { - private readonly Activity _activity; - private SlidingMenu _slidingMenu; - private View _viewAbove; - private View _viewBehind; - private bool _broadcasting; - private bool _onPostCreateCalled; - private bool _enableSlide = true; - - public SlidingActivityHelper(Activity activity) - { - ResourceIdManager.UpdateIdValues(); - _activity = activity; - } - - public void OnCreate(Bundle savedInstanceState) - { - _slidingMenu = (SlidingMenu) LayoutInflater.From(_activity).Inflate(Resource.Layout.slidingmenumain, null); - } - - public void OnPostCreate(Bundle savedInstanceState) - { - if (null == _viewBehind && null == _viewAbove) - throw new InvalidOperationException("Both SetBehindContentView must be called " + - "in OnCreate in addition to SetContentView."); - - _onPostCreateCalled = true; - - _slidingMenu.AttachToActivity(_activity, - _enableSlide ? SlideStyle.Window : SlideStyle.Content); - - bool open, secondary; - if (null != savedInstanceState) - { - open = savedInstanceState.GetBoolean("SlidingActivityHelper.open"); - secondary = savedInstanceState.GetBoolean("SlidingActivityHelper.secondary"); - } - else - { - open = false; - secondary = false; - } - - new Handler().Post(() => - { - if (open) - { - if (secondary) - _slidingMenu.ShowSecondaryMenu(false); - else - _slidingMenu.ShowMenu(false); - } - else - _slidingMenu.ShowContent(false); - }); - } - - public bool SlidingActionBarEnabled - { - get { return _enableSlide; } - set - { - if (_onPostCreateCalled) - throw new InvalidOperationException("EnableSlidingActionBar must be called in OnCreate."); - _enableSlide = value; - } - } - - public View FindViewById(int id) - { - if (_slidingMenu != null) - { - var v = _slidingMenu.FindViewById(id); - if (v != null) - return v; - } - return null; - } - - public void OnSaveInstanceState(Bundle outState) - { - outState.PutBoolean("SlidingActivityHelper.open", _slidingMenu.IsMenuShowing); - outState.PutBoolean("SlidingActivityHelper.secondary", _slidingMenu.IsSecondaryMenuShowing); - } - - public void RegisterAboveContentView(View v, ViewGroup.LayoutParams layoutParams) - { - if (_broadcasting) - _viewAbove = v; - } - - public void SetContentView(View v) - { - _broadcasting = true; - _activity.SetContentView(v); - } - - public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) - { - _viewBehind = view; - _slidingMenu.SetMenu(_viewBehind); - } - - public SlidingMenu SlidingMenu - { - get { return _slidingMenu; } - } - - public void Toggle() - { - _slidingMenu.Toggle(); - } - - public void ShowContent() - { - _slidingMenu.ShowContent(); - } - - public void ShowMenu() - { - _slidingMenu.ShowMenu(); - } - - public void ShowSecondaryMenu() - { - _slidingMenu.ShowSecondaryMenu(); - } - - public bool OnKeyUp(Keycode keycode, KeyEvent keyEvent) - { - if (keycode == Keycode.Back && _slidingMenu.IsMenuShowing) - { - ShowContent(); - return true; - } - return false; - } - } +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using System; +using Android.App; +using Android.OS; +using Android.Views; + +namespace SlidingMenuSharp.App +{ + public class SlidingActivityHelper + { + private readonly Activity _activity; + private SlidingMenu _slidingMenu; + private View _viewAbove; + private View _viewBehind; + private bool _broadcasting; + private bool _onPostCreateCalled; + private bool _enableSlide = true; + + public SlidingActivityHelper(Activity activity) + { + ResourceIdManager.UpdateIdValues(); + _activity = activity; + } + + public void OnCreate(Bundle savedInstanceState) + { + _slidingMenu = (SlidingMenu) LayoutInflater.From(_activity).Inflate(Resource.Layout.slidingmenumain, null); + } + + public void OnPostCreate(Bundle savedInstanceState) + { + if (null == _viewBehind && null == _viewAbove) + throw new InvalidOperationException("Both SetBehindContentView must be called " + + "in OnCreate in addition to SetContentView."); + + _onPostCreateCalled = true; + + _slidingMenu.AttachToActivity(_activity, + _enableSlide ? SlideStyle.Window : SlideStyle.Content); + + bool open, secondary; + if (null != savedInstanceState) + { + open = savedInstanceState.GetBoolean("SlidingActivityHelper.open"); + secondary = savedInstanceState.GetBoolean("SlidingActivityHelper.secondary"); + } + else + { + open = false; + secondary = false; + } + + new Handler().Post(() => + { + if (open) + { + if (secondary) + _slidingMenu.ShowSecondaryMenu(false); + else + _slidingMenu.ShowMenu(false); + } + else + _slidingMenu.ShowContent(false); + }); + } + + public bool SlidingActionBarEnabled + { + get { return _enableSlide; } + set + { + if (_onPostCreateCalled) + throw new InvalidOperationException("EnableSlidingActionBar must be called in OnCreate."); + _enableSlide = value; + } + } + + public View FindViewById(int id) + { + if (_slidingMenu != null) + { + var v = _slidingMenu.FindViewById(id); + if (v != null) + return v; + } + return null; + } + + public void OnSaveInstanceState(Bundle outState) + { + outState.PutBoolean("SlidingActivityHelper.open", _slidingMenu.IsMenuShowing); + outState.PutBoolean("SlidingActivityHelper.secondary", _slidingMenu.IsSecondaryMenuShowing); + } + + public void RegisterAboveContentView(View v, ViewGroup.LayoutParams layoutParams) + { + if (_broadcasting) + _viewAbove = v; + } + + public void SetContentView(View v) + { + _broadcasting = true; + _activity.SetContentView(v); + } + + public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) + { + _viewBehind = view; + _slidingMenu.SetMenu(_viewBehind); + } + + public SlidingMenu SlidingMenu + { + get { return _slidingMenu; } + } + + public void Toggle() + { + _slidingMenu.Toggle(); + } + + public void ShowContent() + { + _slidingMenu.ShowContent(); + } + + public void ShowMenu() + { + _slidingMenu.ShowMenu(); + } + + public void ShowSecondaryMenu() + { + _slidingMenu.ShowSecondaryMenu(); + } + + public bool OnKeyUp(Keycode keycode, KeyEvent keyEvent) + { + if (keycode == Keycode.Back && _slidingMenu.IsMenuShowing) + { + ShowContent(); + return true; + } + return false; + } + } } \ No newline at end of file diff --git a/SlidingMenuSharp/App/SlidingFragmentActivity.cs b/SlidingMenuSharp/App/SlidingFragmentActivity.cs index 02cfade..7ba54af 100644 --- a/SlidingMenuSharp/App/SlidingFragmentActivity.cs +++ b/SlidingMenuSharp/App/SlidingFragmentActivity.cs @@ -1,122 +1,122 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using Android.OS; -using Android.Support.V4.App; -using Android.Views; - -namespace SlidingMenuSharp.App -{ - public class SlidingFragmentActivity : FragmentActivity, ISlidingActivity - { - private SlidingActivityHelper _helper; - - protected override void OnCreate(Bundle savedInstanceState) - { - base.OnCreate(savedInstanceState); - _helper = new SlidingActivityHelper(this); - _helper.OnCreate(savedInstanceState); - } - - protected override void OnPostCreate(Bundle savedInstanceState) - { - base.OnPostCreate(savedInstanceState); - _helper.OnPostCreate(savedInstanceState); - } - - public override View FindViewById(int id) - { - var v = base.FindViewById(id); - return v ?? _helper.FindViewById(id); - } - - protected override void OnSaveInstanceState(Bundle outState) - { - base.OnSaveInstanceState(outState); - _helper.OnSaveInstanceState(outState); - } - - public override void SetContentView(int layoutResId) - { - SetContentView(LayoutInflater.Inflate(layoutResId, null)); - } - - public override void SetContentView(View view) - { - SetContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, - ViewGroup.LayoutParams.MatchParent)); - } - - public override void SetContentView(View view, ViewGroup.LayoutParams @params) - { - base.SetContentView(view, @params); - _helper.RegisterAboveContentView(view, @params); - } - - public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) - { - _helper.SetBehindContentView(view, layoutParams); - } - - public void SetBehindContentView(View view) - { - SetBehindContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, - ViewGroup.LayoutParams.MatchParent)); - } - - public void SetBehindContentView(int layoutResId) - { - SetBehindContentView(LayoutInflater.Inflate(layoutResId, null)); - } - - public SlidingMenu SlidingMenu - { - get { return _helper.SlidingMenu; } - } - - public void Toggle() - { - _helper.Toggle(); - } - - public void ShowContent() - { - _helper.ShowContent(); - } - - public void ShowMenu() - { - _helper.ShowMenu(); - } - - public void ShowSecondaryMenu() - { - _helper.ShowSecondaryMenu(); - } - - public void SetSlidingActionBarEnabled(bool enabled) - { - _helper.SlidingActionBarEnabled = enabled; - } - - public override bool OnKeyUp(Keycode keyCode, KeyEvent e) - { - var b = _helper.OnKeyUp(keyCode, e); - return b ? b : base.OnKeyUp(keyCode, e); - } - } +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using Android.OS; +using Android.Support.V4.App; +using Android.Views; + +namespace SlidingMenuSharp.App +{ + public class SlidingFragmentActivity : FragmentActivity, ISlidingActivity + { + private SlidingActivityHelper _helper; + + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + _helper = new SlidingActivityHelper(this); + _helper.OnCreate(savedInstanceState); + } + + protected override void OnPostCreate(Bundle savedInstanceState) + { + base.OnPostCreate(savedInstanceState); + _helper.OnPostCreate(savedInstanceState); + } + + public override View FindViewById(int id) + { + var v = base.FindViewById(id); + return v ?? _helper.FindViewById(id); + } + + protected override void OnSaveInstanceState(Bundle outState) + { + base.OnSaveInstanceState(outState); + _helper.OnSaveInstanceState(outState); + } + + public override void SetContentView(int layoutResId) + { + SetContentView(LayoutInflater.Inflate(layoutResId, null)); + } + + public override void SetContentView(View view) + { + SetContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, + ViewGroup.LayoutParams.MatchParent)); + } + + public override void SetContentView(View view, ViewGroup.LayoutParams @params) + { + base.SetContentView(view, @params); + _helper.RegisterAboveContentView(view, @params); + } + + public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) + { + _helper.SetBehindContentView(view, layoutParams); + } + + public void SetBehindContentView(View view) + { + SetBehindContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, + ViewGroup.LayoutParams.MatchParent)); + } + + public void SetBehindContentView(int layoutResId) + { + SetBehindContentView(LayoutInflater.Inflate(layoutResId, null)); + } + + public SlidingMenu SlidingMenu + { + get { return _helper.SlidingMenu; } + } + + public void Toggle() + { + _helper.Toggle(); + } + + public void ShowContent() + { + _helper.ShowContent(); + } + + public void ShowMenu() + { + _helper.ShowMenu(); + } + + public void ShowSecondaryMenu() + { + _helper.ShowSecondaryMenu(); + } + + public void SetSlidingActionBarEnabled(bool enabled) + { + _helper.SlidingActionBarEnabled = enabled; + } + + public override bool OnKeyUp(Keycode keyCode, KeyEvent e) + { + var b = _helper.OnKeyUp(keyCode, e); + return b ? b : base.OnKeyUp(keyCode, e); + } + } } \ No newline at end of file diff --git a/SlidingMenuSharp/App/SlidingListActivity.cs b/SlidingMenuSharp/App/SlidingListActivity.cs index 2b02bb5..0cc334e 100644 --- a/SlidingMenuSharp/App/SlidingListActivity.cs +++ b/SlidingMenuSharp/App/SlidingListActivity.cs @@ -1,128 +1,128 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using Android.App; -using Android.OS; -using Android.Views; -using Android.Widget; - -namespace SlidingMenuSharp.App -{ - public class SlidingListActivity : ListActivity, ISlidingActivity - { - private SlidingActivityHelper _helper; - - protected override void OnCreate(Bundle savedInstanceState) - { - base.OnCreate(savedInstanceState); - _helper = new SlidingActivityHelper(this); - _helper.OnCreate(savedInstanceState); - var listView = new ListView(this) - { - Id = Android.Resource.Id.List - }; - SetContentView(listView); - } - - protected override void OnPostCreate(Bundle savedInstanceState) - { - base.OnPostCreate(savedInstanceState); - _helper.OnPostCreate(savedInstanceState); - } - - public override View FindViewById(int id) - { - var v = base.FindViewById(id); - return v ?? _helper.FindViewById(id); - } - - protected override void OnSaveInstanceState(Bundle outState) - { - base.OnSaveInstanceState(outState); - _helper.OnSaveInstanceState(outState); - } - - public override void SetContentView(int layoutResId) - { - SetContentView(LayoutInflater.Inflate(layoutResId, null)); - } - - public override void SetContentView(View view) - { - SetContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, - ViewGroup.LayoutParams.MatchParent)); - } - - public override void SetContentView(View view, ViewGroup.LayoutParams @params) - { - base.SetContentView(view, @params); - _helper.RegisterAboveContentView(view, @params); - } - - public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) - { - _helper.SetBehindContentView(view, layoutParams); - } - - public void SetBehindContentView(View view) - { - SetBehindContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, - ViewGroup.LayoutParams.MatchParent)); - } - - public void SetBehindContentView(int layoutResId) - { - SetBehindContentView(LayoutInflater.Inflate(layoutResId, null)); - } - - public SlidingMenu SlidingMenu - { - get { return _helper.SlidingMenu; } - } - - public void Toggle() - { - _helper.Toggle(); - } - - public void ShowContent() - { - _helper.ShowContent(); - } - - public void ShowMenu() - { - _helper.ShowMenu(); - } - - public void ShowSecondaryMenu() - { - _helper.ShowSecondaryMenu(); - } - - public void SetSlidingActionBarEnabled(bool enabled) - { - _helper.SlidingActionBarEnabled = enabled; - } - - public override bool OnKeyUp(Keycode keyCode, KeyEvent e) - { - var b = _helper.OnKeyUp(keyCode, e); - return b ? b : base.OnKeyUp(keyCode, e); - } - } +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using Android.App; +using Android.OS; +using Android.Views; +using Android.Widget; + +namespace SlidingMenuSharp.App +{ + public class SlidingListActivity : ListActivity, ISlidingActivity + { + private SlidingActivityHelper _helper; + + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + _helper = new SlidingActivityHelper(this); + _helper.OnCreate(savedInstanceState); + var listView = new ListView(this) + { + Id = Android.Resource.Id.List + }; + SetContentView(listView); + } + + protected override void OnPostCreate(Bundle savedInstanceState) + { + base.OnPostCreate(savedInstanceState); + _helper.OnPostCreate(savedInstanceState); + } + + public override View FindViewById(int id) + { + var v = base.FindViewById(id); + return v ?? _helper.FindViewById(id); + } + + protected override void OnSaveInstanceState(Bundle outState) + { + base.OnSaveInstanceState(outState); + _helper.OnSaveInstanceState(outState); + } + + public override void SetContentView(int layoutResId) + { + SetContentView(LayoutInflater.Inflate(layoutResId, null)); + } + + public override void SetContentView(View view) + { + SetContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, + ViewGroup.LayoutParams.MatchParent)); + } + + public override void SetContentView(View view, ViewGroup.LayoutParams @params) + { + base.SetContentView(view, @params); + _helper.RegisterAboveContentView(view, @params); + } + + public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) + { + _helper.SetBehindContentView(view, layoutParams); + } + + public void SetBehindContentView(View view) + { + SetBehindContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, + ViewGroup.LayoutParams.MatchParent)); + } + + public void SetBehindContentView(int layoutResId) + { + SetBehindContentView(LayoutInflater.Inflate(layoutResId, null)); + } + + public SlidingMenu SlidingMenu + { + get { return _helper.SlidingMenu; } + } + + public void Toggle() + { + _helper.Toggle(); + } + + public void ShowContent() + { + _helper.ShowContent(); + } + + public void ShowMenu() + { + _helper.ShowMenu(); + } + + public void ShowSecondaryMenu() + { + _helper.ShowSecondaryMenu(); + } + + public void SetSlidingActionBarEnabled(bool enabled) + { + _helper.SlidingActionBarEnabled = enabled; + } + + public override bool OnKeyUp(Keycode keyCode, KeyEvent e) + { + var b = _helper.OnKeyUp(keyCode, e); + return b ? b : base.OnKeyUp(keyCode, e); + } + } } \ No newline at end of file diff --git a/SlidingMenuSharp/App/SlidingPreferenceActivity.cs b/SlidingMenuSharp/App/SlidingPreferenceActivity.cs index ca28891..c3caa89 100644 --- a/SlidingMenuSharp/App/SlidingPreferenceActivity.cs +++ b/SlidingMenuSharp/App/SlidingPreferenceActivity.cs @@ -1,122 +1,122 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using Android.OS; -using Android.Preferences; -using Android.Views; - -namespace SlidingMenuSharp.App -{ - public class SlidingPrefereceActivity : PreferenceActivity, ISlidingActivity - { - private SlidingActivityHelper _helper; - - protected override void OnCreate(Bundle savedInstanceState) - { - base.OnCreate(savedInstanceState); - _helper = new SlidingActivityHelper(this); - _helper.OnCreate(savedInstanceState); - } - - protected override void OnPostCreate(Bundle savedInstanceState) - { - base.OnPostCreate(savedInstanceState); - _helper.OnPostCreate(savedInstanceState); - } - - public override View FindViewById(int id) - { - var v = base.FindViewById(id); - return v ?? _helper.FindViewById(id); - } - - protected override void OnSaveInstanceState(Bundle outState) - { - base.OnSaveInstanceState(outState); - _helper.OnSaveInstanceState(outState); - } - - public override void SetContentView(int layoutResId) - { - SetContentView(LayoutInflater.Inflate(layoutResId, null)); - } - - public override void SetContentView(View view) - { - SetContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, - ViewGroup.LayoutParams.MatchParent)); - } - - public override void SetContentView(View view, ViewGroup.LayoutParams @params) - { - base.SetContentView(view, @params); - _helper.RegisterAboveContentView(view, @params); - } - - public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) - { - _helper.SetBehindContentView(view, layoutParams); - } - - public void SetBehindContentView(View view) - { - SetBehindContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, - ViewGroup.LayoutParams.MatchParent)); - } - - public void SetBehindContentView(int layoutResId) - { - SetBehindContentView(LayoutInflater.Inflate(layoutResId, null)); - } - - public SlidingMenu SlidingMenu - { - get { return _helper.SlidingMenu; } - } - - public void Toggle() - { - _helper.Toggle(); - } - - public void ShowContent() - { - _helper.ShowContent(); - } - - public void ShowMenu() - { - _helper.ShowMenu(); - } - - public void ShowSecondaryMenu() - { - _helper.ShowSecondaryMenu(); - } - - public void SetSlidingActionBarEnabled(bool enabled) - { - _helper.SlidingActionBarEnabled = enabled; - } - - public override bool OnKeyUp(Keycode keyCode, KeyEvent e) - { - var b = _helper.OnKeyUp(keyCode, e); - return b ? b : base.OnKeyUp(keyCode, e); - } - } +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using Android.OS; +using Android.Preferences; +using Android.Views; + +namespace SlidingMenuSharp.App +{ + public class SlidingPrefereceActivity : PreferenceActivity, ISlidingActivity + { + private SlidingActivityHelper _helper; + + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + _helper = new SlidingActivityHelper(this); + _helper.OnCreate(savedInstanceState); + } + + protected override void OnPostCreate(Bundle savedInstanceState) + { + base.OnPostCreate(savedInstanceState); + _helper.OnPostCreate(savedInstanceState); + } + + public override View FindViewById(int id) + { + var v = base.FindViewById(id); + return v ?? _helper.FindViewById(id); + } + + protected override void OnSaveInstanceState(Bundle outState) + { + base.OnSaveInstanceState(outState); + _helper.OnSaveInstanceState(outState); + } + + public override void SetContentView(int layoutResId) + { + SetContentView(LayoutInflater.Inflate(layoutResId, null)); + } + + public override void SetContentView(View view) + { + SetContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, + ViewGroup.LayoutParams.MatchParent)); + } + + public override void SetContentView(View view, ViewGroup.LayoutParams @params) + { + base.SetContentView(view, @params); + _helper.RegisterAboveContentView(view, @params); + } + + public void SetBehindContentView(View view, ViewGroup.LayoutParams layoutParams) + { + _helper.SetBehindContentView(view, layoutParams); + } + + public void SetBehindContentView(View view) + { + SetBehindContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, + ViewGroup.LayoutParams.MatchParent)); + } + + public void SetBehindContentView(int layoutResId) + { + SetBehindContentView(LayoutInflater.Inflate(layoutResId, null)); + } + + public SlidingMenu SlidingMenu + { + get { return _helper.SlidingMenu; } + } + + public void Toggle() + { + _helper.Toggle(); + } + + public void ShowContent() + { + _helper.ShowContent(); + } + + public void ShowMenu() + { + _helper.ShowMenu(); + } + + public void ShowSecondaryMenu() + { + _helper.ShowSecondaryMenu(); + } + + public void SetSlidingActionBarEnabled(bool enabled) + { + _helper.SlidingActionBarEnabled = enabled; + } + + public override bool OnKeyUp(Keycode keyCode, KeyEvent e) + { + var b = _helper.OnKeyUp(keyCode, e); + return b ? b : base.OnKeyUp(keyCode, e); + } + } } \ No newline at end of file diff --git a/SlidingMenuSharp/CanvasTransformer.cs b/SlidingMenuSharp/CanvasTransformer.cs index 16555e6..6a25e61 100644 --- a/SlidingMenuSharp/CanvasTransformer.cs +++ b/SlidingMenuSharp/CanvasTransformer.cs @@ -1,68 +1,68 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using Android.Graphics; -using Android.Views.Animations; - -namespace SlidingMenuSharp -{ - public interface ICanvasTransformer - { - /** - * Transform canvas. - * - * @param canvas the canvas - * @param percentOpen the percent open - */ - void TransformCanvas(Canvas canvas, float percentOpen); - } - - public class ZoomTransformer : ICanvasTransformer - { - public void TransformCanvas(Canvas canvas, float percentOpen) - { - var scale = (float) (percentOpen * 0.25 + 0.75); - canvas.Scale(scale, scale, canvas.Width / 2f, canvas.Height / 2f); - } - } - - public class SlideTransformer : ICanvasTransformer - { - private static readonly SlideInterpolator Interpolator = new SlideInterpolator(); - public class SlideInterpolator : Java.Lang.Object, IInterpolator - { - public float GetInterpolation(float t) - { - t -= 1.0f; - return t * t * t + 1.0f; - } - } - - public void TransformCanvas(Canvas canvas, float percentOpen) - { - canvas.Translate(0, canvas.Height * (1 - Interpolator.GetInterpolation(percentOpen))); - } - } - - public class ScaleTransformer : ICanvasTransformer - { - public void TransformCanvas(Canvas canvas, float percentOpen) - { - canvas.Scale(percentOpen, 1, 0, 0); - } - } +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using Android.Graphics; +using Android.Views.Animations; + +namespace SlidingMenuSharp +{ + public interface ICanvasTransformer + { + /** + * Transform canvas. + * + * @param canvas the canvas + * @param percentOpen the percent open + */ + void TransformCanvas(Canvas canvas, float percentOpen); + } + + public class ZoomTransformer : ICanvasTransformer + { + public void TransformCanvas(Canvas canvas, float percentOpen) + { + var scale = (float) (percentOpen * 0.25 + 0.75); + canvas.Scale(scale, scale, canvas.Width / 2f, canvas.Height / 2f); + } + } + + public class SlideTransformer : ICanvasTransformer + { + private static readonly SlideInterpolator Interpolator = new SlideInterpolator(); + public class SlideInterpolator : Java.Lang.Object, IInterpolator + { + public float GetInterpolation(float t) + { + t -= 1.0f; + return t * t * t + 1.0f; + } + } + + public void TransformCanvas(Canvas canvas, float percentOpen) + { + canvas.Translate(0, canvas.Height * (1 - Interpolator.GetInterpolation(percentOpen))); + } + } + + public class ScaleTransformer : ICanvasTransformer + { + public void TransformCanvas(Canvas canvas, float percentOpen) + { + canvas.Scale(percentOpen, 1, 0, 0); + } + } } \ No newline at end of file diff --git a/SlidingMenuSharp/CustomViewAbove.cs b/SlidingMenuSharp/CustomViewAbove.cs index 771920c..0597c49 100644 --- a/SlidingMenuSharp/CustomViewAbove.cs +++ b/SlidingMenuSharp/CustomViewAbove.cs @@ -1,870 +1,870 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using System; -using System.Collections.Generic; -using Android.Content; -using Android.Graphics; -using Android.OS; -using Android.Support.V4.View; -using Android.Util; -using Android.Views; -using Android.Views.Animations; -using Android.Widget; - -namespace SlidingMenuSharp -{ - public delegate void PageSelectedEventHandler(object sender, PageSelectedEventArgs e); - public delegate void PageScrolledEventHandler(object sender, PageScrolledEventArgs e); - public delegate void PageScrollStateChangedEventHandler(object sender, PageScrollStateChangedEventArgs e); - - public class CustomViewAbove : ViewGroup - { - private new const string Tag = "CustomViewAbove"; - - private const bool UseCache = false; - - private const int MaxSettleDuration = 600; // ms - private const int MinDistanceForFling = 25; // dips - - private readonly IInterpolator _interpolator = new CVAInterpolator(); - - private class CVAInterpolator : Java.Lang.Object, IInterpolator - { - public float GetInterpolation(float t) - { - t -= 1.0f; - return t * t * t * t * t + 1.0f; - } - } - - private View _content; - - private int _curItem; - private Scroller _scroller; - - private bool _scrollingCacheEnabled; - - private bool _scrolling; - - private bool _isBeingDragged; - private bool _isUnableToDrag; - private int _touchSlop; - private float _initialMotionX; - /** - * Position of the last motion event. - */ - private float _lastMotionX; - private float _lastMotionY; - /** - * ID of the active pointer. This is used to retain consistency during - * drags/flings if multiple pointers are used. - */ - protected int ActivePointerId = InvalidPointer; - /** - * Sentinel value for no current active pointer. - * Used by {@link #ActivePointerId}. - */ - private const int InvalidPointer = -1; - - /** - * Determines speed during touch scrolling - */ - protected VelocityTracker VelocityTracker; - private int _minimumVelocity; - protected int MaximumVelocity; - private int _flingDistance; - - private CustomViewBehind _viewBehind; - // private int mMode; - private bool _enabled = true; - - private readonly IList _ignoredViews = new List(); - - private bool _quickReturn; - private float _scrollX; - - public PageSelectedEventHandler PageSelected; - public PageScrolledEventHandler PageScrolled; - public PageScrollStateChangedEventHandler PageScrollState; - public EventHandler Closed; - public EventHandler Opened; - - - public CustomViewAbove(Context context) : this(context, null) - { - } - - public CustomViewAbove(Context context, IAttributeSet attrs) : base(context, attrs) - { - InitCustomViewAbove(); - } - - void InitCustomViewAbove() - { - TouchMode = TouchMode.Margin; - SetWillNotDraw(false); - DescendantFocusability = DescendantFocusability.AfterDescendants; - Focusable = true; - _scroller = new Scroller(Context, _interpolator); - var configuration = ViewConfiguration.Get(Context); - _touchSlop = ViewConfigurationCompat.GetScaledPagingTouchSlop(configuration); - _minimumVelocity = configuration.ScaledMinimumFlingVelocity; - MaximumVelocity = configuration.ScaledMaximumFlingVelocity; - - var density = Context.Resources.DisplayMetrics.Density; - _flingDistance = (int) (MinDistanceForFling*density); - - PageSelected += (sender, args) => - { - if (_viewBehind == null) return; - switch (args.Position) - { - case 0: - case 2: - _viewBehind.ChildrenEnabled = true; - break; - case 1: - _viewBehind.ChildrenEnabled = false; - break; - } - }; - } - - public void SetCurrentItem(int item) - { - SetCurrentItemInternal(item, true, false); - } - - public void SetCurrentItem(int item, bool smoothScroll) - { - SetCurrentItemInternal(item, smoothScroll, false); - } - - public int GetCurrentItem() - { - return _curItem; - } - - void SetCurrentItemInternal(int item, bool smoothScroll, bool always, int velocity = 0) - { - if (!always && _curItem == item) { - ScrollingCacheEnabled = false; - return; - } - - item = _viewBehind.GetMenuPage(item); - - var dispatchSelected = _curItem != item; - _curItem = item; - var destX = GetDestScrollX(_curItem); - if (dispatchSelected && PageSelected != null) - { - PageSelected(this, new PageSelectedEventArgs { Position = item }); - } - if (smoothScroll) { - SmoothScrollTo(destX, 0, velocity); - } else { - CompleteScroll(); - ScrollTo(destX, 0); - } - } - - public void AddIgnoredView(View v) - { - if (!_ignoredViews.Contains(v)) - _ignoredViews.Add(v); - } - - public void RemoveIgnoredView(View v) - { - _ignoredViews.Remove(v); - } - - public void ClearIgnoredViews() - { - _ignoredViews.Clear(); - } - - static float DistanceInfluenceForSnapDuration(float f) - { - f -= 0.5f; - f *= 0.3f*(float)Math.PI/2.0f; - return FloatMath.Sin(f); - } - - public int GetDestScrollX(int page) - { - switch (page) - { - case 0: - case 2: - return _viewBehind.GetMenuLeft(_content, page); - case 1: - return _content.Left; - } - return 0; - } - - private int LeftBound - { - get { return _viewBehind.GetAbsLeftBound(_content); } - } - - private int RightBound - { - get { return _viewBehind.GetAbsRightBound(_content); } - } - - public int ContentLeft - { - get { return _content.Left + _content.PaddingLeft; } - } - - public bool IsMenuOpen - { - get { return _curItem == 0 || _curItem == 2; } - } - - private bool IsInIgnoredView(MotionEvent ev) - { - var rect = new Rect(); - foreach (var v in _ignoredViews) - { - v.GetHitRect(rect); - if (rect.Contains((int) ev.GetX(), (int) ev.GetY())) - return true; - } - return false; - } - - public int BehindWidth - { - get { - return _viewBehind == null ? 0 : _viewBehind.BehindWidth; - } - } - - public int GetChildWidth(int i) - { - switch (i) - { - case 0: - return BehindWidth; - case 1: - return _content.Width; - default: - return 0; - } - } - - public bool IsSlidingEnabled - { - get { return _enabled; } - set { _enabled = value; } - } - - void SmoothScrollTo(int x, int y, int velocity = 0) - { - if (ChildCount == 0) - { - ScrollingCacheEnabled = false; - return; - } - - var sx = ScrollX; - var sy = ScrollY; - var dx = x - sx; - var dy = y - sy; - if (dx == 0 && dy == 0) - { - CompleteScroll(); - if (IsMenuOpen) - { - if (null != Opened) - Opened(this, EventArgs.Empty); - } - else - { - if (null != Closed) - Closed(this, EventArgs.Empty); - } - return; - } - - ScrollingCacheEnabled = true; - _scrolling = true; - - var width = BehindWidth; - var halfWidth = width / 2; - var distanceRatio = Math.Min(1f, 1.0f * Math.Abs(dx) / width); - var distance = halfWidth + halfWidth * DistanceInfluenceForSnapDuration(distanceRatio); - int duration; - velocity = Math.Abs(velocity); - if (velocity > 0) - duration = (int)(4 * Math.Round(1000 * Math.Abs(distance / velocity))); - else - { - var pageDelta = (float) Math.Abs(dx) / width; - duration = (int) ((pageDelta + 1) * 100); - } - duration = Math.Min(duration, MaxSettleDuration); - - _scroller.StartScroll(sx, sy, dx, dy, duration); - Invalidate(); - } - - public View Content - { - get { return _content; } - set - { - if (_content != null) - RemoveView(_content); - _content = value; - AddView(_content); - } - } - - public CustomViewBehind CustomViewBehind - { - set { _viewBehind = value; } - } - - protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) - { - var width = GetDefaultSize(0, widthMeasureSpec); - var height = GetDefaultSize(0, heightMeasureSpec); - SetMeasuredDimension(width, height); - - var contentWidth = GetChildMeasureSpec(widthMeasureSpec, 0, width); - var contentHeight = GetChildMeasureSpec(heightMeasureSpec, 0, height); - _content.Measure(contentWidth, contentHeight); - } - - protected override void OnSizeChanged(int w, int h, int oldw, int oldh) - { - base.OnSizeChanged(w, h, oldw, oldh); - - if (w == oldw) return; - CompleteScroll(); - ScrollTo(GetDestScrollX(_curItem), ScrollY); - } - - protected override void OnLayout(bool changed, int l, int t, int r, int b) - { - var width = r - l; - var height = b - t; - _content.Layout(0, 0, width, height); - } - - public int AboveOffset - { - set - { - _content.SetPadding(value, _content.PaddingTop, _content.PaddingRight, _content.PaddingBottom); - } - } - - public override void ComputeScroll() - { - if (!_scroller.IsFinished) - { - if (_scroller.ComputeScrollOffset()) - { - var oldX = ScrollX; - var oldY = ScrollY; - var x = _scroller.CurrX; - var y = _scroller.CurrY; - - if (oldX != x ||oldY != y) - { - ScrollTo(x, y); - OnPageScrolled(x); - } - - Invalidate(); - return; - } - } - - CompleteScroll(); - } - - protected void OnPageScrolled(int xpos) - { - var widthWithMargin = Width; - var position = xpos / widthWithMargin; - var offsetPixels = xpos % widthWithMargin; - var offset = (float)offsetPixels / widthWithMargin; - - if (null != PageScrolled) - PageScrolled(this, new PageScrolledEventArgs - { - Position = position, - PositionOffset = offset, - PositionOffsetPixels = offsetPixels - }); - } - - private void CompleteScroll() - { - var needPopulate = _scrolling; - if (needPopulate) - { - ScrollingCacheEnabled = false; - _scroller.AbortAnimation(); - var oldX = ScrollX; - var oldY = ScrollY; - var x = _scroller.CurrX; - var y = _scroller.CurrY; - if (oldX != x || oldY != y) - ScrollTo(x, y); - - if (IsMenuOpen) - { - if (null != Opened) - Opened(this, EventArgs.Empty); - } - else - { - if (null != Closed) - Closed(this, EventArgs.Empty); - } - } - _scrolling = false; - } - - public TouchMode TouchMode { get; set; } - - private bool ThisTouchAllowed(MotionEvent ev) - { - var x = (int) (ev.GetX() + _scrollX); - if (IsMenuOpen) - { - return _viewBehind.MenuOpenTouchAllowed(_content, _curItem, x); - } - switch (TouchMode) - { - case TouchMode.Fullscreen: - return !IsInIgnoredView(ev); - case TouchMode.None: - return false; - case TouchMode.Margin: - return _viewBehind.MarginTouchAllowed(_content, x); - } - return false; - } - - private bool ThisSlideAllowed(float dx) - { - var allowed = IsMenuOpen ? _viewBehind.MenuOpenSlideAllowed(dx) - : _viewBehind.MenuClosedSlideAllowed(dx); -#if DEBUG - Log.Verbose(Tag, "this slide allowed" + allowed + " dx: " + dx); -#endif - return allowed; - } - - private int GetPointerIndex(MotionEvent ev, int id) - { - var activePointerIndex = MotionEventCompat.FindPointerIndex(ev, id); - if (activePointerIndex == -1) - ActivePointerId = InvalidPointer; - return activePointerIndex; - } - - public override bool OnInterceptTouchEvent(MotionEvent ev) - { - if (!_enabled) - return false; - - var action = (int) ev.Action & MotionEventCompat.ActionMask; - -#if DEBUG - if (action == (int) MotionEventActions.Down) - Log.Verbose(Tag, "Recieved ACTION_DOWN"); -#endif - if (action == (int) MotionEventActions.Cancel || action == (int) MotionEventActions.Up || - (action != (int) MotionEventActions.Down && _isUnableToDrag)) - { - EndDrag(); - return false; - } - - switch (action) - { - case (int) MotionEventActions.Move: - DetermineDrag(ev); - break; - case (int) MotionEventActions.Down: - var index = MotionEventCompat.GetActionIndex(ev); - ActivePointerId = MotionEventCompat.GetPointerId(ev, index); - if (ActivePointerId == InvalidPointer) - break; - _lastMotionX = _initialMotionX = MotionEventCompat.GetX(ev, index); - _lastMotionY = MotionEventCompat.GetY(ev, index); - if (ThisTouchAllowed(ev)) - { - _isBeingDragged = false; - _isUnableToDrag = false; - if (IsMenuOpen && _viewBehind.MenuTouchInQuickReturn(_content, _curItem, - ev.GetX() + _scrollX)) - _quickReturn = true; - } - else - _isUnableToDrag = true; - break; - case (int) MotionEventActions.PointerUp: - OnSecondaryPointerUp(ev); - break; - } - - if (!_isBeingDragged) - { - if (VelocityTracker == null) - VelocityTracker = VelocityTracker.Obtain(); - VelocityTracker.AddMovement(ev); - } - return _isBeingDragged || _quickReturn; - } - - public override bool OnTouchEvent(MotionEvent ev) - { - if (!_enabled) - return false; - - if (!_isBeingDragged && !ThisTouchAllowed(ev)) - return false; - - if (VelocityTracker == null) - VelocityTracker = VelocityTracker.Obtain(); - VelocityTracker.AddMovement(ev); - - var action = (int)ev.Action & MotionEventCompat.ActionMask; - switch (action) - { - case (int) MotionEventActions.Down: - CompleteScroll(); - - var index = MotionEventCompat.GetActionIndex(ev); - ActivePointerId = MotionEventCompat.GetPointerId(ev, index); - _lastMotionX = _initialMotionX = ev.GetX(); - break; - case (int) MotionEventActions.Move: - if (!_isBeingDragged) - { - DetermineDrag(ev); - if (_isUnableToDrag) - return false; - } - if (_isBeingDragged) - { - var activePointerIndex = GetPointerIndex(ev, ActivePointerId); - if (ActivePointerId == InvalidPointer) - break; - var x = MotionEventCompat.GetX(ev, activePointerIndex); - var deltaX = _lastMotionX - x; - _lastMotionX = x; - var oldScrollX = ScrollX; - var scrollX = oldScrollX + deltaX; - var leftBound = LeftBound; - var rightBound = RightBound; - if (scrollX < leftBound) - scrollX = leftBound; - else if (scrollX > rightBound) - scrollX = rightBound; - _lastMotionX += scrollX - (int) scrollX; - ScrollTo((int) scrollX, ScrollY); - OnPageScrolled((int)scrollX); - } - break; - case (int) MotionEventActions.Up: - if (_isBeingDragged) - { - var velocityTracker = VelocityTracker; - velocityTracker.ComputeCurrentVelocity(1000, MaximumVelocity); - var initialVelocity = - (int) VelocityTrackerCompat.GetXVelocity(velocityTracker, ActivePointerId); - var scrollX = ScrollX; - var pageOffset = (float) (scrollX - GetDestScrollX(_curItem)) / BehindWidth; - var activePointerIndex = GetPointerIndex(ev, ActivePointerId); - if (ActivePointerId != InvalidPointer) - { - var x = MotionEventCompat.GetX(ev, activePointerIndex); - var totalDelta = (int) (x - _initialMotionX); - var nextPage = DetermineTargetPage(pageOffset, initialVelocity, totalDelta); - SetCurrentItemInternal(nextPage, true, true, initialVelocity); - } - else - SetCurrentItemInternal(_curItem, true, true, initialVelocity); - ActivePointerId = InvalidPointer; - EndDrag(); - } - else if (_quickReturn && - _viewBehind.MenuTouchInQuickReturn(_content, _curItem, ev.GetX() + _scrollX)) - { - SetCurrentItem(1); - EndDrag(); - } - break; - case (int) MotionEventActions.Cancel: - if (_isBeingDragged) - { - SetCurrentItemInternal(_curItem, true, true); - ActivePointerId = InvalidPointer; - EndDrag(); - } - break; - case MotionEventCompat.ActionPointerDown: - var indexx = MotionEventCompat.GetActionIndex(ev); - _lastMotionX = MotionEventCompat.GetX(ev, indexx); - ActivePointerId = MotionEventCompat.GetPointerId(ev, indexx); - break; - case MotionEventCompat.ActionPointerUp: - OnSecondaryPointerUp(ev); - var pointerIndex = GetPointerIndex(ev, ActivePointerId); - if (ActivePointerId == InvalidPointer) - break; - _lastMotionX = MotionEventCompat.GetX(ev, pointerIndex); - break; - } - return true; - } - - private void DetermineDrag(MotionEvent ev) - { - var activePointerId = ActivePointerId; - var pointerIndex = GetPointerIndex(ev, activePointerId); - if (activePointerId == InvalidPointer || pointerIndex == InvalidPointer) - return; - var x = MotionEventCompat.GetX(ev, pointerIndex); - var dx = x - _lastMotionX; - var xDiff = Math.Abs(dx); - var y = MotionEventCompat.GetY(ev, pointerIndex); - var dy = y - _lastMotionY; - var yDiff = Math.Abs(dy); - if (xDiff > (IsMenuOpen ? _touchSlop / 2 : _touchSlop) && xDiff > yDiff && ThisSlideAllowed(dx)) - { - StartDrag(); - _lastMotionX = x; - _lastMotionY = y; - _scrollingCacheEnabled = true; - } - else if (xDiff > _touchSlop) - _isUnableToDrag = true; - } - - public override void ScrollTo(int x, int y) - { - base.ScrollTo(x, y); - - _scrollX = x; - _viewBehind.ScrollBehindTo(_content, x, y); -#if __ANDROID_11__ - ((SlidingMenu) Parent).ManageLayers(PercentOpen); -#endif - } - - private int DetermineTargetPage(float pageOffset, int velocity, int deltaX) - { - var targetPage = _curItem; - if (Math.Abs(deltaX) > _flingDistance && Math.Abs(velocity) > _minimumVelocity) - { - if (velocity > 0 && deltaX > 0) - targetPage -= 1; - else if (velocity < 0 && deltaX < 0) - targetPage += 1; - } - else - targetPage = (int) Math.Round(_curItem + pageOffset); - return targetPage; - } - - public float PercentOpen { get { return Math.Abs(_scrollX - _content.Left) / BehindWidth; } } - - protected override void DispatchDraw(Canvas canvas) - { - base.DispatchDraw(canvas); - - _viewBehind.DrawShadow(_content, canvas); - _viewBehind.DrawFade(_content, canvas, PercentOpen); - _viewBehind.DrawSelector(_content, canvas, PercentOpen); - } - - private void OnSecondaryPointerUp(MotionEvent ev) - { -#if DEBUG - Log.Verbose(Tag, "OnSecondaryPointerUp called"); -#endif - var pointerIndex = MotionEventCompat.GetActionIndex(ev); - var pointerId = MotionEventCompat.GetPointerId(ev, pointerIndex); - if (pointerId == ActivePointerId) - { - var newPointerIndex = pointerIndex == 0 ? 1 : 0; - _lastMotionX = MotionEventCompat.GetX(ev, newPointerIndex); - ActivePointerId = MotionEventCompat.GetPointerId(ev, newPointerIndex); - if (VelocityTracker != null) - VelocityTracker.Clear(); - } - } - - private void StartDrag() - { - _isBeingDragged = true; - _quickReturn = false; - } - - private void EndDrag() - { - _quickReturn = false; - _isBeingDragged = false; - _isUnableToDrag = false; - ActivePointerId = InvalidPointer; - - if (VelocityTracker == null) return; - VelocityTracker.Recycle(); - VelocityTracker = null; - } - - private bool ScrollingCacheEnabled - { - set - { - if (_scrollingCacheEnabled != value) - { - _scrollingCacheEnabled = value; - if (UseCache) - { - var size = ChildCount; - for (var i = 0; i < size; ++i) - { - var child = GetChildAt(i); - if (child.Visibility != ViewStates.Gone) - child.DrawingCacheEnabled = value; - } - } - } - } - } - - protected bool CanScroll(View v, bool checkV, int dx, int x, int y) - { - var viewGroup = v as ViewGroup; - if (viewGroup != null) - { - var scrollX = v.ScrollX; - var scrollY = v.ScrollY; - var count = viewGroup.ChildCount; - - for (var i = count - 1; i >= 0; i--) - { - var child = viewGroup.GetChildAt(i); - if (x + scrollX >= child.Left && x + scrollX < child.Right && - y + scrollY >= child.Top && y + scrollY < child.Bottom && - CanScroll(child, true, dx, x + scrollX - child.Left, y + scrollY - child.Top)) - return true; - } - } - return checkV && ViewCompat.CanScrollHorizontally(v, -dx); - } - - public override bool DispatchKeyEvent(KeyEvent e) - { - return base.DispatchKeyEvent(e) || ExecuteKeyEvent(e); - } - - public bool ExecuteKeyEvent(KeyEvent ev) - { - var handled = false; - if (ev.Action == KeyEventActions.Down) - { - switch (ev.KeyCode) - { - case Keycode.DpadLeft: - handled = ArrowScroll(FocusSearchDirection.Left); - break; - case Keycode.DpadRight: - handled = ArrowScroll(FocusSearchDirection.Right); - break; - case Keycode.Tab: - if ((int)Build.VERSION.SdkInt >= 11) - { - if (KeyEventCompat.HasNoModifiers(ev)) - handled = ArrowScroll(FocusSearchDirection.Forward); -#if __ANDROID_11__ - else if (ev.IsMetaPressed) - handled = ArrowScroll(FocusSearchDirection.Backward); -#endif - } - break; - } - } - return handled; - } - - public bool ArrowScroll(FocusSearchDirection direction) - { - var currentFocused = FindFocus(); - - var handled = false; - - var nextFocused = FocusFinder.Instance.FindNextFocus(this, currentFocused == this ? null : currentFocused, direction); - if (nextFocused != null && nextFocused != currentFocused) - { - if (direction == FocusSearchDirection.Left) - handled = nextFocused.RequestFocus(); - else if (direction == FocusSearchDirection.Right) - { - if (currentFocused != null && nextFocused.Left <= currentFocused.Left) - handled = PageRight(); - else - handled = nextFocused.RequestFocus(); - } - } - else if (direction == FocusSearchDirection.Left || direction == FocusSearchDirection.Backward) - handled = PageLeft(); - else if (direction == FocusSearchDirection.Right || direction == FocusSearchDirection.Forward) - handled = PageRight(); - - if (handled) - PlaySoundEffect(SoundEffectConstants.GetContantForFocusDirection(direction)); - - return handled; - } - - bool PageLeft() - { - if (_curItem > 0) - { - SetCurrentItem(_curItem-1, true); - return true; - } - return false; - } - - bool PageRight() - { - if (_curItem < 1) - { - SetCurrentItem(_curItem+1, true); - return true; - } - return false; - } - } -} +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using System; +using System.Collections.Generic; +using Android.Content; +using Android.Graphics; +using Android.OS; +using Android.Support.V4.View; +using Android.Util; +using Android.Views; +using Android.Views.Animations; +using Android.Widget; + +namespace SlidingMenuSharp +{ + public delegate void PageSelectedEventHandler(object sender, PageSelectedEventArgs e); + public delegate void PageScrolledEventHandler(object sender, PageScrolledEventArgs e); + public delegate void PageScrollStateChangedEventHandler(object sender, PageScrollStateChangedEventArgs e); + + public class CustomViewAbove : ViewGroup + { + private new const string Tag = "CustomViewAbove"; + + private const bool UseCache = false; + + private const int MaxSettleDuration = 600; // ms + private const int MinDistanceForFling = 25; // dips + + private readonly IInterpolator _interpolator = new CVAInterpolator(); + + private class CVAInterpolator : Java.Lang.Object, IInterpolator + { + public float GetInterpolation(float t) + { + t -= 1.0f; + return t * t * t * t * t + 1.0f; + } + } + + private View _content; + + private int _curItem; + private Scroller _scroller; + + private bool _scrollingCacheEnabled; + + private bool _scrolling; + + private bool _isBeingDragged; + private bool _isUnableToDrag; + private int _touchSlop; + private float _initialMotionX; + /** + * Position of the last motion event. + */ + private float _lastMotionX; + private float _lastMotionY; + /** + * ID of the active pointer. This is used to retain consistency during + * drags/flings if multiple pointers are used. + */ + protected int ActivePointerId = InvalidPointer; + /** + * Sentinel value for no current active pointer. + * Used by {@link #ActivePointerId}. + */ + private const int InvalidPointer = -1; + + /** + * Determines speed during touch scrolling + */ + protected VelocityTracker VelocityTracker; + private int _minimumVelocity; + protected int MaximumVelocity; + private int _flingDistance; + + private CustomViewBehind _viewBehind; + // private int mMode; + private bool _enabled = true; + + private readonly IList _ignoredViews = new List(); + + private bool _quickReturn; + private float _scrollX; + + public PageSelectedEventHandler PageSelected; + public PageScrolledEventHandler PageScrolled; + public PageScrollStateChangedEventHandler PageScrollState; + public EventHandler Closed; + public EventHandler Opened; + + + public CustomViewAbove(Context context) : this(context, null) + { + } + + public CustomViewAbove(Context context, IAttributeSet attrs) : base(context, attrs) + { + InitCustomViewAbove(); + } + + void InitCustomViewAbove() + { + TouchMode = TouchMode.Margin; + SetWillNotDraw(false); + DescendantFocusability = DescendantFocusability.AfterDescendants; + Focusable = true; + _scroller = new Scroller(Context, _interpolator); + var configuration = ViewConfiguration.Get(Context); + _touchSlop = ViewConfigurationCompat.GetScaledPagingTouchSlop(configuration); + _minimumVelocity = configuration.ScaledMinimumFlingVelocity; + MaximumVelocity = configuration.ScaledMaximumFlingVelocity; + + var density = Context.Resources.DisplayMetrics.Density; + _flingDistance = (int) (MinDistanceForFling*density); + + PageSelected += (sender, args) => + { + if (_viewBehind == null) return; + switch (args.Position) + { + case 0: + case 2: + _viewBehind.ChildrenEnabled = true; + break; + case 1: + _viewBehind.ChildrenEnabled = false; + break; + } + }; + } + + public void SetCurrentItem(int item) + { + SetCurrentItemInternal(item, true, false); + } + + public void SetCurrentItem(int item, bool smoothScroll) + { + SetCurrentItemInternal(item, smoothScroll, false); + } + + public int GetCurrentItem() + { + return _curItem; + } + + void SetCurrentItemInternal(int item, bool smoothScroll, bool always, int velocity = 0) + { + if (!always && _curItem == item) { + ScrollingCacheEnabled = false; + return; + } + + item = _viewBehind.GetMenuPage(item); + + var dispatchSelected = _curItem != item; + _curItem = item; + var destX = GetDestScrollX(_curItem); + if (dispatchSelected && PageSelected != null) + { + PageSelected(this, new PageSelectedEventArgs { Position = item }); + } + if (smoothScroll) { + SmoothScrollTo(destX, 0, velocity); + } else { + CompleteScroll(); + ScrollTo(destX, 0); + } + } + + public void AddIgnoredView(View v) + { + if (!_ignoredViews.Contains(v)) + _ignoredViews.Add(v); + } + + public void RemoveIgnoredView(View v) + { + _ignoredViews.Remove(v); + } + + public void ClearIgnoredViews() + { + _ignoredViews.Clear(); + } + + static float DistanceInfluenceForSnapDuration(float f) + { + f -= 0.5f; + f *= 0.3f*(float)Math.PI/2.0f; + return FloatMath.Sin(f); + } + + public int GetDestScrollX(int page) + { + switch (page) + { + case 0: + case 2: + return _viewBehind.GetMenuLeft(_content, page); + case 1: + return _content.Left; + } + return 0; + } + + private int LeftBound + { + get { return _viewBehind.GetAbsLeftBound(_content); } + } + + private int RightBound + { + get { return _viewBehind.GetAbsRightBound(_content); } + } + + public int ContentLeft + { + get { return _content.Left + _content.PaddingLeft; } + } + + public bool IsMenuOpen + { + get { return _curItem == 0 || _curItem == 2; } + } + + private bool IsInIgnoredView(MotionEvent ev) + { + var rect = new Rect(); + foreach (var v in _ignoredViews) + { + v.GetHitRect(rect); + if (rect.Contains((int) ev.GetX(), (int) ev.GetY())) + return true; + } + return false; + } + + public int BehindWidth + { + get { + return _viewBehind == null ? 0 : _viewBehind.BehindWidth; + } + } + + public int GetChildWidth(int i) + { + switch (i) + { + case 0: + return BehindWidth; + case 1: + return _content.Width; + default: + return 0; + } + } + + public bool IsSlidingEnabled + { + get { return _enabled; } + set { _enabled = value; } + } + + void SmoothScrollTo(int x, int y, int velocity = 0) + { + if (ChildCount == 0) + { + ScrollingCacheEnabled = false; + return; + } + + var sx = ScrollX; + var sy = ScrollY; + var dx = x - sx; + var dy = y - sy; + if (dx == 0 && dy == 0) + { + CompleteScroll(); + if (IsMenuOpen) + { + if (null != Opened) + Opened(this, EventArgs.Empty); + } + else + { + if (null != Closed) + Closed(this, EventArgs.Empty); + } + return; + } + + ScrollingCacheEnabled = true; + _scrolling = true; + + var width = BehindWidth; + var halfWidth = width / 2; + var distanceRatio = Math.Min(1f, 1.0f * Math.Abs(dx) / width); + var distance = halfWidth + halfWidth * DistanceInfluenceForSnapDuration(distanceRatio); + int duration; + velocity = Math.Abs(velocity); + if (velocity > 0) + duration = (int)(4 * Math.Round(1000 * Math.Abs(distance / velocity))); + else + { + var pageDelta = (float) Math.Abs(dx) / width; + duration = (int) ((pageDelta + 1) * 100); + } + duration = Math.Min(duration, MaxSettleDuration); + + _scroller.StartScroll(sx, sy, dx, dy, duration); + Invalidate(); + } + + public View Content + { + get { return _content; } + set + { + if (_content != null) + RemoveView(_content); + _content = value; + AddView(_content); + } + } + + public CustomViewBehind CustomViewBehind + { + set { _viewBehind = value; } + } + + protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + var width = GetDefaultSize(0, widthMeasureSpec); + var height = GetDefaultSize(0, heightMeasureSpec); + SetMeasuredDimension(width, height); + + var contentWidth = GetChildMeasureSpec(widthMeasureSpec, 0, width); + var contentHeight = GetChildMeasureSpec(heightMeasureSpec, 0, height); + _content.Measure(contentWidth, contentHeight); + } + + protected override void OnSizeChanged(int w, int h, int oldw, int oldh) + { + base.OnSizeChanged(w, h, oldw, oldh); + + if (w == oldw) return; + CompleteScroll(); + ScrollTo(GetDestScrollX(_curItem), ScrollY); + } + + protected override void OnLayout(bool changed, int l, int t, int r, int b) + { + var width = r - l; + var height = b - t; + _content.Layout(0, 0, width, height); + } + + public int AboveOffset + { + set + { + _content.SetPadding(value, _content.PaddingTop, _content.PaddingRight, _content.PaddingBottom); + } + } + + public override void ComputeScroll() + { + if (!_scroller.IsFinished) + { + if (_scroller.ComputeScrollOffset()) + { + var oldX = ScrollX; + var oldY = ScrollY; + var x = _scroller.CurrX; + var y = _scroller.CurrY; + + if (oldX != x ||oldY != y) + { + ScrollTo(x, y); + OnPageScrolled(x); + } + + Invalidate(); + return; + } + } + + CompleteScroll(); + } + + protected void OnPageScrolled(int xpos) + { + var widthWithMargin = Width; + var position = xpos / widthWithMargin; + var offsetPixels = xpos % widthWithMargin; + var offset = (float)offsetPixels / widthWithMargin; + + if (null != PageScrolled) + PageScrolled(this, new PageScrolledEventArgs + { + Position = position, + PositionOffset = offset, + PositionOffsetPixels = offsetPixels + }); + } + + private void CompleteScroll() + { + var needPopulate = _scrolling; + if (needPopulate) + { + ScrollingCacheEnabled = false; + _scroller.AbortAnimation(); + var oldX = ScrollX; + var oldY = ScrollY; + var x = _scroller.CurrX; + var y = _scroller.CurrY; + if (oldX != x || oldY != y) + ScrollTo(x, y); + + if (IsMenuOpen) + { + if (null != Opened) + Opened(this, EventArgs.Empty); + } + else + { + if (null != Closed) + Closed(this, EventArgs.Empty); + } + } + _scrolling = false; + } + + public TouchMode TouchMode { get; set; } + + private bool ThisTouchAllowed(MotionEvent ev) + { + var x = (int) (ev.GetX() + _scrollX); + if (IsMenuOpen) + { + return _viewBehind.MenuOpenTouchAllowed(_content, _curItem, x); + } + switch (TouchMode) + { + case TouchMode.Fullscreen: + return !IsInIgnoredView(ev); + case TouchMode.None: + return false; + case TouchMode.Margin: + return _viewBehind.MarginTouchAllowed(_content, x); + } + return false; + } + + private bool ThisSlideAllowed(float dx) + { + var allowed = IsMenuOpen ? _viewBehind.MenuOpenSlideAllowed(dx) + : _viewBehind.MenuClosedSlideAllowed(dx); +#if DEBUG + Log.Verbose(Tag, "this slide allowed" + allowed + " dx: " + dx); +#endif + return allowed; + } + + private int GetPointerIndex(MotionEvent ev, int id) + { + var activePointerIndex = MotionEventCompat.FindPointerIndex(ev, id); + if (activePointerIndex == -1) + ActivePointerId = InvalidPointer; + return activePointerIndex; + } + + public override bool OnInterceptTouchEvent(MotionEvent ev) + { + if (!_enabled) + return false; + + var action = (int) ev.Action & MotionEventCompat.ActionMask; + +#if DEBUG + if (action == (int) MotionEventActions.Down) + Log.Verbose(Tag, "Recieved ACTION_DOWN"); +#endif + if (action == (int) MotionEventActions.Cancel || action == (int) MotionEventActions.Up || + (action != (int) MotionEventActions.Down && _isUnableToDrag)) + { + EndDrag(); + return false; + } + + switch (action) + { + case (int) MotionEventActions.Move: + DetermineDrag(ev); + break; + case (int) MotionEventActions.Down: + var index = MotionEventCompat.GetActionIndex(ev); + ActivePointerId = MotionEventCompat.GetPointerId(ev, index); + if (ActivePointerId == InvalidPointer) + break; + _lastMotionX = _initialMotionX = MotionEventCompat.GetX(ev, index); + _lastMotionY = MotionEventCompat.GetY(ev, index); + if (ThisTouchAllowed(ev)) + { + _isBeingDragged = false; + _isUnableToDrag = false; + if (IsMenuOpen && _viewBehind.MenuTouchInQuickReturn(_content, _curItem, + ev.GetX() + _scrollX)) + _quickReturn = true; + } + else + _isUnableToDrag = true; + break; + case (int) MotionEventActions.PointerUp: + OnSecondaryPointerUp(ev); + break; + } + + if (!_isBeingDragged) + { + if (VelocityTracker == null) + VelocityTracker = VelocityTracker.Obtain(); + VelocityTracker.AddMovement(ev); + } + return _isBeingDragged || _quickReturn; + } + + public override bool OnTouchEvent(MotionEvent ev) + { + if (!_enabled) + return false; + + if (!_isBeingDragged && !ThisTouchAllowed(ev)) + return false; + + if (VelocityTracker == null) + VelocityTracker = VelocityTracker.Obtain(); + VelocityTracker.AddMovement(ev); + + var action = (int)ev.Action & MotionEventCompat.ActionMask; + switch (action) + { + case (int) MotionEventActions.Down: + CompleteScroll(); + + var index = MotionEventCompat.GetActionIndex(ev); + ActivePointerId = MotionEventCompat.GetPointerId(ev, index); + _lastMotionX = _initialMotionX = ev.GetX(); + break; + case (int) MotionEventActions.Move: + if (!_isBeingDragged) + { + DetermineDrag(ev); + if (_isUnableToDrag) + return false; + } + if (_isBeingDragged) + { + var activePointerIndex = GetPointerIndex(ev, ActivePointerId); + if (ActivePointerId == InvalidPointer) + break; + var x = MotionEventCompat.GetX(ev, activePointerIndex); + var deltaX = _lastMotionX - x; + _lastMotionX = x; + var oldScrollX = ScrollX; + var scrollX = oldScrollX + deltaX; + var leftBound = LeftBound; + var rightBound = RightBound; + if (scrollX < leftBound) + scrollX = leftBound; + else if (scrollX > rightBound) + scrollX = rightBound; + _lastMotionX += scrollX - (int) scrollX; + ScrollTo((int) scrollX, ScrollY); + OnPageScrolled((int)scrollX); + } + break; + case (int) MotionEventActions.Up: + if (_isBeingDragged) + { + var velocityTracker = VelocityTracker; + velocityTracker.ComputeCurrentVelocity(1000, MaximumVelocity); + var initialVelocity = + (int) VelocityTrackerCompat.GetXVelocity(velocityTracker, ActivePointerId); + var scrollX = ScrollX; + var pageOffset = (float) (scrollX - GetDestScrollX(_curItem)) / BehindWidth; + var activePointerIndex = GetPointerIndex(ev, ActivePointerId); + if (ActivePointerId != InvalidPointer) + { + var x = MotionEventCompat.GetX(ev, activePointerIndex); + var totalDelta = (int) (x - _initialMotionX); + var nextPage = DetermineTargetPage(pageOffset, initialVelocity, totalDelta); + SetCurrentItemInternal(nextPage, true, true, initialVelocity); + } + else + SetCurrentItemInternal(_curItem, true, true, initialVelocity); + ActivePointerId = InvalidPointer; + EndDrag(); + } + else if (_quickReturn && + _viewBehind.MenuTouchInQuickReturn(_content, _curItem, ev.GetX() + _scrollX)) + { + SetCurrentItem(1); + EndDrag(); + } + break; + case (int) MotionEventActions.Cancel: + if (_isBeingDragged) + { + SetCurrentItemInternal(_curItem, true, true); + ActivePointerId = InvalidPointer; + EndDrag(); + } + break; + case MotionEventCompat.ActionPointerDown: + var indexx = MotionEventCompat.GetActionIndex(ev); + _lastMotionX = MotionEventCompat.GetX(ev, indexx); + ActivePointerId = MotionEventCompat.GetPointerId(ev, indexx); + break; + case MotionEventCompat.ActionPointerUp: + OnSecondaryPointerUp(ev); + var pointerIndex = GetPointerIndex(ev, ActivePointerId); + if (ActivePointerId == InvalidPointer) + break; + _lastMotionX = MotionEventCompat.GetX(ev, pointerIndex); + break; + } + return true; + } + + private void DetermineDrag(MotionEvent ev) + { + var activePointerId = ActivePointerId; + var pointerIndex = GetPointerIndex(ev, activePointerId); + if (activePointerId == InvalidPointer || pointerIndex == InvalidPointer) + return; + var x = MotionEventCompat.GetX(ev, pointerIndex); + var dx = x - _lastMotionX; + var xDiff = Math.Abs(dx); + var y = MotionEventCompat.GetY(ev, pointerIndex); + var dy = y - _lastMotionY; + var yDiff = Math.Abs(dy); + if (xDiff > (IsMenuOpen ? _touchSlop / 2 : _touchSlop) && xDiff > yDiff && ThisSlideAllowed(dx)) + { + StartDrag(); + _lastMotionX = x; + _lastMotionY = y; + _scrollingCacheEnabled = true; + } + else if (xDiff > _touchSlop) + _isUnableToDrag = true; + } + + public override void ScrollTo(int x, int y) + { + base.ScrollTo(x, y); + + _scrollX = x; + _viewBehind.ScrollBehindTo(_content, x, y); +#if __ANDROID_11__ + ((SlidingMenu) Parent).ManageLayers(PercentOpen); +#endif + } + + private int DetermineTargetPage(float pageOffset, int velocity, int deltaX) + { + var targetPage = _curItem; + if (Math.Abs(deltaX) > _flingDistance && Math.Abs(velocity) > _minimumVelocity) + { + if (velocity > 0 && deltaX > 0) + targetPage -= 1; + else if (velocity < 0 && deltaX < 0) + targetPage += 1; + } + else + targetPage = (int) Math.Round(_curItem + pageOffset); + return targetPage; + } + + public float PercentOpen { get { return Math.Abs(_scrollX - _content.Left) / BehindWidth; } } + + protected override void DispatchDraw(Canvas canvas) + { + base.DispatchDraw(canvas); + + _viewBehind.DrawShadow(_content, canvas); + _viewBehind.DrawFade(_content, canvas, PercentOpen); + _viewBehind.DrawSelector(_content, canvas, PercentOpen); + } + + private void OnSecondaryPointerUp(MotionEvent ev) + { +#if DEBUG + Log.Verbose(Tag, "OnSecondaryPointerUp called"); +#endif + var pointerIndex = MotionEventCompat.GetActionIndex(ev); + var pointerId = MotionEventCompat.GetPointerId(ev, pointerIndex); + if (pointerId == ActivePointerId) + { + var newPointerIndex = pointerIndex == 0 ? 1 : 0; + _lastMotionX = MotionEventCompat.GetX(ev, newPointerIndex); + ActivePointerId = MotionEventCompat.GetPointerId(ev, newPointerIndex); + if (VelocityTracker != null) + VelocityTracker.Clear(); + } + } + + private void StartDrag() + { + _isBeingDragged = true; + _quickReturn = false; + } + + private void EndDrag() + { + _quickReturn = false; + _isBeingDragged = false; + _isUnableToDrag = false; + ActivePointerId = InvalidPointer; + + if (VelocityTracker == null) return; + VelocityTracker.Recycle(); + VelocityTracker = null; + } + + private bool ScrollingCacheEnabled + { + set + { + if (_scrollingCacheEnabled != value) + { + _scrollingCacheEnabled = value; + if (UseCache) + { + var size = ChildCount; + for (var i = 0; i < size; ++i) + { + var child = GetChildAt(i); + if (child.Visibility != ViewStates.Gone) + child.DrawingCacheEnabled = value; + } + } + } + } + } + + protected bool CanScroll(View v, bool checkV, int dx, int x, int y) + { + var viewGroup = v as ViewGroup; + if (viewGroup != null) + { + var scrollX = v.ScrollX; + var scrollY = v.ScrollY; + var count = viewGroup.ChildCount; + + for (var i = count - 1; i >= 0; i--) + { + var child = viewGroup.GetChildAt(i); + if (x + scrollX >= child.Left && x + scrollX < child.Right && + y + scrollY >= child.Top && y + scrollY < child.Bottom && + CanScroll(child, true, dx, x + scrollX - child.Left, y + scrollY - child.Top)) + return true; + } + } + return checkV && ViewCompat.CanScrollHorizontally(v, -dx); + } + + public override bool DispatchKeyEvent(KeyEvent e) + { + return base.DispatchKeyEvent(e) || ExecuteKeyEvent(e); + } + + public bool ExecuteKeyEvent(KeyEvent ev) + { + var handled = false; + if (ev.Action == KeyEventActions.Down) + { + switch (ev.KeyCode) + { + case Keycode.DpadLeft: + handled = ArrowScroll(FocusSearchDirection.Left); + break; + case Keycode.DpadRight: + handled = ArrowScroll(FocusSearchDirection.Right); + break; + case Keycode.Tab: + if ((int)Build.VERSION.SdkInt >= 11) + { + if (ev.HasNoModifiers) + handled = ArrowScroll(FocusSearchDirection.Forward); +#if __ANDROID_11__ + else if (ev.IsMetaPressed) + handled = ArrowScroll(FocusSearchDirection.Backward); +#endif + } + break; + } + } + return handled; + } + + public bool ArrowScroll(FocusSearchDirection direction) + { + var currentFocused = FindFocus(); + + var handled = false; + + var nextFocused = FocusFinder.Instance.FindNextFocus(this, currentFocused == this ? null : currentFocused, direction); + if (nextFocused != null && nextFocused != currentFocused) + { + if (direction == FocusSearchDirection.Left) + handled = nextFocused.RequestFocus(); + else if (direction == FocusSearchDirection.Right) + { + if (currentFocused != null && nextFocused.Left <= currentFocused.Left) + handled = PageRight(); + else + handled = nextFocused.RequestFocus(); + } + } + else if (direction == FocusSearchDirection.Left || direction == FocusSearchDirection.Backward) + handled = PageLeft(); + else if (direction == FocusSearchDirection.Right || direction == FocusSearchDirection.Forward) + handled = PageRight(); + + if (handled) + PlaySoundEffect(SoundEffectConstants.GetContantForFocusDirection(direction)); + + return handled; + } + + bool PageLeft() + { + if (_curItem > 0) + { + SetCurrentItem(_curItem-1, true); + return true; + } + return false; + } + + bool PageRight() + { + if (_curItem < 1) + { + SetCurrentItem(_curItem+1, true); + return true; + } + return false; + } + } +} diff --git a/SlidingMenuSharp/CustomViewBehind.cs b/SlidingMenuSharp/CustomViewBehind.cs index 231dff2..7ad78f7 100644 --- a/SlidingMenuSharp/CustomViewBehind.cs +++ b/SlidingMenuSharp/CustomViewBehind.cs @@ -1,502 +1,502 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using System; -using Android.Content; -using Android.Graphics; -using Android.Graphics.Drawables; -using Android.Util; -using Android.Views; -using Math = System.Math; - -namespace SlidingMenuSharp -{ - public sealed class CustomViewBehind : ViewGroup - { - private new const string Tag = "CustomViewBehind"; - - private const int MARGIN_THRESHOLD = 48; - - private View _content; - private View _secondaryContent; - private int _widthOffset; - private ICanvasTransformer _transformer; - private MenuMode _mode; - private readonly Paint _fadePaint = new Paint(); - private Drawable _shadowDrawable; - private Drawable _secondaryShadowDrawable; - private int _shadowWidth; - private float _fadeDegree; - private Bitmap _selectorDrawable; - private View _selectedView; - - public CustomViewBehind(Context context) - : this(context, null) - { - } - - public CustomViewBehind(Context context, IAttributeSet attrs) - : base(context, attrs) - { - TouchMode = TouchMode.Margin; - MarginThreshold = - (int) TypedValue.ApplyDimension(ComplexUnitType.Dip, MARGIN_THRESHOLD, Resources.DisplayMetrics); - } - - public CustomViewAbove CustomViewAbove { get; set; } - - public ICanvasTransformer CanvasTransformer - { - set { _transformer = value; } - } - - public int WidthOffset - { - get { return _widthOffset; } - set - { - _widthOffset = value; - RequestLayout(); - } - } - - public int MarginThreshold { get; set; } - - public int BehindWidth - { - get { return _content.Width; } - } - - public View Content - { - get { return _content; } - set - { - if (_content != null) - RemoveView(_content); - _content = value; - AddView(_content); - } - } - - public View SecondaryContent - { - get { return _secondaryContent; } - set - { - if (_secondaryContent != null) - RemoveView(_secondaryContent); - _secondaryContent = value; - AddView(_secondaryContent); - } - } - - public bool ChildrenEnabled { get; set; } - - public override void ScrollTo(int x, int y) - { - base.ScrollTo(x, y); - if (_transformer != null) - Invalidate(); - } - - public override bool OnInterceptTouchEvent(MotionEvent ev) - { - return !ChildrenEnabled; - } - - public override bool OnTouchEvent(MotionEvent e) - { - return !ChildrenEnabled; - } - - protected override void DispatchDraw(Canvas canvas) - { - if (_transformer != null) - { - canvas.Save(); - _transformer.TransformCanvas(canvas, CustomViewAbove.PercentOpen); - base.DispatchDraw(canvas); - canvas.Restore(); - } - else - base.DispatchDraw(canvas); - } - - protected override void OnLayout(bool changed, int l, int t, int r, int b) - { - var width = r - l; - var height = b - t; - Content.Layout(0, 0, width - _widthOffset, height); - if (SecondaryContent != null) - SecondaryContent.Layout(0, 0, width - _widthOffset, height); - } - - protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) - { - var width = GetDefaultSize(0, widthMeasureSpec); - var height = GetDefaultSize(0, heightMeasureSpec); - SetMeasuredDimension(width, height); - var contentWidth = GetChildMeasureSpec(widthMeasureSpec, 0, width - _widthOffset); - var contentHeight = GetChildMeasureSpec(heightMeasureSpec, 0, height); - Content.Measure(contentWidth, contentHeight); - if (SecondaryContent != null) - SecondaryContent.Measure(contentWidth, contentHeight); - } - - public MenuMode Mode - { - get { return _mode; } - set - { - if (value == MenuMode.Left || value == MenuMode.Right) - { - if (_content != null) - _content.Visibility = ViewStates.Visible; - if (_secondaryContent != null) - _secondaryContent.Visibility = ViewStates.Invisible; - } - _mode = value; - } - } - - public float ScrollScale { get; set; } - - public Drawable ShadowDrawable - { - get { return _shadowDrawable; } - set - { - _shadowDrawable = value; - Invalidate(); - } - } - - public Drawable SecondaryShadowDrawable - { - get { return _secondaryShadowDrawable; } - set - { - _secondaryShadowDrawable = value; - Invalidate(); - } - } - - public int ShadowWidth - { - get { return _shadowWidth; } - set - { - _shadowWidth = value; - Invalidate(); - } - } - - public bool FadeEnabled { get; set; } - - public float FadeDegree - { - get { return _fadeDegree; } - set - { - if (value > 1.0f || value < 0.0f) - throw new ArgumentOutOfRangeException("value", "The BehindFadeDegree must be between 0.0f and 1.0f"); - _fadeDegree = value; - } - } - - public int GetMenuPage(int page) - { - page = (page > 1) ? 2 : ((page < 1) ? 0 : page); - if (Mode == MenuMode.Left && page > 1) - return 0; - if (Mode == MenuMode.Right && page < 1) - return 2; - return page; - } - - public void ScrollBehindTo(View content, int x, int y) - { - var vis = ViewStates.Visible; - switch (Mode) - { - case MenuMode.Left: - if (x >= content.Left) - vis = ViewStates.Invisible; - ScrollTo((int)((x + BehindWidth) * ScrollScale), y); - break; - case MenuMode.Right: - if (x <= content.Left) - vis = ViewStates.Invisible; - ScrollTo((int)(BehindWidth - Width + (x - BehindWidth) * ScrollScale), y); - break; - case MenuMode.LeftRight: - Content.Visibility = x >= content.Left ? ViewStates.Invisible : ViewStates.Visible; - SecondaryContent.Visibility = x <= content.Left ? ViewStates.Invisible : ViewStates.Visible; - vis = x == 0 ? ViewStates.Invisible : ViewStates.Visible; - if (x <= content.Left) - ScrollTo((int)((x+BehindWidth)*ScrollScale), y); - else - ScrollTo((int)(BehindWidth - Width + (x-BehindWidth)*ScrollScale), y); - break; - } - if (vis == ViewStates.Invisible) - Log.Verbose(Tag, "behind INVISIBLE"); - Visibility = vis; - } - - public int GetMenuLeft(View content, int page) - { - switch (Mode) - { - case MenuMode.Left: - switch (page) - { - case 0: - return content.Left - BehindWidth; - case 2: - return content.Left; - } - break; - case MenuMode.Right: - switch (page) - { - case 0: - return content.Left; - case 2: - return content.Left + BehindWidth; - } - break; - case MenuMode.LeftRight: - switch (page) - { - case 0: - return content.Left - BehindWidth; - case 2: - return content.Left + BehindWidth; - } - break; - } - return content.Left; - } - - public int GetAbsLeftBound(View content) - { - if (Mode == MenuMode.Left || Mode == MenuMode.LeftRight) - return content.Left - BehindWidth; - return Mode == MenuMode.Right ? content.Left : 0; - } - - public int GetAbsRightBound(View content) - { - if (Mode == MenuMode.Right || Mode == MenuMode.LeftRight) - return content.Left + BehindWidth; - return Mode == MenuMode.Left ? content.Left : 0; - } - - public bool MarginTouchAllowed(View content, int x) - { - var left = content.Left; - var right = content.Right; - if (Mode == MenuMode.Left) - return (x >= left && x <= MarginThreshold + left); - if (Mode == MenuMode.Right) - return (x <= right && x >= right - MarginThreshold); - if (Mode == MenuMode.LeftRight) - return (x >= left && x <= MarginThreshold + left) || - (x <= right && x >= right - MarginThreshold); - return false; - } - - public TouchMode TouchMode { get; set; } - - public bool MenuOpenTouchAllowed(View content, int currPage, float x) - { - switch (TouchMode) - { - case TouchMode.Fullscreen: - return true; - case TouchMode.Margin: - return MenuTouchInQuickReturn(content, currPage, x); - } - return false; - } - - public bool MenuTouchInQuickReturn(View content, int currPage, float x) - { - if (Mode == MenuMode.Left || (Mode == MenuMode.LeftRight && currPage == 0)) - return x >= content.Left; - if (Mode == MenuMode.Right || (Mode == MenuMode.LeftRight && currPage == 2)) - return x <= content.Right; - return false; - } - - public bool MenuClosedSlideAllowed(float dx) - { - switch (Mode) - { - case MenuMode.Left: - return dx > 0; - case MenuMode.Right: - return dx < 0; - case MenuMode.LeftRight: - return true; - } - return false; - } - - public bool MenuOpenSlideAllowed(float dx) - { - switch (Mode) - { - case MenuMode.Left: - return dx < 0; - case MenuMode.Right: - return dx > 0; - case MenuMode.LeftRight: - return true; - } - return false; - } - - public void DrawShadow(View content, Canvas canvas) - { - if (ShadowDrawable == null || ShadowWidth <= 0) return; - var left = 0; - switch (Mode) - { - case MenuMode.Left: - left = content.Left - ShadowWidth; - break; - case MenuMode.Right: - left = content.Right; - break; - case MenuMode.LeftRight: - if (SecondaryShadowDrawable != null) - { - left = content.Right; - SecondaryShadowDrawable.SetBounds(left, 0, left + ShadowWidth, Height); - SecondaryShadowDrawable.Draw(canvas); - } - left = content.Left - ShadowWidth; - break; - } - ShadowDrawable.SetBounds(left, 0, left + ShadowWidth, Height); - ShadowDrawable.Draw(canvas); - } - - public void DrawFade(View content, Canvas canvas, float openPercent) - { - if (!FadeEnabled) return; - - var alpha = (int) (FadeDegree * 255 * Math.Abs(1 - openPercent)); - _fadePaint.Color = Color.Argb(alpha, 0, 0, 0); - var left = 0; - var right = 0; - switch (Mode) - { - case MenuMode.Left: - left = content.Left - BehindWidth; - right = content.Left; - break; - case MenuMode.Right: - left = content.Right; - right = content.Right + BehindWidth; - break; - case MenuMode.LeftRight: - left = content.Left - BehindWidth; - right = content.Left; - canvas.DrawRect(left, 0, right, Height, _fadePaint); - left = content.Right; - right = content.Right + BehindWidth; - break; - } - canvas.DrawRect(left, 0, right, Height, _fadePaint); - } - - public void DrawSelector(View content, Canvas canvas, float openPercent) - { - if (!SelectorEnabled) return; - if (_selectorDrawable != null && SelectedView != null) - { - var tag = (string)SelectedView.GetTag(Resource.Id.selected_view); - if (tag.Equals(Tag + "SelectedView")) - { - canvas.Save(); - int left, right; - var offset = (int)(SelectorBitmap.Width * openPercent); - if (Mode == MenuMode.Left) - { - right = content.Left; - left = right - offset; - canvas.ClipRect(left, 0, right, Height); - canvas.DrawBitmap(SelectorBitmap, left, SelectorTop, null); - } - else if (Mode == MenuMode.Right) - { - left = content.Right; - right = left + offset; - canvas.ClipRect(left, 0, right, Height); - canvas.DrawBitmap(SelectorBitmap, right - SelectorBitmap.Width, SelectorTop, null); - } - canvas.Restore(); - } - } - } - - public bool SelectorEnabled { get; set; } - - public View SelectedView - { - get { return _selectedView; } - set - { - if (_selectedView != null) - { - _selectedView.SetTag(Resource.Id.selected_view, null); - _selectedView = null; - } - if (value != null && value.Parent != null) - { - _selectedView = value; - _selectedView.SetTag(Resource.Id.selected_view, Tag+"SelectedView"); - Invalidate(); - } - } - } - - private int SelectorTop - { - get - { - var y = SelectedView.Top; - y += (SelectedView.Height - _selectorDrawable.Height) / 2; - return y; - } - } - - public Bitmap SelectorBitmap - { - get { return _selectorDrawable; } - set - { - _selectorDrawable = value; - RefreshDrawableState(); - } - } - } +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using System; +using Android.Content; +using Android.Graphics; +using Android.Graphics.Drawables; +using Android.Util; +using Android.Views; +using Math = System.Math; + +namespace SlidingMenuSharp +{ + public sealed class CustomViewBehind : ViewGroup + { + private new const string Tag = "CustomViewBehind"; + + private const int MARGIN_THRESHOLD = 48; + + private View _content; + private View _secondaryContent; + private int _widthOffset; + private ICanvasTransformer _transformer; + private MenuMode _mode; + private readonly Paint _fadePaint = new Paint(); + private Drawable _shadowDrawable; + private Drawable _secondaryShadowDrawable; + private int _shadowWidth; + private float _fadeDegree; + private Bitmap _selectorDrawable; + private View _selectedView; + + public CustomViewBehind(Context context) + : this(context, null) + { + } + + public CustomViewBehind(Context context, IAttributeSet attrs) + : base(context, attrs) + { + TouchMode = TouchMode.Margin; + MarginThreshold = + (int) TypedValue.ApplyDimension(ComplexUnitType.Dip, MARGIN_THRESHOLD, Resources.DisplayMetrics); + } + + public CustomViewAbove CustomViewAbove { get; set; } + + public ICanvasTransformer CanvasTransformer + { + set { _transformer = value; } + } + + public int WidthOffset + { + get { return _widthOffset; } + set + { + _widthOffset = value; + RequestLayout(); + } + } + + public int MarginThreshold { get; set; } + + public int BehindWidth + { + get { return _content.Width; } + } + + public View Content + { + get { return _content; } + set + { + if (_content != null) + RemoveView(_content); + _content = value; + AddView(_content); + } + } + + public View SecondaryContent + { + get { return _secondaryContent; } + set + { + if (_secondaryContent != null) + RemoveView(_secondaryContent); + _secondaryContent = value; + AddView(_secondaryContent); + } + } + + public bool ChildrenEnabled { get; set; } + + public override void ScrollTo(int x, int y) + { + base.ScrollTo(x, y); + if (_transformer != null) + Invalidate(); + } + + public override bool OnInterceptTouchEvent(MotionEvent ev) + { + return !ChildrenEnabled; + } + + public override bool OnTouchEvent(MotionEvent e) + { + return !ChildrenEnabled; + } + + protected override void DispatchDraw(Canvas canvas) + { + if (_transformer != null) + { + canvas.Save(); + _transformer.TransformCanvas(canvas, CustomViewAbove.PercentOpen); + base.DispatchDraw(canvas); + canvas.Restore(); + } + else + base.DispatchDraw(canvas); + } + + protected override void OnLayout(bool changed, int l, int t, int r, int b) + { + var width = r - l; + var height = b - t; + Content.Layout(0, 0, width - _widthOffset, height); + if (SecondaryContent != null) + SecondaryContent.Layout(0, 0, width - _widthOffset, height); + } + + protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + var width = GetDefaultSize(0, widthMeasureSpec); + var height = GetDefaultSize(0, heightMeasureSpec); + SetMeasuredDimension(width, height); + var contentWidth = GetChildMeasureSpec(widthMeasureSpec, 0, width - _widthOffset); + var contentHeight = GetChildMeasureSpec(heightMeasureSpec, 0, height); + Content.Measure(contentWidth, contentHeight); + if (SecondaryContent != null) + SecondaryContent.Measure(contentWidth, contentHeight); + } + + public MenuMode Mode + { + get { return _mode; } + set + { + if (value == MenuMode.Left || value == MenuMode.Right) + { + if (_content != null) + _content.Visibility = ViewStates.Visible; + if (_secondaryContent != null) + _secondaryContent.Visibility = ViewStates.Invisible; + } + _mode = value; + } + } + + public float ScrollScale { get; set; } + + public Drawable ShadowDrawable + { + get { return _shadowDrawable; } + set + { + _shadowDrawable = value; + Invalidate(); + } + } + + public Drawable SecondaryShadowDrawable + { + get { return _secondaryShadowDrawable; } + set + { + _secondaryShadowDrawable = value; + Invalidate(); + } + } + + public int ShadowWidth + { + get { return _shadowWidth; } + set + { + _shadowWidth = value; + Invalidate(); + } + } + + public bool FadeEnabled { get; set; } + + public float FadeDegree + { + get { return _fadeDegree; } + set + { + if (value > 1.0f || value < 0.0f) + throw new ArgumentOutOfRangeException("value", "The BehindFadeDegree must be between 0.0f and 1.0f"); + _fadeDegree = value; + } + } + + public int GetMenuPage(int page) + { + page = (page > 1) ? 2 : ((page < 1) ? 0 : page); + if (Mode == MenuMode.Left && page > 1) + return 0; + if (Mode == MenuMode.Right && page < 1) + return 2; + return page; + } + + public void ScrollBehindTo(View content, int x, int y) + { + var vis = ViewStates.Visible; + switch (Mode) + { + case MenuMode.Left: + if (x >= content.Left) + vis = ViewStates.Invisible; + ScrollTo((int)((x + BehindWidth) * ScrollScale), y); + break; + case MenuMode.Right: + if (x <= content.Left) + vis = ViewStates.Invisible; + ScrollTo((int)(BehindWidth - Width + (x - BehindWidth) * ScrollScale), y); + break; + case MenuMode.LeftRight: + Content.Visibility = x >= content.Left ? ViewStates.Invisible : ViewStates.Visible; + SecondaryContent.Visibility = x <= content.Left ? ViewStates.Invisible : ViewStates.Visible; + vis = x == 0 ? ViewStates.Invisible : ViewStates.Visible; + if (x <= content.Left) + ScrollTo((int)((x+BehindWidth)*ScrollScale), y); + else + ScrollTo((int)(BehindWidth - Width + (x-BehindWidth)*ScrollScale), y); + break; + } + if (vis == ViewStates.Invisible) + Log.Verbose(Tag, "behind INVISIBLE"); + Visibility = vis; + } + + public int GetMenuLeft(View content, int page) + { + switch (Mode) + { + case MenuMode.Left: + switch (page) + { + case 0: + return content.Left - BehindWidth; + case 2: + return content.Left; + } + break; + case MenuMode.Right: + switch (page) + { + case 0: + return content.Left; + case 2: + return content.Left + BehindWidth; + } + break; + case MenuMode.LeftRight: + switch (page) + { + case 0: + return content.Left - BehindWidth; + case 2: + return content.Left + BehindWidth; + } + break; + } + return content.Left; + } + + public int GetAbsLeftBound(View content) + { + if (Mode == MenuMode.Left || Mode == MenuMode.LeftRight) + return content.Left - BehindWidth; + return Mode == MenuMode.Right ? content.Left : 0; + } + + public int GetAbsRightBound(View content) + { + if (Mode == MenuMode.Right || Mode == MenuMode.LeftRight) + return content.Left + BehindWidth; + return Mode == MenuMode.Left ? content.Left : 0; + } + + public bool MarginTouchAllowed(View content, int x) + { + var left = content.Left; + var right = content.Right; + if (Mode == MenuMode.Left) + return (x >= left && x <= MarginThreshold + left); + if (Mode == MenuMode.Right) + return (x <= right && x >= right - MarginThreshold); + if (Mode == MenuMode.LeftRight) + return (x >= left && x <= MarginThreshold + left) || + (x <= right && x >= right - MarginThreshold); + return false; + } + + public TouchMode TouchMode { get; set; } + + public bool MenuOpenTouchAllowed(View content, int currPage, float x) + { + switch (TouchMode) + { + case TouchMode.Fullscreen: + return true; + case TouchMode.Margin: + return MenuTouchInQuickReturn(content, currPage, x); + } + return false; + } + + public bool MenuTouchInQuickReturn(View content, int currPage, float x) + { + if (Mode == MenuMode.Left || (Mode == MenuMode.LeftRight && currPage == 0)) + return x >= content.Left; + if (Mode == MenuMode.Right || (Mode == MenuMode.LeftRight && currPage == 2)) + return x <= content.Right; + return false; + } + + public bool MenuClosedSlideAllowed(float dx) + { + switch (Mode) + { + case MenuMode.Left: + return dx > 0; + case MenuMode.Right: + return dx < 0; + case MenuMode.LeftRight: + return true; + } + return false; + } + + public bool MenuOpenSlideAllowed(float dx) + { + switch (Mode) + { + case MenuMode.Left: + return dx < 0; + case MenuMode.Right: + return dx > 0; + case MenuMode.LeftRight: + return true; + } + return false; + } + + public void DrawShadow(View content, Canvas canvas) + { + if (ShadowDrawable == null || ShadowWidth <= 0) return; + var left = 0; + switch (Mode) + { + case MenuMode.Left: + left = content.Left - ShadowWidth; + break; + case MenuMode.Right: + left = content.Right; + break; + case MenuMode.LeftRight: + if (SecondaryShadowDrawable != null) + { + left = content.Right; + SecondaryShadowDrawable.SetBounds(left, 0, left + ShadowWidth, Height); + SecondaryShadowDrawable.Draw(canvas); + } + left = content.Left - ShadowWidth; + break; + } + ShadowDrawable.SetBounds(left, 0, left + ShadowWidth, Height); + ShadowDrawable.Draw(canvas); + } + + public void DrawFade(View content, Canvas canvas, float openPercent) + { + if (!FadeEnabled) return; + + var alpha = (int) (FadeDegree * 255 * Math.Abs(1 - openPercent)); + _fadePaint.Color = Color.Argb(alpha, 0, 0, 0); + var left = 0; + var right = 0; + switch (Mode) + { + case MenuMode.Left: + left = content.Left - BehindWidth; + right = content.Left; + break; + case MenuMode.Right: + left = content.Right; + right = content.Right + BehindWidth; + break; + case MenuMode.LeftRight: + left = content.Left - BehindWidth; + right = content.Left; + canvas.DrawRect(left, 0, right, Height, _fadePaint); + left = content.Right; + right = content.Right + BehindWidth; + break; + } + canvas.DrawRect(left, 0, right, Height, _fadePaint); + } + + public void DrawSelector(View content, Canvas canvas, float openPercent) + { + if (!SelectorEnabled) return; + if (_selectorDrawable != null && SelectedView != null) + { + var tag = (string)SelectedView.GetTag(Resource.Id.selected_view); + if (tag.Equals(Tag + "SelectedView")) + { + canvas.Save(); + int left, right; + var offset = (int)(SelectorBitmap.Width * openPercent); + if (Mode == MenuMode.Left) + { + right = content.Left; + left = right - offset; + canvas.ClipRect(left, 0, right, Height); + canvas.DrawBitmap(SelectorBitmap, left, SelectorTop, null); + } + else if (Mode == MenuMode.Right) + { + left = content.Right; + right = left + offset; + canvas.ClipRect(left, 0, right, Height); + canvas.DrawBitmap(SelectorBitmap, right - SelectorBitmap.Width, SelectorTop, null); + } + canvas.Restore(); + } + } + } + + public bool SelectorEnabled { get; set; } + + public View SelectedView + { + get { return _selectedView; } + set + { + if (_selectedView != null) + { + _selectedView.SetTag(Resource.Id.selected_view, null); + _selectedView = null; + } + if (value != null && value.Parent != null) + { + _selectedView = value; + _selectedView.SetTag(Resource.Id.selected_view, Tag+"SelectedView"); + Invalidate(); + } + } + } + + private int SelectorTop + { + get + { + var y = SelectedView.Top; + y += (SelectedView.Height - _selectorDrawable.Height) / 2; + return y; + } + } + + public Bitmap SelectorBitmap + { + get { return _selectorDrawable; } + set + { + _selectorDrawable = value; + RefreshDrawableState(); + } + } + } } \ No newline at end of file diff --git a/SlidingMenuSharp/Enums.cs b/SlidingMenuSharp/Enums.cs index fbaeecc..53fbbbb 100644 --- a/SlidingMenuSharp/Enums.cs +++ b/SlidingMenuSharp/Enums.cs @@ -1,38 +1,38 @@ -/* - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -namespace SlidingMenuSharp -{ - public enum MenuMode - { - Left = 0, - Right = 1, - LeftRight = 2 - } - - public enum TouchMode - { - Margin = 0, - Fullscreen = 1, - None = 2 - } - - public enum SlideStyle - { - Window = 0, - Content = 1 - } +/* + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +namespace SlidingMenuSharp +{ + public enum MenuMode + { + Left = 0, + Right = 1, + LeftRight = 2 + } + + public enum TouchMode + { + Margin = 0, + Fullscreen = 1, + None = 2 + } + + public enum SlideStyle + { + Window = 0, + Content = 1 + } } \ No newline at end of file diff --git a/SlidingMenuSharp/Properties/AssemblyInfo.cs b/SlidingMenuSharp/Properties/AssemblyInfo.cs index 9ac5c31..96d2a15 100644 --- a/SlidingMenuSharp/Properties/AssemblyInfo.cs +++ b/SlidingMenuSharp/Properties/AssemblyInfo.cs @@ -1,29 +1,29 @@ -using System.Reflection; -using System.Runtime.InteropServices; -using Android.App; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SlidingMenuSharp")] -[assembly: AssemblyDescription("SlidingMenu implementation for Xamarin.Android")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SlidingMenuSharp")] -[assembly: AssemblyCopyright("Copyright © Tomasz Cielecki 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.InteropServices; +using Android.App; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SlidingMenuSharp")] +[assembly: AssemblyDescription("SlidingMenu implementation for Xamarin.Android")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SlidingMenuSharp")] +[assembly: AssemblyCopyright("Copyright © Tomasz Cielecki 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SlidingMenuSharp/ResourceIdFix.cs b/SlidingMenuSharp/ResourceIdFix.cs index cdd200e..695d296 100644 --- a/SlidingMenuSharp/ResourceIdFix.cs +++ b/SlidingMenuSharp/ResourceIdFix.cs @@ -1,47 +1,47 @@ -/* - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using System; -using System.Linq; -using System.Reflection; -using Android.Runtime; - -namespace SlidingMenuSharp -{ - public static class ResourceIdManager - { - static bool _idInitialized; - public static void UpdateIdValues() - { - if (_idInitialized) - return; - var eass = Assembly.GetExecutingAssembly(); - Func f = ass => - ass.GetCustomAttributes(typeof(ResourceDesignerAttribute), true) - .Select(ca => ca as ResourceDesignerAttribute) - .Where(ca => ca != null && ca.IsApplication) - .Select(ca => ass.GetType(ca.FullName)) - .Where(ty => ty != null) - .FirstOrDefault(); - var t = f(eass); - if (t == null) - t = AppDomain.CurrentDomain.GetAssemblies().Select(ass => f(ass)).Where(ty => ty != null).FirstOrDefault(); - if (t != null) - t.GetMethod("UpdateIdValues").Invoke(null, new object[0]); - _idInitialized = true; - } - } +/* + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using System; +using System.Linq; +using System.Reflection; +using Android.Runtime; + +namespace SlidingMenuSharp +{ + public static class ResourceIdManager + { + static bool _idInitialized; + public static void UpdateIdValues() + { + if (_idInitialized) + return; + var eass = Assembly.GetExecutingAssembly(); + Func f = ass => + ass.GetCustomAttributes(typeof(ResourceDesignerAttribute), true) + .Select(ca => ca as ResourceDesignerAttribute) + .Where(ca => ca != null && ca.IsApplication) + .Select(ca => ass.GetType(ca.FullName)) + .Where(ty => ty != null) + .FirstOrDefault(); + var t = f(eass); + if (t == null) + t = AppDomain.CurrentDomain.GetAssemblies().Select(ass => f(ass)).Where(ty => ty != null).FirstOrDefault(); + if (t != null) + t.GetMethod("UpdateIdValues").Invoke(null, new object[0]); + _idInitialized = true; + } + } } \ No newline at end of file diff --git a/SlidingMenuSharp/Resources/Resource.Designer.cs b/SlidingMenuSharp/Resources/Resource.Designer.cs index 7d88ad3..0ad5dba 100644 --- a/SlidingMenuSharp/Resources/Resource.Designer.cs +++ b/SlidingMenuSharp/Resources/Resource.Designer.cs @@ -2,7 +2,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18408 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -15,7 +14,7 @@ namespace SlidingMenuSharp { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "12.3.0.26")] public partial class Resource { @@ -27,47 +26,110 @@ static Resource() public partial class Attribute { - // aapt resource value: 0x7f010003 - public static int behindOffset = 2130771971; + // aapt resource value: 0x7F010000 + public static int alpha = 2130771968; - // aapt resource value: 0x7f010005 - public static int behindScrollScale = 2130771973; + // aapt resource value: 0x7F010001 + public static int behindOffset = 2130771969; - // aapt resource value: 0x7f010004 - public static int behindWidth = 2130771972; + // aapt resource value: 0x7F010002 + public static int behindScrollScale = 2130771970; - // aapt resource value: 0x7f01000b - public static int fadeDegree = 2130771979; + // aapt resource value: 0x7F010003 + public static int behindWidth = 2130771971; - // aapt resource value: 0x7f01000a - public static int fadeEnabled = 2130771978; + // aapt resource value: 0x7F010004 + public static int coordinatorLayoutStyle = 2130771972; - // aapt resource value: 0x7f010000 - public static int mode = 2130771968; + // aapt resource value: 0x7F010005 + public static int fadeDegree = 2130771973; - // aapt resource value: 0x7f01000d - public static int selectorDrawable = 2130771981; + // aapt resource value: 0x7F010006 + public static int fadeEnabled = 2130771974; - // aapt resource value: 0x7f01000c - public static int selectorEnabled = 2130771980; + // aapt resource value: 0x7F010007 + public static int font = 2130771975; - // aapt resource value: 0x7f010008 - public static int shadowDrawable = 2130771976; + // aapt resource value: 0x7F010008 + public static int fontProviderAuthority = 2130771976; - // aapt resource value: 0x7f010009 - public static int shadowWidth = 2130771977; + // aapt resource value: 0x7F010009 + public static int fontProviderCerts = 2130771977; - // aapt resource value: 0x7f010006 - public static int touchModeAbove = 2130771974; + // aapt resource value: 0x7F01000A + public static int fontProviderFetchStrategy = 2130771978; - // aapt resource value: 0x7f010007 - public static int touchModeBehind = 2130771975; + // aapt resource value: 0x7F01000B + public static int fontProviderFetchTimeout = 2130771979; - // aapt resource value: 0x7f010001 - public static int viewAbove = 2130771969; + // aapt resource value: 0x7F01000C + public static int fontProviderPackage = 2130771980; - // aapt resource value: 0x7f010002 - public static int viewBehind = 2130771970; + // aapt resource value: 0x7F01000D + public static int fontProviderQuery = 2130771981; + + // aapt resource value: 0x7F01000E + public static int fontStyle = 2130771982; + + // aapt resource value: 0x7F01000F + public static int fontVariationSettings = 2130771983; + + // aapt resource value: 0x7F010010 + public static int fontWeight = 2130771984; + + // aapt resource value: 0x7F010011 + public static int keylines = 2130771985; + + // aapt resource value: 0x7F010012 + public static int layout_anchor = 2130771986; + + // aapt resource value: 0x7F010013 + public static int layout_anchorGravity = 2130771987; + + // aapt resource value: 0x7F010014 + public static int layout_behavior = 2130771988; + + // aapt resource value: 0x7F010015 + public static int layout_dodgeInsetEdges = 2130771989; + + // aapt resource value: 0x7F010016 + public static int layout_insetEdge = 2130771990; + + // aapt resource value: 0x7F010017 + public static int layout_keyline = 2130771991; + + // aapt resource value: 0x7F010018 + public static int mode = 2130771992; + + // aapt resource value: 0x7F010019 + public static int selectorDrawable = 2130771993; + + // aapt resource value: 0x7F01001A + public static int selectorEnabled = 2130771994; + + // aapt resource value: 0x7F01001B + public static int shadowDrawable = 2130771995; + + // aapt resource value: 0x7F01001C + public static int shadowWidth = 2130771996; + + // aapt resource value: 0x7F01001D + public static int statusBarBackground = 2130771997; + + // aapt resource value: 0x7F01001E + public static int touchModeAbove = 2130771998; + + // aapt resource value: 0x7F01001F + public static int touchModeBehind = 2130771999; + + // aapt resource value: 0x7F010020 + public static int ttcIndex = 2130772000; + + // aapt resource value: 0x7F010021 + public static int viewAbove = 2130772001; + + // aapt resource value: 0x7F010022 + public static int viewBehind = 2130772002; static Attribute() { @@ -79,26 +141,341 @@ private Attribute() } } + public partial class Color + { + + // aapt resource value: 0x7F020000 + public static int notification_action_color_filter = 2130837504; + + // aapt resource value: 0x7F020001 + public static int notification_icon_bg_color = 2130837505; + + // aapt resource value: 0x7F020002 + public static int notification_material_background_media_default_color = 2130837506; + + // aapt resource value: 0x7F020003 + public static int primary_text_default_material_dark = 2130837507; + + // aapt resource value: 0x7F020004 + public static int ripple_material_light = 2130837508; + + // aapt resource value: 0x7F020005 + public static int secondary_text_default_material_dark = 2130837509; + + // aapt resource value: 0x7F020006 + public static int secondary_text_default_material_light = 2130837510; + + static Color() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Color() + { + } + } + + public partial class Dimension + { + + // aapt resource value: 0x7F030000 + public static int compat_button_inset_horizontal_material = 2130903040; + + // aapt resource value: 0x7F030001 + public static int compat_button_inset_vertical_material = 2130903041; + + // aapt resource value: 0x7F030002 + public static int compat_button_padding_horizontal_material = 2130903042; + + // aapt resource value: 0x7F030003 + public static int compat_button_padding_vertical_material = 2130903043; + + // aapt resource value: 0x7F030004 + public static int compat_control_corner_material = 2130903044; + + // aapt resource value: 0x7F030005 + public static int compat_notification_large_icon_max_height = 2130903045; + + // aapt resource value: 0x7F030006 + public static int compat_notification_large_icon_max_width = 2130903046; + + // aapt resource value: 0x7F030007 + public static int notification_action_icon_size = 2130903047; + + // aapt resource value: 0x7F030008 + public static int notification_action_text_size = 2130903048; + + // aapt resource value: 0x7F030009 + public static int notification_big_circle_margin = 2130903049; + + // aapt resource value: 0x7F03000A + public static int notification_content_margin_start = 2130903050; + + // aapt resource value: 0x7F03000B + public static int notification_large_icon_height = 2130903051; + + // aapt resource value: 0x7F03000C + public static int notification_large_icon_width = 2130903052; + + // aapt resource value: 0x7F03000D + public static int notification_main_column_padding_top = 2130903053; + + // aapt resource value: 0x7F03000E + public static int notification_media_narrow_margin = 2130903054; + + // aapt resource value: 0x7F03000F + public static int notification_right_icon_size = 2130903055; + + // aapt resource value: 0x7F030010 + public static int notification_right_side_padding_top = 2130903056; + + // aapt resource value: 0x7F030011 + public static int notification_small_icon_background_padding = 2130903057; + + // aapt resource value: 0x7F030012 + public static int notification_small_icon_size_as_large = 2130903058; + + // aapt resource value: 0x7F030013 + public static int notification_subtext_size = 2130903059; + + // aapt resource value: 0x7F030014 + public static int notification_top_pad = 2130903060; + + // aapt resource value: 0x7F030015 + public static int notification_top_pad_large_text = 2130903061; + + // aapt resource value: 0x7F030016 + public static int subtitle_corner_radius = 2130903062; + + // aapt resource value: 0x7F030017 + public static int subtitle_outline_width = 2130903063; + + // aapt resource value: 0x7F030018 + public static int subtitle_shadow_offset = 2130903064; + + // aapt resource value: 0x7F030019 + public static int subtitle_shadow_radius = 2130903065; + + static Dimension() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Dimension() + { + } + } + + public partial class Drawable + { + + // aapt resource value: 0x7F040000 + public static int notification_action_background = 2130968576; + + // aapt resource value: 0x7F040001 + public static int notification_bg = 2130968577; + + // aapt resource value: 0x7F040002 + public static int notification_bg_low = 2130968578; + + // aapt resource value: 0x7F040003 + public static int notification_bg_low_normal = 2130968579; + + // aapt resource value: 0x7F040004 + public static int notification_bg_low_pressed = 2130968580; + + // aapt resource value: 0x7F040005 + public static int notification_bg_normal = 2130968581; + + // aapt resource value: 0x7F040006 + public static int notification_bg_normal_pressed = 2130968582; + + // aapt resource value: 0x7F040007 + public static int notification_icon_background = 2130968583; + + // aapt resource value: 0x7F040008 + public static int notification_template_icon_bg = 2130968584; + + // aapt resource value: 0x7F040009 + public static int notification_template_icon_low_bg = 2130968585; + + // aapt resource value: 0x7F04000A + public static int notification_tile_bg = 2130968586; + + // aapt resource value: 0x7F04000B + public static int notify_panel_notification_icon_bg = 2130968587; + + static Drawable() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Drawable() + { + } + } + public partial class Id { - // aapt resource value: 0x7f030003 - public static int fullscreen = 2130903043; + // aapt resource value: 0x7F050000 + public static int action0 = 2131034112; + + // aapt resource value: 0x7F050005 + public static int actions = 2131034117; + + // aapt resource value: 0x7F050001 + public static int action_container = 2131034113; + + // aapt resource value: 0x7F050002 + public static int action_divider = 2131034114; + + // aapt resource value: 0x7F050003 + public static int action_image = 2131034115; + + // aapt resource value: 0x7F050004 + public static int action_text = 2131034116; + + // aapt resource value: 0x7F050006 + public static int all = 2131034118; + + // aapt resource value: 0x7F050007 + public static int async = 2131034119; + + // aapt resource value: 0x7F050008 + public static int blocking = 2131034120; + + // aapt resource value: 0x7F050009 + public static int bottom = 2131034121; + + // aapt resource value: 0x7F05000A + public static int cancel_action = 2131034122; + + // aapt resource value: 0x7F05000B + public static int center = 2131034123; + + // aapt resource value: 0x7F05000C + public static int center_horizontal = 2131034124; + + // aapt resource value: 0x7F05000D + public static int center_vertical = 2131034125; + + // aapt resource value: 0x7F05000E + public static int chronometer = 2131034126; + + // aapt resource value: 0x7F05000F + public static int clip_horizontal = 2131034127; + + // aapt resource value: 0x7F050010 + public static int clip_vertical = 2131034128; + + // aapt resource value: 0x7F050011 + public static int end = 2131034129; + + // aapt resource value: 0x7F050012 + public static int end_padder = 2131034130; + + // aapt resource value: 0x7F050013 + public static int fill = 2131034131; + + // aapt resource value: 0x7F050014 + public static int fill_horizontal = 2131034132; + + // aapt resource value: 0x7F050015 + public static int fill_vertical = 2131034133; + + // aapt resource value: 0x7F050016 + public static int forever = 2131034134; + + // aapt resource value: 0x7F050017 + public static int fullscreen = 2131034135; + + // aapt resource value: 0x7F050018 + public static int icon = 2131034136; - // aapt resource value: 0x7f030000 - public static int left = 2130903040; + // aapt resource value: 0x7F050019 + public static int icon_group = 2131034137; - // aapt resource value: 0x7f030002 - public static int margin = 2130903042; + // aapt resource value: 0x7F05001A + public static int info = 2131034138; - // aapt resource value: 0x7f030001 - public static int right = 2130903041; + // aapt resource value: 0x7F05001B + public static int italic = 2131034139; - // aapt resource value: 0x7f030004 - public static int selected_view = 2130903044; + // aapt resource value: 0x7F05001C + public static int left = 2131034140; - // aapt resource value: 0x7f030005 - public static int slidingmenumain = 2130903045; + // aapt resource value: 0x7F05001D + public static int line1 = 2131034141; + + // aapt resource value: 0x7F05001E + public static int line3 = 2131034142; + + // aapt resource value: 0x7F05001F + public static int margin = 2131034143; + + // aapt resource value: 0x7F050020 + public static int media_actions = 2131034144; + + // aapt resource value: 0x7F050021 + public static int none = 2131034145; + + // aapt resource value: 0x7F050022 + public static int normal = 2131034146; + + // aapt resource value: 0x7F050023 + public static int notification_background = 2131034147; + + // aapt resource value: 0x7F050024 + public static int notification_main_column = 2131034148; + + // aapt resource value: 0x7F050025 + public static int notification_main_column_container = 2131034149; + + // aapt resource value: 0x7F050026 + public static int right = 2131034150; + + // aapt resource value: 0x7F050027 + public static int right_icon = 2131034151; + + // aapt resource value: 0x7F050028 + public static int right_side = 2131034152; + + // aapt resource value: 0x7F050029 + public static int selected_view = 2131034153; + + // aapt resource value: 0x7F05002A + public static int slidingmenumain = 2131034154; + + // aapt resource value: 0x7F05002B + public static int start = 2131034155; + + // aapt resource value: 0x7F05002C + public static int status_bar_latest_event_content = 2131034156; + + // aapt resource value: 0x7F05002D + public static int tag_transition_group = 2131034157; + + // aapt resource value: 0x7F05002E + public static int tag_unhandled_key_event_manager = 2131034158; + + // aapt resource value: 0x7F05002F + public static int tag_unhandled_key_listeners = 2131034159; + + // aapt resource value: 0x7F050030 + public static int text = 2131034160; + + // aapt resource value: 0x7F050031 + public static int text2 = 2131034161; + + // aapt resource value: 0x7F050032 + public static int time = 2131034162; + + // aapt resource value: 0x7F050033 + public static int title = 2131034163; + + // aapt resource value: 0x7F050034 + public static int top = 2131034164; static Id() { @@ -110,11 +487,75 @@ private Id() } } + public partial class Integer + { + + // aapt resource value: 0x7F060000 + public static int cancel_button_image_alpha = 2131099648; + + // aapt resource value: 0x7F060001 + public static int status_bar_notification_info_maxnum = 2131099649; + + static Integer() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Integer() + { + } + } + public partial class Layout { - // aapt resource value: 0x7f020000 - public static int slidingmenumain = 2130837504; + // aapt resource value: 0x7F070000 + public static int notification_action = 2131165184; + + // aapt resource value: 0x7F070001 + public static int notification_action_tombstone = 2131165185; + + // aapt resource value: 0x7F070002 + public static int notification_media_action = 2131165186; + + // aapt resource value: 0x7F070003 + public static int notification_media_cancel_action = 2131165187; + + // aapt resource value: 0x7F070004 + public static int notification_template_big_media = 2131165188; + + // aapt resource value: 0x7F070005 + public static int notification_template_big_media_custom = 2131165189; + + // aapt resource value: 0x7F070006 + public static int notification_template_big_media_narrow = 2131165190; + + // aapt resource value: 0x7F070007 + public static int notification_template_big_media_narrow_custom = 2131165191; + + // aapt resource value: 0x7F070008 + public static int notification_template_custom_big = 2131165192; + + // aapt resource value: 0x7F070009 + public static int notification_template_icon_group = 2131165193; + + // aapt resource value: 0x7F07000A + public static int notification_template_lines_media = 2131165194; + + // aapt resource value: 0x7F07000B + public static int notification_template_media = 2131165195; + + // aapt resource value: 0x7F07000C + public static int notification_template_media_custom = 2131165196; + + // aapt resource value: 0x7F07000D + public static int notification_template_part_chronometer = 2131165197; + + // aapt resource value: 0x7F07000E + public static int notification_template_part_time = 2131165198; + + // aapt resource value: 0x7F07000F + public static int slidingmenumain = 2131165199; static Layout() { @@ -126,18 +567,136 @@ private Layout() } } + public partial class String + { + + // aapt resource value: 0x7F080000 + public static int status_bar_notification_info_overflow = 2131230720; + + static String() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private String() + { + } + } + + public partial class Style + { + + // aapt resource value: 0x7F090000 + public static int TextAppearance_Compat_Notification = 2131296256; + + // aapt resource value: 0x7F090001 + public static int TextAppearance_Compat_Notification_Info = 2131296257; + + // aapt resource value: 0x7F090002 + public static int TextAppearance_Compat_Notification_Info_Media = 2131296258; + + // aapt resource value: 0x7F090003 + public static int TextAppearance_Compat_Notification_Line2 = 2131296259; + + // aapt resource value: 0x7F090004 + public static int TextAppearance_Compat_Notification_Line2_Media = 2131296260; + + // aapt resource value: 0x7F090005 + public static int TextAppearance_Compat_Notification_Media = 2131296261; + + // aapt resource value: 0x7F090006 + public static int TextAppearance_Compat_Notification_Time = 2131296262; + + // aapt resource value: 0x7F090007 + public static int TextAppearance_Compat_Notification_Time_Media = 2131296263; + + // aapt resource value: 0x7F090008 + public static int TextAppearance_Compat_Notification_Title = 2131296264; + + // aapt resource value: 0x7F090009 + public static int TextAppearance_Compat_Notification_Title_Media = 2131296265; + + // aapt resource value: 0x7F09000A + public static int Widget_Compat_NotificationActionContainer = 2131296266; + + // aapt resource value: 0x7F09000B + public static int Widget_Compat_NotificationActionText = 2131296267; + + // aapt resource value: 0x7F09000C + public static int Widget_Support_CoordinatorLayout = 2131296268; + + static Style() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Style() + { + } + } + public partial class Styleable { - public static int[] SlidingMenu = new int[] { - 2130771968, - 2130771969, - 2130771970, - 2130771971, - 2130771972, - 2130771973, - 2130771974, - 2130771975, + // aapt resource value: { 0x10101A5,0x101031F,0x7F010000 } + public static int[] ColorStateListItem = new int[] { + 16843173, + 16843551, + 2130771968}; + + // aapt resource value: 2 + public static int ColorStateListItem_alpha = 2; + + // aapt resource value: 1 + public static int ColorStateListItem_android_alpha = 1; + + // aapt resource value: 0 + public static int ColorStateListItem_android_color = 0; + + // aapt resource value: { 0x7F010011,0x7F01001D } + public static int[] CoordinatorLayout = new int[] { + 2130771985, + 2130771997}; + + // aapt resource value: 0 + public static int CoordinatorLayout_keylines = 0; + + // aapt resource value: { 0x10100B3,0x7F010012,0x7F010013,0x7F010014,0x7F010015,0x7F010016,0x7F010017 } + public static int[] CoordinatorLayout_Layout = new int[] { + 16842931, + 2130771986, + 2130771987, + 2130771988, + 2130771989, + 2130771990, + 2130771991}; + + // aapt resource value: 0 + public static int CoordinatorLayout_Layout_android_layout_gravity = 0; + + // aapt resource value: 1 + public static int CoordinatorLayout_Layout_layout_anchor = 1; + + // aapt resource value: 2 + public static int CoordinatorLayout_Layout_layout_anchorGravity = 2; + + // aapt resource value: 3 + public static int CoordinatorLayout_Layout_layout_behavior = 3; + + // aapt resource value: 4 + public static int CoordinatorLayout_Layout_layout_dodgeInsetEdges = 4; + + // aapt resource value: 5 + public static int CoordinatorLayout_Layout_layout_insetEdge = 5; + + // aapt resource value: 6 + public static int CoordinatorLayout_Layout_layout_keyline = 6; + + // aapt resource value: 1 + public static int CoordinatorLayout_statusBarBackground = 1; + + // aapt resource value: { 0x7F010008,0x7F010009,0x7F01000A,0x7F01000B,0x7F01000C,0x7F01000D } + public static int[] FontFamily = new int[] { 2130771976, 2130771977, 2130771978, @@ -145,47 +704,187 @@ public partial class Styleable 2130771980, 2130771981}; + // aapt resource value: { 0x1010532,0x1010533,0x101053F,0x101056F,0x1010570,0x7F010007,0x7F01000E,0x7F01000F,0x7F010010,0x7F010020 } + public static int[] FontFamilyFont = new int[] { + 16844082, + 16844083, + 16844095, + 16844143, + 16844144, + 2130771975, + 2130771982, + 2130771983, + 2130771984, + 2130772000}; + + // aapt resource value: 0 + public static int FontFamilyFont_android_font = 0; + + // aapt resource value: 2 + public static int FontFamilyFont_android_fontStyle = 2; + + // aapt resource value: 4 + public static int FontFamilyFont_android_fontVariationSettings = 4; + + // aapt resource value: 1 + public static int FontFamilyFont_android_fontWeight = 1; + + // aapt resource value: 3 + public static int FontFamilyFont_android_ttcIndex = 3; + + // aapt resource value: 5 + public static int FontFamilyFont_font = 5; + + // aapt resource value: 6 + public static int FontFamilyFont_fontStyle = 6; + + // aapt resource value: 7 + public static int FontFamilyFont_fontVariationSettings = 7; + + // aapt resource value: 8 + public static int FontFamilyFont_fontWeight = 8; + + // aapt resource value: 9 + public static int FontFamilyFont_ttcIndex = 9; + + // aapt resource value: 0 + public static int FontFamily_fontProviderAuthority = 0; + + // aapt resource value: 1 + public static int FontFamily_fontProviderCerts = 1; + + // aapt resource value: 2 + public static int FontFamily_fontProviderFetchStrategy = 2; + // aapt resource value: 3 - public static int SlidingMenu_behindOffset = 3; + public static int FontFamily_fontProviderFetchTimeout = 3; + + // aapt resource value: 4 + public static int FontFamily_fontProviderPackage = 4; // aapt resource value: 5 - public static int SlidingMenu_behindScrollScale = 5; + public static int FontFamily_fontProviderQuery = 5; + + // aapt resource value: { 0x101019D,0x101019E,0x10101A1,0x10101A2,0x10101A3,0x10101A4,0x1010201,0x101020B,0x1010510,0x1010511,0x1010512,0x1010513 } + public static int[] GradientColor = new int[] { + 16843165, + 16843166, + 16843169, + 16843170, + 16843171, + 16843172, + 16843265, + 16843275, + 16844048, + 16844049, + 16844050, + 16844051}; + + // aapt resource value: { 0x10101A5,0x1010514 } + public static int[] GradientColorItem = new int[] { + 16843173, + 16844052}; + + // aapt resource value: 0 + public static int GradientColorItem_android_color = 0; + + // aapt resource value: 1 + public static int GradientColorItem_android_offset = 1; + + // aapt resource value: 7 + public static int GradientColor_android_centerColor = 7; + + // aapt resource value: 3 + public static int GradientColor_android_centerX = 3; // aapt resource value: 4 - public static int SlidingMenu_behindWidth = 4; + public static int GradientColor_android_centerY = 4; - // aapt resource value: 11 - public static int SlidingMenu_fadeDegree = 11; + // aapt resource value: 1 + public static int GradientColor_android_endColor = 1; // aapt resource value: 10 - public static int SlidingMenu_fadeEnabled = 10; + public static int GradientColor_android_endX = 10; - // aapt resource value: 0 - public static int SlidingMenu_mode = 0; + // aapt resource value: 11 + public static int GradientColor_android_endY = 11; - // aapt resource value: 13 - public static int SlidingMenu_selectorDrawable = 13; + // aapt resource value: 5 + public static int GradientColor_android_gradientRadius = 5; - // aapt resource value: 12 - public static int SlidingMenu_selectorEnabled = 12; + // aapt resource value: 0 + public static int GradientColor_android_startColor = 0; // aapt resource value: 8 - public static int SlidingMenu_shadowDrawable = 8; + public static int GradientColor_android_startX = 8; // aapt resource value: 9 - public static int SlidingMenu_shadowWidth = 9; + public static int GradientColor_android_startY = 9; // aapt resource value: 6 - public static int SlidingMenu_touchModeAbove = 6; + public static int GradientColor_android_tileMode = 6; - // aapt resource value: 7 - public static int SlidingMenu_touchModeBehind = 7; + // aapt resource value: 2 + public static int GradientColor_android_type = 2; + + // aapt resource value: { 0x7F010001,0x7F010002,0x7F010003,0x7F010005,0x7F010006,0x7F010018,0x7F010019,0x7F01001A,0x7F01001B,0x7F01001C,0x7F01001E,0x7F01001F,0x7F010021,0x7F010022 } + public static int[] SlidingMenu = new int[] { + 2130771969, + 2130771970, + 2130771971, + 2130771973, + 2130771974, + 2130771992, + 2130771993, + 2130771994, + 2130771995, + 2130771996, + 2130771998, + 2130771999, + 2130772001, + 2130772002}; + + // aapt resource value: 0 + public static int SlidingMenu_behindOffset = 0; // aapt resource value: 1 - public static int SlidingMenu_viewAbove = 1; + public static int SlidingMenu_behindScrollScale = 1; // aapt resource value: 2 - public static int SlidingMenu_viewBehind = 2; + public static int SlidingMenu_behindWidth = 2; + + // aapt resource value: 3 + public static int SlidingMenu_fadeDegree = 3; + + // aapt resource value: 4 + public static int SlidingMenu_fadeEnabled = 4; + + // aapt resource value: 5 + public static int SlidingMenu_mode = 5; + + // aapt resource value: 6 + public static int SlidingMenu_selectorDrawable = 6; + + // aapt resource value: 7 + public static int SlidingMenu_selectorEnabled = 7; + + // aapt resource value: 8 + public static int SlidingMenu_shadowDrawable = 8; + + // aapt resource value: 9 + public static int SlidingMenu_shadowWidth = 9; + + // aapt resource value: 10 + public static int SlidingMenu_touchModeAbove = 10; + + // aapt resource value: 11 + public static int SlidingMenu_touchModeBehind = 11; + + // aapt resource value: 12 + public static int SlidingMenu_viewAbove = 12; + + // aapt resource value: 13 + public static int SlidingMenu_viewBehind = 13; static Styleable() { diff --git a/SlidingMenuSharp/Resources/layout/slidingmenumain.xml b/SlidingMenuSharp/Resources/layout/slidingmenumain.xml index 6396037..d0b3c09 100644 --- a/SlidingMenuSharp/Resources/layout/slidingmenumain.xml +++ b/SlidingMenuSharp/Resources/layout/slidingmenumain.xml @@ -1,5 +1,5 @@ - - + + diff --git a/SlidingMenuSharp/Resources/values/attrs.xml b/SlidingMenuSharp/Resources/values/attrs.xml index aa15696..302b360 100644 --- a/SlidingMenuSharp/Resources/values/attrs.xml +++ b/SlidingMenuSharp/Resources/values/attrs.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SlidingMenuSharp/Resources/values/ids.xml b/SlidingMenuSharp/Resources/values/ids.xml index 6a1844b..f262410 100644 --- a/SlidingMenuSharp/Resources/values/ids.xml +++ b/SlidingMenuSharp/Resources/values/ids.xml @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/SlidingMenuSharp/SlidingMenu.cs b/SlidingMenuSharp/SlidingMenu.cs index 18e0695..871a059 100644 --- a/SlidingMenuSharp/SlidingMenu.cs +++ b/SlidingMenuSharp/SlidingMenu.cs @@ -1,579 +1,579 @@ -/* - * Copyright 2012-2014 Jeremy Feinstein - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using System; -using Android.App; -using Android.Content; -using Android.Graphics; -using Android.Graphics.Drawables; -using Android.OS; -using Android.Util; -using Android.Views; -using Android.Widget; -using Java.Interop; - -namespace SlidingMenuSharp -{ - public class SlidingMenu : RelativeLayout - { - private new const string Tag = "SlidingMenu"; - private bool _mActionbarOverlay; - - private readonly CustomViewAbove _viewAbove; - private readonly CustomViewBehind _viewBehind; - - public event EventHandler Open; - public event EventHandler Close; - public event EventHandler Opened; - public event EventHandler Closed; - - public SlidingMenu(Context context) - : this(context, null) - { - } - - public SlidingMenu(Context context, IAttributeSet attrs) - : this(context, attrs, 0) - { - } - - public SlidingMenu(Context context, IAttributeSet attrs, int defStyle) - : base(context, attrs, defStyle) - { - var behindParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); - _viewBehind = new CustomViewBehind(context); - AddView(_viewBehind, behindParams); - - var aboveParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); - _viewAbove = new CustomViewAbove(context); - AddView(_viewAbove, aboveParams); - - _viewAbove.CustomViewBehind = _viewBehind; - _viewBehind.CustomViewAbove = _viewAbove; - - _viewAbove.PageSelected += (sender, args) => - { - if (args.Position == 0 && null != Open) //position open - Open(this, EventArgs.Empty); - else if (args.Position == 2 && null != Close) //position close - Close(this, EventArgs.Empty); - }; - - _viewAbove.Opened += (sender, args) => { if (null != Opened) Opened(sender, args); }; - _viewAbove.Closed += (sender, args) => { if (null != Closed) Closed(sender, args); }; - - var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SlidingMenu); - var mode = a.GetInt(Resource.Styleable.SlidingMenu_mode, (int) MenuMode.Left); - Mode = (MenuMode) mode; - - var viewAbove = a.GetResourceId(Resource.Styleable.SlidingMenu_viewAbove, -1); - if (viewAbove != -1) - SetContent(viewAbove); - else - SetContent(new FrameLayout(context)); - - TouchModeAbove = (TouchMode)a.GetInt(Resource.Styleable.SlidingMenu_touchModeAbove, (int)TouchMode.Margin); - TouchModeBehind = (TouchMode)a.GetInt(Resource.Styleable.SlidingMenu_touchModeBehind, (int)TouchMode.Margin); - - var offsetBehind = (int) a.GetDimension(Resource.Styleable.SlidingMenu_behindOffset, -1); - var widthBehind = (int) a.GetDimension(Resource.Styleable.SlidingMenu_behindWidth, -1); - if (offsetBehind != -1 && widthBehind != -1) - throw new ArgumentException("Cannot set both behindOffset and behindWidth for SlidingMenu, check your XML"); - if (offsetBehind != -1) - BehindOffset = offsetBehind; - else if (widthBehind != -1) - BehindWidth = widthBehind; - else - BehindOffset = 0; - - var shadowRes = a.GetResourceId(Resource.Styleable.SlidingMenu_shadowDrawable, -1); - if (shadowRes != -1) - ShadowDrawableRes = shadowRes; - - BehindScrollScale = a.GetFloat(Resource.Styleable.SlidingMenu_behindScrollScale, 0.33f); - ShadowWidth = ((int)a.GetDimension(Resource.Styleable.SlidingMenu_shadowWidth, 0)); - FadeEnabled = a.GetBoolean(Resource.Styleable.SlidingMenu_fadeEnabled, true); - FadeDegree = a.GetFloat(Resource.Styleable.SlidingMenu_fadeDegree, 0.33f); - SelectorEnabled = a.GetBoolean(Resource.Styleable.SlidingMenu_selectorEnabled, false); - var selectorRes = a.GetResourceId(Resource.Styleable.SlidingMenu_selectorDrawable, -1); - if (selectorRes != -1) - SelectorDrawable = selectorRes; - - a.Recycle(); - } - - public void AttachToActivity(Activity activity, SlideStyle slideStyle) - { - AttachToActivity(activity, slideStyle, false); - } - - public void AttachToActivity(Activity activity, SlideStyle slideStyle, bool actionbarOverlay) - { - if (Parent != null) - throw new ArgumentException("This SlidingMenu appears to already be attached"); - - // get the window background - var a = activity.Theme.ObtainStyledAttributes(new[] { Android.Resource.Attribute.WindowBackground }); - var background = a.GetResourceId(0, 0); - a.Recycle(); - - switch (slideStyle) - { - case SlideStyle.Window: - _mActionbarOverlay = false; - var decor = (ViewGroup)activity.Window.DecorView; - var decorChild = (ViewGroup)decor.GetChildAt(0); - // save ActionBar themes that have transparent assets - decorChild.SetBackgroundResource(background); - decor.RemoveView(decorChild); - decor.AddView(this); - SetContent(decorChild); - break; - case SlideStyle.Content: - _mActionbarOverlay = actionbarOverlay; - // take the above view out of - var contentParent = (ViewGroup)activity.FindViewById(Android.Resource.Id.Content); - var content = contentParent.GetChildAt(0); - contentParent.RemoveView(content); - contentParent.AddView(this); - SetContent(content); - // save people from having transparent backgrounds - if (content.Background == null) - content.SetBackgroundResource(background); - break; - } - } - - public void SetContent(int res) - { - SetContent(LayoutInflater.From(Context).Inflate(res, null)); - } - - public void SetContent(View view) - { - _viewAbove.Content = view; - ShowContent(); - } - - public View GetContent() - { - return _viewAbove.Content; - } - - public void SetMenu(int res) - { - SetMenu(LayoutInflater.From(Context).Inflate(res, null)); - } - - public void SetMenu(View v) - { - _viewBehind.Content = v; - } - - public View GetMenu() - { - return _viewBehind.Content; - } - - public void SetSecondaryMenu(int res) - { - SetSecondaryMenu(LayoutInflater.From(Context).Inflate(res, null)); - } - - public void SetSecondaryMenu(View v) - { - _viewBehind.SecondaryContent = v; - } - - public View GetSecondaryMenu() - { - return _viewBehind.SecondaryContent; - } - - public bool IsSlidingEnabled - { - get { return _viewAbove.IsSlidingEnabled; } - set { _viewAbove.IsSlidingEnabled = value; } - } - - public MenuMode Mode - { - get { return _viewBehind.Mode; } - set - { - if (value != MenuMode.Left && value != MenuMode.Right && value != MenuMode.LeftRight) - { - throw new ArgumentException("SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT", "value"); - } - _viewBehind.Mode = value; - } - } - - public bool Static - { - set - { - if (value) - { - IsSlidingEnabled = false; - _viewAbove.CustomViewBehind = null; - _viewAbove.SetCurrentItem(1); - } - else - { - _viewAbove.SetCurrentItem(1); - _viewAbove.CustomViewBehind = _viewBehind; - IsSlidingEnabled = true; - } - } - } - - public void ShowMenu() - { - ShowMenu(true); - } - - public void ShowMenu(bool animate) - { - _viewAbove.SetCurrentItem(0, animate); - } - - public void ShowSecondaryMenu() - { - ShowSecondaryMenu(true); - } - - public void ShowSecondaryMenu(bool animate) - { - _viewAbove.SetCurrentItem(2, animate); - } - - public void ShowContent(bool animate = true) - { - _viewAbove.SetCurrentItem(1, animate); - } - - public void Toggle() - { - Toggle(true); - } - - public void Toggle(bool animate) - { - if (IsMenuShowing) - { - ShowContent(animate); - } - else - { - ShowMenu(animate); - } - } - - public bool IsMenuShowing - { - get { return _viewAbove.GetCurrentItem() == 0 || _viewAbove.GetCurrentItem() == 2; } - } - - public bool IsSecondaryMenuShowing - { - get { return _viewAbove.GetCurrentItem() == 2; } - } - - public int BehindOffset - { - get { return _viewBehind.WidthOffset; } - set - { - _viewBehind.WidthOffset = value; - } - } - - public int BehindOffsetRes - { - set - { - var i = (int) Context.Resources.GetDimension(value); - BehindOffset = i; - } - } - - public int AboveOffset - { - set { _viewAbove.AboveOffset = value; } - } - - public int AboveOffsetRes - { - set - { - var i = (int) Context.Resources.GetDimension(value); - AboveOffset = i; - } - } - - public int BehindWidth - { - set - { - var windowService = Context.GetSystemService(Context.WindowService); - var windowManager = windowService.JavaCast(); - var width = windowManager.DefaultDisplay.Width; - BehindOffset = width - value; - } - } - - public int BehindWidthRes - { - set - { - var i = (int)Context.Resources.GetDimension(value); - BehindWidth = i; - } - } - - public float BehindScrollScale - { - get { return _viewBehind.ScrollScale; } - set - { - if (value < 0f && value > 1f) - throw new ArgumentOutOfRangeException("value", "ScrollScale must be between 0f and 1f"); - _viewBehind.ScrollScale = value; - } - } - - public int TouchmodeMarginThreshold - { - get { return _viewBehind.MarginThreshold; } - set { _viewBehind.MarginThreshold = value; } - } - - public TouchMode TouchModeAbove - { - get { return _viewAbove.TouchMode; } - set - { - if (value != TouchMode.Fullscreen && value != TouchMode.Margin - && value != TouchMode.None) - { - throw new ArgumentException("TouchMode must be set to either" + - "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.", "value"); - } - _viewAbove.TouchMode = value; - } - } - - public TouchMode TouchModeBehind - { - set - { - if (value != TouchMode.Fullscreen && value != TouchMode.Margin - && value != TouchMode.None) - { - throw new ArgumentException("TouchMode must be set to either" + - "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.", "value"); - } - _viewBehind.TouchMode = value; - } - } - - public int ShadowDrawableRes - { - set { _viewBehind.ShadowDrawable = Context.Resources.GetDrawable(value); } - } - - public Drawable ShadowDrawable - { - set { _viewBehind.ShadowDrawable = value; } - } - - public int SecondaryShadowDrawableRes - { - set { _viewBehind.SecondaryShadowDrawable = Context.Resources.GetDrawable(value); } - } - - public Drawable SecondaryShadowDrawable - { - set { _viewBehind.SecondaryShadowDrawable = value; } - } - - public int ShadowWidthRes - { - set { ShadowWidth = (int)Context.Resources.GetDimension(value); } - } - - public int ShadowWidth - { - set { _viewBehind.ShadowWidth = value; } - } - - public bool FadeEnabled - { - set { _viewBehind.FadeEnabled = value; } - } - - public float FadeDegree - { - set { _viewBehind.FadeDegree = value; } - } - - public bool SelectorEnabled - { - set { _viewBehind.SelectorEnabled = value; } - } - - public View SelectedView - { - set { _viewBehind.SelectedView = value; } - } - - public int SelectorDrawable - { - set { SelectorBitmap = BitmapFactory.DecodeResource(Resources, value); } - } - - public Bitmap SelectorBitmap - { - set { _viewBehind.SelectorBitmap = value; } - } - - public void AddIgnoredView(View v) - { - _viewAbove.AddIgnoredView(v); - } - - public void RemoveIgnoredView(View v) - { - _viewAbove.RemoveIgnoredView(v); - } - - public void ClearIgnoredViews() - { - _viewAbove.ClearIgnoredViews(); - } - - public ICanvasTransformer BehindCanvasTransformer - { - set { _viewBehind.CanvasTransformer = value; } - } - - public class SavedState : BaseSavedState - { - public int Item { get; private set; } - - public SavedState(IParcelable superState) - : base(superState) - { - - } - - public SavedState(Parcel parcel) - : base(parcel) - { - Item = parcel.ReadInt(); - } - - public override void WriteToParcel(Parcel dest, ParcelableWriteFlags flags) - { - base.WriteToParcel(dest, flags); - dest.WriteInt(Item); - } - - [ExportField("CREATOR")] - static SavedStateCreator InitializeCreator() - { - return new SavedStateCreator(); - } - - class SavedStateCreator : Java.Lang.Object, IParcelableCreator - { - public Java.Lang.Object CreateFromParcel(Parcel source) - { - return new SavedState(source); - } - - public Java.Lang.Object[] NewArray(int size) - { - return new SavedState[size]; - } - } - } - - protected override void OnRestoreInstanceState(IParcelable state) - { - try - { - Bundle bundle = state as Bundle; - if (bundle != null) - { - IParcelable superState = (IParcelable)bundle.GetParcelable("base"); - if (superState != null) - base.OnRestoreInstanceState(superState); - _viewAbove.SetCurrentItem(bundle.GetInt("currentPosition", 0)); - } - } - catch - { - base.OnRestoreInstanceState(state); - // Ignore, this needs to support IParcelable... - } - } - - protected override IParcelable OnSaveInstanceState() - { - var superState = base.OnSaveInstanceState(); - Bundle state = new Bundle(); - state.PutParcelable("base", superState); - state.PutInt("currentPosition", _viewAbove.GetCurrentItem()); - - return state; - } - - protected override bool FitSystemWindows(Rect insets) - { - if (!_mActionbarOverlay) - { - Log.Verbose(Tag, "setting padding"); - SetPadding(insets.Left, insets.Top, insets.Right, insets.Bottom); - } - return true; - } - -#if __ANDROID_11__ - public void ManageLayers(float percentOpen) - { - if ((int) Build.VERSION.SdkInt < 11) return; - - var layer = percentOpen > 0.0f && percentOpen < 1.0f; - var layerType = layer ? LayerType.Hardware : LayerType.None; - - if (layerType != GetContent().LayerType) - { - Handler.Post(() => - { - Log.Verbose(Tag, "changing layerType, hardware? " + (layerType == LayerType.Hardware)); - GetContent().SetLayerType(layerType, null); - GetMenu().SetLayerType(layerType, null); - if (GetSecondaryMenu() != null) - GetSecondaryMenu().SetLayerType(layerType, null); - }); - } - } -#endif - } -} +/* + * Copyright 2012-2014 Jeremy Feinstein + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using System; +using Android.App; +using Android.Content; +using Android.Graphics; +using Android.Graphics.Drawables; +using Android.OS; +using Android.Util; +using Android.Views; +using Android.Widget; +using Java.Interop; + +namespace SlidingMenuSharp +{ + public class SlidingMenu : RelativeLayout + { + private new const string Tag = "SlidingMenu"; + private bool _mActionbarOverlay; + + private readonly CustomViewAbove _viewAbove; + private readonly CustomViewBehind _viewBehind; + + public event EventHandler Open; + public event EventHandler Close; + public event EventHandler Opened; + public event EventHandler Closed; + + public SlidingMenu(Context context) + : this(context, null) + { + } + + public SlidingMenu(Context context, IAttributeSet attrs) + : this(context, attrs, 0) + { + } + + public SlidingMenu(Context context, IAttributeSet attrs, int defStyle) + : base(context, attrs, defStyle) + { + var behindParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); + _viewBehind = new CustomViewBehind(context); + AddView(_viewBehind, behindParams); + + var aboveParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); + _viewAbove = new CustomViewAbove(context); + AddView(_viewAbove, aboveParams); + + _viewAbove.CustomViewBehind = _viewBehind; + _viewBehind.CustomViewAbove = _viewAbove; + + _viewAbove.PageSelected += (sender, args) => + { + if (args.Position == 0 && null != Open) //position open + Open(this, EventArgs.Empty); + else if (args.Position == 2 && null != Close) //position close + Close(this, EventArgs.Empty); + }; + + _viewAbove.Opened += (sender, args) => { if (null != Opened) Opened(sender, args); }; + _viewAbove.Closed += (sender, args) => { if (null != Closed) Closed(sender, args); }; + + var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SlidingMenu); + var mode = a.GetInt(Resource.Styleable.SlidingMenu_mode, (int) MenuMode.Left); + Mode = (MenuMode) mode; + + var viewAbove = a.GetResourceId(Resource.Styleable.SlidingMenu_viewAbove, -1); + if (viewAbove != -1) + SetContent(viewAbove); + else + SetContent(new FrameLayout(context)); + + TouchModeAbove = (TouchMode)a.GetInt(Resource.Styleable.SlidingMenu_touchModeAbove, (int)TouchMode.Margin); + TouchModeBehind = (TouchMode)a.GetInt(Resource.Styleable.SlidingMenu_touchModeBehind, (int)TouchMode.Margin); + + var offsetBehind = (int) a.GetDimension(Resource.Styleable.SlidingMenu_behindOffset, -1); + var widthBehind = (int) a.GetDimension(Resource.Styleable.SlidingMenu_behindWidth, -1); + if (offsetBehind != -1 && widthBehind != -1) + throw new ArgumentException("Cannot set both behindOffset and behindWidth for SlidingMenu, check your XML"); + if (offsetBehind != -1) + BehindOffset = offsetBehind; + else if (widthBehind != -1) + BehindWidth = widthBehind; + else + BehindOffset = 0; + + var shadowRes = a.GetResourceId(Resource.Styleable.SlidingMenu_shadowDrawable, -1); + if (shadowRes != -1) + ShadowDrawableRes = shadowRes; + + BehindScrollScale = a.GetFloat(Resource.Styleable.SlidingMenu_behindScrollScale, 0.33f); + ShadowWidth = ((int)a.GetDimension(Resource.Styleable.SlidingMenu_shadowWidth, 0)); + FadeEnabled = a.GetBoolean(Resource.Styleable.SlidingMenu_fadeEnabled, true); + FadeDegree = a.GetFloat(Resource.Styleable.SlidingMenu_fadeDegree, 0.33f); + SelectorEnabled = a.GetBoolean(Resource.Styleable.SlidingMenu_selectorEnabled, false); + var selectorRes = a.GetResourceId(Resource.Styleable.SlidingMenu_selectorDrawable, -1); + if (selectorRes != -1) + SelectorDrawable = selectorRes; + + a.Recycle(); + } + + public void AttachToActivity(Activity activity, SlideStyle slideStyle) + { + AttachToActivity(activity, slideStyle, false); + } + + public void AttachToActivity(Activity activity, SlideStyle slideStyle, bool actionbarOverlay) + { + if (Parent != null) + throw new ArgumentException("This SlidingMenu appears to already be attached"); + + // get the window background + var a = activity.Theme.ObtainStyledAttributes(new[] { Android.Resource.Attribute.WindowBackground }); + var background = a.GetResourceId(0, 0); + a.Recycle(); + + switch (slideStyle) + { + case SlideStyle.Window: + _mActionbarOverlay = false; + var decor = (ViewGroup)activity.Window.DecorView; + var decorChild = (ViewGroup)decor.GetChildAt(0); + // save ActionBar themes that have transparent assets + decorChild.SetBackgroundResource(background); + decor.RemoveView(decorChild); + decor.AddView(this); + SetContent(decorChild); + break; + case SlideStyle.Content: + _mActionbarOverlay = actionbarOverlay; + // take the above view out of + var contentParent = (ViewGroup)activity.FindViewById(Android.Resource.Id.Content); + var content = contentParent.GetChildAt(0); + contentParent.RemoveView(content); + contentParent.AddView(this); + SetContent(content); + // save people from having transparent backgrounds + if (content.Background == null) + content.SetBackgroundResource(background); + break; + } + } + + public void SetContent(int res) + { + SetContent(LayoutInflater.From(Context).Inflate(res, null)); + } + + public void SetContent(View view) + { + _viewAbove.Content = view; + ShowContent(); + } + + public View GetContent() + { + return _viewAbove.Content; + } + + public void SetMenu(int res) + { + SetMenu(LayoutInflater.From(Context).Inflate(res, null)); + } + + public void SetMenu(View v) + { + _viewBehind.Content = v; + } + + public View GetMenu() + { + return _viewBehind.Content; + } + + public void SetSecondaryMenu(int res) + { + SetSecondaryMenu(LayoutInflater.From(Context).Inflate(res, null)); + } + + public void SetSecondaryMenu(View v) + { + _viewBehind.SecondaryContent = v; + } + + public View GetSecondaryMenu() + { + return _viewBehind.SecondaryContent; + } + + public bool IsSlidingEnabled + { + get { return _viewAbove.IsSlidingEnabled; } + set { _viewAbove.IsSlidingEnabled = value; } + } + + public MenuMode Mode + { + get { return _viewBehind.Mode; } + set + { + if (value != MenuMode.Left && value != MenuMode.Right && value != MenuMode.LeftRight) + { + throw new ArgumentException("SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT", "value"); + } + _viewBehind.Mode = value; + } + } + + public bool Static + { + set + { + if (value) + { + IsSlidingEnabled = false; + _viewAbove.CustomViewBehind = null; + _viewAbove.SetCurrentItem(1); + } + else + { + _viewAbove.SetCurrentItem(1); + _viewAbove.CustomViewBehind = _viewBehind; + IsSlidingEnabled = true; + } + } + } + + public void ShowMenu() + { + ShowMenu(true); + } + + public void ShowMenu(bool animate) + { + _viewAbove.SetCurrentItem(0, animate); + } + + public void ShowSecondaryMenu() + { + ShowSecondaryMenu(true); + } + + public void ShowSecondaryMenu(bool animate) + { + _viewAbove.SetCurrentItem(2, animate); + } + + public void ShowContent(bool animate = true) + { + _viewAbove.SetCurrentItem(1, animate); + } + + public void Toggle() + { + Toggle(true); + } + + public void Toggle(bool animate) + { + if (IsMenuShowing) + { + ShowContent(animate); + } + else + { + ShowMenu(animate); + } + } + + public bool IsMenuShowing + { + get { return _viewAbove.GetCurrentItem() == 0 || _viewAbove.GetCurrentItem() == 2; } + } + + public bool IsSecondaryMenuShowing + { + get { return _viewAbove.GetCurrentItem() == 2; } + } + + public int BehindOffset + { + get { return _viewBehind.WidthOffset; } + set + { + _viewBehind.WidthOffset = value; + } + } + + public int BehindOffsetRes + { + set + { + var i = (int) Context.Resources.GetDimension(value); + BehindOffset = i; + } + } + + public int AboveOffset + { + set { _viewAbove.AboveOffset = value; } + } + + public int AboveOffsetRes + { + set + { + var i = (int) Context.Resources.GetDimension(value); + AboveOffset = i; + } + } + + public int BehindWidth + { + set + { + var windowService = Context.GetSystemService(Context.WindowService); + var windowManager = windowService.JavaCast(); + var width = windowManager.DefaultDisplay.Width; + BehindOffset = width - value; + } + } + + public int BehindWidthRes + { + set + { + var i = (int)Context.Resources.GetDimension(value); + BehindWidth = i; + } + } + + public float BehindScrollScale + { + get { return _viewBehind.ScrollScale; } + set + { + if (value < 0f && value > 1f) + throw new ArgumentOutOfRangeException("value", "ScrollScale must be between 0f and 1f"); + _viewBehind.ScrollScale = value; + } + } + + public int TouchmodeMarginThreshold + { + get { return _viewBehind.MarginThreshold; } + set { _viewBehind.MarginThreshold = value; } + } + + public TouchMode TouchModeAbove + { + get { return _viewAbove.TouchMode; } + set + { + if (value != TouchMode.Fullscreen && value != TouchMode.Margin + && value != TouchMode.None) + { + throw new ArgumentException("TouchMode must be set to either" + + "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.", "value"); + } + _viewAbove.TouchMode = value; + } + } + + public TouchMode TouchModeBehind + { + set + { + if (value != TouchMode.Fullscreen && value != TouchMode.Margin + && value != TouchMode.None) + { + throw new ArgumentException("TouchMode must be set to either" + + "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.", "value"); + } + _viewBehind.TouchMode = value; + } + } + + public int ShadowDrawableRes + { + set { _viewBehind.ShadowDrawable = Context.Resources.GetDrawable(value); } + } + + public Drawable ShadowDrawable + { + set { _viewBehind.ShadowDrawable = value; } + } + + public int SecondaryShadowDrawableRes + { + set { _viewBehind.SecondaryShadowDrawable = Context.Resources.GetDrawable(value); } + } + + public Drawable SecondaryShadowDrawable + { + set { _viewBehind.SecondaryShadowDrawable = value; } + } + + public int ShadowWidthRes + { + set { ShadowWidth = (int)Context.Resources.GetDimension(value); } + } + + public int ShadowWidth + { + set { _viewBehind.ShadowWidth = value; } + } + + public bool FadeEnabled + { + set { _viewBehind.FadeEnabled = value; } + } + + public float FadeDegree + { + set { _viewBehind.FadeDegree = value; } + } + + public bool SelectorEnabled + { + set { _viewBehind.SelectorEnabled = value; } + } + + public View SelectedView + { + set { _viewBehind.SelectedView = value; } + } + + public int SelectorDrawable + { + set { SelectorBitmap = BitmapFactory.DecodeResource(Resources, value); } + } + + public Bitmap SelectorBitmap + { + set { _viewBehind.SelectorBitmap = value; } + } + + public void AddIgnoredView(View v) + { + _viewAbove.AddIgnoredView(v); + } + + public void RemoveIgnoredView(View v) + { + _viewAbove.RemoveIgnoredView(v); + } + + public void ClearIgnoredViews() + { + _viewAbove.ClearIgnoredViews(); + } + + public ICanvasTransformer BehindCanvasTransformer + { + set { _viewBehind.CanvasTransformer = value; } + } + + public class SavedState : BaseSavedState + { + public int Item { get; private set; } + + public SavedState(IParcelable superState) + : base(superState) + { + + } + + public SavedState(Parcel parcel) + : base(parcel) + { + Item = parcel.ReadInt(); + } + + public override void WriteToParcel(Parcel dest, ParcelableWriteFlags flags) + { + base.WriteToParcel(dest, flags); + dest.WriteInt(Item); + } + + [ExportField("CREATOR")] + static SavedStateCreator InitializeCreator() + { + return new SavedStateCreator(); + } + + class SavedStateCreator : Java.Lang.Object, IParcelableCreator + { + public Java.Lang.Object CreateFromParcel(Parcel source) + { + return new SavedState(source); + } + + public Java.Lang.Object[] NewArray(int size) + { + return new SavedState[size]; + } + } + } + + protected override void OnRestoreInstanceState(IParcelable state) + { + try + { + Bundle bundle = state as Bundle; + if (bundle != null) + { + IParcelable superState = (IParcelable)bundle.GetParcelable("base"); + if (superState != null) + base.OnRestoreInstanceState(superState); + _viewAbove.SetCurrentItem(bundle.GetInt("currentPosition", 0)); + } + } + catch + { + base.OnRestoreInstanceState(state); + // Ignore, this needs to support IParcelable... + } + } + + protected override IParcelable OnSaveInstanceState() + { + var superState = base.OnSaveInstanceState(); + Bundle state = new Bundle(); + state.PutParcelable("base", superState); + state.PutInt("currentPosition", _viewAbove.GetCurrentItem()); + + return state; + } + + protected override bool FitSystemWindows(Rect insets) + { + if (!_mActionbarOverlay) + { + Log.Verbose(Tag, "setting padding"); + SetPadding(insets.Left, insets.Top, insets.Right, insets.Bottom); + } + return true; + } + +#if __ANDROID_11__ + public void ManageLayers(float percentOpen) + { + if ((int) Build.VERSION.SdkInt < 11) return; + + var layer = percentOpen > 0.0f && percentOpen < 1.0f; + var layerType = layer ? LayerType.Hardware : LayerType.None; + + if (layerType != GetContent().LayerType) + { + Handler.Post(() => + { + Log.Verbose(Tag, "changing layerType, hardware? " + (layerType == LayerType.Hardware)); + GetContent().SetLayerType(layerType, null); + GetMenu().SetLayerType(layerType, null); + if (GetSecondaryMenu() != null) + GetSecondaryMenu().SetLayerType(layerType, null); + }); + } + } +#endif + } +} diff --git a/SlidingMenuSharp/SlidingMenuEventArgs.cs b/SlidingMenuSharp/SlidingMenuEventArgs.cs index 8803d55..47738d3 100644 --- a/SlidingMenuSharp/SlidingMenuEventArgs.cs +++ b/SlidingMenuSharp/SlidingMenuEventArgs.cs @@ -1,36 +1,36 @@ -/* - * Copyright 2013-2014 Tomasz Cielecki - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -using System; - -namespace SlidingMenuSharp -{ - public class PageSelectedEventArgs : EventArgs - { - public int Position { get; set; } - } - - public class PageScrolledEventArgs : PageSelectedEventArgs - { - public float PositionOffset { get; set; } - public int PositionOffsetPixels { get; set; } - } - - public class PageScrollStateChangedEventArgs : EventArgs - { - public int State { get; set; } - } +/* + * Copyright 2013-2014 Tomasz Cielecki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +using System; + +namespace SlidingMenuSharp +{ + public class PageSelectedEventArgs : EventArgs + { + public int Position { get; set; } + } + + public class PageScrolledEventArgs : PageSelectedEventArgs + { + public float PositionOffset { get; set; } + public int PositionOffsetPixels { get; set; } + } + + public class PageScrollStateChangedEventArgs : EventArgs + { + public int State { get; set; } + } } \ No newline at end of file diff --git a/SlidingMenuSharp/SlidingMenuSharp.csproj b/SlidingMenuSharp/SlidingMenuSharp.csproj index 333c79d..1aa4141 100644 --- a/SlidingMenuSharp/SlidingMenuSharp.csproj +++ b/SlidingMenuSharp/SlidingMenuSharp.csproj @@ -14,7 +14,9 @@ 512 Resources\Resource.Designer.cs Off - v2.2 + v12.0 + + true @@ -34,6 +36,7 @@ 4 + @@ -41,8 +44,92 @@ - - ..\Components\xamandroidsupportv4-18-4.18.1\lib\android\Xamarin.Android.Support.v4.dll + + ..\packages\Xamarin.Android.Arch.Core.Common.1.1.1.3\lib\monoandroid90\Xamarin.Android.Arch.Core.Common.dll + + + ..\packages\Xamarin.Android.Arch.Core.Runtime.1.1.1.3\lib\monoandroid90\Xamarin.Android.Arch.Core.Runtime.dll + + + ..\packages\Xamarin.Android.Arch.Lifecycle.Common.1.1.1.3\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.Common.dll + + + ..\packages\Xamarin.Android.Arch.Lifecycle.LiveData.1.1.1.3\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.LiveData.dll + + + ..\packages\Xamarin.Android.Arch.Lifecycle.LiveData.Core.1.1.1.3\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.LiveData.Core.dll + + + ..\packages\Xamarin.Android.Arch.Lifecycle.Runtime.1.1.1.3\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.Runtime.dll + + + ..\packages\Xamarin.Android.Arch.Lifecycle.ViewModel.1.1.1.3\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.ViewModel.dll + + + ..\packages\Xamarin.Android.Support.Annotations.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Annotations.dll + + + ..\packages\Xamarin.Android.Support.AsyncLayoutInflater.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.AsyncLayoutInflater.dll + + + ..\packages\Xamarin.Android.Support.Collections.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Collections.dll + + + ..\packages\Xamarin.Android.Support.Compat.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Compat.dll + + + ..\packages\Xamarin.Android.Support.CoordinaterLayout.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.CoordinaterLayout.dll + + + ..\packages\Xamarin.Android.Support.Core.UI.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Core.UI.dll + + + ..\packages\Xamarin.Android.Support.Core.Utils.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Core.Utils.dll + + + ..\packages\Xamarin.Android.Support.CursorAdapter.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.CursorAdapter.dll + + + ..\packages\Xamarin.Android.Support.CustomView.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.CustomView.dll + + + ..\packages\Xamarin.Android.Support.DocumentFile.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.DocumentFile.dll + + + ..\packages\Xamarin.Android.Support.DrawerLayout.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.DrawerLayout.dll + + + ..\packages\Xamarin.Android.Support.Fragment.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Fragment.dll + + + ..\packages\Xamarin.Android.Support.Interpolator.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Interpolator.dll + + + ..\packages\Xamarin.Android.Support.Loader.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Loader.dll + + + ..\packages\Xamarin.Android.Support.LocalBroadcastManager.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.LocalBroadcastManager.dll + + + ..\packages\Xamarin.Android.Support.Media.Compat.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Media.Compat.dll + + + ..\packages\Xamarin.Android.Support.Print.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.Print.dll + + + ..\packages\Xamarin.Android.Support.SlidingPaneLayout.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.SlidingPaneLayout.dll + + + ..\packages\Xamarin.Android.Support.SwipeRefreshLayout.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.SwipeRefreshLayout.dll + + + ..\packages\Xamarin.Android.Support.v4.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.v4.dll + + + ..\packages\Xamarin.Android.Support.VersionedParcelable.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.VersionedParcelable.dll + + + ..\packages\Xamarin.Android.Support.ViewPager.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.ViewPager.dll @@ -63,6 +150,7 @@ + @@ -71,21 +159,78 @@ - - - False - 4.18.1 - - - \ No newline at end of file diff --git a/SlidingMenuSharp/packages.config b/SlidingMenuSharp/packages.config new file mode 100644 index 0000000..76fa828 --- /dev/null +++ b/SlidingMenuSharp/packages.config @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file