Skip to content

Instantly share code, notes, and snippets.

View goodev's full-sized avatar

Goodev goodev

View GitHub Profile
@goodev
goodev / Manager.java
Last active November 17, 2016 19:41
fix Crouton the ActionBarOverlay problem
//change de.keyboardsurfer.android.widget.crouton.Manager class
// add this method below 'handleTranslucentActionBar()' method
private void handleActionBarOverlay(ViewGroup.MarginLayoutParams params, Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
final boolean flags = activity.getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
if (flags) {
final int actionBarContainerId = Resources.getSystem().getIdentifier("action_bar_container", "id", "android");
final View actionBarContainer = activity.findViewById(actionBarContainerId);
// The action bar is present: the app is using a Holo theme.
try {
// force to use overflow menu
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class
.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception ex) {
@goodev
goodev / HeaderGridView.java
Created March 4, 2014 07:34
HeaderGridView - android
/*
* Copyright (C) 2013 The Android Open Source Project
*
* 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
@goodev
goodev / GeneratePropertiesFile.java
Created February 8, 2014 02:57
生成 Eclipse ADT 中libs 目录下的 代码关联 properties 文件
public class GeneratePropertiesFile {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
generatePropertiesFile();
}
@goodev
goodev / RigidWebView.java
Created December 24, 2013 04:41
* A custom WebView that is robust to rapid resize events in sequence. * * This is useful for a WebView which needs to have a layout of {@code WRAP_CONTENT}, since any * contents with percent-based height will force the WebView to infinitely expand (or shrink).
/* http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android-apps/4.3_r2.1/com/android/email/view/RigidWebView.java/?v=source
* Copyright (C) 2011 The Android Open Source Project
*
* 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
@goodev
goodev / RotateDrawablePost14Activity.java
Created December 2, 2013 05:32
RotateDrawable 动画技巧
package com.fourmob.sandbox.activities;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.drawable.RotateDrawable;
import android.os.Build;
@goodev
goodev / main.java
Created November 27, 2013 05:59
初始化 ActionBar 图标 并跟随 ListView 来缩放和移动图标
private ImageView getActionBarIconView() {
return (ImageView) findViewById(android.R.id.home);
}
ActionBar actionBar = getActionBar();
actionBar.setIcon(R.drawable.ic_transparent);
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
@goodev
goodev / main.java
Created November 27, 2013 05:58
修改文字的 alpha
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
float ratio = clamp(mHeader.getTranslationY() / mMinHeaderTranslation, 0.0f, 1.0f);
//actionbar title alpha
setTitleAlpha(clamp(5.0F * ratio – 4.0F, 0.0F, 1.0F));
@goodev
goodev / AlphaForegroundColorSpan.java
Created November 27, 2013 05:57
设置文字的 Alpha 值
public class AlphaForegroundColorSpan extends ForegroundColorSpan {
private float mAlpha;
public AlphaForegroundColorSpan(int color) {
super(color);
}
[…]
@Override
@goodev
goodev / main.java
Last active December 29, 2015 12:29
ListView 滚动的时候更新 ActionBar 的 alpha 值
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
float ratio = clamp(mHeader.getTranslationY() / mMinHeaderTranslation, 0.0f, 1.0f);
//actionbar title alpha
getActionBarTitleView().setAlpha(clamp(5.0F * ratio - 4.0F, 0.0F, 1.0F));