Action bar added.
This commit is contained in:
27
res/animator/puzzle_action_bar_enter.xml
Normal file
27
res/animator/puzzle_action_bar_enter.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
** Copyright 2011, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
-->
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate
|
||||
android:interpolator="@android:anim/accelerate_interpolator"
|
||||
android:fromXDelta="0"
|
||||
android:toXDelta="0"
|
||||
android:fromYDelta="-100%"
|
||||
android:toYDelta="0"
|
||||
android:duration="@android:integer/config_mediumAnimTime" />
|
||||
</set>
|
||||
27
res/animator/puzzle_action_bar_exit.xml
Normal file
27
res/animator/puzzle_action_bar_exit.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
** Copyright 2011, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
-->
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate
|
||||
android:interpolator="@android:anim/accelerate_interpolator"
|
||||
android:fromXDelta="0"
|
||||
android:toXDelta="0"
|
||||
android:fromYDelta="0%"
|
||||
android:toYDelta="-100%"
|
||||
android:duration="@android:integer/config_mediumAnimTime" />
|
||||
</set>
|
||||
49
res/layout/puzzle_view_title.xml
Normal file
49
res/layout/puzzle_view_title.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/puzzle_view_title_layout"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_horizontal"
|
||||
android:background="#60404040"
|
||||
android:layout_height="50dp"
|
||||
android:layout_width="match_parent">
|
||||
<TextView
|
||||
android:text="Level"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
android:textSize="40dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:textScaleX="1"
|
||||
android:textColor="#FFE680"
|
||||
android:textStyle="bold"
|
||||
android:typeface="normal"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/title_text"/>
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
<ImageButton
|
||||
android:src="@drawable/undo"
|
||||
android:scaleType="fitCenter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="0"
|
||||
android:layout_margin="3dp"
|
||||
android:background="#00000000"
|
||||
android:onClick="onUndo"
|
||||
android:id="@+id/undo_btn"/>
|
||||
<ImageButton
|
||||
android:src="@drawable/reset"
|
||||
android:scaleType="fitCenter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="0"
|
||||
android:layout_margin="3dp"
|
||||
android:background="#00000000"
|
||||
android:onClick="onReset"
|
||||
android:id="@+id/reset_btn"/>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -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;
|
||||
public PuzzleControl puzzle_view;
|
||||
View title_view;
|
||||
public TextView title_text;
|
||||
|
||||
@Override
|
||||
@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;
|
||||
|
||||
Reference in New Issue
Block a user