Two new fragments added to the main activity. One of which is the puzzle list on view grid.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
android:name="org.dyndns.vahagn.sokoban.App"
|
||||
android:icon="@drawable/icon"
|
||||
android:theme="@android:style/Theme">
|
||||
<activity android:name="org.dyndns.vahagn.sokoban.MainMenu"
|
||||
<activity android:name="org.dyndns.vahagn.sokoban.menu.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:screenOrientation="portrait" >
|
||||
|
||||
27
res/animator/fragment_slide_left_enter.xml
Normal file
27
res/animator/fragment_slide_left_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="100%"
|
||||
android:toXDelta="0%"
|
||||
android:fromYDelta="0"
|
||||
android:toYDelta="0"
|
||||
android:duration="@android:integer/config_mediumAnimTime" />
|
||||
</set>
|
||||
27
res/animator/fragment_slide_left_exit.xml
Normal file
27
res/animator/fragment_slide_left_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="-100%"
|
||||
android:fromYDelta="0"
|
||||
android:toYDelta="0"
|
||||
android:duration="@android:integer/config_mediumAnimTime" />
|
||||
</set>
|
||||
27
res/animator/fragment_slide_right_enter.xml
Normal file
27
res/animator/fragment_slide_right_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="-100%"
|
||||
android:toXDelta="0"
|
||||
android:fromYDelta="0"
|
||||
android:toYDelta="0"
|
||||
android:duration="@android:integer/config_mediumAnimTime" />
|
||||
</set>
|
||||
27
res/animator/fragment_slide_right_exit.xml
Normal file
27
res/animator/fragment_slide_right_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="100%"
|
||||
android:fromYDelta="0"
|
||||
android:toYDelta="0"
|
||||
android:duration="@android:integer/config_mediumAnimTime" />
|
||||
</set>
|
||||
8
res/layout/main_activity.xml
Normal file
8
res/layout/main_activity.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/fragment_container"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
</LinearLayout>
|
||||
|
||||
61
res/layout/main_fragment.xml
Normal file
61
res/layout/main_fragment.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="@drawable/splash"
|
||||
android:gravity="center_vertical">
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="top"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center" />
|
||||
<Button
|
||||
android:id="@+id/btn_start"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/main_menu_btn_vmargin"
|
||||
android:layout_marginBottom="@dimen/main_menu_btn_vmargin"
|
||||
android:layout_marginLeft="@dimen/main_menu_btn_hmargin"
|
||||
android:layout_marginRight="@dimen/main_menu_btn_hmargin"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0"
|
||||
android:padding="@dimen/main_menu_btn_padding"
|
||||
android:background="@color/main_menu_btn_bg"
|
||||
android:textColor="@color/main_menu_btn_text"
|
||||
android:textSize="@dimen/main_menu_text_size"
|
||||
android:text="@string/btn_start_continue"
|
||||
android:onClick="onStartCurrentPuzzle" />
|
||||
<Button
|
||||
android:id="@+id/btn_puzzles"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/main_menu_btn_vmargin"
|
||||
android:layout_marginBottom="@dimen/main_menu_btn_vmargin"
|
||||
android:layout_marginLeft="@dimen/main_menu_btn_hmargin"
|
||||
android:layout_marginRight="@dimen/main_menu_btn_hmargin"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0"
|
||||
android:padding="@dimen/main_menu_btn_padding"
|
||||
android:background="@color/main_menu_btn_bg"
|
||||
android:textColor="@color/main_menu_btn_text"
|
||||
android:textSize="@dimen/main_menu_text_size"
|
||||
android:text="@string/btn_puzzles"
|
||||
android:onClick="onPuzzleListShow" />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center" />
|
||||
<TextView
|
||||
android:id="@+id/footer_txt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/git_version"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_weight="0"
|
||||
android:gravity="center" />
|
||||
</LinearLayout>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<GridView
|
||||
android:id="@+id/puzzle_grid"
|
||||
android:layout_width="match_parent"
|
||||
@@ -14,14 +13,5 @@
|
||||
android:numColumns="auto_fit"
|
||||
android:stretchMode="columnWidth"
|
||||
android:gravity="center" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_start"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onStartCurrentPuzzle"
|
||||
android:text="Start" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
23
res/values/colors.xml
Normal file
23
res/values/colors.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
**
|
||||
** Copyright 2008, 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.
|
||||
*/
|
||||
-->
|
||||
<resources>
|
||||
<color name="main_menu_btn_bg">#80404040</color>
|
||||
<color name="main_menu_btn_text">#C0C0C0C0</color>
|
||||
</resources>
|
||||
26
res/values/dimens.xml
Normal file
26
res/values/dimens.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
**
|
||||
** Copyright 2008, 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<dimen name="main_menu_text_size">18pt</dimen>
|
||||
<dimen name="main_menu_btn_hmargin">10pt</dimen>
|
||||
<dimen name="main_menu_btn_vmargin">2pt</dimen>
|
||||
<dimen name="main_menu_btn_padding">10pt</dimen>
|
||||
</resources>
|
||||
@@ -3,4 +3,9 @@
|
||||
<string name="app_name">Free Sokoban</string>
|
||||
<string name="menu">Menu</string>
|
||||
<string name="play_activity">play_activity</string>
|
||||
<string name="btn_start_begin">Begin</string>
|
||||
<string name="btn_start_continue">Continue</string>
|
||||
<string name="btn_puzzles">Puzzles</string>
|
||||
<string name="version_tag">Version:</string>
|
||||
<string name="copyright">(c) 2013 Vahagn Khachatryan</string>
|
||||
</resources>
|
||||
|
||||
35
res/values/styles.xml
Normal file
35
res/values/styles.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!--style name="WindowTitle">
|
||||
<item name="android:singleLine">true</item-->
|
||||
<!--item name="android:textAppearance">@style/TextAppearance.WindowTitle</item-->
|
||||
<!-- item name="android:shadowColor">#BB000000</item>
|
||||
<item name="android:shadowRadius">2.75</item>
|
||||
</style-->
|
||||
<!-- Base application theme is the default theme. -->
|
||||
<!--style name="Theme.puzzle_view_title" parent="android:Theme"-->
|
||||
<!--style name="puzzle_view_title_layout">
|
||||
<item name="android:windowTitleStyle">@style/title_bar</item>
|
||||
<item name="android:windowTitleSize">10mm</item-->
|
||||
<!--item name="android:windowTitleBackgroundStyle">@style/title_background</item-->
|
||||
<!--/style-->
|
||||
<!--style name="title_bar">
|
||||
<item name="android:singleLine">false</item>
|
||||
<item name="android:textAppearance">@android:style/TextAppearance.WindowTitle</item>
|
||||
<item name="android:shadowColor">#BB0000FF</item>
|
||||
<item name="android:shadowRadius">2.75</item>
|
||||
</style-->
|
||||
<!--style name="title_background">
|
||||
<item name="android:background">@drawable/background_square</item>
|
||||
</style-->
|
||||
|
||||
<!--style name="PlainText">
|
||||
<item name="android:textAppearance">@style/TextAppearance.Theme.PlainText</item>
|
||||
</style-->
|
||||
|
||||
<!--style name="ImageView240dpi">
|
||||
<item name="android:src">@drawable/stylogo240dpi</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
</style-->
|
||||
</resources>
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.dyndns.vahagn.sokoban;
|
||||
package org.dyndns.vahagn.sokoban.menu;
|
||||
|
||||
import org.dyndns.vahagn.sokoban.play.PlayActivity;
|
||||
import android.app.Activity;
|
||||
@@ -12,6 +12,10 @@ import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.view.View;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Display;
|
||||
@@ -22,13 +26,17 @@ import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import org.dyndns.vahagn.sokoban.R;
|
||||
import static org.dyndns.vahagn.sokoban.App.theApp;
|
||||
|
||||
public class MainMenu extends Activity
|
||||
public class MainActivity extends FragmentActivity
|
||||
{
|
||||
protected final String TAG = "SokobanMenu";
|
||||
protected final String LEVEL= "org.dyndns.vahagn.sokoban.LEVEL";
|
||||
protected GridView puzzle_grid;
|
||||
protected MainFragment mainFragment;
|
||||
protected PuzzleListFragment puzzleListFragment;
|
||||
protected float puzzleListXScroll;
|
||||
protected float puzzleListXScrollMax;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
@@ -37,145 +45,31 @@ public class MainMenu extends Activity
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.menu);
|
||||
setContentView(R.layout.main_activity);
|
||||
|
||||
puzzle_grid = (GridView)findViewById(R.id.puzzle_grid);
|
||||
puzzle_grid.setAdapter( new PuzzlesAdapter(this) );
|
||||
//puzzle_grid.addView(puzzle_grid);
|
||||
puzzle_grid.setOnItemClickListener(new OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
|
||||
{
|
||||
onPuzzleClicked(v,(int)id);
|
||||
mainFragment = new MainFragment();
|
||||
puzzleListFragment = new PuzzleListFragment();
|
||||
puzzleListFragment.setOnPuzzleListAction(new PuzzleListFragment.OnPuzzleListAction() {
|
||||
public boolean onPuzzleGridDown() {
|
||||
return onPuzzleGridDown1();
|
||||
}
|
||||
public boolean onPuzzleGridXScroll(float x) {
|
||||
return onPuzzleGridXScroll1(x);
|
||||
}
|
||||
public void onPuzzleLevelClicked(int level) {
|
||||
onPuzzleClicked1(level);
|
||||
}
|
||||
});
|
||||
}
|
||||
puzzleListXScrollMax = getWindowManager().getDefaultDisplay().getWidth();
|
||||
|
||||
public class PuzzlesAdapter extends BaseAdapter
|
||||
{
|
||||
private Context mContext;
|
||||
private int icon_size;
|
||||
private int text_x;
|
||||
private int text_y;
|
||||
private Bitmap lock_icon;
|
||||
private Bitmap unlock_icon;
|
||||
private Paint paint;
|
||||
|
||||
public PuzzlesAdapter(Context c)
|
||||
{
|
||||
mContext = c;
|
||||
icon_size = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 10, getResources().getDisplayMetrics() );
|
||||
int text_size = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 4, getResources().getDisplayMetrics() );
|
||||
text_x = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 9, getResources().getDisplayMetrics() );
|
||||
text_y = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 9, getResources().getDisplayMetrics() );
|
||||
|
||||
Bitmap lock_icon_tmp = BitmapFactory.decodeResource( getResources(), R.drawable.lock );
|
||||
lock_icon = Bitmap.createBitmap(icon_size,icon_size,Bitmap.Config.ARGB_8888);
|
||||
Canvas lock_canvas = new Canvas(lock_icon);
|
||||
lock_canvas.drawBitmap(lock_icon_tmp,
|
||||
new Rect(0,0,lock_icon_tmp.getWidth()-1,lock_icon_tmp.getHeight()-1),
|
||||
new Rect(0,0,icon_size, icon_size),
|
||||
null);
|
||||
|
||||
Bitmap unlock_icon_tmp = BitmapFactory.decodeResource( getResources(), R.drawable.unlock );
|
||||
unlock_icon = Bitmap.createBitmap(icon_size,icon_size,Bitmap.Config.ARGB_8888);
|
||||
Canvas unlock_canvas = new Canvas(unlock_icon);
|
||||
unlock_canvas.drawBitmap(unlock_icon_tmp,
|
||||
new Rect(0,0,unlock_icon_tmp.getWidth()-1,unlock_icon_tmp.getHeight()-1),
|
||||
new Rect(0,0,icon_size, icon_size),
|
||||
null);
|
||||
|
||||
paint = new Paint();
|
||||
paint.setColor( Color.WHITE );
|
||||
paint.setTextSize( text_size );
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
}
|
||||
|
||||
public int getCount()
|
||||
{
|
||||
return theApp().getPuzzleCount();
|
||||
}
|
||||
|
||||
public Object getItem(int position)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getItemId(int position)
|
||||
{
|
||||
return position+1;
|
||||
}
|
||||
|
||||
// create a new ImageView for each item referenced by the Adapter
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
ImageView imageView;
|
||||
if (convertView == null)
|
||||
{ // if it's not recycled, initialize some attributes
|
||||
imageView = new ImageView(mContext);
|
||||
imageView.setLayoutParams(new GridView.LayoutParams(icon_size, icon_size));
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
// imageView.setPadding(8, 8, 8, 8);
|
||||
}
|
||||
else
|
||||
imageView = (ImageView) convertView;
|
||||
|
||||
int id = (int)getItemId(position);
|
||||
Bitmap icon = ( id <= theApp().getAchivedLevel() )
|
||||
? unlock_icon.copy(Bitmap.Config.ARGB_8888,true)
|
||||
: lock_icon.copy(Bitmap.Config.ARGB_8888,true);
|
||||
Canvas canvas = new Canvas(icon);
|
||||
canvas.drawText( Integer.toString(id), text_x, text_y, paint);
|
||||
imageView.setImageBitmap(icon);
|
||||
return imageView;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
Log.d(TAG, "onStart: " );
|
||||
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestart()
|
||||
{
|
||||
Log.d(TAG, "onRestart: " );
|
||||
|
||||
super.onRestart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
Log.d(TAG, "onResume: " );
|
||||
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
Log.d(TAG, "onPause: " );
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
Log.d(TAG, "onStop: " );
|
||||
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
Log.d(TAG, "onDestroy: " );
|
||||
|
||||
super.onDestroy();
|
||||
//
|
||||
// Set initila fragment.
|
||||
//
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||
fragmentTransaction.add(R.id.fragment_container, mainFragment);
|
||||
// fragmentTransaction.add(R.id.fragment_container, puzzleListFragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
//@Override
|
||||
@@ -191,12 +85,51 @@ public class MainMenu extends Activity
|
||||
startActivity( intent );
|
||||
}
|
||||
|
||||
public void onPuzzleClicked(View v, int level )
|
||||
public void onPuzzleListShow(View v)
|
||||
{
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.setCustomAnimations(R.animator.fragment_slide_left_enter,
|
||||
R.animator.fragment_slide_left_exit)
|
||||
.replace(R.id.fragment_container, puzzleListFragment)
|
||||
.commit();
|
||||
}
|
||||
|
||||
public boolean onPuzzleGridDown1()
|
||||
{
|
||||
puzzleListXScroll = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onPuzzleGridXScroll1( float x )
|
||||
{
|
||||
puzzleListXScroll += x;
|
||||
Log.d(TAG, Float.toString(puzzleListXScroll));
|
||||
/*
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.setCustomAnimations(R.animator.fragment_slide_right_enter,
|
||||
R.animator.fragment_slide_right_exit)
|
||||
.commit();
|
||||
*/
|
||||
if ( -puzzleListXScroll/puzzleListXScrollMax > 0.5 )
|
||||
{
|
||||
Log.d(TAG, "annim");
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.setCustomAnimations(R.animator.fragment_slide_right_enter,
|
||||
R.animator.fragment_slide_right_exit)
|
||||
.replace(R.id.fragment_container, mainFragment)
|
||||
.commit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onPuzzleClicked1( int level )
|
||||
{
|
||||
if ( level <= theApp().getAchivedLevel() )
|
||||
{
|
||||
theApp().setCurrentLevel(level);
|
||||
|
||||
Intent intent = new Intent(this, PlayActivity.class);
|
||||
startActivity( intent );
|
||||
}
|
||||
|
||||
39
src/org/dyndns/vahagn/sokoban/menu/MainFragment.java
Normal file
39
src/org/dyndns/vahagn/sokoban/menu/MainFragment.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.dyndns.vahagn.sokoban.menu;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import static org.dyndns.vahagn.sokoban.App.theApp;
|
||||
import org.dyndns.vahagn.sokoban.R;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author vahagnk
|
||||
*/
|
||||
public class MainFragment extends Fragment
|
||||
{
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle)
|
||||
{
|
||||
super.onCreate(icicle);
|
||||
View v = inflater.inflate(R.layout.main_fragment, container, false);
|
||||
if ( theApp().getAchivedLevel() == 1 )
|
||||
((Button)v.findViewById(R.id.btn_start)).setText(R.string.btn_start_begin);
|
||||
//
|
||||
// Set Footer.
|
||||
//
|
||||
String str = getString(R.string.copyright) + "\n"
|
||||
+getString(R.string.version_tag) + " " + getString(R.string.git_version);
|
||||
((TextView)v.findViewById(R.id.footer_txt)).setText(str);
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
187
src/org/dyndns/vahagn/sokoban/menu/PuzzleListFragment.java
Normal file
187
src/org/dyndns/vahagn/sokoban/menu/PuzzleListFragment.java
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.dyndns.vahagn.sokoban.menu;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.TypedValue;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import org.dyndns.vahagn.sokoban.R;
|
||||
import org.dyndns.vahagn.sokoban.R;
|
||||
import static org.dyndns.vahagn.sokoban.App.theApp;
|
||||
import org.dyndns.vahagn.sokoban.play.PlayActivity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author vahagnk
|
||||
*/
|
||||
public class PuzzleListFragment extends Fragment
|
||||
{
|
||||
protected GridView puzzle_grid;
|
||||
GestureDetector gridViewXScrollDetector;
|
||||
|
||||
OnPuzzleListAction lister;
|
||||
|
||||
public interface OnPuzzleListAction
|
||||
{
|
||||
public boolean onPuzzleGridDown();
|
||||
public boolean onPuzzleGridXScroll( float x );
|
||||
public void onPuzzleLevelClicked( int level );
|
||||
}
|
||||
|
||||
public void setOnPuzzleListAction( OnPuzzleListAction l )
|
||||
{
|
||||
lister = l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle)
|
||||
{
|
||||
super.onCreate(icicle);
|
||||
View v = inflater.inflate(R.layout.puzzle_list_fragment, container, false);
|
||||
//
|
||||
// Configure GridView.
|
||||
//
|
||||
puzzle_grid = (GridView)v.findViewById(R.id.puzzle_grid);
|
||||
puzzle_grid.setAdapter( new PuzzlesAdapter(getActivity()) );
|
||||
//puzzle_grid.addView(puzzle_grid);
|
||||
puzzle_grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
|
||||
{
|
||||
onPuzzleClicked(v,(int)id);
|
||||
}
|
||||
});
|
||||
puzzle_grid.setOnTouchListener( new View.OnTouchListener() {
|
||||
public boolean onTouch(View view, MotionEvent me) {
|
||||
gridViewXScrollDetector.onTouchEvent( me );
|
||||
return false;
|
||||
}
|
||||
});
|
||||
gridViewXScrollDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
|
||||
public boolean onDown(MotionEvent e) {
|
||||
return (lister!=null) ? lister.onPuzzleGridDown() : false;
|
||||
}
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float dx, float dy) {
|
||||
return (lister!=null) ? lister.onPuzzleGridXScroll(dx) : false;
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public void onPuzzleClicked(View v, int level )
|
||||
{
|
||||
if (lister!=null)
|
||||
lister.onPuzzleLevelClicked(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if ( puzzle_grid != null )
|
||||
puzzle_grid.invalidate();
|
||||
}
|
||||
|
||||
public class PuzzlesAdapter extends BaseAdapter
|
||||
{
|
||||
private Context context;
|
||||
private int icon_size;
|
||||
private int text_x;
|
||||
private int text_y;
|
||||
private Bitmap lock_icon;
|
||||
private Bitmap unlock_icon;
|
||||
private Paint paint;
|
||||
|
||||
public PuzzlesAdapter(Context c)
|
||||
{
|
||||
context = c;
|
||||
icon_size = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 10, getResources().getDisplayMetrics() );
|
||||
int text_size = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 4, getResources().getDisplayMetrics() );
|
||||
text_x = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 9, getResources().getDisplayMetrics() );
|
||||
text_y = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 9, getResources().getDisplayMetrics() );
|
||||
|
||||
Bitmap lock_icon_tmp = BitmapFactory.decodeResource( getResources(), R.drawable.lock );
|
||||
lock_icon = Bitmap.createBitmap(icon_size,icon_size,Bitmap.Config.ARGB_8888);
|
||||
Canvas lock_canvas = new Canvas(lock_icon);
|
||||
lock_canvas.drawBitmap(lock_icon_tmp,
|
||||
new Rect(0,0,lock_icon_tmp.getWidth()-1,lock_icon_tmp.getHeight()-1),
|
||||
new Rect(0,0,icon_size, icon_size),
|
||||
null);
|
||||
|
||||
Bitmap unlock_icon_tmp = BitmapFactory.decodeResource( getResources(), R.drawable.unlock );
|
||||
unlock_icon = Bitmap.createBitmap(icon_size,icon_size,Bitmap.Config.ARGB_8888);
|
||||
Canvas unlock_canvas = new Canvas(unlock_icon);
|
||||
unlock_canvas.drawBitmap(unlock_icon_tmp,
|
||||
new Rect(0,0,unlock_icon_tmp.getWidth()-1,unlock_icon_tmp.getHeight()-1),
|
||||
new Rect(0,0,icon_size, icon_size),
|
||||
null);
|
||||
|
||||
paint = new Paint();
|
||||
paint.setColor( Color.WHITE );
|
||||
paint.setTextSize( text_size );
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
}
|
||||
|
||||
public int getCount()
|
||||
{
|
||||
return theApp().getPuzzleCount();
|
||||
}
|
||||
|
||||
public Object getItem(int position)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getItemId(int position)
|
||||
{
|
||||
return position+1;
|
||||
}
|
||||
|
||||
// create a new ImageView for each item referenced by the Adapter
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
ImageView imageView;
|
||||
if (convertView == null)
|
||||
{ // if it's not recycled, initialize some attributes
|
||||
imageView = new ImageView(context);
|
||||
imageView.setLayoutParams(new GridView.LayoutParams(icon_size, icon_size));
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
// imageView.setPadding(8, 8, 8, 8);
|
||||
}
|
||||
else
|
||||
imageView = (ImageView) convertView;
|
||||
|
||||
int id = (int)getItemId(position);
|
||||
Bitmap icon = ( id <= theApp().getAchivedLevel() )
|
||||
? unlock_icon.copy(Bitmap.Config.ARGB_8888,true)
|
||||
: lock_icon.copy(Bitmap.Config.ARGB_8888,true);
|
||||
Canvas canvas = new Canvas(icon);
|
||||
canvas.drawText( Integer.toString(id), text_x, text_y, paint);
|
||||
imageView.setImageBitmap(icon);
|
||||
return imageView;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user