Skip to content

Commit

Permalink
feat(): WIP Metro metro
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrucesdeveloper committed Aug 16, 2022
1 parent 489c025 commit dcc93d2
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 71 deletions.
12 changes: 6 additions & 6 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import androidx.constraintlayout.widget.ConstraintLayout;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -42,6 +45,7 @@ public class PlayGameActivity extends AppCompatActivity {
private String lastStationName;
private Station correctAlternative;
private ArrayList<Station> alternatives;
private ArrayList<StationView> stationViews;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -51,57 +55,43 @@ protected void onCreate(Bundle savedInstanceState) {
this.initializeLevelData();
this.initializeLevelViews();
this.setCurrentStationQuestion(this.position);
this.testMethod();
this.drawStationView(150);
}

private void testMethod() {
RelativeLayout linearLayout = findViewById(R.id.gameLayout);
TextView textView = new TextView(this);
textView.setText("HOLa");
textView.setId(View.generateViewId());
linearLayout.addView(textView);

private void drawStationView(float marginStart) {
RelativeLayout gameLayout = findViewById(R.id.gameLayout);
// Layout Params
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

Resources r = this.getResources();
int px = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
285,
r.getDisplayMetrics()
);

layoutParams.setMarginStart(px);
// Margin Start
layoutParams.setMarginStart(this.transformDpToPixel(marginStart));

// Add Station View to GameLayout
StationView stationView = new StationView(this);
stationView.setLayoutParams(layoutParams);
linearLayout.addView(stationView);


StationView stationView2 = new StationView(this);
stationView2.setId(View.generateViewId());
stationViews.add(stationView);
gameLayout.addView(stationView);
}

RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
/**
* Transform Dp value to pixel
* @param valueDp dp value that is going to be transformed to pixel
* @return Pixel value
*/
private int transformDpToPixel(float valueDp) {
Resources r = this.getResources();
return (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
valueDp,
r.getDisplayMetrics()
);
layoutParams2.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

stationView2.setLayoutParams(layoutParams2);
linearLayout.addView(stationView2);

DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;

stationView.animate().translationX(-1000f).setDuration(3000);

}


/**
* Get the lineName from the Intent
*/
Expand All @@ -124,6 +114,7 @@ private void initializeLevelData() {
this.setStationList();
this.position = 0;
this.stationsSize = this.stations.size();
this.stationViews = new ArrayList<>();
}

/**
Expand Down Expand Up @@ -169,8 +160,30 @@ private void setCurrentStationQuestion(int position) {
// Alternatives
this.setCurrentAlternativesData(position);
this.setCurrentAlternativesViews();

// StationView
this.setStationView(position);
}

private void scrollView() {
HorizontalScrollView scrollView = (HorizontalScrollView) findViewById(R.id.mainScrollView);
int max = 2000;
scrollView.smoothScrollBy(scrollView.getBottom(),200);
}

private void setStationView(int position) {
if (position == 0) {return;}
float margin = this.calculateMargin(position);
this.drawStationView(margin);
this.scrollView();
}

private float calculateMargin(int position) {
float margin = 120;
float sizeStation = 300;
float offset = 10 * position;
return margin + (sizeStation * position) - offset;
}
private void setCurrentNumberStationView(int position) {
TextView textViewCurrentNumberQuestion = findViewById(R.id.textViewCurrentNumberQuestion);
textViewCurrentNumberQuestion.setText(String.valueOf(position));
Expand Down Expand Up @@ -244,6 +257,13 @@ private void checkAlternative(String alternativeString) {
}
}

private float calculatePosition() {
float margin = transformDpToPixel(150);
float currentStations = this.stationViews.size() + 1;
float offset = 10;
return margin + currentStations - offset;
}

private void onCorrectAlternative() {
this.position = this.position + 1;
if (this.position < (this.stations.size() - 1)) {
Expand Down
60 changes: 31 additions & 29 deletions app/src/main/res/layout/activity_play_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,57 +35,73 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<TextView
android:id="@+id/textViewAlternative4"
android:id="@+id/textViewAlternative2"
android:layout_width="150dp"
android:layout_height="93dp"
android:layout_marginStart="52dp"
android:layout_marginBottom="124dp"
android:background="@android:drawable/editbox_dropdown_light_frame"
android:gravity="center_horizontal|center_vertical"
android:text="SAN PEDRO"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/textViewAlternative1"
android:layout_width="150dp"
android:layout_height="93dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="48dp"
android:layout_marginBottom="24dp"
android:layout_marginBottom="124dp"
android:background="@android:drawable/editbox_dropdown_light_frame"
android:gravity="center_horizontal|center_vertical"
android:text="SAN PEDRO"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.4"
app:layout_constraintStart_toEndOf="@+id/textViewAlternative3" />

<TextView
android:id="@+id/textViewAlternative3"
android:id="@+id/textViewAlternative4"
android:layout_width="150dp"
android:layout_height="93dp"
android:layout_marginStart="52dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="48dp"
android:layout_marginBottom="24dp"
android:background="@android:drawable/editbox_dropdown_light_frame"
android:gravity="center_horizontal|center_vertical"
android:text="SAN PEDRO"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textViewAlternative3" />

<TextView
android:id="@+id/textViewAlternative1"
android:id="@+id/textViewAlternative3"
android:layout_width="150dp"
android:layout_height="93dp"
android:layout_marginStart="52dp"
android:layout_marginBottom="8dp"
android:layout_marginBottom="24dp"
android:background="@android:drawable/editbox_dropdown_light_frame"
android:gravity="center_horizontal|center_vertical"
android:text="SAN PEDRO"
app:layout_constraintBottom_toTopOf="@+id/textViewAlternative3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />


<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="180dp"
android:layout_marginEnd="181dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="180dp"
android:layout_marginBottom="24dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/textViewAlternative1"
app:layout_constraintBottom_toTopOf="@+id/textViewAlternative2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mainScrollView">

<TextView
android:id="@+id/textViewCurrentNumberQuestion"
Expand All @@ -109,22 +125,8 @@
android:textSize="24sp" />
</LinearLayout>

<TextView
android:id="@+id/textViewAlternative2"
android:layout_width="150dp"
android:layout_height="93dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="48dp"
android:layout_marginBottom="8dp"
android:background="@android:drawable/editbox_dropdown_light_frame"
android:gravity="center_horizontal|center_vertical"
android:text="SAN PEDRO"
app:layout_constraintBottom_toTopOf="@+id/textViewAlternative4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/textViewAlternative1" />

<HorizontalScrollView
android:id="@+id/mainScrollView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
Expand All @@ -136,7 +138,7 @@
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
android:orientation="vertical">

<RelativeLayout
android:id="@+id/gameLayout"
Expand Down

0 comments on commit dcc93d2

Please sign in to comment.