Android Open Source - DashClockWidget Widget Remote Views Factory Service






From Project

Back to project page DashClockWidget.

License

The source code is released under:

Apache License

If you think the Android project DashClockWidget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2013 Google Inc.//from   w w  w . java  2s.  c o m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.apps.dashclock.render;

import com.google.android.apps.dashclock.*;
import com.google.android.apps.dashclock.configuration.AppearanceConfig;

import net.nurik.roman.dashclock.R;

import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;

import java.util.ArrayList;
import java.util.List;

import static com.google.android.apps.dashclock.LogUtils.LOGD;

/**
 * This is the service that provides the factory to be bound to the collection. Basically the
 * {@link android.widget.Adapter} for expanded DashClock extensions.
 */
public class WidgetRemoteViewsFactoryService extends RemoteViewsService {
    private static final String TAG = LogUtils.makeLogTag(WidgetRemoteViewsFactoryService.class);

    public static String EXTRA_TARGET = "com.google.android.apps.dashclock.extra.TARGET";

    public static String EXTRA_IS_MINI = "com.google.android.apps.dashclock.extra.IS_MINI";

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public RemoteViewsFactory onGetViewFactory(Intent intent) {
        LOGD(TAG, "Instantiating a remote views factory.");
        int target = intent.getIntExtra(EXTRA_TARGET, DashClockRenderer.Options.TARGET_HOME_SCREEN);
        boolean isMini = intent.getBooleanExtra(EXTRA_IS_MINI, false);
        return new WidgetRemoveViewsFactory(this, target, isMini);
    }

    /**
     * This is the factory that will provide data to the collection widget. Behaves pretty much like
     * an {@link android.widget.Adapter}.
     */
    class WidgetRemoveViewsFactory implements RemoteViewsService.RemoteViewsFactory {
        private Context mContext;
        private ExtensionManager mExtensionManager;
        private List<ExtensionManager.ExtensionWithData>
                mVisibleExtensions = new ArrayList<ExtensionManager.ExtensionWithData>();
        private int mTarget;
        private boolean mIsMini;

        public WidgetRemoveViewsFactory(Context context, int target, boolean isMini) {
            mContext = context;
            mTarget = target;
            mIsMini = isMini;
            mExtensionManager = ExtensionManager.getInstance(context);
        }

        public void onCreate() {
        }

        public void onDestroy() {
        }

        public void onDataSetChanged() {
            mVisibleExtensions = mExtensionManager.getVisibleExtensionsWithData();
        }

        public int getViewTypeCount() {
            return 1;
        }

        public long getItemId(int position) {
            ExtensionManager.ExtensionWithData ewd = getItemAtProtected(position);
            return (ewd != null) ? ewd.listing.componentName.hashCode() : 0;
        }

        public boolean hasStableIds() {
            return true;
        }

        public int getCount() {
            return mVisibleExtensions.size();
        }

        private ExtensionManager.ExtensionWithData getItemAtProtected(int position) {
            return position < mVisibleExtensions.size() ? mVisibleExtensions.get(position) : null;
        }

        public RemoteViews getViewAt(int position) {
            if (position >= mVisibleExtensions.size()) {
                // TODO: trap this better
                // See note on synchronization below.
                return null;
            }

            WidgetRenderer renderer = new WidgetRenderer(mContext);
            DashClockRenderer.Options options = new DashClockRenderer.Options();
            options.target = mTarget;
            options.foregroundColor = AppearanceConfig.getForegroundColor(mContext, mTarget);
            renderer.setOptions(options);
            ExtensionManager.ExtensionWithData ewd = getItemAtProtected(position);
            return (RemoteViews) (mIsMini
                    ? renderer.renderCollapsedExtension(null, null, true, ewd)
                    : renderer.renderExpandedExtension(null, null, true, ewd));
        }

        public RemoteViews getLoadingView() {
            return new RemoteViews(mContext.getPackageName(),
                    R.layout.widget_list_item_expanded_extension_loading);
        }
    }

}




Java Source Code List

com.example.dashclock.exampleextension.ExampleExtension.java
com.example.dashclock.exampleextension.ExampleSettingsActivity.java
com.google.android.apps.dashclock.BackupAgent.java
com.google.android.apps.dashclock.DashClockService.java
com.google.android.apps.dashclock.DaydreamService.java
com.google.android.apps.dashclock.ExtensionHost.java
com.google.android.apps.dashclock.ExtensionManager.java
com.google.android.apps.dashclock.ExtensionPackageChangeReceiver.java
com.google.android.apps.dashclock.HelpUtils.java
com.google.android.apps.dashclock.LogAttachmentProvider.java
com.google.android.apps.dashclock.LogUtils.java
com.google.android.apps.dashclock.PeriodicExtensionRefreshReceiver.java
com.google.android.apps.dashclock.Utils.java
com.google.android.apps.dashclock.WidgetClickProxyActivity.java
com.google.android.apps.dashclock.WidgetProvider.java
com.google.android.apps.dashclock.api.DashClockExtension.java
com.google.android.apps.dashclock.api.ExtensionData.java
com.google.android.apps.dashclock.api.VisibleExtension.java
com.google.android.apps.dashclock.api.package-info.java
com.google.android.apps.dashclock.calendar.CalendarExtension.java
com.google.android.apps.dashclock.calendar.CalendarSelectionPreference.java
com.google.android.apps.dashclock.calendar.CalendarSettingsActivity.java
com.google.android.apps.dashclock.configuration.AppChooserPreference.java
com.google.android.apps.dashclock.configuration.AppearanceConfig.java
com.google.android.apps.dashclock.configuration.BaseSettingsActivity.java
com.google.android.apps.dashclock.configuration.ColorPreference.java
com.google.android.apps.dashclock.configuration.ConfigurationActivity.java
com.google.android.apps.dashclock.configuration.ConfigureAdvancedFragment.java
com.google.android.apps.dashclock.configuration.ConfigureAppearanceFragment.java
com.google.android.apps.dashclock.configuration.ConfigureDaydreamFragment.java
com.google.android.apps.dashclock.configuration.ConfigureExtensionsFragment.java
com.google.android.apps.dashclock.configuration.DaydreamProxyActivity.java
com.google.android.apps.dashclock.gmail.GmailContract.java
com.google.android.apps.dashclock.gmail.GmailExtension.java
com.google.android.apps.dashclock.gmail.GmailSettingsActivity.java
com.google.android.apps.dashclock.nextalarm.NextAlarmExtension.java
com.google.android.apps.dashclock.nextalarm.NextAlarmSettingsActivity.java
com.google.android.apps.dashclock.phone.MissedCallsExtension.java
com.google.android.apps.dashclock.phone.SmsExtension.java
com.google.android.apps.dashclock.phone.TelephonyProviderConstants.java
com.google.android.apps.dashclock.render.DashClockRenderer.java
com.google.android.apps.dashclock.render.SimpleRenderer.java
com.google.android.apps.dashclock.render.SimpleViewBuilder.java
com.google.android.apps.dashclock.render.ViewBuilder.java
com.google.android.apps.dashclock.render.WidgetRemoteViewsFactoryService.java
com.google.android.apps.dashclock.render.WidgetRenderer.java
com.google.android.apps.dashclock.render.WidgetViewBuilder.java
com.google.android.apps.dashclock.ui.DragGripView.java
com.google.android.apps.dashclock.ui.EdgeEffectUtil.java
com.google.android.apps.dashclock.ui.PagerPositionStrip.java
com.google.android.apps.dashclock.ui.SimplePagedTabsHelper.java
com.google.android.apps.dashclock.ui.SwipeDismissListViewTouchListener.java
com.google.android.apps.dashclock.ui.UndoBarController.java
com.google.android.apps.dashclock.weather.CantGetWeatherException.java
com.google.android.apps.dashclock.weather.WeatherData.java
com.google.android.apps.dashclock.weather.WeatherExtension.java
com.google.android.apps.dashclock.weather.WeatherLocationPreference.java
com.google.android.apps.dashclock.weather.WeatherRetryReceiver.java
com.google.android.apps.dashclock.weather.WeatherSettingsActivity.java
com.google.android.apps.dashclock.weather.YahooWeatherApiClient.java
com.google.android.apps.dashclock.weather.YahooWeatherApiConfig.java