Android Open Source - ringydingydingy Api Handler






From Project

Back to project page ringydingydingy.

License

The source code is released under:

GNU General Public License

If you think the Android project ringydingydingy listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * This file is part of RingyDingyDingy.
 * Copyright (C) 2011-2012 Ayron Jungren
 *//from  w w w  .ja  v  a  2  s.c om
 * RingyDingyDingy is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License only.
 *
 * RingyDingyDingy is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with RingyDingyDingy.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.dririan.RingyDingyDingy;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

public class ApiHandler extends BroadcastReceiver {
    // Permissions
    public static final String PERMISSION_EXECUTE = "com.dririan.RingyDingyDingy.EXECUTE_COMMAND";
    public static final String PERMISSION_HANDLE = "com.dririan.RingyDingyDingy.HANDLE_COMMAND";
    public static final String PERMISSION_HANDLE_INTERNAL = "com.dririan.RingyDingyDingy.HANDLE_INTERNAL_COMMAND";

    // Generic result codes
    public static final int RESULT_UNKNOWN_COMMAND = -42;

    // COMMAND_LOCK result codes
    public static final int RESULT_NEEDS_FROYO = 1;
    public static final int RESULT_NOT_ACTIVE = 2;

    // COMMAND_RING result codes
    public static final int RESULT_ALREADY_RINGING = 1;
    public static final int RESULT_PAGER_DISABLED = 2;

    // COMMAND_STOP result codes
    public static final int RESULT_NOT_RINGING = 1;

    // Pre-defined command intents
    public static final String INTENT_LOCK = "com.dririan.RingyDingyDingy.COMMAND_LOCK";
    public static final String INTENT_RING = "com.dririan.RingyDingyDingy.COMMAND_RING";
    public static final String INTENT_STOP = "com.dririan.RingyDingyDingy.COMMAND_STOP";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if(action.compareTo(INTENT_LOCK) == 0) {
            if(Build.VERSION.SDK_INT >= 8) {
                LockingSupport lockingSupport = LockingSupport.getInstance(context);
                if(lockingSupport.isActive()) {
                    lockingSupport.lock();
                    setResultCode(Activity.RESULT_OK);
                    setResultData(context.getString(R.string.sms_lock_success));
                    return;
                }
                else {
                    setResultCode(RESULT_NOT_ACTIVE);
                    setResultData(context.getString(R.string.sms_lock_needs_permission));
                    return;
                }
            }
            else {
                setResultCode(RESULT_NEEDS_FROYO);
                setResultData(context.getString(R.string.sms_lock_needs_froyo));
                return;
            }
        }
        else if(action.compareTo(INTENT_RING) == 0) {
            // If a remote ring is already happening, don't start another
            // However, if a ring is happening, a page will override it
            if(RemoteRingActivity.activationLevel == RemoteRingActivity.LEVEL_RING_ACTIVE && !intent.hasExtra("message")) {
                setResultCode(RESULT_ALREADY_RINGING);
                setResultData(context.getString(R.string.sms_ring_was_ringing));
                return;
            }
            else {
                Intent newIntent = new Intent(context, RemoteRingActivity.class);

                if(intent.hasExtra("message")) {
                    if(!PreferencesManager.getInstance(context).pagerEnabled()) {
                        setResultCode(ApiHandler.RESULT_PAGER_DISABLED);
                        setResultData(context.getString(R.string.sms_page_disabled));
                        return;
                    }

                    if(RemoteRingActivity.activationLevel > RemoteRingActivity.LEVEL_NOT_ACTIVE) {
                        RemoteRingActivity.updateDialog(intent.getStringExtra("source"), intent.getStringExtra("message"));
                        setResultData(context.getString(R.string.sms_page_success));
                        return;
                    }

                    setResultData(context.getString(R.string.sms_page_success));
                    newIntent.putExtra("message", intent.getStringExtra("message"));
                }
                else
                    setResultData(context.getString(R.string.sms_ring_success));

                if(intent.hasExtra("source"))
                    newIntent.putExtra("source", intent.getStringExtra("source"));

                newIntent.setAction(action)
                         .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(newIntent);

                setResultCode(Activity.RESULT_OK);
                return;
            }
        }
        else if(action.compareTo(INTENT_STOP) == 0) {
            if(RemoteRingActivity.stopRinging()) {
                setResultCode(Activity.RESULT_OK);
                setResultData(context.getString(R.string.sms_stop_success));
                return;
            }
            else {
                setResultCode(RESULT_NOT_RINGING);
                setResultData(context.getString(R.string.sms_stop_was_not_ringing));
                return;
            }
        }
    }
}




Java Source Code List

com.dririan.RingyDingyDingy.ApiHandler.java
com.dririan.RingyDingyDingy.ContactSupport.java
com.dririan.RingyDingyDingy.DeviceAdmin.java
com.dririan.RingyDingyDingy.DeviceDefaultDialogBuilder.java
com.dririan.RingyDingyDingy.GoogleVoiceReceiver.java
com.dririan.RingyDingyDingy.HoloDialogBuilder.java
com.dririan.RingyDingyDingy.LockingSupport.java
com.dririan.RingyDingyDingy.LogActivity.java
com.dririan.RingyDingyDingy.LogDatabase.java
com.dririan.RingyDingyDingy.LogEntry.java
com.dririan.RingyDingyDingy.LogHandler.java
com.dririan.RingyDingyDingy.LogOpenHelper.java
com.dririan.RingyDingyDingy.MainActivity.java
com.dririan.RingyDingyDingy.MessageHandler.java
com.dririan.RingyDingyDingy.NotificationHandler.java
com.dririan.RingyDingyDingy.PreferencesActivity.java
com.dririan.RingyDingyDingy.PreferencesManager.java
com.dririan.RingyDingyDingy.RemoteRingActivity.java
com.dririan.RingyDingyDingy.SmsErrorHandler.java
com.dririan.RingyDingyDingy.SmsReceiver.java
com.dririan.RingyDingyDingy.ThemedDialogBuilder.java
com.dririan.RingyDingyDingy.ToggleHandler.java