Skip to content

Instantly share code, notes, and snippets.

View brucetoo's full-sized avatar
🎧
Visualization

Bruce too brucetoo

🎧
Visualization
View GitHub Profile
@brucetoo
brucetoo / onStartComand
Created July 13, 2015 13:09
service onStartCommand的返回值
onStartComand 可以有四个返回值:START_STICKY、START_NO_STICKY、START_REDELIVER_INTENT、START_STICKY_COMPATIBILITY。
它们的含义分别是:
1):START_STICKY:如果service进程被kill掉,保留service的状态为开始状态,但不保留递送的intent对象。随后系统会尝试重新创建service,由于服务状态为开始状态,所以创建服务后一定会调用onStartCommand(Intent,int,int)方法。如果在此期间没有任何启动命令被传递到service,那么参数Intent将为null。
2):START_NOT_STICKY:“非粘性的”。使用这个返回值时,如果在执行完onStartCommand后,服务被异常kill掉,系统不会自动重启该服务
3):START_REDELIVER_INTENT:重传Intent。使用这个返回值时,如果在执行完onStartCommand后,服务被异常kill掉,系统会自动重启该服务,并将Intent的值传入。
4):START_STICKY_COMPATIBILITY:START_STICKY的兼容版本,但不保证服务被kill后一定能重启
@brucetoo
brucetoo / .java
Created July 21, 2015 03:43
PullToRefresh自动刷新
@Override
public void onResume() {
super.onResume();
//自动刷新值需要在onResume方法中延迟执行 mPulltoRefreshView.setRefreshing(true)
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mGridView.setRefreshing(true);
//异步执行加载数据任务
//加载数据成功后,必须调用 mPullToRefreshView.onRefreshComplete()
adapter的getView方法,我们要进行单条刷新就要手动调用这个方法。
public View getView(int position, View convertView, ViewGroup parent)
那么这三个参数是如何确定的呢,第三个参数很好确定,就是你的listview。
为了确定另外两个参数position和converView,这里介绍几个lisView的新方法:
getFirstVisiblePosition(),该方法获取当前状态下list的第一个可见item的position。
getLastVisiblePosition(),该方法获取当前状态下list的最后一个可见item的position。
getItemAtPosition(int position),该方法返回当前状态下position位置上listView的convertView
我们通过从getFirstVisiblePosition的值到getLastVisiblePosition的值之间的listitem和需要进行更新的条件(比如id)进行比较确定哪一个是要更新的(如果不在当前可是范围内也就没有必要更新了,等list拉动的时候自然就会更新出来)
@brucetoo
brucetoo / 打开另一个应用.java
Created August 4, 2015 09:31
从一个应用打开另一个应用的简单办法
Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage(AppConstants.CC_PACKAGE_NAME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
@brucetoo
brucetoo / 自定义ProgressBar.xml
Last active August 29, 2015 14:26
自定义ProgressBar
<ProgressBar
android:id="@+id/mgsdk__progressBar_loading"
style="@android:style/Widget.ProgressBar.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:background="@drawable/mgsdk__progress_bg"
android:indeterminateDrawable="@drawable/mgsdk__progress" />
@brucetoo
brucetoo / README.md
Last active August 29, 2015 14:26 — forked from gabrielemariotti/README.md
How to manage the support libraries in a multi-module projects. Thanks to Fernando Cejas (http://fernandocejas.com/)

Centralize the support libraries dependencies in gradle

Working with multi-modules project, it is very useful to centralize the dependencies, especially the support libraries.

A very good way is to separate gradle build files, defining something like:

root
  --gradleScript
 ----dependencies.gradle
@brucetoo
brucetoo / InputMethodManager.java
Created August 11, 2015 08:21
输入的显示和隐藏
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); //切换输入法的显示和隐藏
imm.showSoftInput(edittext, InputMethodManager.SHOW_FORCED); //强制显示输入法,edittext为输入接收的view
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);//隐藏输入法
@brucetoo
brucetoo / ScrollAwareFABBehavior.java
Last active August 29, 2015 14:27
FAB使用在CoordinatorLayout的隐藏动画
package com.support.android.designlibdemo;
import android.content.Context;
import android.os.Build;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.AttributeSet;
@brucetoo
brucetoo / RealmModulesExample.java
Created August 18, 2015 12:58
RealmModules的使用
/*
* Copyright 2015 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@brucetoo
brucetoo / sp和dp转换成px.java
Created August 19, 2015 12:19
不用Context 将sp和dp转换成px
private int dp2px(float dpVal) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dpVal, getResources().getDisplayMetrics());
}
private int sp2px(float dpVal) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
dpVal, getResources().getDisplayMetrics());
}