Skip to content

Instantly share code, notes, and snippets.

View bottomSheetView = getDialog().getWindow().getDecorView().findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior.from(bottomSheetView).setHideable(false);
private BottomSheetBehavior.BottomSheetCallback mBottomSheetCallback
= new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet,
@BottomSheetBehavior.State int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
dismiss();
}
}
<FrameLayout
android:id="@+id/design_bottom_sheet"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal|top"
  android:clickable="true"
  app:layout_behavior="@string/bottom_sheet_behavior"
  style="?attr/bottomSheetStyle"/>
View touchOutsideView = getDialog().getWindow().getDecorView().findViewById(android.support.design.R.id.touch_outside);
touchOutsideView.setOnClickListener(null);
private View wrapInBottomSheet(int layoutResId, View view, ViewGroup.LayoutParams params) {
...
if (shouldWindowCloseOnTouchOutside()) {
coordinator.findViewById(R.id.touch_outside).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isShowing()) {
cancel();
}
<View
android:id="@+id/touch_outside"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:soundEffectsEnabled="false"/>
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec, description: ‘Compile JNI source via NDK’) {
println(‘executing ndkBuild’)
  def ndkDir = project.android.ndkDirectory
  commandLine “$ndkDir/ndk-build”,
  ‘NDK_PROJECT_PATH=build/intermediates/ndk’,
  ‘APP_BUILD_SCRIPT=src/main/jni/Android.mk’,
  ‘NDK_APPLICATION_MK=src/main/jni/Application.mk’,
  ‘V=1’
}
// Find the class of Float
jclass FloatClass = env->FindClass(“java/lang/Float”);
// And the method ID of constructor of the Float class
jmethodID FloatInit = env->GetMethodID(FloatClass, “<init>”, “(F)V”);
for (int i = 0; i < 10; i += 1) {
jsize index = i;
// Create instances of Float
jobject value1 = env->NewObject(FloatClass, FloatInit, xxx);
jobject value2 = env->NewObject(FloatClass, FloatInit, xxx);
// Put the Float values into float arrays
// Find the Java class of ArrayList
jclass arrayListClass = (*env).FindClass(“java/util/ArrayList”);
// Create an instance by finding the method ID of the constructor
jobject arrayList = (*env).NewObject(arrayListClass, (*env).GetMethodID(arrayListClass, “<init>”, “()V”));
// Find the class of float
jclass floatClass = env->FindClass(“F”);
// Let’s assume a float array contains 10 elements
jsize size = 10;
// Create arrays