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
//定义泛型接口
public interface HttpCallBack<T> {
public void onSuccess(T result);
public void onFail(Throwable throwable);
}
//定义父类子类model
public class ChildModel extends ParentModel {
String result;
//滑动视图
public class MyScrollView extends ViewGroup {
Context context;
Scroller scroller=null;
VelocityTracker tracker=null;
//判断点击还是滑动
int touchSlop=0;
//滑动速度临界值
//fragment页签使用方法
//初始化时候将缓存的所有fragment全部隐藏
List<Fragment> fragments=getSupportFragmentManager().getFragments();
if(fragments!=null) {
for(int i=0;i<fragments.size();i++) {
getSupportFragmentManager().beginTransaction().hide(fragments.get(i)).commit();
}
}
//viewPager中加载frament方法
//查找是不是已经保存过fragment,优先使用保存过的fragment
if(savedInstanceState!=null) {
fragment1=(MyGridViewFragment) getChildFragmentManager().getFragment(savedInstanceState, "first");
if((MyGridViewFragment) getChildFragmentManager().getFragment(savedInstanceState, "first")==null) {
fragment1=MyGridViewFragment.getInstance(1);
}
else {
fragment1=(MyGridViewFragment) getChildFragmentManager().getFragment(savedInstanceState, "first");
//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 {
//动态刷新fragment的方法
//将FragmentTransaction中的fragment全部清除
public void addFragment() {
if(fragment_list != null){
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
for(Fragment f: fragment_list){
ft.remove(f);
}
ft.commitAllowingStateLoss();
// 循环检测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);
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();
}
@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(
@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中也要预先定好多少行多少列