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
private void saveCurrentPosition() { | |
if (mListView != null) { | |
int position = mListView.getFirstVisiblePosition(); | |
View v = mListView.getChildAt(0); | |
int top = (v == null) ? 0 : v.getTop(); | |
//保存position和top | |
} | |
} | |
private void restorePosition() { |
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.content.Context; | |
public class DensityUtil { | |
/** | |
* 根据手机的分辨率从 dp 的单位 转成为 px(像素) | |
*/ | |
public static int dip2px(Context context, float dpValue) { | |
final float scale = context.getResources().getDisplayMetrics().density; | |
return (int) (dpValue * scale + 0.5f); |
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 boolean isIntentAvailable(Context context, String action) { | |
final PackageManager packageManager = context.getPackageManager(); | |
final Intent intent = new Intent(action); | |
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); | |
return list.size() > 0; | |
} |
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 boolean checkNickname(String sequence) { | |
final String format = "[^\\u4E00-\\u9FA5\\uF900-\\uFA2D\\w-_]"; | |
Pattern pattern = Pattern.compile(format); | |
Matcher matcher = pattern.matcher(sequence); | |
return !matcher.find(); | |
} |
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 final void collapseStatusBar(Context ctx) { | |
Object sbservice = ctx.getSystemService("statusbar"); | |
try { | |
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager"); | |
Method collapse; | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | |
collapse = statusBarManager.getMethod("collapsePanels"); | |
} else { | |
collapse = statusBarManager.getMethod("collapse"); | |
} |
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
<span style="font-size:14px;">package com.test.twiceexit; | |
import java.util.Timer; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.os.Handler; | |
import android.os.Message; | |
import android.view.KeyEvent; | |
import android.view.Menu; |
NewerOlder