Android Open Source - L5RHelper Manage Template View






From Project

Back to project page L5RHelper.

License

The source code is released under:

Copyright (c) 2010 Robert Uhl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Sof...

If you think the Android project L5RHelper 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

package com.uhl;
//from   w  w  w  .  jav a  2  s.  c om
import java.util.Hashtable;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import com.uhl.db.DBServiceLocator;
import com.uhl.db.IDBHelper;
import com.uhl.db.Profile;

public class ManageTemplateView extends ListActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    dbHelper = DBServiceLocator.getDBHelper(this);
    profile = dbHelper.loadProfile(getIntent().getExtras().getInt("ID"));
    
    initView();
    
    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
          String selection = (String)((TextView) view).getText();
          if(selection.equals(getString(R.string.new_template))){
            StartActivity(EditTemplateActivity.class, -1, profile.getId() );
          }else {
            int value = templates.get(selection);          
            StartActivity(EditTemplateActivity.class, value, profile.getId() );
          }
      }
    });
  }
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data){
    //for now just return to the list, call finish here if we want to return to character overview.
    initView();
  }
  
  private void initView() {
    buildTemplateTable(profile.getId());
      String[] names = new String[templates.keySet().size()];
      templates.keySet().toArray(names);
      String[] listData = new String[names.length+1];
      listData[0] = getString(R.string.new_template);
      System.arraycopy(names, 0, listData, 1, names.length);    
      
      setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, listData));    
  }

  private void StartActivity(Class<?> classInput, Integer Id, Integer profileId) {
    Intent intent = new Intent(this, classInput);
    intent.putExtra("ID", Id);
    intent.putExtra("PROFILE_ID", profileId);
    this.startActivityForResult(intent, 0);
    
  }  
  
  private void buildTemplateTable(int profileId) {
    templates = new Hashtable<String, Integer>();
    Cursor cursor = dbHelper.getTemplateNames(profileId);    
    if(cursor.getCount() < 1){
      cursor.close();
      return;
    }
    do{
      templates.put(cursor.getString(1), cursor.getInt(0));
    }while(cursor.moveToNext());
    cursor.close();
  }

  private IDBHelper dbHelper;
  private Hashtable<String, Integer> templates;
  private Profile profile;
  
}




Java Source Code List

com.uhl.CasterRollCalculateActivity.java
com.uhl.EditCharacterActivity.java
com.uhl.EditTemplateActivity.java
com.uhl.HomeActivity.java
com.uhl.L5RUtilites.java
com.uhl.LoadProfileView.java
com.uhl.ManageTemplateView.java
com.uhl.MeleeRollCalculateActivity.java
com.uhl.ProfileOverviewActivity.java
com.uhl.calc.Histogram.java
com.uhl.calc.Raises.java
com.uhl.calc.Roll.java
com.uhl.db.DBHelper.java
com.uhl.db.DBServiceLocator.java
com.uhl.db.DefaultViews.java
com.uhl.db.IDBHelper.java
com.uhl.db.Profile.java
com.uhl.db.Record.java
com.uhl.db.Template.java