public static void Initialize(Activity activity) { audioManager = (AudioManager)activity.GetSystemService(Context.AudioService); mediaPlayer = MediaPlayer.Create(activity.ApplicationContext, Resource.Raw.Message); notificationManager = (NotificationManager)activity.GetSystemService(Context.NotificationService); vibrator = (Vibrator)activity.GetSystemService(Context.VibratorService); //context = activity.ApplicationContext; context = activity; isAlertsEnabled = true; isProgressEnabled = true; }
public UnbindPopWindow (Activity _activity,GuardianInfoListItem item) { activity = _activity; LayoutInflater inflater = (LayoutInflater) activity.GetSystemService (Context.LayoutInflaterService); contentView = inflater.Inflate(Resource.Layout.customunbinddialogLayout, null); ContentView = contentView; Width = 900; Height = 450; Focusable = true; OutsideTouchable = true; //Update (); SetBackgroundDrawable (new ColorDrawable()); AnimationStyle = Resource.Style.AnimationPreview; var btn_confirm = contentView.FindViewById<Button> (Resource.Id.btn_confirm); btn_confirm.Click += (sender, e) => { Dismiss(); if(UnBindEventHandler != null) UnBindEventHandler(item); }; var btn_cancel = contentView.FindViewById<Button> (Resource.Id.btn_cancel); btn_cancel.Click += (sender, e) => { Dismiss(); }; DismissEvent += (sender, e) => { BackgroundAlpha(1f); }; }
/// <summary> /// 网络是否联通 /// </summary> public static bool isNetworkConnected(Activity active) { bool net = false; ConnectivityManager connManager = (ConnectivityManager)active.GetSystemService(Context.ConnectivityService); // connManager.ActiveNetworkInfo ==null 手机无法连接网络 if (connManager.ActiveNetworkInfo != null) { //获得 wifi 连接管理 NetworkInfo networkInfo = connManager.GetNetworkInfo(ConnectivityType.Wifi); //获得 GPRS 连接管理 NetworkInfo gp = connManager.GetNetworkInfo(ConnectivityType.Mobile); if (networkInfo != null && networkInfo.IsAvailable != false) { //Toast.MakeText(active, "WIFI打开!", ToastLength.Long).Show(); net = true; } // gp.IsConnected==false 有信号无网络 if (gp != null && gp.IsConnected != false) { //Toast.MakeText(active, "有信号gprs打开!", ToastLength.Long).Show(); net = true; } } else { //Toast.MakeText(active, "无法连接到互联网!", ToastLength.Long).Show(); } return net; }
private ProtoPadServer(View window, int? overrideListeningPort = null, string overrideBroadcastedAppName = null) { _window = window; _contextActivity = window.Context as Activity; _httpServer = new SimpleHttpServer(responseBytes => { var response = "{}"; var remoteCommandDoneEvent = new AutoResetEvent(false); _contextActivity.RunOnUiThread(() => Response(responseBytes, remoteCommandDoneEvent, ref response)); remoteCommandDoneEvent.WaitOne(); return response; }); IPAddress broadCastAddress; using (var wifi = _contextActivity.GetSystemService(Android.Content.Context.WifiService) as WifiManager) { _mcLock = wifi.CreateMulticastLock("ProtoPadLock"); _mcLock.Acquire(); broadCastAddress = GetBroadcastAddress(wifi); } BroadcastedAppName = overrideBroadcastedAppName ?? String.Format("ProtoPad Service on ANDROID Device {0}", Android.OS.Build.Model); ListeningPort = overrideListeningPort ?? 8080; LocalIPAddress = Helpers.GetCurrentIPAddress(); _udpServer = new UdpDiscoveryServer(BroadcastedAppName, String.Format("http://{0}:{1}/", LocalIPAddress, ListeningPort), broadCastAddress); }
public SelectPicPopWindow (Activity _activity,View.IOnClickListener listener) { activity = _activity; LayoutInflater inflater = (LayoutInflater) activity.GetSystemService (Context.LayoutInflaterService); contentView = inflater.Inflate(Resource.Layout.headImgSelectorPop, null); ContentView = contentView; btn_take_photo = contentView.FindViewById<Button> (Resource.Id.btn_take_photo); btn_pick_photo = contentView.FindViewById<Button> (Resource.Id.btn_pick_photo); btn_cancel = contentView.FindViewById<Button> (Resource.Id.btn_pic_cancel); //设置宽度、高度 Width = Android.Views.ViewGroup.LayoutParams.MatchParent; Height = Android.Views.ViewGroup.LayoutParams.WrapContent; Focusable = true; OutsideTouchable = true; SetBackgroundDrawable (new ColorDrawable()); AnimationStyle = Resource.Style.Animationbottom; //设置按钮绑定 btn_take_photo.SetOnClickListener (listener); btn_pick_photo.SetOnClickListener (listener); //取消 btn_cancel.Click += (sender, e) => { Dismiss(); }; DismissEvent+= (sender, e) => { BackgroundAlpha(1f); }; }
public static void Measure (Activity context) { Resources resources = context.Resources; ScreenWidth = resources.DisplayMetrics.WidthPixels; RealSize = new Android.Graphics.Point (); context.Window.WindowManager.DefaultDisplay.GetRealSize (RealSize); ScreenHeight = resources.DisplayMetrics.HeightPixels; int navBarId = resources.GetIdentifier("navigation_bar_height", "dimen", "android"); int statusbarId = resources.GetIdentifier("status_bar_height", "dimen", "android"); NavigationBarHeight = resources.GetDimensionPixelSize(navBarId); StatusBarHeight = resources.GetDimensionPixelSize(statusbarId); TrueScreenHeight = ScreenHeight - NavigationBarHeight - StatusBarHeight; Density = resources.DisplayMetrics.Density; // memory const string ActivityService = global::Android.Content.Context.ActivityService; ActivityManager manager = (ActivityManager)context.GetSystemService(ActivityService); ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo(); manager.GetMemoryInfo(outInfo); Memory = outInfo.TotalMem; RuntimeMemory = Java.Lang.Runtime.GetRuntime().MaxMemory(); }
//Shows the soft keyboard public void showSoftKeyboard(Android.App.Activity activity, View view) { InputMethodManager inputMethodManager = (InputMethodManager)activity.GetSystemService(Context.InputMethodService); view.RequestFocus(); inputMethodManager.ShowSoftInput(view, 0); inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);//personal line added }
public static void HideKeyboard(Activity activity, EditText field) { if (activity != null && field != null) { InputMethodManager imm = (InputMethodManager)activity.GetSystemService(Context.InputMethodService); imm.HideSoftInputFromWindow(field.WindowToken, 0); } }
public Locator(Activity ctx) { this.ctx = ctx; locationManager = (LocationManager)ctx.GetSystemService (Context.LocationService); locationManager.RequestLocationUpdates (LocationManager.PassiveProvider, 5 * 60 * 1000, 2, this); if (Geocoder.IsPresent) geocoder = new Geocoder (ctx); }
public AndroidDevice(Activity activity, ConnectionType connectionType, string connectionString) : base(connectionType, connectionString, new JsonProvider()) { // Setup the WebView/Browser _activity = activity; Browser = new AndroidBrowser(new WebView(activity)); _activity.SetContentView(WebView); // Populate device info Wifi = (WifiManager)activity.GetSystemService(Context.WifiService); DeviceInfo = new DeviceInfo(); DeviceInfo.MobileOs = MobileOs.Android; DeviceInfo.DeviceModel = Build.Model; DeviceInfo.OsVersion = Build.VERSION.Release; DeviceInfo.IP = IP; var tm = (TelephonyManager)activity.GetSystemService(Context.TelephonyService); DeviceInfo.UniqueId = tm.DeviceId; }
public static void Show(Activity activity) { if (activity != null) { InputMethodManager inputManager = (InputMethodManager)activity.GetSystemService(Context.InputMethodService); var currentFocus = activity.CurrentFocus; if(currentFocus!=null) inputManager.ShowSoftInput(currentFocus, ShowFlags.Implicit); } }
public static void Hide(Activity activity) { if(activity!=null) { InputMethodManager inputManager = (InputMethodManager)activity.GetSystemService(Context.InputMethodService); var currentFocus = activity.CurrentFocus; if(currentFocus!=null) inputManager.HideSoftInputFromWindow(currentFocus.WindowToken, HideSoftInputFlags.None); } }
// Hides the soft keyboard public void hideSoftKeyboard(Android.App.Activity activity) { var currentFocus = activity.CurrentFocus; if (currentFocus != null) { InputMethodManager inputMethodManager = (InputMethodManager)activity.GetSystemService(Context.InputMethodService); inputMethodManager.HideSoftInputFromWindow(currentFocus.WindowToken, HideSoftInputFlags.None); } }
/// <summary> /// 获取手机序列号 /// </summary> /// <param name="active"></param> /// <returns></returns> public static String MEID(Activity active) { if (!string.IsNullOrEmpty(_MEID)) { return _MEID; } Android.Telephony.TelephonyManager tm = (Android.Telephony.TelephonyManager)active.GetSystemService(Context.TelephonyService); ; _MEID = tm.DeviceId; return tm.DeviceId; }
public static View CreateView (Activity context, int iconResourceStringId) { var inflater = (LayoutInflater) context.GetSystemService (Context.LayoutInflaterService); var tabView = inflater.Inflate (Resource.Layout.Tab, null, false); var tabIcon = tabView.FindViewById<TextView> (Resource.Id.TabIcon); tabIcon.Text = context.ApplicationContext.GetString(iconResourceStringId); IconProvider.ConvertTextViewToIcon (context.Assets, tabIcon); return tabView; }
public static bool IsOnline (Activity context,int close) { //for checking internet is on ConnectivityManager connectivityManager = (ConnectivityManager)context.GetSystemService("connectivity"); var activeConnection = connectivityManager.ActiveNetworkInfo; //internet is on if ((activeConnection != null) && activeConnection.IsConnected) { Console.Error.WriteLine ("1st level checking"); var client1 = new TcpClient(); try{ if (!client1.ConnectAsync (host1, port).Wait (timeout)) { client1.Close (); } return true; } catch { try{ Console.Error.WriteLine ("2nd level checking"); var client2 = new TcpClient(); if (!client2.ConnectAsync (host2, port).Wait (timeout)) { client2.Close (); } return true; } catch { try{ Console.Error.WriteLine ("3rd level checking"); var client3 = new TcpClient(); if (!client3.ConnectAsync (host3, port).Wait (timeout)) { dialogErrorInternet (context, errorInternet, close); client3.Close (); return false; } return true; } catch { Console.Error.WriteLine ("internet off"); dialogErrorInternet (context, errorInternet, close); return false; } } } } else { Console.Error.WriteLine ("internet off"); dialogErrorInternet (context, errorInternet, close); return false; } }
private static void DismissKeyboardInternal(Activity activity) { if (activity == null) return; var inputManager = activity.GetSystemService(Context.InputMethodService) as InputMethodManager; if (inputManager == null || activity.CurrentFocus == null) return; inputManager.HideSoftInputFromWindow(activity.CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways); }
static public void CloseKeyboard(Activity activity) { try { if (activity.CurrentFocus != null) { InputMethodManager input = (InputMethodManager)activity.GetSystemService(Context.InputMethodService); input.HideSoftInputFromWindow(activity.CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways); } } catch (Exception) { } }
public static void CancelNotification(Activity activity) { try { NotificationManager notificationManager = activity.GetSystemService (Context.NotificationService) as NotificationManager; notificationManager.Cancel(notificationId); builder = null; } catch (Exception e) { Console.WriteLine (e.Message); } }
public void PresentFacialCaptureInterfaceWithDelegate(bool cancelVisible, string watermarkText, string message, int x, int y) { String instrunctionStr = "Get closer until Red Rectangle appears and Blink"; String subInstString = "Analyzing..."; instance.SetWatermarkText(watermarkText, 0, 0, 30, 0); var metrics = new DisplayMetrics(); IWindowManager windowManager = mainActivity.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); windowManager.DefaultDisplay.GetMetrics(metrics); var height = metrics.HeightPixels; var width = metrics.WidthPixels; Paint textPaint = new Paint(); Typeface currentTypeFace = textPaint.Typeface; textPaint.Color = Android.Graphics.Color.White; textPaint.TextSize = 50; textPaint.TextAlign = Paint.Align.Left; Paint subtextPaint = new Paint(); subtextPaint.Color = Android.Graphics.Color.Red; subtextPaint.TextAlign = Paint.Align.Left; subtextPaint.TextSize = 40; Rect bounds = new Rect(); textPaint.GetTextBounds(instrunctionStr, 0, instrunctionStr.Length, bounds); int top = (int)(height * 0.05); int left = (width - bounds.Width()) / 2; subtextPaint.GetTextBounds(subInstString, 0, subInstString.Length, bounds); int subLeft = (width - bounds.Width()) / 2; instance.SetInstructionText(instrunctionStr, left, top, textPaint); instance.SetSubInstructionText(subInstString, subLeft, top + 30, subtextPaint); instance.FacialRecognitionTimeoutInSeconds = 20; instance.ShowManualFacialCameraInterface(mainActivity); }
private ProtoPadServer(Activity activity, int? overrideListeningPort = null, string overrideBroadcastedAppName = null) { _contextActivity = activity; BroadcastedAppName = overrideBroadcastedAppName ?? String.Format("ProtoPad Service on ANDROID Device {0}", Android.OS.Build.Model); ListeningPort = overrideListeningPort ?? 8080; LocalIPAddress = Helpers.GetCurrentIPAddress(); var mainMonodroidAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name.ToLower() == "mono.android"); var requestHandlers = new Dictionary<string, Func<byte[], string>> { {"GetMainXamarinAssembly", data => mainMonodroidAssembly.FullName}, {"WhoAreYou", data => "Android"}, {"ExecuteAssembly", data => { var response = "{}"; var remoteCommandDoneEvent = new AutoResetEvent(false); _contextActivity.RunOnUiThread(() => Response(data, remoteCommandDoneEvent, ref response)); remoteCommandDoneEvent.WaitOne(); return response; } } }; _httpServer = new SimpleHttpServer(ListeningPort, requestHandlers); IPAddress broadCastAddress; using (var wifi = _contextActivity.GetSystemService(Android.Content.Context.WifiService) as WifiManager) { try { _mcLock = wifi.CreateMulticastLock("ProtoPadLock"); _mcLock.Acquire(); } catch (Java.Lang.SecurityException e) { Debug.WriteLine("Could not optain Multicast lock: {0}. Did you enable CHANGE_WIFI_MULTICAST_STATE permission in your app manifest?", e.Message); } broadCastAddress = GetBroadcastAddress(wifi); } var inEmulator = Build.Brand.Equals("generic", StringComparison.InvariantCultureIgnoreCase); _udpServer = new UdpDiscoveryServer(BroadcastedAppName, String.Format("http://{0}:{1}/", inEmulator ? "localhost" : LocalIPAddress.ToString(), inEmulator ? "?" : ListeningPort.ToString()), broadCastAddress); }
public static void UpdateNotification(Activity activity, string text, string title = "Uptred Mobile") { if (builder == null) { builder = new Notification.Builder (activity) .SetSmallIcon (Resource.Drawable.logotransparent); } builder.SetContentTitle (title).SetContentText (text); // Build the notification: Notification notification = builder.Build(); // Get the notification manager: NotificationManager notificationManager = activity.GetSystemService (Context.NotificationService) as NotificationManager; // Publish the notification: notificationManager.Notify (notificationId, notification); }
// Activates the location listener // distance: enforces to set a minimum distance that must be reached before the places api will be requested public void ActivateLocationChangeRequests(Activity Activity,float distance) { LocHandler = new LocationHandler(Activity.GetSystemService(Activity.LocationService) as LocationManager); LocHandler.LocationRequest += async (sender, args) => { if (args == LocationHandler.messageType.LOCATION) { // sets the location initially var loc = (Location)sender; var calcDist = double.MaxValue; if(lastPosition != null) { calcDist = LatLngDist.distance(loc.Latitude, loc.Longitude, lastPosition.Latitude, lastPosition.Longitude, 'K'); } if (distance < calcDist) { JsonValue x = await GetPlacesAsJSON(loc.Latitude, loc.Longitude, 200); var handler = PlacesResponse; if (handler != null) { handler(x, EventArgs.Empty); } lastPosition = loc; } } else if (args == LocationHandler.messageType.DISABLED) { Toast.MakeText(Activity, Resource.String.ENABLE_GPS, ToastLength.Long).Show(); } }; // initializes the LocationHandler and fires an event if any porblems occur LocHandler.Init(); }
/// <summary> /// Initializes a new instance of the <see cref="EldYoungAndroidApp.Common.ApplybindPopWindow"/> class. /// </summary> /// <param name="_activity">Activity.</param> /// <param name="userId">要申请绑定的用户id</param> public ApplybindPopWindow (Activity _activity,SearchGuardianListItem item) { activity = _activity; LayoutInflater inflater = (LayoutInflater) activity.GetSystemService (Context.LayoutInflaterService); contentView = inflater.Inflate(Resource.Layout.customapplybinddialog, null); ContentView = contentView; Width = 960; Height = 690; Focusable = true; OutsideTouchable = true; Update (); SetBackgroundDrawable (new ColorDrawable()); AnimationStyle = Resource.Style.AnimationPreview; var btn_Send = contentView.FindViewById<Button> (Resource.Id.btn_Send); var txt_ApplyMsgContent = contentView.FindViewById<EditText> (Resource.Id.txt_ApplyMsgContent); txt_ApplyMsgContent.Text = string.IsNullOrEmpty(item.Remark)?string.Empty:item.Remark; btn_Send.Click += (sender, e) => { Dismiss(); if(applyBindEventHandler!=null) applyBindEventHandler(item,txt_ApplyMsgContent.Text); }; var btn_cancel = contentView.FindViewById<Button> (Resource.Id.btn_cancel); btn_cancel.Click += (sender, e) => { Dismiss(); }; DismissEvent += (sender, e) => { BackgroundAlpha(1f); }; }
public ConfirmphonePopWindow (Activity _activity,string _phoneNumber) { activity = _activity; LayoutInflater inflater = (LayoutInflater) activity.GetSystemService (Context.LayoutInflaterService); contentView = inflater.Inflate(Resource.Layout.customconfirmphonedialog, null); ContentView = contentView; btn_confirm = contentView.FindViewById<Button> (Resource.Id.btn_confirm); btn_cancel = contentView.FindViewById<Button> (Resource.Id.btn_cancel); tv_phoneNumber = contentView.FindViewById<TextView> (Resource.Id.tv_phoneNumber); //设置宽度、高度 Width = 960; Height = Android.Views.ViewGroup.LayoutParams.WrapContent; Focusable = true; OutsideTouchable = true; //Update (); SetBackgroundDrawable (new ColorDrawable()); AnimationStyle = Resource.Style.Animationbottom; tv_phoneNumber.Text = "+86 " + _phoneNumber; //设置按钮绑定 btn_confirm.SetOnClickListener ((Android.Views.View.IOnClickListener)activity); //取消 btn_cancel.Click += (sender, e) => { Dismiss(); }; DismissEvent+= (sender, e) => { BackgroundAlpha(1f); }; }
public static String phoneId(Activity active) { Android.Telephony.TelephonyManager tm = (Android.Telephony.TelephonyManager)active.GetSystemService(Context.TelephonyService); ; return tm.Line1Number; }
public static bool HasConnection(Activity activity) { ConnectivityManager connectivityManager = (ConnectivityManager)activity.GetSystemService(Context.ConnectivityService); NetworkInfo activeConnection = connectivityManager.ActiveNetworkInfo; return ((activeConnection != null) && activeConnection.IsConnected); }
public SongsAdapter(Activity context, Song[] songs) { this.context = context; this.songs = songs; inflater = (LayoutInflater)context.GetSystemService(Android.Content.Context.LayoutInflaterService); }
public Dialog PresentationDialog(Activity activity, string title, string message = "", bool save = true) { LayoutInflater inflater = (LayoutInflater)activity.GetSystemService(Context.LayoutInflaterService); View layout = inflater.Inflate(Resource.Layout.HTMLWebView, null); AlertDialog.Builder dialog = new AlertDialog.Builder(activity, Android.Resource.Style.ThemeDeviceDefaultNoActionBarFullscreen); dialog.SetTitle(title); dialog.SetIcon(Resource.Drawable.Icon); dialog.SetNegativeButton("X", (o, args) => { // Do something }); NotesDbAdapter dbHelper = new NotesDbAdapter(activity); dbHelper.Open(); if (save) { dialog.SetPositiveButton("Save", (o, args) => { AlertDialog.Builder alert = new AlertDialog.Builder(activity, Android.Resource.Style.ThemeDeviceDefaultNoActionBarFullscreen); EditText input = new EditText(activity); input.Hint = "favorite title"; alert.SetTitle("Add Favorite - " + title); alert.SetMessage(Html.FromHtml("<i>Favorite Title:</i>")); alert.SetView(input); alert.SetPositiveButton("Save", (o2, args2) => { long id = dbHelper.CreateNote(title, message, input.Text, " ", "GEMFAVORITE"); }); alert.SetNegativeButton("X", (o2, args2) => { }); alert.Show(); }); } //TextView textview = layout.FindViewById<TextView>(Resource.Id.htmltextbox); //textview.MovementMethod = LinkMovementMethod.Instance; //textview.SetText(Html.FromHtml(message), TextView.BufferType.Normal); WebView PresentationWebView = layout.FindViewById<WebView>(Resource.Id.htmlWebView); var client = new NWTBibleWebView(activity, Language); PresentationWebView.SetWebViewClient(client); PresentationWebView.Settings.JavaScriptEnabled = true; PresentationWebView.Settings.PluginsEnabled = true; PresentationWebView.Settings.BuiltInZoomControls = true; PresentationWebView.Settings.DefaultFontSize = UserFontSize(activity); PresentationWebView.LoadDataWithBaseURL("file:///android_asset/", message, "text/html", "utf-8", null); dialog.SetView(layout); return dialog.Create(); }
public static AppMsg MakeText(Activity context, string text, Style style, int layoutId) { var inflate = (LayoutInflater) context.GetSystemService(Context.LayoutInflaterService); View v = inflate.Inflate(layoutId, null); return MakeText(context, text, style, v, true); }
public void HideSoftKeyboard1(Activity activity) { var view = activity.CurrentFocus; if (view != null) { InputMethodManager manager = (InputMethodManager)activity.GetSystemService(Context.InputMethodService); manager.HideSoftInputFromWindow(view.WindowToken, 0); } }
public static void hideSoftKeyboard(Activity activity) { InputMethodManager inputMethodManager = (InputMethodManager) activity.GetSystemService(Activity.InputMethodService); inputMethodManager.HideSoftInputFromWindow(activity.CurrentFocus.WindowToken, 0); }
/// <summary> /// 获取手机序列号 /// </summary> /// <param name="active"></param> /// <returns></returns> public static String MEID(Activity active) { string ls_meid = ""; Android.Telephony.TelephonyManager tm = (Android.Telephony.TelephonyManager)active.GetSystemService(Context.TelephonyService); ; ls_meid = tm.DeviceId; if (string.IsNullOrEmpty(ls_meid)) ls_meid = Android.Provider.Settings.Secure.GetString(active.ContentResolver, Android.Provider.Settings.Secure.AndroidId); ls_meid = gyDES.of_Md5_Gy(ls_meid, ".19288230023823988398!!~@ddd"); return ls_meid; }