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.pageIndicator.CirclePageIndicator;
- import org.aidmaid.settings.ApplicationSettings;
- 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;
- FloatingActionButton settingsButton;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- FacebookSdk.sdkInitialize(getApplicationContext());
- setContentView(R.layout.activity_main);
- initialize();
- //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) {
- if (position == 2) {
- settingsButton.setVisibility(View.GONE);
- }
- }
- @Override
- public void onPageSelected(int position) {
- }
- @Override
- public void onPageScrollStateChanged(int state) {
- }
- });
- }
- @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() {
- // 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);
- settingsButton = (FloatingActionButton) findViewById(R.id.settingsImageButton);
- settingsButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- mViewPager.setCurrentItem(2);
- }
- });
- 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(1);
- 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 == 0)
- return DiscoverFragment.newInstance();
- if (position == 1)
- return PanicButtonFragment.newInstance();
- if (position == 2)
- return SettingsFragment.newInstance();
- //return CrimesMapFragment.newInstance();
- // if(position == 4)
- return null;
- // 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 3;
- }
- @Override
- public CharSequence getPageTitle(int position) {
- Locale l = Locale.getDefault();
- switch (position) {
- case 0:
- return getString(R.string.title_section1).toUpperCase(l);
- // return getString(R.string.title_section3).toUpperCase(l);
- case 1:
- return getString(R.string.title_section2).toUpperCase(l);
- //return getString(R.string.title_section1).toUpperCase(l);
- case 2:
- return getString(R.string.action_settings).toUpperCase(l);
- // 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