Back to project page WhatsUp.
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.
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); } }