Android Text Search
The Android guide for Search Overview is oriented towards searching external content rather than text. There is a mention of Using the Search Dialog. However all the bits you need are there. To get a search dialog in the toolbar that pops up when needed, you need a seach item in the menu. It should be the first item, unless there is a good reason otherwise.
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
<item
android:id="@+id/search"
android:showAsAction="ifRoom|collapseActionView"
android:title="@string/search"
android:actionViewClass="android.widget.SearchView"
android:icon="@drawable/ic_action_search" />
The search dialog will still pop up if the search item is in the menu rather than the toolbar. The dialog pops up and collapses all by itself in response to user interaction without any developer code. To implement the search, you need an OnQueryTextListener, which is called by the SearchView.
Read more →Using Emacs in Android Development
I’ve got a folder full of country flags which I have renamed using scripts so the names correspond to currency symbols. I want an integer array with references to the flags as android resources. This can be automated using emacs.
I get a list of the file names into a buffer using find, which I then open with emacs.
% find src/ -name flag* > data/sym-flags.lst

They are already sorted, but just to make sure I use M-x sort-lines.
Markdown OpenStreetMap Maps
There does not seem to be a convention for showing maps or
co-ordinates in Markdown, but almost anything gets put in square
brackets [<anything>].
I had a request from Marco the other day to put OpenStreetMap maps in my Diary app using
[<lat>,<lng>]
syntax. So I did a bit of a search to see if there was a convention in Markdown for co-ordinates and couldn’t find anything. So we seem to have broken new ground here.
Read more →Getting Related Content working
The latest release of Hugo includes Related Content, which I thought would be nice to add to my blog. However the docs, although they show you how to set it up, don’t explain how it works. To find that out, I had to look at the various threads on the Hugo forums.
There are four parts - you need to create a new partial template in
layouts/partials/related.html containing something like this:
{{ $related := .Site.RegularPages.Related . | first 5 }}
{{ with $related }}
<hr>
<h3>See Also</h3>
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ safeHTML .Title }}</a></li>
{{ end }}
</ul>
{{ end }}
You need to add a reference to your new partial template in your single page template in layouts/_default/single.html possibly near the end:
Adding a calendar event in android
The android docs for the Calendar Provider are quite useful, but
recommend the use of an AsyncQueryHandler for querying or adding
events to calendars in an asynchronous thread. However the
AsyncQueryHandler docs don’t include much guidance as to how to use
it.
To add an entry to an android calendar you first have to find out the calendar id using an asynchronous query on the calendars table.
// QueryHandler
public class QueryHandler extends AsyncQueryHandler
{
private static final String TAG = "QueryHandler";
// Projection arrays
private static final String[] CALENDAR_PROJECTION = new String[]
{
Calendars._ID
};
// The indices for the projection array above.
private static final int CALENDAR_ID_INDEX = 0;
private static final int CALENDAR = 0;
private static final int EVENT = 1;
private static final int REMINDER = 2;
private static QueryHandler queryHandler;
// QueryHandler
public QueryHandler(ContentResolver resolver)
{
super(resolver);
}
// insertEvent
public static void insertEvent(Context context, long startTime,
long endTime, String title)
{
ContentResolver resolver = context.getContentResolver();
if (queryHandler == null)
queryHandler = new QueryHandler(resolver);
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startTime);
values.put(Events.DTEND, endTime);
values.put(Events.TITLE, title);
if (BuildConfig.DEBUG)
Log.d(TAG, "Calendar query start");
queryHandler.startQuery(CALENDAR, values, Calendars.CONTENT_URI,
CALENDAR_PROJECTION, null, null, null);
}
This method is called from an app activity.
Read more →