Esempio n. 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_info);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

    // Back button
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
      actionBar.setDisplayHomeAsUpEnabled(true);
    }

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

    // Set title if object exists.
    MalwareObject malwareObject = getIntent().getExtras().getParcelable("malware");
    if (malwareObject != null) {
      getSupportActionBar().setTitle(malwareObject.getName());
    }
  }
Esempio n. 2
0
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   View rootView;
   MalwareObject malwareObject = getActivity().getIntent().getExtras().getParcelable("malware");
   List<String> urlList = new ArrayList<>();
   switch (getArguments().getInt(ARG_SECTION_NUMBER)) {
       // Info tab
     case 1:
       // Elements
       rootView = inflater.inflate(R.layout.fragment_item, container, false);
       TextView type = (TextView) rootView.findViewById(R.id.textType);
       TextView platform = (TextView) rootView.findViewById(R.id.textPlatform);
       TextView sourceLanguage = (TextView) rootView.findViewById(R.id.textSourceLanguage);
       TextView fileType = (TextView) rootView.findViewById(R.id.textFileType);
       TextView size = (TextView) rootView.findViewById(R.id.textSize);
       TextView author = (TextView) rootView.findViewById(R.id.textAuthor);
       TextView origin = (TextView) rootView.findViewById(R.id.textOrigin);
       TextView dateDiscovery = (TextView) rootView.findViewById(R.id.textDateDiscovery);
       TextView aliases = (TextView) rootView.findViewById(R.id.textAliases);
       TextView description = (TextView) rootView.findViewById(R.id.textDescription);
       // Setting up values
       if (malwareObject != null) {
         type.setText(malwareObject.getType());
         platform.setText(malwareObject.getPlatform());
         sourceLanguage.setText(malwareObject.getSourceLanguage());
         fileType.setText(malwareObject.getFileType());
         // If size is lower or equal to 0, treat it as unknown.
         if (malwareObject.getSize() > 0) {
           size.setText(String.format("%d", malwareObject.getSize()));
         } else {
           size.setText(R.string.unknown);
         }
         author.setText(malwareObject.getAuthor());
         origin.setText(malwareObject.getOrigin());
         dateDiscovery.setText(malwareObject.getDateDiscovery());
         // Get aliases in predefined format.
         aliases.setText(malwareObject.getAliasesToString());
         description.setText(malwareObject.getDescription());
         // Receive only links on list. Media is not added.
         urlList = malwareObject.getLinksListByType("link");
       }
       RecyclerView recyclerViewLinks =
           (RecyclerView) rootView.findViewById(R.id.recyclerViewLinks);
       recyclerViewLinks.setHasFixedSize(true);
       // Disable scrolling with alternate LinearLayoutManager class.
       recyclerViewLinks.setLayoutManager(
           new NoScrollLinearLayoutManager(rootView.getContext()));
       recyclerViewLinks.setAdapter(new RecyclerViewInfoLinksAdapter(urlList));
       break;
       // Media tab
     case 2:
       rootView = inflater.inflate(R.layout.fragment_gallery, container, false);
       if (malwareObject != null) {
         // Receive only media on list. Links are not added here.
         urlList = malwareObject.getLinksListByType("media");
       }
       RecyclerView recyclerViewImage =
           (RecyclerView) rootView.findViewById(R.id.recyclerViewGallery);
       recyclerViewImage.setHasFixedSize(true);
       recyclerViewImage.setLayoutManager(new LinearLayoutManager(rootView.getContext()));
       recyclerViewImage.setAdapter(new RecyclerViewGalleryAdapter(urlList));
       break;
       // Whatever it gets broken tab
     default:
       rootView = inflater.inflate(R.layout.fragment_info, container, false);
       TextView textView = (TextView) rootView.findViewById(R.id.section_label);
       textView.setText(
           getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
       break;
   }
   return rootView;
 }