package com.howard.rockear.Utils;

import java.util.Formatter;
import java.util.Locale;

import android.content.Context;

import com.howard.rockear.R;

public class StringUtils {
	/**
	 * @param context
	 * @param secs
	 * @return time String
	 */
	public static String makeTimeString(Context context, long secs) {

		StringBuilder sFormatBuilder = new StringBuilder();

		Formatter sFormatter = new Formatter(sFormatBuilder,
				Locale.getDefault());

		String durationformat = context
				.getString(secs < 3600 ? R.string.durationformatshort
						: R.string.durationformatlong);

		final Object[] sTimeArgs = new Object[5];

		/*
		 * Provide multiple arguments so the format can be changed easily by
		 * modifying the xml.
		 */
		sFormatBuilder.setLength(0);

		final Object[] timeArgs = sTimeArgs;
		timeArgs[0] = secs / 3600;
		timeArgs[1] = secs / 60;
		timeArgs[2] = secs / 60 % 60;
		timeArgs[3] = secs;
		timeArgs[4] = secs % 60;

		String resultString = sFormatter.format(durationformat, timeArgs)
				.toString();
		sFormatter.close();
		return resultString;
	}

}
