Home | History | Annotate | Download | only in browse
      1 /*
      2  * Copyright (C) 2012 Google Inc.
      3  * Licensed to The Android Open Source Project.
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.mail.browse;
     19 
     20 import android.app.AlertDialog;
     21 import android.app.Dialog;
     22 import android.app.DialogFragment;
     23 import android.content.DialogInterface;
     24 import android.content.Intent;
     25 import android.os.Bundle;
     26 import android.provider.Settings;
     27 
     28 import com.android.mail.R;
     29 
     30 /**
     31  * Implements a {@link DialogFragment} that uses an internal {@link AlertDialog}
     32  * to show information when there is a {@link UIProvider.LastSyncResult.STORAGE_ERROR}.
     33  */
     34 public class SyncErrorDialogFragment extends DialogFragment {
     35     // Public no-args constructor needed for fragment re-instantiation
     36     public SyncErrorDialogFragment() {}
     37 
     38     public static SyncErrorDialogFragment newInstance() {
     39         SyncErrorDialogFragment frag = new SyncErrorDialogFragment();
     40         return frag;
     41     }
     42 
     43     @Override
     44     public Dialog onCreateDialog(Bundle savedInstanceState) {
     45         return new AlertDialog.Builder(getActivity())
     46                 .setTitle(R.string.sync_error)
     47                 .setMessage(R.string.sync_error_message)
     48                 .setPositiveButton(R.string.ok,
     49                     new DialogInterface.OnClickListener() {
     50                         @Override
     51                         public void onClick(DialogInterface dialog, int whichButton) {
     52                             dialog.dismiss();
     53                         }
     54                     }
     55                 )
     56                 .setNegativeButton(R.string.storage,
     57                     new DialogInterface.OnClickListener() {
     58                         @Override
     59                         public void onClick(DialogInterface dialog, int whichButton) {
     60                             Intent intent = new Intent(
     61                                     Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
     62                             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
     63                             startActivity(intent);
     64                             dialog.dismiss();
     65                         }
     66                     }
     67                 )
     68                 .create();
     69     }
     70 }
     71