This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest package="com.my.whatever" | |
xmlns:android="http://schemas.android.com/apk/res/android"> | |
<uses-permission android:name="com.android.vending.BILLING"/> | |
<application> | |
<activity | |
android:name=".IapDelegateActivity" | |
android:theme="@style/AppTheme.Invisible"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 1, from an android.app.Activity: | |
// Use the startActivityForResult(Intent, int) and subscribe | |
// the result in onActivityResult(int, int, Intent). | |
startActivityForResult( | |
new Intent(this, IapDelegateActivity.class) | |
.putExtra(IapDelegateActivity.PARAMS_SKU, "sku") | |
.putExtra(IapDelegateActivity.PARAMS_SKU_PRICE, 1.99f)); | |
// Example 2, from a android.app.Service: | |
// Use the startActivity(Intent) and subscribe the result in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2017-present boyw165 | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void cancelChildrenTouchEvent(MotionEvent event) { | |
// MotionEvent.obtain creates a new MotionEvent`, copying from an existing one. | |
final MotionEvent canceledEvent = MotionEvent.obtain(event); | |
// The event was handled by the certain child view. In order to make the touch event | |
// lifecycle complete, we have to fake a ACTION_CANCEL for the child view. | |
// Otherwise, it would be chaos. | |
canceledEvent.setAction(MotionEvent.ACTION_CANCEL); | |
super.dispatchTouchEvent(canceledEvent); | |
canceledEvent.recycle(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void cancelSelfTouchEvent(MotionEvent event) { | |
final MotionEvent canceledEvent = MotionEvent.obtain(event); | |
canceledEvent.setAction(MotionEvent.ACTION_CANCEL); | |
onTouchEvent(canceledEvent); | |
canceledEvent.recycle(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface NestedScrollingChild { | |
/** | |
* Begin a nestable scroll operation along the given axes. | |
* | |
* @param axes Flags consisting of a combination of {@link ViewCompat#SCROLL_AXIS_HORIZONTAL} | |
* and/or {@link ViewCompat#SCROLL_AXIS_VERTICAL}. | |
* @return true if a cooperative parent was found and nested scrolling has been enabled for | |
* the current gesture. | |
*/ | |
public boolean startNestedScroll(int axes); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CoordinatorLayout extends ViewGroup | |
implements NestedScrollingParent { | |
@Override | |
public void onNestedScroll(View target, int dxConsumed, int dyConsumed, | |
int dxUnconsumed, int dyUnconsumed) { | |
final int childCount = getChildCount(); | |
boolean accepted = false; | |
for (int i = 0; i < childCount; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, | |
final int position, | |
List<Object> payloads) { | |
final ImageView imageView = (ImageView) viewHolder.itemView; | |
final IPhoto photo = getPhotoAt(position); | |
Glide.with(getContext()) | |
.load(photo.thumbnailPath()) | |
// Setting the placeholder will fix the "ghost images" problem. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class CursorRecyclerViewAdapter<VH extends RecyclerView.ViewHolder> | |
extends RecyclerView.Adapter<VH> { | |
final private WeakReference<Context> mContext; | |
final private WeakReference<LayoutInflater> mInflater; | |
private RecyclerView mRecyclerView; | |
private Cursor mCursor; | |
// State. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Change the underlying cursor to a new cursor. If there is an existing | |
* cursor it will be closed. | |
*/ | |
public void setData(Cursor cursor) { | |
Cursor old = swapCursor(cursor); | |
if (old != null && !old.isClosed()) { | |
old.close(); | |
} | |
} |