Use WearableListView in Timer sample app.
Bug: 15864517 Change-Id: Ia56111457c2d74571e69a5a554d5755bb1c1b220
This commit is contained in:
@@ -3,14 +3,12 @@ apply plugin: 'android'
|
||||
android {
|
||||
compileSdkVersion 20
|
||||
buildToolsVersion '20'
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 20
|
||||
targetSdkVersion 20
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionName '1.0'
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
runProguard false
|
||||
@@ -20,5 +18,5 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "com.google.android.support:wearable:1.0.+"
|
||||
compile 'com.google.android.support:wearable:+'
|
||||
}
|
||||
|
||||
@@ -26,23 +26,23 @@ import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.provider.AlarmClock;
|
||||
import android.support.wearable.view.WearableListView;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.android.wearable.timer.util.Constants;
|
||||
import com.example.android.wearable.timer.util.TimerFormat;
|
||||
|
||||
/** This class sets a timer. */
|
||||
public class SetTimerActivity extends Activity implements AdapterView.OnItemClickListener {
|
||||
public class SetTimerActivity extends Activity implements WearableListView.ClickListener {
|
||||
|
||||
public static final int NUMBER_OF_TIMES = 10;
|
||||
public static final String TAG = "SetTimerActivity";
|
||||
|
||||
private ListViewItem[] mTimeOptions = new ListViewItem[NUMBER_OF_TIMES];
|
||||
private ListView mListView;
|
||||
private WearableListView mWearableListView;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -70,11 +70,9 @@ public class SetTimerActivity extends Activity implements AdapterView.OnItemClic
|
||||
setContentView(R.layout.timer_set_timer);
|
||||
|
||||
// Initialize a simple list of countdown time options.
|
||||
mListView = (ListView) findViewById(R.id.times_list_view);
|
||||
ArrayAdapter<ListViewItem> arrayAdapter = new ArrayAdapter<ListViewItem>(this,
|
||||
android.R.layout.simple_list_item_1, mTimeOptions);
|
||||
mListView.setAdapter(arrayAdapter);
|
||||
mListView.setOnItemClickListener(this);
|
||||
mWearableListView = (WearableListView) findViewById(R.id.times_list_view);
|
||||
mWearableListView.setAdapter(new TimerWearableListViewAdapter(this));
|
||||
mWearableListView.setClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,11 +96,15 @@ public class SetTimerActivity extends Activity implements AdapterView.OnItemClic
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
long duration = mTimeOptions[position].duration;
|
||||
public void onClick(WearableListView.ViewHolder holder) {
|
||||
long duration = mTimeOptions[holder.getPosition()].duration;
|
||||
setupTimer(duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopEmptyRegionClick() {
|
||||
}
|
||||
|
||||
private void registerWithAlarmManager(long duration) {
|
||||
// Get the alarm manager.
|
||||
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
@@ -184,4 +186,32 @@ public class SetTimerActivity extends Activity implements AdapterView.OnItemClic
|
||||
}
|
||||
}
|
||||
|
||||
private final class TimerWearableListViewAdapter extends WearableListView.Adapter {
|
||||
private final Context mContext;
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
private TimerWearableListViewAdapter(Context context) {
|
||||
mContext = context;
|
||||
mInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new WearableListView.ViewHolder(
|
||||
mInflater.inflate(R.layout.timer_list_item, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(WearableListView.ViewHolder holder, int position) {
|
||||
TextView view = (TextView) holder.itemView.findViewById(R.id.time_text);
|
||||
view.setText(mTimeOptions[position].label);
|
||||
holder.itemView.setTag(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return NUMBER_OF_TIMES;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.wearable.timer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.support.wearable.view.WearableListView;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class WearableListItemLayout extends LinearLayout implements WearableListView.Item {
|
||||
private final float mFadedTextAlpha;
|
||||
private final int mFadedCircleColor;
|
||||
private final int mChosenCircleColor;
|
||||
private ImageView mCircle;
|
||||
private float mScale;
|
||||
private TextView mName;
|
||||
|
||||
public WearableListItemLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public WearableListItemLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public WearableListItemLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
mFadedTextAlpha = getResources().getInteger(R.integer.action_text_faded_alpha) / 100f;
|
||||
mFadedCircleColor = getResources().getColor(R.color.wl_gray);
|
||||
mChosenCircleColor = getResources().getColor(R.color.wl_blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mCircle = (ImageView) findViewById(R.id.circle);
|
||||
mName = (TextView) findViewById(R.id.time_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProximityMinValue() {
|
||||
return 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProximityMaxValue() {
|
||||
return 1.6f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCurrentProximityValue() {
|
||||
return mScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScalingAnimatorValue(float scale) {
|
||||
mScale = scale;
|
||||
mCircle.setScaleX(scale);
|
||||
mCircle.setScaleY(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScaleUpStart() {
|
||||
mName.setAlpha(1f);
|
||||
((GradientDrawable) mCircle.getDrawable()).setColor(mChosenCircleColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScaleDownStart() {
|
||||
((GradientDrawable) mCircle.getDrawable()).setColor(mFadedCircleColor);
|
||||
mName.setAlpha(mFadedTextAlpha);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@color/wl_gray"/>
|
||||
</shape>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.example.android.wearable.timer.WearableListItemLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp">
|
||||
<ImageView
|
||||
android:id="@+id/circle"
|
||||
android:layout_height="20dp"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_width="20dp"
|
||||
android:src="@drawable/wl_circle"/>
|
||||
<TextView
|
||||
android:id="@+id/time_text"
|
||||
android:gravity="center_vertical|left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_height="match_parent"
|
||||
android:fontFamily="sans-serif-condensed-light"
|
||||
android:lineSpacingExtra="-4sp"
|
||||
android:textColor="@color/text_color"
|
||||
android:textSize="16sp"/>
|
||||
</com.example.android.wearable.timer.WearableListItemLayout>
|
||||
@@ -14,7 +14,10 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
<android.support.wearable.view.WearableListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/times_list_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/times_list_view" />
|
||||
android:scrollbars="none"
|
||||
android:dividerHeight="0dp" />
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="wl_blue">#2878ff</color>
|
||||
<color name="wl_gray">#c1c1c1</color>
|
||||
<color name="text_color">#434343</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="action_text_faded_alpha">40</integer>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user