protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);
			SetContentView (Resource.Layout.activity_main);

			mRegistrationProgressBar = FindViewById<ProgressBar> (Resource.Id.registrationProgressBar);
			mRegistrationBroadcastReceiver = new BroadcastReceiver ();
			mRegistrationBroadcastReceiver.OnReceiveImpl = (context, intent) => {
				mRegistrationProgressBar.Visibility = ViewStates.Gone;
				var sharedPreferences =
					PreferenceManager.GetDefaultSharedPreferences (context);
				var sentToken = sharedPreferences.GetBoolean (QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
				if (sentToken) {
					mInformationTextView.Text = GetString (Resource.String.gcm_send_message);
				} else {
					mInformationTextView.Text = GetString (Resource.String.token_error_message);
				}
			};
			mInformationTextView = FindViewById<TextView> (Resource.Id.informationTextView);

			if (CheckPlayServices ()) {
				// Start IntentService to register this application with GCM.
				var intent = new Intent (this, typeof(RegistrationIntentService));
				StartService (intent);
			}
		}
        protected override void OnCreate(Bundle savedInstanceState) {
            base.OnCreate(savedInstanceState);

            SetContentView(R.Layout.local_service_broadcaster);

            // This is where we print the data we get back.
            TextView callbackData = (TextView)FindViewById(R.Id.callback);

            // Put in some initial text.
            callbackData.Text = ("No broadcast received yet");

            // We use this to send broadcasts within our local process.
            mLocalBroadcastManager = LocalBroadcastManager.GetInstance(this);

            // We are going to watch for interesting local broadcasts.
            IntentFilter filter = new IntentFilter();
            filter.AddAction(ACTION_STARTED);
            filter.AddAction(ACTION_UPDATE);
            filter.AddAction(ACTION_STOPPED);
            mReceiver = new MyBroadcastReceiver(callbackData);
            
            mLocalBroadcastManager.RegisterReceiver(mReceiver, filter);

            // Watch for button clicks.
            Button button = (Button)FindViewById(R.Id.start);
            button.Click += (o,e) => StartService(new Intent(this, typeof(LocalService)));
            button = (Button)FindViewById(R.Id.stop);
            button.Click += (o,e) => StopService(new Intent(this, typeof(LocalService)));
        }
		public override void OnActivityCreated (Bundle savedInstanceState)
		{
			base.OnActivityCreated (savedInstanceState);

			alarmWentOffBroadcastReceiver = new AlarmWentOffReceiver (this);
			LocalBroadcastManager.GetInstance (Activity)
								 .RegisterReceiver (alarmWentOffBroadcastReceiver,
													new IntentFilter (AlarmIntentService.ALARM_WENT_OFF_ACTION));
		}
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            _ioc = App.Kp2a.GetDb().Ioc;

            _intentReceiver = new LockingClosePreferenceActivityBroadcastReceiver(this);
            IntentFilter filter = new IntentFilter();
            filter.AddAction(Intents.DatabaseLocked);
            RegisterReceiver(_intentReceiver, filter);
        }
Esempio n. 5
0
        protected override void OnResume()
        {
            base.OnResume();

            _smsSentBroadcastReceiver = new SMSSentReceiver();
            _smsDeliveredBroadcastReceiver = new SMSDeliveredReceiver();

            RegisterReceiver(_smsSentBroadcastReceiver, new IntentFilter("SMS_SENT"));
            RegisterReceiver(_smsDeliveredBroadcastReceiver, new IntentFilter("SMS_DELIVERED"));
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: static void showUsbDialog(final android.content.Context context, final java.util.Set<android.hardware.usb.UsbDevice> usbDevices, final android.content.BroadcastReceiver usbReceiver)
		internal static void showUsbDialog(Context context, ISet<UsbDevice> usbDevices, BroadcastReceiver usbReceiver)
		{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String[] items = new String[usbDevices.size()];
			string[] items = new string[usbDevices.Count];
			int index = 0;
			foreach (UsbDevice device in usbDevices)
			{
				items[index++] = "Device name: " + device.DeviceName + ", Product ID: " + device.ProductId + ", Device ID: " + device.DeviceId;
			}

			(new AlertDialog.Builder(context)).setTitle("Connected USB printers").setItems(items, new OnClickListenerAnonymousInnerClassHelper2(context, usbDevices, usbReceiver))
				   .show();
		}
Esempio n. 7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            _design.ApplyTheme();

            if (PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(
                GetString(Resource.String.ViewDatabaseSecure_key), true))
            {
                Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
            }

            _ioc = App.Kp2a.GetDb().Ioc;

            _intentReceiver = new LockCloseListActivityBroadcastReceiver(this);
            IntentFilter filter = new IntentFilter();

            filter.AddAction(Intents.DatabaseLocked);
            filter.AddAction(Intent.ActionScreenOff);
            RegisterReceiver(_intentReceiver, filter);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            channelIdUpdateReceiver = new ChannelIdBroadcastReceiver ((Intent) => {
                UpdateChannelIdField ();
            });

            channelID = FindViewById<TextView> (Resource.Id.channel_id);
            channelID.Click += (sender, e) => {
                if (!string.IsNullOrEmpty (channelID.Text)) {
                    // Using deprecated ClipboardManager to support Gingerbread (API 10)
                    var clipboard = GetSystemService (Context.ClipboardService).JavaCast<ClipboardManager> ();
                    clipboard.Text = channelID.Text;
                    Toast.MakeText (this, "Channel ID copied to clipboard", ToastLength.Short).Show ();
                }
            };
        }
 public OnClickListenerAnonymousInnerClassHelper2(Context context, ISet <UsbDevice> usbDevices, BroadcastReceiver usbReceiver)
 {
     this.context     = context;
     this.usbDevices  = usbDevices;
     this.usbReceiver = usbReceiver;
 }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: static void showUsbDialog(final android.content.Context context, final java.util.Set<android.hardware.usb.UsbDevice> usbDevices, final android.content.BroadcastReceiver usbReceiver)
        internal static void showUsbDialog(Context context, ISet <UsbDevice> usbDevices, BroadcastReceiver usbReceiver)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String[] items = new String[usbDevices.size()];
            string[] items = new string[usbDevices.Count];
            int      index = 0;

            foreach (UsbDevice device in usbDevices)
            {
                items[index++] = "Device name: " + device.DeviceName + ", Product ID: " + device.ProductId + ", Device ID: " + device.DeviceId;
            }

            (new AlertDialog.Builder(context)).setTitle("Connected USB printers").setItems(items, new OnClickListenerAnonymousInnerClassHelper2(context, usbDevices, usbReceiver))
            .show();
        }
 void moveObject()
 {
     transform.position = new Vector3(0, 1, BroadcastReceiver.getBeaconDistance(1));
 }
Esempio n. 12
0
 void RegisterDeepLinkReceiver()
 {
     deepLinkReceiver = new BroadcastReceiver ();
     deepLinkReceiver.OnReceiveImpl = (context, intent) => {
         if (AppInviteReferral.HasReferral (intent)) {
             LaunchDeepLinkActivity (intent);
         }
     };
     var intentFilter = new IntentFilter (GetString (Resource.String.action_deep_link));
     LocalBroadcastManager.GetInstance (this).RegisterReceiver (
         deepLinkReceiver, intentFilter);
 }
Esempio n. 13
0
 protected override void OnResume()
 {
     base.OnResume();
     _receiver = new WiFiDirectBroadcastReceiver(_manager, _channel, this);
     RegisterReceiver(_receiver, _intentFilter);
 }
        /// <summary>
        /// The on destroy.
        /// </summary>
        public override void OnDestroy()
        {
            if (this.connectionReceiver != null)
            {
                this.UnregisterReceiver(this.connectionReceiver);
                this.connectionReceiver = null;
            }

            this.serviceConnection.Disconnect(this);
            base.OnDestroy();
        }
Esempio n. 15
0
        public override void OnCreate()
        {
            base.OnCreate();
            try
            {
                //_logger = new Logger(Environment.ExternalStorageDirectory.AbsolutePath);
                _powerManager = (PowerManager)BaseContext.GetSystemService(PowerService);
                _sensorManager = (SensorManager)BaseContext.GetSystemService(SensorService);
                _wakeLockPartial = _powerManager.NewWakeLock(WakeLockFlags.Partial, _tag);
                _screenOffReceiver = new WakeUpServiceReceiver(() =>
                {
                    new Handler().PostDelayed(() =>
                    {
                        UnregisterListener();
                        RegisterListener();
                        Log.Debug("WakeUpServiceReceiver", "Screen turned off.");
                    }, 500);
                });
                RegisterReceiver(_screenOffReceiver, new IntentFilter(Intent.ActionScreenOff));

                Status = ServiceStatus.STARTED;
                Log.Debug("WakeUpService", "Service started.");
            }
            catch (Exception ex)
            {
                Log.Error("WakeUpService", ex.ToString());
                Status = ServiceStatus.FAILED;
            }
        }
Esempio n. 16
0
 static PowerStatus()
 {
     _batteryStatusReceiver = new BatteryStatusBroadCastReceiver();
     Game.contextInstance.RegisterReceiver(_batteryStatusReceiver, new IntentFilter(Intent.ActionBatteryChanged));
 }
Esempio n. 17
0
 public override void Init()
 {
     _receiver = new WifiBroadcastReceiver();
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Log.Debug(TAG, "OnCreate");
            //create a new kid
            //RandomString rString = new RandomString();
            //k_id = RandomString.GetRandomString(32);
            //Log.Debug(TAG, "session_id = " + k_id);

            context = Android.App.Application.Context;

            //get virtual keyboard
            imm = (InputMethodManager)GetSystemService(Activity.InputMethodService);
            //get default
            prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            //pda type
            pda_type = prefs.GetInt("PDA_TYPE", 0);
            //default port
            web_soap_port = prefs.GetString("WEB_SOAP_PORT", "8484");
            //save current kid
            //editor = prefs.Edit();
            //editor.PutString("CURRENT_K_ID", k_id);
            //editor.Apply();

            SetContentView(Resource.Layout.activity_main);
            //Android.Support.V7.Widget.Toolbar toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            myToolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(myToolbar);

            /*FloatingActionButton fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
             * fab.Click += FabOnClick;*/

            DrawerLayout          drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, myToolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);

            drawer.AddDrawerListener(toggle);
            toggle.SyncState();

            NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);

            navigationView.SetNavigationItemSelectedListener(this);
            View headerLayout = navigationView.GetHeaderView(0);

            empID = headerLayout.FindViewById <TextView>(Resource.Id.empId);

            menuItemLogin  = navigationView.Menu.FindItem(Resource.Id.nav_login);
            menuItemLogout = navigationView.Menu.FindItem(Resource.Id.nav_logout);
            //menuItemReceiveGoods = navigationView.Menu.FindItem(Resource.Id.nav_receiving);
            //menuItemShipment = navigationView.Menu.FindItem(Resource.Id.nav_shipment);
            menuItemSearch            = navigationView.Menu.FindItem(Resource.Id.nav_search);
            menuItemAllocationSendMsg = navigationView.Menu.FindItem(Resource.Id.nav_allocation_send_msg);
            menuItemAllocation        = navigationView.Menu.FindItem(Resource.Id.nav_allocation);
            menuItemEnteringWareHouse = navigationView.Menu.FindItem(Resource.Id.nav_entering_warehouse);
            menuItemProductionStorage = navigationView.Menu.FindItem(Resource.Id.nav_production_storage);
            //menuItemProductionStorage = navigationView.Menu.FindItem(Resource.Id.nav_production_storage);
            //menuItemReceivingInspection = navigationView.Menu.FindItem(Resource.Id.nav_receiving_inspection);



            if (!isLogin)
            {
                Fragment fragment = new LoginFragment();
                fragmentManager = this.FragmentManager;

                FragmentTransaction fragmentTx = fragmentManager.BeginTransaction();
                //fragmentTx.Add(Resource.Id.flContent, fragment);
                fragmentTx.Replace(Resource.Id.flContent, fragment);

                fragmentTx.Commit();
            }

            //broadcast receiver
            if (!isRegister)
            {
                IntentFilter filter = new IntentFilter();
                mReceiver = new MyBoradcastReceiver();
                filter.AddAction(Constants.SOAP_CONNECTION_FAIL);
                filter.AddAction(Constants.ACTION_SOCKET_TIMEOUT);
                filter.AddAction(Constants.ACTION_LOGIN_FAIL);
                filter.AddAction(Constants.ACTION_LOGIN_SUCCESS);
                filter.AddAction(Constants.ACTION_LOGOUT_ACTION);
                filter.AddAction(Constants.ACTION_SETTING_PDA_TYPE_ACTION);
                filter.AddAction(Constants.ACTION_SETTING_WEB_SOAP_PORT_ACTION);
                //filter.AddAction(Constants.ACTION_ENTERING_WAREHOUSE_INTO_STOCK_SHOW_DIALOG);
                filter.AddAction(Constants.ACTION_SEARCH_MENU_SHOW_ACTION);
                filter.AddAction(Constants.ACTION_SEARCH_MENU_HIDE_ACTION);
                filter.AddAction(Constants.ACTION_RESET_TITLE_PART_IN_STOCK);
                RegisterReceiver(mReceiver, filter);
                isRegister = true;
            }
        }
 // Use this for initialization
 void Start()
 {
     type = BroadcastReceiver.getScanServiceType();
     InvokeRepeating("moveObject", 3.0f, 1.0f);
 }
Esempio n. 20
0
 /// <summary>
 /// Registers the receiver using <see cref="Application.Context"/>.
 /// </summary>
 /// <returns>The receiver intent.</returns>
 /// <param name="receiver">Receiver.</param>
 /// <param name="intentFilter">Intent filter.</param>
 public static Intent RegisterReceiver(this BroadcastReceiver receiver, IntentFilter intentFilter)
 {
     return(Application.Context.RegisterReceiver(receiver, intentFilter));
 }
Esempio n. 21
0
		void RegisterDeepLinkReceiver() 
		{
			// Create local Broadcast receiver that starts 
			//DeepLinkActivity when a deep link is found
			deepLinkReceiver = new InviteBroadcastReceiver(this);

			var intentFilter = new IntentFilter(GetString(Resource.String.action_deep_link));
			LocalBroadcastManager.GetInstance(this).RegisterReceiver(
				deepLinkReceiver, intentFilter);
		}
        /// <summary>
        /// This is the main thread for the Downloader. 
        /// This thread is responsible for queuing up downloads and other goodness.
        /// </summary>
        /// <param name="intent">
        /// The intent that was recieved.
        /// </param>
        protected override void OnHandleIntent(Intent intent)
        {
            Log.Debug(Tag,"DownloaderService.OnHandleIntent");

            this.IsServiceRunning = true;
            try
            {
                var pendingIntent = (PendingIntent)intent.GetParcelableExtra(DownloaderServiceExtras.PendingIntent);

                if (null != pendingIntent)
                {
                    this.downloadNotification.PendingIntent = pendingIntent;
                    this.pPendingIntent = pendingIntent;
                }
                else if (null != this.pPendingIntent)
                {
                    this.downloadNotification.PendingIntent = this.pPendingIntent;
                }
                else
                {
                    Log.Debug(Tag,"LVLDL Downloader started in bad state without notification intent.");
                    return;
                }

                // when the LVL check completes, a successful response will update the service
                if (IsLvlCheckRequired(this.packageInfo))
                {
                    this.UpdateLvl(this);
                    return;
                }

                // get each download
                List<DownloadInfo> infos = DownloadsDatabase.GetDownloads();
                this.BytesSoFar = 0;
                this.TotalLength = 0;
                this.fileCount = infos.Count();
                foreach (DownloadInfo info in infos)
                {
                    // We do an (simple) integrity check on each file, just to 
                    // make sure and to verify that the file matches the state
                    if (info.Status == DownloadStatus.Success
                        && !Helpers.DoesFileExist(this, info.FileName, info.TotalBytes, true))
                    {
                        info.Status = DownloadStatus.None;
                        info.CurrentBytes = 0;
                    }

                    // get aggregate data
                    this.TotalLength += info.TotalBytes;
                    this.BytesSoFar += info.CurrentBytes;
                }

                this.PollNetworkState();
                if (this.connectionReceiver == null)
                {
                    // We use this to track network state, such as when WiFi, Cellular, etc. is enabled
                    // when downloads are paused or in progress.
                    this.connectionReceiver = new InnerBroadcastReceiver(this);
                    var intentFilter = new IntentFilter(ConnectivityManager.ConnectivityAction);
                    intentFilter.AddAction(WifiManager.WifiStateChangedAction);
                    this.RegisterReceiver(this.connectionReceiver, intentFilter);
                }

                // loop through all downloads and fetch them
                int types = Enum.GetValues(typeof(ApkExpansionPolicy.ExpansionFileType)).Length;
                for (int index = 0; index < types; index++)
                {
                    DownloadInfo info = infos[index];
                    Log.Debug(Tag,"Starting download of " + info.FileName);

                    long startingCount = info.CurrentBytes;

                    if (info.Status != DownloadStatus.Success)
                    {
                        var dt = new DownloadThread(info, this, this.downloadNotification);
                        this.CancelAlarms();
                        this.ScheduleAlarm(ActiveThreadWatchdog);
                        dt.Run();
                        this.CancelAlarms();
                    }

                    DownloadsDatabase.UpdateFromDatabase(ref info);
                    bool setWakeWatchdog = false;
                    DownloaderState notifyStatus;
                    switch (info.Status)
                    {
                        case DownloadStatus.Forbidden:

                            // the URL is out of date
                            this.UpdateLvl(this);
                            return;
                        case DownloadStatus.Success:
                            this.BytesSoFar += info.CurrentBytes - startingCount;

                            if (index < infos.Count() - 1)
                            {
                                continue;
                            }

                            DownloadsDatabase.UpdateMetadata(this.packageInfo.VersionCode, DownloadStatus.None);
                            this.downloadNotification.OnDownloadStateChanged(DownloaderState.Completed);
                            return;
                        case DownloadStatus.FileDeliveredIncorrectly:

                            // we may be on a network that is returning us a web page on redirect
                            notifyStatus = DownloaderState.PausedNetworkSetupFailure;
                            info.CurrentBytes = 0;
                            DownloadsDatabase.UpdateDownload(info);
                            setWakeWatchdog = true;
                            break;
                        case DownloadStatus.PausedByApp:
                            notifyStatus = DownloaderState.PausedByRequest;
                            break;
                        case DownloadStatus.WaitingForNetwork:
                        case DownloadStatus.WaitingToRetry:
                            notifyStatus = DownloaderState.PausedNetworkUnavailable;
                            setWakeWatchdog = true;
                            break;
                        case DownloadStatus.QueuedForWifi:
                        case DownloadStatus.QueuedForWifiOrCellularPermission:

                            // look for more detail here
                            notifyStatus = this.wifiManager != null && !this.wifiManager.IsWifiEnabled
                                               ? DownloaderState.PausedWifiDisabledNeedCellularPermission
                                               : DownloaderState.PausedNeedCellularPermission;
                            setWakeWatchdog = true;
                            break;
                        case DownloadStatus.Canceled:
                            notifyStatus = DownloaderState.FailedCanceled;
                            setWakeWatchdog = true;
                            break;

                        case DownloadStatus.InsufficientSpaceError:
                            notifyStatus = DownloaderState.FailedSdCardFull;
                            setWakeWatchdog = true;
                            break;

                        case DownloadStatus.DeviceNotFoundError:
                            notifyStatus = DownloaderState.PausedSdCardUnavailable;
                            setWakeWatchdog = true;
                            break;

                        default:
                            notifyStatus = DownloaderState.Failed;
                            break;
                    }

                    if (setWakeWatchdog)
                    {
                        this.ScheduleAlarm(WatchdogWakeTimer);
                    }
                    else
                    {
                        this.CancelAlarms();
                    }

                    // failure or pause state
                    this.downloadNotification.OnDownloadStateChanged(notifyStatus);
                    return;
                }

                this.downloadNotification.OnDownloadStateChanged(DownloaderState.Completed);
            }
            catch (Exception ex)
            {
                Log.Error(Tag,ex.Message);
                Log.Error(Tag,ex.StackTrace);
            }
            finally
            {
                this.IsServiceRunning = false;
            }
        }
Esempio n. 23
0
 /// <summary>
 /// Unregisters the receiver using <see cref="Application.Context"/>.
 /// </summary>
 /// <param name="receiver">Receiver to unregister.</param>
 public static void UnregisterReceiver(this BroadcastReceiver receiver)
 {
     Application.Context.UnregisterReceiver(receiver);
 }
Esempio n. 24
0
 public void Register(BroadcastReceiver stopNavigationReceiver, Context applicationContext)
 {
     this.stopNavigationReceiver = stopNavigationReceiver;
     applicationContext.RegisterReceiver(stopNavigationReceiver, new IntentFilter(STOP_NAVIGATION_ACTION));
 }
        /// <summary>
        /// This is the main thread for the Downloader.
        /// This thread is responsible for queuing up downloads and other goodness.
        /// </summary>
        /// <param name="intent">
        /// The intent that was recieved.
        /// </param>
        protected override void OnHandleIntent(Intent intent)
        {
            Log.Debug(Tag, "DownloaderService.OnHandleIntent");

            this.IsServiceRunning = true;
            try
            {
                var pendingIntent = (PendingIntent)intent.GetParcelableExtra(DownloaderServiceExtras.PendingIntent);

                if (null != pendingIntent)
                {
                    this.downloadNotification.PendingIntent = pendingIntent;
                    this.pPendingIntent = pendingIntent;
                }
                else if (null != this.pPendingIntent)
                {
                    this.downloadNotification.PendingIntent = this.pPendingIntent;
                }
                else
                {
                    Log.Debug(Tag, "LVLDL Downloader started in bad state without notification intent.");
                    return;
                }

                // when the LVL check completes, a successful response will update the service
                if (IsLvlCheckRequired(this.packageInfo))
                {
                    this.UpdateLvl(this);
                    return;
                }

                // get each download
                List <DownloadInfo> infos = DownloadsDatabase.GetDownloads();
                this.BytesSoFar  = 0;
                this.TotalLength = 0;
                this.fileCount   = infos.Count();
                foreach (DownloadInfo info in infos)
                {
                    // We do an (simple) integrity check on each file, just to
                    // make sure and to verify that the file matches the state
                    if (info.Status == ExpansionDownloadStatus.Success &&
                        !Helpers.DoesFileExist(this, info.FileName, info.TotalBytes, true))
                    {
                        info.Status       = ExpansionDownloadStatus.None;
                        info.CurrentBytes = 0;
                    }

                    // get aggregate data
                    this.TotalLength += info.TotalBytes;
                    this.BytesSoFar  += info.CurrentBytes;
                }

                this.PollNetworkState();
                if (this.connectionReceiver == null)
                {
                    // We use this to track network state, such as when WiFi, Cellular, etc. is enabled
                    // when downloads are paused or in progress.
                    this.connectionReceiver = new InnerBroadcastReceiver(this);
                    var intentFilter = new IntentFilter(ConnectivityManager.ConnectivityAction);
                    intentFilter.AddAction(WifiManager.WifiStateChangedAction);
                    this.RegisterReceiver(this.connectionReceiver, intentFilter);
                }

                // loop through all downloads and fetch them
                int types = Enum.GetValues(typeof(ApkExpansionPolicy.ExpansionFileType)).Length;
                for (int index = 0; index < types; index++)
                {
                    DownloadInfo info = infos[index];
                    Log.Debug(Tag, "Starting download of " + info.FileName);

                    long startingCount = info.CurrentBytes;

                    if (info.Status != ExpansionDownloadStatus.Success)
                    {
                        var dt = new DownloadThread(info, this, this.downloadNotification);
                        this.CancelAlarms();
                        this.ScheduleAlarm(ActiveThreadWatchdog);
                        dt.Run();
                        this.CancelAlarms();
                    }

                    DownloadsDatabase.UpdateFromDatabase(ref info);
                    bool            setWakeWatchdog = false;
                    DownloaderState notifyStatus;
                    switch (info.Status)
                    {
                    case ExpansionDownloadStatus.Forbidden:

                        // the URL is out of date
                        this.UpdateLvl(this);
                        return;

                    case ExpansionDownloadStatus.Success:
                        this.BytesSoFar += info.CurrentBytes - startingCount;

                        if (index < infos.Count() - 1)
                        {
                            continue;
                        }

                        DownloadsDatabase.UpdateMetadata(this.packageInfo.VersionCode, ExpansionDownloadStatus.None);
                        this.downloadNotification.OnDownloadStateChanged(DownloaderState.Completed);
                        return;

                    case ExpansionDownloadStatus.FileDeliveredIncorrectly:

                        // we may be on a network that is returning us a web page on redirect
                        notifyStatus      = DownloaderState.PausedNetworkSetupFailure;
                        info.CurrentBytes = 0;
                        DownloadsDatabase.UpdateDownload(info);
                        setWakeWatchdog = true;
                        break;

                    case ExpansionDownloadStatus.PausedByApp:
                        notifyStatus = DownloaderState.PausedByRequest;
                        break;

                    case ExpansionDownloadStatus.WaitingForNetwork:
                    case ExpansionDownloadStatus.WaitingToRetry:
                        notifyStatus    = DownloaderState.PausedNetworkUnavailable;
                        setWakeWatchdog = true;
                        break;

                    case ExpansionDownloadStatus.QueuedForWifi:
                    case ExpansionDownloadStatus.QueuedForWifiOrCellularPermission:

                        // look for more detail here
                        notifyStatus = this.wifiManager != null && !this.wifiManager.IsWifiEnabled
                                               ? DownloaderState.PausedWifiDisabledNeedCellularPermission
                                               : DownloaderState.PausedNeedCellularPermission;
                        setWakeWatchdog = true;
                        break;

                    case ExpansionDownloadStatus.Canceled:
                        notifyStatus    = DownloaderState.FailedCanceled;
                        setWakeWatchdog = true;
                        break;

                    case ExpansionDownloadStatus.InsufficientSpaceError:
                        notifyStatus    = DownloaderState.FailedSdCardFull;
                        setWakeWatchdog = true;
                        break;

                    case ExpansionDownloadStatus.DeviceNotFoundError:
                        notifyStatus    = DownloaderState.PausedSdCardUnavailable;
                        setWakeWatchdog = true;
                        break;

                    default:
                        notifyStatus = DownloaderState.Failed;
                        break;
                    }

                    if (setWakeWatchdog)
                    {
                        this.ScheduleAlarm(WatchdogWakeTimer);
                    }
                    else
                    {
                        this.CancelAlarms();
                    }

                    // failure or pause state
                    this.downloadNotification.OnDownloadStateChanged(notifyStatus);
                    return;
                }

                this.downloadNotification.OnDownloadStateChanged(DownloaderState.Completed);
            }
            catch (Exception ex)
            {
                Log.Error(Tag, ex.Message);
                Log.Error(Tag, ex.StackTrace);
            }
            finally
            {
                this.IsServiceRunning = false;
            }
        }
Esempio n. 26
0
 static PowerStatus()
 {
     _batteryStatusReceiver = new BatteryStatusBroadCastReceiver();
     Game.Activity.RegisterReceiver(_batteryStatusReceiver, new IntentFilter(Intent.ActionBatteryChanged));
 }
Esempio n. 27
0
 private void RegisterReceiver(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter)
 {
     _context.RegisterReceiver(broadcastReceiver, intentFilter);
 }
 protected override void OnResume()
 {
     base.OnResume();
     _receiver = new WiFiDirectBroadcastReceiver(_manager, _channel, this);
     RegisterReceiver(_receiver, _intentFilter);
 }
Esempio n. 29
0
 private void UnregisterReceiver(BroadcastReceiver broadcastReceiver)
 {
     _context.UnregisterReceiver(broadcastReceiver);
 }
Esempio n. 30
0
			public OnClickListenerAnonymousInnerClassHelper2(Context context, ISet<UsbDevice> usbDevices, BroadcastReceiver usbReceiver)
			{
				this.context = context;
				this.usbDevices = usbDevices;
				this.usbReceiver = usbReceiver;
			}
Esempio n. 31
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            // return inflater.Inflate(Resource.Layout.YourFragment, container, false);
            View view = inflater.Inflate(Resource.Layout.production_storage_fragment, container, false);

            fragmentContext = Application.Context;

            //get default
            prefs = PreferenceManager.GetDefaultSharedPreferences(fragmentContext);
            //emp_no
            emp_no = prefs.GetString("EMP_NO", "");

            mLayoutManager = new LinearLayoutManager(fragmentContext);

            relativeLayout = view.FindViewById <RelativeLayout>(Resource.Id.production_storage_list_container);

            progressBar = new ProgressBar(fragmentContext);
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(200, 200);
            layoutParams.AddRule(LayoutRules.CenterInParent);
            relativeLayout.AddView(progressBar, layoutParams);
            progressBar.Visibility = ViewStates.Gone;

            editTextInNo            = view.FindViewById <EditText>(Resource.Id.editTextInNo);
            btnUserInputConfirm     = view.FindViewById <Button>(Resource.Id.btnUserInputConfirm);
            c_in_no                 = view.FindViewById <TextView>(Resource.Id.c_in_no);
            c_in_date               = view.FindViewById <TextView>(Resource.Id.c_in_date);
            c_made_no               = view.FindViewById <TextView>(Resource.Id.c_made_no);
            c_dept_name             = view.FindViewById <TextView>(Resource.Id.c_dept_name);
            productListRecyclerView = view.FindViewById <RecyclerView>(Resource.Id.productListView);
            btnInStockConfirm       = view.FindViewById <Button>(Resource.Id.btnInStockConfirm);

            productList.Clear();

            btnUserInputConfirm.Click += (Sender, e) =>
            {
                progressBar.Visibility = ViewStates.Visible;

                WebReference.Service dx = new WebReference.Service();
                try
                {
                    bool ret = dx.Check_TT_product_Entry_already_confirm("MAT", editTextInNo.Text);

                    if (!ret)
                    {
                        Intent checkResultIntent = new Intent(Constants.ACTION_CHECK_TT_PRODUCT_ENTRY_ALREADY_CONFIRM_NO);
                        fragmentContext.SendBroadcast(checkResultIntent);
                    }
                    else
                    {
                        Intent checkResultIntent = new Intent(Constants.ACTION_CHECK_TT_PRODUCT_ENTRY_ALREADY_CONFIRM_YES);
                        fragmentContext.SendBroadcast(checkResultIntent);
                    }
                }
                catch (SocketTimeoutException ex)
                {
                    ex.PrintStackTrace();
                    Intent timeoutIntent = new Intent(Constants.ACTION_SOCKET_TIMEOUT);
                    fragmentContext.SendBroadcast(timeoutIntent);
                }
                catch (SoapException ex)
                {
                    Intent timeoutIntent = new Intent(Constants.SOAP_CONNECTION_FAIL);
                    fragmentContext.SendBroadcast(timeoutIntent);
                }
            };

            btnInStockConfirm.Click += (Sender, e) =>
            {
                bool found_product_not_scan = false;

                if (productList.Count > 0)
                {
                    for (int i = 0; i < productList.Count; i++)
                    {
                        if (productList[i].getLocate_no_scan().Equals(""))
                        {
                            found_product_not_scan = true;
                            break;
                        }
                    }


                    if (!found_product_not_scan)
                    { //all scanner, start in stock
                        //unselect all
                        for (int i = 0; i < productList.Count; i++)
                        {
                            productList[i].setSelected(false);
                        }
                        productionStorageItemAdapter.NotifyDataSetChanged();
                        item_select = -1;

                        Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(fragmentContext);
                        alert.SetTitle(Resource.String.production_storage_dialog_title);
                        alert.SetIcon(Resource.Drawable.ic_warning_black_48dp);
                        alert.SetMessage(Resource.String.production_storage_dialog_content);
                        alert.SetPositiveButton(Resource.String.ok, (senderAlert, args) =>
                        {
                            progressBar.Visibility = ViewStates.Visible;

                            WebReference.Service dx = new WebReference.Service();

                            try
                            {
                                bool found_error = false;
                                foreach (DataRow dr in dataTable_RR.Rows)
                                {
                                    bool is_exist = dx.Check_stock_locate_no_exist("MAT", dr["stock_no"].ToString(), dr["locate_no"].ToString());
                                    if (is_exist) //update product entry
                                    {
                                        dx.Update_TT_product_Entry_locate_no("MAT", dr["in_no"].ToString(), int.Parse(dr["item_no"].ToString()), dr["locate_no"].ToString());
                                    }
                                    else
                                    {
                                        toast(fragmentContext.GetString(Resource.String.production_storage_in_stock_process_abort));
                                        found_error = true;
                                        break;
                                    }
                                }

                                if (!found_error)
                                {
                                    if (product_table_X_M != null)
                                    {
                                        product_table_X_M.Clear();
                                    }
                                    else
                                    {
                                        product_table_X_M = new DataTable("X_M");
                                    }
                                    DataColumn v1 = new DataColumn("script");
                                    product_table_X_M.Columns.Add(v1);

                                    DataRow kr;
                                    kr = product_table_X_M.NewRow();

                                    string script_string = "sh run_me 1 2 " + c_in_no.Text + " " + emp_no;

                                    Log.Warn(TAG, "script_string = " + script_string);

                                    kr["script"] = script_string;
                                    product_table_X_M.Rows.Add(kr);

                                    //execute Execute_Script_TT
                                    bool executeTT_ret = dx.Execute_Script_TT("MAT", product_table_X_M);

                                    Intent checkResultIntent;
                                    if (!executeTT_ret)
                                    {
                                        checkResultIntent = new Intent(Constants.ACTION_EXECUTE_TT_FAILED);
                                        fragmentContext.SendBroadcast(checkResultIntent);
                                    }
                                    else
                                    {
                                        checkResultIntent = new Intent(Constants.ACTION_PRODUCT_IN_STOCK_WORK_COMPLETE);
                                        checkResultIntent.PutExtra("IN_NO", c_in_no.Text);
                                        fragmentContext.SendBroadcast(checkResultIntent);
                                    }
                                }
                                //dx.Check_stock_locate_no_exist("MAT", productList[e].getStock_no(), barcode, k_id);

                                /*Intent checkIntent = new Intent(fragmentContext, CheckStockLocateNoExistService.class);
                                 * checkIntent.setAction(Constants.ACTION.ACTION_PRODUCT_CHECK_STOCK_LOCATE_NO_EXIST_ACTION);
                                 *  checkIntent.putExtra("STOCK_NO", productList.get(last).getStock_no());
                                 *  checkIntent.putExtra("LOCATE_NO", productList.get(last).getLocate_no());
                                 *  checkIntent.putExtra("CURRENT_INDEX", String.valueOf(last));
                                 *  fragmentContext.startService(checkIntent);*/
                            }
                            catch (SocketTimeoutException ex)
                            {
                                ex.PrintStackTrace();
                                Intent timeoutIntent = new Intent(Constants.ACTION_SOCKET_TIMEOUT);
                                fragmentContext.SendBroadcast(timeoutIntent);
                            }
                            catch (SoapException ex)
                            {
                                Intent timeoutIntent = new Intent(Constants.SOAP_CONNECTION_FAIL);
                                fragmentContext.SendBroadcast(timeoutIntent);
                            }
                        });

                        alert.SetNegativeButton(Resource.String.cancel, (senderAlert, args) =>
                        {
                        });

                        Dialog dialog = alert.Create();
                        dialog.Show();
                    }
                    else
                    {
                        toast(fragmentContext.GetString(Resource.String.production_storage_product_locate_not_scanned));
                    }
                }
            };


            if (!isRegister)
            {
                IntentFilter filter = new IntentFilter();
                mReceiver = new MyBoradcastReceiver();
                filter.AddAction(Constants.SOAP_CONNECTION_FAIL);
                filter.AddAction(Constants.ACTION_SOCKET_TIMEOUT);
                filter.AddAction(Constants.ACTION_CHECK_TT_PRODUCT_ENTRY_ALREADY_CONFIRM_YES);
                filter.AddAction(Constants.ACTION_CHECK_TT_PRODUCT_ENTRY_ALREADY_CONFIRM_NO);
                filter.AddAction(Constants.ACTION_CHECK_TT_PRODUCT_ENTRY_ALREADY_CONFIRM_FAILED);

                filter.AddAction(Constants.ACTION_GET_TT_PRODUCT_ENTRY_FAILED);
                filter.AddAction(Constants.ACTION_GET_TT_PRODUCT_ENTRY_SUCCESS);
                filter.AddAction(Constants.ACTION_GET_TT_PRODUCT_ENTRY_EMPTY);

                filter.AddAction(Constants.ACTION_PRODUCT_CHECK_STOCK_LOCATE_NO_EXIST_YES);
                filter.AddAction(Constants.ACTION_PRODUCT_CHECK_STOCK_LOCATE_NO_EXIST_NO);
                filter.AddAction(Constants.ACTION_PRODUCT_CHECK_STOCK_LOCATE_NO_EXIST_FAILED);

                filter.AddAction(Constants.ACTION_PRODUCT_UPDATE_TT_PRODUCT_ENTRY_LOCATE_NO_FAILED);
                filter.AddAction(Constants.ACTION_PRODUCT_UPDATE_TT_PRODUCT_ENTRY_LOCATE_NO_SUCCESS);

                filter.AddAction(Constants.ACTION_EXECUTE_TT_FAILED);
                filter.AddAction(Constants.ACTION_PRODUCT_IN_STOCK_WORK_COMPLETE);
                filter.AddAction(Constants.ACTION_PRODUCT_SWIPE_LAYOUT_UPDATE);

                filter.AddAction(Constants.ACTION_GET_TT_ERROR_STATUS_FAILED);
                filter.AddAction(Constants.ACTION_GET_TT_ERROR_STATUS_SUCCESS);

                filter.AddAction(Constants.ACTION_PRODUCT_DELETE_ITEM_CONFIRM);
                filter.AddAction("unitech.scanservice.data");
                fragmentContext.RegisterReceiver(mReceiver, filter);
                isRegister = true;
            }

            return(view);
        }