开发者

Convenient place to put a change log

I am an old school C programmer and I have the habbit of putting my change log in comments at the top of my main 开发者_开发百科source file.

I would like to put my change log in a more convenient place so that I could pull it up at run time and display it to the user on request.

Any suggestions ?


Most projects keep the change log in a file called Changelog in the project root.

Often this file is created manually: Developers are often ... "creative" when committing things and/or comments like "Reduced global variables", "Organized imports", etc. don't make much sense to the user.

In your case, I suggest to put the file next to the class which displays it or in the root of your (re-)source folder. That way, you can easily load it using About.class.getResourceAsStream("Changelog") (relative to About) or getClass().getClassLoader().getResourceAsStream("Changelog") (relative to source root folder)


My suggestion would be to put it in an html file on the filesystem under assets. Then in the Activity in which you want to display the change log, just use the following web view code:

    WebView changeLogWebView = (WebView) findViewById(R.id.ChangeLogWebView);
    InputStream fin = null;
    try {
        fin = getAssets().open("changelog.html");
        byte[] buffer = new byte[fin.available()];
        fin.read(buffer);
        String contents = new String(buffer, "UTF-8");
        changeLogWebView.loadData(contents, "text/html", "UTF-8");
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (fin != null) {
            try {
                fin.close();
            } catch (IOException e) {
            }
        }
    }


Check this out: http://code.google.com/p/android-change-log/


You can simply add a folder "raw" in the resource folder and store your own files there - also text files. A file "res/raw/changelog.txt" gets an identifier R.raw.changelog in your Java code, you then can open and read the file using getResources().openRawResource(). :-)

http://developer.android.com/reference/android/content/res/Resources.html#openRawResource%28int%29


Depending on how your application is structured, you could put an "About" menu tab or something similar and have a changelog button that brings up your change log when it is clicked. Then you could just read the local changelog and copy over it whenever you make changes to keep it updated. Maybe something like that?


Here is a piece of code that combines mreichelt's and Micah's answers. Thanks

Text in a raw resource dispayed in a WebView.

    WebView computerWebView = (WebView) findViewById(R.id.changelog_webview);
    InputStream istream = null;
    String strLine;
    StringBuilder strbText = new StringBuilder();
    try
        {
        istream = getResources().openRawResource(R.raw.changelog_html);
        InputStreamReader isreader = new InputStreamReader(istream);
        BufferedReader myReader = new BufferedReader(isreader);
        while ((strLine = myReader.readLine()) != null)
            {
            strbText.append(strLine);
            }
        computerWebView.loadData(strbText.toString(), "text/html", "UTF-8");
        }
    catch (Exception e)
        {
        computerWebView
                .loadData("No data to display", "text/html", "UTF-8");
        }
    finally
        {
        if (istream != null)
            try
                {
                istream.close();
                }
            catch (IOException e)
                {
                }
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜