Example usage for android.content Intent getFlags

List of usage examples for android.content Intent getFlags

Introduction

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

Prototype

public @Flags int getFlags() 

Source Link

Document

Retrieve any special flags associated with this intent.

Usage

From source file:org.cafemember.ui.LaunchActivity.java

private boolean handleIntent(Intent intent, boolean isNew, boolean restore, boolean fromPassword) {
    int flags = intent.getFlags();
    if (!fromPassword && (AndroidUtilities.needShowPasscode(true) || UserConfig.isWaitingForPasscodeEnter)) {
        showPasscodeActivity();/*w  w w .ja v  a 2s. c om*/
        passcodeSaveIntent = intent;
        passcodeSaveIntentIsNew = isNew;
        passcodeSaveIntentIsRestore = restore;
        UserConfig.saveConfig(false);
    } else {
        boolean pushOpened = false;

        Integer push_user_id = 0;
        Integer push_chat_id = 0;
        Integer push_enc_id = 0;
        Integer open_settings = 0;
        long dialogId = intent != null && intent.getExtras() != null ? intent.getExtras().getLong("dialogId", 0)
                : 0;
        boolean showDialogsList = false;
        boolean showPlayer = false;

        photoPathsArray = null;
        videoPath = null;
        sendingText = null;
        documentsPathsArray = null;
        documentsOriginalPathsArray = null;
        documentsMimeType = null;
        documentsUrisArray = null;
        contactsToSend = null;

        if (UserConfig.isClientActivated() && (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
            if (intent != null && intent.getAction() != null && !restore) {
                if (Intent.ACTION_SEND.equals(intent.getAction())) {
                    boolean error = false;
                    String type = intent.getType();
                    if (type != null && type.equals(ContactsContract.Contacts.CONTENT_VCARD_TYPE)) {
                        try {
                            Uri uri = (Uri) intent.getExtras().get(Intent.EXTRA_STREAM);
                            if (uri != null) {
                                ContentResolver cr = getContentResolver();
                                InputStream stream = cr.openInputStream(uri);

                                String name = null;
                                String nameEncoding = null;
                                String nameCharset = null;
                                ArrayList<String> phones = new ArrayList<>();
                                BufferedReader bufferedReader = new BufferedReader(
                                        new InputStreamReader(stream, "UTF-8"));
                                String line;
                                while ((line = bufferedReader.readLine()) != null) {
                                    String[] args = line.split(":");
                                    if (args.length != 2) {
                                        continue;
                                    }
                                    if (args[0].startsWith("FN")) {
                                        String[] params = args[0].split(";");
                                        for (String param : params) {
                                            String[] args2 = param.split("=");
                                            if (args2.length != 2) {
                                                continue;
                                            }
                                            if (args2[0].equals("CHARSET")) {
                                                nameCharset = args2[1];
                                            } else if (args2[0].equals("ENCODING")) {
                                                nameEncoding = args2[1];
                                            }
                                        }
                                        name = args[1];
                                        if (nameEncoding != null
                                                && nameEncoding.equalsIgnoreCase("QUOTED-PRINTABLE")) {
                                            while (name.endsWith("=") && nameEncoding != null) {
                                                name = name.substring(0, name.length() - 1);
                                                line = bufferedReader.readLine();
                                                if (line == null) {
                                                    break;
                                                }
                                                name += line;
                                            }
                                            byte[] bytes = AndroidUtilities
                                                    .decodeQuotedPrintable(name.getBytes());
                                            if (bytes != null && bytes.length != 0) {
                                                String decodedName = new String(bytes, nameCharset);
                                                if (decodedName != null) {
                                                    name = decodedName;
                                                }
                                            }
                                        }
                                    } else if (args[0].startsWith("TEL")) {
                                        String phone = PhoneFormat.stripExceptNumbers(args[1], true);
                                        if (phone.length() > 0) {
                                            phones.add(phone);
                                        }
                                    }
                                }
                                try {
                                    bufferedReader.close();
                                    stream.close();
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                if (name != null && !phones.isEmpty()) {
                                    contactsToSend = new ArrayList<>();
                                    for (String phone : phones) {
                                        TLRPC.User user = new TLRPC.TL_userContact_old2();
                                        user.phone = phone;
                                        user.first_name = name;
                                        user.last_name = "";
                                        user.id = 0;
                                        contactsToSend.add(user);
                                    }
                                }
                            } else {
                                error = true;
                            }
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                            error = true;
                        }
                    } else {
                        String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                        if (text == null) {
                            CharSequence textSequence = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
                            if (textSequence != null) {
                                text = textSequence.toString();
                            }
                        }
                        String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);

                        if (text != null && text.length() != 0) {
                            if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null
                                    && subject.length() != 0) {
                                text = subject + "\n" + text;
                            }
                            sendingText = text;
                        } else if (subject != null && subject.length() > 0) {
                            sendingText = subject;
                        }

                        Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                        if (parcelable != null) {
                            String path;
                            if (!(parcelable instanceof Uri)) {
                                parcelable = Uri.parse(parcelable.toString());
                            }
                            Uri uri = (Uri) parcelable;
                            if (uri != null) {
                                if (isInternalUri(uri)) {
                                    error = true;
                                }
                            }
                            if (!error) {
                                if (uri != null && (type != null && type.startsWith("image/")
                                        || uri.toString().toLowerCase().endsWith(".jpg"))) {
                                    if (photoPathsArray == null) {
                                        photoPathsArray = new ArrayList<>();
                                    }
                                    photoPathsArray.add(uri);
                                } else {
                                    path = AndroidUtilities.getPath(uri);
                                    if (path != null) {
                                        if (path.startsWith("file:")) {
                                            path = path.replace("file://", "");
                                        }
                                        if (type != null && type.startsWith("video/")) {
                                            videoPath = path;
                                        } else {
                                            if (documentsPathsArray == null) {
                                                documentsPathsArray = new ArrayList<>();
                                                documentsOriginalPathsArray = new ArrayList<>();
                                            }
                                            documentsPathsArray.add(path);
                                            documentsOriginalPathsArray.add(uri.toString());
                                        }
                                    } else {
                                        if (documentsUrisArray == null) {
                                            documentsUrisArray = new ArrayList<>();
                                        }
                                        documentsUrisArray.add(uri);
                                        documentsMimeType = type;
                                    }
                                }
                                if (sendingText != null) {
                                    if (sendingText.contains("WhatsApp")) { //remove unnecessary caption 'sent from WhatsApp' from photos forwarded from WhatsApp
                                        sendingText = null;
                                    }
                                }
                            }
                        } else if (sendingText == null) {
                            error = true;
                        }
                    }
                    if (error) {
                        Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
                    }
                } else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
                    boolean error = false;
                    try {
                        ArrayList<Parcelable> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                        String type = intent.getType();
                        if (uris != null) {
                            for (int a = 0; a < uris.size(); a++) {
                                Parcelable parcelable = uris.get(a);
                                if (!(parcelable instanceof Uri)) {
                                    parcelable = Uri.parse(parcelable.toString());
                                }
                                Uri uri = (Uri) parcelable;
                                if (uri != null) {
                                    if (isInternalUri(uri)) {
                                        uris.remove(a);
                                        a--;
                                    }
                                }
                            }
                            if (uris.isEmpty()) {
                                uris = null;
                            }
                        }
                        if (uris != null) {
                            if (type != null && type.startsWith("image/")) {
                                for (int a = 0; a < uris.size(); a++) {
                                    Parcelable parcelable = uris.get(a);
                                    if (!(parcelable instanceof Uri)) {
                                        parcelable = Uri.parse(parcelable.toString());
                                    }
                                    Uri uri = (Uri) parcelable;
                                    if (photoPathsArray == null) {
                                        photoPathsArray = new ArrayList<>();
                                    }
                                    photoPathsArray.add(uri);
                                }
                            } else {
                                for (int a = 0; a < uris.size(); a++) {
                                    Parcelable parcelable = uris.get(a);
                                    if (!(parcelable instanceof Uri)) {
                                        parcelable = Uri.parse(parcelable.toString());
                                    }
                                    String path = AndroidUtilities.getPath((Uri) parcelable);
                                    String originalPath = parcelable.toString();
                                    if (originalPath == null) {
                                        originalPath = path;
                                    }
                                    if (path != null) {
                                        if (path.startsWith("file:")) {
                                            path = path.replace("file://", "");
                                        }
                                        if (documentsPathsArray == null) {
                                            documentsPathsArray = new ArrayList<>();
                                            documentsOriginalPathsArray = new ArrayList<>();
                                        }
                                        documentsPathsArray.add(path);
                                        documentsOriginalPathsArray.add(originalPath);
                                    }
                                }
                            }
                        } else {
                            error = true;
                        }
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                        error = true;
                    }
                    if (error) {
                        Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
                    }
                } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
                    Uri data = intent.getData();
                    if (data != null) {
                        String username = null;
                        String group = null;
                        String sticker = null;
                        String botUser = null;
                        String botChat = null;
                        String message = null;
                        Integer messageId = null;
                        boolean hasUrl = false;
                        String scheme = data.getScheme();
                        if (scheme != null) {
                            if ((scheme.equals("http") || scheme.equals("https"))) {
                                String host = data.getHost().toLowerCase();
                                if (host.equals("telegram.me") || host.equals("telegram.dog")) {
                                    String path = data.getPath();
                                    if (path != null && path.length() > 1) {
                                        path = path.substring(1);
                                        if (path.startsWith("joinchat/")) {
                                            group = path.replace("joinchat/", "");
                                        } else if (path.startsWith("addstickers/")) {
                                            sticker = path.replace("addstickers/", "");
                                        } else if (path.startsWith("msg/") || path.startsWith("share/")) {
                                            message = data.getQueryParameter("url");
                                            if (message == null) {
                                                message = "";
                                            }
                                            if (data.getQueryParameter("text") != null) {
                                                if (message.length() > 0) {
                                                    hasUrl = true;
                                                    message += "\n";
                                                }
                                                message += data.getQueryParameter("text");
                                            }
                                        } else if (path.length() >= 1) {
                                            List<String> segments = data.getPathSegments();
                                            if (segments.size() > 0) {
                                                username = segments.get(0);
                                                if (segments.size() > 1) {
                                                    messageId = Utilities.parseInt(segments.get(1));
                                                    if (messageId == 0) {
                                                        messageId = null;
                                                    }
                                                }
                                            }
                                            botUser = data.getQueryParameter("start");
                                            botChat = data.getQueryParameter("startgroup");
                                        }
                                    }
                                }
                            } else if (scheme.equals("tg")) {
                                String url = data.toString();
                                if (url.startsWith("tg:resolve") || url.startsWith("tg://resolve")) {
                                    url = url.replace("tg:resolve", "tg://telegram.org").replace("tg://resolve",
                                            "tg://telegram.org");
                                    data = Uri.parse(url);
                                    username = data.getQueryParameter("domain");
                                    botUser = data.getQueryParameter("start");
                                    botChat = data.getQueryParameter("startgroup");
                                } else if (url.startsWith("tg:join") || url.startsWith("tg://join")) {
                                    url = url.replace("tg:join", "tg://telegram.org").replace("tg://join",
                                            "tg://telegram.org");
                                    data = Uri.parse(url);
                                    group = data.getQueryParameter("invite");
                                } else if (url.startsWith("tg:addstickers")
                                        || url.startsWith("tg://addstickers")) {
                                    url = url.replace("tg:addstickers", "tg://telegram.org")
                                            .replace("tg://addstickers", "tg://telegram.org");
                                    data = Uri.parse(url);
                                    sticker = data.getQueryParameter("set");
                                } else if (url.startsWith("tg:msg") || url.startsWith("tg://msg")
                                        || url.startsWith("tg://share") || url.startsWith("tg:share")) {
                                    url = url.replace("tg:msg", "tg://telegram.org")
                                            .replace("tg://msg", "tg://telegram.org")
                                            .replace("tg://share", "tg://telegram.org")
                                            .replace("tg:share", "tg://telegram.org");
                                    data = Uri.parse(url);
                                    message = data.getQueryParameter("url");
                                    if (message == null) {
                                        message = "";
                                    }
                                    if (data.getQueryParameter("text") != null) {
                                        if (message.length() > 0) {
                                            hasUrl = true;
                                            message += "\n";
                                        }
                                        message += data.getQueryParameter("text");
                                    }
                                }
                            }
                        }
                        if (username != null || group != null || sticker != null || message != null) {
                            runLinkRequest(username, group, sticker, botUser, botChat, message, hasUrl,
                                    messageId, 0);
                        } else {
                            try {
                                Cursor cursor = getContentResolver().query(intent.getData(), null, null, null,
                                        null);
                                if (cursor != null) {
                                    if (cursor.moveToFirst()) {
                                        int userId = cursor.getInt(cursor.getColumnIndex("DATA4"));
                                        NotificationCenter.getInstance()
                                                .postNotificationName(NotificationCenter.closeChats);
                                        push_user_id = userId;
                                    }
                                    cursor.close();
                                }
                            } catch (Exception e) {
                                FileLog.e("tmessages", e);
                            }
                        }
                    }
                } else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) {
                    open_settings = 1;
                } else if (intent.getAction().startsWith("com.tmessages.openchat")) {
                    int chatId = intent.getIntExtra("chatId", 0);
                    int userId = intent.getIntExtra("userId", 0);
                    int encId = intent.getIntExtra("encId", 0);
                    if (chatId != 0) {
                        NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                        push_chat_id = chatId;
                    } else if (userId != 0) {
                        NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                        push_user_id = userId;
                    } else if (encId != 0) {
                        NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                        push_enc_id = encId;
                    } else {
                        showDialogsList = true;
                    }
                } else if (intent.getAction().equals("com.tmessages.openplayer")) {
                    showPlayer = true;
                }
            }
        }

        if (push_user_id != 0) {
            Bundle args = new Bundle();
            args.putInt("user_id", push_user_id);
            if (mainFragmentsStack.isEmpty() || MessagesController.checkCanOpenChat(args,
                    mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
                ChatActivity fragment = new ChatActivity(args);
                if (actionBarLayout.presentFragment(fragment, false, true, true)) {
                    pushOpened = true;
                }
            }
        } else if (push_chat_id != 0) {
            Bundle args = new Bundle();
            args.putInt("chat_id", push_chat_id);
            if (mainFragmentsStack.isEmpty() || MessagesController.checkCanOpenChat(args,
                    mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
                ChatActivity fragment = new ChatActivity(args);
                if (actionBarLayout.presentFragment(fragment, false, true, true)) {
                    pushOpened = true;
                }
            }
        } else if (push_enc_id != 0) {
            Bundle args = new Bundle();
            args.putInt("enc_id", push_enc_id);
            ChatActivity fragment = new ChatActivity(args);
            if (actionBarLayout.presentFragment(fragment, false, true, true)) {
                pushOpened = true;
            }
        } else if (showDialogsList) {
            if (!AndroidUtilities.isTablet()) {
                actionBarLayout.removeAllFragments();
            } else {
                if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
                    for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
                        layersActionBarLayout
                                .removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
                        a--;
                    }
                    layersActionBarLayout.closeLastFragment(false);
                }
            }
            pushOpened = false;
            isNew = false;
        } else if (showPlayer) {
            if (AndroidUtilities.isTablet()) {
                for (int a = 0; a < layersActionBarLayout.fragmentsStack.size(); a++) {
                    BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(a);
                    if (fragment instanceof AudioPlayerActivity) {
                        layersActionBarLayout.removeFragmentFromStack(fragment);
                        break;
                    }
                }
                actionBarLayout.showLastFragment();
                rightActionBarLayout.showLastFragment();
                drawerLayoutContainer.setAllowOpenDrawer(false, false);
            } else {
                for (int a = 0; a < actionBarLayout.fragmentsStack.size(); a++) {
                    BaseFragment fragment = actionBarLayout.fragmentsStack.get(a);
                    if (fragment instanceof AudioPlayerActivity) {
                        actionBarLayout.removeFragmentFromStack(fragment);
                        break;
                    }
                }
                drawerLayoutContainer.setAllowOpenDrawer(true, false);
            }
            actionBarLayout.presentFragment(new AudioPlayerActivity(), false, true, true);
            pushOpened = true;
        } else if (videoPath != null || photoPathsArray != null || sendingText != null
                || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
            if (!AndroidUtilities.isTablet()) {
                NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
            }
            if (dialogId == 0) {
                Bundle args = new Bundle();
                args.putBoolean("onlySelect", true);
                if (contactsToSend != null) {
                    args.putString("selectAlertString",
                            LocaleController.getString("SendContactTo", R.string.SendMessagesTo));
                    args.putString("selectAlertStringGroup",
                            LocaleController.getString("SendContactToGroup", R.string.SendContactToGroup));
                } else {
                    args.putString("selectAlertString",
                            LocaleController.getString("SendMessagesTo", R.string.SendMessagesTo));
                    args.putString("selectAlertStringGroup",
                            LocaleController.getString("SendMessagesToGroup", R.string.SendMessagesToGroup));
                }
                DialogsActivity fragment = new DialogsActivity(args);
                dialogsFragment = fragment;
                fragment.setDelegate(this);
                boolean removeLast;
                if (AndroidUtilities.isTablet()) {
                    removeLast = layersActionBarLayout.fragmentsStack.size() > 0
                            && layersActionBarLayout.fragmentsStack.get(
                                    layersActionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
                } else {
                    removeLast = actionBarLayout.fragmentsStack.size() > 1 && actionBarLayout.fragmentsStack
                            .get(actionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
                }
                actionBarLayout.presentFragment(fragment, removeLast, true, true);
                pushOpened = true;
                if (PhotoViewer.getInstance().isVisible()) {
                    PhotoViewer.getInstance().closePhoto(false, true);
                }

                drawerLayoutContainer.setAllowOpenDrawer(false, false);
                if (AndroidUtilities.isTablet()) {
                    actionBarLayout.showLastFragment();
                    rightActionBarLayout.showLastFragment();
                } else {
                    drawerLayoutContainer.setAllowOpenDrawer(true, false);
                }
            } else {
                didSelectDialog(null, dialogId, false);
            }
        } else if (open_settings != 0) {
            actionBarLayout.presentFragment(new SettingsActivity(), false, true, true);
            if (AndroidUtilities.isTablet()) {
                actionBarLayout.showLastFragment();
                rightActionBarLayout.showLastFragment();
                drawerLayoutContainer.setAllowOpenDrawer(false, false);
            } else {
                drawerLayoutContainer.setAllowOpenDrawer(true, false);
            }
            pushOpened = true;
        }

        if (!pushOpened && !isNew) {
            if (AndroidUtilities.isTablet()) {
                if (!UserConfig.isClientActivated()) {
                    if (layersActionBarLayout.fragmentsStack.isEmpty()) {
                        layersActionBarLayout.addFragmentToStack(new LoginActivity());
                        drawerLayoutContainer.setAllowOpenDrawer(false, false);
                    }
                } else {
                    if (actionBarLayout.fragmentsStack.isEmpty()) {
                        actionBarLayout.addFragmentToStack(new DialogsActivity(null));
                        drawerLayoutContainer.setAllowOpenDrawer(true, false);
                    }
                }
            } else {
                if (actionBarLayout.fragmentsStack.isEmpty()) {
                    if (!UserConfig.isClientActivated()) {
                        actionBarLayout.addFragmentToStack(new LoginActivity());
                        drawerLayoutContainer.setAllowOpenDrawer(false, false);
                    } else {
                        actionBarLayout.addFragmentToStack(new DialogsActivity(null));
                        drawerLayoutContainer.setAllowOpenDrawer(true, false);
                    }
                }
            }
            actionBarLayout.showLastFragment();
            if (AndroidUtilities.isTablet()) {
                layersActionBarLayout.showLastFragment();
                rightActionBarLayout.showLastFragment();
            }
        }

        intent.setAction(null);
        return pushOpened;
    }
    return false;
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }/*  ww w.j ava  2  s .  co  m*/
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        final boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();
        mWorkspace.requestFocus();

        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps customize page
        if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
            mAppsCustomizeTabHost.reset();
        }
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }
}

From source file:org.appspot.apprtc.CallActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == FILE_CODE && resultCode == Activity.RESULT_OK) {
        Uri path = intent.getData();//from w  w  w. j  a  v  a 2 s.c o m
        long size = 0;
        String name = "";
        ContentResolver cr = this.getContentResolver();
        String mime = cr.getType(path);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            size = TokenPeerConnection.getContentSize(path, this);
            name = TokenPeerConnection.getContentName(path, this);

            final int takeFlags = intent.getFlags()
                    & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            // Check for the freshest data.
            getContentResolver().takePersistableUriPermission(path,
                    Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else {
            size = TokenPeerConnection.getContentSize(path, this);
            name = TokenPeerConnection.getContentName(path, this);
        }

        // Do something with the result...
        if (mService != null) {
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
            fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
            String time = fmt.format(new Date());
            FileInfo fileInfo = new FileInfo("", "", name, String.valueOf(size), mime);
            mService.sendFileMessage(time, mService.getAccountName(), "self", fileInfo, path.toString(), size,
                    name, mime, mFileRecipient, mService.getCurrentRoomName());

            ChatItem item = new ChatItem(time, mService.getAccountName(), fileInfo, "self", mFileRecipient);
            item.setOutgoing();

            chatFragment.addOutgoingMessage(item);
        }

    }
}

From source file:im.neon.activity.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (null == getIntent()) {
        Log.d(LOG_TAG, "## onCreate(): IN with no intent");
    } else {/*w  w  w  .  j a v  a  2 s. c o  m*/
        Log.d(LOG_TAG, "## onCreate(): IN with flags " + Integer.toHexString(getIntent().getFlags()));
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vector_login);

    // warn that the application has started.
    CommonActivityUtils.onApplicationStarted(this);

    Intent intent = getIntent();
    Bundle receivedBundle = (null != intent) ? getIntent().getExtras() : null;

    // resume the application
    if (null != receivedBundle) {
        if (receivedBundle.containsKey(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI)) {
            mUniversalLinkUri = receivedBundle
                    .getParcelable(VectorUniversalLinkReceiver.EXTRA_UNIVERSAL_LINK_URI);
            Log.d(LOG_TAG, "## onCreate() Login activity started by universal link");
            // activity has been launched from an universal link
        } else if (receivedBundle.containsKey(VectorRegistrationReceiver.EXTRA_EMAIL_VALIDATION_PARAMS)) {
            Log.d(LOG_TAG, "## onCreate() Login activity started by email verification for registration");
            processEmailValidationExtras(receivedBundle);
        }
    }
    // already registered
    if (hasCredentials()) {
        if ((null != intent) && (intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) == 0) {
            Log.d(LOG_TAG, "## onCreate(): goToSplash because the credentials are already provided.");
            goToSplash();
        } else {
            // detect if the application has already been started
            if (null == EventStreamService.getInstance()) {
                Log.d(LOG_TAG,
                        "## onCreate(): goToSplash with credentials but there is no event stream service.");
                goToSplash();
            } else {
                Log.d(LOG_TAG, "## onCreate(): close the login screen because it is a temporary task");
            }
        }

        finish();
        return;
    }

    // bind UI widgets
    mLoginMaskView = (RelativeLayout) findViewById(R.id.flow_ui_mask_login);

    // login
    mLoginEmailTextView = (EditText) findViewById(R.id.login_user_name);
    mLoginPhoneNumber = (EditText) findViewById(R.id.login_phone_number_value);
    mLoginPhoneNumberCountryCode = (EditText) findViewById(R.id.login_phone_number_country);
    mLoginPasswordTextView = (EditText) findViewById(R.id.login_password);

    // account creation
    mCreationUsernameTextView = (EditText) findViewById(R.id.creation_your_name);
    mCreationPassword1TextView = (EditText) findViewById(R.id.creation_password1);
    mCreationPassword2TextView = (EditText) findViewById(R.id.creation_password2);

    // account creation - three pid
    mThreePidInstructions = (TextView) findViewById(R.id.instructions);
    mEmailAddress = (EditText) findViewById(R.id.registration_email);
    mPhoneNumberLayout = findViewById(R.id.registration_phone_number);
    mPhoneNumber = (EditText) findViewById(R.id.registration_phone_number_value);
    mPhoneNumberCountryCode = (EditText) findViewById(R.id.registration_phone_number_country);
    mSubmitThreePidButton = (Button) findViewById(R.id.button_submit);
    mSkipThreePidButton = (Button) findViewById(R.id.button_skip);

    // forgot password
    mPasswordForgottenTxtView = (TextView) findViewById(R.id.login_forgot_password);
    mForgotEmailTextView = (TextView) findViewById(R.id.forget_email_address);
    mForgotPassword1TextView = (EditText) findViewById(R.id.forget_new_password);
    mForgotPassword2TextView = (EditText) findViewById(R.id.forget_confirm_new_password);

    mHomeServerOptionLayout = findViewById(R.id.homeserver_layout);
    mHomeServerText = (EditText) findViewById(R.id.login_matrix_server_url);
    mIdentityServerText = (EditText) findViewById(R.id.login_identity_url);

    mLoginButton = (Button) findViewById(R.id.button_login);
    mRegisterButton = (Button) findViewById(R.id.button_register);
    mForgotPasswordButton = (Button) findViewById(R.id.button_reset_password);
    mForgotValidateEmailButton = (Button) findViewById(R.id.button_forgot_email_validate);

    mHomeServerUrlsLayout = findViewById(R.id.login_matrix_server_options_layout);
    mUseCustomHomeServersCheckbox = (CheckBox) findViewById(R.id.display_server_url_expand_checkbox);

    mProgressTextView = (TextView) findViewById(R.id.flow_progress_message_textview);

    mMainLayout = findViewById(R.id.main_input_layout);
    mButtonsView = findViewById(R.id.login_actions_bar);

    if (null != savedInstanceState) {
        restoreSavedData(savedInstanceState);
    } else {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
        mHomeServerText.setText(preferences.getString(HOME_SERVER_URL_PREF,
                getResources().getString(R.string.default_hs_server_url)));
        mIdentityServerText.setText(preferences.getString(IDENTITY_SERVER_URL_PREF,
                getResources().getString(R.string.default_identity_server_url)));
    }

    // trap the UI events
    mLoginMaskView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        }
    });

    mLoginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onLoginClick();
        }
    });

    // account creation handler
    mRegisterButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mIsUserNameAvailable = false;
            onRegisterClick(true);
        }
    });

    // forgot password button
    mForgotPasswordButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onForgotPasswordClick();
        }
    });

    mForgotValidateEmailButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onForgotOnEmailValidated(getHsConfig());
        }
    });

    // home server input validity: if the user taps on the next / done button
    mHomeServerText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                onHomeServerUrlUpdate();
                return true;
            }

            return false;
        }
    });

    // home server input validity: when focus changes
    mHomeServerText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                onHomeServerUrlUpdate();
            }
        }
    });

    // identity server input validity: if the user taps on the next / done button
    mIdentityServerText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                onIdentityserverUrlUpdate();
                return true;
            }

            return false;
        }
    });

    // identity server input validity: when focus changes
    mIdentityServerText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                onIdentityserverUrlUpdate();
            }
        }
    });

    // "forgot password?" handler
    mPasswordForgottenTxtView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mMode = MODE_FORGOT_PASSWORD;
            refreshDisplay();
        }
    });

    mUseCustomHomeServersCheckbox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mUseCustomHomeServersCheckbox.post(new Runnable() {
                @Override
                public void run() {
                    // reset the HS urls.
                    mHomeServerUrl = null;
                    mIdentityServerUrl = null;
                    onIdentityserverUrlUpdate();
                    onHomeServerUrlUpdate();
                    refreshDisplay();
                }
            });
        }
    });

    mLoginPhoneNumberHandler = new PhoneNumberHandler(this, mLoginPhoneNumber, mLoginPhoneNumberCountryCode,
            PhoneNumberHandler.DISPLAY_COUNTRY_ISO_CODE, REQUEST_LOGIN_COUNTRY);
    mLoginPhoneNumberHandler.setCountryCode(PhoneNumberUtils.getCountryCode(this));
    mRegistrationPhoneNumberHandler = new PhoneNumberHandler(this, mPhoneNumber, mPhoneNumberCountryCode,
            PhoneNumberHandler.DISPLAY_COUNTRY_ISO_CODE, REQUEST_REGISTRATION_COUNTRY);

    refreshDisplay();

    // reset the badge counter
    CommonActivityUtils.updateBadgeCount(this, 0);

    mHomeServerText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString(HOME_SERVER_URL_PREF, mHomeServerText.getText().toString().trim());
            editor.apply();
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    mIdentityServerText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString(IDENTITY_SERVER_URL_PREF, mIdentityServerText.getText().toString().trim());
            editor.apply();
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    // set the handler used by the register to poll the server response
    mHandler = new Handler(getMainLooper());
}

From source file:com.android.launcher2.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();//  w ww.  ja  v  a  2s .  com

        final boolean alreadyOnHome = ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        Runnable processIntent = new Runnable() {
            public void run() {
                if (mWorkspace == null) {
                    // Can be cases where mWorkspace is null, this prevents a NPE
                    return;
                }
                Folder openFolder = mWorkspace.getOpenFolder();
                // In all these cases, only animate if we're already on home
                mWorkspace.exitWidgetResizeMode();
                if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()
                        && openFolder == null) {
                    mWorkspace.moveToDefaultScreen(true);
                }

                closeFolder();
                exitSpringLoadedDragMode();

                // If we are already on home, then just animate back to the workspace,
                // otherwise, just wait until onResume to set the state back to Workspace
                if (alreadyOnHome) {
                    showWorkspace(true);
                } else {
                    mOnResumeState = State.WORKSPACE;
                }

                final View v = getWindow().peekDecorView();
                if (v != null && v.getWindowToken() != null) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }

                // Reset AllApps to its initial state
                if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
                    mAppsCustomizeTabHost.reset();
                }
            }
        };

        if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
            // Delay processing of the intent to allow the status bar animation to finish
            // first in order to avoid janky animations.
            mWorkspace.postDelayed(processIntent, 350);
        } else {
            // Process the intent immediately.
            processIntent.run();
        }

    }
}

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();//from  w w  w . j  av a 2 s .  c  o m

        final boolean alreadyOnHome = ((intent.getFlags()
                & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

        Runnable processIntent = new Runnable() {
            public void run() {
                Folder openFolder = mWorkspace.getOpenFolder();
                // In all these cases, only animate if we're already on home
                mWorkspace.exitWidgetResizeMode();
                if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()
                        && openFolder == null) {
                    mWorkspace.moveToDefaultScreen(true);
                }

                closeFolder();
                exitSpringLoadedDragMode();

                // If we are already on home, then just animate back to the workspace,
                // otherwise, just wait until onResume to set the state back to Workspace
                if (alreadyOnHome) {
                    showWorkspace(true);
                } else {
                    mOnResumeState = State.WORKSPACE;
                }

                final View v = getWindow().peekDecorView();
                if (v != null && v.getWindowToken() != null) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }

                // Reset AllApps to its initial state
                if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
                    mAppsCustomizeTabHost.reset();
                }
            }
        };

        if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
            // Delay processing of the intent to allow the status bar animation to finish
            // first in order to avoid janky animations.
            mWorkspace.postDelayed(processIntent, 350);
        } else {
            // Process the intent immediately.
            processIntent.run();
        }

    }
}

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_FILE_CODE) {

            final Uri data = intent.getData();
            final GreatUri newUri = new GreatUri(data, AccessStorageApi.getPath(this, data),
                    AccessStorageApi.getName(this, data));

            newFileToOpen(newUri, "");
        } else if (requestCode == SELECT_FOLDER_CODE) {
            FileFilter fileFilter = new FileFilter() {
                public boolean accept(File file) {
                    return file.isFile();
                }//from   w  ww  .jav a2 s.  co  m
            };
            final Uri data = intent.getData();
            File dir = new File(data.getPath());
            File[] fileList = dir.listFiles(fileFilter);
            for (int i = 0; i < fileList.length; i++) {
                Uri particularUri = Uri.parse("file://" + fileList[i].getPath());
                final GreatUri newUri = new GreatUri(particularUri,
                        AccessStorageApi.getPath(this, particularUri),
                        AccessStorageApi.getName(this, particularUri));
                greatUris.add(newUri);

                refreshList(newUri, true, false);
                arrayAdapter.selectPosition(newUri);
            }
            if (fileList.length > 0) {
                Uri particularUri = Uri.parse("file://" + fileList[0].getPath());
                final GreatUri newUri = new GreatUri(particularUri,
                        AccessStorageApi.getPath(this, particularUri),
                        AccessStorageApi.getName(this, particularUri));
                newFileToOpen(newUri, "");
            }

        } else {

            final Uri data = intent.getData();
            final GreatUri newUri = new GreatUri(data, AccessStorageApi.getPath(this, data),
                    AccessStorageApi.getName(this, data));

            // grantUriPermission(getPackageName(), data, Intent.FLAG_GRANT_READ_URI_PERMISSION);
            final int takeFlags = intent.getFlags()
                    & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            // Check for the freshest data.
            getContentResolver().takePersistableUriPermission(data, takeFlags);

            if (requestCode == READ_REQUEST_CODE || requestCode == CREATE_REQUEST_CODE) {

                newFileToOpen(newUri, "");
            }

            if (requestCode == SAVE_AS_REQUEST_CODE) {

                new SaveFileTask(this, newUri, pageSystem.getAllText(mEditor.getText().toString()),
                        currentEncoding, new SaveFileTask.SaveFileInterface() {
                            @Override
                            public void fileSaved(Boolean success) {
                                savedAFile(greatUri, false);
                                newFileToOpen(newUri, "");
                            }
                        }).execute();
            }
        }

    }
}

From source file:com.android.launcher3.Launcher.java

@Override
protected void onNewIntent(Intent intent) {
    long startTime = 0;
    if (DEBUG_RESUME_TIME) {
        startTime = System.currentTimeMillis();
    }// w w  w.  j  av a2s.c o  m
    super.onNewIntent(intent);

    boolean alreadyOnHome = mHasFocus && ((intent.getFlags()
            & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

    // Check this condition before handling isActionMain, as this will get reset.
    boolean shouldMoveToDefaultScreen = alreadyOnHome && mState == State.WORKSPACE
            && getTopFloatingView() == null;

    boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
    if (isActionMain) {
        // also will cancel mWaitingForResult.
        closeSystemDialogs();

        if (mWorkspace == null) {
            // Can be cases where mWorkspace is null, this prevents a NPE
            return;
        }
        // In all these cases, only animate if we're already on home
        mWorkspace.exitWidgetResizeMode();

        closeFolder(alreadyOnHome);
        closeShortcutsContainer(alreadyOnHome);
        exitSpringLoadedDragMode();

        // If we are already on home, then just animate back to the workspace,
        // otherwise, just wait until onResume to set the state back to Workspace
        if (alreadyOnHome) {
            showWorkspace(true);
        } else {
            mOnResumeState = State.WORKSPACE;
        }

        final View v = getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }

        // Reset the apps view
        if (!alreadyOnHome && mAppsView != null) {
            mAppsView.scrollToTop();
        }

        // Reset the widgets view
        if (!alreadyOnHome && mWidgetsView != null) {
            mWidgetsView.scrollToTop();
        }

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onHomeIntent();
        }
    }

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onNewIntent(intent);
    }

    // Defer moving to the default screen until after we callback to the LauncherCallbacks
    // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
    // animation.
    if (isActionMain) {
        boolean callbackAllowsMoveToDefaultScreen = mLauncherCallbacks != null
                ? mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent()
                : true;
        if (shouldMoveToDefaultScreen && !mWorkspace.isTouchActive() && callbackAllowsMoveToDefaultScreen) {

            // We use this flag to suppress noisy callbacks above custom content state
            // from onResume.
            mMoveToDefaultScreenFromNewIntent = true;
            mWorkspace.post(new Runnable() {
                @Override
                public void run() {
                    if (mWorkspace != null) {
                        mWorkspace.moveToDefaultScreen(true);
                    }
                }
            });
        }
    }

    if (DEBUG_RESUME_TIME) {
        Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
    }
}

From source file:com.igniva.filemanager.activities.MainActivity.java

protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
    if (requestCode == RC_SIGN_IN && !mGoogleApiKey && mGoogleApiClient != null) {
        new Thread(new Runnable() {
            @Override//from  w  w  w . j a v  a 2 s . c  o  m
            public void run() {
                mIntentInProgress = false;
                mGoogleApiKey = true;
                // !mGoogleApiClient.isConnecting
                if (mGoogleApiClient.isConnecting()) {
                    mGoogleApiClient.connect();
                } else
                    mGoogleApiClient.disconnect();

            }
        }).run();
    } else if (requestCode == image_selector_request_code) {
        if (Sp != null && intent != null && intent.getData() != null) {
            if (Build.VERSION.SDK_INT >= 19)
                getContentResolver().takePersistableUriPermission(intent.getData(),
                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Sp.edit().putString("drawer_header_path", intent.getData().toString()).commit();
            setDrawerHeaderBackground();
        }
    } else if (requestCode == 3) {
        String p = Sp.getString("URI", null);

        Uri oldUri = p != null ? Uri.parse(p) : null;
        Uri treeUri = null;
        if (responseCode == Activity.RESULT_OK) {
            // Get Uri from Storage Access Framework.
            treeUri = intent.getData();
            // Persist URI - this is required for verification of writability.
            if (treeUri != null)
                Sp.edit().putString("URI", treeUri.toString()).commit();
        }
        // If not confirmed SAF, or if still not writable, then revert settings.
        if (responseCode != Activity.RESULT_OK) {
            /* DialogUtil.displayError(getActivity(), R.string.message_dialog_cannot_write_to_folder_saf, false,
                currentFolder);||!FileUtil.isWritableNormalOrSaf(currentFolder)
            */
            if (treeUri != null)
                Sp.edit().putString("URI", oldUri.toString()).commit();
            return;
        }

        // After confirmation, update stored value of folder.
        // Persist access permissions.
        final int takeFlags = intent.getFlags()
                & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
        switch (operation) {
        case DataUtils.DELETE://deletion
            new DeleteTask(null, mainActivity).execute((oparrayList));
            break;
        case DataUtils.COPY://copying
            Intent intent1 = new Intent(con, CopyService.class);
            intent1.putExtra("FILE_PATHS", (oparrayList));
            intent1.putExtra("COPY_DIRECTORY", oppathe);
            startService(intent1);
            break;
        case DataUtils.MOVE://moving
            new MoveFiles((oparrayList), ((Main) getFragment().getTab()),
                    ((Main) getFragment().getTab()).getActivity(), 0)
                            .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, path);
            break;
        case DataUtils.NEW_FOLDER://mkdir
            Main ma1 = ((Main) getFragment().getTab());
            mainActivityHelper.mkDir(RootHelper.generateBaseFile(new File(oppathe), true), ma1);
            break;
        case DataUtils.RENAME:
            mainActivityHelper.rename(HFile.LOCAL_MODE, (oppathe), (oppathe1), mainActivity,
                    BaseActivity.rootMode);
            Main ma2 = ((Main) getFragment().getTab());
            ma2.updateList();
            break;
        case DataUtils.NEW_FILE:
            Main ma3 = ((Main) getFragment().getTab());
            mainActivityHelper.mkFile(new HFile(HFile.LOCAL_MODE, oppathe), ma3);

            break;
        case DataUtils.EXTRACT:
            mainActivityHelper.extractFile(new File(oppathe));
            break;
        case DataUtils.COMPRESS:
            mainActivityHelper.compressFiles(new File(oppathe), oparrayList);
        }
        operation = -1;
    }
}

From source file:com.amaze.filemanager.activities.MainActivity.java

protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
    if (requestCode == RC_SIGN_IN && !mGoogleApiKey && mGoogleApiClient != null) {
        new Thread(new Runnable() {
            @Override/*from   w ww  .j a  v  a2  s .co  m*/
            public void run() {
                mIntentInProgress = false;
                mGoogleApiKey = true;
                // !mGoogleApiClient.isConnecting
                if (mGoogleApiClient.isConnecting()) {
                    mGoogleApiClient.connect();
                } else
                    mGoogleApiClient.disconnect();

            }
        }).run();
    } else if (requestCode == image_selector_request_code) {
        if (Sp != null && intent != null && intent.getData() != null) {
            if (Build.VERSION.SDK_INT >= 19)
                getContentResolver().takePersistableUriPermission(intent.getData(),
                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Sp.edit().putString("drawer_header_path", intent.getData().toString()).commit();
            setDrawerHeaderBackground();
        }
    } else if (requestCode == 3) {
        String p = Sp.getString("URI", null);
        Uri oldUri = null;
        if (p != null)
            oldUri = Uri.parse(p);
        Uri treeUri = null;
        if (responseCode == Activity.RESULT_OK) {
            // Get Uri from Storage Access Framework.
            treeUri = intent.getData();
            // Persist URI - this is required for verification of writability.
            if (treeUri != null)
                Sp.edit().putString("URI", treeUri.toString()).commit();
        }
        // If not confirmed SAF, or if still not writable, then revert settings.
        if (responseCode != Activity.RESULT_OK) {
            /* DialogUtil.displayError(getActivity(), R.string.message_dialog_cannot_write_to_folder_saf, false,
                currentFolder);||!FileUtil.isWritableNormalOrSaf(currentFolder)
            */
            if (treeUri != null)
                Sp.edit().putString("URI", oldUri.toString()).commit();
            return;
        }

        // After confirmation, update stored value of folder.
        // Persist access permissions.
        final int takeFlags = intent.getFlags()
                & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
        switch (operation) {
        case DataUtils.DELETE://deletion
            new DeleteTask(null, mainActivity).execute((oparrayList));
            break;
        case DataUtils.COPY://copying
            Intent intent1 = new Intent(con, CopyService.class);
            intent1.putExtra("FILE_PATHS", (oparrayList));
            intent1.putExtra("COPY_DIRECTORY", oppathe);
            startService(intent1);
            break;
        case DataUtils.MOVE://moving
            new MoveFiles((oparrayList), ((Main) getFragment().getTab()),
                    ((Main) getFragment().getTab()).getActivity(), 0)
                            .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, path);
            break;
        case DataUtils.NEW_FOLDER://mkdir
            Main ma1 = ((Main) getFragment().getTab());
            mainActivityHelper.mkDir(RootHelper.generateBaseFile(new File(oppathe), true), ma1);
            break;
        case DataUtils.RENAME:
            mainActivityHelper.rename(HFile.LOCAL_MODE, (oppathe), (oppathe1), mainActivity, rootmode);
            Main ma2 = ((Main) getFragment().getTab());
            ma2.updateList();
            break;
        case DataUtils.NEW_FILE:
            Main ma3 = ((Main) getFragment().getTab());
            mainActivityHelper.mkFile(new HFile(HFile.LOCAL_MODE, oppathe), ma3);

            break;
        case DataUtils.EXTRACT:
            mainActivityHelper.extractFile(new File(oppathe));
            break;
        case DataUtils.COMPRESS:
            mainActivityHelper.compressFiles(new File(oppathe), oparrayList);
        }
        operation = -1;
    }
}