public static CrimeLab GetInstance(Context c) { if (sCrimeLab == null) { sCrimeLab = new CrimeLab(c.ApplicationContext); } return sCrimeLab; }
public static CrimeLab GetInstance(Context c) { if (sCrimeLab == null) { sCrimeLab = new CrimeLab(c.ApplicationContext); } return(sCrimeLab); }
public override void OnResume() { base.OnResume(); // Create a new ListAdapter instead of updating to deal with delete // not calling OnCreate of this fragment // ((CrimeAdapter)this.ListAdapter).NotifyDataSetChanged(); CrimeAdapter adapter = new CrimeAdapter(Activity, CrimeLab.GetInstance(CrimeListActivity.Context).Crimes); this.ListAdapter = adapter; }
private void NewCrime() { Crime crime = new Crime(); CrimeLab.GetInstance(Activity).AddCrime(crime); CrimeAdapter adapter = this.ListAdapter as CrimeAdapter; adapter.Add(crime); // adapter.NotifyDataSetChanged(); // Start Activity or load fragment into detail contatiner // Intent i = new Intent(Activity, typeof(CrimePagerActivity)); // i.PutExtra(CrimeFragment.EXTRA_CRIME_ID, crime.Id); // StartActivity(i); mCallbacks.OnCrimeSelected(crime); }
public override bool OnContextItemSelected(IMenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.MenuInfo; int position = info.Position; CrimeAdapter adapter = (CrimeAdapter)ListAdapter; Crime crime = adapter.GetItem(position); switch (item.ItemId) { case Resource.Id.menu_item_delete_crime: CrimeLab.GetInstance(Activity).DeleteCrime(crime); adapter.Remove(crime); return(true); } return(base.OnContextItemSelected(item)); }
public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Title set in CrimePagerActivity when page is selected // Activity.SetTitle(Resource.String.crime_title); // Subtitle not used in this fragment // if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb) // Activity.ActionBar.SetSubtitle(Resource.String.title_activity_crime); // Create your fragment here string crimeId = Arguments.GetString(EXTRA_CRIME_ID); mCrime = CrimeLab.GetInstance(Activity).GetCrime(crimeId); if (mCrime.Photo != null && !File.Exists(mCrime.Photo.Filename)) { // System.Diagnostics.Debug.WriteLine(String.Format("Crime '{0}' removed missing file link: {1}", mCrime.Title, mCrime.Photo.Filename), TAG); mCrime.Photo = null; } HasOptionsMenu = true; }
public bool OnActionItemClicked(ActionMode mode, IMenuItem item) { switch (item.ItemId) { case Resource.Id.menu_item_delete_crime: CrimeAdapter adapter = (CrimeAdapter)ListAdapter; CrimeLab crimelab = CrimeLab.GetInstance(Activity); for (int i = adapter.Count - 1; i >= 0; i--) { if (ListView.IsItemChecked(i)) { crimelab.DeleteCrime(adapter.GetItem(i)); adapter.Remove(adapter.GetItem(i)); } } mode.Finish(); adapter.NotifyDataSetChanged(); return(true); default: return(false); } }
public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case Resource.Id.menu_item_delete_crime: AlertDialog.Builder ad = new AlertDialog.Builder(Activity); ad.SetTitle(mCrime.Title); ad.SetMessage("Do you really want to delete this crime?"); ad.SetCancelable(true); ad.SetPositiveButton("DELETE", delegate(object s, DialogClickEventArgs evt) { CrimeLab crimelab = CrimeLab.GetInstance(Activity); crimelab.DeleteCrime(mCrime); // Using ParentActivity and NavUtils causes OnCreate to be called again // in CrimeListFragment, causing the subtitle view to be reset // if (NavUtils.GetParentActivityName(Activity) != null) { // NavUtils.NavigateUpFromSameTask(Activity); // } mCallBacks.RemoveCrimeFragment(); mCallBacks.OnCrimeUpdated(); }); ad.SetNegativeButton("Cancel", (s, evt) => {}); ad.Show(); return(true); case Android.Resource.Id.Home: // Using ParentActivity and NavUtils causes OnCreate to be called again // in CrimeListFragment, causing the subtitle view to be reset // if (NavUtils.GetParentActivityName(Activity) != null) { // NavUtils.NavigateUpFromSameTask(Activity); // } mCallBacks.RemoveCrimeFragment(); return(true); default: return(base.OnOptionsItemSelected(item)); } }
protected override void OnCreate(Android.OS.Bundle savedInstanceState) { //RequestWindowFeature(Android.Views.WindowFeatures.ActionBar); base.OnCreate(savedInstanceState); CrimePagerActivity.context = this; mViewPager = new ViewPager(this); mViewPager.Id = (Resource.Id.viewPager); SetContentView(mViewPager); mCrimes = CrimeLab.GetInstance(CrimePagerActivity.context).Crimes; Title = mCrimes[0].Title; CrimePagerAdapter adapter = new CrimePagerAdapter(SupportFragmentManager); mViewPager.Adapter = adapter; mViewPager.PageSelected += (object sender, ViewPager.PageSelectedEventArgs e) => { var crime = mCrimes[e.Position]; if (crime.Title != null) { Title = crime.Title; } }; // mViewPager.SetOnPageChangeListener(this); string crimeId = Intent.GetStringExtra(CrimeFragment.EXTRA_CRIME_ID); for (int i = 0; i < mCrimes.Count; i++) { if (mCrimes[i].Id == crimeId) { mViewPager.SetCurrentItem(i, false); break; } } }
public CrimePagerAdapter(Android.Support.V4.App.FragmentManager fm) : base(fm) { CONTENT = CrimeLab.GetInstance(CrimePagerActivity.context).Crimes; }
public void UpdateUI() { CrimeAdapter adapter = new CrimeAdapter(Activity, CrimeLab.GetInstance(CrimeListActivity.Context).Crimes); this.ListAdapter = adapter; }
public override void OnPause() { base.OnPause(); CrimeLab.GetInstance(Activity).SaveCrimes(); }