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

    /*  ScheduleManager.getInstance(this.getApplicationContext());

    // check if this is first app use
    ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
    int sizeStack =  am.getRunningTasks(1).get(0).numActivities;

    if (sizeStack == 2)
    {
        // if first app use have user fill out profile

        Intent launchIntent = new Intent(this, ProfileActivity.class);
        this.startActivity(launchIntent);
    }
    else
    {
        // then set RUNBEFORE to true to turn profiles over to notification manager

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean(MainActivity.RUNBEFORE, true);
        editor.commit();
    } */
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    this.getMenuInflater().inflate(R.menu.menu_paged_intro, menu);

    this._menu = menu;

    MenuItem back = this._menu.findItem(R.id.action_previous);
    back.setVisible(false);

    MenuItem done = this._menu.findItem(R.id.action_done);
    done.setVisible(false);

    return true;
  }
  @SuppressLint("SetJavaScriptEnabled")

  /*
  protected void onCreate() {
       // check if this is first app use
       ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
       int sizeStack =  am.getRunningTasks(1).get(0).numActivities;

       // if first app use have user fill out profile
       if (sizeStack == 2)
       {Intent launchIntent = new Intent(this, ProfileActivity.class);
           this.startActivity(launchIntent);

           return;}

       // then set RUNBEFORE to true to turn profiles over to notification manager
       else {
           SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
           SharedPreferences.Editor editor = prefs.edit();
           editor.putBoolean(MainActivity.RUNBEFORE, true);
           editor.commit();

           return;
       }
   }

   */

  protected void onResume() {
    super.onResume();

    /*
            CrashManager.register(this, APP_ID, new CrashManagerListener()
            {
                public bintoolean shouldAutoUploadCrashes()
                {
                    return true;
                }
            });
    */
    final MainActivity me = this;

    ArrayList<Tool> tools = new ArrayList<Tool>();

    tools.add(
        new Tool(
            this.getString(R.string.tool_use_log),
            this.getString(R.string.desc_tool_chooser_log),
            R.drawable.ic_action_view_as_list,
            new Intent(this, ToolTrackerActivity.class)));
    tools.add(
        new Tool(
            this.getString(R.string.tool_worry_practice),
            this.getString(R.string.desc_worry_practice),
            R.drawable.ic_action_alarms,
            new Intent(this, WorryPracticeActivity.class)));
    tools.add(
        new Tool(
            this.getString(R.string.survey_wizard_title),
            this.getString(R.string.desc_survey_wizard),
            R.drawable.ic_action_keyboard,
            new Intent(this, RuminationLogActivity.class)));
    tools.add(
        new Tool(
            this.getResources().getString(R.string.tool_didactic_content),
            this.getString(R.string.desc_didactic_content),
            R.drawable.ic_action_slideshow,
            new Intent(this, PagedDidacticActivity.class)));

    ListView toolsList = (ListView) this.findViewById(R.id.list_tools);

    final ArrayAdapter<Tool> adapter =
        new ArrayAdapter<Tool>(this, R.layout.row_home_tool, tools) {
          public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
              LayoutInflater inflater = LayoutInflater.from(parent.getContext());
              convertView = inflater.inflate(R.layout.row_home_tool, parent, false);
            }

            TextView desc = (TextView) convertView.findViewById(R.id.label_tool_description);

            Tool t = this.getItem(position);

            desc.setText(t.description);

            ImageView icon = (ImageView) convertView.findViewById(R.id.icon_tool);

            if (t.icon != 0) icon.setImageDrawable(me.getResources().getDrawable(t.icon));

            return convertView;
          }
        };

    toolsList.setAdapter(adapter);

    toolsList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int which, long id) {
            Tool t = adapter.getItem(which);

            if (t.launchIntent != null) me.startActivity(t.launchIntent);
          }
        });

    String[] punBank = this.getResources().getStringArray(R.array.pun_bank);

    Random random = new SecureRandom();

    TextView puns = (TextView) this.findViewById(R.id.pun);
    puns.setText(punBank[random.nextInt(punBank.length)]);
  }
  protected void onPause() {
    super.onPause();

    // TODO: Log that user exited this activity using LogManager...
  }
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    this.getMenuInflater().inflate(R.menu.menu_activity_main, menu);

    return true;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.activity_paged_content);

    this.getSupportActionBar().setSubtitle(R.string.app_name);

    final PagedIntroActivity me = this;

    final ViewPager pager = (ViewPager) this.findViewById(R.id.pager_content);

    final ImageView background = (ImageView) this.findViewById(R.id.background_image);

    pager.setAdapter(
        new PagerAdapter() {
          public int getCount() {
            return 27;
          }

          public boolean isViewFromObject(View view, Object content) {
            return view.getTag().equals(content);
          }

          public void destroyItem(ViewGroup container, int position, Object content) {
            int toRemove = -1;

            for (int i = 0; i < container.getChildCount(); i++) {
              View child = container.getChildAt(i);

              if (this.isViewFromObject(child, content)) toRemove = i;
            }

            if (toRemove >= 0) container.removeViewAt(toRemove);
          }

          public Object instantiateItem(ViewGroup container, int position) {
            LayoutInflater inflater =
                (LayoutInflater) me.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View view = inflater.inflate(R.layout.view_paged_content, null);

            String[] contentValues = me.getResources().getStringArray(R.array.intro_content);

            TextView content = (TextView) view.findViewById(R.id.content_text);

            content.setText(contentValues[position]);

            view.setTag("" + position);

            container.addView(view);

            LayoutParams layout = (LayoutParams) view.getLayoutParams();
            layout.height = LayoutParams.MATCH_PARENT;
            layout.width = LayoutParams.MATCH_PARENT;

            view.setLayoutParams(layout);

            return view.getTag();
          }
        });

    pager.setOnPageChangeListener(
        new OnPageChangeListener() {
          public void onPageScrollStateChanged(int arg0) {}

          public void onPageScrolled(int arg0, float arg1, int arg2) {}

          public void onPageSelected(int position) {
            MenuItem back = me._menu.findItem(R.id.action_previous);
            MenuItem next = me._menu.findItem(R.id.action_next);
            MenuItem done = me._menu.findItem(R.id.action_done);

            int[] introImages = {
              R.drawable.greet_1,
              R.drawable.greet_2,
              R.drawable.greet_3,
              R.drawable.intent_1,
              R.drawable.intent_2,
              R.drawable.intent_3,
              R.drawable.intent_4,
              R.drawable.intent_5,
              R.drawable.intent_6,
              R.drawable.rumination_1,
              R.drawable.rumination_2,
              R.drawable.rumination_3,
              R.drawable.rumination_4,
              R.drawable.rumination_5,
              R.drawable.rumination_6,
              R.drawable.specific_4,
              R.drawable.specific_1,
              R.drawable.specific_2,
              R.drawable.specific_2,
              R.drawable.specific_4,
              R.drawable.specific_5,
              R.drawable.specific_7,
              R.drawable.specific_9,
              R.drawable.specific_11,
              R.drawable.conclusion_1,
              R.drawable.conclusion_2,
              R.drawable.conclusion_3
            };

            background.setImageResource(introImages[position]);

            back.setVisible(true);
            next.setVisible(true);
            done.setVisible(false);

            if (position == 0) back.setVisible(false);

            if (position == pager.getAdapter().getCount() - 1) {
              next.setVisible(false);
              done.setVisible(true);
            }

            // TODO: Pull out into strings file...
            me.getSupportActionBar()
                .setTitle("Page " + (position + 1) + " of " + pager.getAdapter().getCount());
          }
        });

    // TODO: Pull out into strings file...
    me.getSupportActionBar().setTitle("Page " + 1 + " of " + pager.getAdapter().getCount());
  }