类android.support.annotation.BinderThread源码实例Demo

下面列出了怎么用android.support.annotation.BinderThread的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: delion   文件: BookmarkWidgetService.java
@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;
    }
}
 
源代码2 项目: AndroidChromium   文件: BookmarkWidgetService.java
@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;
    }
}
 
源代码3 项目: AndroidChromium   文件: BookmarkWidgetService.java
@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);
}
 
源代码4 项目: 365browser   文件: BookmarkWidgetService.java
@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;
    }
}
 
源代码5 项目: 365browser   文件: BookmarkWidgetService.java
@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);
}
 
源代码6 项目: 365browser   文件: BookmarkWidgetService.java
@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);
}
 
源代码7 项目: delion   文件: BookmarkWidgetService.java
@BinderThread
@Override
public void onDestroy() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mBookmarkModel != null) mBookmarkModel.destroy();
        }
    });
    deleteWidgetState(mContext, mWidgetId);
}
 
源代码8 项目: delion   文件: BookmarkWidgetService.java
@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();
}
 
源代码9 项目: delion   文件: BookmarkWidgetService.java
@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);
}
 
源代码10 项目: AndroidChromium   文件: BookmarkWidgetService.java
@BinderThread
@Override
public void onDestroy() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mBookmarkModel != null) mBookmarkModel.destroy();
        }
    });
    deleteWidgetState(mContext, mWidgetId);
}
 
源代码11 项目: AndroidChromium   文件: BookmarkWidgetService.java
@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();
}
 
源代码12 项目: AndroidChromium   文件: BookmarkWidgetService.java
@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);
}
 
@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);
}
 
@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);
}
 
源代码15 项目: 365browser   文件: BookmarkWidgetService.java
@BinderThread
@Override
public void onDestroy() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mBookmarkModel != null) mBookmarkModel.destroy();
        }
    });
    deleteWidgetState(mContext, mWidgetId);
}
 
源代码16 项目: 365browser   文件: BookmarkWidgetService.java
@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();
}
 
源代码17 项目: 365browser   文件: BookmarkWidgetService.java
@BinderThread
@Override
public long getItemId(int position) {
    Bookmark bookmark = getBookmarkForPosition(position);
    if (bookmark == null) return BookmarkId.INVALID_FOLDER_ID;
    return bookmark.id.getId();
}
 
源代码18 项目: delion   文件: BookmarkWidgetService.java
@BinderThread
@Override
public void onDataSetChanged() {
    updateBookmarkList();
}
 
源代码19 项目: delion   文件: BookmarkWidgetService.java
@BinderThread
@Override
public int getViewTypeCount() {
    return 2;
}
 
源代码20 项目: delion   文件: BookmarkWidgetService.java
@BinderThread
@Override
public boolean hasStableIds() {
    return false;
}
 
源代码21 项目: delion   文件: BookmarkWidgetService.java
@BinderThread
@Override
public int getCount() {
    if (mCurrentFolder == null) return 0;
    return mCurrentFolder.children.size() + (mCurrentFolder.parent != null ? 1 : 0);
}
 
源代码22 项目: delion   文件: BookmarkWidgetService.java
@BinderThread
@Override
public long getItemId(int position) {
    return getBookmarkForPosition(position).id.getId();
}
 
源代码23 项目: delion   文件: BookmarkWidgetService.java
@BinderThread
@Override
public RemoteViews getLoadingView() {
    return new RemoteViews(mContext.getPackageName(), R.layout.bookmark_widget_item);
}
 
源代码24 项目: AndroidChromium   文件: BookmarkWidgetService.java
@BinderThread
@Override
public void onDataSetChanged() {
    updateBookmarkList();
}
 
源代码25 项目: AndroidChromium   文件: BookmarkWidgetService.java
@BinderThread
@Override
public int getViewTypeCount() {
    return 2;
}
 
源代码26 项目: AndroidChromium   文件: BookmarkWidgetService.java
@BinderThread
@Override
public boolean hasStableIds() {
    return false;
}
 
源代码27 项目: AndroidChromium   文件: BookmarkWidgetService.java
@BinderThread
@Override
public long getItemId(int position) {
    return getBookmarkForPosition(position).id.getId();
}
 
源代码28 项目: AndroidChromium   文件: BookmarkWidgetService.java
@BinderThread
@Override
public RemoteViews getLoadingView() {
    return new RemoteViews(mContext.getPackageName(), R.layout.bookmark_widget_item);
}
 
源代码29 项目: Study_Android_Demo   文件: ThreadAnnotation.java
@BinderThread
public void workOnBinderThread(){
    logThreadInfo();
}
 
/**
 * 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));
}
 
 同包方法