Home | History | Annotate | Download | only in wearaccessibilityapp
      1 /*
      2  * Copyright (C) 2017 Google Inc. All Rights Reserved.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.example.android.wearable.wear.wearaccessibilityapp;
     17 
     18 import android.app.Activity;
     19 import android.os.Bundle;
     20 import android.support.wear.ambient.AmbientMode;
     21 import android.view.LayoutInflater;
     22 import android.view.View;
     23 import android.widget.AdapterView;
     24 import android.widget.ListView;
     25 import android.widget.TextView;
     26 
     27 import java.util.ArrayList;
     28 import java.util.List;
     29 
     30 public class ListsActivity extends Activity implements AmbientMode.AmbientCallbackProvider {
     31     private List<ListsItem> mItems;
     32 
     33     @Override
     34     protected void onCreate(Bundle savedInstanceState) {
     35         super.onCreate(savedInstanceState);
     36         setContentView(R.layout.activity_lists);
     37 
     38         AmbientMode.attachAmbientSupport(this);
     39 
     40         // Create a list of items for adapter to display.
     41         mItems = new ArrayList<>();
     42         mItems.add(new ListsItem(R.string.a_long_list, LongListActivity.class));
     43         mItems.add(new ListsItem(R.string.list_of_graphics, ListOfGraphicsActivity.class));
     44 
     45         // Initialize an adapter and set it to ListView listView.
     46         ListViewAdapter adapter = new ListViewAdapter(this, mItems);
     47         final ListView listView = findViewById(R.id.list_view_lists);
     48         listView.setAdapter(adapter);
     49 
     50         // Set header of listView to be the title from title_layout.
     51         LayoutInflater inflater = LayoutInflater.from(this);
     52         View titleLayout = inflater.inflate(R.layout.title_layout, null);
     53         TextView titleView = titleLayout.findViewById(R.id.title_text);
     54         titleView.setText(R.string.lists);
     55         titleView.setOnClickListener(null); // make title non-clickable.
     56 
     57         listView.addHeaderView(titleView);
     58 
     59         // Goes to a new screen when you click on one of the list items.
     60         // Dependent upon position of click.
     61         listView.setOnItemClickListener(
     62                 new AdapterView.OnItemClickListener() {
     63                     @Override
     64                     public void onItemClick(
     65                             AdapterView<?> parent, View view, int position, long id) {
     66                         mItems.get(position - listView.getHeaderViewsCount())
     67                                 .launchActivity(getApplicationContext());
     68                     }
     69                 });
     70     }
     71 
     72     @Override
     73     public AmbientMode.AmbientCallback getAmbientCallback() {
     74         return new MyAmbientCallback();
     75     }
     76 
     77     private class MyAmbientCallback extends AmbientMode.AmbientCallback {}
     78 }
     79