Skip to content

Instantly share code, notes, and snippets.

@pbednarz
Created January 8, 2017 19:20
Show Gist options
  • Save pbednarz/99fbd2204dbe7ca8279f2241daa24a42 to your computer and use it in GitHub Desktop.
Save pbednarz/99fbd2204dbe7ca8279f2241daa24a42 to your computer and use it in GitHub Desktop.

Revisions

  1. pbednarz created this gist Jan 8, 2017.
    104 changes: 104 additions & 0 deletions AboutUtils.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,104 @@
    package pl.pbednarz.myapplication;


    import android.app.Dialog;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.support.annotation.NonNull;
    import android.support.annotation.Nullable;
    import android.support.v4.app.DialogFragment;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentTransaction;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatDialogFragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;

    /**
    * This is a set of helper methods for showing various "about" information in the app.
    */
    public class AboutUtils {

    public static void showShieldDialog(FragmentActivity activity) {
    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("shield_dialog");
    if (prev != null) {
    ft.remove(prev);
    }
    ft.addToBackStack(null);

    new ShieldDialog().show(ft, "shield_dialog");
    }

    public static void showCustomDialog(FragmentActivity activity) {
    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("custom_dialog");
    if (prev != null) {
    ft.remove(prev);
    }
    ft.addToBackStack(null);
    new CustomDialogFragment().show(ft, "custom_dialog");
    }

    public static class ShieldDialog extends AppCompatDialogFragment {

    public ShieldDialog() {
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity(), R.style.MyDialogTheme)
    .setTitle(R.string.use_fingerprint_to_authenticate_title)
    .setView(R.layout.dialog_content)
    .setPositiveButton(R.string.ok,
    new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
    dialog.dismiss();
    }
    }
    )
    .create();
    }
    }

    public static class CustomDialogFragment extends AppCompatDialogFragment {

    public CustomDialogFragment() {
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialogTheme2);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    getDialog().setTitle(R.string.use_fingerprint_to_authenticate_title);
    return inflater.inflate(R.layout.dialog_content2, container);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    view.findViewById(android.R.id.button1).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    dismiss();
    }
    });
    view.findViewById(android.R.id.button2).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    dismiss();
    }
    });
    }
    }
    }
    70 changes: 70 additions & 0 deletions dialog_content.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    <?xml version="1.0" encoding="utf-8"?>
    <!--
    ~ Copyright (C) 2015 The Android Open Source Project
    ~
    ~ Licensed under the Apache License, Version 2.0 (the "License");
    ~ you may not use this file except in compliance with the License.
    ~ You may obtain a copy of the License at
    ~
    ~ http://www.apache.org/licenses/LICENSE-2.0
    ~
    ~ Unless required by applicable law or agreed to in writing, software
    ~ distributed under the License is distributed on an "AS IS" BASIS,
    ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    ~ See the License for the specific language governing permissions and
    ~ limitations under the License
    -->
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fingerprint_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="24dp"
    android:paddingLeft="24dp"
    android:paddingRight="24dp"
    android:paddingTop="20dp">

    <TextView
    android:id="@+id/fingerprint_description"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:drawableTop="@drawable/android_robot"
    android:text="@string/fingerprint_description"
    android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
    android:textColor="?android:attr/textColorSecondary"/>


    <ImageView
    android:id="@+id/fingerprint_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/fingerprint_description"
    android:layout_marginTop="20dp"
    android:src="@drawable/ic_fp_40px"/>

    <TextView
    android:id="@+id/fingerprint_status"
    style="@style/TextAppearance.AppCompat.Body1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/fingerprint_icon"
    android:layout_alignTop="@+id/fingerprint_icon"
    android:layout_marginLeft="16dp"
    android:layout_marginStart="16dp"
    android:layout_toEndOf="@+id/fingerprint_icon"
    android:layout_toRightOf="@+id/fingerprint_icon"
    android:gravity="center_vertical"
    android:text="@string/fingerprint_hint"
    android:textColor="@color/hint_color"/>

    <Button
    android:text="agree"
    android:id="@+id/second_dialog_button"
    style="?attr/buttonBarNegativeButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
    </RelativeLayout>
    88 changes: 88 additions & 0 deletions dialog_content2.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    <?xml version="1.0" encoding="utf-8"?>
    <!--
    ~ Copyright (C) 2015 The Android Open Source Project
    ~
    ~ Licensed under the Apache License, Version 2.0 (the "License");
    ~ you may not use this file except in compliance with the License.
    ~ You may obtain a copy of the License at
    ~
    ~ http://www.apache.org/licenses/LICENSE-2.0
    ~
    ~ Unless required by applicable law or agreed to in writing, software
    ~ distributed under the License is distributed on an "AS IS" BASIS,
    ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    ~ See the License for the specific language governing permissions and
    ~ limitations under the License
    -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
    android:id="@+id/fingerprint_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingBottom="8dp"
    android:paddingLeft="24dp"
    android:paddingRight="24dp"
    android:paddingTop="20dp">

    <TextView
    android:id="@+id/fingerprint_description"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/fingerprint_description"
    android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
    android:textColor="?attr/colorAccent"/>

    <TextView
    android:id="@+id/fingerprint_status"
    style="@style/TextAppearance.AppCompat.Body1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:drawableLeft="@drawable/ic_fp_40px"
    android:drawablePadding="16dp"
    android:gravity="center_vertical"
    android:text="@string/fingerprint_hint"
    android:textColor="@color/hint_color"/>
    </LinearLayout>

    <android.support.v7.widget.ButtonBarLayout
    style="?attr/buttonBarStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom"
    android:layoutDirection="locale"
    android:orientation="horizontal"
    android:paddingBottom="4dp"
    android:paddingLeft="12dp"
    android:paddingRight="12dp"
    android:paddingTop="4dp"
    app:allowStacking="@bool/abc_allow_stacked_button_bar">

    <android.support.v4.widget.Space
    android:id="@+id/spacer"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:visibility="invisible"/>

    <Button
    android:id="@android:id/button2"
    style="?attr/buttonBarNegativeButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Cancel"/>

    <Button
    android:id="@android:id/button1"
    style="?attr/buttonBarPositiveButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ok"/>
    </android.support.v7.widget.ButtonBarLayout>
    </LinearLayout>