1 /* 2 * Copyright (C) 2017 The Android Open Source Project 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 17 package com.android.dialer.enrichedcall.simulator; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.support.annotation.NonNull; 23 import android.support.annotation.Nullable; 24 import android.support.v7.app.AppCompatActivity; 25 import android.support.v7.widget.LinearLayoutManager; 26 import android.support.v7.widget.RecyclerView; 27 import android.support.v7.widget.Toolbar; 28 import android.view.View; 29 import android.view.View.OnClickListener; 30 import android.widget.Button; 31 import com.android.dialer.common.Assert; 32 import com.android.dialer.common.LogUtil; 33 import com.android.dialer.enrichedcall.EnrichedCallComponent; 34 import com.android.dialer.enrichedcall.EnrichedCallManager; 35 import com.android.dialer.enrichedcall.EnrichedCallManager.StateChangedListener; 36 37 /** 38 * Activity used to display Enriched call sessions that are currently in memory, and create new 39 * outgoing sessions with various bits of data. 40 * 41 * <p>This activity will dynamically refresh as new sessions are added or updated, but there's no 42 * update when sessions are deleted from memory. Use the refresh button to update the view. 43 */ 44 public class EnrichedCallSimulatorActivity extends AppCompatActivity 45 implements StateChangedListener, OnClickListener { 46 newIntent(@onNull Context context)47 public static Intent newIntent(@NonNull Context context) { 48 return new Intent(Assert.isNotNull(context), EnrichedCallSimulatorActivity.class); 49 } 50 51 private Button refreshButton; 52 53 private SessionsAdapter sessionsAdapter; 54 55 @Override onCreate(@ullable Bundle bundle)56 protected void onCreate(@Nullable Bundle bundle) { 57 LogUtil.enterBlock("EnrichedCallSimulatorActivity.onCreate"); 58 super.onCreate(bundle); 59 setContentView(R.layout.enriched_call_simulator_activity); 60 Toolbar toolbar = findViewById(R.id.toolbar); 61 toolbar.setTitle(R.string.enriched_call_simulator_activity); 62 63 refreshButton = findViewById(R.id.refresh); 64 refreshButton.setOnClickListener(this); 65 66 RecyclerView recyclerView = findViewById(R.id.sessions_recycler_view); 67 recyclerView.setLayoutManager(new LinearLayoutManager(this)); 68 69 sessionsAdapter = new SessionsAdapter(); 70 sessionsAdapter.setSessionStrings(getEnrichedCallManager().getAllSessionsForDisplay()); 71 recyclerView.setAdapter(sessionsAdapter); 72 } 73 74 @Override onResume()75 protected void onResume() { 76 LogUtil.enterBlock("EnrichedCallSimulatorActivity.onResume"); 77 super.onResume(); 78 getEnrichedCallManager().registerStateChangedListener(this); 79 } 80 81 @Override onPause()82 protected void onPause() { 83 LogUtil.enterBlock("EnrichedCallSimulatorActivity.onPause"); 84 super.onPause(); 85 getEnrichedCallManager().unregisterStateChangedListener(this); 86 } 87 88 @Override onEnrichedCallStateChanged()89 public void onEnrichedCallStateChanged() { 90 LogUtil.enterBlock("EnrichedCallSimulatorActivity.onEnrichedCallStateChanged"); 91 refreshSessions(); 92 } 93 94 @Override onClick(View v)95 public void onClick(View v) { 96 if (v == refreshButton) { 97 LogUtil.i("EnrichedCallSimulatorActivity.onClick", "refreshing sessions"); 98 refreshSessions(); 99 } 100 } 101 refreshSessions()102 private void refreshSessions() { 103 sessionsAdapter.setSessionStrings(getEnrichedCallManager().getAllSessionsForDisplay()); 104 sessionsAdapter.notifyDataSetChanged(); 105 } 106 getEnrichedCallManager()107 private EnrichedCallManager getEnrichedCallManager() { 108 return EnrichedCallComponent.get(this).getEnrichedCallManager(); 109 } 110 } 111