Commit 33979812 authored by jake.ejraee's avatar jake.ejraee

Completed homeScreen. Might need merging with MainActivity

parent cd69355c
...@@ -7,43 +7,50 @@ import android.support.v7.app.AppCompatActivity; ...@@ -7,43 +7,50 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.Button;
public class homeScreen extends AppCompatActivity { public class homeScreen extends AppCompatActivity {
int swipeStartX = -50; //arbitrary default value int swipeStartX;
int swipeEndX; int swipeEndX;
View sideView; View sideView;
Button settingsButton;
Button helpButton;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
sideView = this.findViewById(R.id.sideView); sideView = this.findViewById(R.id.sideView);
ViewCompat.setTranslationZ(sideView, 100f); //bring sideView in front of buttons settingsButton = this.findViewById(R.id.buttonSettings);
helpButton = this.findViewById(R.id.buttonHelp);
ViewCompat.setTranslationZ(sideView, 20f); //bring sideView in front of buttons
} }
@Override @Override
public boolean onTouchEvent(MotionEvent event){ public boolean onTouchEvent(MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN){ //finger touches screen if(event.getAction() == MotionEvent.ACTION_DOWN){ //finger touches screen
if(event.getX() <= 80){ //finger on right side of phone swipeStartX = (int)event.getX();
swipeStartX = (int)event.getX();
}
}else if(event.getAction() == MotionEvent.ACTION_UP){ //finger leaves screen }else if(event.getAction() == MotionEvent.ACTION_UP){ //finger leaves screen
if(swipeStartX != -50){ //swipe from side has occurred swipeEndX = (int)event.getX();
swipeEndX = (int)event.getX(); int difference = swipeStartX - swipeEndX;
int difference = swipeStartX - swipeEndX; if((swipeStartX <= 80) && (difference < -10)){ //swipe from left to right
swipeStartX = -50; //reset for future swipes animateSwipeOut();
if(difference < -10){ //swipe was left }else if(difference > 20){ //swipe from right to left
//successful swipe animateSwipeIn();
animateSwipe();
}
} }
} }
return super.onTouchEvent(event); return super.onTouchEvent(event);
} }
public void animateSwipe(){ public void animateSwipeOut(){ //bring sideview out
ObjectAnimator anim = ObjectAnimator.ofFloat(sideView, "translationX", 500f); ObjectAnimator anim = ObjectAnimator.ofFloat(sideView, "translationX", 570f);
anim.setDuration(500);
anim.start();
}
public void animateSwipeIn(){ //hide away sideview
ObjectAnimator anim = ObjectAnimator.ofFloat(sideView, "translationX", 0f);
anim.setDuration(500); anim.setDuration(500);
anim.start(); anim.start();
} }
...@@ -57,4 +64,9 @@ public class homeScreen extends AppCompatActivity { ...@@ -57,4 +64,9 @@ public class homeScreen extends AppCompatActivity {
Intent intent = new Intent(this, searchScreen.class); Intent intent = new Intent(this, searchScreen.class);
startActivity(intent); startActivity(intent);
} }
public void settingsViewOnClick(View view) {
Intent intent = new Intent(this, settings.class);
startActivity(intent);
}
} }
...@@ -4,21 +4,40 @@ ...@@ -4,21 +4,40 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".homeScreen">
<View <android.support.constraint.ConstraintLayout
android:id="@+id/sideView" android:id="@+id/sideView"
android:layout_width="205dp" android:layout_width="239dp"
android:layout_height="wrap_content" android:layout_height="750dp"
android:layout_marginEnd="400dp" android:layout_marginEnd="396dp"
android:layout_marginRight="400dp" android:layout_marginRight="396dp"
android:alpha="255" android:background="#FFFFFF"
android:background="#FFFFFFFF"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent">
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="@+id/buttonHelp"
android:layout_width="181dp"
android:layout_height="52dp"
android:layout_marginTop="176dp"
android:layout_marginEnd="28dp"
android:layout_marginRight="28dp"
android:text="Help and Support"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/buttonSettings"
android:layout_width="138dp"
android:layout_height="52dp"
android:layout_marginTop="84dp"
android:layout_marginEnd="48dp"
android:layout_marginRight="48dp"
android:text="Settings"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<Button <Button
android:id="@+id/suggestButton" android:id="@+id/suggestButton"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment