Created
October 31, 2017 21:38
-
-
Save PanHyridae/ce8b80606676bf542a41029fe7c684a3 to your computer and use it in GitHub Desktop.
Original Java code for the Main Activity of Data Jacket. The current version uses Kotlin instead.
This file contains hidden or 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.marlonjones.datajacketapp; | |
import android.content.Intent; | |
import android.support.design.widget.TabLayout; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.design.widget.Snackbar; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.Toolbar; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.FragmentManager; | |
import android.support.v4.app.FragmentPagerAdapter; | |
import android.support.v4.view.ViewPager; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.TextView; | |
import com.afollestad.materialdialogs.MaterialDialog; | |
public class MainActivity extends AppCompatActivity { | |
private SectionsPagerAdapter mSectionsPagerAdapter; | |
private ViewPager mViewPager; | |
private final String[] mTabsTitle = {"ADDED", "ALL APPS"}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main_normal); | |
Toolbar toolbar = findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); | |
mViewPager = findViewById(R.id.container); | |
mViewPager.setAdapter(mSectionsPagerAdapter); | |
TabLayout tabLayout = findViewById(R.id.tabs); | |
tabLayout.setupWithViewPager(mViewPager); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.menu_main, menu); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
int id = item.getItemId(); | |
if (id == R.id.action_settings) { | |
Intent settingsIntent = new Intent (this, SettingsActivity.class); | |
startActivity(settingsIntent); | |
} | |
if (id == R.id.action_about){ | |
new MaterialDialog.Builder(this) | |
.title(R.string.about) | |
.content(R.string.about_contents) | |
.positiveText(R.string.dismiss) | |
.show(); | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
public static class PlaceholderFragment extends Fragment { | |
private static final String ARG_SECTION_NUMBER = "section_number"; | |
public PlaceholderFragment() { | |
} | |
public static PlaceholderFragment newInstance(int sectionNumber) { | |
PlaceholderFragment fragment = new PlaceholderFragment(); | |
Bundle args = new Bundle(); | |
args.putInt(ARG_SECTION_NUMBER, sectionNumber); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
View rootView = inflater.inflate(R.layout.fragment_main, container, false); | |
TextView textView = rootView.findViewById(R.id.section_label); | |
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER))); | |
return rootView; | |
} | |
} | |
public class SectionsPagerAdapter extends FragmentPagerAdapter { | |
public SectionsPagerAdapter(FragmentManager fm) { | |
super(fm); | |
} | |
@Override | |
public Fragment getItem(int position) { | |
switch(position) { | |
case 0: | |
return new ItemFragmentSaved(); | |
case 1: | |
return new AllAppsFragment(); | |
} | |
return null; | |
} | |
@Override | |
public int getCount() { | |
return 2; | |
} | |
@Override | |
public CharSequence getPageTitle(int position) { | |
switch (position) { | |
case 0: | |
return "ADDED"; | |
case 1: | |
return "ALL APPS"; //If name matches in Added, then grey out that app or remove from list | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment