use of fr.neamar.kiss.DataHandler in project KISS by Neamar.
the class UninstallShortcutHandler method onReceive.
@Override
public void onReceive(Context context, Intent data) {
DataHandler dh = KissApplication.getDataHandler(context);
ShortcutsProvider sp = dh.getShortcutsProvider();
if (sp == null)
return;
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Log.d("onReceive", "Uninstall shortcut " + name);
ShortcutsPojo pojo = (ShortcutsPojo) sp.findByName(name);
if (pojo == null) {
Log.d("onReceive", "Shortcut " + name + " not found");
return;
}
dh.removeShortcut(pojo);
}
use of fr.neamar.kiss.DataHandler in project KISS by Neamar.
the class IncomingSmsHandler method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
// Only handle SMS received
if (!intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
return;
}
// Stop if contacts are not enabled
DataHandler dataHandler = KissApplication.getDataHandler(context);
ContactsProvider contactsProvider = dataHandler.getContactsProvider();
if (contactsProvider == null) {
// Contacts have been disabled from settings
return;
}
// Get the SMS message passed in, if any
Bundle bundle = intent.getExtras();
if (bundle == null) {
return;
}
// Retrieve the SMS message received.
// Since we're not interested in content, we can safely discard
// all records but the first one
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus == null) {
return;
}
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[0]);
// Now, retrieve the contact by its lookup key on our contactsProvider
ContactsPojo contactPojo = contactsProvider.findByPhone(msg.getOriginatingAddress());
if (contactPojo != null) {
// We have a match!
dataHandler.addToHistory(contactPojo.id);
}
}
use of fr.neamar.kiss.DataHandler in project KISS by Neamar.
the class IncomingCallHandler method onReceive.
@Override
public void onReceive(final Context context, Intent intent) {
try {
DataHandler dataHandler = KissApplication.getDataHandler(context);
ContactsProvider contactsProvider = dataHandler.getContactsProvider();
// Stop if contacts are not enabled
if (contactsProvider == null) {
return;
}
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (phoneNumber == null) {
// Skipping (private call)
return;
}
ContactsPojo contactPojo = contactsProvider.findByPhone(phoneNumber);
if (contactPojo != null) {
dataHandler.addToHistory(contactPojo.id);
}
}
} catch (Exception e) {
Log.e("Phone Receive Error", " " + e);
}
}
use of fr.neamar.kiss.DataHandler in project KISS by Neamar.
the class InstallShortcutHandler method onReceive.
@Override
public void onReceive(Context context, Intent data) {
DataHandler dh = KissApplication.getDataHandler(context);
ShortcutsProvider sp = dh.getShortcutsProvider();
if (sp == null)
return;
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Log.d("onReceive", "Received shortcut " + name);
Intent target = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
if (target.getAction() == null) {
target.setAction(Intent.ACTION_VIEW);
}
ShortcutsPojo pojo = createPojo(name);
// convert target intent to parsable uri
pojo.intentUri = target.toUri(0);
//get embedded icon
Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
if (icon != null) {
Log.d("onReceive", "Shortcut " + name + " has embedded icon");
pojo.icon = icon;
} else {
ShortcutIconResource sir = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (sir != null) {
Log.d("onReceive", "Received icon package name " + sir.packageName);
Log.d("onReceive", "Received icon resource name " + sir.resourceName);
pojo.packageName = sir.packageName;
pojo.resourceName = sir.resourceName;
} else {
//invalid shortcut
Log.d("onReceive", "Invalid shortcut " + name + ", ignoring");
return;
}
}
try {
Intent intent = Intent.parseUri(pojo.intentUri, 0);
if (intent.getCategories() != null && intent.getCategories().contains(Intent.CATEGORY_LAUNCHER) && intent.getAction().equals(Intent.ACTION_MAIN)) {
// The Play Store has an option to create shortcut for new apps,
// However, KISS already displays all apps, so we discard the shortcut to avoid duplicates.
Log.d("onReceive", "Shortcut for launcher app, discarded.");
return;
}
} catch (URISyntaxException e) {
// Invalid intentUri: skip
// (should logically not happen)
e.printStackTrace();
return;
}
dh.addShortcut(pojo);
}
Aggregations