From e735517c1de3e1dac426e05394ed1695c342bd31 Mon Sep 17 00:00:00 2001 From: Rey Pham Date: Mon, 30 Mar 2015 11:07:50 +0700 Subject: [PATCH] Add sb_text, sb_actionText, sb_duration attribute to SnackBar class. Add SpinnersFragment class. Add some gif. --- app/build.gradle | 4 +- .../com/rey/material/demo/MainActivity.java | 10 +++- .../rey/material/demo/SnackbarFragment.java | 10 +--- .../rey/material/demo/SpinnersFragment.java | 53 ++++++++++++++++++ app/src/main/res/layout/fragment_spinner.xml | 49 ++++++++++++++++ app/src/main/res/layout/row_spn.xml | 2 +- app/src/main/res/layout/row_spn_dropdown.xml | 14 +++++ app/src/main/res/values/styles.xml | 14 +++++ image/spn.gif | Bin 0 -> 41879 bytes image/tpi.gif | Bin 0 -> 197628 bytes .../com/rey/material/widget/SnackBar.java | 15 ++++- .../java/com/rey/material/widget/Spinner.java | 4 +- lib/src/main/res/values/attrs.xml | 3 + 13 files changed, 161 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/com/rey/material/demo/SpinnersFragment.java create mode 100644 app/src/main/res/layout/fragment_spinner.xml create mode 100644 app/src/main/res/layout/row_spn_dropdown.xml create mode 100644 image/spn.gif create mode 100644 image/tpi.gif diff --git a/app/build.gradle b/app/build.gradle index f58862b3..d6b94325 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.rey.material.demo" minSdkVersion 9 targetSdkVersion 21 - versionCode 1 - versionName "0.0.1" + versionCode 2 + versionName "0.0.2" } signingConfigs { diff --git a/app/src/main/java/com/rey/material/demo/MainActivity.java b/app/src/main/java/com/rey/material/demo/MainActivity.java index 9345ffaf..85931959 100644 --- a/app/src/main/java/com/rey/material/demo/MainActivity.java +++ b/app/src/main/java/com/rey/material/demo/MainActivity.java @@ -47,7 +47,7 @@ public class MainActivity extends ActionBarActivity implements AdapterView.OnIte private ToolbarManager mToolbarManager; private SnackBar mSnackBar; - private Tab[] mItems = new Tab[]{Tab.PROGRESS, Tab.BUTTONS, Tab.FAB, Tab.SWITCHES, Tab.SLIDERS, Tab.TEXTFIELDS, Tab.SNACKBARS, Tab.DIALOGS}; + private Tab[] mItems = new Tab[]{Tab.PROGRESS, Tab.BUTTONS, Tab.FAB, Tab.SWITCHES, Tab.SLIDERS, Tab.SPINNERS, Tab.TEXTFIELDS, Tab.SNACKBARS, Tab.DIALOGS}; @Override protected void onCreate(Bundle savedInstanceState) { @@ -159,6 +159,7 @@ public enum Tab { FAB ("FABs"), SWITCHES ("Switches"), SLIDERS ("Sliders"), + SPINNERS ("Spinners"), TEXTFIELDS ("TextFields"), SNACKBARS ("SnackBars"), DIALOGS ("Dialogs"); @@ -229,7 +230,7 @@ public View getView(int position, View convertView, ViewGroup parent) { private static class PagerAdapter extends FragmentStatePagerAdapter { - Fragment[] mFragments = new Fragment[3]; + Fragment[] mFragments; Tab[] mTabs; private static final Field sActiveField; @@ -266,6 +267,8 @@ else if(fragment instanceof SwitchesFragment) setFragment(Tab.SWITCHES, fragment); else if(fragment instanceof SliderFragment) setFragment(Tab.SLIDERS, fragment); + else if(fragment instanceof SpinnersFragment) + setFragment(Tab.SPINNERS, fragment); else if(fragment instanceof TextfieldFragment) setFragment(Tab.TEXTFIELDS, fragment); else if(fragment instanceof SnackbarFragment) @@ -304,6 +307,9 @@ public Fragment getItem(int position) { break; case SLIDERS: mFragments[position] = SliderFragment.newInstance(); + break; + case SPINNERS: + mFragments[position] = SpinnersFragment.newInstance(); break; case TEXTFIELDS: mFragments[position] = TextfieldFragment.newInstance(); diff --git a/app/src/main/java/com/rey/material/demo/SnackbarFragment.java b/app/src/main/java/com/rey/material/demo/SnackbarFragment.java index 182d6640..e7369cc1 100644 --- a/app/src/main/java/com/rey/material/demo/SnackbarFragment.java +++ b/app/src/main/java/com/rey/material/demo/SnackbarFragment.java @@ -40,17 +40,11 @@ public void onClick(View v) { else{ switch (v.getId()) { case R.id.snackbar_bt_mobile_single: - mSnackBar.applyStyle(R.style.Material_Widget_SnackBar_Mobile) - .text("This is single-line snackbar.") - .actionText("CLOSE") - .duration(0) + mSnackBar.applyStyle(R.style.SnackBarSingleLine) .show(); break; case R.id.snackbar_bt_mobile_multi: - mSnackBar.applyStyle(R.style.Material_Widget_SnackBar_Mobile_MultiLine) - .text("This is multi-line snackbar.\nIt will auto-close after 5s.") - .actionText(null) - .duration(5000) + mSnackBar.applyStyle(R.style.SnackBarMultiLine) .show(); break; case R.id.snackbar_bt_tablet_single: diff --git a/app/src/main/java/com/rey/material/demo/SpinnersFragment.java b/app/src/main/java/com/rey/material/demo/SpinnersFragment.java new file mode 100644 index 00000000..bd10789d --- /dev/null +++ b/app/src/main/java/com/rey/material/demo/SpinnersFragment.java @@ -0,0 +1,53 @@ +package com.rey.material.demo; + +import android.annotation.TargetApi; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; + +import com.rey.material.widget.FloatingActionButton; +import com.rey.material.widget.Spinner; + +public class SpinnersFragment extends Fragment{ + + + public static SpinnersFragment newInstance(){ + SpinnersFragment fragment = new SpinnersFragment(); + + return fragment; + } + + private Drawable[] mDrawables = new Drawable[2]; + private int index = 0; + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.fragment_spinner, container, false); + + Spinner spn_label = (Spinner)v.findViewById(R.id.spinner_label); + Spinner spn_no_arrow = (Spinner)v.findViewById(R.id.spinner_no_arrow); + ArrayAdapter adapter = new ArrayAdapter<>(getActivity(), R.layout.row_spn, new String[]{"Item 1", "Item 2", "Item 333333333333333"}); + adapter.setDropDownViewResource(R.layout.row_spn_dropdown); + spn_label.setAdapter(adapter); + spn_no_arrow.setAdapter(adapter); + + return v; + } + + @Override + public void onPause() { + super.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + } + +} diff --git a/app/src/main/res/layout/fragment_spinner.xml b/app/src/main/res/layout/fragment_spinner.xml new file mode 100644 index 00000000..9da39856 --- /dev/null +++ b/app/src/main/res/layout/fragment_spinner.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/row_spn.xml b/app/src/main/res/layout/row_spn.xml index 2be7949c..ac8e94f8 100644 --- a/app/src/main/res/layout/row_spn.xml +++ b/app/src/main/res/layout/row_spn.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/row_spn_tv" android:layout_width="match_parent" - android:layout_height="48dp" + android:layout_height="32dp" android:textSize="16sp" android:gravity="center_vertical" android:textColor="#FF000000" diff --git a/app/src/main/res/layout/row_spn_dropdown.xml b/app/src/main/res/layout/row_spn_dropdown.xml new file mode 100644 index 00000000..2be7949c --- /dev/null +++ b/app/src/main/res/layout/row_spn_dropdown.xml @@ -0,0 +1,14 @@ + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 6b34fe91..05f4b45f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -179,6 +179,20 @@ + + +