Skip to content

Commit

Permalink
Add "copy to clipboard" button
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey committed Oct 31, 2010
1 parent be4818c commit d2dbe06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions res/layout/main.xml
Expand Up @@ -13,6 +13,11 @@
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Copy postcode"
android:id="@+id/btnCopyPostcode" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Update postcode"
android:id="@+id/btnUpdate" />
</LinearLayout>
24 changes: 22 additions & 2 deletions src/net/tevp/postcode/Postcode.java
Expand Up @@ -7,8 +7,10 @@
import android.location.Location;
import android.widget.Button;
import android.view.View;
import java.text.SimpleDateFormat;
import android.widget.Toast;
import android.text.ClipboardManager;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Postcode extends Activity implements PostcodeListener {
Expand Down Expand Up @@ -41,7 +43,25 @@ public void onClick(View v) {
self.newPostcode(true);
}
});
}
((Button) findViewById(R.id.btnCopyPostcode)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (self.lastPostcode == null)
self.toastText("Don't yet have a postcode!");
else
{
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(self.lastPostcode);
self.toastText("Copied postcode to clipboard");
}
}
});
}

private void toastText(String text)
{
Context context = getApplicationContext();
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}

private void newPostcode(boolean mustBeNew)
{
Expand Down

0 comments on commit d2dbe06

Please sign in to comment.