Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.aidmaid;
- import android.app.ActivityManager;
- import android.content.Context;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.support.design.widget.FloatingActionButton;
- 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.support.v7.app.AppCompatActivity;
- import android.view.View;
- import com.facebook.CallbackManager;
- import com.facebook.FacebookSdk;
- import org.aidmaid.alarm.AlarmService;
- import org.aidmaid.broadcast.Red5TranslationViewActivity;
- import org.aidmaid.broadcast.RemoteVideoStreamConfig;
- import org.aidmaid.discover.DiscoverFragment;
- import org.aidmaid.main.SliderFragment;
- import org.aidmaid.pageIndicator.CirclePageIndicator;
- import org.aidmaid.settings.ApplicationSettings;
- import org.aidmaid.settings.SettingsActivity;
- import org.aidmaid.settings.SettingsFragment;
- import org.aidmaid.shaking.ShakeDetectionService;
- import org.aidmaid.wear.WearListenerService;
- import java.util.Locale;
- public class MainActivity extends AppCompatActivity {
- /**
- * The {@link android.support.v4.view.PagerAdapter} that will provide
- * fragments for each of the sections. We use a
- * {@link FragmentPagerAdapter} derivative, which will keep every
- * loaded fragment in memory. If this becomes too memory intensive, it
- * may be best to switch to a
- * {@link android.support.v4.app.FragmentStatePagerAdapter}.
- */
- SectionsPagerAdapter mSectionsPagerAdapter;
- /**
- * The {@link ViewPager} that will host the section contents.
- */
- ViewPager mViewPager;
- //MaterialTabHost tabHost;
- private int tabId;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- FacebookSdk.sdkInitialize(getApplicationContext());
- setContentView(R.layout.activity_main);
- // Create the adapter that will return a fragment for each of the three
- // primary sections of the activity.
- mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
- // Set up the ViewPager with the sections adapter.
- mViewPager = (ViewPager) findViewById(R.id.pager);
- mViewPager.setAdapter(mSectionsPagerAdapter);
- //PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
- //tabs.setViewPager(mViewPager);
- //tabs.setIndicatorColor(0xFFFFFFFF);
- //tabs.setUnderlineColor(0xFFFFA0A0);
- //tabs.setBackgroundColor(0xFFd0021b);
- //tabs.setTextColor(0xFFFFFFFF);
- //tabs.setIndicatorHeight(6);
- CirclePageIndicator circlePageIndicator = (CirclePageIndicator) findViewById(R.id.circlePageIndicator);
- circlePageIndicator.setViewPager(mViewPager);
- circlePageIndicator.setCurrentItem(0);
- circlePageIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
- @Override
- public void onPageSelected(int position) {
- }
- @Override
- public void onPageScrollStateChanged(int state) {
- }
- });
- // tabHost = (MaterialTabHost) this.findViewById(R.id.materialTabHost);
- // mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
- // @Override
- // public void onPageSelected(int position) {
- // // when user do a swipe the selected tab change
- // tabHost.setSelectedNavigationItem(position);
- // }
- // });
- //
- // for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
- // final int pos = i;
- // tabHost.addTab(
- // tabHost.newTab()
- // .setIcon(getIcon(pos))
- // .setSelectedIcon(getSelectedIcon(pos))
- // .setTabListener(new MaterialTabListener() {
- // @Override
- // public void onTabSelected(MaterialTab materialTab) {
- // mViewPager.setCurrentItem(pos);
- // }
- //
- // @Override
- // public void onTabReselected(MaterialTab materialTab) {
- //
- // }
- //
- // @Override
- // public void onTabUnselected(MaterialTab materialTab) {
- //
- // }
- // })
- // .setText(getTabText(pos))
- // );
- // }
- initialize();
- }
- // private String getTabText(int tabPosition)
- // {
- // switch (tabPosition){
- // case 0:
- // return "Alerts";
- // case 1:
- // return "Network";
- // case 2:
- // return "Panic";
- // case 3:
- // return "Discover";
- // case 4:
- // return "Settings";
- // }
- //
- // return "";
- // }
- // private Drawable getIcon(int tabId)
- // {
- // switch (tabId){
- // case 0:
- // return getResources().getDrawable(R.drawable.alerts_tab_icon);
- // case 1:
- // return getResources().getDrawable(R.drawable.network_tab_icon);
- // case 2:
- // return getResources().getDrawable(R.drawable.panic_tab_icon);
- // case 3:
- // return getResources().getDrawable(R.drawable.discover_tab_icon);
- // case 4:
- // return getResources().getDrawable(R.drawable.settings_tab_icon);
- // }
- //
- // return null;
- // }
- //
- // private Drawable getSelectedIcon(int tabId)
- // {
- // this.tabId = tabId;
- // switch (tabId){
- // case 0:
- // return getResources().getDrawable(R.drawable.alerts_red_tab_icon);
- // case 1:
- // return getResources().getDrawable(R.drawable.network_red_tab_icon);
- // case 2:
- // return getResources().getDrawable(R.drawable.panic_red_tab_icon);
- // case 3:
- // return getResources().getDrawable(R.drawable.discover_red_tab_icon);
- // case 4:
- // return getResources().getDrawable(R.drawable.settings_red_tab_icon);
- // }
- //
- // return null;
- // }
- @Override
- public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- CallbackManager callbackManager = CallbackManager.Factory.create();
- callbackManager.onActivityResult(requestCode, resultCode, data);
- if(FacebookSdk.isFacebookRequestCode(requestCode) && mViewPager.getCurrentItem() == 0)
- {
- Intent intent = new Intent(Intent.ACTION_DIAL);
- intent.setData(Uri.parse("tel:" + ApplicationSettings.getPolicePhone(getApplicationContext())));
- startActivity(intent);
- }
- }
- private void initialize()
- {
- FloatingActionButton settingsButton = (FloatingActionButton) findViewById(R.id.settingsImageButton);
- settingsButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
- startActivity(intent);
- }
- });
- Intent shakeDetectionIntent = new Intent(this, ShakeDetectionService.class);
- Intent alarmServiceIntent = new Intent(this, AlarmService.class);
- Intent wearListenerServiceIntent = new Intent(this, WearListenerService.class);
- boolean hasStartedShakeDetection = false;
- boolean hasStartedAlarmService= false;
- boolean hasStartedWearService= false;
- ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
- for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
- if (ShakeDetectionService.class.getName().equals(service.service.getClassName())) {
- hasStartedShakeDetection = true;
- }
- if (AlarmService.class.getName().equals(service.service.getClassName())) {
- hasStartedAlarmService = true;
- }
- if (WearListenerService.class.getName().equals(service.service.getClassName())) {
- hasStartedWearService = true;
- }
- }
- if(!hasStartedAlarmService)
- startService(alarmServiceIntent);
- if(!hasStartedShakeDetection)
- startService(shakeDetectionIntent);
- if(!hasStartedWearService)
- startService(wearListenerServiceIntent);
- Uri data = getIntent().getData();
- mViewPager.setCurrentItem(2);
- if(data != null && data.getScheme().equals("aidmaidlogin")){
- mViewPager.setCurrentItem(4);
- }
- if(data != null && data.getScheme().equals("aidmaid")){
- Intent startBroadcast = new Intent(this, Red5TranslationViewActivity.class);
- startBroadcast.putExtra(RemoteVideoStreamConfig.VIDEO_STREAM_PARAMETER_NAME, data.getHost());
- startActivity(startBroadcast);
- }
- }
- /**
- * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
- * one of the sections/tabs/pages.
- */
- public class SectionsPagerAdapter extends FragmentPagerAdapter {
- public SectionsPagerAdapter(FragmentManager fm) {
- super(fm);
- }
- @Override
- public Fragment getItem(int position) {
- if(position == 1)
- return DiscoverFragment.newInstance();
- if(position == 2)
- return PanicButtonFragment.newInstance();
- if(position == 3)
- return CrimesMapFragment.newInstance();
- if(position == 4)
- return SettingsFragment.newInstance();
- // getItem is called to instantiate the fragment for the given page.
- // Return a PlaceholderFragment (defined as a static inner class below).
- return SliderFragment.newInstance();
- }
- @Override
- public int getCount() {
- // Show 3 total pages.
- return 5;
- }
- @Override
- public CharSequence getPageTitle(int position) {
- Locale l = Locale.getDefault();
- switch (position) {
- case 0:
- return getString(R.string.title_section3).toUpperCase(l);
- case 1:
- return getString(R.string.title_section1).toUpperCase(l);
- case 2:
- return getString(R.string.title_section2).toUpperCase(l);
- case 3:
- return getString(R.string.title_section4).toUpperCase(l);
- case 4:
- return getString(R.string.title_section5).toUpperCase(l);
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement