Phone Goggles: System settings
Phone Goggles provides to the end user the ability to filter its
outgoing communications and avoid any unwilling call or SMS to be
sent. Several settings can be configured: the way the user will
be informed that his communication has been blocked (and whether
or not is allowed to unlock the blocking), the period during which
the communications will be filtered, the type of phones that will
be filtered (Work, Mobile, Other)...
Latest commit:
- Complete API that allows external APK to use the PhoneGoggles
API without loosing the compatibility with non-CyanogenMod ROMs.
- Better readability of the code (thanks to Volodymyr Lisivka) as
Uthe I creation and the logic have been separated into several
specialized methods.
- The PhoneGoggles utility class now offers a single method
'processCommunication' that will manage the entire process.
- There are no traces of the former name (Drunk Mode) of the
feature in the source code, I hope this will avoid any trouble
related to the appearing lack of professionalism of the feature.
- The user is now able to choose the kind of phone types he wants
to filter (Work, Mobile, Other)
- Corrections thanks to Evan Charlton (copyright added to the new
classes, arrays translations are now in string.xml, no more
useless comments and the typo on 'translatable="falses"' is
fixed)
Using the PhoneGoggles API
Here is how a developer can use Phone Goggles in his APK without breaking the
compatibility with non-CyanogenMod ROMs:
1) Add the following Intent Filter to the Activity that will call the Phone
Goggles API, that way, the user will be able to configure it in the
Settings.
<intent-filter>
<action android:name="android.intent.action.PHONE_GOGGLES_COMMUNICATION"/>
</intent-filter>
2) In your Activity or in an Util class of your APK (in the case where you
use Phone Goggles in several Activities in the same APK), add these few
lines. They will allow you to check if the Phone Goggles API is available.
private static Method phoneGoggles;
static {
try {
Class phoneGogglesClass = Class.forName("android.util.PhoneGoggles");
phoneGoggles = phoneGogglesClass.getMethod("processCommunication",
new Class[] {Context.class, int.class, String[].class,
Runnable.class, Runnable.class, int.class, int.class,
int.class, int.class, int.class, int.class});
} catch (ClassNotFoundException e) {
} catch (SecurityException e) {
} catch (NoSuchMethodException e) {
}
}
3) When you need to create a communication, simply do it like that:
final Runnable onRun = new Runnable() {
public void run() {
// Perform the communication
}
};
final Runnable onCancel = new Runnable() {
public void run() {
// Abandon the communication before even starting it
}
};
if (phoneGoggles != null) {
try {
phoneGoggles.invoke(null, this,
1, // 1 for phone numbers
// 2 for email addresses
// 0 otherwise
numbers, // a String[] containing the phone numbers OR the
// email addresses of the contacts
onRun, onCancel,
R.string.dialog_phone_goggles_title, // Values to be
R.string.dialog_phone_goggles_title_unlocked, // defined in the
R.string.dialog_phone_goggles_content, // string.xml files
R.string.dialog_phone_goggles_unauthorized,
R.string.dialog_phone_goggles_ok,
R.string.dialog_phone_goggles_cancel);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
// If the Phone Goggles API doesn't exist
} else {
onRun.run();
}
Change-Id: Ib62808302c6a27e19d600567e9bf854d15732945
Loading
Please register or sign in to comment