This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cerrno> | |
#include <system_error> | |
#include <type_traits> | |
void check_errno() { | |
const auto e = errno; | |
if (e) { | |
errno = 0; | |
throw std::system_error(e, std::system_category()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct finally { | |
inline explicit finally(const std::function<void()>& code) noexcept: m_code{code} {} | |
inline ~finally() noexcept { try { m_code(); } catch(...) {} } | |
private: | |
finally(const finally&) = delete; | |
finally(finally&&) = delete; | |
finally& operator=(const finally&) = delete; | |
finally& operator=(finally&&) = delete; | |
std::function<void()> m_code; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String toString(InputStream is) throws IOException { | |
InputStreamReader isr = null; | |
try { | |
isr = new InputStreamReader(is, "UTF-8"); | |
char[] buf = new char[512]; | |
StringBuilder str = new StringBuilder(); | |
int i = 0; | |
while ( (i = isr.read(buf)) != -1 ) str.append(buf, 0 ,i); | |
return str.toString(); | |
} finally { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.DataInput; | |
import java.io.EOFException; | |
import java.io.FilterInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
public class LEDataInputStream extends FilterInputStream implements DataInput { | |
private final byte[] buffer = new byte[8]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Looper; | |
import android.os.MessageQueue; | |
import android.util.Log; | |
import android.util.Printer; | |
public class ANRDetector { | |
public static final String TAG = "ANRDetector"; | |
private final Looper looper; | |
private final MessageQueue queue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int getLowBatteryWarningLevel() { | |
return Resources.getSystem().getInteger( | |
Resources.getSystem().getIdentifier("config_lowBatteryWarningLevel", "integer", "android")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Create a circle avatar from a Bitmap. Use in ImageView | |
* with setImageDrawable() | |
*/ | |
public static Drawable makeCircleAvatar(Bitmap bmp) { | |
ShapeDrawable dr = new ShapeDrawable(new OvalShape()); | |
dr.getPaint().setShader(new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP)); | |
dr.setIntrinsicWidth(bmp.getWidth()); | |
dr.setIntrinsicHeight(bmp.getHeight()); | |
return dr; |
NewerOlder