From f3d6a16008454673c1f7f5b1bfc6cd28307e5d46 Mon Sep 17 00:00:00 2001 From: Aidan Follestad Date: Tue, 21 Apr 2015 22:03:17 -0500 Subject: [PATCH] Updated Support Library, RecyclerView, Annotations, and AppCompat. Also changed deprecated ActionBarActivity to AppCompatActivity. RecyclerView's scroll listener 'set' method was also deprecated in favor of an 'add' version. Today's Google lib updates are big. --- build.gradle | 4 +- library/build.gradle | 5 +- .../melnykov/fab/FloatingActionButton.java | 24 ++-- sample/build.gradle | 5 +- .../com/melnykov/fab/sample/MainActivity.java | 116 +++++++++--------- 5 files changed, 77 insertions(+), 77 deletions(-) diff --git a/build.gradle b/build.gradle index 52b1bbf8..efd32c1e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,9 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { repositories { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.1.0' + classpath 'com.android.tools.build:gradle:1.1.3' } } diff --git a/library/build.gradle b/library/build.gradle index 5bfc958f..30ab2085 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -23,9 +23,10 @@ android { } dependencies { - compile 'com.android.support:support-annotations:21.0.3' - compile 'com.android.support:recyclerview-v7:21.0.3' + compile 'com.android.support:support-annotations:22.1.0' + compile 'com.android.support:recyclerview-v7:22.1.0@aar' compile 'com.nineoldandroids:library:2.4.0' + compile 'com.android.support:support-v4:22.1.0@aar' } apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' diff --git a/library/src/main/java/com/melnykov/fab/FloatingActionButton.java b/library/src/main/java/com/melnykov/fab/FloatingActionButton.java index 3f88ddf8..ee437211 100644 --- a/library/src/main/java/com/melnykov/fab/FloatingActionButton.java +++ b/library/src/main/java/com/melnykov/fab/FloatingActionButton.java @@ -81,7 +81,7 @@ public FloatingActionButton(Context context, AttributeSet attrs, int defStyle) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int size = getDimension( - mType == TYPE_NORMAL ? R.dimen.fab_size_normal : R.dimen.fab_size_mini); + mType == TYPE_NORMAL ? R.dimen.fab_size_normal : R.dimen.fab_size_mini); if (mShadow && !hasLollipopApi()) { size += mShadowSize * 2; setMarginsWithoutShadow(); @@ -110,13 +110,13 @@ private void initAttributes(Context context, AttributeSet attributeSet) { if (attr != null) { try { mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, - getColor(R.color.material_blue_500)); + getColor(R.color.material_blue_500)); mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, - darkenColor(mColorNormal)); + darkenColor(mColorNormal)); mColorRipple = attr.getColor(R.styleable.FloatingActionButton_fab_colorRipple, - lightenColor(mColorNormal)); + lightenColor(mColorNormal)); mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, - mColorDisabled); + mColorDisabled); mShadow = attr.getBoolean(R.styleable.FloatingActionButton_fab_shadow, true); mType = attr.getInt(R.styleable.FloatingActionButton_fab_type, TYPE_NORMAL); } finally { @@ -140,7 +140,7 @@ private Drawable createDrawable(int color) { if (mShadow && !hasLollipopApi()) { Drawable shadowDrawable = getResources().getDrawable(mType == TYPE_NORMAL ? R.drawable.fab_shadow - : R.drawable.fab_shadow_mini); + : R.drawable.fab_shadow_mini); LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{shadowDrawable, shapeDrawable}); layerDrawable.setLayerInset(1, mShadowSize, mShadowSize, mShadowSize, mShadowSize); return layerDrawable; @@ -184,18 +184,18 @@ private void setBackgroundCompat(Drawable drawable) { float elevation; if (mShadow) { elevation = getElevation() > 0.0f ? getElevation() - : getDimension(R.dimen.fab_elevation_lollipop); + : getDimension(R.dimen.fab_elevation_lollipop); } else { elevation = 0.0f; } setElevation(elevation); RippleDrawable rippleDrawable = new RippleDrawable(new ColorStateList(new int[][]{{}}, - new int[]{mColorRipple}), drawable, null); + new int[]{mColorRipple}), drawable, null); setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { int size = getDimension(mType == TYPE_NORMAL ? R.dimen.fab_size_normal - : R.dimen.fab_size_mini); + : R.dimen.fab_size_mini); outline.setOval(0, 0, size, size); } }); @@ -329,8 +329,8 @@ public boolean onPreDraw() { int translationY = visible ? 0 : height + getMarginBottom(); if (animate) { ViewPropertyAnimator.animate(this).setInterpolator(mInterpolator) - .setDuration(TRANSLATE_DURATION_MILLIS) - .translationY(translationY); + .setDuration(TRANSLATE_DURATION_MILLIS) + .translationY(translationY); } else { ViewHelper.setTranslationY(this, translationY); } @@ -387,7 +387,7 @@ public void attachToRecyclerView(@NonNull RecyclerView recyclerView, scrollDetector.setScrollDirectionListener(scrollDirectionlistener); scrollDetector.setOnScrollListener(onScrollListener); scrollDetector.setScrollThreshold(mScrollThreshold); - recyclerView.setOnScrollListener(scrollDetector); + recyclerView.addOnScrollListener(scrollDetector); } public void attachToScrollView(@NonNull ObservableScrollView scrollView, diff --git a/sample/build.gradle b/sample/build.gradle index 53493f8a..579cdf40 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -21,6 +21,7 @@ android { dependencies { compile project(':library') - compile 'com.android.support:appcompat-v7:21.0.3' - compile 'com.android.support:recyclerview-v7:21.0.3' + compile 'com.android.support:appcompat-v7:22.1.0@aar' + compile 'com.android.support:recyclerview-v7:22.1.0@aar' + compile 'com.android.support:support-v4:22.1.0@aar' } \ No newline at end of file diff --git a/sample/src/main/java/com/melnykov/fab/sample/MainActivity.java b/sample/src/main/java/com/melnykov/fab/sample/MainActivity.java index b68c99f2..5e491417 100644 --- a/sample/src/main/java/com/melnykov/fab/sample/MainActivity.java +++ b/sample/src/main/java/com/melnykov/fab/sample/MainActivity.java @@ -7,7 +7,7 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -28,7 +28,7 @@ import com.melnykov.fab.ObservableScrollView; import com.melnykov.fab.ScrollDirectionListener; -public class MainActivity extends ActionBarActivity { +public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { @@ -42,53 +42,53 @@ private void initActionBar() { ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.addTab(actionBar.newTab() - .setText("ListView") - .setTabListener(new ActionBar.TabListener() { - @Override - public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - fragmentTransaction.replace(android.R.id.content, new ListViewFragment()); - } - - @Override - public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - } - - @Override - public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - } - })); + .setText("ListView") + .setTabListener(new ActionBar.TabListener() { + @Override + public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + fragmentTransaction.replace(android.R.id.content, new ListViewFragment()); + } + + @Override + public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + } + + @Override + public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + } + })); actionBar.addTab(actionBar.newTab() - .setText("RecyclerView") - .setTabListener(new ActionBar.TabListener() { - @Override - public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - fragmentTransaction.replace(android.R.id.content, new RecyclerViewFragment()); - } - - @Override - public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - } - - @Override - public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - } - })); + .setText("RecyclerView") + .setTabListener(new ActionBar.TabListener() { + @Override + public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + fragmentTransaction.replace(android.R.id.content, new RecyclerViewFragment()); + } + + @Override + public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + } + + @Override + public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + } + })); actionBar.addTab(actionBar.newTab() - .setText("ScrollView") - .setTabListener(new ActionBar.TabListener() { - @Override - public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - fragmentTransaction.replace(android.R.id.content, new ScrollViewFragment()); - } - - @Override - public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - } - - @Override - public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - } - })); + .setText("ScrollView") + .setTabListener(new ActionBar.TabListener() { + @Override + public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + fragmentTransaction.replace(android.R.id.content, new ScrollViewFragment()); + } + + @Override + public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + } + + @Override + public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + } + })); } } @@ -105,15 +105,15 @@ public boolean onOptionsItemSelected(MenuItem item) { content.setMovementMethod(LinkMovementMethod.getInstance()); content.setText(Html.fromHtml(getString(R.string.about_body))); new AlertDialog.Builder(this) - .setTitle(R.string.about) - .setView(content) - .setInverseBackgroundForced(true) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }).create().show(); + .setTitle(R.string.about) + .setView(content) + .setInverseBackgroundForced(true) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }).create().show(); } return super.onOptionsItemSelected(item); } @@ -127,7 +127,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa ListView list = (ListView) root.findViewById(android.R.id.list); ListViewAdapter listAdapter = new ListViewAdapter(getActivity(), - getResources().getStringArray(R.array.countries)); + getResources().getStringArray(R.array.countries)); list.setAdapter(listAdapter); FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.fab); @@ -169,7 +169,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST)); RecyclerViewAdapter adapter = new RecyclerViewAdapter(getActivity(), getResources() - .getStringArray(R.array.countries)); + .getStringArray(R.array.countries)); recyclerView.setAdapter(adapter); FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.fab);