Search in sources :

Example 21 with Window

use of wei.mark.standout.ui.Window in project StandOut by pingpongboss.

the class FloatingFolder method resizeToGridAndSave.

private void resizeToGridAndSave(final int id, final int cols) {
    final Window window = getWindow(id);
    window.post(new Runnable() {

        @Override
        public void run() {
            FlowLayout flow = (FlowLayout) window.findViewById(R.id.flow);
            FolderModel folder = mFolders.get(id);
            int count = folder.apps.size();
            int columns = cols;
            if (cols == -1) {
                columns = flow.getCols();
            }
            if (columns < 2) {
                columns = 2;
            }
            int rows = count / columns;
            if (count % columns > 0) {
                rows++;
            }
            if (rows < 1) {
                rows = 1;
            }
            int width = flow.getLeft() + (((ViewGroup) flow.getParent()).getWidth() - flow.getRight()) + columns * squareWidth;
            int height = width;
            if (count > 0) {
                height = flow.getTop() + (((ViewGroup) flow.getParent()).getHeight() - flow.getBottom()) + rows * flow.getChildHeight();
            }
            StandOutLayoutParams params = window.getLayoutParams();
            params.width = width;
            params.height = height;
            updateViewLayout(id, params);
            folder.width = width;
            folder.height = height;
            saveFolder(folder);
        }
    });
}
Also used : Window(wei.mark.standout.ui.Window) StandOutWindow(wei.mark.standout.StandOutWindow) ViewGroup(android.view.ViewGroup)

Example 22 with Window

use of wei.mark.standout.ui.Window in project StandOut by pingpongboss.

the class StandOutWindow method close.

/**
 * Close a window corresponding to the id.
 *
 * @param id
 *            The id of the window.
 */
public final synchronized void close(final int id) {
    // get the view corresponding to the id
    final Window window = getWindow(id);
    if (window == null) {
        throw new IllegalArgumentException("Tried to close(" + id + ") a null window.");
    }
    if (window.visibility == Window.VISIBILITY_TRANSITION) {
        return;
    }
    // alert callbacks and cancel if instructed
    if (onClose(id, window)) {
        Log.w(TAG, "Window " + id + " close cancelled by implementation.");
        return;
    }
    // remove hidden notification
    mNotificationManager.cancel(getClass().hashCode() + id);
    unfocus(window);
    window.visibility = Window.VISIBILITY_TRANSITION;
    // get animation
    Animation animation = getCloseAnimation(id);
    // remove window
    try {
        // animate
        if (animation != null) {
            animation.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    // remove the window from the window manager
                    mWindowManager.removeView(window);
                    window.visibility = Window.VISIBILITY_GONE;
                    // remove view from internal map
                    sWindowCache.removeCache(id, StandOutWindow.this.getClass());
                    // if we just released the last window, quit
                    if (getExistingIds().size() == 0) {
                        // tell Android to remove the persistent
                        // notification
                        // the Service will be shutdown by the system on low
                        // memory
                        startedForeground = false;
                        stopForeground(true);
                    }
                }
            });
            window.getChildAt(0).startAnimation(animation);
        } else {
            // remove the window from the window manager
            mWindowManager.removeView(window);
            // remove view from internal map
            sWindowCache.removeCache(id, getClass());
            // if we just released the last window, quit
            if (sWindowCache.getCacheSize(getClass()) == 0) {
                // tell Android to remove the persistent notification
                // the Service will be shutdown by the system on low memory
                startedForeground = false;
                stopForeground(true);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Window(wei.mark.standout.ui.Window) PopupWindow(android.widget.PopupWindow) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener)

Aggregations

Window (wei.mark.standout.ui.Window)22 PopupWindow (android.widget.PopupWindow)16 Animation (android.view.animation.Animation)9 Notification (android.app.Notification)7 AnimationListener (android.view.animation.Animation.AnimationListener)6 StandOutWindow (wei.mark.standout.StandOutWindow)6 SharedPreferences (android.content.SharedPreferences)3 ViewGroup (android.view.ViewGroup)3 TextView (android.widget.TextView)3 ActivityInfo (android.content.pm.ActivityInfo)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 NotificationManager (android.app.NotificationManager)1 Intent (android.content.Intent)1 ResolveInfo (android.content.pm.ResolveInfo)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 OnClickListener (android.view.View.OnClickListener)1