alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 1 | /* |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 2 | * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 32 | package com.savoirfairelinux.sflphone.fragments; |
| 33 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 34 | import android.animation.Animator; |
| 35 | import android.animation.AnimatorListenerAdapter; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 36 | import android.app.Activity; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 37 | import android.app.Fragment; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 38 | import android.content.Context; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 39 | import android.os.Build; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 40 | import android.os.Bundle; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 41 | import android.view.LayoutInflater; |
| 42 | import android.view.View; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 43 | import android.view.View.OnClickListener; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 44 | import android.view.ViewGroup; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 45 | import android.view.inputmethod.EditorInfo; |
| 46 | import android.view.inputmethod.InputMethodManager; |
| 47 | import android.widget.Button; |
| 48 | import android.widget.ImageButton; |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 49 | import android.widget.Toast; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 50 | |
| 51 | import com.savoirfairelinux.sflphone.R; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 52 | import com.savoirfairelinux.sflphone.service.ISipService; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 53 | import com.savoirfairelinux.sflphone.views.ClearableEditText; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 54 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 55 | public class DialingFragment extends Fragment { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 56 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 57 | private static final String TAG = DialingFragment.class.getSimpleName(); |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 58 | public static final String ARG_SECTION_NUMBER = "section_number"; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 59 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 60 | ClearableEditText textField; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 61 | // private AccountSelectionSpinner mAccountSelectionSpinner; |
| 62 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 63 | // AccountSelectionAdapter mAdapter; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 64 | private Callbacks mCallbacks = sDummyCallbacks; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 65 | // private Spinner spinnerAccounts; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 69 | */ |
| 70 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 71 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 72 | public void onCallDialed(String to) { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public ISipService getService() { |
| 77 | // TODO Auto-generated method stub |
| 78 | return null; |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | /** |
| 83 | * The Activity calling this fragment has to implement this interface |
| 84 | * |
| 85 | */ |
| 86 | public interface Callbacks { |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 87 | void onCallDialed(String account); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 88 | |
| 89 | public ISipService getService(); |
| 90 | |
| 91 | } |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 92 | |
| 93 | @Override |
| 94 | public void onAttach(Activity activity) { |
| 95 | super.onAttach(activity); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 96 | |
| 97 | if (!(activity instanceof Callbacks)) { |
| 98 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 99 | } |
| 100 | |
| 101 | mCallbacks = (Callbacks) activity; |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 102 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void onDetach() { |
| 107 | super.onDetach(); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 108 | mCallbacks = sDummyCallbacks; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void onCreate(Bundle savedInstanceState) { |
| 113 | super.onCreate(savedInstanceState); |
| 114 | // mAdapter = new HistoryAdapter(getActivity(),new ArrayList<HashMap<String, String>>()); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { |
| 119 | View inflatedView = inflater.inflate(R.layout.frag_dialing, parent, false); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 120 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 121 | textField = (ClearableEditText) inflatedView.findViewById(R.id.textField); |
| 122 | ((ImageButton) inflatedView.findViewById(R.id.buttonCall)).setOnClickListener(new OnClickListener() { |
| 123 | @Override |
| 124 | public void onClick(View v) { |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 125 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 126 | String to = textField.getText().toString(); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 127 | if (to.contentEquals("")) { |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 128 | textField.setError(getString(R.string.error_no_number_dialed)); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 129 | } else { |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 130 | mCallbacks.onCallDialed(to); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 131 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 132 | } |
| 133 | }); |
| 134 | |
| 135 | ((Button) inflatedView.findViewById(R.id.alphabetic_keyboard)).setOnClickListener(new OnClickListener() { |
| 136 | |
| 137 | @Override |
| 138 | public void onClick(View v) { |
| 139 | textField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 140 | InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 141 | lManager.showSoftInput(textField.getEdit_text(), 0); |
| 142 | } |
| 143 | }); |
| 144 | |
| 145 | ((Button) inflatedView.findViewById(R.id.numeric_keyboard)).setOnClickListener(new OnClickListener() { |
| 146 | |
| 147 | @Override |
| 148 | public void onClick(View v) { |
| 149 | textField.setInputType(EditorInfo.TYPE_CLASS_NUMBER); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 150 | InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 151 | lManager.showSoftInput(textField.getEdit_text(), 0); |
| 152 | } |
| 153 | }); |
| 154 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 155 | return inflatedView; |
| 156 | } |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 157 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 158 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 159 | @Override |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 160 | public void onResume() { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 161 | super.onResume(); |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public void onStart() { |
| 166 | super.onStart(); |
| 167 | |
| 168 | } |
| 169 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 170 | } |