Skip to content

Instantly share code, notes, and snippets.

View r17171709's full-sized avatar
🏠
Working from home

Ren Yu r17171709

🏠
Working from home
View GitHub Profile
@r17171709
r17171709 / ListScrollDistanceCalculator.java
Created December 31, 2015 02:26 — forked from mariotaku/ListScrollDistanceCalculator.java
Calculate list scroll distance without any modification to ListView and ListAdapter. great for QuickReturn pattern
package org.mariotaku.twidere.util;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
/**
* Created by mariotaku on 14/10/22.
*/
public class ListScrollDistanceCalculator implements OnScrollListener {
@r17171709
r17171709 / viewPager动画切换效果
Last active October 10, 2015 07:13
viewPager动画切换效果
ViewPager vp=null;
RelativeLayout rel_layout=null;
ArrayList<Fragment> fragments=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@r17171709
r17171709 / notificationCompat的使用
Created October 9, 2015 08:34
notificationCompat的使用
private void showNotification() {
NotificationCompat.Builder build=new NotificationCompat.Builder(this);
build.setSmallIcon(R.mipmap.ic_launcher);
build.setTicker("这是通知");
build.setContentTitle("这是标题");
//设置优先级
build.setPriority(NotificationCompat.PRIORITY_MIN);
build.setContentText("这是内容");
build.setContentIntent(getPendingIntent("普通文字", 0));
private void easeRegist(final String objectId) {
JSONObject object=new JSONObject();
try {
object.put("username", objectId);
object.put("password", "abcd1234");
object.put("nickname", objectId);
final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
OkHttpClient client = HttpUtils.getInstance().clone();
RequestBody body = RequestBody.create(JSON, object.toString());
Request request = new Request.Builder().addHeader("Content-Type", "application/json").url(ParamsUtil.HXUsers).post(body).build();
@r17171709
r17171709 / gridlayout动态添加
Created July 15, 2015 06:01
gridlayout动态添加
//类似数组[行, 列]
//表示起始位置为0,占据2行
GridLayout.Spec rowSpec=GridLayout.spec(0, 2, GridLayout.UNDEFINED);
//表示起始位置为1,占据1列
GridLayout.Spec columnSpec=GridLayout.spec(i, 1, GridLayout.UNDEFINED);
GridLayout.LayoutParams params=new GridLayout.LayoutParams(rowSpec, columnSpec);
gridlayout.addView(view, params);
此外xml中也要预先定好多少行多少列
@r17171709
r17171709 / 视频横竖屏切换
Created June 22, 2015 04:23
视频横竖屏切换
// 切换为全屏
private void setFullScreen() {
if (Build.VERSION.SDK_INT >= 9) {
setRequestedOrientation(6);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
getWindow().addFlags(1024);
mActionBar.hide();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
try {
db.beginTransaction();
String[][] lifes = {{"potato", "tomato", "apple"}, {"rat", "cat", "dog"}};
SQLiteStatement stmt = db.compileStatement("insert into life values(?,?)");
for(int i=0;i<lifes[0].length;i++){
stmt.clearBindings();
stmt.bindString(1, lifes[0][i]);
stmt.bindString(1, lifes[1][i]);
stmt.executeInsert();
}
// 循环检测activity是否初始化完毕
starnum_seekbar.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (null != getWindow().getDecorView().getWindowToken()) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View undoView = inflater.inflate(
R.layout.view_seekbarhint2, null);
//动态刷新fragment的方法
//将FragmentTransaction中的fragment全部清除
public void addFragment() {
if(fragment_list != null){
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
for(Fragment f: fragment_list){
ft.remove(f);
}
ft.commitAllowingStateLoss();
//viewpager中同时包含image跟surfaceview的情况处理
//给viewPager中的View添加id,便于后续查找
for(int i=0;i<multi_media.size();i++) {
if (multi_media.get(i).gettype().endsWith("0")) {
ImageView imageView=new ImageView(this);
imageView.setImageResource(R.drawable.ic_launcher);
bitmapUtils.display(imageView, multi_media.get(i).getDescription_url(), config);
views.add(imageView);
} else {