diff options
Diffstat (limited to 'accessibility/CheckableLayout/Application/src')
21 files changed, 310 insertions, 0 deletions
diff --git a/accessibility/CheckableLayout/Application/src/main/AndroidManifest.xml b/accessibility/CheckableLayout/Application/src/main/AndroidManifest.xml new file mode 100644 index 00000000..9488f0ab --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/AndroidManifest.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- + Copyright 2016 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.checkablelayout"> + + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:supportsRtl="true" + android:theme="@style/AppTheme"> + <activity android:name=".MainActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + +</manifest> diff --git a/accessibility/CheckableLayout/Application/src/main/java/com/example/android/checkablelayout/CheckableFrameLayout.java b/accessibility/CheckableLayout/Application/src/main/java/com/example/android/checkablelayout/CheckableFrameLayout.java new file mode 100644 index 00000000..52da5551 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/java/com/example/android/checkablelayout/CheckableFrameLayout.java @@ -0,0 +1,91 @@ +/* +* Copyright (C) 2016 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.checkablelayout; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.accessibility.AccessibilityEvent; +import android.view.accessibility.AccessibilityNodeInfo; +import android.widget.Checkable; +import android.widget.FrameLayout; + +/** + * Simple wrapper for {@link FrameLayout} that implements the {@link Checkable} + * interface. Keeps an internal 'checked' state flag. + */ +public class CheckableFrameLayout extends FrameLayout implements Checkable { + private static final int[] CHECKED_STATE_SET = { + android.R.attr.state_activated, + android.R.attr.state_checked, + }; + + private boolean mChecked; + + public CheckableFrameLayout(Context context) { + this(context, null, 0); + } + + public CheckableFrameLayout(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public CheckableFrameLayout(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + setFocusable(true); + } + + @Override + protected int[] onCreateDrawableState(int extraSpace) { + final int[] drawableState = super.onCreateDrawableState(extraSpace + 2); + if (mChecked) { + mergeDrawableStates(drawableState, CHECKED_STATE_SET); + } + return drawableState; + } + + @Override + public void setChecked(boolean checked) { + if (mChecked != checked) { + mChecked = checked; + sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); + refreshDrawableState(); + } + } + + @Override + public boolean isChecked() { + return mChecked; + } + + @Override + public void toggle() { + setChecked(!mChecked); + } + + @Override + public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(info); + info.setCheckable(true); + info.setChecked(isChecked()); + } + + @Override + public void onInitializeAccessibilityEvent(AccessibilityEvent event) { + super.onInitializeAccessibilityEvent(event); + event.setChecked(isChecked()); + } +}
\ No newline at end of file diff --git a/accessibility/CheckableLayout/Application/src/main/java/com/example/android/checkablelayout/MainActivity.java b/accessibility/CheckableLayout/Application/src/main/java/com/example/android/checkablelayout/MainActivity.java new file mode 100644 index 00000000..32b56495 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/java/com/example/android/checkablelayout/MainActivity.java @@ -0,0 +1,39 @@ +/* +* Copyright (C) 2016 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.checkablelayout; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; + +public class MainActivity extends AppCompatActivity { + + private CheckableFrameLayout mFrameLayout; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + mFrameLayout = (CheckableFrameLayout) findViewById(R.id.frame_layout); + mFrameLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mFrameLayout.toggle(); + } + }); + } +} diff --git a/accessibility/CheckableLayout/Application/src/main/res/drawable-hdpi/ic_done_green.png b/accessibility/CheckableLayout/Application/src/main/res/drawable-hdpi/ic_done_green.png Binary files differnew file mode 100755 index 00000000..9635fa5d --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/drawable-hdpi/ic_done_green.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/drawable-mdpi/ic_done_green.png b/accessibility/CheckableLayout/Application/src/main/res/drawable-mdpi/ic_done_green.png Binary files differnew file mode 100755 index 00000000..383d125c --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/drawable-mdpi/ic_done_green.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/drawable-xhdpi/ic_done_green.png b/accessibility/CheckableLayout/Application/src/main/res/drawable-xhdpi/ic_done_green.png Binary files differnew file mode 100755 index 00000000..9a50c661 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/drawable-xhdpi/ic_done_green.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/drawable-xxhdpi/ic_done_green.png b/accessibility/CheckableLayout/Application/src/main/res/drawable-xxhdpi/ic_done_green.png Binary files differnew file mode 100755 index 00000000..23d2a335 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/drawable-xxhdpi/ic_done_green.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/drawable-xxxhdpi/ic_done_green.png b/accessibility/CheckableLayout/Application/src/main/res/drawable-xxxhdpi/ic_done_green.png Binary files differnew file mode 100755 index 00000000..1f0c35ec --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/drawable-xxxhdpi/ic_done_green.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/drawable/birch_leaves.jpeg b/accessibility/CheckableLayout/Application/src/main/res/drawable/birch_leaves.jpeg Binary files differnew file mode 100644 index 00000000..3e7d8462 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/drawable/birch_leaves.jpeg diff --git a/accessibility/CheckableLayout/Application/src/main/res/drawable/ic_checkable_item.xml b/accessibility/CheckableLayout/Application/src/main/res/drawable/ic_checkable_item.xml new file mode 100644 index 00000000..9b9d0b01 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/drawable/ic_checkable_item.xml @@ -0,0 +1,15 @@ +<!-- + Copyright 2016 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. + --> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_checked="true" android:drawable="@drawable/ic_done_green" /> +</selector> diff --git a/accessibility/CheckableLayout/Application/src/main/res/layout/activity_main.xml b/accessibility/CheckableLayout/Application/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..18b0f4b3 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/layout/activity_main.xml @@ -0,0 +1,51 @@ +<!-- + Copyright 2016 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. + --> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + tools:context="com.example.android.checkablelayout.MainActivity"> + + + <com.example.android.checkablelayout.CheckableFrameLayout + android:id="@+id/frame_layout" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:focusable="true"> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:contentDescription="@string/birch_leaves" + android:scaleType="centerInside" + android:src="@drawable/birch_leaves" /> + + <!-- + This ImageView uses `android:duplicateParentState` and a drawable tied to + android:state_checked, causing the checked image to display only when the parent is checked. + --> + <ImageView + android:layout_width="@dimen/check_dimen" + android:layout_height="@dimen/check_dimen" + android:layout_gravity="center" + android:duplicateParentState="true" + android:src="@drawable/ic_checkable_item" /> + </com.example.android.checkablelayout.CheckableFrameLayout> + +</LinearLayout> diff --git a/accessibility/CheckableLayout/Application/src/main/res/mipmap-hdpi/ic_launcher.png b/accessibility/CheckableLayout/Application/src/main/res/mipmap-hdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..21c4e7b5 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/mipmap-mdpi/ic_launcher.png b/accessibility/CheckableLayout/Application/src/main/res/mipmap-mdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..28683887 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/mipmap-xhdpi/ic_launcher.png b/accessibility/CheckableLayout/Application/src/main/res/mipmap-xhdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..ffbc0df4 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png b/accessibility/CheckableLayout/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..3d016e54 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/accessibility/CheckableLayout/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png Binary files differnew file mode 100755 index 00000000..d7cedb6c --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/accessibility/CheckableLayout/Application/src/main/res/values-w820dp/dimens.xml b/accessibility/CheckableLayout/Application/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 00000000..146c0e15 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,3 @@ +<resources> + <dimen name="activity_horizontal_margin">64dp</dimen> +</resources> diff --git a/accessibility/CheckableLayout/Application/src/main/res/values/colors.xml b/accessibility/CheckableLayout/Application/src/main/res/values/colors.xml new file mode 100644 index 00000000..17f5a9f6 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/values/colors.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2016 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. + --> +<resources> + <color name="colorPrimary">#3F51B5</color> + <color name="colorPrimaryDark">#303F9F</color> + <color name="colorAccent">#FF4081</color> +</resources> diff --git a/accessibility/CheckableLayout/Application/src/main/res/values/dimens.xml b/accessibility/CheckableLayout/Application/src/main/res/values/dimens.xml new file mode 100644 index 00000000..b6e57b36 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/values/dimens.xml @@ -0,0 +1,19 @@ +<!-- + Copyright 2016 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. + --> +<resources> + <!-- Default screen margins, per the Android Design guidelines. --> + <dimen name="activity_horizontal_margin">16dp</dimen> + <dimen name="activity_vertical_margin">16dp</dimen> + + <dimen name="check_dimen">144dp</dimen> +</resources> diff --git a/accessibility/CheckableLayout/Application/src/main/res/values/strings.xml b/accessibility/CheckableLayout/Application/src/main/res/values/strings.xml new file mode 100644 index 00000000..76f9b95d --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/values/strings.xml @@ -0,0 +1,16 @@ +<!-- + Copyright 2016 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. + --> +<resources> + <string name="app_name">CheckableLayout</string> + <string name="birch_leaves">Birch leaves</string> +</resources> diff --git a/accessibility/CheckableLayout/Application/src/main/res/values/styles.xml b/accessibility/CheckableLayout/Application/src/main/res/values/styles.xml new file mode 100644 index 00000000..87edfaa7 --- /dev/null +++ b/accessibility/CheckableLayout/Application/src/main/res/values/styles.xml @@ -0,0 +1,21 @@ +<!-- + Copyright 2016 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. + --> +<resources> + + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="colorAccent">@color/colorAccent</item> + </style> + +</resources> |