Search in sources :

Example 1 with InboxUtil

use of dev.sagar.smsblocker.tech.utils.InboxUtil in project SMSBlocker by sagarpawardev.

the class ThreadActivity method init.

private void init() {
    final String methodName = "init()";
    log.justEntered(methodName);
    try {
        // TODO Analytics App
        sAnalytics = GoogleAnalytics.getInstance(this);
        sTracker = getDefaultTracker();
        sTracker.setScreenName("Image~HomeActivity");
        sTracker.send(new HitBuilders.ScreenViewBuilder().build());
    } catch (Exception e) {
        log.info(methodName, "Logging Error..");
        log.error(methodName, e);
    }
    recyclerView = (RecyclerView) findViewById(R.id.lv_sms);
    btnSend = (ImageButton) findViewById(R.id.btn_send);
    etMsg = (EditText) findViewById(R.id.et_msg);
    holderBodyET = findViewById(R.id.holder_sms_et);
    tvReplyNotSupported = findViewById(R.id.tv_reply_not_supported);
    holderLoader = findViewById(R.id.holder_loader);
    holderMain = findViewById(R.id.holder_main);
    if (inboxUtil == null)
        inboxUtil = new InboxUtil(this, this);
    smsUtil = new SMSUtil(this);
    smsReceivedReceiver = new LocalSMSReceivedReceiver(this);
    smsDeliveredReceiver = new LocalSMSDeliveredReceiver(this);
    smsSentReceiver = new LocalSMSSentReceiver(this);
    // From Previous Activity
    Bundle basket = getIntent().getExtras();
    address = basket.getString(KEY_ADDRESS);
    adapter = new RVThreadAdapter(this, this, smses);
    amCallback = new AMCallbackThread(this, adapter);
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    mLayoutManager.setReverseLayout(true);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setAdapter(adapter);
    log.returning(methodName);
}
Also used : LocalSMSReceivedReceiver(dev.sagar.smsblocker.tech.broadcastreceivers.LocalSMSReceivedReceiver) Bundle(android.os.Bundle) InboxUtil(dev.sagar.smsblocker.tech.utils.InboxUtil) RVThreadAdapter(dev.sagar.smsblocker.ux.adapters.RVThreadAdapter) AMCallbackThread(dev.sagar.smsblocker.ux.listeners.actionmodecallbacks.AMCallbackThread) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ReadContactPermissionException(dev.sagar.smsblocker.tech.exceptions.ReadContactPermissionException) LocalSMSDeliveredReceiver(dev.sagar.smsblocker.tech.broadcastreceivers.LocalSMSDeliveredReceiver) LocalSMSSentReceiver(dev.sagar.smsblocker.tech.broadcastreceivers.LocalSMSSentReceiver) SMSUtil(dev.sagar.smsblocker.tech.utils.SMSUtil)

Example 2 with InboxUtil

use of dev.sagar.smsblocker.tech.utils.InboxUtil in project SMSBlocker by sagarpawardev.

the class StarredSMSActivity method init.

private void init() {
    final String methodName = "init()";
    log.justEntered(methodName);
    parentHolder = findViewById(R.id.view_holder);
    rvStarredSMS = (RecyclerView) findViewById(R.id.rv_starred_sms);
    inboxUtil = new InboxUtil(this);
    log.returning(methodName);
}
Also used : InboxUtil(dev.sagar.smsblocker.tech.utils.InboxUtil)

Example 3 with InboxUtil

use of dev.sagar.smsblocker.tech.utils.InboxUtil in project SMSBlocker by sagarpawardev.

the class SMSReceivedReceiver method smsReceived.

/**
 * This method is called if event is SMS_RECEIVED
 * @param context
 * @param intent
 */
private void smsReceived(Context context, Intent intent) {
    // Start Log
    final String methodName = "smsReceived()";
    log.justEntered(methodName);
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        int slot = bundle.getInt("slot", -1);
        int subscription = bundle.getInt("subscription", -1);
        log.info(methodName, "Slot: " + slot);
        log.info(methodName, "Subscription: " + subscription);
        final SmsMessage[] messages = new SmsMessage[pdus.length];
        log.debug(methodName, String.format("message count = %s", messages.length));
        // Join Multi parts
        StringBuilder sbMessage = new StringBuilder();
        for (int i = 0; i < pdus.length; i++) {
            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], MSG_FORMAT);
            String msg = messages[i].getMessageBody();
            sbMessage.append(msg);
        }
        // Create an SMS body
        String msgBody = sbMessage.toString();
        SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[0], MSG_FORMAT);
        String address = smsMessage.getOriginatingAddress();
        boolean isReplySupported = PhoneUtilsSingleton.getInstance().isReplySupported(address);
        SMS sms = new SMS();
        sms.setAddress(address);
        sms.setDateTime(smsMessage.getTimestampMillis());
        sms.setBody(msgBody);
        sms.setRead(false);
        sms.setType(SMS.TYPE_RECEIVED);
        sms.setSubscription(subscription);
        sms.setReplySupported(isReplySupported);
        log.debug(methodName, "Service Center: " + smsMessage.getServiceCenterAddress());
        log.info(methodName, "Received Message From: " + smsMessage.getDisplayOriginatingAddress());
        boolean isAppDefault = PermissionUtilSingleton.getInstance().isAppDefault(context);
        if (!isAppDefault)
            log.error(methodName, "App is not default");
        if (isAppDefault) {
            // Save SMS in DataProvider
            try {
                log.info(methodName, "Saving SMS in DataProvider");
                InboxUtil inboxUtil = new InboxUtil(context);
                String id = inboxUtil.insertSMS(sms);
                log.info(methodName, "Received Created id: " + id);
                sms.setId(id);
            } catch (Exception e) {
                log.info(methodName, "Logging Error..");
                log.error(methodName, e);
                Toast.makeText(context, "Failed in Saving", Toast.LENGTH_SHORT).show();
            }
            try {
                // Broadcast SMS Locally
                log.info(methodName, "Broadcasting SMS");
                broadcastLocalSMS(context, sms);
            } catch (Exception e) {
                log.info(methodName, "Logging Error..");
                log.error(methodName, e);
                Toast.makeText(context, "Failed in Broadcasting", Toast.LENGTH_SHORT).show();
            }
            // Create Notification
            try {
                notifUtil.createSMSNotification(context, sms);
            } catch (Exception e) {
                log.info(methodName, "Logging Error..");
                log.error(methodName, e);
                Toast.makeText(context, "Failed in creating notification", Toast.LENGTH_SHORT).show();
            }
        }
    }
    log.returning(methodName);
}
Also used : SmsMessage(android.telephony.SmsMessage) Bundle(android.os.Bundle) SMS(dev.sagar.smsblocker.tech.beans.SMS) InboxUtil(dev.sagar.smsblocker.tech.utils.InboxUtil)

Aggregations

InboxUtil (dev.sagar.smsblocker.tech.utils.InboxUtil)3 Bundle (android.os.Bundle)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 SmsMessage (android.telephony.SmsMessage)1 SMS (dev.sagar.smsblocker.tech.beans.SMS)1 LocalSMSDeliveredReceiver (dev.sagar.smsblocker.tech.broadcastreceivers.LocalSMSDeliveredReceiver)1 LocalSMSReceivedReceiver (dev.sagar.smsblocker.tech.broadcastreceivers.LocalSMSReceivedReceiver)1 LocalSMSSentReceiver (dev.sagar.smsblocker.tech.broadcastreceivers.LocalSMSSentReceiver)1 ReadContactPermissionException (dev.sagar.smsblocker.tech.exceptions.ReadContactPermissionException)1 SMSUtil (dev.sagar.smsblocker.tech.utils.SMSUtil)1 RVThreadAdapter (dev.sagar.smsblocker.ux.adapters.RVThreadAdapter)1 AMCallbackThread (dev.sagar.smsblocker.ux.listeners.actionmodecallbacks.AMCallbackThread)1