SHARE
TWEET

Untitled

Pit_Anonim Apr 21st, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.a1.bottombar;
  2.  
  3. import android.app.ActivityOptions;
  4. import android.content.Intent;
  5. import android.os.Build;
  6. import android.os.Bundle;
  7. import android.support.annotation.NonNull;
  8. import android.support.annotation.RequiresApi;
  9. import android.support.design.widget.BottomNavigationView;
  10. import android.support.v7.app.AppCompatActivity;
  11. import android.support.v7.widget.LinearLayoutManager;
  12. import android.support.v7.widget.RecyclerView;
  13. import android.transition.Transition;
  14. import android.transition.TransitionManager;
  15. import android.util.TypedValue;
  16. import android.view.MenuItem;
  17. import android.view.View;
  18. import android.widget.LinearLayout;
  19. import android.widget.SimpleAdapter;
  20. import android.widget.TextView;
  21.  
  22. import java.util.ArrayList;
  23.  
  24. public class MainActivity extends AppCompatActivity {
  25.  
  26.     LinearLayout linearLayout;
  27.     SimpleAdapter theory;
  28.     RecyclerView recyclerView;
  29.     ItemAdapter itemAdapter;
  30.     ArrayList<CardItem> list;
  31.  
  32.     TextView currentView;
  33.     Transition a;
  34.  
  35.     String[] orig,local;
  36.  
  37.     private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
  38.             = new BottomNavigationView.OnNavigationItemSelectedListener() {
  39.  
  40.         @Override
  41.         public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  42.             linearLayout.removeAllViews();
  43.             switch (item.getItemId()) {
  44.                 case R.id.theory:
  45.                     linearLayout.addView(recyclerView);
  46.                     return true;
  47.                 case R.id.test:
  48.                     return true;
  49.             }
  50.             return false;
  51.         }
  52.     };
  53.  
  54.     @Override
  55.     protected void onCreate(Bundle savedInstanceState) {
  56.         super.onCreate(savedInstanceState);
  57.         setContentView(R.layout.activity_main);
  58.         init();
  59.     }
  60.  
  61.     private void init(){
  62.         orig = getResources().getStringArray(R.array.menu_orig);
  63.         local = getResources().getStringArray(R.array.menu_ru);
  64.  
  65.         linearLayout = findViewById(R.id.mainlayout);
  66.  
  67.         BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
  68.         navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
  69.  
  70.         recyclerView = new RecyclerView(this);
  71.         recyclerView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
  72.                 LinearLayout.LayoutParams.MATCH_PARENT));
  73.         recyclerView.setHasFixedSize(true);
  74.         recyclerView.setLayoutManager( new LinearLayoutManager(this));
  75.  
  76.         list = new ArrayList<>();
  77.  
  78.         for (int i = 0; i < orig.length; i++) {
  79.             list.add(new CardItem(local[i], orig[i]));
  80.         }
  81.  
  82.         itemAdapter = new ItemAdapter(list);
  83.         ItemAdapter.OnItemClickListener onItemClickListener = new ItemAdapter.OnItemClickListener() {
  84.             @Override
  85.             public void onItemClick(CardItem item, TextView v) {
  86.  
  87.                 Bundle bundle = null;
  88.  
  89.                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
  90.                     if (v != null) {
  91.                         a = new TextSizeTransition();
  92.                         TransitionManager.beginDelayedTransition(recyclerView, a);
  93.  
  94.                         currentView = v;
  95.                         currentView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
  96.                         ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, v, MainActivity.this.getString(R.string.title_transition));
  97.                         bundle = options.toBundle();
  98.                     }
  99.                 }
  100.  
  101.                 Intent intent = new Intent(MainActivity.this, TheoryActivity.class);
  102.                 intent.putExtra("Title", item.title);
  103.                 intent.putExtra("orig", item.text);
  104.                 if (bundle == null) {
  105.                     MainActivity.this.startActivity(intent);
  106.                 } else {
  107.                     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  108.                         MainActivity.this.startActivityForResult(intent, 1, bundle);
  109.                     }
  110.                 }
  111.             }
  112.  
  113.         };
  114.         itemAdapter = new ItemAdapter(onItemClickListener, list);
  115.         recyclerView.setAdapter(itemAdapter);
  116.  
  117.         linearLayout.addView(recyclerView);
  118.     }
  119.  
  120.     @Override
  121.     protected void onResume() {
  122.         super.onResume();
  123.         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ) {
  124.             if (currentView != null) {
  125.                 TransitionManager.beginDelayedTransition(recyclerView, a);
  126.                 currentView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
  127.             }
  128.         }
  129.     }
  130.  
  131.  
  132. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top