If you think the Android project hpush listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.hpush.utils;
/*fromwww.java2s.com*/import java.util.Map;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
importstatic android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
importstatic android.text.format.DateUtils.FORMAT_SHOW_DATE;
importstatic android.text.format.DateUtils.FORMAT_SHOW_TIME;
importstatic android.text.format.DateUtils.FORMAT_SHOW_YEAR;
importstatic android.text.format.DateUtils.formatDateTime;
/**
* Util-methods.
*
* @author Xinyue Zhao
*/publicfinalclass Utils {
/**
* There is different between android pre 3.0 and 3.x, 4.x on this wording.
*/publicstaticfinal String ALPHA =
(android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) ? "alpha" : "Alpha";
/**
* Convert a timestamps to a readable date in string.
*
* @param cxt
* {@link android.content.Context}.
* @param timestamps
* A long value for a timestamps.
*
* @return A date string format.
*/publicstatic String convertTimestamps2DateString(Context cxt, long timestamps) {
return formatDateTime(cxt, timestamps, FORMAT_SHOW_YEAR | FORMAT_SHOW_DATE |
FORMAT_SHOW_TIME | FORMAT_ABBREV_MONTH);
}
/**
* Standard sharing app for sharing on actionbar.
*/publicstatic Intent getDefaultShareIntent(android.support.v7.widget.ShareActionProvider provider, String subject,
String body) {
if (provider != null) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
i.putExtra(android.content.Intent.EXTRA_TEXT, body);
provider.setShareIntent(i);
return i;
}
return null;
}
/**
* Do some correct on http-header.
* @param headers The available http-header.
*/publicstaticvoid makeHttpHeaders(Map<String, String> headers) {
if (headers.get("Accept-Encoding") == null) {
headers.put("Accept-Encoding", "gzip");
}
if (headers.get("Content-Type") == null) {
headers.put("Content-Type", "application/x-www-form-urlencoded");
}
if (headers.get("Content-Length") == null) {
headers.put("Content-Length", "0");
}
}
}