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