]> iEval git - fonbot.git/blame - src/ro/ieval/fonbot/DynamicEventReceiver.java
Add SH and ROOTSH commands
[fonbot.git] / src / ro / ieval / fonbot / DynamicEventReceiver.java
CommitLineData
8dfb76c9
MG
1package ro.ieval.fonbot;
2
3import static ro.ieval.fonbot.R.string.*;
4
5import static ro.ieval.fonbot.Utils.toNonNull;
6
7import org.eclipse.jdt.annotation.Nullable;
8
9import ro.ieval.fonbot.Utils.MessageType;
10import android.content.BroadcastReceiver;
11import android.content.Context;
12import android.content.Intent;
13import android.preference.PreferenceManager;
14
15/*
16 * Copyright © 2013 Marius Gavrilescu
17 *
18 * This file is part of FonBot.
19 *
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.
24 *
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.
29 *
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/>.
32 */
33
34/**
35 * A BroadcastReceiver that receives "dynamic" events like {@link Intent#ACTION_SCREEN_ON ACTION_SCREEN_ON}, {@link Intent#ACTION_BATTERY_CHANGED ACTION_BATTERY_CHANGED} and {@link Intent#ACTION_HEADSET_PLUG}
36 *
37 * @author Marius Gavrilescu <marius@ieval.ro>
38 */
39public final class DynamicEventReceiver extends BroadcastReceiver {
40
41 @Override
42 public void onReceive(final @Nullable Context context, final @Nullable Intent intent) {
43 if(context==null || intent==null || isInitialStickyBroadcast())
44 return;
45
46 final String action=intent.getAction();
47
ca40a5cc 48 if(action.equals(Intent.ACTION_BATTERY_CHANGED))
8dfb76c9
MG
49 Heavy.describeBatteryLevel(context, null, toNonNull(MessageType.BATTERY_CHANGED));
50 else if(action.equals(Intent.ACTION_HEADSET_PLUG)){
51 final int state=intent.getIntExtra("state", 0);
52 final String name=intent.getStringExtra("name");
53 final int microphone=intent.getIntExtra("microphone", 0);
54
55 final StringBuilder builder=new StringBuilder(100);
56 if(microphone==1)
57 builder.append(toNonNull(context.getString(headset_with_microphone)));
58 else
59 builder.append(toNonNull(context.getString(headset_without_microphone)));
60 builder.append(' ');
61 builder.append(name);
62 builder.append(' ');
63 if(state==1)
64 builder.append(toNonNull(context.getString(plugged_in)));
65 else
66 builder.append(toNonNull(context.getString(unplugged)));
67 builder.append(". ");
68
69 Utils.sendMessage(context,
70 toNonNull(MessageType.HEADSET),
71 toNonNull(builder.toString()));
72 }
73 }
74
75}
This page took 0.038304 seconds and 4 git commands to generate.