MaterialActivity.java :  » App » dragoid » de » wathoserver » android » dragoid » activity » tabs » Android Open Source

Android Open Source » App » dragoid 
dragoid » de » wathoserver » android » dragoid » activity » tabs » MaterialActivity.java
/*******************************************************************************
 * Copyright 2011 WaTho
 * 
 * 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 de.wathoserver.android.dragoid.activity.tabs;

import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import de.wathoserver.android.dragoid.R;
import de.wathoserver.android.dragoid.activity.singlebuilding.SingleBuildingActivity;
import de.wathoserver.android.dragoid.api.Building;
import de.wathoserver.android.dragoid.api.DragoApi;
import de.wathoserver.android.dragoid.util.DialogHelper;
import de.wathoserver.android.dragoid.util.UrlParsingActivity;
import de.wathoserver.android.dragoid.util.UrlParsingTask;

/**
 * Zeigt eine Liste mit den verfgbaren Materialien aller Gebude an. (Reiter M)
 * 
 * @author watho
 * 
 */
public class MaterialActivity extends ListActivity implements
    UrlParsingActivity<List<Map<String, String>>> {

  private String[] col_names;
  private int[] view_ids;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    col_names = new String[] { Building.COL_NAME, Building.COL_SUPPLIESTO };
    view_ids = new int[] { R.id.building_name, R.id.building_suppliesto };
    reload();
  }

  @Override
  protected void onResume() {
    super.onResume();
  }

  @Override
  public void reload() {
    new UrlParsingTask<List<Map<String, String>>>(this, this).execute();
  }

  @Override
  protected Dialog onCreateDialog(int id) {
    return DialogHelper.createDialogById(this, DIALOG_PROGRESS);
  }

  @Override
  public List<Map<String, String>> fetchData() throws IllegalAccessException {
    return DragoApi.getApi().getSuppliesTo();
  }

  @Override
  public void onSuccess(List<Map<String, String>> result) {
    setListAdapter(new SimpleAdapter(this, result, R.layout.materialview,
        col_names, view_ids));
    ListView lv = getListView();
    lv.setOnItemClickListener(new OnItemClickListener() {

      @Override
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
        @SuppressWarnings("unchecked")
        Map<String, String> building = (Map<String, String>) parent
            .getItemAtPosition(position);
        startActivity(SingleBuildingActivity.createIntent(
            MaterialActivity.this,
            Integer.parseInt(building.get(Building.COL_POSITION)),
            SingleBuildingActivity.TAB_MATERIAL));
      }
    });
  }

  @Override
  public Activity getUserInfoActivity() {
    return this.getParent();
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.