/*
ApicAday - Everyday.. is different, your mood, your life.
Copyright (c) 2010
Oliver Selinger <oliver.selinger@autburst.com>,
Michael Greifeneder <michael.greifeneder@autburst.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.autburst.picture;
import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class MainActivityController {
private static final int NO_ALBUMS_EXIST = 0;
private static final int ALBUMS_EXIST_NO_IMAGES = 1;
private static final int ALBUM_AND_IMAGES_EXIST = 2;
//stati
private boolean DELETE_BUTTON_VISIBLE = false;
private boolean DELETE_BUTTON_VISIBLE_AND_OPEN = false;
private boolean OPEN_BUTTON_VISIBLE = false;
private boolean OPEN_BUTTON_VISIBLE_AND_OPEN = false;
//actions from gui
public static final int STARTED = -1;
public static final int CREATED_ALBUM = 0;
public static final int PIC_SAVED = 1;
public static final int OPEN_BUTTON_PRESSED = 2;
public static final int OPEN_ALBUM = 4;
public static final int DELETE_BUTTON_PRESSED = 3;
public static final int DELETED_ALBUMS = 5;
private Context ctx;
private ImageButton openButton;
private ImageButton deleteButton;
private LinearLayout deletionPanel;
public MainActivityController(Context ctx, ImageButton openButton, ImageButton deleteButton, LinearLayout deletionPanel) {
this.ctx = ctx;
this.openButton = openButton;
this.deleteButton = deleteButton;
this.deletionPanel = deletionPanel;
}
/**
* brings controller stati and buttons back to start position
*/
public void reset() {
openButton.setVisibility(View.GONE);
deleteButton.setVisibility(View.GONE);
DELETE_BUTTON_VISIBLE = false;
DELETE_BUTTON_VISIBLE_AND_OPEN = false;
OPEN_BUTTON_VISIBLE = false;
OPEN_BUTTON_VISIBLE_AND_OPEN = false;
}
public void transformGUI(int cmd) {
int albumStatus = getAlbumStatus();
switch (cmd) {
case STARTED:
switch (albumStatus) {
case NO_ALBUMS_EXIST:
//do nothing (set buttons gone in xml)
break;
case ALBUMS_EXIST_NO_IMAGES:
//fade in delete button
AnimationHelper.fadeInFromLeftToRight(ctx, deleteButton);
DELETE_BUTTON_VISIBLE = true;
break;
case ALBUM_AND_IMAGES_EXIST:
//fade in delete and open button
AnimationHelper.fadeInFromLeftToRight(ctx, deleteButton);
DELETE_BUTTON_VISIBLE = true;
AnimationHelper.fadeInFromRightToLeft(ctx, openButton);
OPEN_BUTTON_VISIBLE = true;
break;
}
break;
case CREATED_ALBUM:
//fade in delete button if not visible
if(!DELETE_BUTTON_VISIBLE) {
AnimationHelper.fadeInFromLeftToRight(ctx, deleteButton);
DELETE_BUTTON_VISIBLE = true;
}
break;
case PIC_SAVED:
//fade in open button if not visible and delete button not open
if(!OPEN_BUTTON_VISIBLE && !DELETE_BUTTON_VISIBLE_AND_OPEN) {
AnimationHelper.fadeInFromRightToLeft(ctx, openButton);
OPEN_BUTTON_VISIBLE = true;
}
break;
case OPEN_BUTTON_PRESSED:
if (!OPEN_BUTTON_VISIBLE_AND_OPEN) {
//fade out delete button
AnimationHelper.fadeOutToLeftSide(ctx, deleteButton);
DELETE_BUTTON_VISIBLE = false;
OPEN_BUTTON_VISIBLE_AND_OPEN = true;
} else if(OPEN_BUTTON_VISIBLE_AND_OPEN) {
//fade in delete button
AnimationHelper.fadeInFromLeftToRight(ctx, deleteButton);
DELETE_BUTTON_VISIBLE = true;
OPEN_BUTTON_VISIBLE_AND_OPEN = false;
}
break;
case OPEN_ALBUM:
//fade in delete button
// AnimationHelper.fadeInFromLeftToRight(ctx, deleteButton);
// DELETE_BUTTON_VISIBLE = true;
OPEN_BUTTON_VISIBLE_AND_OPEN = false;
break;
case DELETE_BUTTON_PRESSED:
if (!DELETE_BUTTON_VISIBLE_AND_OPEN) {
//fade out open button if visible
if (OPEN_BUTTON_VISIBLE) {
AnimationHelper.fadeOutToRightSide(ctx, openButton);
OPEN_BUTTON_VISIBLE = false;
}
// open deletionPanel
Animation myFadeInAnimation = AnimationUtils.loadAnimation(
ctx, R.anim.slight_top);
deletionPanel.startAnimation(myFadeInAnimation);
deletionPanel.setVisibility(View.VISIBLE);
DELETE_BUTTON_VISIBLE_AND_OPEN = true;
} else if(DELETE_BUTTON_VISIBLE_AND_OPEN) {
//fade in open button if allowed
switch (albumStatus) {
case ALBUM_AND_IMAGES_EXIST:
//fade in delete and open button
AnimationHelper.fadeInFromRightToLeft(ctx, openButton);
OPEN_BUTTON_VISIBLE = true;
break;
}
// close deletionPanel
Animation myFadeInAnimation = AnimationUtils.loadAnimation(
ctx, R.anim.slight_bottom);
deletionPanel.startAnimation(myFadeInAnimation);
deletionPanel.setVisibility(View.GONE);
DELETE_BUTTON_VISIBLE_AND_OPEN = false;
}
break;
case DELETED_ALBUMS:
// close deletionPanel
Animation myFadeInAnimation = AnimationUtils.loadAnimation(
ctx, R.anim.slight_bottom);
deletionPanel.startAnimation(myFadeInAnimation);
deletionPanel.setVisibility(View.GONE);
DELETE_BUTTON_VISIBLE_AND_OPEN = false;
switch (albumStatus) {
case NO_ALBUMS_EXIST:
//if open and delete buttons visible fade out
if (OPEN_BUTTON_VISIBLE) {
AnimationHelper.fadeOutToRightSide(ctx, openButton);
OPEN_BUTTON_VISIBLE = false;
}
if (DELETE_BUTTON_VISIBLE) {
AnimationHelper.fadeOutToLeftSide(ctx, deleteButton);
DELETE_BUTTON_VISIBLE = false;
}
break;
case ALBUMS_EXIST_NO_IMAGES:
//fade out open button if visible
if (OPEN_BUTTON_VISIBLE) {
AnimationHelper.fadeOutToRightSide(ctx, openButton);
OPEN_BUTTON_VISIBLE = false;
}
break;
case ALBUM_AND_IMAGES_EXIST:
//do nothing
break;
}
break;
default:
break;
}
}
private int getAlbumStatus() {
if(Utilities.hasAnyAlbumPics())
return ALBUM_AND_IMAGES_EXIST;
else if(Utilities.hasAlbums())
return ALBUMS_EXIST_NO_IMAGES;
else
return NO_ALBUMS_EXIST;
}
}