blob: dedf36f9f034fd36b376e9401a8ee509f37ada08 [file] [log] [blame]
alision11e8e162013-05-28 10:33:14 -04001/*
alision2ec64f92013-06-17 17:28:58 -04002 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
alision11e8e162013-05-28 10:33:14 -04003 *
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
alisiond295ec22013-05-17 10:12:13 -040032package com.savoirfairelinux.sflphone.fragments;
33
34import android.app.Activity;
alisiond295ec22013-05-17 10:12:13 -040035import android.app.Fragment;
alision9f7a6ec2013-05-24 16:26:26 -040036import android.content.Context;
37import android.os.Bundle;
alisiond295ec22013-05-17 10:12:13 -040038import android.view.LayoutInflater;
39import android.view.View;
alision9f7a6ec2013-05-24 16:26:26 -040040import android.view.View.OnClickListener;
alisiond295ec22013-05-17 10:12:13 -040041import android.view.ViewGroup;
alision9f7a6ec2013-05-24 16:26:26 -040042import android.view.inputmethod.EditorInfo;
43import android.view.inputmethod.InputMethodManager;
44import android.widget.Button;
45import android.widget.ImageButton;
alision58356b72013-06-03 17:13:36 -040046import android.widget.Toast;
alisiond295ec22013-05-17 10:12:13 -040047
48import com.savoirfairelinux.sflphone.R;
alisiond295ec22013-05-17 10:12:13 -040049import com.savoirfairelinux.sflphone.service.ISipService;
alision9f7a6ec2013-05-24 16:26:26 -040050import com.savoirfairelinux.sflphone.views.ClearableEditText;
alisiond295ec22013-05-17 10:12:13 -040051
alision907bde72013-06-20 14:40:37 -040052public class DialingFragment extends Fragment {
alision9f7a6ec2013-05-24 16:26:26 -040053
alision1005ba12013-06-19 13:52:44 -040054 private static final String TAG = DialingFragment.class.getSimpleName();
alisiond295ec22013-05-17 10:12:13 -040055 public static final String ARG_SECTION_NUMBER = "section_number";
alision907bde72013-06-20 14:40:37 -040056
alisiond295ec22013-05-17 10:12:13 -040057
alision9f7a6ec2013-05-24 16:26:26 -040058 ClearableEditText textField;
alision11e8e162013-05-28 10:33:14 -040059 // private AccountSelectionSpinner mAccountSelectionSpinner;
60
alision907bde72013-06-20 14:40:37 -040061// AccountSelectionAdapter mAdapter;
alision9f7a6ec2013-05-24 16:26:26 -040062 private Callbacks mCallbacks = sDummyCallbacks;
alision907bde72013-06-20 14:40:37 -040063// private Spinner spinnerAccounts;
alision55c36cb2013-06-14 14:57:38 -040064
alision2ec64f92013-06-17 17:28:58 -040065
alision9f7a6ec2013-05-24 16:26:26 -040066
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
alision907bde72013-06-20 14:40:37 -040072 public void onCallDialed(String to) {
alision9f7a6ec2013-05-24 16:26:26 -040073 }
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 {
alision907bde72013-06-20 14:40:37 -040087 void onCallDialed(String account);
alision9f7a6ec2013-05-24 16:26:26 -040088
89 public ISipService getService();
90
91 }
alisiond295ec22013-05-17 10:12:13 -040092
93 @Override
94 public void onAttach(Activity activity) {
95 super.onAttach(activity);
alision9f7a6ec2013-05-24 16:26:26 -040096
97 if (!(activity instanceof Callbacks)) {
98 throw new IllegalStateException("Activity must implement fragment's callbacks.");
99 }
100
101 mCallbacks = (Callbacks) activity;
alision58356b72013-06-03 17:13:36 -0400102
alisiond295ec22013-05-17 10:12:13 -0400103 }
104
105 @Override
106 public void onDetach() {
107 super.onDetach();
alision58356b72013-06-03 17:13:36 -0400108 mCallbacks = sDummyCallbacks;
alisiond295ec22013-05-17 10:12:13 -0400109 }
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);
alision58356b72013-06-03 17:13:36 -0400120
alision907bde72013-06-20 14:40:37 -0400121
alision9f7a6ec2013-05-24 16:26:26 -0400122
123 textField = (ClearableEditText) inflatedView.findViewById(R.id.textField);
124 ((ImageButton) inflatedView.findViewById(R.id.buttonCall)).setOnClickListener(new OnClickListener() {
125 @Override
126 public void onClick(View v) {
alision11e8e162013-05-28 10:33:14 -0400127
alision84813a12013-05-27 17:40:39 -0400128 String to = textField.getText().toString();
alision58356b72013-06-03 17:13:36 -0400129 if (to.contentEquals("")) {
130 Toast.makeText(getActivity(), "Enter a number", Toast.LENGTH_LONG).show();
131 } else {
alision907bde72013-06-20 14:40:37 -0400132 mCallbacks.onCallDialed(to);
alision58356b72013-06-03 17:13:36 -0400133 }
alision9f7a6ec2013-05-24 16:26:26 -0400134 }
135 });
136
137 ((Button) inflatedView.findViewById(R.id.alphabetic_keyboard)).setOnClickListener(new OnClickListener() {
138
139 @Override
140 public void onClick(View v) {
141 textField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
alision11e8e162013-05-28 10:33:14 -0400142 InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
alision9f7a6ec2013-05-24 16:26:26 -0400143 lManager.showSoftInput(textField.getEdit_text(), 0);
144 }
145 });
146
147 ((Button) inflatedView.findViewById(R.id.numeric_keyboard)).setOnClickListener(new OnClickListener() {
148
149 @Override
150 public void onClick(View v) {
151 textField.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
alision11e8e162013-05-28 10:33:14 -0400152 InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
alision9f7a6ec2013-05-24 16:26:26 -0400153 lManager.showSoftInput(textField.getEdit_text(), 0);
154 }
155 });
156
alision85704182013-05-29 15:23:03 -0400157 return inflatedView;
158 }
alision58356b72013-06-03 17:13:36 -0400159
alision85704182013-05-29 15:23:03 -0400160 @Override
alision58356b72013-06-03 17:13:36 -0400161 public void onResume() {
alision85704182013-05-29 15:23:03 -0400162 super.onResume();
alisiond295ec22013-05-17 10:12:13 -0400163 }
164
165 @Override
166 public void onStart() {
167 super.onStart();
168
169 }
170
alisiond295ec22013-05-17 10:12:13 -0400171}