@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // NavigationDrawer View[] btns = {findViewById(R.id.review), findViewById(R.id.mail)}; for (View view : btns) { view.setOnClickListener(this); } // ツールバーをアクションバーとしてセット Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar); toolbar.setTitle("俺的フェラーリ速報"); setSupportActionBar(toolbar); toolbar.setBackgroundColor(getResources().getColor(R.color.ferrari_red)); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.app_name, R.string.app_name); mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor("#ffffff")); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); // Shimmer ShimmerTextView shimmerLine = (ShimmerTextView) findViewById(R.id.logo_techmond); Shimmer shimmer = new Shimmer(); shimmer.setDuration(2500).setStartDelay(1000); shimmer.start(shimmerLine); setScreenName(getString(R.string.activity_main)); sendScreenAnalytics(); // goodAD mAdManager = new AdManager(); mAdManager.init(this); RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.icon_ad_layout); mAdManager.setUpIconAd(this, rootLayout); // 背景画像 ImageView bg = (ImageView) findViewById(R.id.bg_main); AnimationUtil anim = new AnimationUtil(); anim.animateAlpha(bg, 1500); // 通知 NotificationUtil notify = new NotificationUtil(this); notify.setNotification(21, 30); // レビュー if (PreferenceManager.getDefaultSharedPreferences(this).getInt("launch", 0) != 0) { Random rnd = new Random(); int ran = rnd.nextInt(3); if (ran == 1) { UserSupportUtil util = new UserSupportUtil(this); util.popReviewDialog(); } } PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("launch", 1).apply(); // INDICATOR_OFFSET・・・ タブのindicatorの幅 final float density = getResources().getDisplayMetrics().density; mIndicatorOffset = (int) (INDICATOR_OFFSET * density); // Viewを取得 mTrackScroller = (HorizontalScrollView) findViewById(R.id.track_scroller); mTrack = (ViewGroup) findViewById(R.id.track); mIndicator = findViewById(R.id.indicator); // ViewPagerのセットアップ // adapterは自由に作成 mPagerAdapter = new ViewPagerAdapter(this, getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mPagerAdapter); // サイズ計測後の処理 final RelativeLayout mainView = (RelativeLayout) findViewById(R.id.mainView); mainView.post( new Runnable() { @Override public void run() { // タブをコンテナに追加 LayoutInflater inflater = LayoutInflater.from(MainActivity.this); for (int i = 0; i < mPagerAdapter.getCount(); i++) { final int position = i; TextView tv = (TextView) inflater.inflate(R.layout.tab_item, mTrack, false); tv.setText(mPagerAdapter.getPageTitle(position)); tv.getLayoutParams().width = mainView.getMeasuredWidth() / mPagerAdapter.getCount(); // タブタップ時対応したviewPagerを表示 tv.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(position); } }); mTrack.addView(tv); } mIndicator.getLayoutParams().width = mainView.getMeasuredWidth() / mPagerAdapter.getCount(); mPager.setOnPageChangeListener(new PageChangeListener()); mPager.setCurrentItem(1); } }); }
@Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); mRequestToken = (RequestToken) savedInstanceState.getSerializable(REQUEST_TOKEN); }
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putSerializable(REQUEST_TOKEN, mRequestToken); }
@Override protected void onDestroy() { ImobileSdkAd.activityDestory(); super.onDestroy(); }
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); }
@Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); mDrawerToggle.syncState(); }