3llomi / RecordView

A Simple Audio Recorder View with "hold to Record Button" and "Swipe to Cancel " Like WhatsApp
Apache License 2.0
368 stars 109 forks source link

record button releases immediately! #28

Closed alexinadev closed 6 years ago

alexinadev commented 6 years ago

Hi, I am using the latest version of Record-view library (compile 'com.devlomi.record-view:record-view:2.0.1'). I want to use it in a dialog view. When I use library codes in the activity everything works fine but in dialog view when I touch and hold the record button it acts like I tap it. I mean touch and release record button happens immediately! the code below is my dialog XML layout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="300dp"
    android:padding="16dp"
    android:layout_margin="24dp"
    android:background="@drawable/background_dialog"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.alexina.counselor.CustomViews.mTextView
                android:drawablePadding="8dp"
                android:gravity="bottom"
                android:textAlignment="gravity"
                android:drawableLeft="@drawable/ic_clock"
                android:textColor="@color/textColorMedium"
                android:id="@+id/input_time"
                android:text="@string/time"
                android:textSize="12sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/input_cost"
                android:layout_alignParentStart="true" />

            <ImageView
                android:padding="4dp"
                android:background="@drawable/bg_mic_btn"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:src="@drawable/tejarat"
                android:id="@+id/input_logo"
                android:layout_width="32dp"
                android:layout_height="32dp" />

            <com.alexina.counselor.CustomViews.mTextViewBold
                android:drawableLeft="@drawable/ic_credit_card"
                android:id="@+id/input_cost"
                android:gravity="center"
                android:textSize="24sp"
                android:paddingLeft="12dp"
                android:paddingRight="24dp"
                android:textColor="@color/textColorLight"
                android:text="120000"
                android:textAlignment="gravity"
                android:paddingTop="4dp"
                android:paddingBottom="2dp"
                android:layout_marginTop="4dp"
                android:layout_below="@+id/input_logo"
                android:background="@color/colorPrimary"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <LinearLayout
                android:layout_below="@+id/input_cost"
                android:orientation="vertical"
                android:id="@+id/input_category"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <com.github.florent37.expansionpanel.ExpansionHeader
                    android:background="@color/colorPrimaryDark"
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    app:expansion_headerIndicator="@+id/headerIndicator"
                    app:expansion_layout="@+id/expansionLayout"
                    app:expansion_toggleOnClick="true">

                    <android.support.v7.widget.AppCompatImageView

                        android:adjustViewBounds="true"
                        android:id="@+id/headerIndicator"
                        android:layout_gravity="center_vertical|right"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="12dp"
                        android:layout_width="wrap_content"
                        app:srcCompat="@drawable/ic_expand_button" />

                    <com.alexina.counselor.CustomViews.mTextView
                        android:paddingTop="4dp"
                        android:paddingBottom="4dp"
                        android:layout_marginRight="32dp"
                        android:text="@string/category"
                        android:textSize="12sp"
                        android:textColor="@color/textColorMedium"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </com.github.florent37.expansionpanel.ExpansionHeader>

                <com.github.florent37.expansionpanel.ExpansionLayout
                    android:id="@+id/expansionLayout"
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent">

                    <segmented_control.widget.custom.android.com.segmentedcontrol.SegmentedControl

                        android:background="@color/colorPrimaryDark"
                        android:id="@+id/segmented_control"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:radiusForEverySegment="true"
                        app:columnCount="4"
                        app:distributeEvenly="false"
                        app:radius="14dp"
                        app:textVerticalPadding="4dp"
                        app:strokeWidth="0.5dp"
                        app:segmentVerticalMargin="2dp"
                        app:segmentHorizontalMargin="2dp"
                        app:unSelectedStrokeColor="@color/colorAccent"
                        app:selectedTextColor="@color/textColorLight"
                        app:selectedStrokeColor="@color/toast"
                        app:selectedBackgroundColor="@color/toast"/>

                </com.github.florent37.expansionpanel.ExpansionLayout>

            </LinearLayout>

            <ImageView
                android:scaleType="centerCrop"
                android:src="@drawable/map"
                android:id="@+id/input_map"
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:layout_below="@+id/input_category" />

            <ImageView
                android:padding="4dp"
                android:background="@drawable/bg_mic_btn"
                android:src="@drawable/ic_refresh"
                android:id="@+id/input_map_refresh"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_margin="4dp"
                android:layout_below="@+id/input_category"
                android:layout_alignParentStart="true" />

            <com.alexina.counselor.CustomViews.mTextView
                android:paddingRight="12dp"
                android:paddingLeft="24dp"
                android:textColor="@color/tik"
                android:id="@+id/input_address"
                android:textSize="12sp"
                android:textAlignment="center"
                android:background="@color/colorPrimary"
                android:text="@string/address"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/input_map"
                android:paddingTop="2dp"
                android:layout_alignParentStart="true" />

            <RelativeLayout
                android:layout_margin="8dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/input_address"
                android:layout_alignParentStart="true">

                <com.devlomi.record_view.RecordView
                    android:id="@+id/record_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_toLeftOf="@+id/record_button"
                    app:slide_to_cancel_arrow="@drawable/recv_ic_arrow"
                    app:slide_to_cancel_arrow_color="#000000"
                    app:slide_to_cancel_bounds="8dp"
                    app:slide_to_cancel_margin_right="10dp"
                    app:slide_to_cancel_text="Slide To Cancel"
                    app:counter_time_color="#ff0000"
                    />

                <com.devlomi.record_view.RecordButton
                    android:id="@+id/record_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:background="@drawable/recv_bg_mic"
                    android:scaleType="centerInside"
                    app:mic_icon="@drawable/recv_ic_mic_white" />

            </RelativeLayout>

            <ImageButton
                android:src="@drawable/ic_photo_camera_black_24dp"
                android:background="@drawable/bg_mic_btn"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:id="@+id/imageButton"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="4dp"
                android:layout_alignTop="@+id/input_map_refresh"
                android:layout_alignParentEnd="true"
                android:layout_marginEnd="11dp" />

            <com.alexina.counselor.CustomViews.mEdittext
                android:id="@+id/input_description"
                android:background="@drawable/background_edittext"
                android:hint="@string/explanation"
                android:textSize="16sp"
                android:padding="8sp"
                android:layout_marginTop="4dp"
                android:textColorHint="@color/textColorMedium"
                android:inputType="textMultiLine"
                android:gravity="top|right"
                android:textColor="@color/textColorLight"
                android:layout_below="@+id/input_address"
                android:layout_width="match_parent"
                android:layout_height="72sp" />

            <LinearLayout
                android:layout_marginTop="4dp"
                android:layout_below="@+id/input_description"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <com.alexina.counselor.CustomViews.mButton
                    android:id="@+id/dialog_cancel_btn"
                    android:textColor="@color/textColorMedium"
                    android:text="@string/cancel"
                    android:layout_margin="2dp"
                    android:background="@drawable/background_dialog_btn_solid_neg"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <com.alexina.counselor.CustomViews.mButton
                    android:id="@+id/dialog_approve_btn"
                    android:textColor="@color/textColorLight"
                    android:text="@string/save"
                    android:layout_margin="2dp"
                    android:background="@drawable/background_dialog_btn_solid_pos"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </RelativeLayout>

    </LinearLayout>

</ScrollView>

and my Java code is:

public static void popUpDialogInput(final Context context, List<String> categories, int layout,
                                        View.OnClickListener approveClick, View.OnClickListener cancelClick){

        dialog = new Dialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(layout);
        dialog.setCancelable(false);
        Button ok = (Button)dialog.findViewById(R.id.dialog_approve_btn);
        Button cancel = (Button)dialog.findViewById(R.id.dialog_cancel_btn);
        ok.setOnClickListener(approveClick);
        cancel.setOnClickListener(cancelClick);

        RecordView recordView = (RecordView) dialog.findViewById(R.id.record_view);
        RecordButton recordButton = (RecordButton) dialog.findViewById(R.id.record_button);
        //IMPORTANT
        recordButton.setRecordView(recordView);
        recordView.setSlideToCancelText(context.getString(R.string.say_sth));
        recordView.setOnRecordListener(new OnRecordListener() {
            @Override
            public void onStart() {
                //Start Recording..
                Log.d("RecordView", "onStart");
            }

            @Override
            public void onCancel() {
                //On Swipe To Cancel
                Log.d("RecordView", "onCancel");

            }

            @Override
            public void onFinish(long recordTime) {
                //Stop Recording..    
            }

            @Override
            public void onLessThanSecond() {
                //When the record time is less than One Second
                Log.d("RecordView", "onLessThanSecond");
            }
        });

        final SegmentedControl segmentedControl = (SegmentedControl) dialog.findViewById(R.id.segmented_control);
        segmentedControl.addSegments(categories);
        segmentedControl.setAdapter(new AdapterAppSegment());
        segmentedControl.addOnSegmentSelectListener(new OnSegmentSelectedListener() {
            @Override
            public void onSegmentSelected(SegmentViewHolder segmentViewHolder, boolean b, boolean b1) {
                Log.d("ALEXINA", "onSegmentSelected");
            }
        });

        segmentedControl.addOnSegmentClickListener(new OnSegmentClickListener() {
            @Override
            public void onSegmentClick(SegmentViewHolder segmentViewHolder) {
                Log.d("ALEXINA", "onSegmentClick");

            }
        });

        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.show();
    }
Menris commented 6 years ago

@alexinadev I had that problem because my cancel text was too long. Try change setSlideToCancelText as "Cancel" or smth short and try again. This releases when your error text touch the timer while sliding left(I might be wrong). If screen is small - error text is on timer when you start recording by default.

3llomi commented 6 years ago

Hey @alexinadev , sorry for late response. i just tried to put the RecordView Sample app into a Dialog and it works fine. i tried to use your sample but there are a lot of customViews that you are using. you can try the following:

  1. since you are using a ScrollView you can refer to this issue

  2. as @Menris said you might want to decrease cancelBounds using recordView.setCancelBounds(value) because the dialog width will not take the whole space.

  3. otherwise you can send me a sample project so i can deep dive into it.