/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.udacity.example.quizexample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

/**
 * Gets the data from the ContentProvider and shows a series of flash cards.
 */

public class MainActivity extends AppCompatActivity {

    // The current state of the app
    private int mCurrentState;

    // TODO (3) Create an instance variable storing a Cursor called mData
    private Button mButton;

    // This state is when the word definition is hidden and clicking the button will therefore
    // show the definition
    private final int STATE_HIDDEN = 0;

    // This state is when the word definition is shown and clicking the button will therefore
    // advance the app to the next word
    private final int STATE_SHOWN = 1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Get the views
        mButton = (Button) findViewById(R.id.button_next);

        // TODO (5) Create and execute your AsyncTask here
    }

    /**
     * This is called from the layout when the button is clicked and switches between the
     * two app states.
     * @param view The view that was clicked
     */
    public void onButtonClick(View view) {

        // Either show the definition of the current word, or if the definition is currently
        // showing, move to the next word.
        switch (mCurrentState) {
            case STATE_HIDDEN:
                showDefinition();
                break;
            case STATE_SHOWN:
                nextWord();
                break;
        }
    }

    public void nextWord() {

        // Change button text
        mButton.setText(getString(R.string.show_definition));

        mCurrentState = STATE_HIDDEN;

    }

    public void showDefinition() {

        // Change button text
        mButton.setText(getString(R.string.next_word));

        mCurrentState = STATE_SHOWN;

    }

    // TODO (1) Create AsyncTask with the following generic types <Void, Void, Cursor>
    // TODO (2) In the doInBackground method, write the code to access the DroidTermsExample
    // provider and return the Cursor object
    // TODO (4) In the onPostExecute method, store the Cursor object in mData

}

@@ -656,16 +656,117 @@
 ample;%0A%0A
+import android.content.ContentResolver;%0Aimport android.database.Cursor;%0Aimport android.os.AsyncTask;%0A
 import a
@@ -889,16 +889,90 @@
 utton;%0A%0A
+import com.udacity.example.droidtermsprovider.DroidTermsExampleContract;%0A%0A
 /**%0A * G
@@ -1179,20 +1179,25 @@
 %0A    // 
-TODO
+completed
  (3) Cre
@@ -1278,16 +1278,42 @@
 mButton;
+%0A    private Cursor mData;
 %0A%0A    //
@@ -1904,20 +1904,25 @@
      // 
-TODO
+completed
  (5) Cre
@@ -1957,16 +1957,55 @@
 sk here%0A
+        new TermQueryTask().execute();%0A
     %7D%0A%0A 
@@ -2920,20 +2920,25 @@
 %0A    // 
-TODO
+completed
  (1) Cre
@@ -3012,20 +3012,25 @@
 %0A    // 
-TODO
+completed
  (2) In 
@@ -3159,12 +3159,17 @@
  // 
-TODO
+completed
  (4)
@@ -3230,12 +3230,503 @@
 in mData
+%0A    public class TermQueryTask extends AsyncTask%3CVoid, Void, Cursor%3E%7B%0A%0A%0A        @Override%0A        protected Cursor doInBackground(Void... voids) %7B%0A%0A            ContentResolver resolver = getContentResolver();%0A            Cursor cursor = resolver.query(DroidTermsExampleContract.CONTENT_URI,%0A                    null, null, null, null);%0A            return cursor;%0A        %7D%0A%0A        @Override%0A        protected void onPostExecute(Cursor cursor)%7B%0A%0A            mData = cursor;%0A        %7D%0A%0A    %7D
 %0A%0A%7D%0A

complete adding asynctask and using resolver within asynctask class