Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from rey5137/dev
Browse files Browse the repository at this point in the history
Add sb_text, sb_actionText, sb_duration attribute to SnackBar class.
  • Loading branch information
rey5137 committed Mar 30, 2015
2 parents aff0f07 + e735517 commit c32788c
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/rey/material/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -159,6 +159,7 @@ public enum Tab {
FAB ("FABs"),
SWITCHES ("Switches"),
SLIDERS ("Sliders"),
SPINNERS ("Spinners"),
TEXTFIELDS ("TextFields"),
SNACKBARS ("SnackBars"),
DIALOGS ("Dialogs");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/com/rey/material/demo/SnackbarFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
53 changes: 53 additions & 0 deletions app/src/main/java/com/rey/material/demo/SpinnersFragment.java
Original file line number Diff line number Diff line change
@@ -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<String> 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();
}

}
49 changes: 49 additions & 0 deletions app/src/main/res/layout/fragment_spinner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbarStyle="outsideOverlay">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:padding="8dp">

<com.rey.material.widget.Spinner
style="@style/Material.Widget.Spinner.Light"
android:id="@+id/spinner_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="128dp"
app:ripple="@style/FlatWaveButtonRippleStyle"
app:delayClick="false"
app:spn_labelEnable="true"
app:spn_label="Spinner with arrow"
app:spn_arrowSwitchMode="true"
app:spn_arrowAnimDuration="@android:integer/config_shortAnimTime"
app:spn_arrowInterpolator="@android:anim/decelerate_interpolator"/>

<com.rey.material.widget.Spinner
style="@style/Material.Widget.Spinner.Light"
android:id="@+id/spinner_no_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="128dp"
android:layout_marginTop="16dp"
app:ripple="@style/FlatWaveButtonRippleStyle"
app:delayClick="false"
app:spn_labelEnable="true"
app:spn_label="Spinner without arrow"
app:spn_arrowSize="0dp"
app:spn_popupItemAnimation="@anim/abc_fade_in"/>


</LinearLayout>


</ScrollView>

2 changes: 1 addition & 1 deletion app/src/main/res/layout/row_spn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/row_spn_dropdown.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<com.rey.material.widget.TextView xmlns:android="http://schemas.android.com/apk/res/android"
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:textSize="16sp"
android:gravity="center_vertical"
android:textColor="#FF000000"
android:paddingLeft="16dp"
android:paddingRight="16dp"
app:ripple="@style/MenuItemRippleStyle"
app:delayClick="true"/>

14 changes: 14 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@

<style name="CheckBoxDrawable" parent="Material.Drawable.CheckBox"/>

<!-- SnackBar Style -->

<style name="SnackBarSingleLine" parent="Material.Widget.SnackBar.Mobile">
<item name="sb_text">This is single-line snackbar.</item>
<item name="sb_actionText">CLOSE</item>
<item name="sb_duration">0</item>
</style>

<style name="SnackBarMultiLine" parent="Material.Widget.SnackBar.Mobile.MultiLine">
<item name="sb_text">This is multi-line snackbar.\nIt will auto-close after 5s.</item>
<item name="sb_actionText"></item>
<item name="sb_duration">5000</item>
</style>

<!-- FloatingActionButton Style -->

<style name="FloatingActionButton" parent="Material.Widget.FloatingActionButton.Light">
Expand Down
Binary file added image/spn.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/tpi.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions lib/src/main/java/com/rey/material/widget/SnackBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.util.TypedValue;
Expand Down Expand Up @@ -230,6 +231,7 @@ private void applyStyle(AttributeSet attrs, int defStyleAttr, int defStyleRes){
boolean hasTextColor = a.hasValue(R.styleable.SnackBar_sb_textColor);
int textColor = hasTextColor ? a.getColor(R.styleable.SnackBar_sb_textColor, 0xFFFFFFFF) : 0;
int textAppearance = a.getResourceId(R.styleable.SnackBar_sb_textAppearance, 0);
String text = a.getString(R.styleable.SnackBar_sb_text);
boolean singleLine = a.getBoolean(R.styleable.SnackBar_sb_singleLine, true);
int maxLines = a.getInteger(R.styleable.SnackBar_sb_maxLines, 0);
int lines = a.getInteger(R.styleable.SnackBar_sb_lines, 0);
Expand All @@ -242,10 +244,13 @@ private void applyStyle(AttributeSet attrs, int defStyleAttr, int defStyleRes){
else
actionTextColor = a.getColorStateList(R.styleable.SnackBar_sb_actionTextColor);
int actionTextAppearance = a.getResourceId(R.styleable.SnackBar_sb_actionTextAppearance, 0);
String actionText = a.getString(R.styleable.SnackBar_sb_actionText);
int actionRipple = a.getResourceId(R.styleable.SnackBar_sb_actionRipple, 0);
int duration = a.getInteger(R.styleable.SnackBar_sb_duration, -1);
mInAnimationId = a.getResourceId(R.styleable.SnackBar_sb_inAnimation, 0);
mOutAnimationId = a.getResourceId(R.styleable.SnackBar_sb_outAnimation, 0);
mRemoveOnDismiss = a.getBoolean(R.styleable.SnackBar_sb_removeOnDismiss, true);


a.recycle();

Expand All @@ -258,7 +263,9 @@ private void applyStyle(AttributeSet attrs, int defStyleAttr, int defStyleRes){
if(textSize > 0)
textSize(textSize);
if(hasTextColor)
textColor(textColor);
textColor(textColor);
if(text != null)
text(text);
singleLine(singleLine);
if(maxLines > 0)
maxLines(maxLines);
Expand Down Expand Up @@ -296,8 +303,12 @@ private void applyStyle(AttributeSet attrs, int defStyleAttr, int defStyleRes){
actionTextSize(actionTextSize);
if(actionTextColor != null)
actionTextColor(actionTextColor);
if(actionText != null)
actionText(actionText);
if(actionRipple != 0)
actionRipple(actionRipple);
if(duration >= 0)
duration(duration);
}

public SnackBar applyStyle(int resId){
Expand Down Expand Up @@ -356,7 +367,7 @@ public SnackBar actionId(int id){
}

public SnackBar actionText(CharSequence text){
if(text == null)
if(TextUtils.isEmpty(text))
mAction.setVisibility(View.INVISIBLE);
else{
mAction.setVisibility(View.VISIBLE);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/rey/material/widget/Spinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ public void init(Context context, AttributeSet attrs, int defStyleAttr, int defS
ColorStateList dividerColor = a.getColorStateList(R.styleable.Spinner_spn_dividerColor);
if(dividerColor == null){
int[][] states = new int[][]{
new int[]{-android.R.attr.state_focused},
new int[]{android.R.attr.state_focused, android.R.attr.state_enabled},
new int[]{-android.R.attr.state_pressed},
new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled},
};
int[] colors = new int[]{
ThemeUtil.colorControlNormal(context, 0xFF000000),
Expand Down
3 changes: 3 additions & 0 deletions lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
<attr name="sb_textSize" format="reference|dimension"/>
<attr name="sb_textColor" format="reference|color"/>
<attr name="sb_textAppearance" format="reference"/>
<attr name="sb_text" format="reference|string"/>
<attr name="sb_singleLine" format="boolean"/>
<attr name="sb_maxLines" format="reference|integer"/>
<attr name="sb_lines" format="reference|integer"/>
Expand All @@ -301,7 +302,9 @@
<attr name="sb_actionTextSize" format="reference|dimension"/>
<attr name="sb_actionTextColor" format="reference|color"/>
<attr name="sb_actionTextAppearance" format="reference"/>
<attr name="sb_actionText" format="reference|string"/>
<attr name="sb_actionRipple" format="reference"/>
<attr name="sb_duration" format="reference|integer"/>
<attr name="sb_inAnimation" format="reference"/>
<attr name="sb_outAnimation" format="reference"/>
<attr name="sb_removeOnDismiss" format="boolean" />
Expand Down

0 comments on commit c32788c

Please sign in to comment.