use of wei.mark.standout.ui.Window in project StandOut by pingpongboss.
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.");
}
if (window.visibility == Window.VISIBILITY_GONE) {
throw new IllegalStateException("Tried to bringToFront(" + id + ") a window that is not shown.");
}
if (window.visibility == Window.VISIBILITY_TRANSITION) {
return;
}
// alert callbacks and cancel if instructed
if (onBringToFront(id, window)) {
Log.w(TAG, "Window " + id + " bring to front cancelled by implementation.");
return;
}
StandOutLayoutParams params = window.getLayoutParams();
// remove from window manager then add back
try {
mWindowManager.removeView(window);
} catch (Exception ex) {
ex.printStackTrace();
}
try {
mWindowManager.addView(window, params);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of wei.mark.standout.ui.Window in project StandOut by pingpongboss.
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) {
throw new IllegalArgumentException("Tried to updateViewLayout(" + id + ") a null window.");
}
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();
}
}
use of wei.mark.standout.ui.Window in project StandOut by pingpongboss.
the class StandOutWindow method show.
/**
* Show or restore a window corresponding to the id. Return the window that
* was shown/restored.
*
* @param id
* The id of the window.
* @return The window shown.
*/
public final synchronized Window show(int id) {
// get the window corresponding to the id
Window cachedWindow = getWindow(id);
final Window window;
// check cache first
if (cachedWindow != null) {
window = cachedWindow;
} else {
window = new Window(this, id);
}
// alert callbacks and cancel if instructed
if (onShow(id, window)) {
Log.d(TAG, "Window " + id + " show cancelled by implementation.");
return null;
}
// focus an already shown window
if (window.visibility == Window.VISIBILITY_VISIBLE) {
Log.d(TAG, "Window " + id + " is already shown.");
focus(id);
return window;
}
window.visibility = Window.VISIBILITY_VISIBLE;
// get animation
Animation animation = getShowAnimation(id);
// get the params corresponding to the id
StandOutLayoutParams params = window.getLayoutParams();
try {
// add the view to the window manager
mWindowManager.addView(window, params);
// animate
if (animation != null) {
window.getChildAt(0).startAnimation(animation);
}
} catch (Exception ex) {
ex.printStackTrace();
}
// add view to internal map
sWindowCache.putCache(id, getClass(), window);
// get the persistent notification
Notification notification = getPersistentNotification(id);
// show the notification
if (notification != null) {
notification.flags = notification.flags | Notification.FLAG_NO_CLEAR;
// only show notification if not shown before
if (!startedForeground) {
// tell Android system to show notification
startForeground(getClass().hashCode() + ONGOING_NOTIFICATION_ID, notification);
startedForeground = true;
} else {
// update notification if shown before
mNotificationManager.notify(getClass().hashCode() + ONGOING_NOTIFICATION_ID, notification);
}
} else {
// notification can only be null if it was provided before
if (!startedForeground) {
throw new RuntimeException("Your StandOutWindow service must" + "provide a persistent notification." + "The notification prevents Android" + "from killing your service in low" + "memory situations.");
}
}
focus(id);
return window;
}
use of wei.mark.standout.ui.Window in project StandOut by pingpongboss.
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.");
}
// alert callbacks and cancel if instructed
if (onHide(id, window)) {
Log.d(TAG, "Window " + id + " hide cancelled by implementation.");
return;
}
// ignore if window is already hidden
if (window.visibility == Window.VISIBILITY_GONE) {
Log.d(TAG, "Window " + id + " is already hidden.");
}
// 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);
}
}
use of wei.mark.standout.ui.Window in project StandOut by pingpongboss.
the class FloatingFolder method onReceiveData.
@Override
public void onReceiveData(int id, int requestCode, Bundle data, Class<? extends StandOutWindow> fromCls, int fromId) {
switch(requestCode) {
case APP_SELECTOR_CODE:
if (APP_SELECTOR_ID == id) {
// app selector receives data
Window window = show(APP_SELECTOR_ID);
window.data.putInt("fromId", fromId);
}
break;
case APP_SELECTOR_FINISHED_CODE:
final ActivityInfo app = data.getParcelable("app");
Log.d("FloatingFolder", "Received app: " + app);
Window window = getWindow(id);
if (window == null) {
return;
}
ViewGroup flow = (ViewGroup) window.findViewById(R.id.flow);
addAppToFolder(id, app, flow);
onUserAddApp(id, app);
break;
case STARTUP_CODE:
loadAllFolders();
if (mFolders.size() == 0) {
mFolders.put(DEFAULT_ID, new FolderModel());
show(DEFAULT_ID);
} else {
for (int i = 0; i < mFolders.size(); i++) {
FolderModel folder = mFolders.get(mFolders.keyAt(i));
if (folder.shown) {
show(folder.id);
}
}
}
break;
}
}
Aggregations