Commit 8f50c75e authored by Paded's avatar Paded

read bus data from firebase

parent 0f417f4d
......@@ -14,7 +14,9 @@
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize" />
<activity android:name=".CreateAccountActivity" />
<activity android:name=".CreateAccountActivity"
android:windowSoftInputMode="adjustResize"
/>
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
......
......@@ -5,14 +5,19 @@ import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
......@@ -23,21 +28,30 @@ import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.h6ah4i.android.materialshadowninepatch.MaterialShadowContainerView;
public class CreateAccountActivity extends AppCompatActivity {
import java.util.ArrayList;
public class CreateAccountActivity extends AppCompatActivity implements ItemAdapter.ItemListener{
private EditText inputEmail, inputPassword, inputName;
private Button btnCreateAccount, btnLogin, btnResetPassword, btnAddBus;
private ProgressBar progressBar;
private FirebaseAuth auth;
private ScrollView mainLayout;
private String TAG = "TEST22";
private FrameLayout layout_MainMenu;
BottomSheetDialog bottomSheetDialog;
BottomSheetBehavior bottomSheetBehavior;
RecyclerView recyclerView;
private ItemAdapter mAdapter;
CoordinatorLayout coordinatorLayout;
BottomSheetBehavior behavior;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -46,7 +60,7 @@ public class CreateAccountActivity extends AppCompatActivity {
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
mainLayout = (ScrollView) findViewById(R.id.mainlayout);
// mainLayout = (ScrollView) findViewById(R.id.mainlayout);
inputEmail = (EditText)findViewById(R.id.input_email);
inputPassword = (EditText)findViewById(R.id.input_password);
......@@ -59,31 +73,34 @@ public class CreateAccountActivity extends AppCompatActivity {
btnLogin = (Button)findViewById(R.id.btnLogin);
btnAddBus = (Button)findViewById(R.id.btn_addBus);
View bottomSheetView = getLayoutInflater().inflate(R.layout.bottom_sheet_layout, null);
bottomSheetDialog = new BottomSheetDialog(CreateAccountActivity.this);
bottomSheetDialog.setContentView(bottomSheetView);
layout_MainMenu = (FrameLayout) findViewById( R.id.framelayout);
layout_MainMenu.getForeground().setAlpha( 0);
bottomSheetBehavior = BottomSheetBehavior.from((View) bottomSheetView.getParent());
// View bottomSheetView = getLayoutInflater().inflate(R.layout.bottom_sheet_layout, null);
// bottomSheetDialog = new BottomSheetDialog(CreateAccountActivity.this);
// bottomSheetDialog.setContentView(bottomSheetView);
//
// bottomSheetBehavior = BottomSheetBehavior.from((View) bottomSheetView.getParent());
//
// bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
// TextView addMenu = (TextView) bottomSheetView.findViewById(R.id.menu_add_bus0);
// TextView editMenu = (TextView) bottomSheetView.findViewById(R.id.menu_add_bus1);
// TextView deleteMenu = (TextView) bottomSheetView.findViewById(R.id.menu_add_bus2);
TextView addMenu = (TextView) bottomSheetView.findViewById(R.id.menu_add_bus0);
TextView editMenu = (TextView) bottomSheetView.findViewById(R.id.menu_add_bus1);
TextView deleteMenu = (TextView) bottomSheetView.findViewById(R.id.menu_add_bus2);
addMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bottomSheetDialog.hide();
}
});
// addMenu.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// bottomSheetDialog.hide();
// }
// });
btnCreateAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mainLayout.getWindowToken(), 0);
imm.hideSoftInputFromWindow(coordinatorLayout.getWindowToken(), 0);
String email = inputEmail.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
......@@ -152,10 +169,76 @@ public class CreateAccountActivity extends AppCompatActivity {
}
});
coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
View bottomSheet = findViewById(R.id.bottom_sheet);
behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
Log.d(TAG, "onStateChanged: "+newState);
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
if(slideOffset == 0.0){
layout_MainMenu.getForeground().setAlpha(0);
}
Log.d(TAG, "slideOffset: "+slideOffset);
// React to dragging events
}
});
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// Get a reference to our posts
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("server/saving-data/fireblog/posts");
// Attach a listener to read the data at our posts reference
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Post post = dataSnapshot.getValue(Post.class);
System.out.println(post);
}
@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
ArrayList<String> items = new ArrayList<>();
items.add("Item 16");
items.add("Item 2");
items.add("Item 3");
items.add("Item 4");
items.add("Item 5");
items.add("Item 6");
mAdapter = new ItemAdapter(items, this);
recyclerView.setAdapter(mAdapter);
btnAddBus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bottomSheetDialog.show();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(coordinatorLayout.getWindowToken(), 0);
layout_MainMenu.getForeground().setAlpha(100);
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
......@@ -174,4 +257,27 @@ public class CreateAccountActivity extends AppCompatActivity {
super.onResume();
progressBar.setVisibility(View.GONE);
}
@Override
public void onBackPressed() {
if (behavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
layout_MainMenu.getForeground().setAlpha(0);
Log.d(TAG, "onBackPressed:1 "+behavior.getState());
}else{
super.onBackPressed();
}
}
// for button sheet click
@Override
public void onItemClick(String item) {
Snackbar.make(coordinatorLayout,item + " is selected", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
package ubontransitdriver.paded.com.ubontransitdriver;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ViewHolder> {
private List<String> mItems;
private ItemListener mListener;
ItemAdapter(List<String> items, ItemListener listener) {
mItems = items;
mListener = listener;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.bottom_sheet_layout, parent, false));
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.setData(mItems.get(position));
}
@Override
public int getItemCount() {
return mItems.size();
}
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textView;
String item;
ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
textView = (TextView) itemView.findViewById(R.id.bus_text);
}
void setData(String item) {
this.item = item;
textView.setText(item);
}
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.onItemClick(item);
}
}
}
interface ItemListener {
void onItemClick(String item);
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/bg_add_bus_menu_clicked" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/bg_add_bus_menu_clicked" />
<item android:drawable="@drawable/bg_add_bus_menu_normal" />
</selector>
\ No newline at end of file
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="@color/gray_100" >
</solid>
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" >
</padding>
<!--<corners-->
<!--android:radius="8dp" >-->
<!--</corners>-->
</shape>
\ No newline at end of file
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="@color/white" >
</solid>
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" >
</padding>
<!--<corners-->
<!--android:radius="8dp" >-->
<!--</corners>-->
</shape>
\ No newline at end of file
......@@ -6,8 +6,6 @@
android:color="@color/gray" >
</solid>
<padding
android:left="5dp"
android:top="5dp"
......
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#000000" />
</shape>
\ No newline at end of file
......@@ -7,37 +7,20 @@
android:orientation="vertical"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<TextView
android:id="@+id/menu_add_bus0"
android:id="@+id/bus_text"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center"
android:drawablePadding="@dimen/activity_horizontal_margin"
android:textColor="@color/half_black"
android:background="@drawable/bg_add_bus_menu"
android:drawableStart="@drawable/ic_frontal_bus_silhouette"
android:gravity="center_vertical"
android:padding="@dimen/activity_horizontal_margin"
android:text="@string/Bus_no0" />
<TextView
android:id="@+id/menu_add_bus1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center"
android:drawablePadding="@dimen/activity_horizontal_margin"
android:drawableStart="@drawable/ic_frontal_bus_silhouette"
android:gravity="center_vertical"
android:padding="@dimen/activity_horizontal_margin"
android:text="@string/Bus_no1" />
<TextView
android:id="@+id/menu_add_bus2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center"
android:drawablePadding="@dimen/activity_horizontal_margin"
android:drawableStart="@drawable/ic_frontal_bus_silhouette"
android:gravity="center_vertical"
android:padding="@dimen/activity_horizontal_margin"
android:text="@string/Bus_no2" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainlayout"
android:fitsSystemWindows="true"
tools:context=".CreateAccountActivity">
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/framelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:foreground="@drawable/shape_window_dim" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
......@@ -18,72 +30,68 @@
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/create_account_label"
android:layout_above="@+id/input_name"
android:textSize="40dp"
android:textStyle="bold"
android:textColor="@color/blue"
android:layout_marginBottom="15dp"
/>
<EditText
android:id="@+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_edittext"
android:drawableLeft="@drawable/ic_man_user"
android:drawablePadding="10dp"
android:ems="10"
android:hint="Your Name"
android:padding="15dp" />
<EditText
android:id="@+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_name"
android:drawableLeft="@drawable/ic_email"
android:drawablePadding="10dp"
android:padding="15dp"
android:layout_marginTop="10dp"
android:hint="Your Email"
android:background="@drawable/bg_edittext"
android:ems="10"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_email"
android:drawableLeft="@drawable/ic_pass_key"
android:drawablePadding="10dp"
android:padding="15dp"
android:layout_marginTop="10dp"
android:hint="Your Password"
android:background="@drawable/bg_edittext"
android:ems="10"
android:inputType="textPassword" />
android:text="@string/create_account_label"
android:textColor="@color/blue"
android:textSize="40dp"
android:textStyle="bold" />
<EditText
android:id="@+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_edittext"
android:drawableLeft="@drawable/ic_man_user"
android:drawablePadding="10dp"
android:ems="10"
android:hint="Your Name"
android:padding="15dp" />
<EditText
android:id="@+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_name"
android:layout_marginTop="10dp"
android:background="@drawable/bg_edittext"
android:drawableLeft="@drawable/ic_email"
android:drawablePadding="10dp"
android:ems="10"
android:hint="Your Email"
android:inputType="textEmailAddress"
android:padding="15dp" />
<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_email"
android:layout_marginTop="10dp"
android:background="@drawable/bg_edittext"
android:drawableLeft="@drawable/ic_pass_key"
android:drawablePadding="10dp"
android:ems="10"
android:hint="Your Password"
android:inputType="textPassword"
android:padding="15dp" />
<Button
android:id="@+id/btn_addBus"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_password"
android:layout_marginTop="10dp"
android:background="@drawable/bg_add_bus"
android:drawableLeft="@drawable/ic_plus"
android:drawablePadding="10dp"
android:background="@drawable/bg_add_bus"
android:padding="15dp"
android:gravity="left|center_vertical"
style="?android:attr/borderlessButtonStyle"
android:padding="15dp"
android:text="@string/add_bus_label"
android:textColor="@color/blue" />
<Button
android:id="@+id/btn_create_account"
android:layout_width="match_parent"
......@@ -98,8 +106,8 @@
<Button
android:id="@+id/btn_reset_password"
android:layout_width="fill_parent"
android:layout_below="@+id/btn_create_account"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_create_account"
android:layout_marginTop="20dip"
android:background="@null"
android:text="@string/btn_forgot_password"
......@@ -130,6 +138,67 @@
</LinearLayout>
</ScrollView>
</FrameLayout>
<LinearLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:fitsSystemWindows="true"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
android:orientation="vertical"
app:layout_behavior="@string/bottom_sheet_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Choose your bus"
android:paddingLeft="16dp"
android:textSize="16dp"
android:textColor="@color/gray_500"
android:textStyle="bold" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
<!--<?xml version="1.0" encoding="utf-8"?>--><!--<ScrollView 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"--><!--android:id="@+id/mainlayout"--><!--tools:context=".CreateAccountActivity">-->
<!--<LinearLayout--><!--android:layout_width="match_parent"--><!--android:layout_height="wrap_content"--><!--android:layout_gravity="center"--><!--android:orientation="vertical"--><!--android:padding="25dp">-->
<!--<TextView--><!--android:layout_width="match_parent"--><!--android:layout_height="match_parent"--><!--android:text="@string/create_account_label"--><!--android:layout_above="@+id/input_name"--><!--android:textSize="40dp"--><!--android:textStyle="bold"--><!--android:textColor="@color/blue"--><!--android:layout_marginBottom="15dp"--><!--/>-->
<!--<EditText--><!--android:id="@+id/input_name"--><!--android:layout_width="match_parent"--><!--android:layout_height="wrap_content"--><!--android:background="@drawable/bg_edittext"--><!--android:drawableLeft="@drawable/ic_man_user"--><!--android:drawablePadding="10dp"--><!--android:ems="10"--><!--android:hint="Your Name"--><!--android:padding="15dp" />-->
<!--<EditText--><!--android:id="@+id/input_email"--><!--android:layout_width="match_parent"--><!--android:layout_height="wrap_content"--><!--android:layout_below="@+id/input_name"--><!--android:drawableLeft="@drawable/ic_email"--><!--android:drawablePadding="10dp"--><!--android:padding="15dp"--><!--android:layout_marginTop="10dp"--><!--android:hint="Your Email"--><!--android:background="@drawable/bg_edittext"--><!--android:ems="10"--><!--android:inputType="textEmailAddress" />--><!--<EditText--><!--android:id="@+id/input_password"--><!--android:layout_width="match_parent"--><!--android:layout_height="wrap_content"--><!--android:layout_below="@+id/input_email"--><!--android:drawableLeft="@drawable/ic_pass_key"--><!--android:drawablePadding="10dp"--><!--android:padding="15dp"--><!--android:layout_marginTop="10dp"--><!--android:hint="Your Password"--><!--android:background="@drawable/bg_edittext"--><!--android:ems="10"--><!--android:inputType="textPassword" />--><!--<Button--><!--android:id="@+id/btn_addBus"--><!--android:layout_width="match_parent"--><!--android:layout_height="wrap_content"--><!--android:layout_below="@+id/input_password"--><!--android:layout_marginTop="10dp"--><!--android:drawableLeft="@drawable/ic_plus"--><!--android:drawablePadding="10dp"--><!--android:background="@drawable/bg_add_bus"--><!--android:padding="15dp"--><!--android:gravity="left|center_vertical"--><!--style="?android:attr/borderlessButtonStyle"--><!--android:text="@string/add_bus_label"--><!--android:textColor="@color/blue" />-->
<!--<Button--><!--android:id="@+id/btn_create_account"--><!--android:layout_width="match_parent"--><!--android:layout_height="wrap_content"--><!--android:layout_below="@+id/shadow_item_container"--><!--android:layout_marginTop="20dp"--><!--android:background="@drawable/create_account_btn_color"--><!--android:padding="10dp"--><!--android:text="@string/create_account_btn_txt_ENG"--><!--android:textColor="#ffffffff" />-->
<!--<Button--><!--android:id="@+id/btn_reset_password"--><!--android:layout_width="fill_parent"--><!--android:layout_below="@+id/btn_create_account"--><!--android:layout_height="wrap_content"--><!--android:layout_marginTop="20dip"--><!--android:background="@null"--><!--android:text="@string/btn_forgot_password"--><!--android:textAllCaps="false"--><!--android:textColor="@drawable/button_text_color_blue" />-->
<!--&lt;!&ndash; Link to Login Screen &ndash;&gt;-->
<!--<Button--><!--android:id="@+id/btnLogin"--><!--android:layout_width="fill_parent"--><!--android:layout_height="wrap_content"--><!--android:background="@null"--><!--android:text="@string/btn_login"--><!--android:textAllCaps="false"--><!--android:textColor="@drawable/button_text_color_green"--><!--android:textSize="15dp" />-->
<!--<ProgressBar--><!--android:id="@+id/progressBar"--><!--android:layout_width="158dp"--><!--android:layout_height="30dp"--><!--android:layout_below="@+id/btn_reset_password"--><!--android:layout_gravity="center|bottom"--><!--android:layout_marginBottom="20dp"--><!--android:visibility="gone" />-->
<!--</LinearLayout>-->
</ScrollView>
\ No newline at end of file
<!--</ScrollView>-->
......@@ -10,6 +10,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="25dp">
......
......@@ -18,6 +18,8 @@
android:layout_centerInParent="true"
android:orientation="vertical"
android:gravity="center"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="25dp">
<TextView
......
......@@ -13,6 +13,7 @@
<color name="off_green">#47c75d</color>
<color name="red">#ff2d55</color>
<color name="black">#000000</color>
<color name="half_black">#303030</color>
<color name="gray">#ececec</color>
<color name="off_gray">#e1e1e1</color>
<color name="gray_100">#F5F5F5</color>
......
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