I want to show my screen during the incoming call.
Is there is any way to override the InCall Screen in Blackberry?
You can make use of PhoneListener interface and then override the methods to do the same.
public class CatchCall extends Application implements PhoneListener {
boolean yes = false;
int st;
public CatchCall() {
Phone.addPhoneListener(this);
}
public static void main(String[] args) {
new CatchCall().enterEventDispatcher();
}
public void callAdded(int callId) {
}
public void callAnswered(int callId) {
}
public void callConferenceCallEstablished(int callId) {
}
public void callConnected(int callId) {
// TODO Auto-generated method s
PhoneCall phoneCall = Phone.getCall(callId);
if (phoneCall != null) {
//TODO: push your screen here
Dialog.ask(Dialog.D_YES_NO, "Push my screen here");
}
}
public void callDirectConnectConnected(int callId) {
}
public void callDirectConnectDisconnected(int callId) {
}
public void callDisconnected(int callId) {
}
public void callEndedByUser(int callId) {
}
public void callFailed(int callId, int reason) {
}
public void callHeld(int callId) {
}
public void callIncoming(int callId) {
//TODO: push your screen here
Dialog.ask(Dialog.D_YES_NO, "Push my screen here");
}
public void callInitiated(int callid) {
PhoneCall phoneCall = Phone.getCall(callid);
if (phoneCall != null) {
//TODO: push your screen here
Dialog.ask(Dialog.D_YES_NO, "Push my screen here");
}
}
public void callRemoved(int callId) {
}
public void callResumed(int callId) {
}
public void callWaiting(int callid) {
}
public void conferenceCallDisconnected(int callId) {
}
}
Related
I am building a multi-column picker control, and I have some issues with the xamarin.ios renderer.
I have two columns in the picker. One for the month and another for the year. I have got the values binded to the picker control properly. However when I make a selection the app crashes.
The error is Specified cast is not valid.
Stacktrace is
at Xamarin.Forms.Platform.iOS.PickerRendererBase`1[TControl].OnEnded
(System.Object sender, System.EventArgs eventArgs) [0x0000b] in
<0648e2dffe9e4201b8c6e274ced6579f>:0 at
UIKit.UIControlEventProxy.Activated () [0x00004] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.16.0.5/src/Xamarin.iOS/UIKit/UIControl.cs:38
My ios Custom Renderer code is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using CoreGraphics;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(YearMonthPicker), typeof(YearMonthPickerRenderer))]
namespace TestApp.iOS.Renderers
{
public class YearMonthPickerRenderer : PickerRenderer
{
private MonthYear _monthYear = new MonthYear();
private UILabel _monthLabel;
private UILabel _yearLabel;
public YearMonthPickerRenderer()
{
_monthYear.Months = new List<string>();
_monthYear.Years = new List<int>();
InitValues();
}
private void InitValues()
{
_monthYear.Months = new List<string>{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"Sepetember",
"October",
"November",
"December"
};
}
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var customPicker = e.NewElement as YearMonthPicker;
var startYear = customPicker.StartYear;
var endYear = customPicker.EndYear;
do
{
_monthYear.Years.Add(startYear);
startYear++;
} while (startYear <= endYear);
if (_monthLabel == null)
{
_monthLabel = new UILabel();
_monthLabel.Text = customPicker.MonthLabel;
_monthLabel.TextColor = customPicker.LabelColor.ToUIColor();
_monthLabel.Font = _monthLabel.Font.WithSize(14.0f);
}
if (_yearLabel == null)
{
_yearLabel = new UILabel();
_yearLabel.Text = customPicker.YearLabel;
_yearLabel.TextColor = customPicker.LabelColor.ToUIColor();
_yearLabel.Font = _yearLabel.Font.WithSize(14.0f);
}
if (Control is UITextField textField)
{
var pickerView = textField.InputView as UIPickerView;
var yearMonthModel = new YearMonthModel(textField, _monthYear);
var yearMonthDelegate = new YearMonthPickerDelegate(textField, _monthYear);
pickerView.Model = yearMonthModel;
pickerView.Delegate = yearMonthDelegate;
textField.BorderStyle = UITextBorderStyle.None;
textField.AddSubview(_monthLabel);
textField.AddSubview(_yearLabel);
}
}
var toolbar = new UIToolbar(new CGRect(0.0f, 0.0f, Control.Frame.Size.Width, 44.0f));
toolbar.Items = new[]
{
new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
new UIBarButtonItem("Done",
UIBarButtonItemStyle.Done,
delegate {
Control.ResignFirstResponder();
})
};
if (this.Control != null)
{
Control.InputAccessoryView = toolbar;
}
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
_monthLabel.Frame = new CGRect(0, -10,
Control.Frame.Width / 2,
Control.Frame.Height - 5);
_yearLabel.Frame = new CGRect(Control.Frame.Width / 2, -10,
Control.Frame.Width / 2,
Control.Frame.Height - 5);
}
protected override void Dispose(bool disposing)
{
_monthLabel?.Dispose();
_yearLabel?.Dispose();
_monthLabel = null;
_yearLabel = null;
base.Dispose(disposing);
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
}
}
public class YearMonthModel : UIPickerViewModel
{
private UITextField _uITextField;
private string _selectedMonth = string.Empty;
private string _selectedYear = string.Empty;
private MonthYear _monthYear;
public YearMonthModel(UITextField uITextField, MonthYear monthYear)
{
_uITextField = uITextField;
_monthYear = monthYear;
}
public override nint GetComponentCount(UIPickerView pickerView)
{
return 2;
}
public override nint GetRowsInComponent(UIPickerView pickerView, nint component)
{
if (component == 0)
return _monthYear.Months.Count;
else
return _monthYear.Years.Count;
}
public override string GetTitle(UIPickerView pickerView, nint row, nint component)
{
if (component == 0)
return _monthYear.Months[(int)row];
else
return _monthYear.Years[(int)row].ToString();
}
public override void Selected(UIPickerView pickerView, nint row, nint component)
{
if (component == 0)
_selectedMonth = _monthYear.Months[(int)row];
if (component == 1)
_selectedYear = _monthYear.Years[(int)row].ToString();
_uITextField.Text = $"{_selectedMonth} {_selectedYear}";
}
public override nfloat GetComponentWidth(UIPickerView picker, nint component)
{
if (component == 0)
return 140f;
else
return 100f;
}
public override nfloat GetRowHeight(UIPickerView picker, nint component)
{
return 40f;
}
}
public class YearMonthPickerDelegate : UIPickerViewDelegate
{
private UITextField _uITextField;
private string _selectedMonth = string.Empty;
private string _selectedYear = string.Empty;
private MonthYear _monthYear;
public YearMonthPickerDelegate(UITextField uITextField, MonthYear monthYear)
{
_uITextField = uITextField;
_monthYear = monthYear;
}
public override string GetTitle(UIPickerView pickerView, nint row, nint component)
{
if (component == 0)
return _monthYear.Months[(int)row];
else
return _monthYear.Years[(int)row].ToString();
}
public override void Selected(UIPickerView pickerView, nint row, nint component)
{
if (component == 0)
_selectedMonth = _monthYear.Months[(int)row];
if (component == 1)
_selectedYear = _monthYear.Years[(int)row].ToString();
_uITextField.Text = $"{_selectedMonth} {_selectedYear}";
}
}
public class MonthYear
{
public List<string> Months { get; set; }
public List<int> Years { get; set; }
}
}
Edit 1
I am adding the YearMonthPicker class
public class YearMonthPicker : Picker
{
public YearMonthPicker()
{
}
public static readonly BindableProperty StartYearProperty =
BindableProperty.Create(nameof(StartYear), typeof(int), typeof(YearMonthPicker), 1900);
public int StartYear
{
get { return (int)GetValue(StartYearProperty); }
set { SetValue(StartYearProperty, value); }
}
public static readonly BindableProperty EndYearProperty =
BindableProperty.Create(nameof(EndYear), typeof(int), typeof(YearMonthPicker), 9999);
public int EndYear
{
get { return (int)GetValue(EndYearProperty); }
set { SetValue(EndYearProperty, value); }
}
public static readonly BindableProperty YearLabelProperty =
BindableProperty.Create(nameof(YearLabel), typeof(string), typeof(YearMonthPicker), string.Empty);
public string YearLabel
{
get { return (string)GetValue(YearLabelProperty); }
set { SetValue(YearLabelProperty, value); }
}
public static readonly BindableProperty MonthLabelProperty =
BindableProperty.Create(nameof(MonthLabel), typeof(string), typeof(YearMonthPicker), string.Empty);
public string MonthLabel
{
get { return (string)GetValue(MonthLabelProperty); }
set { SetValue(MonthLabelProperty, value); }
}
public static readonly BindableProperty LabelColorProperty =
BindableProperty.Create(nameof(LabelColor), typeof(Color), typeof(YearMonthPicker), default(Color));
public Color LabelColor
{
get { return (Color)GetValue(LabelColorProperty); }
set { SetValue(LabelColorProperty, value); }
}
}
I appreciate if someone can help me identify what causes the crash.
Finally, I found your problem is you did not assign the pickerView to the textField's inputView.
To assign the picker to the textField's inputView, use below code:
if (Control is UITextField textField)
{
//Change here
var pickerView = new UIPickerView();
Control.InputView = pickerView;
var yearMonthModel = new YearMonthModel(textField, _monthYear);
var yearMonthDelegate = new YearMonthPickerDelegate(textField, _monthYear);
pickerView.Model = yearMonthModel;
pickerView.Delegate = yearMonthDelegate;
textField.BorderStyle = UITextBorderStyle.None;
textField.AddSubview(_monthLabel);
textField.AddSubview(_yearLabel);
}
I have a controller:
public class CatController
{
public something DoStuff([FromBody]string bibble)
{
}
}
I want to create an ActionFilter and loop through each parameter, and see what attributes that parameter has, such as [FromBody]. How can I do this?
public class InspectParametersActionFilter : ActionFilterAttribute, IActionFilter
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
actionContext.ActionDescriptor.?
actionContext.ActionArguments.?
}
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var allCustomAttributes = filterContext.ActionDescriptor.GetParameters()
.Select(s => s.GetCustomAttributes(false));
}
I just need to render PDF from website in ASP.NET MVC. I have found quite interesting article about generating PDF from ASP.NET MVC. I think it could be done even better if the page is rendered through ActionFilterAttribute. My Idea is somesthing like that:
[EnableCompression]
[OutputCache(Duration=7200)]
[EvoPDFFilter]
public ActionResult DownloadAsPDF()
{
var model= GetModel();
return View(model); //return just HTML and convert it by filter to PDF
}
public class EvoPDFFilterAttribute: ActionFilterAttribute
{
//some code should be here. Is this solution even possible?
}
It is possible? How should look like the EvoPDFFilterAttribute?
I finally managed to do it :-)
using EvoPdf;
using System.IO;
using System.Web;
using System.Web.Mvc;
namespace MyProject.Helpers
{
/// <summary>
/// PDF filter based on code https://lostechies.com/jimmybogard/2014/02/04/rendering-asp-net-content-as-pdf/
/// </summary>
public class EvoPDFFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpRequestBase request = filterContext.HttpContext.Request;
HttpResponseBase response = filterContext.HttpContext.Response;
if (response.Filter == null)//RenderAction
return;
string acceptEncoding = request.Headers["Accept-Encoding"];
if (acceptEncoding == null)
return;
response.ContentType = "application/pdf";
var baseUrl = string.Format("{0}://{1}{2}/", request.Url.Scheme, request.Url.Authority, request.ApplicationPath.TrimEnd('/'));
response.Filter = new PdfFilter(response.Filter, baseUrl);
}
public class PdfFilter : Stream
{
private readonly Stream _oldFilter;
private readonly string _baseUrl;
private readonly MemoryStream _memStream;
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return true; }
}
public override bool CanRead
{
get { return false; }
}
public override long Position
{
get { return 0L; }
set { }
}
public override long Length
{
get { return 0L; }
}
public PdfFilter(Stream oldFilter, string baseUrl)
{
_oldFilter = oldFilter;
_baseUrl = baseUrl;
_memStream = new MemoryStream();
}
public override int Read(byte[] buffer, int offset, int count)
{
return 0;
}
public override long Seek(long offset, SeekOrigin origin)
{
return 0L;
}
public override void SetLength(long value)
{
}
public override void Write(byte[] buffer, int offset, int count)
{
_memStream.Write(buffer, offset, count);
}
public override void Flush()
{
}
public override void Close()
{
var converter = new PdfConverter
{
MediaType = "print",
};
converter.PdfDocumentOptions.LiveUrlsEnabled = false;
_memStream.Position = 0;
converter.SavePdfFromHtmlStreamToStream(_memStream, System.Text.Encoding.UTF8, _baseUrl, _oldFilter);
_oldFilter.Close();
}
}
}
}
Below is NinjectHttpApplication configuration..
public class MvcApplication : NinjectHttpApplication
{
public MvcApplication()
{
Error += NinjectWebsiteApplication_Error;
}
}
protected override IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Load<ApplicationConfig>();
return kernel;
}
void NinjectWebsiteApplication_Error(object sender, System.EventArgs e)
{
ILogger _iLogger = **//How to get instance of Applogger here from Ninject kernel..**
}
Below is the ApplicationConfig class...
public class ApplicationConfig : NHibernateNinjectModule
{
public ApplicationConfig()
{
//other settings such as ddl script generation is present here
}
public override void Load()
{
base.Load();
Bind<ILogger>().To<AppLogger>().InSingletonScope();
}
}
void NinjectWebsiteApplication_Error(object sender, System.EventArgs e)
{
var kernel = CreateKernel();
ILogger _iLogger = kernel.Get<ILogger>();
}
Ok, as it seems NinjectHttpApplication stores generated kernel object in
public IKernel Kernel
{
get { return _kernel; }
}
So you could rewrite above as
void NinjectWebsiteApplication_Error(object sender, System.EventArgs e)
{
ILogger _iLogger = Kernel.Get<ILogger>();
}
Does anyone have an examples for using the BaseExpandableListAdapter with Mono for Android. I'm trying to implement this for one of my views, but am having issues with finding something that is thorough. Can anyone provide any examples on how they got this working with Mono for Android?
Here's an admittedly crude looking but functional example of using a custom expandable list adapter. You can think of the data source as being a list of lists, since each item will expand to display a list of items underneath it. To represent that, we'll use this simple model:
public class Group : Java.Lang.Object
{
public string Name { get; set; }
public IList<string> Items { get; set; }
}
Using that model you can then create a class that inherits from BaseExpandableListAdapter and implements all the required methods/properties:
public class MyAdapter : BaseExpandableListAdapter
{
private readonly Context _context;
private readonly IList<Group> _groups;
public MyAdapter(Context context, IList<Group> groups)
{
_context = context;
_groups = groups;
}
public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
{
return _groups[groupPosition].Items[childPosition];
}
public override long GetChildId(int groupPosition, int childPosition)
{
return (groupPosition * _groups.Count) + childPosition;
}
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
var view = (TextView)(convertView ?? new TextView(_context));
view.Text = _groups[groupPosition].Items[childPosition];
return view;
}
public override int GetChildrenCount(int groupPosition)
{
return _groups[groupPosition].Items.Count;
}
public override Java.Lang.Object GetGroup(int groupPosition)
{
return _groups[groupPosition];
}
public override long GetGroupId(int groupPosition)
{
return groupPosition;
}
public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
var view = (TextView)(convertView ?? new TextView(_context));
view.Text = _groups[groupPosition].Name;
return view;
}
public override bool IsChildSelectable(int groupPosition, int childPosition)
{
return true;
}
public override int GroupCount
{
get { return _groups.Count; }
}
public override bool HasStableIds
{
get { return true; }
}
}
The constructor for the adapter takes in a list of groups, and uses that to implement the methods that ask for a group, item, etc. To keep things simple, for each view I'm just rendering a single TextView but you can create/inflate any view you want for the items.
To demonstrate this in action, here's a sample activity that will load up an expandable list with some data:
[Activity(Label = "ExpandableListDemo", MainLauncher = true, Icon = "#drawable/icon")]
public class MyExpandableListActivity : ExpandableListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var groups = new List<Group>
{
new Group
{
Name = "Group 1",
Items = new List<string> { "Item 1.1", "Item 1.2", "Item 1.3" }
},
new Group
{
Name = "Group 2",
Items = new List<string> { "Item 2.1", "Item 2.2", "Item 2.3" }
}
};
var adapter = new MyAdapter(this, groups);
SetListAdapter(adapter);
}
}