summaryrefslogtreecommitdiffstats
path: root/samples/Support4Demos/src
diff options
context:
space:
mode:
authorBenjamin Weiss <benweiss@google.com>2015-06-25 16:17:07 +0100
committerBenjamin Weiss <benweiss@google.com>2015-07-07 11:49:45 +0100
commitc84455c11fdace9bc5c82aae99318bd9cd2480fa (patch)
treea9892cfdee750734cc361e9dec99e24f58a2cedd /samples/Support4Demos/src
parent0d21ec5c41d905122dda25c214c5931666d7ec10 (diff)
downloadandroid_development-c84455c11fdace9bc5c82aae99318bd9cd2480fa.tar.gz
android_development-c84455c11fdace9bc5c82aae99318bd9cd2480fa.tar.bz2
android_development-c84455c11fdace9bc5c82aae99318bd9cd2480fa.zip
Introduce sample for RoundedBitmapDrawable
Shows how to set an image to circular using the setCircular API. Change-Id: Ic65b9feb74942b6bd1c9debcf88fad5935df6d67
Diffstat (limited to 'samples/Support4Demos/src')
-rw-r--r--samples/Support4Demos/src/com/example/android/supportv4/graphics/RoundedBitmapDrawableActivity.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/samples/Support4Demos/src/com/example/android/supportv4/graphics/RoundedBitmapDrawableActivity.java b/samples/Support4Demos/src/com/example/android/supportv4/graphics/RoundedBitmapDrawableActivity.java
new file mode 100644
index 000000000..d89d4628b
--- /dev/null
+++ b/samples/Support4Demos/src/com/example/android/supportv4/graphics/RoundedBitmapDrawableActivity.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2015 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.supportv4.graphics;
+
+import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Bundle;
+import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
+import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
+import android.widget.CompoundButton;
+import android.widget.ImageView;
+import android.widget.ToggleButton;
+
+import com.example.android.supportv4.R;
+
+/**
+ * Demonstrates use of a {@link RoundedBitmapDrawable}'s ability to become circular.
+ */
+public class RoundedBitmapDrawableActivity extends Activity {
+
+ private static final int IMAGE_RES = R.drawable.android_robot;
+ private RoundedBitmapDrawable mRoundedBitmapDrawable;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_rounded_bitmap);
+
+ // Create a bitmap and set it circular.
+ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), IMAGE_RES);
+ mRoundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
+
+ // Get references to the inflated views.
+ ToggleButton toggle = (ToggleButton) findViewById(R.id.toggle_round);
+ ImageView image = (ImageView) findViewById(R.id.image);
+
+ // Set up initial view state and on checked change listener.
+ image.setImageDrawable(mRoundedBitmapDrawable);
+ toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ mRoundedBitmapDrawable.setCircular(isChecked);
+ }
+ });
+ }
+
+}