From b5de9c7b9d17d90396ec52cb32999698a945b28f Mon Sep 17 00:00:00 2001 From: Yigit Boyar Date: Thu, 15 May 2014 21:02:05 -0700 Subject: [PATCH] Added CardView demo to SupportV7 demo app Change-Id: Ie1b81426dc67c67766eb20fb8f1fc984d25a42cf --- samples/Support7Demos/Android.mk | 8 +- samples/Support7Demos/AndroidManifest.xml | 9 ++ .../res/layout/activity_card_view.xml | 84 ++++++++++++++++ samples/Support7Demos/res/values/strings.xml | 4 + .../supportv7/view/CardViewActivity.java | 98 +++++++++++++++++++ 5 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 samples/Support7Demos/res/layout/activity_card_view.xml create mode 100644 samples/Support7Demos/src/com/example/android/supportv7/view/CardViewActivity.java diff --git a/samples/Support7Demos/Android.mk b/samples/Support7Demos/Android.mk index ca8310fea..ef516408a 100644 --- a/samples/Support7Demos/Android.mk +++ b/samples/Support7Demos/Android.mk @@ -27,13 +27,15 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ android-support-v7-appcompat \ android-support-v7-gridlayout \ android-support-v7-mediarouter \ - android-support-v7-recyclerview + android-support-v7-recyclerview \ + android-support-v7-cardview LOCAL_RESOURCE_DIR = \ $(LOCAL_PATH)/res \ frameworks/support/v7/appcompat/res \ frameworks/support/v7/gridlayout/res \ - frameworks/support/v7/mediarouter/res + frameworks/support/v7/mediarouter/res \ + frameworks/support/v7/cardview/res LOCAL_AAPT_FLAGS := \ --auto-add-overlay \ - --extra-packages android.support.v7.appcompat:android.support.v7.gridlayout:android.support.v7.mediarouter + --extra-packages android.support.v7.cardview:android.support.v7.appcompat:android.support.v7.gridlayout:android.support.v7.mediarouter include $(BUILD_PACKAGE) diff --git a/samples/Support7Demos/AndroidManifest.xml b/samples/Support7Demos/AndroidManifest.xml index 6f9b2373e..3cbb35951 100644 --- a/samples/Support7Demos/AndroidManifest.xml +++ b/samples/Support7Demos/AndroidManifest.xml @@ -201,5 +201,14 @@ + + + + + + + diff --git a/samples/Support7Demos/res/layout/activity_card_view.xml b/samples/Support7Demos/res/layout/activity_card_view.xml new file mode 100644 index 000000000..f88daf7f4 --- /dev/null +++ b/samples/Support7Demos/res/layout/activity_card_view.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + diff --git a/samples/Support7Demos/res/values/strings.xml b/samples/Support7Demos/res/values/strings.xml index 7e4e03c1a..5a80295d6 100644 --- a/samples/Support7Demos/res/values/strings.xml +++ b/samples/Support7Demos/res/values/strings.xml @@ -109,4 +109,8 @@ D+A d1a2d3 + Card View + Radius + Width + Height diff --git a/samples/Support7Demos/src/com/example/android/supportv7/view/CardViewActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/view/CardViewActivity.java new file mode 100644 index 000000000..e680aaa2c --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/view/CardViewActivity.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.android.supportv7.view; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.widget.CardView; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.SeekBar; +import android.widget.TextView; +import com.example.android.supportv7.R; + +public class CardViewActivity extends Activity { + + CardView mCardView; + + TextView mInfoText; + + SeekBar mCornerRadiusSeekBar; + + SeekBar mWidthSeekBar; + + SeekBar mHeightSeekBar; + + private SeekBar.OnSeekBarChangeListener mOnSeekBarChangedListener + = new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + update(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }; + + private void update() { + mCardView.setRadius(mCornerRadiusSeekBar.getProgress()); + LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mCardView.getLayoutParams(); + lp.width = mWidthSeekBar.getProgress(); + lp.height = mHeightSeekBar.getProgress(); + mCardView.setLayoutParams(lp); + mInfoText.setText("radius : " + mCornerRadiusSeekBar.getProgress() + + "\n w:" + lp.width + "\nh:" + lp.height); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_card_view); + mInfoText = (TextView) findViewById(R.id.info_text); + mCardView = (CardView) findViewById(R.id.card_view); + mCornerRadiusSeekBar = (SeekBar) findViewById(R.id.corner_radius_seek_bar); + mCornerRadiusSeekBar.setProgress((int) mCardView.getRadius()); + mCornerRadiusSeekBar.setOnSeekBarChangeListener(mOnSeekBarChangedListener); + + mWidthSeekBar = (SeekBar) findViewById(R.id.width_seek_bar); + mWidthSeekBar.setProgress(mCardView.getLayoutParams().width); + + mWidthSeekBar.setOnSeekBarChangeListener(mOnSeekBarChangedListener); + + mHeightSeekBar = (SeekBar) findViewById(R.id.height_seek_bar); + mHeightSeekBar.setProgress(mCardView.getLayoutParams().height); + mHeightSeekBar.setOnSeekBarChangeListener(mOnSeekBarChangedListener); + + update(); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + View content = findViewById(android.R.id.content); + mWidthSeekBar.setMax(content.getWidth()); + mHeightSeekBar.setMax(content.getHeight()); + } + }, 100); + } + +}