Example usage for android.content ComponentName ComponentName

List of usage examples for android.content ComponentName ComponentName

Introduction

In this page you can find the example usage for android.content ComponentName ComponentName.

Prototype

private ComponentName(String pkg, Parcel in) 

Source Link

Usage

From source file:com.wso2.mobile.mdm.services.PolicyTester.java

@SuppressWarnings("static-access")
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public boolean testPolicy(String code, String data) {
    if (code.equals(CommonUtilities.OPERATION_CLEAR_PASSWORD)) {
        ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
        JSONObject jobj = new JSONObject();
        // data = intent.getStringExtra("data");
        try {//from  w w w  . ja  v a 2s .c o  m
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);
            params.put("status", "200");

            if (IS_ENFORCE) {
                devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                        DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
                devicePolicyManager.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
                devicePolicyManager.lockNow();
                devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                        DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
                jobj.put("status", true);
            } else {
                if (devicePolicyManager.getPasswordQuality(
                        demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                    jobj.put("status", false);
                } else {
                    jobj.put("status", true);
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            jobj.put("code", code);

            //finalArray.put(jobj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_WIFI)) {
        boolean wifistatus = false;
        JSONObject jobjc = new JSONObject();
        WiFiConfig config = new WiFiConfig(context);
        // data = intent.getStringExtra("data");
        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data);
            if (!jobj.isNull("ssid")) {
                ssid = (String) jobj.get("ssid");
            }
            if (!jobj.isNull("password")) {
                password = (String) jobj.get("password");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Map<String, String> inparams = new HashMap<String, String>();
        inparams.put("code", code);
        if (IS_ENFORCE) {
            try {
                wifistatus = config.saveWEPConfig(ssid, password);
                jobjc.put("status", true);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        try {
            if (config.readWEPConfig(ssid)) {
                jobjc.put("status", true);
            } else {
                jobjc.put("status", false);
                if (usermessage != null && usermessage != "") {
                    usermessage += "\nYou are not using company WIFI account, please change your WIFI configuration \n";
                } else {
                    usermessage += "You are not using company WIFI account, please change your WIFI configuration \n";
                }

            }
            jobjc.put("code", code);

            finalArray.put(jobjc);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_DISABLE_CAMERA)) {
        ComponentName cameraAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
        boolean camFunc = false;
        // data = intent.getStringExtra("data");
        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data);

            if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("enable")) {
                camFunc = false;
            } else if (!jobj.isNull("function")
                    && jobj.get("function").toString().equalsIgnoreCase("disable")) {
                camFunc = true;
            } else if (!jobj.isNull("function")) {
                camFunc = Boolean.parseBoolean(jobj.get("function").toString());
            }

            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);
            params.put("status", "200");
            String cammode = "Disabled";
            if (camFunc) {
                cammode = "Disabled";
            } else {
                cammode = "Enabled";
            }

            if (IS_ENFORCE && (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
                devicePolicyManager.setCameraDisabled(cameraAdmin, camFunc);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        JSONObject jobj = new JSONObject();
        try {
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                if (!camFunc) {
                    if (!devicePolicyManager.getCameraDisabled(cameraAdmin)) {
                        jobj.put("status", true);
                    } else {
                        jobj.put("status", false);
                    }
                } else {
                    if (devicePolicyManager.getCameraDisabled(cameraAdmin)) {
                        jobj.put("status", true);
                    } else {
                        jobj.put("status", false);
                        /*if(usermessage!=null && usermessage!=""){
                           usermessage+="\nYour camera should be deactivated according to the policy, please deactivate your camera\n";
                        }else{
                           usermessage+="Your camera should be deactivated according to the policy, please deactivate your camera \n";
                        }*/
                    }
                }
            } else {
                jobj.put("status", false);
            }
            jobj.put("code", code);

            finalArray.put(jobj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_ENCRYPT_STORAGE)) {
        boolean encryptFunc = true;
        String pass = "";

        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data);

            if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("encrypt")) {
                encryptFunc = true;
            } else if (!jobj.isNull("function")
                    && jobj.get("function").toString().equalsIgnoreCase("decrypt")) {
                encryptFunc = false;
            } else if (!jobj.isNull("function")) {
                encryptFunc = Boolean.parseBoolean(jobj.get("function").toString());
            }

            ComponentName admin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);

            if (IS_ENFORCE) {
                if (encryptFunc && devicePolicyManager
                        .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
                    if (devicePolicyManager
                            .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) {
                        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                            devicePolicyManager.setStorageEncryption(admin, encryptFunc);
                            Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(intent);
                        }
                    }
                } else if (!encryptFunc && devicePolicyManager
                        .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
                    if (devicePolicyManager
                            .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVE
                            || devicePolicyManager
                                    .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVATING) {
                        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                            devicePolicyManager.setStorageEncryption(admin, encryptFunc);
                        }
                    }
                }
            }
            if (devicePolicyManager
                    .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
                params.put("status", "200");
            } else {
                params.put("status", "400");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        JSONObject jobj = new JSONObject();
        try {
            jobj.put("code", code);
            if (encryptFunc) {
                if (devicePolicyManager
                        .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED
                        && devicePolicyManager
                                .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) {
                    jobj.put("status", true);
                } else {
                    jobj.put("status", false);
                    if (usermessage != null && usermessage != "") {
                        usermessage += "\nYour device should be encrypted according to the policy, please enable device encryption through device settings\n";
                    } else {
                        usermessage += "Your device should be encrypted according to the policy, please enable device encryption through device settings \n";
                    }
                }
            } else {
                if (devicePolicyManager
                        .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED
                        || devicePolicyManager
                                .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) {
                    jobj.put("status", true);
                } else {
                    jobj.put("status", false);
                }
            }
            finalArray.put(jobj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else if (code.equals(CommonUtilities.OPERATION_MUTE)) {

        try {
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);
            params.put("status", "200");
            if (IS_ENFORCE) {
                muteDevice();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        JSONObject jobj = new JSONObject();
        try {
            jobj.put("code", code);
            if (isMuted()) {
                jobj.put("status", true);
            } else {
                jobj.put("status", false);
                if (usermessage != null && usermessage != "") {
                    usermessage += "\nYour phone should be muted according to the policy, please mute your phone \n";
                } else {
                    usermessage += "Your phone should be muted according to the policy, please mute your phone \n";
                }
            }
            finalArray.put(jobj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_PASSWORD_POLICY)) {

        ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
        JSONObject jobjx = new JSONObject();
        int attempts, length, history, specialChars;
        String alphanumeric, complex;
        boolean b_alphanumeric = false, b_complex = false, is_comply = true, comply_fac1 = true,
                comply_fac2 = true, comply_fac3 = true, comply_fac4 = true, comply_fac5 = true,
                comply_fac6 = true, comply_fac7 = true;
        long timout;
        Map<String, String> inparams = new HashMap<String, String>();
        // data = intent.getStringExtra("data");
        JSONParser jp = new JSONParser();
        try {
            JSONObject jobjpass = new JSONObject();
            jobjpass.put("code", CommonUtilities.OPERATION_CHANGE_LOCK_CODE);

            if (devicePolicyManager.isActivePasswordSufficient()) {
                is_comply = true;
                //finalArray.put(jobjpass);
            } else {
                is_comply = false;
            }

            JSONObject jobj = new JSONObject(data);
            if (!jobj.isNull("maxFailedAttempts") && jobj.get("maxFailedAttempts") != null) {
                attempts = Integer.parseInt((String) jobj.get("maxFailedAttempts"));
                if (IS_ENFORCE) {
                    devicePolicyManager.setMaximumFailedPasswordsForWipe(demoDeviceAdmin, attempts);
                    comply_fac1 = true;
                } else {
                    if (devicePolicyManager.getMaximumFailedPasswordsForWipe(demoDeviceAdmin) != attempts) {
                        comply_fac1 = false;
                    } else {
                        comply_fac1 = true;
                    }
                }
            }

            if (!jobj.isNull("minLength") && jobj.get("minLength") != null) {
                length = Integer.parseInt((String) jobj.get("minLength"));
                if (IS_ENFORCE) {
                    devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, length);
                    comply_fac2 = true;
                } else {
                    if (devicePolicyManager.getPasswordMinimumLength(demoDeviceAdmin) != length) {
                        comply_fac2 = false;
                    } else {
                        comply_fac2 = true;
                    }
                }
            }

            if (!jobj.isNull("pinHistory") && jobj.get("pinHistory") != null) {
                history = Integer.parseInt((String) jobj.get("pinHistory"));
                if (IS_ENFORCE) {
                    devicePolicyManager.setPasswordHistoryLength(demoDeviceAdmin, history);
                    comply_fac3 = true;
                } else {
                    if (devicePolicyManager.getPasswordHistoryLength(demoDeviceAdmin) != history) {
                        comply_fac3 = false;
                    } else {
                        comply_fac3 = true;
                    }
                }
            }

            if (!jobj.isNull("minComplexChars") && jobj.get("minComplexChars") != null) {
                specialChars = Integer.parseInt((String) jobj.get("minComplexChars"));
                if (IS_ENFORCE) {
                    devicePolicyManager.setPasswordMinimumSymbols(demoDeviceAdmin, specialChars);
                    comply_fac4 = true;
                } else {
                    if (devicePolicyManager.getPasswordMinimumSymbols(demoDeviceAdmin) != specialChars) {
                        comply_fac4 = false;
                    } else {
                        comply_fac4 = true;
                    }
                }
            }

            if (!jobj.isNull("requireAlphanumeric") && jobj.get("requireAlphanumeric") != null) {

                if (jobj.get("requireAlphanumeric") instanceof String) {
                    alphanumeric = (String) jobj.get("requireAlphanumeric").toString();
                    if (alphanumeric.equals("true")) {
                        b_alphanumeric = true;
                    } else {
                        b_alphanumeric = false;
                    }
                } else if (jobj.get("requireAlphanumeric") instanceof Boolean) {
                    b_alphanumeric = jobj.getBoolean("requireAlphanumeric");
                }
                if (b_alphanumeric) {
                    if (IS_ENFORCE) {
                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                                DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
                        comply_fac5 = true;
                    } else {
                        if (devicePolicyManager.getPasswordQuality(
                                demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC) {
                            comply_fac5 = false;
                        } else {
                            comply_fac5 = true;
                        }
                    }
                } else {
                    if (devicePolicyManager.getPasswordQuality(
                            demoDeviceAdmin) == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC) {
                        comply_fac5 = false;
                    } else {
                        comply_fac5 = true;
                    }
                }
            }

            if (!jobj.isNull("allowSimple") && jobj.get("allowSimple") != null) {

                if (jobj.get("allowSimple") instanceof String) {
                    complex = (String) jobj.get("allowSimple").toString();
                    if (complex.equals("true")) {
                        b_complex = true;
                    } else {
                        b_complex = false;
                    }
                } else if (jobj.get("allowSimple") instanceof Boolean) {
                    b_complex = jobj.getBoolean("allowSimple");
                }

                if (!b_complex) {
                    if (IS_ENFORCE) {
                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                                DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);
                        comply_fac6 = true;
                    } else {
                        if (devicePolicyManager.getPasswordQuality(
                                demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
                            comply_fac6 = false;
                        } else {
                            comply_fac6 = true;
                        }
                    }
                } else {
                    if (devicePolicyManager.getPasswordQuality(
                            demoDeviceAdmin) == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
                        comply_fac6 = false;
                    } else {
                        comply_fac6 = true;
                    }
                }
            }

            if (!jobj.isNull("maxPINAgeInDays") && jobj.get("maxPINAgeInDays") != null) {
                int daysOfExp = Integer.parseInt((String) jobj.get("maxPINAgeInDays"));
                timout = (long) (daysOfExp * 24 * 60 * 60 * 1000);
                if (IS_ENFORCE) {
                    devicePolicyManager.setPasswordExpirationTimeout(demoDeviceAdmin, timout);
                    comply_fac7 = true;
                } else {
                    if (devicePolicyManager.getPasswordExpirationTimeout(demoDeviceAdmin) != timout) {
                        comply_fac7 = false;
                    } else {
                        comply_fac7 = true;
                    }
                }
            }

            if (!is_comply || !comply_fac1 || !comply_fac2 || !comply_fac3 || !comply_fac4 || !comply_fac5
                    || !comply_fac6 || !comply_fac7) {
                jobjx.put("status", false);
                if (usermessage != null && usermessage != "") {
                    usermessage += "\nYour screen lock password doesn't meet current policy requirement. Please reset your passcode \n";
                } else {
                    usermessage += "Your screen lock password doesn't meet current policy requirement. Please reset your passcode \n";
                }
            } else {
                jobjx.put("status", true);
            }

            inparams.put("code", code);
            inparams.put("status", "200");

        } catch (Exception e) {
            // TODO Auto-generated catch block

            e.printStackTrace();
        }

        try {
            jobjx.put("code", code);

            finalArray.put(jobjx);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_BLACKLIST_APPS)) {
        ArrayList<PInfo> apps = appList.getInstalledApps(false); /*
                                                                 * false =
                                                                 * no system
                                                                 * packages
                                                                 */
        JSONArray jsonArray = new JSONArray();
        int max = apps.size();

        Boolean flag = true;

        try {
            JSONObject appObj = new JSONObject(data);
            String identity = (String) appObj.get("identity");
            for (int j = 0; j < max; j++) {
                JSONObject jsonObj = new JSONObject();
                try {
                    jsonObj.put("name", apps.get(j).appname);
                    jsonObj.put("package", apps.get(j).pname);
                    if (identity.trim().equals(apps.get(j).pname)) {
                        jsonObj.put("notviolated", false);
                        flag = false;
                        jsonObj.put("package", apps.get(j).pname);
                        if (apps.get(j).appname != null) {
                            appcount++;
                            apz = appcount + ". " + apps.get(j).appname;
                        }

                        if (apz != null || !apz.trim().equals("")) {
                            if (usermessage != null && usermessage != "") {
                                if (appcount > 1) {
                                    usermessage += "\n" + apz;
                                } else {
                                    usermessage += "\nFollowing apps are blacklisted by your MDM Admin, please remove them \n\n"
                                            + apz;
                                }
                            } else {
                                if (appcount > 1) {
                                    usermessage += "\n" + apz;
                                } else {
                                    usermessage += "Following apps are blacklisted by your MDM Admin, please remove them \n\n"
                                            + apz;
                                }

                            }
                        }

                    } else {
                        jsonObj.put("notviolated", true);
                    }

                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                jsonArray.put(jsonObj);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        /*
         * for(int i=0;i<apps.length;i++){ jsonArray.add(apps[i]); }
         */
        JSONObject appsObj = new JSONObject();
        try {
            //appsObj.put("data", jsonArray);
            appsObj.put("status", flag);
            appsObj.put("code", code);
            finalArray.put(appsObj);

        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    }

    return true;
}

From source file:androidx.media.MediaSessionService2.java

/**
 * Default implementation for {@link MediaSessionService2} to initialize session service.
 * <p>/*from www.  j  a v  a2 s. c  o m*/
 * Override this method if you need your own initialization. Derived classes MUST call through
 * to the super class's implementation of this method.
 */
@CallSuper
@Override
public void onCreate() {
    super.onCreate();
    mBrowserServiceCompat.attachToBaseContext(this);
    mBrowserServiceCompat.onCreate();
    SessionToken2 token = new SessionToken2(this, new ComponentName(getPackageName(), getClass().getName()));
    if (token.getType() != getSessionType()) {
        throw new RuntimeException("Expected session type " + getSessionType() + " but was " + token.getType());
    }
    MediaSession2 session = onCreateSession(token.getId());
    synchronized (mLock) {
        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        mStartSelfIntent = new Intent(this, getClass());
        mSession = session;
        if (mSession == null || !token.getId().equals(mSession.getToken().getId())) {
            throw new RuntimeException("Expected session with id " + token.getId() + ", but got " + mSession);
        }
        mBrowserServiceCompat.setSessionToken(mSession.getToken().getSessionCompatToken());
    }
}

From source file:com.fvd.nimbus.MainActivity.java

public static void deleteShortcut(Context context) {
    Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Nimbus Clipper");
    ComponentName comp = new ComponentName("com.fvd.nimbus", "com.fvd.nimbus.MainActivity");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
    context.sendBroadcast(shortcut);//from  w w  w.j a  v a2 s  .com
}

From source file:com.example.android.AudioArchive.ui.FullScreenPlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_player);
    initializeToolbar();/*from  w  w w  . ja v  a2s  .  c o m*/
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    mBackgroundImage = (ImageView) findViewById(R.id.background_image);
    mPauseDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_pause_white_48dp);
    mPlayDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_play_arrow_white_48dp);
    mPlayPause = (ImageView) findViewById(R.id.play_pause);
    mSkipNext = (ImageView) findViewById(R.id.next);
    mSkipPrev = (ImageView) findViewById(R.id.prev);

    mLine1 = (TextView) findViewById(R.id.line1);
    mLine2 = (TextView) findViewById(R.id.line2);
    mLine3 = (TextView) findViewById(R.id.line3);
    mLoading = (ProgressBar) findViewById(R.id.progressBar1);
    mControllers = findViewById(R.id.controllers);

    mSkipNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToNext();
        }
    });

    mSkipPrev.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToPrevious();
        }
    });

    mPlayPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PlaybackStateCompat state = getSupportMediaController().getPlaybackState();
            if (state != null) {
                MediaControllerCompat.TransportControls controls = getSupportMediaController()
                        .getTransportControls();
                switch (state.getState()) {
                case PlaybackStateCompat.STATE_PLAYING: // fall through
                case PlaybackStateCompat.STATE_BUFFERING:
                    controls.pause();

                    break;
                case PlaybackStateCompat.STATE_PAUSED:
                case PlaybackStateCompat.STATE_STOPPED:
                    controls.play();

                    break;
                default:
                    LogHelper.d(TAG, "onClick with state ", state.getState());
                }
            }
        }
    });

    ;

    // Only update from the intent if we are not recreating from a config change:
    if (savedInstanceState == null) {
        updateFromParams(getIntent());
    }

    mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class),
            mConnectionCallback, null);
}

From source file:com.configurer.easyscreenlock.MainActivity.java

/**
 * Initialise below components ://from w  w w.  ja v a 2s  .  c o  m
 * <li><b>Device Policy Manager </b> - Public interface for managing policies enforced on a device. </li>
 * <li><b>Activity Manager </b> - Interact with the overall activities running in the system. </li>
 * <li><b>Component Name </b> - Identifier for a specific application component.</li>
 */
private void initializeComponents() {
    try {
        deviceManger = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
        activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        compName = new ComponentName(this, DeviceAdministratorReceiver.class);
    } catch (Exception e) {
        deviceManger = null;
        activityManager = null;
        compName = null;
        Log.e(TAG, e.getMessage());
    }
}

From source file:com.android.transmart.PlaceActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Inflate the layout
    setContentView(R.layout.nearby);/*from  w ww .ja  v  a 2s. co m*/

    // Get a handle to the Fragments
    placeListFragment = (PlaceListFragment) getSupportFragmentManager().findFragmentById(R.id.list_fragment);
    checkinFragment = (CheckinFragment) getSupportFragmentManager().findFragmentById(R.id.checkin_fragment);

    // Get references to the managers
    packageManager = getPackageManager();
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Get a reference to the Shared Preferences and a Shared Preference Editor.
    prefs = getSharedPreferences(LocationConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE);
    prefsEditor = prefs.edit();

    // Instantiate a SharedPreferenceSaver class based on the available platform version.
    // This will be used to save shared preferences
    sharedPreferenceSaver = PlatformSpecific.getSharedPreferenceSaver(this);

    // Save that we've been run once.
    prefsEditor.putBoolean(LocationConstants.SP_KEY_RUN_ONCE, true);
    sharedPreferenceSaver.savePreferences(prefsEditor, false);

    // Specify the Criteria to use when requesting location updates while the application is Active
    criteria = new Criteria();
    if (LocationConstants.USE_GPS_WHEN_ACTIVITY_VISIBLE)
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
    else
        criteria.setPowerRequirement(Criteria.POWER_LOW);

    // Setup the location update Pending Intents
    Intent activeIntent = new Intent(this, LocationChangedReceiver.class);
    locationListenerPendingIntent = PendingIntent.getBroadcast(this, 0, activeIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent passiveIntent = new Intent(this, PassiveLocReceiver.class);
    locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Instantiate a LastLocationFinder class.
    // This will be used to find the last known location when the application starts.
    lastLocationFinder = PlatformSpecific.getLastLocationFinder(this);
    lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener);

    // Instantiate a Location Update Requester class based on the available platform version.
    // This will be used to request location updates.
    locationUpdateRequester = PlatformSpecific.getLocationUpdateRequester(locationManager);

    // Create an Intent Filter to listen for checkins
    newCheckinReceiverName = new ComponentName(this, NewCheckinReceiver.class);
    newCheckinFilter = new IntentFilter(LocationConstants.NEW_CHECKIN_ACTION);

    // Check to see if an Place ID has been specified in the launch Intent.
    // If so, we should display the details for the specified venue.
    if (getIntent().hasExtra(LocationConstants.EXTRA_KEY_ID)) {
        Intent intent = getIntent();
        String key = intent.getStringExtra(LocationConstants.EXTRA_KEY_ID);
        if (key != null) {
            selectDetail(null, key);
            // Remove the ID from the Intent (so that a resume doesn't reselect).
            intent.removeExtra(LocationConstants.EXTRA_KEY_ID);
            setIntent(intent);
        }
    }
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.nowplaying.NowPlayingActivity.java

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Dart.inject(this);
    AndroidInjection.inject(this);

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        final Intent intent = Intent.makeMainActivity(new ComponentName(this, HomeActivity.class));
        startActivity(intent);//from ww  w .  ja v a  2 s  . com
        return;
    }

    if (TransitionUtils.supportsActivityTransitions()) {
        NowPlayingActivityLollipop.applyTransitions(this);
    }

    mRequestManager = Glide.with(this);

    mTransitionPostponed = false;
    mTransitionStarted = false;

    final ActivityNowplayingBinding binding = DataBindingUtil.setContentView(this,
            R.layout.activity_nowplaying);
    ButterKnife.bind(this);

    ViewCompat.setTransitionName(albumArt, TRANSITION_NAME_ALBUM_ART);
    ViewCompat.setTransitionName(root, TRANSITION_NAME_ROOT);

    mModel.setBtnPlayRes(R.drawable.ic_play_arrow_white_36dp);
    mModel.setShuffleEnabled(mPlaybackParams.isShuffleEnabled());
    mModel.setRepeatMode(mPlaybackParams.getRepeatMode());

    binding.setModel(mModel);
    setSupportActionBar(toolbar);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(final SeekBar seekBar, final int i, final boolean b) {

        }

        @Override
        public void onStartTrackingTouch(final SeekBar seekBar) {
            mSeekBarTracking = true;
        }

        @Override
        public void onStopTrackingTouch(final SeekBar seekBar) {
            mPlaybackServiceControl.seek((float) seekBar.getProgress() / (float) seekBar.getMax());
            mSeekBarTracking = false;
        }
    });

    mIntentHandler = new NowPlayingActivityIntentHandler(this);
    mIntentHandler.handleIntent(getIntent());

    mNavigationController = new NavigationController(this, findViewById(R.id.drawerLayout));
    mNavigationController.bind();
}

From source file:co.edu.uniajc.vtf.content.SwipeContentActivity.java

@Override
protected void onPause() {
    ComponentName loComponent = new ComponentName(this, NetworkStatusReceiver.class);
    this.getPackageManager().setComponentEnabledSetting(loComponent,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    super.onPause();
}

From source file:com.boko.vimusic.NotificationHelper.java

/**
 * @param which//from w  w w. j  a  va2s .  co m
 *            Which {@link PendingIntent} to return
 * @return A {@link PendingIntent} ready to control playback
 */
private final PendingIntent retreivePlaybackActions(final int which) {
    Intent action;
    PendingIntent pendingIntent;
    final ComponentName serviceName = new ComponentName(mService, MediaPlaybackService.class);
    switch (which) {
    case 1:
        // Play and pause
        action = new Intent(MediaPlaybackService.ACTION_PLAYER_TOGGLEPAUSE);
        action.setComponent(serviceName);
        pendingIntent = PendingIntent.getService(mService, 1, action, 0);
        return pendingIntent;
    case 2:
        // Skip tracks
        action = new Intent(MediaPlaybackService.ACTION_PLAYER_NEXT);
        action.setComponent(serviceName);
        pendingIntent = PendingIntent.getService(mService, 2, action, 0);
        return pendingIntent;
    case 3:
        // Previous tracks
        action = new Intent(MediaPlaybackService.ACTION_PLAYER_PREVIOUS);
        action.setComponent(serviceName);
        pendingIntent = PendingIntent.getService(mService, 3, action, 0);
        return pendingIntent;
    case 4:
        // Stop and collapse the notification
        action = new Intent(MediaPlaybackService.ACTION_PLAYER_STOP);
        action.setComponent(serviceName);
        pendingIntent = PendingIntent.getService(mService, 4, action, 0);
        return pendingIntent;
    default:
        break;
    }
    return null;
}

From source file:com.example.android.mediabrowserservice.MusicService.java

@Override
public void onCreate() {
    super.onCreate();
    LogHelper.d(TAG, "onCreate");

    mPlayingQueue = new ArrayList<>();
    mMusicProvider = new MusicProvider();
    mPackageValidator = new PackageValidator(this);

    // Start a new MediaSession
    mSession = new MediaSessionCompat(this, "MusicService",
            new ComponentName(this, MediaNotificationManager.class), null);
    setSessionToken(mSession.getSessionToken());
    mSession.setCallback(new MediaSessionCallback());
    mSession.setFlags(//w w w.  j  a  va2  s  .  c  o m
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    mPlayback = new Playback(this, mMusicProvider);
    mPlayback.setState(PlaybackStateCompat.STATE_NONE);
    mPlayback.setCallback(this);
    mPlayback.start();

    Context context = getApplicationContext();
    Intent intent = new Intent(context, MusicPlayerActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mSession.setSessionActivity(pi);

    Bundle extras = new Bundle();
    CarHelper.setSlotReservationFlags(extras, true, true, true);
    mSession.setExtras(extras);

    updatePlaybackState(null);

    mMediaNotificationManager = new MediaNotificationManager(this);
}