Created
August 5, 2020 07:46
-
-
Save cortinico/1c0e5db962966414d444f3e790e80c3d to your computer and use it in GitHub Desktop.
AppIntro SlideBackgroundColorHolder example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.appintro.example.ui; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.LinearLayout; | |
import androidx.annotation.ColorInt; | |
import androidx.annotation.LayoutRes; | |
import androidx.annotation.NonNull; | |
import androidx.fragment.app.Fragment; | |
import com.github.appintro.SlideBackgroundColorHolder; | |
import com.github.appintro.example.R; | |
import org.jetbrains.annotations.Nullable; | |
public class ColorCustomLayoutFragment extends Fragment implements SlideBackgroundColorHolder { | |
private static final String ARG_LAYOUT_RES_ID = "LAYOUT_RES_ID"; | |
private static final String ARG_COLOR_INT = "COLOR_INT"; | |
private int layoutResId = 0; | |
private int originalColor = 0; | |
private LinearLayout background = null; | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
layoutResId = getArguments().getInt(ARG_LAYOUT_RES_ID); | |
originalColor = getArguments().getInt(ARG_COLOR_INT); | |
} | |
@Nullable | |
@Override | |
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
return inflater.inflate(layoutResId, container, false); | |
} | |
@Override | |
public void onViewCreated(@NonNull View view, @androidx.annotation.Nullable Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
background = view.findViewById(R.id.custom_slide_background); | |
} | |
static ColorCustomLayoutFragment newInstance(@LayoutRes int layoutResId, @ColorInt int originalColor) { | |
ColorCustomLayoutFragment newFragment = new ColorCustomLayoutFragment(); | |
Bundle args = new Bundle(); | |
args.putInt(ARG_LAYOUT_RES_ID, layoutResId); | |
args.putInt(ARG_COLOR_INT, originalColor); | |
newFragment.setArguments(args); | |
return newFragment; | |
} | |
@Override | |
public int getDefaultBackgroundColor() { | |
return originalColor; | |
} | |
@Override | |
public void setBackgroundColor(int backgroundColor) { | |
background.setBackgroundColor(backgroundColor); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.appintro.example.ui; | |
import android.graphics.Color; | |
import android.os.Bundle; | |
import com.github.appintro.AppIntro; | |
import com.github.appintro.example.R; | |
import org.jetbrains.annotations.Nullable; | |
public class SampleIntro extends AppIntro { | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
addSlide(ColorCustomLayoutFragment.newInstance(R.layout.slide, Color.RED)); | |
addSlide(ColorCustomLayoutFragment.newInstance(R.layout.slide, Color.GREEN)); | |
addSlide(ColorCustomLayoutFragment.newInstance(R.layout.slide, Color.BLUE)); | |
setColorTransitionsEnabled(true); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:id="@+id/custom_slide_background" | |
android:gravity="center" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Hello" | |
android:layout_margin="24dp" | |
android:textSize="40sp" /> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code will produce this AppIntro: