Search in sources :

Example 16 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project ADWLauncher2 by boombuler.

the class WidgetCellLayout method onViewportIn.

/**
     * Called when this cell layout get into the viewport
     */
public void onViewportIn() {
    View child;
    AppWidgetHostView widgetView;
    AppWidgetProviderInfo widgetInfo;
    Intent intent;
    for (int i = this.getChildCount() - 1; i >= 0; i--) {
        try {
            child = this.getChildAt(i);
            if (child instanceof AppWidgetHostView) {
                widgetView = ((AppWidgetHostView) child);
                widgetInfo = widgetView.getAppWidgetInfo();
                int appWidgetId = widgetView.getAppWidgetId();
                intent = new Intent(LauncherIntent.Notification.NOTIFICATION_IN_VIEWPORT).setComponent(widgetInfo.provider);
                intent.putExtra(LauncherIntent.Extra.EXTRA_APPWIDGET_ID, appWidgetId);
                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                getContext().sendBroadcast(intent);
            }
        } catch (Exception e) {
        // LauncherApplication.reportExceptionStack(e);
        }
    }
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherIntent(mobi.intuitit.android.content.LauncherIntent) Intent(android.content.Intent) AppWidgetHostView(android.appwidget.AppWidgetHostView) ImageView(android.widget.ImageView) View(android.view.View)

Example 17 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project ADWLauncher2 by boombuler.

the class Launcher method editWidget.

protected void editWidget(final View widget) {
    if (mWorkspace != null) {
        mIsWidgetEditMode = true;
        final CellLayout screen = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentScreen());
        if (screen != null) {
            mEditingAppWidget = (LauncherAppWidgetInfo) widget.getTag();
            final long itemId = mEditingAppWidget.id;
            final Intent motosize = new Intent("com.motorola.blur.home.ACTION_SET_WIDGET_SIZE");
            final int appWidgetId = ((AppWidgetHostView) widget).getAppWidgetId();
            final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
            if (appWidgetInfo != null) {
                motosize.setComponent(appWidgetInfo.provider);
            }
            motosize.putExtra("appWidgetId", appWidgetId);
            motosize.putExtra("com.motorola.blur.home.EXTRA_NEW_WIDGET", true);
            final int minw = (mWorkspace.getWidth() - screen.getLeftPadding() - screen.getRightPadding()) / screen.getCountX();
            final int minh = (mWorkspace.getHeight() - screen.getBottomPadding() - screen.getTopPadding()) / screen.getCountY();
            mScreensEditor = new ResizeViewHandler(this);
            // Create a default HightlightView if we found no face in the picture.
            int width = (mEditingAppWidget.spanX * minw);
            int height = (mEditingAppWidget.spanY * minh);
            final Rect screenRect = new Rect(0, 0, mWorkspace.getWidth() - screen.getRightPadding(), mWorkspace.getHeight() - screen.getBottomPadding());
            final int x = mEditingAppWidget.cellX * minw;
            final int y = mEditingAppWidget.cellY * minh;
            final int[] spans = new int[] { 1, 1 };
            final int[] position = new int[] { 1, 1 };
            final CellLayout.LayoutParams lp = (CellLayout.LayoutParams) widget.getLayoutParams();
            RectF widgetRect = new RectF(x, y, x + width, y + height);
            mScreensEditor.setup(null, screenRect, widgetRect, false, false, minw - 10, minh - 10);
            mDragLayer.addView(mScreensEditor);
            mScreensEditor.setOnValidateSizingRect(new ResizeViewHandler.OnSizeChangedListener() {

                @Override
                public void onTrigger(RectF r) {
                    if (r != null) {
                        final float left = Math.round(r.left / minw) * minw;
                        final float top = Math.round(r.top / minh) * minh;
                        final float right = left + (Math.max(Math.round(r.width() / (minw)), 1) * minw);
                        final float bottom = top + (Math.max(Math.round(r.height() / (minh)), 1) * minh);
                        r.set(left, top, right, bottom);
                    }
                }
            });
            final Rect checkRect = new Rect();
            (mScreensEditor).setOnSizeChangedListener(new ResizeViewHandler.OnSizeChangedListener() {

                @Override
                public void onTrigger(RectF r) {
                    int[] tmpspans = { Math.max(Math.round(r.width() / (minw)), 1), Math.max(Math.round(r.height() / (minh)), 1) };
                    int[] tmpposition = { Math.round(r.left / minw), Math.round(r.top / minh) };
                    checkRect.set(tmpposition[0], tmpposition[1], tmpposition[0] + tmpspans[0], tmpposition[1] + tmpspans[1]);
                    boolean ocupada = ocuppiedArea(screen.getScreen(), itemId, checkRect);
                    if (!ocupada) {
                        (mScreensEditor).setColliding(false);
                    } else {
                        (mScreensEditor).setColliding(true);
                    }
                    if (tmpposition[0] != position[0] || tmpposition[1] != position[1] || tmpspans[0] != spans[0] || tmpspans[1] != spans[1]) {
                        if (!ocupada) {
                            position[0] = tmpposition[0];
                            position[1] = tmpposition[1];
                            spans[0] = tmpspans[0];
                            spans[1] = tmpspans[1];
                            lp.cellX = position[0];
                            lp.cellY = position[1];
                            lp.cellHSpan = spans[0];
                            lp.cellVSpan = spans[1];
                            widget.setLayoutParams(lp);
                            mEditingAppWidget.cellX = lp.cellX;
                            mEditingAppWidget.cellY = lp.cellY;
                            mEditingAppWidget.spanX = lp.cellHSpan;
                            mEditingAppWidget.spanY = lp.cellVSpan;
                            widget.setTag(mEditingAppWidget);
                            //send the broadcast
                            motosize.putExtra("spanX", spans[0]);
                            motosize.putExtra("spanY", spans[1]);
                            Launcher.this.sendBroadcast(motosize);
                            Log.d("RESIZEHANDLER", "sent resize broadcast");
                        }
                    }
                }
            });
        }
    }
}
Also used : Rect(android.graphics.Rect) Intent(android.content.Intent) LauncherIntent(mobi.intuitit.android.content.LauncherIntent) RectF(android.graphics.RectF) AppWidgetHostView(android.appwidget.AppWidgetHostView) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 18 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_frameworks_base by DirtyUnicorns.

the class AppWidgetHostActivity method addAppWidgetView.

void addAppWidgetView(int appWidgetId, AppWidgetProviderInfo appWidget) {
    // Inflate the AppWidget's RemoteViews
    AppWidgetHostView view = mHost.createView(this, appWidgetId, appWidget);
    // Add it to the list
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    mAppWidgetContainer.addView(view, layoutParams);
    registerForContextMenu(view);
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) LinearLayout(android.widget.LinearLayout)

Example 19 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_frameworks_base by ResurrectionRemix.

the class AppWidgetHostActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mAppWidgetManager = AppWidgetManager.getInstance(this);
    setContentView(R.layout.appwidget_host);
    mHost = new AppWidgetHost(this, HOST_ID) {

        protected AppWidgetHostView onCreateView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
            return new MyAppWidgetView(appWidgetId);
        }
    };
    findViewById(R.id.add_appwidget).setOnClickListener(mOnClickListener);
    mAppWidgetContainer = (AppWidgetContainerView) findViewById(R.id.appwidget_container);
    if (false) {
        if (false) {
            mHost.deleteHost();
        } else {
            AppWidgetHost.deleteAllHosts();
        }
    }
}
Also used : Context(android.content.Context) AppWidgetHostView(android.appwidget.AppWidgetHostView) AppWidgetHost(android.appwidget.AppWidgetHost) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 20 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_frameworks_base by ResurrectionRemix.

the class AppWidgetHostActivity method addAppWidgetView.

void addAppWidgetView(int appWidgetId, AppWidgetProviderInfo appWidget) {
    // Inflate the AppWidget's RemoteViews
    AppWidgetHostView view = mHost.createView(this, appWidgetId, appWidget);
    // Add it to the list
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    mAppWidgetContainer.addView(view, layoutParams);
    registerForContextMenu(view);
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) LinearLayout(android.widget.LinearLayout)

Aggregations

AppWidgetHostView (android.appwidget.AppWidgetHostView)45 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)18 Point (android.graphics.Point)11 View (android.view.View)10 Context (android.content.Context)6 Intent (android.content.Intent)6 Bundle (android.os.Bundle)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 AppWidgetHost (android.appwidget.AppWidgetHost)5 LinearLayout (android.widget.LinearLayout)5 Test (org.junit.Test)5 Rect (android.graphics.Rect)4 Resources (android.content.res.Resources)3 Bitmap (android.graphics.Bitmap)3 RecognizerIntent (android.speech.RecognizerIntent)3 LauncherIntent (mobi.intuitit.android.content.LauncherIntent)3 SuppressLint (android.annotation.SuppressLint)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Paint (android.graphics.Paint)1