Android Open Source - MapsMeasure Delete Adapter






From Project

Back to project page MapsMeasure.

License

The source code is released under:

Apache License

If you think the Android project MapsMeasure 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 2014 Thomas Hoffmann//from   w w  w .  j  a v a 2  s. c  o m
 * 
 * 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.j4velin.mapsmeasure;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

/**
 * Class for showing a list of saved traces and the ability to delete them
 * 
 */
class DeleteAdapter extends BaseAdapter {

  private final ArrayList<File> files;
  private final LayoutInflater mInflater;
  private final OnClickListener deleteListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
            int file = (Integer) v.getTag();
            files.remove(file).delete();
      notifyDataSetChanged();
    }
  };

  /**
   * @param f
   *            the files to show
   * @param c
   *            the calling activity
   */
  public DeleteAdapter(final File[] f, final Map c) {
    files = new ArrayList<File>(Arrays.asList(f));
    mInflater = c.getLayoutInflater();
  }

  /**
   * Gets a file from the list. Used to load the file when clicking on it.
   * 
   * @param position
   *            of the file in the list
   * @return the corresponding file
   */
  File getFile(int position) {
    return files.get(position);
  }

  @Override
  public int getCount() {
    return files.size();
  }

  @Override
  public Object getItem(int position) {
    return files.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @SuppressWarnings("deprecation")
  @Override
  public View getView(int position, View convertView, final ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.deletelistitem, null);
      holder = new ViewHolder();
      holder.iv = convertView.findViewById(R.id.icon);
      holder.tv = (TextView) convertView.findViewById(R.id.text);
      holder.iv.setOnClickListener(deleteListener);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }
    String filename = files.get(position).getName();
    if (filename.startsWith("MapsMeasure_")) {
      try {
        Date date = new Date(Long.parseLong(filename.substring(filename.lastIndexOf("_") + 1, filename.lastIndexOf("."))));
        filename = date.toLocaleString();
      } catch (NumberFormatException nfe) {
      }
    } else {
      filename = filename.substring(0, filename.lastIndexOf("."));
    }
    holder.tv.setText(filename);
    holder.iv.setTag(position);
    return convertView;
  }

  private static class ViewHolder {
    private TextView tv; // the TextView showing the name of the file
    private View iv; // the ImageView showing the delete icon
  }

}




Java Source Code List

com.google.maps.android.MathUtil.java
com.google.maps.android.SphericalUtil.java
de.j4velin.mapsmeasure.DeleteAdapter.java
de.j4velin.mapsmeasure.Dialogs.java
de.j4velin.mapsmeasure.DrawerListAdapter.java
de.j4velin.mapsmeasure.GeocoderTask.java
de.j4velin.mapsmeasure.Map.java
de.j4velin.mapsmeasure.Util.java
de.j4velin.mapsmeasure.wrapper.API17Wrapper.java
de.j4velin.mapsmeasure.wrapper.API8Wrapper.java