Search in sources :

Example 1 with Window

use of wei.mark.standout.ui.Window in project FloatingStickies by MohammadAdib.

the class StandOutWindow method bringToFront.

/**
     * Bring the window corresponding to this id in front of all other windows.
     * The window may flicker as it is removed and restored by the system.
     *
     * @param id The id of the window to bring to the front.
     */
public final synchronized void bringToFront(int id) {
    Window window = getWindow(id);
    if (window == null) {
        throw new IllegalArgumentException("Tried to bringToFront(" + id + ") a null window.");
    }
    StandOutLayoutParams params = window.getLayoutParams();
    // remove from window manager then add back
    try {
        mWindowManager.removeView(window);
        mWindowManager.addView(window, params);
        inFront = window.id;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Window(wei.mark.standout.ui.Window) PopupWindow(android.widget.PopupWindow)

Example 2 with Window

use of wei.mark.standout.ui.Window in project FloatingStickies by MohammadAdib.

the class StandOutWindow method hide.

/**
     * Hide a window corresponding to the id. Show a notification for the hidden
     * window.
     *
     * @param id The id of the window.
     */
public final synchronized void hide(int id) {
    // get the view corresponding to the id
    final Window window = getWindow(id);
    if (window == null) {
        throw new IllegalArgumentException("Tried to hide(" + id + ") a null window.");
    }
    if (window.visibility == Window.VISIBILITY_GONE) {
        throw new IllegalStateException("Tried to hide(" + id + ") a window that is not shown.");
    }
    // alert callbacks and cancel if instructed
    if (onHide(id, window)) {
        Log.w(TAG, "Window " + id + " hide cancelled by implementation.");
        return;
    }
    // check if hide enabled
    if (Utils.isSet(window.flags, StandOutFlags.FLAG_WINDOW_HIDE_ENABLE)) {
        window.visibility = Window.VISIBILITY_TRANSITION;
        // get the hidden notification for this view
        Notification notification = getHiddenNotification(id);
        // get animation
        Animation animation = getHideAnimation(id);
        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;
                    }
                });
                window.getChildAt(0).startAnimation(animation);
            } else {
                // remove the window from the window manager
                mWindowManager.removeView(window);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // display the notification
        notification.flags = notification.flags | Notification.FLAG_NO_CLEAR | Notification.FLAG_AUTO_CANCEL;
        mNotificationManager.notify(getClass().hashCode() + id, notification);
    } else {
        // if hide not enabled, close window
        close(id);
    }
}
Also used : Window(wei.mark.standout.ui.Window) PopupWindow(android.widget.PopupWindow) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener) Notification(android.app.Notification)

Example 3 with Window

use of wei.mark.standout.ui.Window in project FloatingStickies by MohammadAdib.

the class StandOutWindow method save.

public void save() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor = prefs.edit();
                File sdcard = Environment.getExternalStorageDirectory();
                File dir = new File(sdcard.getAbsolutePath() + "/FloatingStickies/");
                dir.mkdirs();
                for (int id : getExistingIds()) {
                    String text = getWindow(id).getText();
                    if (text.length() > 0) {
                        File file = new File(dir, "sticky" + id + ".txt");
                        Window window = getWindow(id);
                        int x = window.getLayoutParams().x;
                        if (x <= 0) {
                            editor.putString("_id" + id, x + "," + window.getLayoutParams().y + "," + window.dockW + "," + window.dockH + "," + file.getAbsolutePath()).commit();
                        } else {
                            editor.putString("_id" + id, x + "," + window.getLayoutParams().y + "," + window.getWidth() + "," + window.getHeight() + "," + file.getAbsolutePath()).commit();
                        }
                        FileOutputStream f = new FileOutputStream(file);
                        f.write(text.getBytes());
                        f.flush();
                        f.close();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : Window(wei.mark.standout.ui.Window) PopupWindow(android.widget.PopupWindow) SharedPreferences(android.content.SharedPreferences) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 4 with Window

use of wei.mark.standout.ui.Window in project FloatingStickies by MohammadAdib.

the class StandOutWindow method updateViewLayout.

/**
     * Update the window corresponding to this id with the given params.
     *
     * @param id     The id of the window.
     * @param params The updated layout params to apply.
     */
public void updateViewLayout(int id, StandOutLayoutParams params) {
    Window window = getWindow(id);
    if (window != null) {
        if (window.visibility == Window.VISIBILITY_GONE) {
            return;
        }
        if (window.visibility == Window.VISIBILITY_TRANSITION) {
            return;
        }
        // alert callbacks and cancel if instructed
        if (onUpdate(id, window, params)) {
            Log.w(TAG, "Window " + id + " update cancelled by implementation.");
            return;
        }
        try {
            window.setLayoutParams(params);
            mWindowManager.updateViewLayout(window, params);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : Window(wei.mark.standout.ui.Window) PopupWindow(android.widget.PopupWindow)

Example 5 with Window

use of wei.mark.standout.ui.Window in project Roundr by MohammadAdib.

the class StandOutWindow method hide.

/**
 * Hide a window corresponding to the id. Show a notification for the hidden
 * window.
 *
 * @param id
 *            The id of the window.
 */
public final synchronized void hide(int id) {
    // get the view corresponding to the id
    final Window window = getWindow(id);
    if (window == null) {
        throw new IllegalArgumentException("Tried to hide(" + id + ") a null window.");
    }
    if (window.visibility == Window.VISIBILITY_GONE) {
        throw new IllegalStateException("Tried to hide(" + id + ") a window that is not shown.");
    }
    // alert callbacks and cancel if instructed
    if (onHide(id, window)) {
        Log.w(TAG, "Window " + id + " hide cancelled by implementation.");
        return;
    }
    // check if hide enabled
    if (Utils.isSet(window.flags, StandOutFlags.FLAG_WINDOW_HIDE_ENABLE)) {
        window.visibility = Window.VISIBILITY_TRANSITION;
        // get the hidden notification for this view
        Notification notification = getHiddenNotification(id);
        // get animation
        Animation animation = getHideAnimation(id);
        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;
                    }
                });
                window.getChildAt(0).startAnimation(animation);
            } else {
                // remove the window from the window manager
                mWindowManager.removeView(window);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // display the notification
        notification.flags = notification.flags | Notification.FLAG_NO_CLEAR | Notification.FLAG_AUTO_CANCEL;
        mNotificationManager.notify(getClass().hashCode() + id, notification);
    } else {
        // if hide not enabled, close window
        close(id);
    }
}
Also used : Window(wei.mark.standout.ui.Window) PopupWindow(android.widget.PopupWindow) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener) Notification(android.app.Notification)

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