Last active
April 6, 2017 13:56
-
-
Save mikkipastel/e81b3b6fb46cb168e51114c0a6dbd9c2 to your computer and use it in GitHub Desktop.
questionare in android app by firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AfterFeedbackFragment extends Fragment { | |
public AfterFeedbackFragment() { | |
super(); | |
} | |
public static AfterFeedbackFragment newInstance() { | |
AfterFeedbackFragment fragment = new AfterFeedbackFragment(); | |
Bundle args = new Bundle(); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
View rootView = inflater.inflate(R.layout.fragment_afterfeedback, container, false); | |
initInstances(rootView); | |
return rootView; | |
} | |
public void initInstances(View rootView){ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mikkipastel.buslinebysukhum; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import com.mikkipastel.buslinebysukhum.fragment.AfterFeedbackFragment; | |
import com.mikkipastel.buslinebysukhum.fragment.FeedbackFragment; | |
/** | |
* Created by acer on 9/4/2016. | |
*/ | |
public class FeedbackActivity extends AppCompatActivity implements FeedbackFragment.FragmentListener{ | |
String userEmail; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_feedback); | |
//get user email | |
userEmail = getIntent().getStringExtra("user_email"); | |
if (savedInstanceState == null) { | |
//1st created | |
//place fragment | |
getSupportFragmentManager().beginTransaction() | |
.add(R.id.contentContainer, FeedbackFragment.newInstance(userEmail)) | |
.commit(); | |
} | |
} | |
@Override | |
public void onClick() { | |
getSupportFragmentManager().beginTransaction() | |
.remove(FeedbackFragment.newInstance(userEmail)) | |
.replace(R.id.contentContainer, AfterFeedbackFragment.newInstance()) | |
.commit(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mikkipastel.buslinebysukhum.fragment; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.RadioGroup; | |
import android.widget.Toast; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.Locale; | |
import com.google.firebase.database.DatabaseReference; | |
import com.google.firebase.database.FirebaseDatabase; | |
import com.mikkipastel.buslinebysukhum.R; | |
import com.mikkipastel.buslinebysukhum.model.Message; | |
/** | |
* Created by acer on 9/4/2016. | |
*/ | |
public class FeedbackFragment extends Fragment { | |
RadioGroup selectTopic; | |
EditText inputTopic, inputDetail, inputEmail; | |
Button submitData; | |
String feedbackType, feedbackTopic, feedbackDetail; | |
static String feedbackEmail; | |
public FeedbackFragment() { | |
super(); | |
} | |
public static FeedbackFragment newInstance(String userEmail) { | |
FeedbackFragment fragment = new FeedbackFragment(); | |
feedbackEmail = userEmail; | |
Bundle args = new Bundle(); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
View rootView = inflater.inflate(R.layout.fragment_feedback, container, false); | |
initInstances(rootView); | |
return rootView; | |
} | |
public void initInstances(View rootView){ | |
selectTopic = (RadioGroup)rootView.findViewById(R.id.rgFeedback); | |
inputTopic = (EditText)rootView.findViewById(R.id.inputTopic); | |
inputDetail = (EditText)rootView.findViewById(R.id.inputDetail); | |
inputEmail = (EditText)rootView.findViewById(R.id.inputEmail); | |
submitData = (Button)rootView.findViewById(R.id.submit); | |
submitData.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
//get type of feedback topic | |
switch (selectTopic.getCheckedRadioButtonId()){ | |
case R.id.rbProblem: //rbProblem.isChecked() | |
feedbackType = "App problem"; | |
break; | |
case R.id.rbBusline: //rbBusline.isChecked() | |
feedbackType = "Busline feedback"; | |
break; | |
case R.id.rbFeedback: //rbFeedback.isChecked() | |
feedbackType = "User feedback"; | |
break; | |
default: | |
feedbackType = "None"; | |
} | |
//get topic and detail for feedback | |
feedbackEmail = inputEmail.getText().toString(); | |
feedbackTopic = inputTopic.getText().toString(); | |
feedbackDetail = inputDetail.getText().toString(); | |
//check not null string and check length to quality feedback | |
if (feedbackTopic.isEmpty()) { | |
Toast.makeText(getContext(), | |
"ใส่ชื่อหัวข้อให้ลุงด้วยนะจ๊ะ", | |
Toast.LENGTH_SHORT) | |
.show(); | |
} else if (feedbackDetail.isEmpty()) { | |
Toast.makeText(getContext(), | |
"ขอรายละเอียดด้วยจ้า", | |
Toast.LENGTH_SHORT) | |
.show(); | |
} else if (feedbackTopic.length() < 10) { | |
Toast.makeText(getContext(), | |
"ใส่ตัวอักษรที่ห้วข้อเพิ่มนิดนึงนะหลาน", | |
Toast.LENGTH_SHORT) | |
.show(); | |
} else if (feedbackDetail.length() < 15) { | |
Toast.makeText(getContext(), | |
"ลุงอยากได้รายละเอียดเพิ่ม เดี๋ยวทีมงานเขาดุลุงนะ", | |
Toast.LENGTH_SHORT) | |
.show(); | |
} else { | |
// Write a message to the database | |
FirebaseDatabase database = FirebaseDatabase.getInstance(); | |
DatabaseReference rootDbRef = database.getReference(); //root | |
//point to sub-level in database | |
DatabaseReference feedbackDbRef = rootDbRef.child("user_feedback"); | |
String tmp_stamp = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault()).format(new Date()); | |
Message userFeedback = new Message(feedbackType, feedbackTopic, feedbackDetail, tmp_stamp, feedbackEmail); | |
//rootDbRef.setValue(userFeedback); | |
feedbackDbRef.push().setValue(userFeedback); | |
//offline : Persistence Behavior | |
//FirebaseDatabase.getInstance().setPersistenceEnabled(true); | |
//send finish, Sukhum say thank you, pop to activity | |
FragmentListener listener = (FragmentListener) getActivity(); | |
listener.onClick(); | |
} | |
} | |
}); | |
} | |
//add for pop to activity | |
public interface FragmentListener{ | |
void onClick(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@color/transparent" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
android:gravity="center_vertical"> | |
<ImageView | |
android:layout_width="200dp" | |
android:layout_height="200dp" | |
android:src="@drawable/sukhum" | |
android:contentDescription="@string/app_sukhum" | |
android:layout_gravity="center_horizontal"/> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:textAppearance="?android:attr/textAppearanceMedium" | |
android:textSize="@dimen/fontsize_header" | |
android:text="@string/sukhum_saythanks" | |
android:id="@+id/textView" | |
android:textColor="@color/white" | |
android:layout_gravity="center_horizontal" | |
android:fontFamily="font/TH Baijam.ttf" | |
android:padding="@dimen/activity_vertical_margin" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@color/transparent" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin"> | |
<TextView | |
android:id="@+id/header1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:textColor="@android:color/background_light" | |
android:textSize="@dimen/fontsize_subheader" | |
android:text="@string/feedback_header1" /> | |
<RadioGroup | |
android:id="@+id/rgFeedback" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:checkedButton="@+id/rbProblem" | |
android:orientation="vertical"> | |
<RadioButton | |
android:id="@+id/rbProblem" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:textColor="@android:color/background_light" | |
android:textSize="@dimen/fontsize_normal" | |
android:text="@string/feedback_detail1"/> | |
<RadioButton | |
android:id="@+id/rbBusline" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:textColor="@android:color/background_light" | |
android:textSize="@dimen/fontsize_normal" | |
android:text="@string/feedback_detail2"/> | |
<RadioButton | |
android:id="@+id/rbFeedback" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:textColor="@android:color/background_light" | |
android:textSize="@dimen/fontsize_normal" | |
android:text="@string/feedback_detail3"/> | |
</RadioGroup> | |
<android.support.design.widget.TextInputLayout | |
android:id="@+id/input_layout_email" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<EditText | |
android:id="@+id/inputEmail" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:inputType="textEmailAddress" | |
android:hint="@string/feedback_header4"/> | |
</android.support.design.widget.TextInputLayout> | |
<android.support.design.widget.TextInputLayout | |
android:id="@+id/input_layout_topic" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<EditText | |
android:id="@+id/inputTopic" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:inputType="text" | |
android:hint="@string/feedback_header2"/> | |
</android.support.design.widget.TextInputLayout> | |
<android.support.design.widget.TextInputLayout | |
android:id="@+id/input_layout_detail" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<EditText | |
android:id="@+id/inputDetail" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:maxLines="3" | |
android:paddingBottom="@dimen/activity_padding_all" | |
android:inputType="textMultiLine" | |
android:hint="@string/feedback_header3"/> | |
</android.support.design.widget.TextInputLayout> | |
<Button | |
android:id="@+id/submit" | |
android:layout_marginTop="@dimen/activity_padding_all" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:textSize="@dimen/fontsize_normal" | |
android:background="@color/blueA200" | |
android:text="@string/feedback_submit"/> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment