Skip to content

Instantly share code, notes, and snippets.

View Reacoder's full-sized avatar

赵小龙_同学 Reacoder

  • shanghai china
View GitHub Profile
@Reacoder
Reacoder / StatusBar.java
Created June 6, 2014 07:07
Show or hide status bar.
private void hideStatusBar() {
if (Build.VERSION.SDK_INT < 16) {
hideStatusBarLowVersion();
} else {
hideStatusBarHighVersion();
}
}
private void showStatusBar() {
if (Build.VERSION.SDK_INT < 16) {
@Reacoder
Reacoder / dpToPixel.java
Created June 10, 2014 01:39
dp convert to pixel.
/// Converts 14 dip into its equivalent px
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, getResources().getDisplayMetrics());
private OnClickListener popupClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.share_google:
System.out.println("===== share_google");
break;
case R.id.share_facebook:
System.out.println("===== share_facebook");
@Reacoder
Reacoder / gsonArray.java
Created June 10, 2014 04:00
Gson get string from arrayList.
Gson gson = new Gson();
String videosJson = gson.toJson(playingVideos,
new TypeToken<ArrayList<PlayingVideo>>() {
}.getType());
@Reacoder
Reacoder / queryIntent.java
Created June 10, 2014 09:56
Check intent .
public static boolean isAvailable(Context ctx, Intent intent) {
final PackageManager mgr = ctx.getPackageManager();
List<ResolveInfo> list =
mgr.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
@Reacoder
Reacoder / divider.xml
Created June 11, 2014 04:20
listview divider margin left 60dp.
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="60dp"
android:insetRight="8dp" >
<shape>
<solid android:color="#c0c0c0" />
</shape>
</inset>
@Reacoder
Reacoder / softKeyBoard.java
Created June 11, 2014 07:22
hide soft key board.
InputMethodManager imm = (InputMethodManager) mActivity
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
@Reacoder
Reacoder / regex.java
Created June 17, 2014 02:31
regex extract string.
public static String extractJsUrl(String originHtml) {
// <script src="//s.ytimg.com/yts/jsbin/html5player-zh_CN-vflHa9pzi.js"
// name="html5player"></script>
final String REGEX = "//s[.]ytimg[.]com/.*html5player.*[.]js";
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(originHtml);
String jsUrl = null;
if (m.find()) {
jsUrl = originHtml.substring(m.start(), m.end());
@Reacoder
Reacoder / isMain.java
Created July 23, 2014 03:56
判断是不是在主线程中。
static boolean isMain() {
return Looper.getMainLooper().getThread() == Thread.currentThread();
}
@Reacoder
Reacoder / FragmentInFragment.java
Created July 23, 2014 05:11
Add this in father fragment.
/**
* This seems to be a bug in the newly added support for nested fragments.
* Basically, the child FragmentManager ends up with a broken internal state
* when it is detached from the activity. A short-term workaround that fixed
* it for me is to add the following to onDetach() of every Fragment which
* you call getChildFragmentManager() on:
*/
@Override
public void onDetach() {
super.onDetach();