@@ -0,0 +1,4240 @@
+/*%0A * Copyright (c) 2017 Mobvoi Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage ticwear.design.app;%0A%0Aimport android.content.Context;%0Aimport android.content.DialogInterface;%0Aimport android.content.DialogInterface.OnDismissListener;%0Aimport android.support.annotation.NonNull;%0Aimport android.support.annotation.Nullable;%0A%0A/**%0A * Create some common ticwear dialogs.%0A *%0A * Created by tankery on 08/03/2017.%0A */%0A%0Apublic class TicwearDialogs %7B%0A%0A    @NonNull%0A    public static AlertDialog permissionRequestDialog(@NonNull Context context,%0A                                                      @Nullable String message,%0A                                                      @Nullable final Runnable positiveAction) %7B%0A        return permissionRequestDialog(context, message, positiveAction, null);%0A    %7D%0A%0A    @NonNull%0A    public static AlertDialog permissionRequestDialog(@NonNull Context context,%0A                                                      @Nullable String message,%0A                                                      @Nullable final Runnable positiveAction,%0A                                                      @Nullable final Runnable negativeAction) %7B%0A        return permissionRequestDialog(context, message, positiveAction, negativeAction, null);%0A    %7D%0A%0A    @NonNull%0A    public static AlertDialog permissionRequestDialog(@NonNull Context context,%0A                                                      @Nullable String message,%0A                                                      @Nullable final Runnable positiveAction,%0A                                                      @Nullable final Runnable negativeAction,%0A                                                      @Nullable final Runnable cancelAction) %7B%0A        class ActionStatus %7B%0A            boolean hasAction = false;%0A        %7D%0A%0A        final ActionStatus actionStatus = new ActionStatus();%0A%0A        return new AlertDialog.Builder(context)%0A                .setMessage(message)%0A                .setPositiveButtonIcon(ticwear.design.R.drawable.tic_ic_btn_ok,%0A                        new DialogInterface.OnClickListener() %7B%0A                            @Override%0A                            public void onClick(DialogInterface dialog, int which) %7B%0A                                actionStatus.hasAction = true;%0A                                dialog.dismiss();%0A                                if (positiveAction != null) %7B%0A                                    positiveAction.run();%0A                                %7D%0A                            %7D%0A                        %7D)%0A                .setNegativeButtonIcon(ticwear.design.R.drawable.tic_ic_btn_cancel,%0A                        new DialogInterface.OnClickListener() %7B%0A                            @Override%0A                            public void onClick(DialogInterface dialog, int which) %7B%0A                                actionStatus.hasAction = true;%0A                                dialog.dismiss();%0A                                if (negativeAction != null) %7B%0A                                    negativeAction.run();%0A                                %7D%0A                            %7D%0A                        %7D)%0A                .setOnDismissListener(new OnDismissListener() %7B%0A                    @Override%0A                    public void onDismiss(DialogInterface dialogInterface) %7B%0A                        // If dismiss with no user action, we know the user has cancel the dialog.%0A                        if (!actionStatus.hasAction && cancelAction != null) %7B%0A                            cancelAction.run();%0A                        %7D%0A                    %7D%0A                %7D)%0A                .setDelayConfirmAction(DialogInterface.BUTTON_POSITIVE, 5000)%0A                .create();%0A    %7D%0A%0A%7D%0A

Unify Permission request rationale dialog.