1 /* ownCloud Android client application 
   2  *   Copyright (C) 2012-2013 ownCloud Inc. 
   4  *   This program is free software: you can redistribute it and/or modify 
   5  *   it under the terms of the GNU General Public License version 2, 
   6  *   as published by the Free Software Foundation. 
   8  *   This program is distributed in the hope that it will be useful, 
   9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
  10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  11  *   GNU General Public License for more details. 
  13  *   You should have received a copy of the GNU General Public License 
  14  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  18 package com
.owncloud
.android
.ui
.dialog
; 
  20 import android
.app
.Dialog
; 
  21 import android
.app
.ProgressDialog
; 
  22 import android
.content
.DialogInterface
; 
  23 import android
.content
.DialogInterface
.OnKeyListener
; 
  24 import android
.os
.Bundle
; 
  25 import android
.view
.KeyEvent
; 
  27 import com
.actionbarsherlock
.app
.SherlockDialogFragment
; 
  28 import com
.owncloud
.android
.R
; 
  30 public class IndeterminateProgressDialog 
extends SherlockDialogFragment 
{ 
  32     private static final String ARG_MESSAGE_ID 
= IndeterminateProgressDialog
.class.getCanonicalName() + ".ARG_MESSAGE_ID"; 
  33     private static final String ARG_CANCELABLE 
= IndeterminateProgressDialog
.class.getCanonicalName() + ".ARG_CANCELABLE"; 
  37      * Public factory method to get dialog instances. 
  39      * @param messageId     Resource id for a message to show in the dialog. 
  40      * @param cancelable    If 'true', the dialog can be cancelled by the user input (BACK button, touch outside...) 
  41      * @return              New dialog instance, ready to show. 
  43     public static IndeterminateProgressDialog 
newInstance(int messageId
, boolean cancelable
) { 
  44         IndeterminateProgressDialog fragment 
= new IndeterminateProgressDialog(); 
  45         Bundle args 
= new Bundle(); 
  46         args
.putInt(ARG_MESSAGE_ID
, messageId
); 
  47         args
.putBoolean(ARG_CANCELABLE
, cancelable
); 
  48         fragment
.setArguments(args
); 
  57     public Dialog 
onCreateDialog(Bundle savedInstanceState
) { 
  58         /// create indeterminate progress dialog 
  59         final ProgressDialog dialog 
= new ProgressDialog(getActivity()); 
  60         dialog
.setIndeterminate(true
); 
  63         int messageId 
= getArguments().getInt(ARG_MESSAGE_ID
, R
.string
.placeholder_sentence
); 
  64         dialog
.setMessage(getString(messageId
)); 
  66         /// set cancellation behavior 
  67         boolean cancelable 
= getArguments().getBoolean(ARG_CANCELABLE
, false
); 
  69             dialog
.setCancelable(false
); 
  70             // disable the back button 
  71             OnKeyListener keyListener 
= new OnKeyListener() { 
  73                 public boolean onKey(DialogInterface dialog
, int keyCode
, 
  76                     if( keyCode 
== KeyEvent
.KEYCODE_BACK
){                   
  83             dialog
.setOnKeyListener(keyListener
);