Search in sources :

Example 1 with Pair

use of androidx.core.util.Pair in project android by owncloud.

the class FileSyncAdapter method synchronizeFolder.

/**
 * Synchronizes the list of files contained in a folder identified with its remote path.
 * <p>
 * Fetches the list and properties of the files contained in the given folder, including their
 * properties, and updates the local database with them.
 * <p>
 * Enters in the child folders to synchronize their contents also, following a recursive
 * depth first strategy.
 *
 * @param folder   Folder to synchronize.
 * @param pushOnly When 'true', it's assumed that the folder did not change in the
 *                 server, so data will not be fetched. Only local changes of
 *                 available offline files will be pushed.
 */
private void synchronizeFolder(OCFile folder, boolean pushOnly) {
    if (mFailedResultsCounter > MAX_FAILED_RESULTS || isFinisher(mLastFailedResult)) {
        return;
    }
    // folder synchronization
    SynchronizeFolderOperation synchFolderOp = new SynchronizeFolderOperation(getContext(), folder.getRemotePath(), getAccount(), mCurrentSyncTime, pushOnly, // sync full account
    true, // sync regular files in folder
    false);
    RemoteOperationResult result;
    boolean repeat;
    do {
        repeat = false;
        result = synchFolderOp.execute(getClient(), getStorageManager());
    } while (repeat);
    // synchronized folder -> notice to UI - ALWAYS, although !result.isSuccess
    sendLocalBroadcast(EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED, folder.getRemotePath(), result);
    // check the result of synchronizing the folder
    if (result.isSuccess() || result.getCode() == ResultCode.SYNC_CONFLICT) {
        if (result.getCode() == ResultCode.SYNC_CONFLICT) {
            mConflictsFound += synchFolderOp.getConflictsFound();
            mFailsInFavouritesFound += synchFolderOp.getFailsInFileSyncsFound();
        }
        if (result.isSuccess()) {
            // synchronize children folders
            List<Pair<OCFile, Boolean>> children = synchFolderOp.getFoldersToVisit();
            // beware of the 'hidden' recursion here!
            syncSubfolders(children);
        }
    } else if (result.getCode() != ResultCode.FILE_NOT_FOUND) {
        // in failures, the statistics for the global result are updated
        if (RemoteOperationResult.ResultCode.UNAUTHORIZED.equals(result.getCode())) {
            mSyncResult.stats.numAuthExceptions++;
        } else if (result.getException() instanceof DavException) {
            mSyncResult.stats.numParseExceptions++;
        } else if (result.getException() instanceof IOException) {
            mSyncResult.stats.numIoExceptions++;
        }
        mFailedResultsCounter++;
        mLastFailedResult = result;
    }
// else, ResultCode.FILE_NOT_FOUND is ignored, remote folder was
// removed from other thread or other client during the synchronization,
// before this thread fetched its contents
}
Also used : SynchronizeFolderOperation(com.owncloud.android.operations.SynchronizeFolderOperation) DavException(at.bitfire.dav4jvm.exception.DavException) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) IOException(java.io.IOException) Pair(androidx.core.util.Pair)

Example 2 with Pair

use of androidx.core.util.Pair in project kdeconnect-android by KDE.

the class RemoteKeyboardPlugin method handleSpecialKey.

private boolean handleSpecialKey(int key, boolean shift, boolean ctrl, boolean alt) {
    int keyEvent = specialKeyMap.get(key, 0);
    if (keyEvent == 0)
        return false;
    InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection();
    // special sequences:
    if (ctrl && (keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT)) {
        // Ctrl + right -> next word
        ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
        int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
        if (pos == -1)
            pos = currentTextLength(extractedText);
        else
            pos++;
        int startPos = pos;
        int endPos = pos;
        if (shift) {
            // Shift -> select word (otherwise jump)
            Pair<Integer, Integer> sel = currentSelection(extractedText);
            int cursor = currentCursorPos(extractedText);
            // Log.d("RemoteKeyboardPlugin", "Selection (to right): " + sel.first + " / " + sel.second + " cursor: " + cursor);
            startPos = cursor;
            if (// active selection from left to right -> grow
            sel.first < cursor || // active selection from right to left -> shrink
            sel.first > sel.second)
                startPos = sel.first;
        }
        inputConn.setSelection(startPos, endPos);
    } else if (ctrl && keyEvent == KeyEvent.KEYCODE_DPAD_LEFT) {
        // Ctrl + left -> previous word
        ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
        int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
        if (pos == -1)
            pos = 0;
        else
            pos++;
        int startPos = pos;
        int endPos = pos;
        if (shift) {
            Pair<Integer, Integer> sel = currentSelection(extractedText);
            int cursor = currentCursorPos(extractedText);
            // Log.d("RemoteKeyboardPlugin", "Selection (to left): " + sel.first + " / " + sel.second + " cursor: " + cursor);
            startPos = cursor;
            if (// active selection from right to left -> grow
            cursor < sel.first || // active selection from right to left -> shrink
            sel.first < sel.second)
                startPos = sel.first;
        }
        inputConn.setSelection(startPos, endPos);
    } else if (shift && (keyEvent == KeyEvent.KEYCODE_DPAD_LEFT || keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT || keyEvent == KeyEvent.KEYCODE_DPAD_UP || keyEvent == KeyEvent.KEYCODE_DPAD_DOWN || keyEvent == KeyEvent.KEYCODE_MOVE_HOME || keyEvent == KeyEvent.KEYCODE_MOVE_END)) {
        // Shift + up/down/left/right/home/end
        long now = SystemClock.uptimeMillis();
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
    } else if (keyEvent == KeyEvent.KEYCODE_NUMPAD_ENTER || keyEvent == KeyEvent.KEYCODE_ENTER) {
        // Enter key
        EditorInfo editorInfo = RemoteKeyboardService.instance.getCurrentInputEditorInfo();
        // Log.d("RemoteKeyboardPlugin", "Enter: " + editorInfo.imeOptions);
        if (editorInfo != null && (((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) || ctrl)) {
            // Ctrl+Return overrides IME_FLAG_NO_ENTER_ACTION (FIXME: make configurable?)
            // check for special DONE/GO/etc actions first:
            int[] actions = { EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_SEND, EditorInfo.IME_ACTION_SEARCH, // note: DONE should be last or we might hide the ime instead of "go"
            EditorInfo.IME_ACTION_DONE };
            for (int action : actions) {
                if ((editorInfo.imeOptions & action) == action) {
                    // Log.d("RemoteKeyboardPlugin", "Enter-action: " + actions[i]);
                    inputConn.performEditorAction(action);
                    return true;
                }
            }
        } else {
            // else: fall back to regular Enter-event:
            // Log.d("RemoteKeyboardPlugin", "Enter: normal keypress");
            inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
            inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
        }
    } else {
        // default handling:
        inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
        inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
    }
    return true;
}
Also used : InputConnection(android.view.inputmethod.InputConnection) KeyEvent(android.view.KeyEvent) EditorInfo(android.view.inputmethod.EditorInfo) ExtractedTextRequest(android.view.inputmethod.ExtractedTextRequest) ExtractedText(android.view.inputmethod.ExtractedText) Pair(androidx.core.util.Pair)

Example 3 with Pair

use of androidx.core.util.Pair in project AntennaPod by AntennaPod.

the class EpisodeActionFilter method getRemoteActionsOverridingLocalActions.

public static Map<Pair<String, String>, EpisodeAction> getRemoteActionsOverridingLocalActions(List<EpisodeAction> remoteActions, List<EpisodeAction> queuedEpisodeActions) {
    // make sure more recent local actions are not overwritten by older remote actions
    Map<Pair<String, String>, EpisodeAction> remoteActionsThatOverrideLocalActions = new ArrayMap<>();
    Map<Pair<String, String>, EpisodeAction> localMostRecentPlayActions = createUniqueLocalMostRecentPlayActions(queuedEpisodeActions);
    for (EpisodeAction remoteAction : remoteActions) {
        Pair<String, String> key = new Pair<>(remoteAction.getPodcast(), remoteAction.getEpisode());
        switch(remoteAction.getAction()) {
            case NEW:
                remoteActionsThatOverrideLocalActions.put(key, remoteAction);
                break;
            case DOWNLOAD:
                break;
            case PLAY:
                EpisodeAction localMostRecent = localMostRecentPlayActions.get(key);
                if (secondActionOverridesFirstAction(remoteAction, localMostRecent)) {
                    break;
                }
                EpisodeAction remoteMostRecentAction = remoteActionsThatOverrideLocalActions.get(key);
                if (secondActionOverridesFirstAction(remoteAction, remoteMostRecentAction)) {
                    break;
                }
                remoteActionsThatOverrideLocalActions.put(key, remoteAction);
                break;
            case DELETE:
                // NEVER EVER call DBWriter.deleteFeedMediaOfItem() here, leads to an infinite loop
                break;
            default:
                Log.e(TAG, "Unknown remoteAction: " + remoteAction);
                break;
        }
    }
    return remoteActionsThatOverrideLocalActions;
}
Also used : ArrayMap(androidx.collection.ArrayMap) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) Pair(androidx.core.util.Pair)

Example 4 with Pair

use of androidx.core.util.Pair in project AntennaPod by AntennaPod.

the class EpisodeActionFilter method createUniqueLocalMostRecentPlayActions.

private static Map<Pair<String, String>, EpisodeAction> createUniqueLocalMostRecentPlayActions(List<EpisodeAction> queuedEpisodeActions) {
    Map<Pair<String, String>, EpisodeAction> localMostRecentPlayAction;
    localMostRecentPlayAction = new ArrayMap<>();
    for (EpisodeAction action : queuedEpisodeActions) {
        Pair<String, String> key = new Pair<>(action.getPodcast(), action.getEpisode());
        EpisodeAction mostRecent = localMostRecentPlayAction.get(key);
        if (mostRecent == null || mostRecent.getTimestamp() == null) {
            localMostRecentPlayAction.put(key, action);
        } else if (mostRecent.getTimestamp().before(action.getTimestamp())) {
            localMostRecentPlayAction.put(key, action);
        }
    }
    return localMostRecentPlayAction;
}
Also used : EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) Pair(androidx.core.util.Pair)

Example 5 with Pair

use of androidx.core.util.Pair in project Douya by DreaminginCodeZH.

the class TransitionUtils method makeActivityOptionsBundle.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Bundle makeActivityOptionsBundle(Activity activity, View... sharedViews) {
    if (!shouldEnableTransition()) {
        return null;
    }
    ArrayList<Pair<View, String>> sharedElementList = new ArrayList<>();
    for (View sharedView : sharedViews) {
        sharedElementList.add(Pair.create(sharedView, sharedView.getTransitionName()));
    }
    View appbar = activity.findViewById(R.id.appBarWrapper);
    if (appbar != null) {
        sharedElementList.add(Pair.create(appbar, appbar.getTransitionName()));
    }
    // noinspection unchecked
    Pair<View, String>[] sharedElements = sharedElementList.toArray(new Pair[sharedElementList.size()]);
    // noinspection unchecked
    return ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElements).toBundle();
}
Also used : ArrayList(java.util.ArrayList) View(android.view.View) Pair(androidx.core.util.Pair) TargetApi(android.annotation.TargetApi)

Aggregations

Pair (androidx.core.util.Pair)31 ArrayList (java.util.ArrayList)9 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)7 ReferenceManager (org.javarosa.core.reference.ReferenceManager)6 Test (org.junit.Test)6 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)6 CollectHelpers.setupFakeReferenceManager (org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager)6 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)6 Date (java.util.Date)5 ImageView (android.widget.ImageView)4 SimpleDateFormat (java.text.SimpleDateFormat)4 RandomString (net.bytebuddy.utility.RandomString)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 Drawable (android.graphics.drawable.Drawable)3 Uri (android.net.Uri)3 View (android.view.View)3 Nullable (androidx.annotation.Nullable)3 FileWidgetTest (org.odk.collect.android.widgets.base.FileWidgetTest)3 SynchronousImageLoader (org.odk.collect.android.widgets.support.SynchronousImageLoader)3 ImageLoader (org.odk.collect.imageloader.ImageLoader)3