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
......@@ -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