コード例 #1
0
    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
        ICursor cursor = null;

        try
        {
            // assuming image
            var docID       = DocumentsContract.GetDocumentId(data.Data);
            var id          = docID.Split(':')[1];
            var whereSelect = MediaStore.Images.ImageColumns.Id + "=?";
            var projections = new string[] { MediaStore.Images.ImageColumns.Data };
            // Try internal storage first
            cursor = ContentResolver.Query(MediaStore.Images.Media.InternalContentUri, projections, whereSelect, new string[] { id }, null);
            if (cursor.Count == 0)
            {
                // not found on internal storage, try external storage
                cursor = ContentResolver.Query(MediaStore.Images.Media.ExternalContentUri, projections, whereSelect, new string[] { id }, null);
            }
            var colData = cursor.GetColumnIndexOrThrow(MediaStore.Images.ImageColumns.Data);
            cursor.MoveToFirst();
            var fullPathToImage = cursor.GetString(colData);
            Log.Info("MediaPath", fullPathToImage);
        }
        catch (Error err)
        {
            Log.Error("MediaPath", err.Message);
        }
        finally
        {
            cursor?.Close();
            cursor?.Dispose();
        }
    }
コード例 #2
0
 private static List<Transaction> cursorToList(ICursor c)
 {
     List<Transaction> transactions = new List<Transaction>();
     if (c != null)
     {
         while (c.MoveToNext())
         {
             Transaction purchase = BillingDB.createTransaction(c);
             transactions.Add(purchase);
         }
         c.Close();
     }
     return transactions;
 }
コード例 #3
0
        private void AddData()
        {
            ICursor selectData = sqliteDB.RawQuery("SELECT Course FROM courses WHERE College LIKE " + collss + " AND Department LIKE " + depss + " ORDER BY Department", new string[] { });

            if (selectData.Count > 0)
            {
                selectData.MoveToFirst();
                do
                {
                    string value = selectData.GetString(selectData.GetColumnIndex("Course"));
                    courselist.Add(value);
                }while (selectData.MoveToNext());
                selectData.Close();
            }
        }
コード例 #4
0
		private void OnSpeakersQueryComplete (ICursor cursor)
		{
			try {
				mSpeakersCursor = true;
				// TODO: remove any existing speakers from layout, since this cursor
				// might be from a data change notification.
				ViewGroup speakersGroup = mRootView.FindViewById<ViewGroup> (Resource.Id.session_speakers_block);
				LayoutInflater inflater = Activity.LayoutInflater;
	
				bool hasSpeakers = false;
	
				while (cursor.MoveToNext()) {
					String speakerName = cursor.GetString (SpeakersQuery.SPEAKER_NAME);
					if (TextUtils.IsEmpty (speakerName)) {
						continue;
					}
	
					String speakerImageUrl = cursor.GetString (SpeakersQuery.SPEAKER_IMAGE_URL);
					String speakerCompany = cursor.GetString (SpeakersQuery.SPEAKER_COMPANY);
					String speakerUrl = cursor.GetString (SpeakersQuery.SPEAKER_URL);
					String speakerAbstract = cursor.GetString (SpeakersQuery.SPEAKER_ABSTRACT);
	
					String speakerHeader = speakerName;
					if (!TextUtils.IsEmpty (speakerCompany)) {
						speakerHeader += ", " + speakerCompany;
					}
	
					var speakerView = inflater.Inflate (Resource.Layout.speaker_detail, speakersGroup, false);
					var speakerHeaderView = speakerView.FindViewById<TextView> (Resource.Id.speaker_header);
					var speakerImgView = speakerView.FindViewById<ImageView> (Resource.Id.speaker_image);
					var speakerUrlView = speakerView.FindViewById<TextView> (Resource.Id.speaker_url);
					var speakerAbstractView = speakerView.FindViewById<TextView> (Resource.Id.speaker_abstract);
					
					if (!TextUtils.IsEmpty (speakerImageUrl)) {
						BitmapUtils.FetchImage (Activity, new Java.Lang.String (speakerImageUrl), null, null, (result) => {
							Activity.RunOnUiThread (() => {
								speakerImgView.SetImageBitmap (result);
							});
						});
					}
	
					speakerHeaderView.Text = speakerHeader;
					UIUtils.SetTextMaybeHtml (speakerAbstractView, speakerAbstract);
	
					if (!TextUtils.IsEmpty (speakerUrl)) {
						UIUtils.SetTextMaybeHtml (speakerUrlView, speakerUrl);
						speakerUrlView.Visibility = ViewStates.Visible;
					} else {
						speakerUrlView.Visibility = ViewStates.Gone;
					}
	
					speakersGroup.AddView (speakerView);
					hasSpeakers = true;
					mHasSummaryContent = true;
				}
	
				speakersGroup.Visibility = (hasSpeakers ? ViewStates.Visible : ViewStates.Gone);
	
				// Show empty message when all data is loaded, and nothing to show
				if (mSessionCursor && !mHasSummaryContent) {
					mRootView.FindViewById (Android.Resource.Id.Empty).Visibility = ViewStates.Visible;
				}
			} finally {
				if (null != cursor) {
					cursor.Close ();
				}
			}
		}
コード例 #5
0
		/**
	     * Handle {@link TracksQuery} {@link Cursor}.
	     */
		private void OnTrackQueryComplete (ICursor cursor)
		{
			try {
				if (!cursor.MoveToFirst ()) {
					return;
				}
	
				// Use found track to build title-bar
				ActivityHelper activityHelper = ((BaseActivity)Activity).ActivityHelper;
				activityHelper.SetActionBarTitle (new Java.Lang.String (cursor.GetString (TracksQuery.TRACK_NAME)));
				activityHelper.SetActionBarColor (new Color (cursor.GetInt (TracksQuery.TRACK_COLOR)));
			} finally {
				cursor.Close ();
			}
		}
コード例 #6
0
		/**
	     * Handle {@link SessionsQuery} {@link Cursor}.
	     */
		private void OnSessionQueryComplete (ICursor cursor)
		{
			try {
				mSessionCursor = true;
				if (!cursor.MoveToFirst ()) {
					return;
				}
	
				// Format time block this session occupies
				long blockStart = cursor.GetLong (SessionsQuery.BLOCK_START);
				long blockEnd = cursor.GetLong (SessionsQuery.BLOCK_END);
				String roomName = cursor.GetString (SessionsQuery.ROOM_NAME);
				String subtitle = UIUtils.FormatSessionSubtitle (blockStart, blockEnd, roomName, Activity);
	
				mTitleString = cursor.GetString (SessionsQuery.TITLE);
				mTitle.Text = mTitleString;
				mSubtitle.Text = subtitle;
	
				mUrl = cursor.GetString (SessionsQuery.URL);
				if (TextUtils.IsEmpty (mUrl)) {
					mUrl = "";
				}
	
				mHashtag = cursor.GetString (SessionsQuery.HASHTAG);
				mTagDisplay = mRootView.FindViewById<TextView> (Resource.Id.session_tags_button);
				if (!TextUtils.IsEmpty (mHashtag)) {
					// Create the button text
					SpannableStringBuilder sb = new SpannableStringBuilder ();
					sb.Append (GetString (Resource.String.tag_stream) + " ");
					int boldStart = sb.Length ();
					sb.Append (GetHashtagsString ());
					sb.SetSpan (sBoldSpan, boldStart, sb.Length (), SpanTypes.ExclusiveExclusive);
	
					mTagDisplay.Text = (string)sb;
					mTagDisplay.Click += (sender, e) => {
						Intent intent = new Intent (Activity, typeof(TagStreamActivity));
						intent.PutExtra (TagStreamFragment.EXTRA_QUERY, GetHashtagsString ());
						StartActivity (intent);	
					};
					
				} else {
					mTagDisplay.Visibility = ViewStates.Gone;
				}
	
				mRoomId = cursor.GetString (SessionsQuery.ROOM_ID);
	
				// Unregister around setting checked state to avoid triggering
				// listener since change isn't user generated.
				mStarred.CheckedChange += null;
				mStarred.Checked = cursor.GetInt (SessionsQuery.STARRED) != 0;
				mStarred.CheckedChange += HandleCheckedChange;
	
				String sessionAbstract = cursor.GetString (SessionsQuery.ABSTRACT);
				if (!TextUtils.IsEmpty (sessionAbstract)) {
					UIUtils.SetTextMaybeHtml (mAbstract, sessionAbstract);
					mAbstract.Visibility = ViewStates.Visible;
					mHasSummaryContent = true;
				} else {
					mAbstract.Visibility = ViewStates.Gone;
				}
	
				View requirementsBlock = mRootView.FindViewById (Resource.Id.session_requirements_block);
				String sessionRequirements = cursor.GetString (SessionsQuery.REQUIREMENTS);
				if (!TextUtils.IsEmpty (sessionRequirements)) {
					UIUtils.SetTextMaybeHtml (mRequirements, sessionRequirements);
					requirementsBlock.Visibility = ViewStates.Visible;
					mHasSummaryContent = true;
				} else {
					requirementsBlock.Visibility = ViewStates.Gone;
				}
	
				// Show empty message when all data is loaded, and nothing to show
				if (mSpeakersCursor && !mHasSummaryContent) {
					mRootView.FindViewWithTag (Android.Resource.Id.Empty).Visibility = ViewStates.Visible;
				}
	
				//AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString);
	
				UpdateLinksTab (cursor);
				UpdateNotesTab ();
	
			} finally {
				cursor.Close ();
			}
		}
コード例 #7
0
		/**
	     * {@inheritDoc}
	     */
		public void OnQueryComplete (int token, Java.Lang.Object cookie, ICursor cursor)
		{
			if (Activity == null) {
				return;
			}
	
			if (token == SessionsQuery._TOKEN) {
				OnSessionQueryComplete (cursor);
			} else if (token == TracksQuery._TOKEN) {
				OnTrackQueryComplete (cursor);
			} else if (token == SpeakersQuery._TOKEN) {
				OnSpeakersQueryComplete (cursor);
			} else {
				cursor.Close ();
			}
		}
コード例 #8
0
		/**
	     * {@inheritDoc}
	     */
		public void OnQueryComplete (int token, Java.Lang.Object cookie, ICursor cursor)
		{
			if (Activity == null) {
				return;
			}
	
			try {
				if (!cursor.MoveToFirst ()) {
					return;
				}
	
				mNameString = cursor.GetString (VendorsQuery.NAME);
				mName.Text = mNameString;
	
				// Unregister around setting checked state to avoid triggering
				// listener since change isn't user generated.
				mStarred.CheckedChange += null;
				mStarred.Checked = cursor.GetInt (VendorsQuery.STARRED) != 0;
				mStarred.CheckedChange += HandleCheckedChange;
	
				// Start background fetch to load vendor logo
				String logoUrl = cursor.GetString (VendorsQuery.LOGO_URL);
	
				if (!TextUtils.IsEmpty (logoUrl)) {
					BitmapUtils.FetchImage (Activity, new Java.Lang.String (logoUrl), null, null, (result) => {
						Activity.RunOnUiThread (() => {
							if (result == null) {
								mLogo.Visibility = ViewStates.Gone;
							} else {
								mLogo.Visibility = ViewStates.Visible;
								mLogo.SetImageBitmap (result);
							}
						});
					});
				}
	
				mUrl.Text = cursor.GetString (VendorsQuery.URL);
				mDesc.Text = cursor.GetString (VendorsQuery.DESC);
				mProductDesc.Text = cursor.GetString (VendorsQuery.PRODUCT_DESC);
	
				mTrackId = cursor.GetString (VendorsQuery.TRACK_ID);
	
				// Assign track details when found
				// TODO: handle vendors not attached to track
				ActivityHelper activityHelper = ((BaseActivity)Activity).ActivityHelper;
				activityHelper.SetActionBarTitle (new Java.Lang.String (cursor.GetString (VendorsQuery.TRACK_NAME)));
				activityHelper.SetActionBarColor (new Color (cursor.GetInt (VendorsQuery.TRACK_COLOR)));
	
				//AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sandbox/Vendors/" + mNameString);
	
			} finally {
				cursor.Close ();
			}
		}
コード例 #9
0
		public void OnQueryComplete (int token, Java.Lang.Object cookie, ICursor cursor)
		{
			if (Activity == null) {
	            return;
	        }
			
			Day day = (Day) cookie;
			
			// Clear out any existing sessions before inserting again
	        day.BlocksView.RemoveAllBlocks();
			
			try {
	            while (cursor.MoveToNext()) {
	                string type = cursor.GetString(BlocksQuery.BLOCK_TYPE);
	                
					// TODO: place random blocks at bottom of entire layout
					int column;
					try {
						column = TypeColumnMap[type];
					} catch {
						continue;
					}
	                
	                string blockId = cursor.GetString(BlocksQuery.BLOCK_ID);
	                string title = cursor.GetString(BlocksQuery.BLOCK_TITLE);
	                long start = cursor.GetLong(BlocksQuery.BLOCK_START);
	                long end = cursor.GetLong(BlocksQuery.BLOCK_END);
	                bool containsStarred = cursor.GetInt(BlocksQuery.CONTAINS_STARRED) != 0;
	
	                BlockView blockView = new BlockView(Activity, blockId, title, start, end, containsStarred, column);
	
	                int sessionsCount = cursor.GetInt(BlocksQuery.SESSIONS_COUNT);
					
	                if (sessionsCount > 0) {
	                    blockView.Click += HandleClick;
	                } else {
	                    blockView.Focusable = false;
	                    blockView.Enabled = false;
	                    LayerDrawable buttonDrawable = (LayerDrawable) blockView.Background;
	                    buttonDrawable.GetDrawable(0).SetAlpha(DISABLED_BLOCK_ALPHA);
	                    buttonDrawable.GetDrawable(2).SetAlpha(DISABLED_BLOCK_ALPHA);
	                }
	
	                day.BlocksView.AddView(blockView);
	            }
	        } finally {
	            cursor.Close();
	        }

		}
コード例 #10
0
		protected override void OnQueryComplete (int token, Java.Lang.Object cookie, ICursor cursor)
		{
			var listener = mListener == null ? null : mListener.Target as AsyncQueryListener;
	        if (listener != null) {
	            listener.OnQueryComplete(token, cookie, cursor);
	        } else if (cursor != null) {
	            cursor.Close();
	        }
		}
コード例 #11
0
		/**
	     * Handle {@link TracksQuery} {@link Cursor}.
	     */
		private void OnTrackQueryComplete (ICursor cursor)
		{
			try {
				if (!cursor.MoveToFirst ()) {
					return;
				}
	
				// Use found track to build title-bar
				ActivityHelper activityHelper = ((BaseActivity)Activity).ActivityHelper;
				String trackName = cursor.GetString (TracksQuery.TRACK_NAME);
				activityHelper.SetActionBarTitle (new Java.Lang.String (trackName));
				activityHelper.SetActionBarColor (new Color (cursor.GetInt (TracksQuery.TRACK_COLOR)));
				//AnalyticsUtils.getInstance(getActivity()).trackPageView("/Tracks/" + trackName);
			} finally {
				cursor.Close ();
			}
		}
コード例 #12
0
		public void OnQueryComplete (int token, Java.Lang.Object cookie, ICursor cursor)
		{
			if (Activity == null) {
				return;
			}
	
			if (token == VendorsQuery._TOKEN || token == SearchQuery._TOKEN) {
				OnVendorsOrSearchQueryComplete (cursor);
			} else if (token == TracksQuery._TOKEN) {
				OnTrackQueryComplete (cursor);
			} else {
				cursor.Close ();
			}
		}
コード例 #13
0
ファイル: TestProvider.cs プロジェクト: Screech129/WeatherApp
        /*
           This helper function Deletes all records from both database tables using the ContentProvider.
           It also queries the ContentProvider to make sure that the database has been successfully
           Deleted, so it cannot be used until the Query and Delete functions have been written
           in the ContentProvider.

           Students: Replace the calls to DeleteAllRecordsFromDB with this one after you have written
           the Delete functionality in the ContentProvider.
         */
        public void DeleteAllRecordsFromProvider()
        {
            context.ContentResolver.Delete (
                WeatherContractOpen.WeatherEntryOpen.CONTENT_URI,
                null,
                null
            );
            context.ContentResolver.Delete (
                WeatherContractOpen.LocationEntryOpen.CONTENT_URI,
                null,
                null
            );

            cursor = context.ContentResolver.Query (
                WeatherContractOpen.WeatherEntryOpen.CONTENT_URI,
                null,
                null,
                null,
                null
            );
            Assert.AreEqual (0, cursor.Count, "Error: Records not Deleted from Weather table during Delete");
            cursor.Close ();

            cursor = context.ContentResolver.Query (
                WeatherContractOpen.LocationEntryOpen.CONTENT_URI,
                null,
                null,
                null,
                null
            );
            Assert.AreEqual (0, cursor.Count, "Error: Records not Deleted from Location table during Delete");
            cursor.Close ();
        }
コード例 #14
0
ファイル: TestProvider.cs プロジェクト: Screech129/WeatherApp
        /*
        This test uses the provider to insert and then update the data. Uncomment this test to
        see if your update location is functioning correctly.
         */
        public void testUpdateLocation()
        {
            const string LOG_TAG = "Provider Test";

            // Create a new map of values, where column names are the keys
            ContentValues values = TestUtilitiesOpen.createNorthPoleLocationValues ();

            Android.Net.Uri locationUri = context.ContentResolver.
                        Insert (WeatherContractOpen.LocationEntryOpen.CONTENT_URI, values);
            long locationRowId = ContentUris.ParseId (locationUri);

            // Verify we got a row back.
            Assert.IsTrue (locationRowId != -1);
            Log.Debug (LOG_TAG, "New row id: " + locationRowId);

            ContentValues updatedValues = new ContentValues (values);
            updatedValues.Put (WeatherContractOpen.LocationEntryOpen._ID, locationRowId);
            updatedValues.Put (WeatherContractOpen.LocationEntryOpen.COLUMN_CITY_NAME, "Santa's Village");

            // Create a cursor with observer to make sure that the content provider is notifying
            // the observers as expected
            var location = context.ContentResolver.Query (WeatherContractOpen.LocationEntryOpen.CONTENT_URI, null, null, null, null);

            TestUtilitiesOpen.TestContentObserver tco = TestUtilitiesOpen.getTestContentObserver ();
            location.RegisterContentObserver (tco);

            int count = context.ContentResolver.Update (
                            WeatherContractOpen.LocationEntryOpen.CONTENT_URI, updatedValues, WeatherContractOpen.LocationEntryOpen._ID + "= ?",
                            new String[] { locationRowId.ToString () });
            Assert.AreEqual (count, 1);

            // Test to make sure our observer is called.  If not, we throw an assertion.
            //
            // Students: If your code is failing here, it means that your content provider
            // isn't calling getContext().ContentResolver.notifyChange(uri, null);
            tco.waitForNotificationOrFail ();

            location.UnregisterContentObserver (tco);
            location.Close ();

            // A cursor is your primary interface to the Query results.
            cursor = context.ContentResolver.Query (
                WeatherContractOpen.LocationEntryOpen.CONTENT_URI,
                null,   // projection
                WeatherContractOpen.LocationEntryOpen._ID + " = " + locationRowId,
                null,   // Values for the "where" clause
                null    // sort order
            );

            Assert.IsTrue (location.MoveToFirst (), "Cursor is empty");
            TestUtilitiesOpen.validateCurrentRecord ("testUpdateLocation.  Error validating location entry update.",
                cursor, updatedValues);

            cursor.Close ();
        }
コード例 #15
0
ファイル: TestProvider.cs プロジェクト: Screech129/WeatherApp
        public void testBulkInsert()
        {
            // first, let's create a location value
            ContentValues testValues = TestUtilitiesOpen.createNorthPoleLocationValues ();
            Android.Net.Uri locationUri = context.ContentResolver.Insert (WeatherContractOpen.LocationEntryOpen.CONTENT_URI, testValues);
            long locationRowId = ContentUris.ParseId (locationUri);

            // Verify we got a row back.
            Assert.IsTrue (locationRowId != -1);

            // Data's inserted.  IN THEORY.  Now pull some out to stare at it and verify it made
            // the round trip.

            // A cursor is your primary interface to the Query results.
            cursor = context.ContentResolver.Query (
                WeatherContractOpen.LocationEntryOpen.CONTENT_URI,
                null, // leaving "columns" null just returns all the columns.
                null, // cols for "where" clause
                null, // values for "where" clause
                null  // sort order
            );

            Assert.IsTrue (cursor.MoveToFirst (), "Cursor is empty");
            TestUtilitiesOpen.validateCurrentRecord ("testBulkInsert. Error validating WeatherContractOpen.LocationEntryOpen.",
                cursor, testValues);

            // Now we can bulkInsert some weather.  In fact, we only implement BulkInsert for weather
            // entries.  With ContentProviders, you really only have to implement the features you
            // use, after all.
            ContentValues[] bulkInsertContentValues = createBulkInsertWeatherValues (locationRowId);

            // Register a content observer for our bulk insert.
            TestUtilitiesOpen.TestContentObserver weatherObserver = TestUtilitiesOpen.getTestContentObserver ();
            context.ContentResolver.RegisterContentObserver (WeatherContractOpen.WeatherEntryOpen.CONTENT_URI, true, weatherObserver);

            int insertCount = context.ContentResolver.BulkInsert (WeatherContractOpen.WeatherEntryOpen.CONTENT_URI, bulkInsertContentValues);

            // Students:  If this fails, it means that you most-likely are not calling the
            // getContext().ContentResolver.notifyChange(uri, null); in your BulkInsert
            // ContentProvider method.
            weatherObserver.waitForNotificationOrFail ();
            context.ContentResolver.UnregisterContentObserver (weatherObserver);

            Assert.AreEqual (insertCount, BULK_INSERT_RECORDS_TO_INSERT);

            // A cursor is your primary interface to the Query results.
            cursor = context.ContentResolver.Query (
                WeatherContractOpen.WeatherEntryOpen.CONTENT_URI,
                null, // leaving "columns" null just returns all the columns.
                null, // cols for "where" clause
                null, // values for "where" clause
                WeatherContractOpen.WeatherEntryOpen.COLUMN_DATE + " ASC"  // sort order == by DATE ASCENDING
            );

            // we should have as many records in the database as we've inserted
            Assert.AreEqual (cursor.Count, BULK_INSERT_RECORDS_TO_INSERT);

            // and let's make sure they match the ones we created
            cursor.MoveToFirst ();
            for (int i = 0; i < BULK_INSERT_RECORDS_TO_INSERT; i++, cursor.MoveToNext ()) {
                TestUtilitiesOpen.validateCurrentRecord ("testBulkInsert.  Error validating WeatherContractOpen.WeatherEntryOpen " + i,
                    cursor, bulkInsertContentValues [i]);
            }
            cursor.Close ();
        }