Ajout de la partie "Liste de cartes" disponible depuis l'accueil.
Avec : - Image - Nb Attaque et Nb PVs - Lien clickable (reste qu'à ajouter une barre de recherche)
This commit is contained in:
@@ -0,0 +1,113 @@
|
|||||||
|
package com.iutlaval.myapplication;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.text.util.Linkify;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.CardRegistery;
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.Mythes.Mythes_Perséphone;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
public class CardListActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
TextView test;
|
||||||
|
LinearLayout linearLayout;
|
||||||
|
int inf;
|
||||||
|
int sup;
|
||||||
|
ImageView cardPicture;
|
||||||
|
private TextView cardName;
|
||||||
|
private int screenHeight;
|
||||||
|
private int screenWidth;
|
||||||
|
private TextView cardStats;
|
||||||
|
private TextView cardLink;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_card_list);
|
||||||
|
test = findViewById(R.id.textViewDeck);
|
||||||
|
linearLayout = findViewById(R.id.linearLayout);
|
||||||
|
|
||||||
|
|
||||||
|
//récupération de la taille de l'écran
|
||||||
|
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
|
||||||
|
final DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||||
|
wm.getDefaultDisplay().getMetrics(displayMetrics);
|
||||||
|
screenHeight = displayMetrics.heightPixels;
|
||||||
|
screenWidth = displayMetrics.widthPixels;
|
||||||
|
|
||||||
|
SharedPreferences chosenOne = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
int deckIndex = chosenOne.getInt("deckIndex", 0);
|
||||||
|
|
||||||
|
String[] mTestArray = getResources().getStringArray(R.array.decks);
|
||||||
|
|
||||||
|
test.setText(mTestArray[deckIndex]);
|
||||||
|
|
||||||
|
switch (deckIndex) {
|
||||||
|
case 0 :
|
||||||
|
inf = 0;
|
||||||
|
sup = 30;
|
||||||
|
break;
|
||||||
|
case 1 :
|
||||||
|
inf = 30;
|
||||||
|
sup = 60;
|
||||||
|
break;
|
||||||
|
case 2 :
|
||||||
|
inf = 60;
|
||||||
|
sup = 90;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
showDeckCards(inf, sup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showDeckCards(int inf, int sup) {
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = inf; i < sup; i++) {
|
||||||
|
try {
|
||||||
|
Class c = CardRegistery.get(i);
|
||||||
|
Constructor con = c.getConstructor(String.class, Context.class);
|
||||||
|
Card card = (Card) con.newInstance(null, null);
|
||||||
|
cardPicture = new ImageView(this);
|
||||||
|
cardPicture.setBackgroundResource(card.getCardPicture());
|
||||||
|
cardPicture.setLayoutParams(new ViewGroup.LayoutParams((int) (screenWidth / 1.2), (int) (screenHeight / 1.4)));
|
||||||
|
linearLayout.addView(cardPicture);
|
||||||
|
|
||||||
|
cardName = new TextView(this);
|
||||||
|
cardName.setText(card.getName()+"\n");
|
||||||
|
linearLayout.addView(cardName);
|
||||||
|
|
||||||
|
cardStats = new TextView(this);
|
||||||
|
cardStats.setText("Attaque : "+card.getAttack()+" Vie : "+card.getHealth()+"\n");
|
||||||
|
linearLayout.addView(cardStats);
|
||||||
|
|
||||||
|
cardLink = new TextView(this);
|
||||||
|
cardLink.setText("Lien : "+card.getWikipediaLink()+"\n\n\n");
|
||||||
|
Linkify.addLinks(cardLink, Linkify.ALL);
|
||||||
|
linearLayout.addView(cardLink);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.iutlaval.myapplication;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
public class DeckPickDialogueList extends DeckPickDialogueGame {
|
||||||
|
public DeckPickDialogueList(@NonNull Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
return super.onCreateDialog(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startActivity(String[] mTestArray, int which) {
|
||||||
|
Intent cardListActivity = new Intent(context, CardListActivity.class);
|
||||||
|
cardListActivity.putExtra("DECK", mTestArray[which]);
|
||||||
|
cardListActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
|
||||||
|
SharedPreferences chosenOne = PreferenceManager.getDefaultSharedPreferences(context);;
|
||||||
|
SharedPreferences.Editor editor = chosenOne.edit();
|
||||||
|
editor.putInt("deckIndex", which);
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
|
startActivity(cardListActivity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.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">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scrollView"
|
||||||
|
android:layout_width="304dp"
|
||||||
|
android:layout_height="677dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.491"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="1.0">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/linearLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textViewDeck"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="TextView"
|
||||||
|
tools:layout_editor_absoluteX="155dp"
|
||||||
|
tools:layout_editor_absoluteY="116dp" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Reference in New Issue
Block a user