-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #29
- Loading branch information
Showing
5 changed files
with
250 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...t/app/src/main/java/pt/ulisboa/tecnico/ist/cmu/locmess/adapters/LocationsListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package pt.ulisboa.tecnico.ist.cmu.locmess.adapters; | ||
|
||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.location.Location; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
import android.widget.TextView; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import pt.ulisboa.tecnico.ist.cmu.locmess.R; | ||
import pt.ulisboa.tecnico.ist.cmu.locmess.dto.LocationDto; | ||
|
||
/** | ||
* Created by jorge on 05/05/17. | ||
*/ | ||
|
||
public class LocationsListAdapter extends BaseAdapter { | ||
|
||
private List<LocationDto> _locations; | ||
private Activity _activity; | ||
|
||
public LocationsListAdapter(List<LocationDto> locations,Activity parentActivity){ | ||
_locations=locations; | ||
_activity=parentActivity; | ||
} | ||
|
||
@Deprecated | ||
public LocationsListAdapter(Activity parentActivity){ | ||
_locations=new ArrayList<>(); | ||
_activity=parentActivity; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return _locations.size(); | ||
} | ||
|
||
@Override | ||
public LocationDto getItem(int i) { | ||
return _locations.get(i); | ||
} | ||
|
||
@Override | ||
public long getItemId(int i) { | ||
return i; | ||
} | ||
|
||
@Override | ||
public View getView(final int index, View reusableView, ViewGroup viewGroup) { | ||
final ViewHolder holder; | ||
if (reusableView == null) { | ||
// create a new view | ||
holder = new ViewHolder(); | ||
LayoutInflater inflater = _activity.getLayoutInflater(); | ||
reusableView = inflater.inflate(android.R.layout.simple_list_item_1, null); | ||
holder.text = (TextView) reusableView.findViewById(android.R.id.text1); | ||
reusableView.setTag(holder); | ||
} else { | ||
// an old view can be reused! | ||
holder = (ViewHolder) reusableView.getTag(); | ||
} | ||
holder.index = index; | ||
|
||
holder.text.setText(_locations.get(index).getName()); | ||
reusableView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
final ViewHolder holder = (ViewHolder) view.getTag(); | ||
showEditTopicDialog(holder.index, getItem(holder.index).getName()); | ||
} | ||
}); | ||
return reusableView; | ||
} | ||
|
||
private class ViewHolder { | ||
TextView text; | ||
int index; | ||
} | ||
|
||
public void showEditTopicDialog(final int index, final String title) { | ||
final AlertDialog.Builder builder = new AlertDialog.Builder(_activity); | ||
builder.setTitle(title); | ||
|
||
final LayoutInflater inflater = _activity.getLayoutInflater(); | ||
final View view1 = inflater.inflate(R.layout.dialog_location_info, null); | ||
final TextView dialogText = (TextView) view1.findViewById(R.id.textView); | ||
dialogText.setText("Latitude: "+_locations.get(index).getLat()+"\nLongitude: "+_locations.get(index).getLongitude() | ||
+"\nRadius: "+_locations.get(index).getRadius()+"\nSSids: "+ | ||
_locations.get(index).getWifiIdsAsString()); | ||
|
||
builder.setView(view1); | ||
builder.show(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
android-project/app/src/main/java/pt/ulisboa/tecnico/ist/cmu/locmess/dto/LocationDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package pt.ulisboa.tecnico.ist.cmu.locmess.dto; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by jorge on 05/05/17. | ||
*/ | ||
|
||
public class LocationDto implements LocMessDto { | ||
|
||
private String _name; | ||
private String _lat="",_longitude="",_radius=""; | ||
private List<String> _wifiIds=null; | ||
|
||
@Deprecated | ||
private String wifiids; | ||
|
||
public LocationDto(String name, String lat, String longitude, String radius){ | ||
_name=name; | ||
_lat=lat; | ||
_longitude=longitude; | ||
_radius=radius; | ||
} | ||
|
||
public LocationDto(String name, List<String> wifiIds){ | ||
_name=name; | ||
_wifiIds=wifiIds; | ||
} | ||
|
||
@Deprecated | ||
public LocationDto(String name, String wifi){ | ||
_name=name; | ||
_wifiIds=new ArrayList<>(); | ||
wifiids=wifi; | ||
} | ||
|
||
|
||
public String getName() { | ||
return _name; | ||
} | ||
|
||
public String getLat() { | ||
return _lat; | ||
} | ||
|
||
public String getLongitude() { | ||
return _longitude; | ||
} | ||
|
||
public String getRadius() { | ||
return _radius; | ||
} | ||
|
||
public List<String> getWifiIds() { | ||
return _wifiIds; | ||
} | ||
|
||
public String getWifiIdsAsString(){ | ||
if(_wifiIds!=null){ | ||
String ids=""; | ||
for(String s: _wifiIds){ | ||
ids+=s; | ||
} | ||
return ids; | ||
} | ||
return "None"; | ||
} | ||
|
||
@Deprecated | ||
public String getWifiids() { | ||
return wifiids; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters