Commit 0f76b6a5 authored by jcqln's avatar jcqln
Browse files

Client: map (kinda different)

parent 9957ed54
package com.sist.j.grandquest;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link MapFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link MapFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class MapFragment extends Fragment implements View.OnTouchListener {
private MapGridView sqrTable;
private int currentSqrDraw = R.drawable.blue_sqr40; //like put the chara on that square
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.table_fragment, container, true);
sqrTable = (MapGridView) v.findViewById(R.id.sqrTable);
sqrTable.setOnTouchListener(this);
//create grid
sqrTable.setCurrentColor(currentSqrDraw);
this.setRetainInstance(true);
return v;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int) event.getX() ;
int y = (int) event.getY() ;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
sqrTable.changeSqrColor(x, y); //like changePlace
return true;
}
else if (event.getAction() == MotionEvent.ACTION_MOVE) {
sqrTable.changeSqrColor(x, y); //like changePlace
return true;
}
return false;
}
public void setCurrentSqr(int id) {
this.currentSqrDraw = id;
sqrTable.setCurrentColor(currentSqrDraw); //like setCurrentPlace
}
/* public void clearBoard() {
sqrTable.removeAllViews();
sqrTable.invalidate();
createBoard();
}
public Bitmap createBitmap() {
return sqrTable.createBitmap();
}
public void setBackground(int resourceId) {
sqrTable.setBackgroundResource(resourceId);
}*/
/*
@SuppressWarnings("deprecation")
public void setBackground(Bitmap b) {
sqrTable.setBackgroundDrawable(new BitmapDrawable(this.getResources(), b ) );
}
*/
/* private void createBoard() {
//define table grid
Display d = getActivity().getWindowManager().getDefaultDisplay();
//draw square, not really quite like this
int sqrSize = (int) (TableConfig.convertDpToPixel(TableConfig.DEFAULT_SQR_SIZE, getActivity()));
int[] vals = sqrTable.disposeSqr(d.getWidth(), d.getHeight(), sqrSize); //later, getWidth & getHeight from server
}*/
}
\ No newline at end of file
package com.sist.j.grandquest;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.widget.SlidingPaneLayout;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.GridView;
import com.sist.j.grandquest.MapFragment;
import com.sist.j.grandquest.MenuFragment;
public class MapGridActivity extends Activity {
//plus slidingpanelayout
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_grid);
GridView gridview = (GridView) findViewById(R.id.gridview);
final MapGridView.GridAdapter gridadapter = new MapGridView.GridAdapter(this);
gridview.setAdapter(gridadapter));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(gridadapter.getItem(position).getImageUrlString()));
startActivity(i);
}
});
}
}
/*
public class MapGridActivity extends Activity implements
MenuFragment.MenuEventListener {
private SlidingPaneLayout sPaneLy;
private MapFragment sqrTableFrag;
private static final int SELECT_PICTURE = 1410;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
this.sPaneLy = (SlidingPaneLayout) findViewById(R.id.sp);
sqrTableFrag = (MapFragment) getFragmentManager()
.findFragmentById(R.id.sqrTable);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_donate) {
// Show popup
// Handle donate here
}
return false;
}
@Override
public void onSqrSelected(int sqrId) {
sqrTableFrag.setCurrentSqr(sqrId);
closeMenu();
}
@Override
/* public void onClearSelected() {
closeMenu();
LayoutInflater inf = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inf.inflate(R.layout.popclear_layout, null, false);
final PopupWindow pw = new PopupWindow(v);
pw.setWidth(RelativeLayout.LayoutParams.WRAP_CONTENT);
pw.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
TextView yesTxt = (TextView) v.findViewById(R.id.dlgYes);
TextView noTxt = (TextView) v.findViewById(R.id.dlgNo);
noTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pw.dismiss();
}
});
yesTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pw.dismiss();
sqrTableFrag.clearBoard();
}
});
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
}*/
/*@Override
public void onSaveSelected() {
closeMenu();
LayoutInflater inf = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inf.inflate(R.layout.popsave_layout, null, false);
final PopupWindow pw = new PopupWindow(v);
pw.setFocusable(true);
pw.setWidth(RelativeLayout.LayoutParams.WRAP_CONTENT);
pw.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
final EditText edt = (EditText) v.findViewById(R.id.edtFileName);
TextView saveTxt = (TextView) v.findViewById(R.id.dlgSave);
TextView cancelTxt = (TextView) v.findViewById(R.id.dlgCancel);
cancelTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pw.dismiss();
}
});
saveTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pw.dismiss();
Bitmap b = sqrTableFrag.createBitmap();
try {//to save data
ImageUtility.saveImage(b, edt.getEditableText().toString(),
MapGridActivity.this);
} catch (SaveFileException sfe) {
Toast.makeText(MapGridActivity.this,
getResources().getText(R.string.msgSaveFileError),
Toast.LENGTH_LONG).show();
}
}
});
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SELECT_PICTURE:
if (resultCode == RESULT_OK) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap bkgImg = BitmapFactory.decodeFile(filePath);
Display disp = getWindowManager().getDefaultDisplay();
int w = disp.getWidth();
int h = disp.getHeight();
double scaleX = (w * 1.0) / bkgImg.getWidth();
double scaleY = (h * 1.0) / bkgImg.getHeight();
double scale = Math.min(scaleX, scaleY);
double sw = w * scaleX;
double sh = h * scaleY;
bkgImg = Bitmap.createBitmap(bkgImg, 0, 0, w, h);
sqrTableFrag.setBackground(bkgImg);
}
}
}
private void closeMenu() {
if (sPaneLy.isSlideable()) {
//close the left fragment
sPaneLy.closePane();
}
}
}*/
\ No newline at end of file
package com.sist.j.grandquest;
import com.sist.j.grandquest.R;
import com.sist.j.grandquest.R.drawable;
import com.sist.j.grandquest.R.id;
import com.sist.j.grandquest.R.layout;
import com.sist.j.grandquest.TableConfig;
import android.app.Fragment;
import android.content.Context;
import android.graphics.Shader;
import android.graphics.drawable.ShapeDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
public class MenuFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.menu_fragment, container, true);
ImageAdapter ia = new ImageAdapter(getActivity());
GridView gv = (GridView) v.findViewById(R.id.sqrGrid);
gv.setAdapter(ia);
// Clear btn
final TextView clearTxt = (TextView) v.findViewById(R.id.clearTxt);
final Animation animClear = TableConfig.getRotateAnim(this.getActivity());
animClear.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
( (MenuEventListener) getActivity()).onClearSelected();
}
});
//should automated clear the chara image from previous place ... to prepare to move the chara
clearTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clearTxt.startAnimation(animClear);
}
});
saveTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveTxt.startAnimation(animSave);
}
});
bkgTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bkgTxt.startAnimation(animBkg);
}
});
return v;
}
//Handle logout
//Handle show time
/*
class ImageAdapter extends BaseAdapter {
private Context ctx;
public ImageAdapter(Context ctx) {
this.ctx = ctx;
}
@Override
public int getCount() {
return TableConfig.sqrCharaDraw.length;
}
@Override
public Object getItem(int arg0) {
return TableConfig.sqrCharaDraw;
}
@Override
public long getItemId(int arg0) {
return TableConfig.sqrCharaDraw;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ImageView imageView = null;
if (imageView == null) {
imageView = new ImageView(ctx);
imageView.setLayoutParams(new GridView.LayoutParams(75, 75));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(2, 2, 2, 2);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("SQR", "Sqr:" + TableConfig.sqrCharaDraw[position]);
( (MenuEventListener) getActivity()).onSqrSelected(TableConfig.sqrCharaDraw[position]);
}
});
}
else
imageView = (ImageView) convertView;
imageView.setImageResource(TableConfig.sqrCharaDraw[position]);
return imageView;
}
}
*/
public static interface MenuEventListener {
public void onSqrSelected(int sqrId);
public void onLogoutSelected();
public void onCollectSelected();
public void onInvSelected();
public void onTBoxSelected();
public void onFindSelected();
public void onOfferSelected();
}
}
package com.sist.j.grandquest;
import android.content.Context;
import android.content.res.Resources;
import android.media.MediaPlayer;
import android.util.DisplayMetrics;
public class TableConfig {
public static int DEFAULT_SQR_SIZE = 30;
private static MediaPlayer player ;
public static float convertDpToPixel(float dp, Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return px;
}
public static int sqrCharaDraw {
R.drawable.chara;
}
public static int sqrBackground = R.drawable.tilebkg;
//square, (BG yg nanti ditempatin si chara)
/* public static Animation getFadeScaleOutAnim(Context ctx) {
return AnimationUtils.loadAnimation(ctx.getApplicationContext(), R.anim.fadeout_scaleout);
}
public static Animation getFadeScaleInAnim(Context ctx) {
return AnimationUtils.loadAnimation(ctx.getApplicationContext(), R.anim.fadein_scalein);
}
public static Animation getRotateAnim(Context ctx) {
return AnimationUtils.loadAnimation(ctx.getApplicationContext(), R.anim.rotate);
}*/
public static void playSound(Context ctx) {
if (player != null) {
if (player.isPlaying()) {
return ;
}
}
else
player = MediaPlayer.create(ctx, R.raw.pinsound);
_play();
}
private static void _play() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
player.start();
}
});
t.start();
}
}
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.sist.j.grandquest.MapFragment">
<!-- TODO: Update blank fragment layout -->
<TextView android:layout_width="match_parent" android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/wm"
android:padding="5dp">
<TextView
android:id="@+id/lblMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Map" />
<!--<GridView android:id="@+id/pinGrid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnWidth="70dp"
android:numColumns="auto_fit"
android:verticalSpacing="4dp"
android:horizontalSpacing="4dp"
android:stretchMode="columnWidth"
android:layout_below="@id/lblMenu"
android:layout_centerHorizontal="true"/>-->
<!-- <Button
android:id="@+id/saveTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/clearTxt"
android:layout_alignEnd="@+id/clearTxt"
android:layout_marginBottom="185dp" />-->
<Button