Action bar added.
This commit is contained in:
@@ -11,12 +11,22 @@ import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.zip.Inflater;
|
||||
import static org.dyndns.vahagn.sokoban.App.TAG;
|
||||
import static org.dyndns.vahagn.sokoban.App.theApp;
|
||||
import org.dyndns.vahagn.sokoban.R;
|
||||
import org.dyndns.vahagn.sokoban.Puzzle;
|
||||
import org.dyndns.vahagn.sokoban.MainMenu;
|
||||
import org.dyndns.vahagn.sokoban.menu.MainActivity;
|
||||
|
||||
public class PlayActivity extends Activity
|
||||
implements PuzzleControl.PuzzleControlLister
|
||||
@@ -25,38 +35,33 @@ public class PlayActivity extends Activity
|
||||
protected final static int UNDO_ITEM = 2;
|
||||
|
||||
public Puzzle puzzle = null;
|
||||
public PuzzleControl view;
|
||||
public View title;
|
||||
|
||||
@Override
|
||||
public PuzzleControl puzzle_view;
|
||||
View title_view;
|
||||
public TextView title_text;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
Log.d(TAG, "onCreate: " + savedInstanceState );
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//
|
||||
// No title.
|
||||
//
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
//requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
|
||||
//requestWindowFeature(Window.FEATURE_OPTIONS_PANEL);
|
||||
//getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, RESULT_OK);
|
||||
//getWindow().getWindowStyle().
|
||||
//getWindow().
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Create and set up the view.
|
||||
// Create and set up the puzzle_view.
|
||||
//
|
||||
view = new PuzzleControl( this );
|
||||
setContentView( view );
|
||||
view.setPuzzleControlLister( this );
|
||||
registerForContextMenu(view);
|
||||
puzzle_view = new PuzzleControl( this );
|
||||
setContentView( puzzle_view );
|
||||
puzzle_view.setPuzzleControlLister( this );
|
||||
registerForContextMenu(puzzle_view);
|
||||
//
|
||||
// Create action bar.
|
||||
//
|
||||
FrameLayout rootLayout = (FrameLayout)findViewById(android.R.id.content);
|
||||
View.inflate(this, R.layout.puzzle_view_title, rootLayout);
|
||||
title_text = (TextView)findViewById(R.id.title_text);
|
||||
title_view = findViewById(R.id.puzzle_view_title_layout);
|
||||
//
|
||||
// Load the puzzle.
|
||||
//
|
||||
@@ -64,8 +69,6 @@ public class PlayActivity extends Activity
|
||||
|
||||
if (savedInstanceState == null)
|
||||
{
|
||||
|
||||
|
||||
// We were just launched -- set up a new game
|
||||
// mSnakeView.setMode(SnakeView.READY);
|
||||
}
|
||||
@@ -110,8 +113,7 @@ public class PlayActivity extends Activity
|
||||
{
|
||||
public void onClick(DialogInterface d, int w)
|
||||
{
|
||||
Intent intent = new Intent(PlayActivity.this, MainMenu.class);
|
||||
startActivity( intent );
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("Next",
|
||||
@@ -120,7 +122,7 @@ public class PlayActivity extends Activity
|
||||
public void onClick(DialogInterface d, int w)
|
||||
{
|
||||
loadCurrentPuzzle();
|
||||
view.invalidate();
|
||||
puzzle_view.invalidate();
|
||||
}
|
||||
});
|
||||
AlertDialog dlg = builder.create();
|
||||
@@ -129,62 +131,64 @@ public class PlayActivity extends Activity
|
||||
|
||||
public void onLongPress()
|
||||
{
|
||||
openContextMenu(view);
|
||||
if ( title_view.getVisibility() != View.VISIBLE )
|
||||
showTitle();
|
||||
}
|
||||
|
||||
public boolean onReset()
|
||||
public void onTouch()
|
||||
{
|
||||
loadCurrentPuzzle();
|
||||
view.invalidate();
|
||||
if ( title_view.getVisibility() == View.VISIBLE )
|
||||
hideTitle();
|
||||
}
|
||||
|
||||
public void showTitle()
|
||||
{
|
||||
Animation anim = AnimationUtils.loadAnimation(this, R.animator.puzzle_action_bar_enter);
|
||||
title_view.startAnimation(anim);
|
||||
title_view.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void hideTitle()
|
||||
{
|
||||
Animation anim = AnimationUtils.loadAnimation(this, R.animator.puzzle_action_bar_exit);
|
||||
title_view.startAnimation(anim);
|
||||
title_view.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
public boolean onReset( View v )
|
||||
{
|
||||
while ( puzzle.isUndoable() )
|
||||
puzzle.restore();
|
||||
puzzle_view.invalidate();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onUndo()
|
||||
public boolean onUndo( View v )
|
||||
{
|
||||
if ( puzzle.isUndoable() )
|
||||
{
|
||||
puzzle.restore();
|
||||
view.invalidate();
|
||||
puzzle_view.invalidate();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||
ContextMenuInfo menuInfo)
|
||||
{
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
//
|
||||
// Undo item.
|
||||
//
|
||||
if ( puzzle.isUndoable() )
|
||||
{
|
||||
menu.add("Undo").setOnMenuItemClickListener(
|
||||
new MenuItem.OnMenuItemClickListener(){
|
||||
public boolean onMenuItemClick(MenuItem mi){
|
||||
return onUndo();
|
||||
}
|
||||
});
|
||||
}
|
||||
//
|
||||
// Reset item.
|
||||
//
|
||||
menu.add("Reset").setOnMenuItemClickListener(
|
||||
new MenuItem.OnMenuItemClickListener(){
|
||||
public boolean onMenuItemClick(MenuItem mi){
|
||||
return onReset();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadCurrentPuzzle()
|
||||
{
|
||||
puzzle = theApp().getCurrentPuzzle();
|
||||
view.setPuzzle(puzzle);
|
||||
puzzle_view.setPuzzle(puzzle);
|
||||
|
||||
String title = "Sokoban: level " + new Integer(theApp().getCurrentLevel()).toString();
|
||||
String title = "Level " + new Integer(theApp().getCurrentLevel()).toString();
|
||||
setTitle(title);
|
||||
}
|
||||
|
||||
public void setTitle(CharSequence title)
|
||||
{
|
||||
super.setTitle(title);
|
||||
if (title_text != null) {
|
||||
title_text.setText(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ public class PuzzleControl extends PuzzleView
|
||||
{
|
||||
public void onSolved();
|
||||
public void onLongPress();
|
||||
public void onTouch();
|
||||
}
|
||||
|
||||
public PuzzleControl(Context c)
|
||||
@@ -135,6 +136,11 @@ public class PuzzleControl extends PuzzleView
|
||||
animator.play();
|
||||
}
|
||||
//
|
||||
// Notify that we were touched.
|
||||
//
|
||||
if ( lister != null )
|
||||
lister.onTouch();
|
||||
//
|
||||
// This event is processed.
|
||||
//
|
||||
return true;
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.dyndns.vahagn.sokoban.R;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PuzzleView extends View
|
||||
public class PuzzleView extends View
|
||||
{
|
||||
protected Puzzle puzzle;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user