/* * Copyright(c) 2017 lizhaotailang * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package io.github.marktony.espresso.ui.onboarding; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.widget.AppCompatTextView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import io.github.marktony.espresso.R; public class OnboardingFragment extends Fragment { private AppCompatTextView sectionLabel; private AppCompatTextView sectionIntro; private ImageView sectionImg; private int page; // The fragment argument representing // the section number for this fragment. private static final String ARG_SECTION_NUMBER = "section_number"; public OnboardingFragment() {} /** * Returns a new instance of this fragment for the given section * number. */ public static OnboardingFragment newInstance(int sectionNumber) { OnboardingFragment fragment = new OnboardingFragment(); Bundle args = new Bundle(); args.putInt(ARG_SECTION_NUMBER, sectionNumber); fragment.setArguments(args); return fragment; } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); page = getArguments().getInt(ARG_SECTION_NUMBER); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_onboarding, container, false); initViews(view); switch (page) { case 0: sectionImg.setBackgroundResource(R.drawable.ic_beenhere_black_24dp); sectionLabel.setText(R.string.onboarding_section_1); sectionIntro.setText(R.string.onboarding_intro_1); break; case 1: sectionImg.setBackgroundResource(R.drawable.ic_camera_black_24dp); sectionLabel.setText(R.string.onboarding_section_2); sectionIntro.setText(R.string.onboarding_intro_2); break; case 2: sectionImg.setBackgroundResource(R.drawable.ic_notifications_black_24dp); sectionLabel.setText(R.string.onboarding_section_3); sectionIntro.setText(R.string.onboarding_intro_3); break; default: break; } return view; } private void initViews(View view) { sectionLabel = view.findViewById(R.id.section_label); sectionIntro = view.findViewById(R.id.section_intro); sectionImg = view.findViewById(R.id.section_img); } }