Android Open Source - napping-player Start Activity






From Project

Back to project page napping-player.

License

The source code is released under:

GNU General Public License

If you think the Android project napping-player listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

// Copyright (C) 2013 Werner Robitza
///* www  .  j  a v  a  2  s .co  m*/
// This file is part of NappingPlayer.
//
// NappingPlayer is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. 
//
// NappingPlayer is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with NappingPlayer.  If not, see <http://www.gnu.org/licenses/>.
//
// NappingPlayer was written at the University of Vienna by Werner Robitza.

package at.ac.univie.nappingplayer;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import at.ac.univie.nappingplayer.util.Configuration;

public class StartActivity extends Activity {
  private static final String TAG = StartActivity.class.getSimpleName();
  
  EditText mEditName;
  
  private static final int NAPPING_START_REQUEST = 0;

  /**
   * Called when the activity is first started
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start);
    View v = findViewById(R.id.layout_start);
    v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
    
    mEditName = (EditText) findViewById(R.id.et_person_name);
    try {
      // initialize SD card
      Configuration.initialize(this);
      VideoPlaylist.initialize(Configuration.getVideos());
    } catch (Exception e) {
      Log.e(TAG, "Error while initializing SD card. Aborting");
      e.printStackTrace();
      finish();
    }
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
  }

  /**
   * Return callback for when another activity finishes (e.g. napping)
   */
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "Returned from activity; request code " + requestCode);
    if (requestCode == NAPPING_START_REQUEST) {
      if (resultCode == RESULT_OK) {
        // if we return from napping and everything went as expected
        if (VideoPlaylist.getState() == VideoPlaylist.STATE_FINISHED) {
          resetExperiment();
          Toast.makeText(this, getText(R.string.finished_napping),
              Toast.LENGTH_LONG).show();
        }
      } else if (resultCode == RESULT_CANCELED) {
        // the user canceled the activity
        resetExperiment();
        Toast.makeText(this, getText(R.string.canceled_napping),
            Toast.LENGTH_LONG).show();
      }
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_start, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.menu_data:
      startDataExplorer();
      return true;
    case R.id.menu_settings:
      startPreferences();
      return true;
    case R.id.menu_credits:
      startCredits();
      return true;
    default:
      return super.onOptionsItemSelected(item);
    }
  }

  /**
   * Resets experiment data (i.e. clears name and playlist state) for next
   * observer
   */
  private void resetExperiment() {
    VideoPlaylist.reset();
    mEditName.setText("");
  }
  
  /**
   * Sets off the napping experiment
   */
  public void startNapping(View view) {
    Intent startNapping = new Intent(this, NappingActivity.class);
    startNapping.putExtra("userName", mEditName.getText().toString());
    if (mEditName.getText().toString().equals("")) {
      Toast.makeText(this, getText(R.string.enter_name_prompt), Toast.LENGTH_SHORT).show();
      mEditName.requestFocus();
      return;
    }
    startActivityForResult(startNapping, NAPPING_START_REQUEST);
  }

  public void startPreferences() {
    Intent prefIntent = new Intent(this, PreferencesActivity.class);
    startActivity(prefIntent);
  }
  
  public void startDataExplorer() {
    Intent dataIntent = new Intent(this, DataExplorerActivity.class);
    startActivity(dataIntent);
  }
  
  public void startCredits() {
    Intent creditsIntent = new Intent(this, CreditsActivity.class);
    startActivity(creditsIntent);
  }
  
  
}




Java Source Code List

at.ac.univie.nappingplayer.CreditsActivity.java
at.ac.univie.nappingplayer.DataExplorerActivity.java
at.ac.univie.nappingplayer.NappingActivity.java
at.ac.univie.nappingplayer.PreferencesActivity.java
at.ac.univie.nappingplayer.StartActivity.java
at.ac.univie.nappingplayer.StartVideoListener.java
at.ac.univie.nappingplayer.VideoPlaylist.java
at.ac.univie.nappingplayer.ViewActivity.java
at.ac.univie.nappingplayer.grouping.SelectVideoListener.java
at.ac.univie.nappingplayer.grouping.VideoGroupAdapter.java
at.ac.univie.nappingplayer.grouping.VideoGroup.java
at.ac.univie.nappingplayer.util.Configuration.java
at.ac.univie.nappingplayer.util.IOUtil.java
at.ac.univie.nappingplayer.views.DataExplorerAdapter.java
at.ac.univie.nappingplayer.views.DataExplorerChild.java
at.ac.univie.nappingplayer.views.DataExplorerGroup.java
at.ac.univie.nappingplayer.views.VideoButtonView.java