Merge "Add color picker to cardview demo" into lmp-mr1-dev
This commit is contained in:
@@ -123,13 +123,61 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@id/alpha_label"
|
||||
android:layout_alignTop="@id/alpha_label"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:id="@+id/color_label"
|
||||
android:textColor="@android:color/black"
|
||||
android:text="@string/card_view_bg_color"
|
||||
android:layout_below="@id/alpha_label"
|
||||
android:layout_alignRight="@id/alpha_label"/>
|
||||
<RadioGroup
|
||||
android:id="@+id/select_bg_color_radio"
|
||||
android:layout_toRightOf="@id/color_label"
|
||||
android:layout_alignTop="@id/color_label"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_below="@id/alpha_seek_bar">
|
||||
<RadioButton
|
||||
android:id="@+id/def"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/cardview_light_background"
|
||||
android:checked="true"/>
|
||||
<RadioButton
|
||||
android:id="@+id/yellow"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/card_yellow"/>
|
||||
<RadioButton
|
||||
android:id="@+id/aquatic"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/card_aquatic"/>
|
||||
<RadioButton
|
||||
android:id="@+id/classic"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/card_classic"/>
|
||||
<RadioButton
|
||||
android:id="@+id/sunbrite"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/card_sunbrite"/>
|
||||
<RadioButton
|
||||
android:id="@+id/tropical"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/card_tropical"/>
|
||||
</RadioGroup>
|
||||
<RadioGroup
|
||||
android:id="@+id/select_target_radio"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_below="@id/alpha_seek_bar">
|
||||
android:layout_below="@id/color_label">
|
||||
<RadioButton
|
||||
android:id="@+id/resize_card_view"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -144,7 +192,6 @@
|
||||
android:textColor="@android:color/black"
|
||||
android:text="@string/card_view_resize_content"/>
|
||||
</RadioGroup>
|
||||
|
||||
</RelativeLayout>
|
||||
<RelativeLayout android:layout_width="fill_parent"
|
||||
android:layout_height="match_parent">
|
||||
@@ -155,9 +202,10 @@
|
||||
card_view:cardElevation="10dp">
|
||||
<TextView
|
||||
android:id="@+id/info_text"
|
||||
android:text="@string/card_view"
|
||||
android:textColor="@android:color/black"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</android.support.v7.widget.CardView>
|
||||
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:text="@string/card_view_sample_text"
|
||||
|
||||
@@ -16,4 +16,9 @@
|
||||
|
||||
<resources>
|
||||
<drawable name="blue">#770000ff</drawable>
|
||||
<color name="card_yellow">#FCF0AD</color>
|
||||
<color name="card_aquatic">#FCF0AD</color>
|
||||
<color name="card_classic">#BAB7A9</color>
|
||||
<color name="card_sunbrite">#F9D6AC</color>
|
||||
<color name="card_tropical">#56C4E8</color>
|
||||
</resources>
|
||||
|
||||
@@ -150,6 +150,7 @@
|
||||
<string name="card_view_radius">Radius</string>
|
||||
<string name="card_view_width">Width</string>
|
||||
<string name="card_view_height">Height</string>
|
||||
<string name="card_view_bg_color">Background</string>
|
||||
<string name="card_view_elevation">Elevation</string>
|
||||
<string name="card_view_max_elevation">Max Elevation</string>
|
||||
<string name="card_view_alpha">Alpha</string>
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package com.example.android.supportv7.view;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
@@ -25,8 +27,11 @@ import android.view.ViewGroup;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.android.supportv7.R;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class CardViewActivity extends Activity {
|
||||
|
||||
CardView mCardView;
|
||||
@@ -84,7 +89,7 @@ public class CardViewActivity extends Activity {
|
||||
lp = setViewBounds(mInfoText);
|
||||
}
|
||||
mInfoText.setText("radius: " + mCornerRadiusSeekBar.getProgress()
|
||||
+", alpha: " + mAlphaSeekBar.getProgress()
|
||||
+ ", alpha: " + mAlphaSeekBar.getProgress()
|
||||
+ "\n w: " + lp.width + "\nh: " + lp.height
|
||||
+ "\nelevation: " + mCardView.getCardElevation() + " of "
|
||||
+ mCardView.getMaxCardElevation());
|
||||
@@ -143,15 +148,42 @@ public class CardViewActivity extends Activity {
|
||||
}
|
||||
});
|
||||
|
||||
update();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
View content = findViewById(android.R.id.content);
|
||||
mWidthSeekBar.setProgress(mCardView.getWidth());
|
||||
mHeightSeekBar.setProgress(mCardView.getHeight());
|
||||
mWidthSeekBar.setMax(content.getWidth());
|
||||
mHeightSeekBar.setMax(content.getHeight());
|
||||
update();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
((RadioGroup) findViewById(R.id.select_bg_color_radio))
|
||||
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
mCardView.setCardBackgroundColor(
|
||||
getResources().getColor(getColorId(checkedId)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int getColorId(int id) {
|
||||
switch (id) {
|
||||
case R.id.yellow:
|
||||
return R.color.card_yellow;
|
||||
case R.id.aquatic:
|
||||
return R.color.card_aquatic;
|
||||
case R.id.classic:
|
||||
return R.color.card_classic;
|
||||
case R.id.sunbrite:
|
||||
return R.color.card_sunbrite;
|
||||
case R.id.tropical:
|
||||
return R.color.card_tropical;
|
||||
default:
|
||||
return R.color.cardview_light_background;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,7 +480,7 @@ public class AnimatedRecyclerView extends Activity {
|
||||
}
|
||||
|
||||
public void selectItem(MyViewHolder holder, boolean selected) {
|
||||
mSelected.put((String) holder.textView.getText(), selected);
|
||||
mSelected.put((String) holder.textView.getText().toString(), selected);
|
||||
}
|
||||
|
||||
public void toggleExpanded(MyViewHolder holder) {
|
||||
|
||||
Reference in New Issue
Block a user