Android Open Source - WhatsUp Ref Point Activity






From Project

Back to project page WhatsUp.

License

The source code is released under:

GNU General Public License

If you think the Android project WhatsUp 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 nu.placebo.whatsup.activity;
/*from  ww  w . ja v a2s  .  c  o  m*/
import java.util.ArrayList;
import java.util.List;

import nu.placebo.whatsup.R;
import nu.placebo.whatsup.constants.Constants;
import nu.placebo.whatsup.datahandling.DataProvider;
import nu.placebo.whatsup.model.ReferencePoint;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class RefPointActivity extends ListActivity implements OnClickListener {

  private List<ReferencePoint> refs;
  private MarkerAdapter adapter;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.ref_point_activity);
    Log.d("whatsup", "Starting refPointActivity");

    refs = DataProvider.getDataProvider(this).getAllReferencePoints();

    this.adapter = new MarkerAdapter(this, R.layout.ref_item,
        new ArrayList<ReferencePoint>());
    this.setListAdapter(adapter);

    ImageButton addBtn = (ImageButton) this
        .findViewById(R.id.add_reference);
    addBtn.setOnClickListener(this);

  }

  /*
   * (non-Javadoc)
   * 
   * @see android.app.Activity#onResume()
   */
  @Override
  protected void onResume() {

    refresh();
    super.onResume();
  }

  private void refresh() {
    refs.clear();
    refs = DataProvider.getDataProvider(this).getAllReferencePoints();
    this.adapter.fetchCurrentRefId();
    adapter.markers.clear();
    adapter.notifyDataSetChanged();
    for (int i = 0; i < refs.size(); i++) {
      adapter.add(refs.get(i));

    }
    adapter.notifyDataSetChanged();
  }

  public void onClick(View v) {
    if (v.getId() == R.id.add_reference) {
      Intent intent = new Intent(this, PositionPickerActivity.class);
      intent.putExtra("requestCode", Constants.REFERENCE_POINT);
      String[] existingNames = new String[refs.size()];
      
      for(int i = 0; i < refs.size(); i++) {
        existingNames[i] = refs.get(i).getName();
      }
      
      intent.putExtra("existing_names", existingNames);
      this.startActivity(intent);
    }
  }

  private class MarkerAdapter extends ArrayAdapter<ReferencePoint> implements
      OnClickListener {
    private Activity ctx;
    private ArrayList<ReferencePoint> markers;
    private int currentRefId;

    public MarkerAdapter(Activity context, int textViewResourceId,
        ArrayList<ReferencePoint> objects) {
      super(context, textViewResourceId, objects);
      this.markers = objects;
      this.ctx = context;
      fetchCurrentRefId();
    }

    public void fetchCurrentRefId() {
      ReferencePoint currentRef = DataProvider.getDataProvider(ctx)
          .getCurrentReferencePoint();

      if (currentRef != null) {
        currentRefId = currentRef.getId();
      } else {
        currentRefId = -2;
      }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

      View v = convertView;
      if (v == null) {
        LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.ref_item, null);
      }

      ReferencePoint gl = markers.get(position);
      if (gl != null) {
        TextView t_title = (TextView) v
            .findViewById(R.id.ref_item_title);

        if (t_title != null) {
          t_title.setText(gl.getName());
        }
        ImageView iv = (ImageView) v.findViewById(R.id.current_image);
        if (gl.getId() == currentRefId) {
          iv.setVisibility(View.VISIBLE);
        } else {
          iv.setVisibility(View.INVISIBLE);
        }
        v.setId(R.id.ref_id);
        v.setTag(R.id.ref_id, gl.getId());
        ImageButton delBtn = (ImageButton) v
            .findViewById(R.id.ref_item_delete);
        if(gl.getName().equals("physical_position")) {
          delBtn.setVisibility(View.INVISIBLE);
        } else {
          delBtn.setVisibility(View.VISIBLE);
          delBtn.setTag(R.id.ref_id, gl.getId());
          delBtn.setOnClickListener(this);
        }
        v.setOnClickListener(this);

      }
      return v;
    }

    public void onClick(View v) {
      if (v.getId() == R.id.ref_item_delete) {
        DataProvider.getDataProvider(ctx).removeReferencePoint(
            (Integer) v.getTag(R.id.ref_id));
        ((RefPointActivity) ctx).refresh();
      } else if (v.getId() == R.id.ref_id) {
        DataProvider.getDataProvider(ctx).setCurrentReferencePoint(
            (Integer) v.getTag(R.id.ref_id));
        ctx.finish();
      }
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuHelper.inflate(menu, this.getMenuInflater());
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    return MenuHelper.onOptionsItemSelected(item, this);
  }

  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    return MenuHelper.onPrepareOptionsMenu(menu, this);
  }
}




Java Source Code List

nu.placebo.whatsup.activity.AnnotationActivity.java
nu.placebo.whatsup.activity.CreateAnnotationActivity.java
nu.placebo.whatsup.activity.CreateCommentActivity.java
nu.placebo.whatsup.activity.ListViewActivity.java
nu.placebo.whatsup.activity.LogInActivity.java
nu.placebo.whatsup.activity.LoginRegTabActivity.java
nu.placebo.whatsup.activity.MapViewActivity.java
nu.placebo.whatsup.activity.Marker.java
nu.placebo.whatsup.activity.MenuHelper.java
nu.placebo.whatsup.activity.PositionPickerActivity.java
nu.placebo.whatsup.activity.RefPointActivity.java
nu.placebo.whatsup.activity.RegisterActivity.java
nu.placebo.whatsup.android.os.AsyncTask.java
nu.placebo.whatsup.balloon.BalloonItemizedOverlay.java
nu.placebo.whatsup.balloon.BalloonOverlayView.java
nu.placebo.whatsup.constants.Constants.java
nu.placebo.whatsup.ctrl.SessionHandler.java
nu.placebo.whatsup.datahandling.DataProvider.java
nu.placebo.whatsup.datahandling.DataReturnListener.java
nu.placebo.whatsup.datahandling.DataReturn.java
nu.placebo.whatsup.datahandling.DatabaseConnectionLayer.java
nu.placebo.whatsup.datahandling.DatabaseHelper.java
nu.placebo.whatsup.model.Annotation.java
nu.placebo.whatsup.model.Comment.java
nu.placebo.whatsup.model.ExtendedOverlayItem.java
nu.placebo.whatsup.model.GeoLocation.java
nu.placebo.whatsup.model.ListMarker.java
nu.placebo.whatsup.model.ReferencePoint.java
nu.placebo.whatsup.model.SessionInfo.java
nu.placebo.whatsup.network.AbstractNetworkOperation.java
nu.placebo.whatsup.network.Action.java
nu.placebo.whatsup.network.AnnotationCreate.java
nu.placebo.whatsup.network.AnnotationRetrieve.java
nu.placebo.whatsup.network.CommentCreate.java
nu.placebo.whatsup.network.GeoLocationsRetrieve.java
nu.placebo.whatsup.network.Login.java
nu.placebo.whatsup.network.NetworkCalls.java
nu.placebo.whatsup.network.NetworkOperationListener.java
nu.placebo.whatsup.network.NetworkOperation.java
nu.placebo.whatsup.network.NetworkTask.java
nu.placebo.whatsup.network.OperationResult.java
nu.placebo.whatsup.network.RegisterOperation.java
nu.placebo.whatsup.network.SessionTest.java
nu.placebo.whatsup.util.GeoPointUtil.java
nu.placebo.whatsup.util.Geodetics.java
nu.placebo.whatsup.util.ValidationUtil.java
nu.placebo.whatsuptest.TestStarter.java
nu.placebo.whatsuptest.activitytest.AnnotationActivityTest.java
nu.placebo.whatsuptest.activitytest.ListViewActivityTest.java
nu.placebo.whatsuptest.activitytest.MapViewActivityTest.java
nu.placebo.whatsuptest.networktest.NetworkTest.java
nu.placebo.whatsuptest.utiltest.GeoPointUtilTest.java
nu.placebo.whatsuptest.utiltest.GeodeticsTest.java
nu.placebo.whatsuptest.utiltest.ValidationTest.java