本文整理汇总了C#中Android.App.Activity.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Activity.GetType方法的具体用法?C# Activity.GetType怎么用?C# Activity.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.App.Activity
的用法示例。
在下文中一共展示了Activity.GetType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
public void Bind(Activity activity)
{
if (activity == null)
throw new ArgumentNullException();
activity.SetContentView(ResourceId);
if (BindOutlets)
{
FieldInfo[] fields = activity.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (FieldInfo field in fields)
{
object[] outlets = field.GetCustomAttributes(typeof(OutletAttribute), false);
if (outlets.Length == 0)
continue;
OutletAttribute outlet = (OutletAttribute) outlets[0];
field.SetValue(activity, activity.FindViewById(outlet.ResourceId));
}
}
if (BindActions)
{
MethodInfo[] methods = activity.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (MethodInfo method in methods)
{
object[] actions = method.GetCustomAttributes(typeof(ActionAttribute), false);
if (actions.Length == 0)
continue;
foreach (ActionAttribute action in actions)
{
try
{
FieldInfo field = activity.GetType().GetField(action.Field, BindingFlags.NonPublic | BindingFlags.Instance);
if (field == null)
throw new Exception();
EventInfo handler = field.FieldType.GetEvent(action.Handler, BindingFlags.Public | BindingFlags.Instance);
if (handler == null)
throw new Exception();
handler.AddEventHandler(field.GetValue(activity), Delegate.CreateDelegate(handler.EventHandlerType, activity, method));
}
catch
{
Console.WriteLine("Can't bind {0}.{1} with {2}", action.Field, action.Handler, method.Name);
continue;
}
}
}
}
}
示例2: ActivityRoutedViewHost
public ActivityRoutedViewHost(Activity hostActivity)
{
var keyUp = hostActivity.GetType()
.GetMethods(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Instance)
.FirstOrDefault(x => x.Name == "OnKeyUp");
if (keyUp == null) {
throw new Exception("You must override OnKeyUp and call theRoutedViewHost.OnKeyUp");
}
var viewFor = hostActivity as IViewFor;
if (viewFor == null) {
throw new Exception("You must implement IViewFor<TheViewModelClass>");
}
bool firstSet = false;
_inner = _hostScreen.Router.ViewModelObservable()
.Where(x => x != null)
.Subscribe(vm => {
if (!firstSet) {
viewFor.ViewModel = vm;
firstSet = true;
return;
}
var view = RxRouting.ResolveView(vm);
if (view.GetType() != typeof(Type)) {
throw new Exception("Views in Android must be the Type of an Activity");
}
hostActivity.StartActivity((Type)view);
});
}
示例3: InvalidateOptionsMenu
public static void InvalidateOptionsMenu(Activity act)
{
try {
_invalidateOptMenuMethod = act.GetType().GetMethod("InvalidateOptionsMenu", new Type[]{});
} catch (Exception)
{
// Do nothing if method doesn't exist
}
if (_invalidateOptMenuMethod != null) {
try {
_invalidateOptMenuMethod.Invoke(act, (new Object[]{}));
} catch (Exception)
{
// Do nothing
}
}
}
示例4: ActivityRoutedViewHost
public ActivityRoutedViewHost(Activity hostActivity, IViewLocator viewLocator = null)
{
viewLocator = viewLocator ?? ViewLocator.Current;
var platform = RxApp.DependencyResolver.GetService<IPlatformOperations>();
var keyUp = hostActivity.GetType()
.GetMethods(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Instance)
.FirstOrDefault(x => x.Name == "OnKeyUp");
if (keyUp == null) {
throw new Exception("You must override OnKeyUp and call theRoutedViewHost.OnKeyUp");
}
var viewFor = hostActivity as IViewFor;
if (viewFor == null) {
throw new Exception("You must implement IViewFor<TheViewModelClass>");
}
bool firstSet = false;
_inner = _hostScreen.Router.CurrentViewModel
.Where(x => x != null)
.Subscribe(vm => {
if (!firstSet) {
viewFor.ViewModel = vm;
firstSet = true;
return;
}
var view = viewLocator.ResolveView(vm, platform.GetOrientation());
if (view.GetType() != typeof(Type)) {
throw new Exception("Views in Android must be the Type of an Activity");
}
hostActivity.StartActivity((Type)view);
});
}
示例5: StartActivity
private void StartActivity(Activity sourceActivity, Type activityType)
{
var intent = new Intent(sourceActivity, activityType);
intent.PutExtra("sourceActivity", sourceActivity.GetType().FullName);
sourceActivity.StartActivity(intent);
}
示例6: OnAttached
public void OnAttached(Activity activity)
{
var actionBar = activity.GetActionBar();
if (actionBar == null)
{
Tracer.Error("Cannot apply ActionBarView the ActionBar is null, activity {0}", activity.GetType().FullName);
return;
}
var activityView = activity as IActivityView;
if (activityView != null)
activityView.Mediator.Destroyed += DestroyedHandler;
if (_resourceId != int.MinValue)
{
if (_tabContentId != int.MinValue)
ServiceProvider.AttachedValueProvider.SetValue(actionBar, TabContentIdKey, _tabContentId);
using (XmlReader reader = Context.Resources.GetLayout(_resourceId))
{
//NOTE XDocument throws an error.
var document = new XmlDocument();
document.Load(reader);
using (var stringReader = new StringReader(PlatformExtensions.XmlTagsToUpper(document.InnerXml)))
{
var barTemplate = (ActionBarTemplate)Serializer.Deserialize(stringReader);
barTemplate.Apply(activity);
}
}
}
if (_bindings == null)
return;
for (int i = 0; i < _bindings.Count; i++)
BindingServiceProvider.BindingProvider.CreateBindingsFromString(actionBar, _bindings[i], null);
this.RemoveFromParent();
this.ClearBindingsRecursively(true, true);
}
示例7: TagScreen
/// <summary>
/// Tag screen using type of activity as name.
/// </summary>
/// <param name="activity">Activity which's type name to use for TagScreen.</param>
public void TagScreen(Activity activity)
{
if (!IsEnabled)
return;
if (null == activity)
throw new ArgumentNullException("activity");
var activityType = activity.GetType();
var screen = activityType.Name;
TagScreen(screen);
}
示例8: GetActivityName
private static string GetActivityName(Activity activity)
{
return activity.GetType().Name;
}