Skip to content

Instantly share code, notes, and snippets.

View Reacoder's full-sized avatar

赵小龙_同学 Reacoder

  • shanghai china
View GitHub Profile
@Reacoder
Reacoder / PagerAdapter.java
Created July 30, 2014 02:54
fragment 中 包含 fragment, 还有 indicator。
package com.ilegendsoft.toprankapps.musictube.adapters;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.toprankapps.musictube4.R;
import com.ilegendsoft.toprankapps.musictube.fragments.HotArtistFragment;
import com.ilegendsoft.toprankapps.musictube.fragments.PopularFragment;
@Reacoder
Reacoder / modifyActionButton.java
Created July 30, 2014 08:40
动态改变actionbutton。
/* Called whenever we call invalidateOptionsMenu() */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
Logger.d("======== onPrepareOptionsMenu =========="+mSubscribed);
MenuItem item = menu.findItem(R.id.action_subscribe);
if (mSubscribed) {
item.setTitle(R.string.menu_unsubscribe);
item.setIcon(R.drawable.btn_actionbar_unsubscriptions);
} else {
item.setTitle(R.string.menu_subscribe);
/* Clear all Fragments inside current adapter */
public class MyPagerAdapter extends FragmentPagerAdapter
{
private ArrayList<Fragment> fragments=new ArrayList<Fragment>();
//...some stuff
public void clearAll() //Clear all page
{
for(int i=0; i<fragments.size(); i++)
fragMan.beginTransaction().remove(fragments.get(i)).commit();
@Reacoder
Reacoder / edittext.java
Created August 5, 2014 05:27
EditText onClick event is not triggering
When a user interacts with a UI element the various listeners are called in a top down order. (For example: OnTouch -> OnFocusChange -> OnClick.) If a listener has been defined (with setOn...Listener) and it consumes this event: the lower priority listeners will not be called. By its nature the first time you touch an EditText it receives focus with OnFocusChangeListener so that the user can type. The action is consumed here therefor OnClick is not called. Each successive touch doesn't change the focus so the event trickles down to the OnClickListener.
Basically, you have three choices:
Set the focusable attribute to false in your XML:
android:focusable="false"
Now the OnClickListener will fire every time it is clicked. But this makes the EditText useless since the user can no longer enter any text...
Implement an OnFocusChangeListener along with the OnClickListener:
@Reacoder
Reacoder / PopupWindow.java
Created August 5, 2014 09:30
PopupWindow - Dismiss when clicked outside
mFilterWindow = new PopupWindow(popupLayout,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT);
mFilterWindow.setOutsideTouchable(true);
mFilterWindow.setBackgroundDrawable(new ColorDrawable());
mFilterWindow.setFocusable(true);
@Reacoder
Reacoder / SeekBar.xml
Created August 8, 2014 08:29
自定义seekBar
<SeekBar
android:id="@+id/mediacontroller_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="24dp"
android:maxHeight="2dp"
android:progressDrawable="@drawable/seekbar"
android:thumb="@drawable/seekbar_thumb" />
@Reacoder
Reacoder / FSUtil.java
Created August 8, 2014 10:38
获得 sdcard 空间。
package com.ilegendsoft.toprankapps.tubeplayer.utils;
import android.os.Environment;
import android.os.StatFs;
public class FSUtil {
// One binary gigabyte equals 1,073,741,824 bytes.
private static final long PER_G_NUM = 1073741824;
public static String getAvailableSpace() {
List<Fruit> fruits= new ArrayList<Fruit>();
Fruit fruit;
for(int i=0;i<100;i++)
{
fruit = new fruit();
fruit.setname(...);
fruits.add(fruit);
}
@Reacoder
Reacoder / Theme.AppCompat.Light.NoActionBar.xml
Created August 19, 2014 02:05
Theme.AppCompat.Light.NoActionBar
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
@Reacoder
Reacoder / actionbar.java
Last active August 29, 2015 14:05
更换 actionBar 的 icon
<activity
android:name="com.ilegendsoft.toprankapps.tubeplayer.activities.PlayVideoActivity"
android:configChanges="orientation|screenSize"
android:launchMode="singleTop"
android:logo="@drawable/play_video_back" >
</activity>
<?xml version="1.0" encoding="utf-8"?>
<layer-list