Add test deck preview screen.

This commit is contained in:
kenkeiras 2018-01-21 12:05:54 +01:00
parent 8fa2e22d55
commit bd20e39785
18 changed files with 297 additions and 16 deletions

View File

@ -29,4 +29,5 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:25.4.0' implementation 'com.android.support:design:25.4.0'
compile 'com.getbase:floatingactionbutton:1.10.1' compile 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.android.support:cardview-v7:25.4.0'
} }

View File

@ -4,7 +4,9 @@
<!-- OpenGL ES 2.0 --> <!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application <application
android:allowBackup="true" android:allowBackup="true"
@ -13,12 +15,23 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".MainActivity"> <activity android:name=".CardActivity">
<intent-filter>
<action android:name="com.codigoparallevar.minicards.CARD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".DeckPreviewActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="com.codigoparallevar.minicards.DECK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity> </activity>
</application> </application>

View File

@ -34,7 +34,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectStreamException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -63,7 +62,7 @@ class CanvasView extends View implements PartGrid {
private String name = "default"; private String name = "default";
private final static float touchTimeForLongTouchInMillis = 500; private final static float touchTimeForLongTouchInMillis = 500;
private boolean _isDragging = false; private boolean _isDragging = false;
private MainActivity parentActivity = null; private CardActivity parentActivity = null;
private Tuple4<Integer, Integer, Integer, Integer> _dropToRemoveZone = new Tuple4<>(0, 0, 0, 0); private Tuple4<Integer, Integer, Integer, Integer> _dropToRemoveZone = new Tuple4<>(0, 0, 0, 0);
private boolean _devMode = false; private boolean _devMode = false;
@ -458,7 +457,7 @@ class CanvasView extends View implements PartGrid {
return _isDragging; return _isDragging;
} }
public void setParentActivity(MainActivity parentActivity) { public void setParentActivity(CardActivity parentActivity) {
this.parentActivity = parentActivity; this.parentActivity = parentActivity;
} }

View File

@ -1,17 +1,17 @@
package com.codigoparallevar.minicards; package com.codigoparallevar.minicards;
import android.app.Dialog; import android.content.Intent;
import android.content.DialogInterface;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
public class MainActivity extends AppCompatActivity { public class CardActivity extends AppCompatActivity {
public final static String INTENT = "com.codigoparallevar.minicards.CARD";
CanvasView canvasView; CanvasView canvasView;
com.getbase.floatingactionbutton.AddFloatingActionButton AddPartButton; com.getbase.floatingactionbutton.AddFloatingActionButton AddPartButton;
@ -21,6 +21,8 @@ public class MainActivity extends AppCompatActivity {
com.getbase.floatingactionbutton.FloatingActionsMenu devFabMenu; com.getbase.floatingactionbutton.FloatingActionsMenu devFabMenu;
com.getbase.floatingactionbutton.FloatingActionsMenu userFabMenu; com.getbase.floatingactionbutton.FloatingActionsMenu userFabMenu;
com.getbase.floatingactionbutton.FloatingActionButton ShowDeckFromDevModeButton;
com.getbase.floatingactionbutton.FloatingActionButton ShowDeckFromUserModeButton;
boolean devMode = false; boolean devMode = false;
FloatingActionButton removePartFab; FloatingActionButton removePartFab;
@ -78,7 +80,27 @@ public class MainActivity extends AppCompatActivity {
SetDevModeButton.setOnClickListener(new View.OnClickListener() { SetDevModeButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
MainActivity.this.setDevMode(true); CardActivity.this.setDevMode(true);
}
});
ShowDeckFromDevModeButton = (com.getbase.floatingactionbutton.FloatingActionButton)
findViewById(R.id.show_deck_from_dev_mode_button);
ShowDeckFromDevModeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(DeckPreviewActivity.INTENT);
CardActivity.this.startActivity(i);
}
});
ShowDeckFromUserModeButton = (com.getbase.floatingactionbutton.FloatingActionButton)
findViewById(R.id.show_deck_from_user_mode_button);
ShowDeckFromUserModeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(DeckPreviewActivity.INTENT);
CardActivity.this.startActivity(i);
} }
}); });
@ -87,7 +109,7 @@ public class MainActivity extends AppCompatActivity {
SetUserModeButton.setOnClickListener(new View.OnClickListener() { SetUserModeButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
MainActivity.this.setDevMode(false); CardActivity.this.setDevMode(false);
} }
}); });
@ -120,7 +142,7 @@ public class MainActivity extends AppCompatActivity {
return canvasView.onTouchEvent(event); return canvasView.onTouchEvent(event);
} }
Log.e("MainActivity", "CanvasView is null"); Log.e("CardActivity", "CanvasView is null");
return super.onTouchEvent(event); return super.onTouchEvent(event);
} }

View File

@ -0,0 +1,49 @@
package com.codigoparallevar.minicards;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
class CardPreviewArrayAdapter extends ArrayAdapter<PreviewCard> {
private final PreviewCard[] cards;
public CardPreviewArrayAdapter(@NonNull Context context, PreviewCard[] cards) {
super(context, R.layout.card_preview);
this.cards = cards;
}
@Override
public int getCount() {
return this.cards.length;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.card_preview, parent, false);
PreviewCard card = this.cards[position];
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(CardActivity.INTENT);
CardPreviewArrayAdapter.this.getContext().startActivity(i);
}
});
CardView cardView = (CardView) row.findViewById(R.id.card_preview_card);
TextView nameView = (TextView) row.findViewById(R.id.card_preview_name);
cardView.setBackgroundColor(card.getColor());
nameView.setText(card.getName());
nameView.setTextColor(0xFFFFFF ^ card.getColor());
return row;
}
}

View File

@ -0,0 +1,46 @@
package com.codigoparallevar.minicards;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ListView;
public class DeckPreviewActivity extends AppCompatActivity {
public static final String INTENT = "com.codigoparallevar.minicards.DECK";
private ListView listView;
private CardPreviewArrayAdapter cardArrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deck_preview);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.create_new_card_fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
listView = (ListView) findViewById(R.id.card_deck_list);
cardArrayAdapter = new CardPreviewArrayAdapter(getApplicationContext(), new PreviewCard[]{
new PreviewCard("Default", 0, PreviewCard.DEFAULT_COLOR),
new PreviewCard("Second", 1, Color.parseColor("#FF00FF")),
new PreviewCard("Greenie", 2, Color.parseColor("#00FF00")),
});
listView.setAdapter(cardArrayAdapter);
}
}

View File

@ -0,0 +1,28 @@
package com.codigoparallevar.minicards;
import android.graphics.Color;
class PreviewCard {
public static final int DEFAULT_COLOR = Color.parseColor("#044563");
private final String name;
private final int cardId;
private final int color;
public PreviewCard(String name, int cardId, int color) {
this.name = name;
this.cardId = cardId;
this.color = color;
}
public String getName() {
return name;
}
public int getCardId() {
return cardId;
}
public int getColor() {
return color;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.codigoparallevar.minicards.DeckPreviewActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_deck_preview" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/create_new_card_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/ic_add_black" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -6,7 +6,7 @@
xmlns:fab="http://schemas.android.com/apk/res-auto" xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.codigoparallevar.minicards.MainActivity"> tools:context="com.codigoparallevar.minicards.CardActivity">
<!-- <!--
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout
@ -26,8 +26,9 @@
<com.codigoparallevar.minicards.CanvasView <com.codigoparallevar.minicards.CanvasView
android:id="@+id/canvasView" android:id="@+id/canvasView"
android:layout_width="match_parent" android:layout_width="383dp"
android:layout_height="match_parent" /> android:layout_height="match_parent"
tools:layout_editor_absoluteX="1dp" />
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/remove_part_fab" android:id="@+id/remove_part_fab"
@ -57,6 +58,14 @@
fab:fab_labelStyle="@style/menu_labels_style" fab:fab_labelStyle="@style/menu_labels_style"
fab:fab_labelsPosition="left"> fab:fab_labelsPosition="left">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/show_deck_from_user_mode_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/white"
fab:fab_title="Show deck"
fab:fab_colorPressed="@color/white_pressed"/>
<com.getbase.floatingactionbutton.FloatingActionButton <com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/set_developer_mode_button" android:id="@+id/set_developer_mode_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -102,6 +111,14 @@
fab:fab_title="Center view" fab:fab_title="Center view"
fab:fab_colorPressed="@color/white_pressed" /> fab:fab_colorPressed="@color/white_pressed" />
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/show_deck_from_dev_mode_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/white"
fab:fab_title="Show deck"
fab:fab_colorPressed="@color/white_pressed"/>
<com.getbase.floatingactionbutton.FloatingActionButton <com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/set_user_mode_button" android:id="@+id/set_user_mode_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/card_preview_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:minHeight="100dp"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="5dp"
card_view:cardCornerRadius="5dp"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/card_preview_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="TextView"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="3dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v7.widget.LinearLayoutCompat>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.codigoparallevar.minicards.DeckPreviewActivity"
tools:showIn="@layout/activity_deck_preview">
<ListView
android:id="@+id/card_deck_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:paddingTop="5dp"
android:dividerHeight="2dp" />
</android.support.constraint.ConstraintLayout>

View File

@ -1,3 +1,4 @@
<resources> <resources>
<string name="app_name">mini-cards</string> <string name="app_name">mini-cards</string>
<string name="title_activity_deck_preview">DeckPreviewActivity</string>
</resources> </resources>

View File

@ -13,4 +13,13 @@
<item name="android:background">@drawable/fab_label_background</item> <item name="android:background">@drawable/fab_label_background</item>
<item name="android:textColor">@color/white</item> <item name="android:textColor">@color/white</item>
</style> </style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources> </resources>