@Override public void onBackPressed() { if (isPanelOpen) { toolbarPanelLayout.closePanel(); ; return; } else { finish(); } super.onBackPressed(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); getSupportActionBar().hide(); setContentView(R.layout.activity_breeds_list); toolbarPanelLayout = (ToolbarPanelLayout) findViewById(R.id.sliding_down_toolbar_layout); final ImageButton menu_button = (ImageButton) findViewById(R.id.imageButton); final ImageButton home_button = (ImageButton) findViewById(R.id.homeButton); ImageButton searchButton = (ImageButton) findViewById(R.id.searchButton); final Toolbar toolbarView = (Toolbar) findViewById(R.id.toolbar); findViewById(R.id.panel) .setY( (float) getResources() .getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material)); Category_name = getIntent().getExtras().getString("Category"); final List<String> categories = getIntent().getStringArrayListExtra("Category_list"); ListView Cat_list = (ListView) findViewById(R.id.cat_list); set_category_list(categories, Cat_list); Typeface font = Typeface.createFromAsset(getAssets(), "raleway.ttf"); cat_tag = (TextView) findViewById(R.id.cat_tag); cat_tag.setText(Category_name); cat_tag.setTypeface(font); breeds_list = (ParallaxListView) findViewById(R.id.breed_list); breeds = getBreedsFromDb(Category_name); breeds_adapter = new breed_list_view_adapter(this); breeds_adapter.addAll(breeds); breeds_list.setAdapter(breeds_adapter); assert searchButton != null; searchButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent toSearch = new Intent(Breeds_list.this, search.class); startActivity(toSearch); overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left); } }); breeds_list.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(Breeds_list.this, CardsActivity.class); intent.putExtra("Category", Category_name); intent.putExtra("Breed", breeds_adapter.getItem(position)); ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation( // the context of the activity Breeds_list.this, new Pair<View, String>( view.findViewById(R.id.img), getString(R.string.transition_name_image))); ActivityCompat.startActivity(Breeds_list.this, intent, options.toBundle()); } }); assert home_button != null; home_button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Breeds_list.this, Home_Activity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); } }); assert Cat_list != null; Cat_list.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (cat_adapter.getItem(position).equals("Diet")) { Intent i = new Intent(Breeds_list.this, CardsActivity.class); i.putExtra("Category", cat_adapter.getItem(position)); i.putExtra("Breed", cat_adapter.getItem(position)); startActivity(i); } else { breeds.clear(); breeds_adapter.clear(); breeds = getBreedsFromDb(cat_adapter.getItem(position)); breeds_adapter.addAll(breeds); Category_name = cat_adapter.getItem(position); breeds_list.setAdapter(breeds_adapter); toolbarPanelLayout.closePanel(); } } }); assert toolbarView != null; toolbarView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (isPanelOpen) toolbarPanelLayout.closePanel(); if (!isPanelOpen) toolbarPanelLayout.openPanel(); } }); assert menu_button != null; menu_button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (isPanelOpen) toolbarPanelLayout.closePanel(); if (!isPanelOpen) toolbarPanelLayout.openPanel(); } }); assert toolbarPanelLayout != null; toolbarPanelLayout.setToolbarPanelListener( new ToolbarPanelListener() { @Override public void onPanelOpened(Toolbar toolbar, View panelView) { cat_tag.setText("Categories"); isPanelOpen = true; } @Override public void onPanelSlide(Toolbar toolbar, View panelView, float slideOffset) { toolbar.setY((float) 0.0); findViewById(R.id.cat_list).setAlpha(slideOffset); if (slideOffset < 0.5) { cat_tag.setText(Category_name); cat_tag.setAlpha(1 - slideOffset); } if (slideOffset >= 0.5) { cat_tag.setText("Categories"); cat_tag.setAlpha(slideOffset); } if (slideOffset > 0.3 && !isPanelOpen) { menu_button_state = false; menu_button.setBackgroundResource(R.drawable.menu_to_arrow); ((AnimationDrawable) menu_button.getBackground()).start(); } if (slideOffset < 0.7 && isPanelOpen) { menu_button_state = true; menu_button.setBackgroundResource(R.drawable.arrow_to_menu); ((AnimationDrawable) menu_button.getBackground()).start(); } if (slideOffset == 0.0) onPanelClosed(toolbar, panelView); if (slideOffset == 1.0) onPanelOpened(toolbar, panelView); } @Override public void onPanelClosed(Toolbar toolbar, View panelView) { if (!menu_button_state) { menu_button.setBackgroundResource(R.drawable.arrow_to_menu); ((AnimationDrawable) menu_button.getBackground()).start(); menu_button_state = true; } panelView.setY((float) -(panelView.getHeight() - toolbarView.getHeight())); cat_tag.setText(Category_name); cat_tag.setAlpha((float) 1.0); isPanelOpen = false; } }); }