Android Open Source - intelligent-lock-pattern Start Experiment Activity






From Project

Back to project page intelligent-lock-pattern.

License

The source code is released under:

GNU General Public License

If you think the Android project intelligent-lock-pattern 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 2012 Lucas Andr? de Alencar"
 * /*from  w  w w  .ja v  a  2s  .c om*/
 * This file is part of "Intelligent Lock Pattern".
 * 
 * "Intelligent Lock Pattern" 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.
 * 
 * "Intelligent Lock Pattern" 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 "Intelligent Lock Pattern".  If not, see <http://www.gnu.org/licenses/>.
 */

package org.unioeste.ilp;

import java.util.List;

import org.unioeste.ilp.adapters.ExperiencesUserAdapter;
import org.unioeste.ilp.models.Experience;
import org.unioeste.ilp.models.User;
import org.unioeste.ilp.models.UserDao.Properties;

import android.content.Intent;
import android.database.sqlite.SQLiteConstraintException;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Activity responsible for:
 *   - Insert new users
 *   - Permits selection of experiments already started but not ended
 *   - Users that don't have already started a experiment, can start a new one.
 * 
 * @author Lucas Andr? de Alencar
 *
 */
public class StartExperimentActivity extends BaseActivity {
  
  ExperiencesUserAdapter adapter;
  ListView list;
  TextView user_name;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.select_user);
    
    user_name = (EditText) findViewById(R.id.user_name);
    list = (ListView) findViewById(R.id.users_list_view);
  }
  
  @Override
  protected void onResume() {
    super.onResume();
    user_name.setText(""); // Cleans the user name field
    updateUsersList();
    
    // Set the action when User is selected on list
    list.setOnItemClickListener(new OnItemClickListener() {

      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        selectedListItemAction(position);
      }

    });
  }
  
  private void updateUsersList () {
    List<User> users = ilp.userDao.queryBuilder().orderDesc(Properties.Id).list();
    adapter = new ExperiencesUserAdapter(this, users, CollectSamplesActivity.defaultNumberOfTries);
    list.setAdapter(adapter);
  }
  
  public void selectedListItemAction (int position) {
    User user = (User) list.getAdapter().getItem(position);
    List<Experience> experiences = user.getExperiences();
    
    if (experiences.size() > 0)
      gotoCollectSamplesActivity(user, experiences.get(experiences.size() - 1));
    else
      gotoShowPatternsActivity(user);
  }
  
  public void continueButtonAction (View view) {    
    if (!user_name.getText().toString().equals("")) {
      User user = new User(null, user_name.getText().toString());
      addUser(user);
      gotoShowPatternsActivity(user);
    } else {
      Toast.makeText(this, R.string.insert_user_name_error, Toast.LENGTH_SHORT).show();
    }
  }
  
  public void newExperimentButtonAction (View view) {
    int position = list.getPositionForView((View) (view.getParent()));
    User user = (User) list.getAdapter().getItem(position);
    gotoShowPatternsActivity(user);
  }
  
  private void addUser (User user) {
    try {
      ilp.insertUser(user);
      updateUsersList();
    } catch (SQLiteConstraintException e) {
      Toast.makeText(this, R.string.user_exist, Toast.LENGTH_SHORT).show();
    }
  }
  
  private void gotoCollectSamplesActivity (User user, Experience experience) {
    Intent i = new Intent(this, CollectSamplesActivity.class);
    
    if (experience != null)
      i.putExtra(CollectSamplesActivity.experience_id, experience.getId());
    
    if (user != null)
      i.putExtra(CollectSamplesActivity.user_id, user.getId());
    
    startActivity(i);
  }
  
  private void gotoShowPatternsActivity (User user) {
    Intent i = new Intent(this, ShowPatternsActivity.class);
    
    if (user != null)
      i.putExtra(ShowPatternsActivity.user_id, user.getId());
    
    startActivity(i);
  }
}




Java Source Code List

group.pals.android.lib.ui.lockpattern.LockPatternActivity.java
group.pals.android.lib.ui.lockpattern.collect.Lists.java
group.pals.android.lib.ui.lockpattern.widget.LockPatternUtils.java
group.pals.android.lib.ui.lockpattern.widget.LockPatternView.java
org.unioeste.ilp.BaseActivity.java
org.unioeste.ilp.CollectSamplesActivity.java
org.unioeste.ilp.DatabaseExporterActivity.java
org.unioeste.ilp.ILPApp.java
org.unioeste.ilp.InsertPatternActivity.java
org.unioeste.ilp.LockPatternActivity.java
org.unioeste.ilp.MainMenuActivity.java
org.unioeste.ilp.PrefsActivity.java
org.unioeste.ilp.ShowPatternsActivity.java
org.unioeste.ilp.StartExperimentActivity.java
org.unioeste.ilp.TestAuthActivity.java
org.unioeste.ilp.adapters.ExperiencesUserAdapter.java
org.unioeste.ilp.adapters.LockPatternGalleryAdapter.java
org.unioeste.ilp.db.DBHelper.java
org.unioeste.ilp.models.AttemptDao.java
org.unioeste.ilp.models.Attempt.java
org.unioeste.ilp.models.DaoMaster.java
org.unioeste.ilp.models.DaoSession.java
org.unioeste.ilp.models.ExperienceDao.java
org.unioeste.ilp.models.Experience.java
org.unioeste.ilp.models.PatternDao.java
org.unioeste.ilp.models.Pattern.java
org.unioeste.ilp.models.SampleDao.java
org.unioeste.ilp.models.Sample.java
org.unioeste.ilp.models.UserDao.java
org.unioeste.ilp.models.User.java
org.unioeste.ilp.services.SamplesCollectorService.java