Skip to content

Commit

Permalink
[ApiDemo] Start to cover additions from Googles latest 'ApiDemos' ite…
Browse files Browse the repository at this point in the history
…ration

Update and begin porting newly offered APIs and examples from Googles ApiDemos sample
  • Loading branch information
pjcollins committed Aug 27, 2013
1 parent 89f6112 commit b019a60
Show file tree
Hide file tree
Showing 582 changed files with 22,619 additions and 2,115 deletions.
2 changes: 1 addition & 1 deletion ApiDemo/ApiDemo.cs
Expand Up @@ -27,7 +27,7 @@

namespace MonoDroid.ApiDemo
{
[Activity (Label = "Mono API Demos", MainLauncher = true, Icon = "@drawable/icon")]
[Activity (Label = "Api Demo (XA)", MainLauncher = true)]
public class ApiDemo : ListActivity
{
public const string SAMPLE_CATEGORY = "mono.apidemo.sample";
Expand Down
606 changes: 528 additions & 78 deletions ApiDemo/ApiDemo.csproj

Large diffs are not rendered by default.

39 changes: 30 additions & 9 deletions ApiDemo/App/ActionBarDisplayOptions.cs
Expand Up @@ -15,7 +15,6 @@
*/

// This sample only works on Android API 11+
#if __ANDROID_11__

using System;

Expand All @@ -24,20 +23,20 @@
using Android.OS;
using Android.Views;

namespace MonoDroid.ApiDemo.App
namespace MonoDroid.ApiDemo
{
// This demo shows how various action bar display option flags can be combined and their effects.
[Activity (Label = "App/Action Bar Display Options")]
[Activity (Label = "@string/action_bar_display_options")]
[IntentFilter (new[] { Intent.ActionMain }, Categories = new string[] { ApiDemo.SAMPLE_CATEGORY })]
public class ActionBarDisplayOptionsActivity : Activity, Android.App.ActionBar.ITabListener
public class ActionBarDisplayOptionsActivity : Activity, ActionBar.ITabListener
{
private View custom_view;

protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

SetContentView (Resource.Layout.ActionBarDisplayOptions);
Window.RequestFeature (WindowFeatures.ActionBar);
SetContentView (Resource.Layout.action_bar_display_options);

// Set up handlers for each of our buttons
var home_as_up = FindViewById (Resource.Id.toggle_home_as_up);
Expand All @@ -64,7 +63,24 @@ protected override void OnCreate (Bundle bundle)
var cycle_gravity = FindViewById (Resource.Id.cycle_custom_gravity);
cycle_gravity.Click += CycleGravity;

custom_view = LayoutInflater.Inflate (Resource.Layout.ActionBarDisplayOptionsCustom, null);
var visibility = FindViewById (Resource.Id.toggle_visibility);
visibility.Click += delegate {
if (ActionBar.IsShowing)
ActionBar.Hide ();
else
ActionBar.Show ();
};

var system_ui = FindViewById (Resource.Id.toggle_system_ui);
system_ui.Click += delegate {

if ((Window.DecorView.SystemUiVisibility & (StatusBarVisibility) SystemUiFlags.Fullscreen) != 0)
Window.DecorView.SystemUiVisibility = 0;
else
Window.DecorView.SystemUiVisibility = (StatusBarVisibility) SystemUiFlags.Fullscreen;
};

custom_view = LayoutInflater.Inflate (Resource.Layout.action_bar_display_options_custom, null);

// Configure several action bar elements that will be toggled by display options.
ActionBar.SetCustomView (custom_view, new ActionBar.LayoutParams (WindowManagerLayoutParams.WrapContent, WindowManagerLayoutParams.WrapContent));
Expand All @@ -85,6 +101,12 @@ protected override void OnCreate (Bundle bundle)
ActionBar.AddTab (tab3);
}

public override bool OnCreateOptionsMenu (IMenu menu)
{
MenuInflater.Inflate (Resource.Menu.display_options_actions, menu);
return true;
}

private void AddActionBarFlag (ActionBarDisplayOptions flag)
{
var bar = ActionBar;
Expand Down Expand Up @@ -129,5 +151,4 @@ public void OnTabUnselected (ActionBar.Tab tab, FragmentTransaction ft)
}
#endregion
}
}
#endif
}
11 changes: 3 additions & 8 deletions ApiDemo/App/ActionBarMechanics.cs
Expand Up @@ -15,8 +15,6 @@
*/

// This sample only works on Android API 11+
#if __ANDROID_11__

using System;

using Android.App;
Expand All @@ -25,17 +23,15 @@
using Android.Views;
using Android.Widget;

namespace MonoDroid.ApiDemo.App
namespace MonoDroid.ApiDemo
{
// This demonstrates the basics of the Action Bar and how it interoperates with the
// standard options menu. This demo is for informative purposes only; see ActionBarUsage for
// an example of using the Action Bar in a more idiomatic manner.
[Activity (Label = "App/Action Bar Mechanics")]
[Activity (Label = "@string/action_bar_mechanics")]
[IntentFilter (new[] { Intent.ActionMain }, Categories = new string[] { ApiDemo.SAMPLE_CATEGORY })]
public class ActionBarMechanics : Activity
{
private View custom_view;

protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
Expand Down Expand Up @@ -80,5 +76,4 @@ public override bool OnOptionsItemSelected (IMenuItem item)
return true;
}
}
}
#endif
}
101 changes: 101 additions & 0 deletions ApiDemo/App/ActionBarSettingsActionProviderActivity.cs
@@ -0,0 +1,101 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* 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.
*/

// This sample only works on Android API 14+
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Provider;

namespace MonoDroid.ApiDemo
{
/**
* This activity demonstrates how to implement an {@link android.view.ActionProvider}
* for adding functionality to the Action Bar. In particular this demo creates an
* ActionProvider for launching the system settings and adds a menu item with that
* provider.
*/
[Activity (Label = "@string/action_bar_settings_action_provider")]
[IntentFilter (new[] { Intent.ActionMain }, Categories = new string[] { ApiDemo.SAMPLE_CATEGORY })]
public class ActionBarSettingsActionProviderActivity : Activity
{
public override bool OnCreateOptionsMenu (IMenu menu)
{
base.OnCreateOptionsMenu (menu);
MenuInflater.Inflate (Resource.Menu.action_bar_settings_action_provider, menu);
return true;
}

public override bool OnOptionsItemSelected (IMenuItem item)
{
// If this callback does not handle the item click, onPerformDefaultAction
// of the ActionProvider is invoked. Hence, the provider encapsulates the
// complete functionality of the menu item.
Toast.MakeText (this, Resource.String.action_bar_settings_action_provider_no_handling,
ToastLength.Short).Show ();
return false;
}
}

public class SettingsActionProvider : ActionProvider
{
/** An intent for launching the system settings. */
static Intent sSettingsIntent = new Intent (Settings.ActionSettings);
/** Context for accessing resources. */
Context mContext;

/**
* Creates a new instance.
*
* @param context Context for accessing resources.
*/
public SettingsActionProvider (Context context) : base (context)
{
mContext = context;
}

public override View OnCreateActionView ()
{
// Inflate the action view to be shown on the action bar.
LayoutInflater layoutInflater = LayoutInflater.From (mContext);
View view = layoutInflater.Inflate (Resource.Layout.action_bar_settings_action_provider, null);

ImageButton button = view.FindViewById <ImageButton> (Resource.Id.button);

// Attach a click listener for launching the system settings.
button.Click += delegate {
mContext.StartActivity (sSettingsIntent);
};

return view;
}

public override bool OnPerformDefaultAction ()
{
// This is called if the host menu item placed in the overflow menu of the
// action bar is clicked and the host activity did not handle the click.
mContext.StartActivity (sSettingsIntent);
return true;
}
}
}
Expand Up @@ -15,12 +15,11 @@
*/

// This sample only works on Android API 14+
#if __ANDROID_14__

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Android.App;
using Android.Content;
Expand All @@ -29,27 +28,28 @@
using Android.Views;
using Android.Widget;

namespace MonoDroid.ApiDemo.App
namespace MonoDroid.ApiDemo
{
// This activity demonstrates how to use an {@link android.view.ActionProvider}
// for adding functionality to the Action Bar. In particular this demo is adding
// a menu item with ShareActionProvider as its action provider. The
// ShareActionProvider is responsible for managing the UI for sharing actions.
[Activity (Label = "App/Action Bar Action Provider")]
[Activity (Label = "@string/action_bar_share_action_provider")]
[IntentFilter (new[] { Intent.ActionMain }, Categories = new string[] { ApiDemo.SAMPLE_CATEGORY })]
public class ActionBarActionProviderActivity : Activity
public class ActionBarShareActionProviderActivity : Activity
{
private string shared_file_name = "shared.png";

protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
CopyPrivateRawResourceToPubliclyAccessibleFile ();
}

public override bool OnCreateOptionsMenu (IMenu menu)
{
// Inflate the menu
MenuInflater.Inflate (Resource.Menu.ActionBarActionProvider, menu);
MenuInflater.Inflate (Resource.Menu.action_bar_share_action_provider, menu);

// Set file with share history to the provider and set the share intent.
var action_item = menu.FindItem (Resource.Id.menu_item_share_action_provider_action_bar);
Expand Down Expand Up @@ -84,6 +84,38 @@ private Intent CreateShareIntent ()

return shareIntent;
}

void CopyPrivateRawResourceToPubliclyAccessibleFile ()
{
Stream inputStream = null;
Stream outputStream = null;

try {
inputStream = Resources.OpenRawResource (Resource.Raw.robot);
outputStream = OpenFileOutput (shared_file_name, FileCreationMode.WorldReadable | FileCreationMode.Append);
byte[] buffer = new byte[1024];
int length = 0;
try {
while ((length = inputStream.Read (buffer, 0, buffer.Length)) > 0) {
outputStream.Write (buffer, 0, length);
}
} catch (IOException) {
/* ignore */
}
} catch (FileNotFoundException) {
/* ignore */
} finally {
try {
inputStream.Close ();
} catch (IOException) {
/* ignore */
}
try {
outputStream.Close ();
} catch (IOException) {
/* ignore */
}
}
}
}
}
#endif
}
11 changes: 4 additions & 7 deletions ApiDemo/App/ActivityRecreate.cs
Expand Up @@ -15,8 +15,6 @@
*/

// This sample only works on Android API 11+
#if __ANDROID_11__

using System;

using Android.App;
Expand All @@ -25,9 +23,9 @@
using Android.Views;
using Android.Widget;

namespace MonoDroid.ApiDemo.App
namespace MonoDroid.ApiDemo
{
[Activity (Label = "App/Activity Recreate")]
[Activity (Label = "@string/activity_recreate")]
[IntentFilter (new[] { Intent.ActionMain }, Categories = new string[] { ApiDemo.SAMPLE_CATEGORY })]
public class ActivityRecreate : Activity
{
Expand Down Expand Up @@ -55,7 +53,7 @@ protected override void OnCreate (Bundle bundle)
SetTheme (current_theme);
}

SetContentView (Resource.Layout.ActivityRecreate);
SetContentView (Resource.Layout.activity_recreate);

// Watch for button clicks
var button = FindViewById<Button> (Resource.Id.recreate);
Expand All @@ -69,5 +67,4 @@ protected override void OnSaveInstanceState (Bundle outState)
outState.PutInt ("theme", current_theme);
}
}
}
#endif
}

0 comments on commit b019a60

Please sign in to comment.