From bd20e39785406e97522a116b649a8169c4a1551b Mon Sep 17 00:00:00 2001 From: kenkeiras Date: Sun, 21 Jan 2018 12:05:54 +0100 Subject: [PATCH] Add test deck preview screen. --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 19 +++++-- .../minicards/CanvasView.java | 5 +- .../{MainActivity.java => CardActivity.java} | 36 ++++++++++--- .../minicards/CardPreviewArrayAdapter.java | 49 ++++++++++++++++++ .../minicards/DeckPreviewActivity.java | 46 ++++++++++++++++ .../minicards/PreviewCard.java | 28 ++++++++++ .../main/res/drawable-hdpi/ic_add_black.png | Bin 0 -> 114 bytes .../main/res/drawable-mdpi/ic_add_black.png | Bin 0 -> 108 bytes .../main/res/drawable-xhdpi/ic_add_black.png | Bin 0 -> 119 bytes .../main/res/drawable-xxhdpi/ic_add_black.png | Bin 0 -> 130 bytes .../res/drawable-xxxhdpi/ic_add_black.png | Bin 0 -> 133 bytes .../main/res/layout/activity_deck_preview.xml | 33 ++++++++++++ app/src/main/res/layout/activity_main.xml | 23 ++++++-- app/src/main/res/layout/card_preview.xml | 44 ++++++++++++++++ .../main/res/layout/content_deck_preview.xml | 19 +++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 9 ++++ 18 files changed, 297 insertions(+), 16 deletions(-) rename app/src/main/java/com/codigoparallevar/minicards/{MainActivity.java => CardActivity.java} (77%) create mode 100644 app/src/main/java/com/codigoparallevar/minicards/CardPreviewArrayAdapter.java create mode 100644 app/src/main/java/com/codigoparallevar/minicards/DeckPreviewActivity.java create mode 100644 app/src/main/java/com/codigoparallevar/minicards/PreviewCard.java create mode 100644 app/src/main/res/drawable-hdpi/ic_add_black.png create mode 100644 app/src/main/res/drawable-mdpi/ic_add_black.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_add_black.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_add_black.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_add_black.png create mode 100644 app/src/main/res/layout/activity_deck_preview.xml create mode 100644 app/src/main/res/layout/card_preview.xml create mode 100644 app/src/main/res/layout/content_deck_preview.xml diff --git a/app/build.gradle b/app/build.gradle index 2041774..60f8f7a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,4 +29,5 @@ dependencies { implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support:design:25.4.0' compile 'com.getbase:floatingactionbutton:1.10.1' + implementation 'com.android.support:cardview-v7:25.4.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ae36000..1b40fe2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,7 +4,9 @@ - + - + + + + + + + - + + + + diff --git a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java index e808942..03d78d8 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java +++ b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java @@ -34,7 +34,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; -import java.io.ObjectStreamException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -63,7 +62,7 @@ class CanvasView extends View implements PartGrid { private String name = "default"; private final static float touchTimeForLongTouchInMillis = 500; private boolean _isDragging = false; - private MainActivity parentActivity = null; + private CardActivity parentActivity = null; private Tuple4 _dropToRemoveZone = new Tuple4<>(0, 0, 0, 0); private boolean _devMode = false; @@ -458,7 +457,7 @@ class CanvasView extends View implements PartGrid { return _isDragging; } - public void setParentActivity(MainActivity parentActivity) { + public void setParentActivity(CardActivity parentActivity) { this.parentActivity = parentActivity; } diff --git a/app/src/main/java/com/codigoparallevar/minicards/MainActivity.java b/app/src/main/java/com/codigoparallevar/minicards/CardActivity.java similarity index 77% rename from app/src/main/java/com/codigoparallevar/minicards/MainActivity.java rename to app/src/main/java/com/codigoparallevar/minicards/CardActivity.java index 390660a..320fc68 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/MainActivity.java +++ b/app/src/main/java/com/codigoparallevar/minicards/CardActivity.java @@ -1,17 +1,17 @@ package com.codigoparallevar.minicards; -import android.app.Dialog; -import android.content.DialogInterface; +import android.content.Intent; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.ActionBar; -import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; 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; com.getbase.floatingactionbutton.AddFloatingActionButton AddPartButton; @@ -21,6 +21,8 @@ public class MainActivity extends AppCompatActivity { com.getbase.floatingactionbutton.FloatingActionsMenu devFabMenu; com.getbase.floatingactionbutton.FloatingActionsMenu userFabMenu; + com.getbase.floatingactionbutton.FloatingActionButton ShowDeckFromDevModeButton; + com.getbase.floatingactionbutton.FloatingActionButton ShowDeckFromUserModeButton; boolean devMode = false; FloatingActionButton removePartFab; @@ -78,7 +80,27 @@ public class MainActivity extends AppCompatActivity { SetDevModeButton.setOnClickListener(new View.OnClickListener() { @Override 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() { @Override 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); } - Log.e("MainActivity", "CanvasView is null"); + Log.e("CardActivity", "CanvasView is null"); return super.onTouchEvent(event); } diff --git a/app/src/main/java/com/codigoparallevar/minicards/CardPreviewArrayAdapter.java b/app/src/main/java/com/codigoparallevar/minicards/CardPreviewArrayAdapter.java new file mode 100644 index 0000000..bde2739 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/CardPreviewArrayAdapter.java @@ -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 { + 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; + } +} diff --git a/app/src/main/java/com/codigoparallevar/minicards/DeckPreviewActivity.java b/app/src/main/java/com/codigoparallevar/minicards/DeckPreviewActivity.java new file mode 100644 index 0000000..783c1f4 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/DeckPreviewActivity.java @@ -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); + + } + +} diff --git a/app/src/main/java/com/codigoparallevar/minicards/PreviewCard.java b/app/src/main/java/com/codigoparallevar/minicards/PreviewCard.java new file mode 100644 index 0000000..1e198b5 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/PreviewCard.java @@ -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; + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_add_black.png b/app/src/main/res/drawable-hdpi/ic_add_black.png new file mode 100644 index 0000000000000000000000000000000000000000..a84106b01fd4402e5d15b08c496a75b76e811999 GIT binary patch literal 114 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xf3?%cF6p=fS?83{ F1OO~S9V-9; literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_add_black.png b/app/src/main/res/drawable-mdpi/ic_add_black.png new file mode 100644 index 0000000000000000000000000000000000000000..3191d5283e981b9eecdcaa54feda419515ef656f GIT binary patch literal 108 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}a}tV^0^ykP61P7Z(aL7zi*O{Br+` z`;vw;dk$=HXVkVR^_;bx1E`8&^BsGK4=F%~hW8~_)0*>!J6N0?fLsPoS3j3^P61hf~_@91(yO*n%%kY1DGxK4;3=Nm#D=w@Ma7_^DVParA VdDB(ycCsqSC{I^Emvv4FO#nC^B`*K~ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_add_black.png b/app/src/main/res/drawable-xxxhdpi/ic_add_black.png new file mode 100644 index 0000000000000000000000000000000000000000..1e1e4d60cbc6134d79297366467d91d1ce14d863 GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0vp^2SAvS8AxUb{c{0QYymzYu0R?HmZtAK52P4Ng8YIR z9G=}s19EgdT^vIy7~fvn$jhL>aM<8q{jM`H4oj_8U!Sv5MfELEMddHv1B)0M!Xmsb ZvF=KqSHL-&YavjW!PC{xWt~$(69A{7Cn*2` literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_deck_preview.xml b/app/src/main/res/layout/activity_deck_preview.xml new file mode 100644 index 0000000..8b41796 --- /dev/null +++ b/app/src/main/res/layout/activity_deck_preview.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index aed2bfe..99f5b30 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,7 +6,7 @@ xmlns:fab="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.codigoparallevar.minicards.MainActivity"> + tools:context="com.codigoparallevar.minicards.CardActivity">