Bill Farmer

Random thoughts on random subjects

Handling Resizing in Windows

by Bill Farmer. Categories: Hacking .

I have a windows app where I want the app window to maintain it’s aspect ratio when it is resized. Windows provides two mechanisms for this, the WM_SIZE message and the WM_SIZING message. The WM_SIZE message is sent when a window has been resized to allow child windows to be resized, the WM_SIZING message is sent while the user is resizing it to allow the size to be adjusted. The messages are handled in the WindowProc callback function.

Read more →

Swift

by Bill Farmer. Categories: Hacking .

Some years ago I wrote an OSX app in C using Carbon because my Hackintosh would only run OSX 10.4 (Tiger). The most difficult part was dealing with the Core Audio API.

I recently decided to port it to Swift to avoid having to attempt to learn Objective C. A derivation of C that sends selectors to targets using the syntax [target selector arguments...] I don’t want to know about.

Core Audio

Having translated the Core Audio part of the app to Swift, I discovered that part of it refused to work. The same code originally written in C works fine.

Read more →

Android Custom Attributes

by Bill Farmer. Categories: Hacking .

I had resisted adding a dark theme to my Diary app until now because it uses a custom calendar with built in customisable styles and preferences with icons. So I had to work out how to make the custom styles of the calendar revert to styles from the current theme, and how to switch icons for the preferences according to the theme.

Calendar custom styles

The custom calendar has a list of styles that are customisable in a attrs.xml file.

Read more →

Android Recent Files

by Bill Farmer. Categories: Hacking .

There are several parts to this - creating the list of files, saving the list in the preferences, restoring the list on startup and creating the list in the menu.


    // onCreate
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        SharedPreferences preferences =
            PreferenceManager.getDefaultSharedPreferences(this);

        // Create a map of scroll positions by file name
        Set<String> pathSet = preferences.getStringSet(PREF_PATHS, null);
        pathMap = new HashMap<String, Integer>();

        if (pathSet != null)
            for (String path : pathSet)
                pathMap.put(path, preferences.getInt(path, 0));

        removeList = new ArrayList<String>();

        // ...
    }

The android preference system only allows a list of strings to be stored as a set, so the last modified date of each file is used below to order the list. The code also saves the scroll position of each file using the file name as a key. The remove list is used to remove old entries.

Read more →

Android Text Search

by Bill Farmer. Categories: Hacking .

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 →
Previous page Next page