diff options
author | Trumeet <liangyuteng12345@gmail.com> | 2018-09-08 21:08:14 -0700 |
---|---|---|
committer | Trumeet <liangyuteng12345@gmail.com> | 2018-09-08 21:08:14 -0700 |
commit | 4b38a99961fac44b14848cf8782d5619c7b3dddc (patch) | |
tree | 0794ba93d3118c00bf05d58f5e165c5924a898ea /app/src/main | |
download | PageIndicator-4b38a99961fac44b14848cf8782d5619c7b3dddc.tar PageIndicator-4b38a99961fac44b14848cf8782d5619c7b3dddc.tar.gz PageIndicator-4b38a99961fac44b14848cf8782d5619c7b3dddc.tar.bz2 PageIndicator-4b38a99961fac44b14848cf8782d5619c7b3dddc.zip |
First commitHEADandroid-9.0.0_r8
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/AndroidManifest.xml | 22 | ||||
-rw-r--r-- | app/src/main/java/moe/yuuta/pageindicator/MainActivity.java | 94 | ||||
-rw-r--r-- | app/src/main/java/moe/yuuta/pageindicator/PageFragment.java | 43 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_main.xml | 21 | ||||
-rw-r--r-- | app/src/main/res/layout/fragment_page.xml | 11 | ||||
-rw-r--r-- | app/src/main/res/mipmap-hdpi/ic_launcher.png | bin | 0 -> 2963 bytes | |||
-rw-r--r-- | app/src/main/res/mipmap-mdpi/ic_launcher.png | bin | 0 -> 2060 bytes | |||
-rw-r--r-- | app/src/main/res/mipmap-xhdpi/ic_launcher.png | bin | 0 -> 4490 bytes | |||
-rw-r--r-- | app/src/main/res/mipmap-xxhdpi/ic_launcher.png | bin | 0 -> 6387 bytes | |||
-rw-r--r-- | app/src/main/res/mipmap-xxxhdpi/ic_launcher.png | bin | 0 -> 9128 bytes | |||
-rw-r--r-- | app/src/main/res/values/colors.xml | 6 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 3 | ||||
-rw-r--r-- | app/src/main/res/values/styles.xml | 13 |
13 files changed, 213 insertions, 0 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4f2b7a3 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="moe.yuuta.pageindicator"> + + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:supportsRtl="true" + android:theme="@style/AppTheme" + tools:ignore="GoogleAppIndexingWarning"> + <activity android:name=".MainActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + +</manifest>
\ No newline at end of file diff --git a/app/src/main/java/moe/yuuta/pageindicator/MainActivity.java b/app/src/main/java/moe/yuuta/pageindicator/MainActivity.java new file mode 100644 index 0000000..e314737 --- /dev/null +++ b/app/src/main/java/moe/yuuta/pageindicator/MainActivity.java @@ -0,0 +1,94 @@ +package moe.yuuta.pageindicator; + +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.Toast; + +import com.android.systemui.qr.PageIndicator; + +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; + +public class MainActivity extends FragmentActivity { + private PageIndicator mPageIndicator; + private float mPageIndicatorPosition; + private int mNumPages; + private ViewPager mPager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + mPager = findViewById(R.id.pager); + setPageIndicator((PageIndicator) findViewById(R.id.indicator)); + mPager.addOnPageChangeListener(this.mOnPageChangeListener); + mPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { + @Override + public Fragment getItem(int position) { + return PageFragment.newInstance(position); + } + + @Override + public int getCount() { + return mNumPages; + } + }); + Toast.makeText(this, "Tap 'ADD' to add pages!", Toast.LENGTH_SHORT).show(); + } + + @Override + protected void onPostCreate(@Nullable Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + addPage(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + menu.add(0, 0, 0, "Add").setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == 0) { + addPage(); + return true; + } + return super.onOptionsItemSelected(item); + } + + private void addPage () { + if (mPager.getAdapter() == null) { + // onCreate not finished, just skip + return; + } + mNumPages++; + mPager.getAdapter().notifyDataSetChanged(); + mPageIndicator.setNumPages(mNumPages); + } + + public void setPageIndicator(PageIndicator indicator) { + mPageIndicator = indicator; + mPageIndicator.setNumPages(mNumPages); + mPageIndicator.setLocation(mPageIndicatorPosition); + } + + private final ViewPager.OnPageChangeListener mOnPageChangeListener = + new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + } + + @Override + public void onPageScrolled(int position, float positionOffset, + int positionOffsetPixels) { + if (mPageIndicator == null) return; + mPageIndicatorPosition = position + positionOffset; + mPageIndicator.setLocation(mPageIndicatorPosition); + } + }; +} diff --git a/app/src/main/java/moe/yuuta/pageindicator/PageFragment.java b/app/src/main/java/moe/yuuta/pageindicator/PageFragment.java new file mode 100644 index 0000000..5524540 --- /dev/null +++ b/app/src/main/java/moe/yuuta/pageindicator/PageFragment.java @@ -0,0 +1,43 @@ +package moe.yuuta.pageindicator; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +public class PageFragment extends Fragment { + private static final String EXTRA_PAGE_INDEX = PageFragment.class.getName() + ".EXTRA_PAGE_INDEX"; + + private int index; + + static PageFragment newInstance (int index) { + Bundle args = new Bundle(); + PageFragment fragment = new PageFragment(); + + args.putInt(EXTRA_PAGE_INDEX, index); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() == null) return; + this.index = getArguments().getInt(EXTRA_PAGE_INDEX); + } + + @SuppressLint("SetTextI18n") + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_page, container, false); + ((TextView) view.findViewById(R.id.text_page_digit)).setText(Integer.toString(index)); + return view; + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..e17567e --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".MainActivity"> + <androidx.viewpager.widget.ViewPager + android:id="@+id/pager" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + </androidx.viewpager.widget.ViewPager> + <com.android.systemui.qr.PageIndicator + android:id="@+id/indicator" + android:layout_width="match_parent" + android:layout_height="48dp" + android:layout_gravity="bottom" + android:layout_marginBottom="24dp" + android:focusable="true" + android:gravity="center" + android:importantForAccessibility="yes"/> +</FrameLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/fragment_page.xml b/app/src/main/res/layout/fragment_page.xml new file mode 100644 index 0000000..0b6eec8 --- /dev/null +++ b/app/src/main/res/layout/fragment_page.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <TextView + android:id="@+id/text_page_digit" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:textAppearance="@android:style/TextAppearance.Material.Headline"/> +</FrameLayout>
\ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..898f3ed --- /dev/null +++ b/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..64ba76f --- /dev/null +++ b/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..e5ed465 --- /dev/null +++ b/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..b0907ca --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..2c18de9 --- /dev/null +++ b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..69b2233 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="colorPrimary">#008577</color> + <color name="colorPrimaryDark">#00574B</color> + <color name="colorAccent">#D81B60</color> +</resources> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..054390a --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ +<resources> + <string name="app_name">PageIndicator</string> +</resources> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..5e8b5e3 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,13 @@ +<resources> + + <!-- Base application theme. --> + <style name="AppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar"> + <!-- Customize your theme here. --> + <item name="android:colorPrimary">@color/colorPrimary</item> + <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="android:colorAccent">@color/colorAccent</item> + <!-- use colorControlActivated to customize indicator's color! --> + <item name="android:colorControlActivated">?android:colorPrimary</item> + </style> + +</resources> |