Search in sources :

Example 1 with TimelinePagerAdapter

use of com.klinker.android.twitter.adapters.TimelinePagerAdapter in project Talon-for-Twitter by klinker24.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    UpdateUtils.checkUpdate(this);
    MainActivity.sendHandler = new Handler();
    context = this;
    sContext = this;
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    DrawerActivity.settings = AppSettings.getInstance(context);
    try {
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    } catch (Exception e) {
    }
    sharedPrefs.edit().putBoolean("refresh_me", getIntent().getBooleanExtra("from_notification", false)).commit();
    setUpTheme();
    setUpWindow();
    setContentView(R.layout.main_activity);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    setUpDrawer(0, getResources().getString(R.string.timeline));
    MainActivity.sendLayout = (LinearLayout) findViewById(R.id.send_layout);
    MainActivity.sendHandler.postDelayed(showSend, 1000);
    MainActivity.sendButton = (ImageButton) findViewById(R.id.send_button);
    MainActivity.sendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent compose = new Intent(context, ComposeActivity.class);
            startActivity(compose);
        }
    });
    actionBar = getActionBar();
    if (!settings.isTwitterLoggedIn) {
        Intent login = new Intent(context, LoginActivity.class);
        startActivity(login);
    }
    mSectionsPagerAdapter = new TimelinePagerAdapter(getFragmentManager(), context, sharedPrefs, getIntent().getBooleanExtra("from_launcher", false));
    int currAccount = sharedPrefs.getInt("current_account", 1);
    int defaultPage = sharedPrefs.getInt("default_timeline_page_" + currAccount, 0);
    actionBar.setTitle(mSectionsPagerAdapter.getPageTitle(defaultPage));
    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        public void onPageScrollStateChanged(int state) {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (!actionBar.isShowing()) {
                actionBar.show();
                if (translucent) {
                    statusBar.setVisibility(View.VISIBLE);
                }
            }
            MainActivity.sendHandler.post(showSend);
        }

        public void onPageSelected(int position) {
            String title = "" + mSectionsPagerAdapter.getPageTitle(position);
            MainDrawerArrayAdapter.setCurrent(context, position);
            drawerList.invalidateViews();
            actionBar.setTitle(title);
        }
    });
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOverScrollMode(View.OVER_SCROLL_NEVER);
    mViewPager.setCurrentItem(defaultPage);
    MainDrawerArrayAdapter.setCurrent(this, defaultPage);
    drawerList.invalidateViews();
    if (getIntent().getBooleanExtra("from_launcher", false)) {
        actionBar.setTitle(mSectionsPagerAdapter.getPageTitle(getIntent().getIntExtra("launcher_page", 0)));
    }
    mViewPager.setOffscreenPageLimit(TimelinePagerAdapter.MAX_EXTRA_PAGES);
    if (getIntent().getBooleanExtra("tutorial", false) && !sharedPrefs.getBoolean("done_tutorial", false)) {
        getIntent().putExtra("tutorial", false);
        sharedPrefs.edit().putBoolean("done_tutorial", true).commit();
        registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "close drawer");
                    mDrawerLayout.closeDrawer(Gravity.LEFT);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_CLOSE_DRAWER));
        registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "open drawer");
                    mDrawerLayout.openDrawer(Gravity.LEFT);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_OPEN_DRAWER));
        registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "page left");
                    mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, true);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_PAGE_LEFT));
        registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "page right");
                    mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, true);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_PAGE_RIGHT));
        startActivity(new Intent(context, TutorialActivity.class));
        overridePendingTransition(0, 0);
    }
    setLauncherPage();
    if (getIntent().getBooleanExtra("from_drawer", false)) {
        mViewPager.setCurrentItem(getIntent().getIntExtra("page_to_open", 1));
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) ComposeActivity(com.klinker.android.twitter.activities.compose.ComposeActivity) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) TimelinePagerAdapter(com.klinker.android.twitter.adapters.TimelinePagerAdapter) BroadcastReceiver(android.content.BroadcastReceiver) View(android.view.View) ViewPager(android.support.v4.view.ViewPager) TutorialActivity(com.klinker.android.twitter.activities.setup.TutorialActivity)

Aggregations

PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Handler (android.os.Handler)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ComposeActivity (com.klinker.android.twitter.activities.compose.ComposeActivity)1 TutorialActivity (com.klinker.android.twitter.activities.setup.TutorialActivity)1 TimelinePagerAdapter (com.klinker.android.twitter.adapters.TimelinePagerAdapter)1