]>
iEval git - fonbot.git/blob - ro/ieval/fonbot/FonBotPhoneStateListener.java
1 package ro
.ieval
.fonbot
;
3 import static ro
.ieval
.fonbot
.R
.string
.phone_status_idle
;
4 import static ro
.ieval
.fonbot
.R
.string
.phone_status_offhook
;
5 import static ro
.ieval
.fonbot
.R
.string
.phone_status_ringing
;
6 import static ro
.ieval
.fonbot
.Utils
.toNonNull
;
8 import org
.eclipse
.jdt
.annotation
.Nullable
;
10 import ro
.ieval
.fonbot
.Utils
.MessageType
;
11 import android
.content
.Context
;
12 import android
.telephony
.PhoneStateListener
;
13 import android
.telephony
.TelephonyManager
;
16 * Copyright © 2013 Marius Gavrilescu
18 * This file is part of FonBot.
20 * FonBot is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * FonBot is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with FonBot. If not, see <http://www.gnu.org/licenses/>.
35 * PhoneStateListener that sends {@link MessageType#PHONE_STATE} notifications.
37 * @author Marius Gavrilescu <marius@ieval.ro>
39 final class FonBotPhoneStateListener
extends PhoneStateListener
{
41 * Context instance used in this class.
43 private final Context context
;
46 * Construct a FonBotPhoneStateListener with a given context.
48 * @param context Context instance
50 public FonBotPhoneStateListener(final Context context
) {
56 public void onCallStateChanged(final int state
, @Nullable final String incomingNumber
) {
57 @SuppressWarnings("hiding")
58 final Context context
=this.context
;
63 case TelephonyManager
.CALL_STATE_IDLE
:
64 Utils
.sendMessage(context
, toNonNull(MessageType
.PHONE_STATE
), phone_status_idle
);
66 case TelephonyManager
.CALL_STATE_RINGING
:
67 if(incomingNumber
==null)
69 final String name
=Utils
.callerId(context
, incomingNumber
);
71 Utils
.sendMessage(context
, toNonNull(MessageType
.PHONE_STATE
), phone_status_ringing
, incomingNumber
);
73 Utils
.sendMessage(context
, toNonNull(MessageType
.PHONE_STATE
),
74 phone_status_ringing
, incomingNumber
+ " ("+name
+")");
76 case TelephonyManager
.CALL_STATE_OFFHOOK
:
77 Utils
.sendMessage(context
, toNonNull(MessageType
.PHONE_STATE
), phone_status_offhook
);
This page took 0.049057 seconds and 4 git commands to generate.