| |
---|
| | import android.content.Intent; |
---|
| | import android.os.Bundle; |
---|
| | import android.support.design.widget.FloatingActionButton; |
---|
| | import android.support.design.widget.Snackbar; |
---|
| | import android.view.Gravity; |
---|
| | import android.view.View; |
---|
| | import android.support.design.widget.NavigationView; |
---|
| | import android.support.v4.view.GravityCompat; |
---|
| | import android.support.v4.widget.DrawerLayout; |
---|
| |
---|
| | import android.support.v7.widget.Toolbar; |
---|
| | import android.view.MenuItem; |
---|
| | import android.widget.ImageView; |
---|
| | import android.widget.LinearLayout; |
---|
| | import android.widget.TableLayout; |
---|
| | import android.widget.TableRow; |
---|
| | import android.widget.TextView; |
---|
| | import android.widget.Toast; |
---|
| | |
---|
| | import com.example.cosmosclient.R; |
---|
| | |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.Collections; |
---|
| | import java.util.Comparator; |
---|
| | |
---|
| | import static android.graphics.Color.BLACK; |
---|
| | |
---|
| | public class RequestListActivity extends AppCompatActivity |
---|
| | implements NavigationView.OnNavigationItemSelectedListener { |
---|
| | |
---|
| | Toast toast; //動作テスト用 |
---|
| | boolean productColorFlag = true; //買うもの色制御 |
---|
| | boolean deadlineColorFlag = true; //購入期限色制御 |
---|
| | boolean locationColorFlag = true; //場所色制御 |
---|
| | |
---|
| | ArrayList<RequestList> requestList = new ArrayList<>(); |
---|
| | |
---|
| | @Override |
---|
| | protected void onCreate(Bundle savedInstanceState) { |
---|
| | super.onCreate(savedInstanceState); |
---|
| |
---|
| | |
---|
| | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); |
---|
| | navigationView.setNavigationItemSelectedListener(this); |
---|
| | |
---|
| | LinearLayout linerlayoutView = (LinearLayout) findViewById(R.id.product); |
---|
| | linerlayoutView.setOnClickListener(new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View v) { |
---|
| | Toast.makeText(RequestListActivity.this, "product sorted", Toast.LENGTH_SHORT).show(); |
---|
| | ImageView product = (ImageView) findViewById(R.id.imageView); |
---|
| | product.setColorFilter(BLACK); |
---|
| | } |
---|
| | }); |
---|
| | requestList.add(new RequestList("わさび", "明日まで", "スーパー")); |
---|
| | requestList.add(new RequestList("ケーキ" , "12/25", "ダニエル")); |
---|
| | requestList.add(new RequestList("からし", "12/22", "コンビニ")); |
---|
| | |
---|
| | AddRequestList(requestList); |
---|
| | |
---|
| | LinearLayout productView = (LinearLayout) findViewById(R.id.product); |
---|
| | productView.setOnClickListener(productOnClick); |
---|
| | |
---|
| | LinearLayout deadlineView = (LinearLayout)findViewById(R.id.deadline); |
---|
| | deadlineView.setOnClickListener(deadlineOnClick); |
---|
| | |
---|
| | LinearLayout locationView = (LinearLayout)findViewById(R.id.location); |
---|
| | locationView.setOnClickListener(locationOnClick); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | // @Override |
---|
| |
---|
| | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); |
---|
| | drawer.closeDrawer(GravityCompat.START); |
---|
| | return true; |
---|
| | } |
---|
| | |
---|
| | private void AddRequestList(ArrayList<RequestList> requestList) { |
---|
| | TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | |
---|
| | for (int i = 0; i < requestList.size(); i++) { |
---|
| | TableRow tableRow = new TableRow(this); |
---|
| | |
---|
| | TextView textProduct = new TextView(this); |
---|
| | textProduct.setText(requestList.get(i).getProduct()); |
---|
| | textProduct.setTextSize(20); |
---|
| | textProduct.setHeight(150); |
---|
| | textProduct.setGravity(Gravity.CENTER); |
---|
| | tableRow.addView(textProduct); |
---|
| | |
---|
| | TextView textDeadline = new TextView(this); |
---|
| | textDeadline.setText(requestList.get(i).getDeadline()); |
---|
| | textDeadline.setTextSize(20); |
---|
| | textDeadline.setHeight(150); |
---|
| | textDeadline.setGravity(Gravity.CENTER); |
---|
| | tableRow.addView(textDeadline); |
---|
| | |
---|
| | TextView textLocation = new TextView(this); |
---|
| | textLocation.setText(requestList.get(i).getLocation()); |
---|
| | textLocation.setTextSize(20); |
---|
| | textLocation.setHeight(150); |
---|
| | textLocation.setGravity(Gravity.CENTER); |
---|
| | tableRow.addView(textLocation); |
---|
| | |
---|
| | requesttable.addView(tableRow); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | private void DeleateRequestList() { |
---|
| | TableLayout requesttable = (TableLayout) findViewById(R.id.RequestList); |
---|
| | |
---|
| | int childCount = requesttable.getChildCount(); |
---|
| | |
---|
| | // Remove all rows except the first one |
---|
| | if (childCount > 1) { |
---|
| | requesttable.removeViews(1, childCount - 1); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | public View.OnClickListener productOnClick = new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view) { |
---|
| | Toast.makeText(RequestListActivity.this, "product sorted", Toast.LENGTH_SHORT).show(); |
---|
| | ImageView product = (ImageView) findViewById(R.id.imageProduct); |
---|
| | if (!productColorFlag) { |
---|
| | product.setColorFilter(null); |
---|
| | productColorFlag = true; |
---|
| | DeleateRequestList(); |
---|
| | AddRequestList(requestList); |
---|
| | } else { |
---|
| | product.setColorFilter(BLACK); |
---|
| | productColorFlag = false; |
---|
| | DeleateRequestList(); |
---|
| | productSort(); |
---|
| | } |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | private void productSort() { |
---|
| | ArrayList<RequestList> requestList1 = (ArrayList<RequestList>) requestList.clone(); |
---|
| | |
---|
| | Collections.sort(requestList1, new Comparator<RequestList>() { |
---|
| | @Override |
---|
| | public int compare(RequestList r1, RequestList r2) { |
---|
| | return r1.getProduct().compareTo((r2.getProduct())); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | AddRequestList(requestList1); |
---|
| | // |
---|
| | // for (int i = 0; i < requestList1.size(); i++) { |
---|
| | // TableRow tableRow = new TableRow(this); |
---|
| | // |
---|
| | // TextView textProduct = new TextView(this); |
---|
| | // textProduct.setText(requestList1.get(i).getProduct()); |
---|
| | // textProduct.setTextSize(20); |
---|
| | // textProduct.setHeight(150); |
---|
| | // textProduct.setGravity(Gravity.CENTER); |
---|
| | // tableRow.addView(textProduct); |
---|
| | // |
---|
| | // TextView textDeadline = new TextView(this); |
---|
| | // textDeadline.setText(requestList1.get(i).getDeadline()); |
---|
| | // textDeadline.setTextSize(20); |
---|
| | // textDeadline.setHeight(150); |
---|
| | // textDeadline.setGravity(Gravity.CENTER); |
---|
| | // tableRow.addView(textDeadline); |
---|
| | // |
---|
| | // TextView textLocation = new TextView(this); |
---|
| | // textLocation.setText(requestList1.get(i).getLocation()); |
---|
| | // textLocation.setTextSize(20); |
---|
| | // textLocation.setHeight(150); |
---|
| | // textLocation.setGravity(Gravity.CENTER); |
---|
| | // tableRow.addView(textLocation); |
---|
| | // |
---|
| | // requesttable.addView(tableRow); |
---|
| | // } |
---|
| | } |
---|
| | |
---|
| | public View.OnClickListener deadlineOnClick = new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view) { |
---|
| | Toast.makeText(RequestListActivity.this, "deadline sorted", Toast.LENGTH_SHORT).show(); |
---|
| | ImageView deadline = (ImageView) findViewById(R.id.imageDeadline); |
---|
| | if (!deadlineColorFlag) { |
---|
| | deadline.setColorFilter(null); |
---|
| | deadlineColorFlag = true; |
---|
| | } else { |
---|
| | deadline.setColorFilter(BLACK); |
---|
| | deadlineColorFlag = false; |
---|
| | } |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | public View.OnClickListener locationOnClick = new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view) { |
---|
| | Toast.makeText(RequestListActivity.this, "location sorted", Toast.LENGTH_SHORT).show(); |
---|
| | ImageView location = (ImageView) findViewById(R.id.imageLocation); |
---|
| | if (!locationColorFlag) { |
---|
| | location.setColorFilter(null); |
---|
| | locationColorFlag = true; |
---|
| | } else { |
---|
| | location.setColorFilter(BLACK); |
---|
| | locationColorFlag = false; |
---|
| | } |
---|
| | } |
---|
| | }; |
---|
| | } |
---|
| | |
---|
| | |