Отключить активность без фрагмента - PullRequest
1 голос
/ 06 ноября 2019

Это мой первый вопрос, так что прости меня, если я сделаю это неправильно.

Вопрос в том, что у меня есть активность "FirstConfig.kt". Когда пользователь нажимает на конкретную кнопку, я показываю фрагмент с биометрической аутентификацией. Фрагмент «на вершине», так что парентеральная деятельность «отстает» от него и служит фоном. Как я могу отключить взаимодействие пользователя с активностью, но без фрагмента, чтобы позволить нажать «отмена» в биометрическом запросе

функция из FirstConfig.kt

private fun ShowBiometricPrompt() {
    supportFragmentManager.beginTransaction()
        .setCustomAnimations(R.anim.slide_up, R.anim.slide_down)
        .add(
            R.id.main_first_config,
            SmallBiometricAuthenticate::class.java.newInstance()
        ).commit()
}

Я пытаюсь это window.setFlags( WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)

Но это блокирует всю активность с фрагментом, и пользователь не может нажать «отмена». Может кто-нибудь помочь мне, пожалуйста?

@ EDIT

Да. Я тоже хочу сделать фрагмент доступным, пока активность недоступна

ActivityLayout (часть этого макета - ConstraintLayout, но stackoverflow вырезает из меня эту часть кода)

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:id="@+id/first_config_layout"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="Przeprowadzimy teraz krótką konfigurację, aby dostować aplikację do Twoich oczekiwań"
        android:textAlignment="center" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="5dp"
        android:text="Powiadomienia"
        android:textAlignment="center"
        android:textColor="#111111"
        android:textSize="18dp"
        android:textStyle="bold" />

    <View
        android:id="@+id/bottom_belk"
        android:layout_width="80dp"
        android:layout_height="2dp"
        android:background="#111111"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"></View>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingStart="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:gravity="center"
                android:text="Zmiany w grafiku" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:gravity="center"
                android:text="Nowa ocena" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:gravity="center"
                android:text="Zbliżająca się płatność" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:gravity="center"
                android:text="Nowa wiadomość" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:orientation="vertical">

            <Switch
                android:id="@+id/graphic_nottification"
                android:layout_width="50dp"
                android:layout_height="40dp"
                android:onClick="RegisterChangeOfPushSwitch" />

            <Switch
                android:id="@+id/mark_nottification"
                android:layout_width="50dp"
                android:layout_height="40dp"
                android:onClick="RegisterChangeOfPushSwitch" />

            <Switch
                android:id="@+id/payment_nottification"
                android:layout_width="50dp"
                android:layout_height="40dp"
                android:onClick="RegisterChangeOfPushSwitch" />

            <Switch
                android:id="@+id/message_nottification"
                android:layout_width="50dp"
                android:layout_height="40dp"
                android:onClick="RegisterChangeOfPushSwitch" />
        </LinearLayout>


    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="5dp"
        android:text="Zabezpieczenie"
        android:textAlignment="center"
        android:textColor="#111111"
        android:textSize="18dp"
        android:textStyle="bold" />

    <View
        android:layout_width="80dp"
        android:layout_height="2dp"
        android:background="#111111"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"></View>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:orientation="horizontal"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        android:weightSum="5">


        <ImageView
            android:id="@+id/security_biometric"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_weight="1"
            android:background="@drawable/black_border"
            android:padding="10dp"
            android:src="@drawable/ic_fingerprint_black_"/>
        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/security_disable"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_weight="1"
            android:background="@drawable/black_border"
            android:padding="10dp"
            android:src="@drawable/ic_no_screen_security"/>

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/security_pin"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_weight="1"
            android:background="@drawable/black_border"
            android:padding="10dp"
            android:src="@drawable/ic_fiber_pin_black" />


    </LinearLayout>

</LinearLayout>

И он фрагментXML (та же ситуация, что и выше. Часть этого - FrameLayout)

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded_corners_small_biometric"
    android:layout_gravity="bottom"
    android:paddingTop="15dp"

    android:orientation="vertical">
<ImageView
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:src="@drawable/ic_fingerprint_black_"
    android:layout_gravity="center"
    android:id="@+id/finger_print_icon"
    android:background="#ffffff"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAlignment="center"
    android:layout_marginTop="15dp"
    android:textSize="15dp"
    android:text="Zidentyfikuj się"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cancel_auth"
        android:text="Anuluj"
        android:textAlignment="center"
        android:textColor="#0055A5"
        android:textStyle="bold"
        android:textSize="22dp"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"/>
</LinearLayout>

Вот так это выглядит. Когда я устанавливаю флаг NOT_TOUCHABLE, пользователь не может отменить авторизацию (нажмите «Anuluj») screen_with_autohrization

@ EDIT2

Спасибо вам @ РСИТ _

Я сделал биометрическую подсказку как диалог активности. И чтобы получить callbak от FingerPrintAPI, я создал интерфейс 'FingerPrintCallback'. Реализовал его в FirstConfigActivity и возвратил в BiometricDialog с контекстом активности:

Большое спасибо, ребята, за помощь :)

Ответы [ 3 ]

0 голосов
/ 06 ноября 2019

Попробуйте сделать FrameLayout кликабельным, используя android:clickable="true"

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_corners_small_biometric"
        android:layout_gravity="bottom"
        android:paddingTop="15dp"
        android:orientation="vertical">
        <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="@drawable/ic_fingerprint_black_"
            android:layout_gravity="center"
            android:id="@+id/finger_print_icon"
            android:background="#ffffff"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:layout_marginTop="15dp"
            android:textSize="15dp"
            android:text="Zidentyfikuj się"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cancel_auth"
            android:text="Anuluj"
            android:textAlignment="center"
            android:textColor="#0055A5"
            android:textStyle="bold"
            android:textSize="22dp"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="20dp"/>
    </LinearLayout>

</FrameLayout>
0 голосов
/ 06 ноября 2019

Yes. I want too make the fragment touchable while activity is not touchable

Для этого вы можете использовать событие прикосновения во фрагменте, возвращая true in onTouch. Например,

SmallBiometricAuthenticate : View.OnTouchListener {
    override fun onTouch(v: View, event:  MotionEvent) {
        return true
    }
}

И добавьте OnTouchListener к корневому фрагменту view.

0 голосов
/ 06 ноября 2019

Просто используйте Activity как диалоговое окно.

Пошагово:

  1. Создание действия с биообнаружением и в манифесте:

    <activity android:name=".BioActivity" android:theme="@android:style/Theme.Dialog"/>
    
  2. В созданном XML-упражнении (BioActivity.xml) добавьте тег android:excludeFromRecents="true" в корневой каталог (LinearLayout или другой):

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".BioActivity"
        android:excludeFromRecents="true"
        >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    
  3. В файле класса Javaиз вашего диалогового действия поместите этот код в метод onCreate() после setContentView();

    public class BioActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.bio_activity);
    
            this.setFinishOnTouchOutside(false);
        }
    }
    
  4. запустить созданное диалоговое действие, используя intent и startActivity () из основного действия;

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...