android.support.annotation.BinderThread Java Examples

The following examples show how to use android.support.annotation.BinderThread. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 6 votes vote down vote up
@BinderThread
private BookmarkFolder loadBookmarks(final BookmarkId folderId) {
    final LinkedBlockingQueue<BookmarkFolder> resultQueue = new LinkedBlockingQueue<>(1);
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            new BookmarkLoader(mContext, folderId, new BookmarkLoaderCallback() {
                @Override
                public void onBookmarksLoaded(BookmarkFolder folder) {
                    resultQueue.add(folder);
                }
            });
        }
    });
    try {
        return resultQueue.take();
    } catch (InterruptedException e) {
        return null;
    }
}
 
Example #2
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 6 votes vote down vote up
@BinderThread
private BookmarkFolder loadBookmarks(final BookmarkId folderId) {
    final LinkedBlockingQueue<BookmarkFolder> resultQueue = new LinkedBlockingQueue<>(1);
    //A reference of BookmarkLoader is needed in binder thread to
    //prevent it from being garbage collected.
    final BookmarkLoader bookmarkLoader = new BookmarkLoader();
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            bookmarkLoader.initialize(mContext, folderId, new BookmarkLoaderCallback() {
                @Override
                public void onBookmarksLoaded(BookmarkFolder folder) {
                    resultQueue.add(folder);
                }
            });
        }
    });
    try {
        return resultQueue.take();
    } catch (InterruptedException e) {
        return null;
    }
}
 
Example #3
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 6 votes vote down vote up
@BinderThread
@Override
public int getCount() {
    //On some Sony devices, getCount() could be called before onDatasetChanged()
    //returns. If it happens, refresh widget until the bookmarks are all loaded.
    if (mCurrentFolder == null || !mPreferences.getString(PREF_CURRENT_FOLDER, "")
            .equals(mCurrentFolder.folder.id.toString())) {
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                refreshWidget();
            }
        });
    }
    if (mCurrentFolder == null) {
        return 0;
    }
    return mCurrentFolder.children.size() + (mCurrentFolder.parent != null ? 1 : 0);
}
 
Example #4
Source Project: 365browser   Author: mogoweb   File: BookmarkWidgetService.java    License: Apache License 2.0 6 votes vote down vote up
@BinderThread
private BookmarkFolder loadBookmarks(final BookmarkId folderId) {
    final LinkedBlockingQueue<BookmarkFolder> resultQueue = new LinkedBlockingQueue<>(1);
    //A reference of BookmarkLoader is needed in binder thread to
    //prevent it from being garbage collected.
    final BookmarkLoader bookmarkLoader = new BookmarkLoader();
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            bookmarkLoader.initialize(mContext, folderId, new BookmarkLoaderCallback() {
                @Override
                public void onBookmarksLoaded(BookmarkFolder folder) {
                    resultQueue.add(folder);
                }
            });
        }
    });
    try {
        return resultQueue.take();
    } catch (InterruptedException e) {
        return null;
    }
}
 
Example #5
Source Project: 365browser   Author: mogoweb   File: BookmarkWidgetService.java    License: Apache License 2.0 6 votes vote down vote up
@BinderThread
private Bookmark getBookmarkForPosition(int position) {
    if (mCurrentFolder == null) return null;

    // The position 0 is saved for an entry of the current folder used to go up.
    // This is not the case when the current node has no parent (it's the root node).
    if (mCurrentFolder.parent != null) {
        if (position == 0) return mCurrentFolder.folder;
        position--;
    }

    // This is necessary because when Chrome is cleared from Application settings, Bookmark
    // widget will not be notified and it causes inconsistency between model and widget.
    // Then if the widget is quickly scrolled down, this has an IndexOutOfBound error.
    if (mCurrentFolder.children.size() <= position) return null;

    return mCurrentFolder.children.get(position);
}
 
Example #6
Source Project: 365browser   Author: mogoweb   File: BookmarkWidgetService.java    License: Apache License 2.0 6 votes vote down vote up
@BinderThread
@Override
public int getCount() {
    //On some Sony devices, getCount() could be called before onDatasetChanged()
    //returns. If it happens, refresh widget until the bookmarks are all loaded.
    if (mCurrentFolder == null || !mPreferences.getString(PREF_CURRENT_FOLDER, "")
            .equals(mCurrentFolder.folder.id.toString())) {
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                refreshWidget();
            }
        });
    }
    if (mCurrentFolder == null) {
        return 0;
    }
    return mCurrentFolder.children.size() + (mCurrentFolder.parent != null ? 1 : 0);
}
 
Example #7
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 5 votes vote down vote up
@BinderThread
@Override
public void onDestroy() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mBookmarkModel != null) mBookmarkModel.destroy();
        }
    });
    deleteWidgetState(mContext, mWidgetId);
}
 
Example #8
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 5 votes vote down vote up
@BinderThread
private void updateBookmarkList() {
    BookmarkId folderId = BookmarkId
            .getBookmarkIdFromString(mPreferences.getString(PREF_CURRENT_FOLDER, null));
    mCurrentFolder = loadBookmarks(folderId);
    mPreferences.edit().putString(PREF_CURRENT_FOLDER, mCurrentFolder.folder.id.toString())
            .apply();
}
 
Example #9
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 5 votes vote down vote up
@BinderThread
private Bookmark getBookmarkForPosition(int position) {
    if (mCurrentFolder == null) return null;

    // The position 0 is saved for an entry of the current folder used to go up.
    // This is not the case when the current node has no parent (it's the root node).
    if (mCurrentFolder.parent != null) {
        if (position == 0) return mCurrentFolder.folder;
        position--;
    }
    return mCurrentFolder.children.get(position);
}
 
Example #10
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 5 votes vote down vote up
@BinderThread
@Override
public void onDestroy() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mBookmarkModel != null) mBookmarkModel.destroy();
        }
    });
    deleteWidgetState(mContext, mWidgetId);
}
 
Example #11
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 5 votes vote down vote up
@BinderThread
private void updateBookmarkList() {
    BookmarkId folderId = BookmarkId
            .getBookmarkIdFromString(mPreferences.getString(PREF_CURRENT_FOLDER, null));
    mCurrentFolder = loadBookmarks(folderId);
    mPreferences.edit().putString(PREF_CURRENT_FOLDER, mCurrentFolder.folder.id.toString())
            .apply();
}
 
Example #12
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 5 votes vote down vote up
@BinderThread
private Bookmark getBookmarkForPosition(int position) {
    if (mCurrentFolder == null) return null;

    // The position 0 is saved for an entry of the current folder used to go up.
    // This is not the case when the current node has no parent (it's the root node).
    if (mCurrentFolder.parent != null) {
        if (position == 0) return mCurrentFolder.folder;
        position--;
    }
    return mCurrentFolder.children.get(position);
}
 
Example #13
Source Project: firebase-jobdispatcher-android   Author: googlearchive   File: JobService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@BinderThread
public void start(Bundle invocationData, IJobCallback callback) {
  JobInvocation.Builder invocation = getJobCoder().decode(invocationData);
  if (invocation == null) {
    Log.wtf(TAG, "start: unknown invocation provided");
    return;
  }

  JobService.this.handleStartJobRequest(invocation.build(), callback);
}
 
Example #14
Source Project: firebase-jobdispatcher-android   Author: googlearchive   File: JobService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@BinderThread
public void stop(Bundle invocationData, boolean needToSendResult) {
  JobInvocation.Builder invocation = getJobCoder().decode(invocationData);
  if (invocation == null) {
    Log.wtf(TAG, "stop: unknown invocation provided");
    return;
  }

  JobService.this.handleStopJobRequest(invocation.build(), needToSendResult);
}
 
Example #15
Source Project: 365browser   Author: mogoweb   File: BookmarkWidgetService.java    License: Apache License 2.0 5 votes vote down vote up
@BinderThread
@Override
public void onDestroy() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mBookmarkModel != null) mBookmarkModel.destroy();
        }
    });
    deleteWidgetState(mContext, mWidgetId);
}
 
Example #16
Source Project: 365browser   Author: mogoweb   File: BookmarkWidgetService.java    License: Apache License 2.0 5 votes vote down vote up
@BinderThread
private void updateBookmarkList() {
    BookmarkId folderId = BookmarkId
            .getBookmarkIdFromString(mPreferences.getString(PREF_CURRENT_FOLDER, null));
    mCurrentFolder = loadBookmarks(folderId);
    mPreferences.edit().putString(PREF_CURRENT_FOLDER, mCurrentFolder.folder.id.toString())
            .apply();
}
 
Example #17
Source Project: 365browser   Author: mogoweb   File: BookmarkWidgetService.java    License: Apache License 2.0 5 votes vote down vote up
@BinderThread
@Override
public long getItemId(int position) {
    Bookmark bookmark = getBookmarkForPosition(position);
    if (bookmark == null) return BookmarkId.INVALID_FOLDER_ID;
    return bookmark.id.getId();
}
 
Example #18
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public void onDataSetChanged() {
    updateBookmarkList();
}
 
Example #19
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public int getViewTypeCount() {
    return 2;
}
 
Example #20
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public boolean hasStableIds() {
    return false;
}
 
Example #21
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public int getCount() {
    if (mCurrentFolder == null) return 0;
    return mCurrentFolder.children.size() + (mCurrentFolder.parent != null ? 1 : 0);
}
 
Example #22
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public long getItemId(int position) {
    return getBookmarkForPosition(position).id.getId();
}
 
Example #23
Source Project: delion   Author: derry   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public RemoteViews getLoadingView() {
    return new RemoteViews(mContext.getPackageName(), R.layout.bookmark_widget_item);
}
 
Example #24
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public void onDataSetChanged() {
    updateBookmarkList();
}
 
Example #25
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public int getViewTypeCount() {
    return 2;
}
 
Example #26
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public boolean hasStableIds() {
    return false;
}
 
Example #27
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public long getItemId(int position) {
    return getBookmarkForPosition(position).id.getId();
}
 
Example #28
Source Project: AndroidChromium   Author: JackyAndroid   File: BookmarkWidgetService.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
@Override
public RemoteViews getLoadingView() {
    return new RemoteViews(mContext.getPackageName(), R.layout.bookmark_widget_item);
}
 
Example #29
Source Project: Study_Android_Demo   Author: RealMoMo   File: ThreadAnnotation.java    License: Apache License 2.0 4 votes vote down vote up
@BinderThread
public void workOnBinderThread(){
    logThreadInfo();
}
 
Example #30
Source Project: firebase-jobdispatcher-android   Author: googlearchive   File: JobService.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Asks the {@code job} to start running. Calls {@link #onStartJob} on the main thread. Once
 * complete, the {@code callback} will be used to send the result back.
 */
@BinderThread
private void handleStartJobRequest(JobParameters job, IJobCallback callback) {
  backgroundExecutor.execute(UnitOfWork.handleStartJobRequest(this, job, callback));
}