상속: BaseAdapter
예제 #1
0
        private void ReloadData(int startId)
        {
            m_AllTasks.Clear();
            foreach(var task in DataManager.GetTasks(Settings.SortBy))
            {
                m_AllTasks.Add(task);
            }

            #if DEBUG
            if(m_AllTasks.Count == 0)
            {
                m_AllTasks = new JavaList<TaskModel>();
                foreach (var item in m_FakeData)
                {
                    var task = new TaskModel {Task = item};
                    task.ID = DataManager.SaveTask(task);
                    m_AllTasks.Add(task);
                }
            }
            #endif
            RunOnUiThread(() =>
            {
                ListAdapter = new TaskAdapter(this, m_AllTasks);
                if (ListView.Visibility == ViewStates.Gone)
                {
                    ListView.Visibility = ViewStates.Visible;
                    ListView.StartAnimation(AnimationUtils.LoadAnimation(this, Resource.Animation.fadein));
                }
            });

            SetChecks();

            SetActionBar();

            if (startId == 0)
                    return;

            var firstTask = m_AllTasks.FirstOrDefault(t => t.ID == startId);
            if(firstTask == null)
                return;

            var itemIndex = m_AllTasks.IndexOf(firstTask);
            RunOnUiThread(()=> ListView.SetSelection(itemIndex));
        }
예제 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            SetTheme(Settings.ThemeSetting == 0 ? Resource.Style.MyTheme : Resource.Style.MyThemeDark);

            base.OnCreate(bundle);

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

            m_OriginalTheme = Settings.ThemeSetting;
            m_OriginalAccent = Settings.ThemeAccent;

            Window.SetSoftInputMode(SoftInput.StateAlwaysHidden);

            m_AllTasks = new JavaList<TaskModel>();
            m_EditTaskPosition = 0;

            m_AddButton = FindViewById<ImageButton>(Resource.Id.button_add_task);
            m_MicrophoneButton = FindViewById<ImageButton>(Resource.Id.button_microphone);
            m_TaskEditText = FindViewById<EditText>(Resource.Id.edit_text_new_task);

            ActionBar = FindViewById<ActionBar.ActionBar>(Resource.Id.actionbar);

            //ActionBar.BackgroundDrawable = Resources.GetDrawable(Resource.Drawable.actionbar_background_blue);
            //ActionBar.ItemBackgroundDrawable = Resources.GetDrawable(Resource.Drawable.actionbar_btn_blue);
            //ActionBar.SeparatorColor = Resources.GetColor(Resource.Color.actionbar_separatorcolor_blue);
            ActionBar.Title = "Tasks";
            ActionBar.CurrentActivity = this;
            ActionBar.SetHomeLogo(Resource.Drawable.ic_launcher);
            RegisterForContextMenu(ListView);

            m_TaskEditText.SetOnEditorActionListener(this);

            ListView.ChoiceMode = ChoiceMode.Multiple;

            m_AddButton.Click += (sender, args) => AddNewTask();

            m_AddButton.SetImageResource(Settings.ThemeSetting == 0 ? Resource.Drawable.ic_action_add : Resource.Drawable.ic_action_add_dark);
            m_MicrophoneButton.SetImageResource(Settings.ThemeSetting == 0 ? Resource.Drawable.ic_action_microphone : Resource.Drawable.ic_action_microphone_dark);

            m_AddButton.SetBackgroundResource(Settings.ImageButtonDrawable);
            m_MicrophoneButton.SetBackgroundResource(Settings.ImageButtonDrawable);

            // remove speech if it doesn't exist
            var activities =PackageManager.QueryIntentActivities(new Intent(RecognizerIntent.ActionRecognizeSpeech), 0);
            if (activities.Count == 0)
            {
                m_MicrophoneButton.Visibility = ViewStates.Gone;
            }
            else
            {
                m_MicrophoneButton.Click += (sender, args) => StartVoiceRecognitionActivity();
            }

            m_TextToSpeech = new TextToSpeech(this, this);

            var saveState = LastNonConfigurationInstance as SaveState;
            if (saveState != null)
            {
                m_AllTasks = new JavaList<TaskModel>(saveState.Tasks);
                ListView.Visibility = ViewStates.Visible;
                RunOnUiThread(() => ListAdapter = new TaskAdapter(this, m_AllTasks));
                RunOnUiThread(() => ListView.SetSelection(saveState.LastPosition));
                SetChecks();
                m_TaskEditText.Text = saveState.NewTaskText;
                m_Editing = saveState.Editing;
                m_EditTaskPosition = saveState.EditIndex;
            }
            else
            {
                FlurryAgent.OnPageView();
                FlurryAgent.LogEvent("MainActivity");
                ReloadData(0);
            }

            SetActionBar();
            try
            {
                if(Intent.GetBooleanExtra("CameFromWidget", false))
                {
                    FocusMainText();
                    return;
                }

                if(Intent.Action == TaskWidgetProvider.UpdateIntent)

                if (Intent.ActionSend != Intent.Action || Intent.Type == null)
                    return;

                if ("text/plain" != Intent.Type)
                    return;

                var sharedText = Intent.GetStringExtra(Intent.ExtraText);
                if (!string.IsNullOrEmpty(sharedText))
                {
                    m_TaskEditText.Text = sharedText;
                    m_Editing = false;
                    SetActionBar();
                }
            }
            finally
            {
                var version = Resources.GetString(Resource.String.VersionNumber);
                if (Settings.CurrentVersionNumber != version)
                {
                    Settings.CurrentVersionNumber = version;
                    PopUpHelpers.ShowOKPopup(this, Resource.String.update_title, Resource.String.update_message, (ok)=>{ });
                }
            }
        }