use of wei.mark.standout.ui.Window in project FloatingStickies by MohammadAdib.
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) {
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);
}
}
});
gracePeriod = System.currentTimeMillis();
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();
}
}
}
use of wei.mark.standout.ui.Window in project FloatingStickies by MohammadAdib.
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(final int id) {
if (gracePeriodOver()) {
inFront = 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);
}
if (window.visibility == Window.VISIBILITY_VISIBLE) {
throw new IllegalStateException("Tried to show(" + id + ") a window that is already shown.");
}
// alert callbacks and cancel if instructed
if (onShow(id, window)) {
Log.d(TAG, "Window " + id + " show cancelled by implementation.");
return null;
}
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) {
gracePeriod = System.currentTimeMillis();
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);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String s = prefs.getString("_id" + id, "");
try {
if (!s.equals("")) {
window.setText(getStringFromFile(s.split(",")[4]));
}
} catch (Exception e) {
e.printStackTrace();
}
return window;
} else {
return null;
}
}
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();
}
}
use of wei.mark.standout.ui.Window in project StandOut by pingpongboss.
the class FloatingFolder method createAndAttachView.
@Override
public void createAndAttachView(final int id, FrameLayout frame) {
LayoutInflater inflater = LayoutInflater.from(this);
// choose which type of window to show
if (APP_SELECTOR_ID == id) {
final View view = inflater.inflate(R.layout.app_selector, frame, true);
final ListView listView = (ListView) view.findViewById(R.id.list);
final List<ActivityInfo> apps = new ArrayList<ActivityInfo>();
listView.setClickable(true);
final AppAdapter adapter = new AppAdapter(this, R.layout.app_row, apps);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
Window window = getWindow(id);
// close self
close(id);
ActivityInfo app = (ActivityInfo) parent.getItemAtPosition(position);
// send data back
if (window.data.containsKey("fromId")) {
Bundle data = new Bundle();
data.putParcelable("app", app);
sendData(id, FloatingFolder.class, window.data.getInt("fromId"), APP_SELECTOR_FINISHED_CODE, data);
}
}
});
new Thread(new Runnable() {
@Override
public void run() {
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> resolveApps = getPackageManager().queryIntentActivities(mainIntent, 0);
Collections.sort(resolveApps, new Comparator<ResolveInfo>() {
@Override
public int compare(ResolveInfo app1, ResolveInfo app2) {
String label1 = app1.loadLabel(mPackageManager).toString();
String label2 = app2.loadLabel(mPackageManager).toString();
return label1.compareTo(label2);
}
});
for (ResolveInfo resolveApp : resolveApps) {
apps.add(resolveApp.activityInfo);
}
Log.d("FloatingFolder", "before");
view.post(new Runnable() {
@Override
public void run() {
Log.d("FloatingFolder", "after");
adapter.notifyDataSetChanged();
}
});
}
}).start();
View cancel = view.findViewById(R.id.cancel);
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// close self
close(id);
}
});
} else {
// id is not app selector
View view = inflater.inflate(R.layout.folder, frame, true);
FlowLayout flow = (FlowLayout) view.findViewById(R.id.flow);
if (mFolders == null) {
loadAllFolders();
}
FolderModel folder = mFolders.get(id);
if (folder != null) {
for (ActivityInfo app : folder.apps) {
addAppToFolder(id, app, flow);
}
}
}
}
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);
}
});
}
Aggregations