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);
}
});
}
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();
}
}
Aggregations