Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Created September 21, 2012 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisRisner/3759507 to your computer and use it in GitHub Desktop.
Save ChrisRisner/3759507 to your computer and use it in GitHub Desktop.
GeoDemo-Android-2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/lblAddPoiHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add New Point of Interest"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/btnSelectImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select Image" />
<ImageView
android:id="@+id/imgSelectedImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/androidmarker" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<Button
android:id="@+id/btnGetSAS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get SAS" />
</LinearLayout>
<TextView
android:id="@+id/lblSASDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="SAS Details" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<Button
android:id="@+id/btnSavePOI"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save Point of Interest" />
</LinearLayout>
</LinearLayout>
</ScrollView>
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_point_of_interest);
mActivity = this;
// Get UI Controls
mBtnGetSAS = (Button) findViewById(R.id.btnGetSAS);
mBtnSavePOI = (Button) findViewById(R.id.btnSavePOI);
mBtnSelectImage = (Button) findViewById(R.id.btnSelectImage);
mImgSelectedImage = (ImageView) findViewById(R.id.imgSelectedImage);
mLblSASDetails = (TextView) findViewById(R.id.lblSASDetails);
mBtnGetSAS.setEnabled(false);
mBtnSavePOI.setEnabled(false);
Intent myIntent = getIntent();
mCurrentLocation = (Location) myIntent.getParcelableExtra("currentLocation");
// Image select handler
mBtnSelectImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
selectImage();
}
});
// Get SAS Handler
mBtnGetSAS.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Start progress dialog and start async task
mProgressDialog = new ProgressDialog(mActivity);
mProgressDialog.setMessage("Requesting SAS URL");
mProgressDialog.show();
new GetSASTask().execute();
}
});
// Save POI handler
mBtnSavePOI.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Start progress dialog and start async task
mProgressDialog = new ProgressDialog(mActivity);
mProgressDialog.setMessage("Uploading Point of Interest");
mProgressDialog.show();
new PostPointOfInterestTask().execute();
}
});
}
// Fire off intent to select image from gallary
protected void selectImage() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 1111);
}
// Result handler for any intents started with startActivityForResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
//handle result from gallary select
if (requestCode == 1111) {
Uri currImageURI = data.getData();
this.mImageUrl = currImageURI;
//Set the image view's image by using imageUri
mImgSelectedImage.setImageURI(currImageURI);
mBtnGetSAS.setEnabled(true);
mBtnSavePOI.setEnabled(false);
}
} catch (Exception ex) {
Log.e("Add point of interest activity", "Error in onActivityResult: " + ex.getMessage());
}
}
private Activity mActivity;
private Button mBtnGetSAS, mBtnSavePOI, mBtnSelectImage;
private TextView mLblSASDetails;
private ImageView mImgSelectedImage;
private ProgressDialog mProgressDialog;
private String _blobImagePostString = null;
private Uri mImageUrl;
private Location mCurrentLocation;
public class Constants {
public static final String kFindPOIUrl = "http://yoursubdomain.azurewebsites.net/api/Location/FindPointsOfInterestWithinRadius";
public static final String kBlobSASUrl = "http://yoursubdomain.azurewebsites.net/api/blobsas/get?container=%s&blobname=%s";
public static final String kAddPOIUrl = "http://yoursubdomain.azurewebsites.net/api/location/postpointofinterest/";
public static final String kContainerName = "test";
}
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location
// provider.
makeUseOfNewLocation(location);
mCurrentLocation = location;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1234) {
// Check to see if a POI was created
if (resultCode == 4321) {
Toast.makeText(getApplicationContext(), "New POI Created!",
Toast.LENGTH_SHORT).show();
loadPointsFromServer(mCurrentLocation);
} else {
Toast.makeText(getApplicationContext(), "Nothing was done",
Toast.LENGTH_SHORT).show();
}
} else
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case (R.id.menu_addpoi):
Intent addPOIIntent = new Intent(getApplicationContext(),
AddPointOfInterestActivity.class);
addPOIIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
addPOIIntent.putExtra("currentLocation", mCurrentLocation);
startActivityForResult(addPOIIntent, 1234);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_settings"
android:title="@string/menu_settings"
android:orderInCategory="100"/>
<item android:id="@+id/menu_addpoi"
android:title="Add Point"
android:orderInCategory="100"/>
</menu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment