Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
InstaMaterial source files
<?xml version="1.0" encoding="utf-8"?>
<!--drawable/btn_feed_action.xml-->
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:enterFadeDuration="200" android:exitFadeDuration="200">
<item android:state_pressed="false">
<shape android:shape="oval">
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="#6621425d" />
</shape>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!--drawable-v21/btn_feed_action.xml-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorPrimaryDark" />
<?xml version="1.0" encoding="utf-8"?>
<!--drawable/btn_send_comment.xml-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<layer-list>
<item android:bottom="0dp" android:left="2dp" android:right="0dp" android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="@color/fab_color_shadow" />
<corners android:radius="2dp" />
</shape>
</item>
<item android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="@color/btn_send_normal" />
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>
</item>
<item android:state_pressed="true">
<shape android:bottom="0dp" android:left="2dp" android:right="0dp" android:shape="rectangle" android:top="2dp">
<solid android:color="@color/btn_send_pressed" />
<corners android:radius="2dp" />
</shape>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!--drawable-v21/btn_send_comment.xml-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffffff">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/btn_send_normal" />
</shape>
</item>
</ripple>
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="2"/>
<?xml version="1.0" encoding="utf-8"?>
<!-- item_feed.xml -->
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android">
<!--...-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ImageButton
android:id="@+id/btnLike"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/btn_feed_action"
android:src="@drawable/ic_heart_outline_grey" />
<ImageButton
android:id="@+id/btnComments"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/btn_feed_action"
android:src="@drawable/ic_comment_outline_grey" />
</LinearLayout>
<!--...-->
</android.support.v7.widget.CardView>
public class MainActivity extends ActionBarActivity implements FeedAdapter.OnFeedItemClickListener {
//...
private void setupFeed() {
//Increase the amount of extra space that should be laid out by LayoutManager.
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this) {
@Override
protected int getExtraLayoutSpace(RecyclerView.State state) {
return 300;
}
};
rvFeed.setLayoutManager(linearLayoutManager);
//...
}
//...
}
public class SendCommentButton extends ViewAnimator implements View.OnClickListener {
public static final int STATE_SEND = 0;
public static final int STATE_DONE = 1;
private static final long RESET_STATE_DELAY_MILLIS = 2000;
private int currentState;
private OnSendClickListener onSendClickListener;
private Runnable revertStateRunnable = new Runnable() {
@Override
public void run() {
setCurrentState(STATE_SEND);
}
};
public SendCommentButton(Context context) {
super(context);
init();
}
public SendCommentButton(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
LayoutInflater.from(getContext()).inflate(R.layout.view_send_comment_button, this, true);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
currentState = STATE_SEND;
super.setOnClickListener(this);
}
@Override
protected void onDetachedFromWindow() {
removeCallbacks(revertStateRunnable);
super.onDetachedFromWindow();
}
public void setCurrentState(int state) {
if (state == currentState) {
return;
}
currentState = state;
if (state == STATE_DONE) {
setEnabled(false);
postDelayed(revertStateRunnable, RESET_STATE_DELAY_MILLIS);
setInAnimation(getContext(), R.anim.slide_in_done);
setOutAnimation(getContext(), R.anim.slide_out_send);
} else if (state == STATE_SEND) {
setEnabled(true);
setInAnimation(getContext(), R.anim.slide_in_send);
setOutAnimation(getContext(), R.anim.slide_out_done);
}
showNext();
}
@Override
public void onClick(View v) {
if (onSendClickListener != null) {
onSendClickListener.onSendClickListener(this);
}
}
public void setOnSendClickListener(OnSendClickListener onSendClickListener) {
this.onSendClickListener = onSendClickListener;
}
@Override
public void setOnClickListener(OnClickListener l) {
//Do nothing, you have you own onClickListener implementation (OnSendClickListener)
}
public interface OnSendClickListener {
public void onSendClickListener(View v);
}
}
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0%"
android:interpolator="@anim/cycle_2"
android:toXDelta="2%" />
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromYDelta="80%p"
android:interpolator="@android:anim/linear_interpolator"
android:toYDelta="0" />
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromYDelta="-80%p"
android:interpolator="@android:anim/linear_interpolator"
android:toYDelta="0" />
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromYDelta="0"
android:interpolator="@android:anim/linear_interpolator"
android:toYDelta="80%p" />
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromYDelta="0"
android:interpolator="@android:anim/linear_interpolator"
android:toYDelta="-80%p" />
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/tvSend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="SEND"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/tvDone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text=""
android:textColor="#ffffff"
android:textSize="12sp" />
</merge>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.