Example usage for android.content Intent setComponent

List of usage examples for android.content Intent setComponent

Introduction

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

Prototype

public @NonNull Intent setComponent(@Nullable ComponentName component) 

Source Link

Document

(Usually optional) Explicitly set the component to handle the intent.

Usage

From source file:info.zamojski.soft.towercollector.MainActivity.java

private Intent createDataRoamingSettingsIntent() {
    Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
    // Theoretically this is not needed starting from 4.0.1 but it sometimes fail
    // bug https://code.google.com/p/android/issues/detail?id=13368
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        ComponentName componentName = new ComponentName("com.android.phone", "com.android.phone.Settings");
        intent.setComponent(componentName);
    }/*from  w ww.j a va  2 s  .c  om*/
    return intent;
}

From source file:com.samsung.multiwindow.MultiWindow.java

/**
 * Executes the request and returns PluginResult.
 * /*from w  w  w  .j  a  v a 2s  .c o m*/
 * @param action
 *            The action to be executed.
 * @param args
 *            JSONArray of arguments for the plugin.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * @return A PluginResult object with a status and message.
 */
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {

    int ret = -1;

    try {
        // window type argument index is same in all cases of
        // createmultiwindow
        windowType = args.getString(mainFsOptions.WINDOW_TYPE.ordinal());

        // Do not allow apis if metadata is missing
        if (!pluginMetadata) {
            callbackContext.error("METADATA_MISSING");
            Log.e("MultiWindow", "Metadata is missing");
            return false;
        }

        // Verify the multiwindow capability of the device
        ret = intializeMultiwindow();
        if (ret != INIT_SUCCESS) {

            switch (ret) {

            case SsdkUnsupportedException.VENDOR_NOT_SUPPORTED:
                callbackContext.error("VENDOR_NOT_SUPPORTED");
                break;
            case SsdkUnsupportedException.DEVICE_NOT_SUPPORTED:
                callbackContext.error("DEVICE_NOT_SUPPORTED");
                break;
            default:
                callbackContext.error("MUTLI_WINDOW_INITIALIZATION_FAILED");
                break;
            }

            return false;
        }

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Multiwindow initialization is successful" + ret);
        }

        // Check window support
        windowSupport = isMultiWindowSupported(windowType);
        if (windowType.equalsIgnoreCase("freestyle")) {

            if (!windowSupport) {
                callbackContext.error("FREE_STYLE_NOT_SUPPORTED");
            }

        } else if (windowType.equalsIgnoreCase("splitstyle")) {

            if (!windowSupport) {
                callbackContext.error("SPLIT_STYLE_NOT_SUPPORTED");
            }
        } else {

            callbackContext.error("INVALID_WINDOW_TYPE");
        }

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "MultiWindow window type Supported:" + windowSupport);
        }

        // Get zone info in case of split style
        if (windowSupport && (action.equals("action_main") || action.equals("action_view"))) {

            if (windowType.equalsIgnoreCase("splitstyle")) {

                switch (args.optInt(mainSsOptions.ZONE_INFO.ordinal())) {
                case ZONE_A:
                    Log.d(TAG, "Zone A selected");
                    zoneInfo = SMultiWindowActivity.ZONE_A;
                    break;
                case ZONE_B:
                    Log.d(TAG, "Zone B selected");
                    zoneInfo = SMultiWindowActivity.ZONE_B;
                    break;
                case ZONE_FULL:
                    Log.d(TAG, "Zone Full selected");
                    zoneInfo = SMultiWindowActivity.ZONE_FULL;
                    break;
                default:
                    Log.d(TAG, "Zone is not selected");
                    callbackContext.error("INVALID_ZONEINFO");
                    return false;
                }
            }
        }
    } catch (Exception e) {

        callbackContext.error(e.getMessage());
    }

    if (action.equals("action_main")) {

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Action is action_main");
        }
        if (!windowSupport) {
            return false;
        }

        cordova.getThreadPool().execute(new Runnable() {

            public void run() {

                Intent intent = new Intent(Intent.ACTION_MAIN);
                int packageNameIndex = 0;
                int activityNameIndex = 0;
                float scaleInfo = 0;
                int zoneInfo = getZoneInfo();
                String windowType = getWindowType();

                if (windowType.equalsIgnoreCase("splitstyle")) {
                    packageNameIndex = mainSsOptions.PACKAGE_NAME.ordinal();
                    activityNameIndex = mainSsOptions.ACTIVITY_NAME.ordinal();
                } else {
                    packageNameIndex = mainFsOptions.PACKAGE_NAME.ordinal();
                    activityNameIndex = mainFsOptions.ACTIVITY_NAME.ordinal();
                }

                try {
                    intent.setComponent(new ComponentName(args.getString(packageNameIndex),
                            args.getString(activityNameIndex)));

                    if (windowType.equalsIgnoreCase("splitstyle")) {
                        SMultiWindowActivity.makeMultiWindowIntent(intent, zoneInfo);
                    } else {

                        scaleInfo = ((float) args.getDouble(mainFsOptions.SCALE_INFO.ordinal())) / 100;
                        if (scaleInfo < 0.6 || scaleInfo > 1.0) {
                            callbackContext.error("INVALID_SCALEINFO");
                            return;
                        }
                        SMultiWindowActivity.makeMultiWindowIntent(intent, scaleInfo);
                    }
                } catch (Exception e) { // May be JSONException

                    callbackContext.error(e.getMessage());
                }
                try {
                    cordova.getActivity().startActivity(intent);
                } catch (ActivityNotFoundException activityNotFound) {
                    callbackContext.error("ACTIVITY_NOT_FOUND");
                }

                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
            }
        });
        return true;

    } else if (action.equals("action_view")) {

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Action is action_view");
        }
        if (!windowSupport) {
            return false;
        }

        cordova.getThreadPool().execute(new Runnable() {

            public void run() {

                int dataUriIndex = 0;
                float scaleInfo = 0;
                Intent dataUrl = null;
                String windowType = getWindowType();
                int zoneInfo = getZoneInfo();

                if (windowType.equalsIgnoreCase("splitstyle")) {
                    dataUriIndex = viewSsOptions.DATA_URI.ordinal();

                } else {
                    dataUriIndex = viewFsOptions.DATA_URI.ordinal();
                }
                String dataUri = null;
                try {
                    dataUri = args.getString(dataUriIndex);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                if (dataUri == null || dataUri.equals("") || dataUri.equals("null")) {
                    callbackContext.error("INVALID_DATA_URI");
                    return;
                } else {
                    boolean isUriProper = false;
                    for (String schema : URI_SCHEMA_SUPPORTED) {
                        if (dataUri.startsWith(schema)) {
                            isUriProper = true;
                            break;
                        }
                    }
                    if (!isUriProper) {
                        callbackContext.error("INVALID_DATA_URI");
                        return;
                    }
                }
                try {
                    dataUrl = new Intent(Intent.ACTION_VIEW, Uri.parse(dataUri));

                    if (windowType.equalsIgnoreCase("splitstyle")) {
                        SMultiWindowActivity.makeMultiWindowIntent(dataUrl, zoneInfo);
                    } else {
                        scaleInfo = ((float) args.getDouble(viewFsOptions.SCALE_INFO.ordinal())) / 100;
                        if (scaleInfo < 0.6 || scaleInfo > 1.0) {
                            callbackContext.error("INVALID_SCALEINFO");
                            return;
                        }
                        SMultiWindowActivity.makeMultiWindowIntent(dataUrl, scaleInfo);
                    }
                } catch (Exception e) { // May be JSONException

                    callbackContext.error(e.getMessage());
                }

                try {

                    if (dataUrl != null) {
                        cordova.getActivity().startActivity(dataUrl);
                    }

                } catch (ActivityNotFoundException activityNotFound) {
                    callbackContext.error("ACTIVITY_NOT_FOUND");
                }
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
            }
        });
        return true;

    } else if (action.equals("action_check")) {

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Action is action_check");
        }

        if (windowSupport) {

            callbackContext.success();
        }
        return true;

    } else if (action.equals("action_getapps")) {

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Action is action_getapps");
        }

        if (!windowSupport) {

            return false;
        }

        getMultiWindowApps(windowType, callbackContext);
        return true;

    }

    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, 0));
    return false;
}

From source file:org.linphone.LinphoneActivity.java

private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras,
        boolean withoutAnimation) {
    if (newFragmentType == currentFragment && newFragmentType != FragmentsAvailable.CHAT) {
        return;//from w  w w .jav  a2s  .co m
    }
    nextFragment = newFragmentType;

    if (currentFragment == FragmentsAvailable.DIALER) {
        try {
            dialerSavedState = getSupportFragmentManager().saveFragmentInstanceState(dialerFragment);
        } catch (Exception e) {
        }
    }

    Fragment newFragment = null;

    switch (newFragmentType) {
    case HISTORY:
        if (getResources().getBoolean(R.bool.use_simple_history)) {
            newFragment = new HistorySimpleFragment();
        } else {
            newFragment = new HistoryFragment();
        }
        break;
    case HISTORY_DETAIL:
        newFragment = new HistoryDetailFragment();
        break;
    case CONTACTS:
        if (getResources().getBoolean(R.bool.use_android_native_contact_edit_interface)) {
            Intent i = new Intent();
            i.setComponent(new ComponentName("com.android.contacts",
                    "com.android.contacts.DialtactsContactsEntryActivity"));
            i.setAction("android.intent.action.MAIN");
            i.addCategory("android.intent.category.LAUNCHER");
            i.addCategory("android.intent.category.DEFAULT");
            startActivity(i);
        } else {
            newFragment = new ContactsListFragment();
            friendStatusListenerFragment = newFragment;
        }
        break;
    case CONTACT:
        newFragment = new ContactFragment();
        break;
    case EDIT_CONTACT:
        newFragment = new EditContactFragment();
        break;
    case DIALER:
        newFragment = new DialerFragment();
        if (extras == null) {
            newFragment.setInitialSavedState(dialerSavedState);
        }
        dialerFragment = newFragment;
        //configureCallButton();
        break;
    case SETTINGS:
        newFragment = new SettingsFragment();
        break;
    case ACCOUNT_SETTINGS:
        newFragment = new AccountPreferencesFragment();
        break;
    case ABOUT:
    case ABOUT_INSTEAD_OF_CHAT:
    case ABOUT_INSTEAD_OF_SETTINGS:
        newFragment = new AboutFragment();
        break;
    case CHATLIST:
        newFragment = new ChatListFragment();
        messageListFragment = new Fragment();
        break;
    case CHAT:
        newFragment = new ChatFragment();
        break;
    default:
        break;
    }

    if (newFragment != null) {
        newFragment.setArguments(extras);
        if (isTablet()) {
            changeFragmentForTablets(newFragment, newFragmentType, withoutAnimation);
        } else {
            changeFragment(newFragment, newFragmentType, withoutAnimation);
        }
    }
}

From source file:org.videolan.vlc.audio.AudioService.java

/**
 * Set up the remote control and tell the system we want to be the default receiver for the MEDIA buttons
 * @see http://android-developers.blogspot.fr/2010/06/allowing-applications-to-play-nicer.html
 *//*from   ww  w .jav  a2s.c  o m*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void setUpRemoteControlClient() {
    Context context = VLCApplication.getAppContext();
    AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);

    if (LibVlcUtil.isICSOrLater()) {
        audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);

        if (mRemoteControlClient == null) {
            Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
            mediaButtonIntent.setComponent(mRemoteControlClientReceiverComponent);
            PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context, 0, mediaButtonIntent, 0);

            // create and register the remote control client
            mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
            audioManager.registerRemoteControlClient(mRemoteControlClient);
        }

        mRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
                | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
    } else if (LibVlcUtil.isFroyoOrLater()) {
        audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
    }
}

From source file:csh.cryptonite.Cryptonite.java

public void launchTerm(boolean root) {
    /* Is a reminal emulator running? */

    /* If Terminal Emulator is not installed or outdated,
     * offer to download//from  w  ww  .  j  a v  a 2 s .c  om
     */
    if (hasExtterm(getBaseContext()) != TERM_AVAILABLE) {
        TermUnavailableDialogFragment newFragment = TermUnavailableDialogFragment.newInstance();
        newFragment.show(getSupportFragmentManager(), "dialog");
    } else {
        ComponentName termComp = new ComponentName("jackpal.androidterm", "jackpal.androidterm.Term");
        try {
            PackageInfo pinfo = getBaseContext().getPackageManager().getPackageInfo(termComp.getPackageName(),
                    0);
            String patchVersion = pinfo.versionName;
            Log.v(TAG, "Terminal Emulator version: " + patchVersion);
            int patchCode = pinfo.versionCode;

            if (patchCode < 32) {
                showAlert(R.string.error, R.string.app_terminal_outdated);
            } else if (patchCode < 43) {
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setComponent(termComp);
                runTerm(intent, extTermRunning(), root);
            } else {
                ComponentName remoteComp = new ComponentName("jackpal.androidterm",
                        "jackpal.androidterm.RemoteInterface");
                Intent intent = new Intent("jackpal.androidterm.RUN_SCRIPT");
                intent.setComponent(remoteComp);
                runTerm(intent, false, root);
            }

        } catch (PackageManager.NameNotFoundException e) {
            Toast.makeText(Cryptonite.this, R.string.app_terminal_missing, Toast.LENGTH_LONG).show();
        }
    }
}

From source file:com.rks.musicx.services.MusicXService.java

@Override
public void mediaLockscreen() {
    mediaSessionLockscreen = new MediaSessionCompat(this, TAG);
    mediaSessionLockscreen.setCallback(new MediaSessionCompat.Callback() {
        @Override//from  w w w . j  a  v  a2  s  .c o  m
        public void onPlay() {
            play();
        }

        @Override
        public void onPause() {
            pause();
        }

        @Override
        public void onSkipToNext() {
            playnext(true);
        }

        @Override
        public void onSkipToPrevious() {
            playprev(true);
        }

        @Override
        public void onStop() {
            stopSelf();
        }

        @Override
        public void onSeekTo(long pos) {
            seekto((int) pos);
        }

        @Override
        public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
            if (mediaButtonReceiver != null) {
                mediaButtonReceiver.onReceive(MusicXService.this, mediaButtonEvent);
            }
            return true;
        }
    });
    mediaSessionLockscreen.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    ComponentName buttonCom = new ComponentName(getApplicationContext(), MediaButtonReceiver.class);
    Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.setComponent(buttonCom);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mediaSessionLockscreen.setMediaButtonReceiver(pendingIntent);
    mediaSessionLockscreen.setActive(true);
}

From source file:com.supremainc.biostar2.push.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (BuildConfig.DEBUG) {
        Log.i(TAG, "========push receiver start =========");
    }/*from   ww  w .  j a va  2s .com*/

    Bundle bundle = intent.getExtras();
    if (bundle == null) {
        setResultCode(Activity.RESULT_OK);
        return;
    }

    if (REGISTER_RESPONSE_ACTION.equals(intent.getAction())) {
        String registrationId = intent.getStringExtra("registration_id");
        Log.e(TAG, "registered:" + registrationId);
        if ((registrationId != null) && (registrationId.length() > 0)) {
            PreferenceUtil.putSharedPreference(context, "registrationId", registrationId);
        }
        PackageInfo packageInfo;
        try {
            packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            PreferenceUtil.putSharedPreference(context, "version", packageInfo.versionCode);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }

        PushDataProvider pushDataProvider = PushDataProvider.getInstance(context);
        pushDataProvider.setNeedUpdateNotificationToken(registrationId);
        ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
        startWakefulService(context, intent.setComponent(comp));
        setResultCode(Activity.RESULT_OK);
        if (BuildConfig.DEBUG) {
            Log.i(TAG, "========push receiver end =========");
        }
        return;
    }
    PushNotification noti = null;
    for (String key : bundle.keySet()) {
        String value;
        try {
            value = (String) bundle.get(key);
        } catch (Exception e) {
            Log.e(TAG, " " + e.getMessage());
            continue;
        }
        if (value == null) {
            continue;
        }
        if (key.equals("CMD") && value.equals("RST_FULL")) {
            if (BuildConfig.DEBUG) {
                Log.e(TAG, "RST_FULL");
            }
            int registeredVersion = PreferenceUtil.getIntSharedPreference(context, "version");
            if (registeredVersion > 0) {
                registeredVersion--;
            }
            PreferenceUtil.putSharedPreference(context, "version", registeredVersion);
            Intent intentBoradCast = new Intent(Setting.BROADCAST_PUSH_TOKEN_UPDATE);
            LocalBroadcastManager.getInstance(context).sendBroadcast(intentBoradCast);
            return;
        }
        String code = null;
        if (key.equals(NotificationType.DEVICE_REBOOT.mName)) {
            code = NotificationType.DEVICE_REBOOT.mName;
        } else if (key.equals(NotificationType.DEVICE_RS485_DISCONNECT.mName)) {
            code = NotificationType.DEVICE_RS485_DISCONNECT.mName;
        } else if (key.equals(NotificationType.DEVICE_TAMPERING.mName)) {
            code = NotificationType.DEVICE_TAMPERING.mName;
        } else if (key.equals(NotificationType.DOOR_FORCED_OPEN.mName)) {
            code = NotificationType.DOOR_FORCED_OPEN.mName;
        } else if (key.equals(NotificationType.DOOR_HELD_OPEN.mName)) {
            code = NotificationType.DOOR_HELD_OPEN.mName;
        } else if (key.equals(NotificationType.DOOR_OPEN_REQUEST.mName)) {
            code = NotificationType.DOOR_OPEN_REQUEST.mName;
        } else if (key.equals(NotificationType.ZONE_APB.mName)) {
            code = NotificationType.ZONE_APB.mName;
        } else if (key.equals(NotificationType.ZONE_FIRE.mName)) {
            code = NotificationType.ZONE_FIRE.mName;
        }
        if (code != null) {
            PushNotification tempNoti = NotificationBuild(value, code, context);
            if (tempNoti != null) {
                noti = tempNoti;
            }
        }

        if (BuildConfig.DEBUG) {
            Log.i(TAG, "|" + String.format("%s : %s (%s)", key, value.toString(), value.getClass().getName())
                    + "|");
        }
    }

    if (noti != null) {
        Notification(noti, context);
    }

    ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
    startWakefulService(context, intent.setComponent(comp));
    setResultCode(Activity.RESULT_OK);
    if (BuildConfig.DEBUG) {
        Log.i(TAG, "========push receiver end =========");
    }
}

From source file:org.videolan.vlc.PlaybackService.java

/**
 * Set up the remote control and tell the system we want to be the default receiver for the MEDIA buttons
 * @see http://android-developers.blogspot.fr/2010/06/allowing-applications-to-play-nicer.html
 *//*from w w  w. j av  a 2 s .c  o  m*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void setUpRemoteControlClient() {
    Context context = VLCApplication.getAppContext();
    AudioManager audioManager = (AudioManager) VLCApplication.getAppContext().getSystemService(AUDIO_SERVICE);

    if (AndroidUtil.isICSOrLater()) {
        audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);

        if (mRemoteControlClient == null) {
            Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
            mediaButtonIntent.setComponent(mRemoteControlClientReceiverComponent);
            PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context, 0, mediaButtonIntent, 0);

            // create and register the remote control client
            mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
            audioManager.registerRemoteControlClient(mRemoteControlClient);
        }

        mRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
                | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
    } else if (AndroidUtil.isFroyoOrLater()) {
        audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
    }
}

From source file:dev.dworks.apps.anexplorer.DocumentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    if (SettingsActivity.getTranslucentMode(this) && Utils.hasKitKat()) {
        setTheme(R.style.Theme_Translucent);
    }//ww w.  j a  v a  2 s.  com
    super.onCreate(icicle);

    mRoots = DocumentsApplication.getRootsCache(this);

    setResult(Activity.RESULT_CANCELED);
    setContentView(R.layout.activity);

    final Resources res = getResources();
    mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);

    if (mShowAsDialog) {
        // backgroundDimAmount from theme isn't applied; do it manually
        final WindowManager.LayoutParams a = getWindow().getAttributes();
        a.dimAmount = 0.6f;
        getWindow().setAttributes(a);

        getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        // Inset ourselves to look like a dialog
        final Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);

        final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x);
        final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y);
        final int insetX = (size.x - width) / 2;
        final int insetY = (size.y - height) / 2;

        final Drawable before = getWindow().getDecorView().getBackground();
        final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY);
        ViewCompat.setBackground(getWindow().getDecorView(), after);

        // Dismiss when touch down in the dimmed inset area
        getWindow().getDecorView().setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    final float x = event.getX();
                    final float y = event.getY();
                    if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) {
                        finish();
                        return true;
                    }
                }
                return false;
            }
        });

    } else {
        // Non-dialog means we have a drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph,
                R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);

        mRootsContainer = findViewById(R.id.container_roots);
    }

    mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);
    mSaveContainer = (FrameLayout) findViewById(R.id.container_save);

    if (icicle != null) {
        mState = icicle.getParcelable(EXTRA_STATE);
        authenticated = icicle.getBoolean(EXTRA_AUTHENTICATED);
    } else {
        buildDefaultState();
    }

    initProtection();

    // Hide roots when we're managing a specific root
    if (mState.action == ACTION_MANAGE) {
        if (mShowAsDialog) {
            findViewById(R.id.dialog_roots).setVisibility(View.GONE);
        } else {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    }

    if (mState.action == ACTION_CREATE) {
        final String mimeType = getIntent().getType();
        final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE);
        SaveFragment.show(getFragmentManager(), mimeType, title);
    }

    if (mState.action == ACTION_BROWSE) {
        final Intent moreApps = new Intent(getIntent());
        moreApps.setComponent(null);
        moreApps.setPackage(null);
        RootsFragment.show(getFragmentManager(), null);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE
            || mState.action == ACTION_GET_CONTENT) {
        RootsFragment.show(getFragmentManager(), new Intent());
    }

    if (!mState.restored) {
        if (mState.action == ACTION_MANAGE) {
            final Uri rootUri = getIntent().getData();
            new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
        } else {
            new RestoreStackTask().execute();
        }
    } else {
        onCurrentDirectoryChanged(ANIM_NONE);
    }

    if (Utils.hasKitKat()) {
        if (SettingsActivity.getTranslucentMode(this)) {
            SystemBarTintManager.setupTint(this);
            SystemBarTintManager.setNavigationInsets(this, mSaveContainer);
            mDirectoryContainer
                    .setLayoutParams(SystemBarTintManager.getToggleParams(false, R.id.container_save));
        } else {
            mDirectoryContainer
                    .setLayoutParams(SystemBarTintManager.getToggleParams(true, R.id.container_save));
        }
    }
}

From source file:com.tdispatch.passenger.fragment.ControlCenterFragment.java

/**[ address search wrapper ]***************************/

protected void doAddressSearch(int type, LocationData address) {
    Intent intent = new Intent();
    intent.putExtra(Const.Bundle.TYPE, type);
    intent.putExtra(Const.Bundle.LOCATION, address);
    intent.putExtra(Const.Bundle.REQUEST_CODE, Const.RequestCode.ADDRESS_SEARCH);
    intent.setComponent(new ComponentName(mContext.getPackageName(), SearchActivity.class.getName()));
    startActivityForResult(intent, Const.RequestCode.ADDRESS_SEARCH);
}