Search in sources :

Example 6 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory in project platform_frameworks_base by android.

the class RemoteViewsAdapter method updateRemoteViews.

private void updateRemoteViews(final int position, boolean notifyWhenLoaded) {
    IRemoteViewsFactory factory = mServiceConnection.getRemoteViewsFactory();
    // Load the item information from the remote service
    RemoteViews remoteViews = null;
    long itemId = 0;
    try {
        remoteViews = factory.getViewAt(position);
        itemId = factory.getItemId(position);
    } catch (RemoteException e) {
        Log.e(TAG, "Error in updateRemoteViews(" + position + "): " + e.getMessage());
        // swapping from the loading view
        return;
    } catch (RuntimeException e) {
        Log.e(TAG, "Error in updateRemoteViews(" + position + "): " + e.getMessage());
        return;
    }
    if (remoteViews == null) {
        // If a null view was returned, we break early to prevent it from getting
        // into our cache and causing problems later. The effect is that the child  at this
        // position will remain as a loading view until it is updated.
        Log.e(TAG, "Error in updateRemoteViews(" + position + "): " + " null RemoteViews " + "returned from RemoteViewsFactory.");
        return;
    }
    int layoutId = remoteViews.getLayoutId();
    RemoteViewsMetaData metaData = mCache.getMetaData();
    boolean viewTypeInRange;
    int cacheCount;
    synchronized (metaData) {
        viewTypeInRange = metaData.isViewTypeInRange(layoutId);
        cacheCount = mCache.mMetaData.count;
    }
    synchronized (mCache) {
        if (viewTypeInRange) {
            int[] visibleWindow = getVisibleWindow(mVisibleWindowLowerBound, mVisibleWindowUpperBound, cacheCount);
            // Cache the RemoteViews we loaded
            mCache.insert(position, remoteViews, itemId, visibleWindow);
            // Notify all the views that we have previously returned for this index that
            // there is new data for it.
            final RemoteViews rv = remoteViews;
            if (notifyWhenLoaded) {
                mMainQueue.post(new Runnable() {

                    @Override
                    public void run() {
                        mRequestedViews.notifyOnRemoteViewsLoaded(position, rv);
                    }
                });
            }
        } else {
            // We need to log an error here, as the the view type count specified by the
            // factory is less than the number of view types returned. We don't return this
            // view to the AdapterView, as this will cause an exception in the hosting process,
            // which contains the associated AdapterView.
            Log.e(TAG, "Error: widget's RemoteViewsFactory returns more view types than " + " indicated by getViewTypeCount() ");
        }
    }
}
Also used : IRemoteViewsFactory(com.android.internal.widget.IRemoteViewsFactory) RemoteException(android.os.RemoteException)

Example 7 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory in project platform_frameworks_base by android.

the class RemoteViewsAdapter method updateTemporaryMetaData.

private void updateTemporaryMetaData() {
    IRemoteViewsFactory factory = mServiceConnection.getRemoteViewsFactory();
    try {
        // get the properties/first view (so that we can use it to
        // measure our dummy views)
        boolean hasStableIds = factory.hasStableIds();
        int viewTypeCount = factory.getViewTypeCount();
        int count = factory.getCount();
        RemoteViews loadingView = factory.getLoadingView();
        RemoteViews firstView = null;
        if ((count > 0) && (loadingView == null)) {
            firstView = factory.getViewAt(0);
        }
        final RemoteViewsMetaData tmpMetaData = mCache.getTemporaryMetaData();
        synchronized (tmpMetaData) {
            tmpMetaData.hasStableIds = hasStableIds;
            // We +1 because the base view type is the loading view
            tmpMetaData.viewTypeCount = viewTypeCount + 1;
            tmpMetaData.count = count;
            tmpMetaData.setLoadingViewTemplates(loadingView, firstView);
        }
    } catch (RemoteException e) {
        processException("updateMetaData", e);
    } catch (RuntimeException e) {
        processException("updateMetaData", e);
    }
}
Also used : IRemoteViewsFactory(com.android.internal.widget.IRemoteViewsFactory) RemoteException(android.os.RemoteException)

Example 8 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory in project XobotOS by xamarin.

the class RemoteViewsAdapter method updateTemporaryMetaData.

private void updateTemporaryMetaData() {
    IRemoteViewsFactory factory = mServiceConnection.getRemoteViewsFactory();
    try {
        // get the properties/first view (so that we can use it to
        // measure our dummy views)
        boolean hasStableIds = factory.hasStableIds();
        int viewTypeCount = factory.getViewTypeCount();
        int count = factory.getCount();
        RemoteViews loadingView = factory.getLoadingView();
        RemoteViews firstView = null;
        if ((count > 0) && (loadingView == null)) {
            firstView = factory.getViewAt(0);
        }
        final RemoteViewsMetaData tmpMetaData = mCache.getTemporaryMetaData();
        synchronized (tmpMetaData) {
            tmpMetaData.hasStableIds = hasStableIds;
            // We +1 because the base view type is the loading view
            tmpMetaData.viewTypeCount = viewTypeCount + 1;
            tmpMetaData.count = count;
            tmpMetaData.setLoadingViewTemplates(loadingView, firstView);
        }
    } catch (RemoteException e) {
        processException("updateMetaData", e);
    } catch (RuntimeException e) {
        processException("updateMetaData", e);
    }
}
Also used : IRemoteViewsFactory(com.android.internal.widget.IRemoteViewsFactory) RemoteException(android.os.RemoteException)

Example 9 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory in project android_frameworks_base by DirtyUnicorns.

the class RemoteViewsAdapter method updateRemoteViews.

private void updateRemoteViews(final int position, boolean notifyWhenLoaded) {
    IRemoteViewsFactory factory = mServiceConnection.getRemoteViewsFactory();
    // Load the item information from the remote service
    RemoteViews remoteViews = null;
    long itemId = 0;
    try {
        remoteViews = factory.getViewAt(position);
        itemId = factory.getItemId(position);
    } catch (RemoteException e) {
        Log.e(TAG, "Error in updateRemoteViews(" + position + "): " + e.getMessage());
        // swapping from the loading view
        return;
    } catch (RuntimeException e) {
        Log.e(TAG, "Error in updateRemoteViews(" + position + "): " + e.getMessage());
        return;
    }
    if (remoteViews == null) {
        // If a null view was returned, we break early to prevent it from getting
        // into our cache and causing problems later. The effect is that the child  at this
        // position will remain as a loading view until it is updated.
        Log.e(TAG, "Error in updateRemoteViews(" + position + "): " + " null RemoteViews " + "returned from RemoteViewsFactory.");
        return;
    }
    int layoutId = remoteViews.getLayoutId();
    RemoteViewsMetaData metaData = mCache.getMetaData();
    boolean viewTypeInRange;
    int cacheCount;
    synchronized (metaData) {
        viewTypeInRange = metaData.isViewTypeInRange(layoutId);
        cacheCount = mCache.mMetaData.count;
    }
    synchronized (mCache) {
        if (viewTypeInRange) {
            int[] visibleWindow = getVisibleWindow(mVisibleWindowLowerBound, mVisibleWindowUpperBound, cacheCount);
            // Cache the RemoteViews we loaded
            mCache.insert(position, remoteViews, itemId, visibleWindow);
            // Notify all the views that we have previously returned for this index that
            // there is new data for it.
            final RemoteViews rv = remoteViews;
            if (notifyWhenLoaded) {
                mMainQueue.post(new Runnable() {

                    @Override
                    public void run() {
                        mRequestedViews.notifyOnRemoteViewsLoaded(position, rv);
                    }
                });
            }
        } else {
            // We need to log an error here, as the the view type count specified by the
            // factory is less than the number of view types returned. We don't return this
            // view to the AdapterView, as this will cause an exception in the hosting process,
            // which contains the associated AdapterView.
            Log.e(TAG, "Error: widget's RemoteViewsFactory returns more view types than " + " indicated by getViewTypeCount() ");
        }
    }
}
Also used : IRemoteViewsFactory(com.android.internal.widget.IRemoteViewsFactory) RemoteException(android.os.RemoteException)

Example 10 with IRemoteViewsFactory

use of com.android.internal.widget.IRemoteViewsFactory in project android_frameworks_base by DirtyUnicorns.

the class RemoteViewsAdapter method updateTemporaryMetaData.

private void updateTemporaryMetaData() {
    IRemoteViewsFactory factory = mServiceConnection.getRemoteViewsFactory();
    try {
        // get the properties/first view (so that we can use it to
        // measure our dummy views)
        boolean hasStableIds = factory.hasStableIds();
        int viewTypeCount = factory.getViewTypeCount();
        int count = factory.getCount();
        RemoteViews loadingView = factory.getLoadingView();
        RemoteViews firstView = null;
        if ((count > 0) && (loadingView == null)) {
            firstView = factory.getViewAt(0);
        }
        final RemoteViewsMetaData tmpMetaData = mCache.getTemporaryMetaData();
        synchronized (tmpMetaData) {
            tmpMetaData.hasStableIds = hasStableIds;
            // We +1 because the base view type is the loading view
            tmpMetaData.viewTypeCount = viewTypeCount + 1;
            tmpMetaData.count = count;
            tmpMetaData.setLoadingViewTemplates(loadingView, firstView);
        }
    } catch (RemoteException e) {
        processException("updateMetaData", e);
    } catch (RuntimeException e) {
        processException("updateMetaData", e);
    }
}
Also used : IRemoteViewsFactory(com.android.internal.widget.IRemoteViewsFactory) RemoteException(android.os.RemoteException)

Aggregations

RemoteException (android.os.RemoteException)33 IRemoteViewsFactory (com.android.internal.widget.IRemoteViewsFactory)33 ComponentName (android.content.ComponentName)12 ServiceConnection (android.content.ServiceConnection)12 IBinder (android.os.IBinder)12 UserHandle (android.os.UserHandle)8 Point (android.graphics.Point)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 FilterComparison (android.content.Intent.FilterComparison)6 Pair (android.util.Pair)5