Skip to content

Instantly share code, notes, and snippets.

@marc0x71
Last active March 30, 2021 01:35
Show Gist options
  • Select an option

  • Save marc0x71/061f53453152d0a68c20 to your computer and use it in GitHub Desktop.

Select an option

Save marc0x71/061f53453152d0a68c20 to your computer and use it in GitHub Desktop.

Revisions

  1. marc0x71 revised this gist Mar 22, 2016. 2 changed files with 64 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions MainActivity.java
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,35 @@
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    openDialog();
    }
    });
    }

    private void openDialog() {
    View view = getLayoutInflater().inflate(R.layout.sheet_main, null);
    dialog = new BottomSheetDialog(this);
    dialog.setContentView(view);
    TextView camera_sel = (TextView) view.findViewById(R.id.camera);
    TextView gallery_sel = (TextView) view.findViewById(R.id.gallery);
    camera_sel.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    takePhotoFromCamera();
    dialog.dismiss();
    }
    });
    gallery_sel.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    takePhotoFromGallery();
    dialog.dismiss();
    }
    });
    dialog.show();
    }
    36 changes: 36 additions & 0 deletions sheet_main.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    <?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="match_parent"
    android:orientation="horizontal"
    android:padding="4dp">

    <TextView
    android:id="@+id/camera"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="?attr/selectableItemBackgroundBorderless"
    android:clickable="true"
    android:drawablePadding="8dp"
    android:drawableTop="@drawable/ic_camera"
    android:gravity="center_horizontal"
    android:padding="16dp"
    android:text="Camera"
    android:textSize="18sp" />

    <TextView
    android:id="@+id/gallery"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="?attr/selectableItemBackgroundBorderless"
    android:clickable="true"
    android:drawablePadding="8dp"
    android:drawableTop="@drawable/ic_panorama"
    android:gravity="center_horizontal"
    android:padding="16dp"
    android:text="Gallery"
    android:textSize="18sp" />

    </LinearLayout>
  2. marc0x71 created this gist Mar 22, 2016.
    7 changes: 7 additions & 0 deletions MainActivity.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    openDialog();
    }
    });