Android boot page GudiesDemo

Reference from https://github.com/javajavadog/guideshow
The jar packages used can be found in https://github.com/javajavadog/guideshow/blob/master/jar/guideshowlib.jar download
1. Create a new project in Android studio, copy the file guideshowlib.jar (to download, see the second line) to the directory.. \ app\libs, and add the dependency compile files('libs/guideshowlib.jar ')

2. Create a new folder drawable xxhdpi under res folder and copy five background and small dot pictures to the directory
The pictures used are https://github.com/javajavadog/guideshow/tree/master/GuideShowDemo/res/drawable-xxhdpi

3. Create a new fragment · entry.xml layout file
On the fifth page of the guidance page, click the OK button to start the MainActivity activity

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/bg_page_05" />

    <Button
        android:id="@+id/btn_entry"
        android:layout_width="160dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginBottom="120dp"
        android:text="@string/entry"/>

</FrameLayout>

4. New EntryFragment.java file inherits from Fragment registration onCreateView event

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_entry, null);

        view.findViewById(R.id.btn_entry).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GuideActivity activity = (GuideActivity)getActivity();
                activity.entryApp();
                //It will explode because there is no GuideActivity, but it doesn't matter. I'll finish next step
            }
        });
        return view;
    }

5. The new GuideActivity.java file inherits from the AbsGuideActivity,
import com.chechezhi.ui.guide.AbsGuideActivity;
Adding method

    @Override
    public List<SinglePage> buildGuideContent() {
        // prepare the information for our guide
        List<SinglePage> guideContent = new ArrayList<SinglePage>();

        SinglePage page01 = new SinglePage();
        page01.mBackground = getResources().getDrawable(R.drawable.bg_page_01);

        guideContent.add(page01);

        SinglePage page02 = new SinglePage();
        page02.mBackground = getResources().getDrawable(R.drawable.bg_page_02);

        guideContent.add(page02);

        SinglePage page03 = new SinglePage();
        page03.mBackground = getResources().getDrawable(R.drawable.bg_page_03);

        guideContent.add(page03);

        SinglePage page04 = new SinglePage();
        page04.mBackground = getResources().getDrawable(R.drawable.bg_page_04);

        guideContent.add(page04);

        SinglePage page05 = new SinglePage();
        page05.mCustomFragment = new EntryFragment();
        guideContent.add(page05);

        return guideContent;
    }

    @Override
    public Bitmap dotDefault() {
        return BitmapFactory.decodeResource(getResources(), R.drawable.ic_dot_default);
    }

    @Override
    public Bitmap dotSelected() {
        return BitmapFactory.decodeResource(getResources(), R.drawable.ic_dot_selected);
    }

    @Override
    public boolean drawDot() {
        return true;
    }

    /**
     * You need provide an id to the pager. You could define an id in
     * values/ids.xml and use it.
     */
    @Override
    public int getPagerId() {
        return R.id.guide_container;
    }

    public void entryApp() {
        // Time to entry your app! We just finish the activity, replace it with
        // your code.
        finish();
        Intent i = new Intent(GuideActivity.this, MainActivity.class);
        startActivity(i);
    }

The guide_container used by getPagerId() method is added in values/ids.xml (a new XML file is required)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="guide_container" type="id"/>
</resources>

6. Modify and start the Android manifest.xml file to GuideActivity, and add MainActivity activity

    <application
        ...
        <activity android:name=".GuideActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity" />
    </application>

ok.

Tags: Android xml github Fragment

Posted on Fri, 27 Mar 2020 12:47:09 -0400 by aravind_mg