카테고리 없음

BottomBehavior

그란. 2017. 12. 10. 18:00

public class DialogTimePicker extends BottomSheetDialog {

private SeekBar seekBar;
private ActivityMaps parent;
TextView seekbar_text;
String selected = null;

public DialogTimePicker(final ActivityMaps parent) {
super(parent);
this.parent = parent;
View v = (View) View.inflate(getContext(), R.layout.dialog_timepicker, null);
seekBar = (SeekBar) v.findViewById(R.id.seekbar_distance);
seekbar_text = (TextView) v.findViewById(R.id.seekbar_text);
final Integer[] distanceList_int = {300, 500, 1000, 3000, 5000};
final String[] distanceList_str = {"300m", "500m", "1km", "3km", "5km"};


seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
selected = distanceList_str[progress];
seekbar_text.setText(selected);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
selected = distanceList_str[progress];
parent.spinnerdistance.setText(selected);
parent.clearView();
parent.settingMap(distanceList_int[progress]);
parent.retrieveWithDistance(distanceList_int[progress]);
dismiss();

}
});


setContentView(v);
configureBottomSheetBehavior(v);
}

private void configureBottomSheetBehavior(View contentView) {
BottomSheetBehavior mBottomSheetBehavior = BottomSheetBehavior.from((View) contentView.getParent());

if (mBottomSheetBehavior != null) {
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {

@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
//showing the different states
switch (newState) {
case BottomSheetBehavior.STATE_HIDDEN:
dismiss(); //if you want the modal to be dismissed when user drags the bottomsheet down
break;
case BottomSheetBehavior.STATE_EXPANDED:
break;
case BottomSheetBehavior.STATE_COLLAPSED:
break;
case BottomSheetBehavior.STATE_DRAGGING:
break;
case BottomSheetBehavior.STATE_SETTLING:
break;
}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
}
}
}



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#eeeeee"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="검색 반경 선택" />

<TextView
android:id="@+id/seekbar_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="300m"
android:textColor="#000000"
android:textSize="24sp" />

<SeekBar
android:thumb="@drawable/red_scrubber_control"
android:progressDrawable="@drawable/red_scrubber_progress"
android:id="@+id/seekbar_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="30dp"
android:max="4"
android:solidColor="#fffff0" />

</LinearLayout>