• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.dialer.calllog.ui;
17 
18 import android.app.Fragment;
19 import android.app.LoaderManager.LoaderCallbacks;
20 import android.content.Context;
21 import android.content.Loader;
22 import android.database.Cursor;
23 import android.os.Bundle;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.CursorAdapter;
28 import android.widget.ListView;
29 import android.widget.SimpleCursorAdapter;
30 import android.widget.TextView;
31 import com.android.dialer.calllog.CallLogComponent;
32 import com.android.dialer.calllog.CallLogFramework;
33 import com.android.dialer.calllog.CallLogFramework.CallLogUi;
34 import com.android.dialer.calllog.database.AnnotatedCallLog.Columns;
35 import com.android.dialer.common.LogUtil;
36 import java.text.SimpleDateFormat;
37 import java.util.Locale;
38 
39 /** The "new" call log fragment implementation, which is built on top of the annotated call log. */
40 public final class NewCallLogFragment extends Fragment
41     implements CallLogUi, LoaderCallbacks<Cursor> {
42 
43   private CursorAdapter cursorAdapter;
44 
NewCallLogFragment()45   public NewCallLogFragment() {
46     LogUtil.enterBlock("NewCallLogFragment.NewCallLogFragment");
47   }
48 
49   @Override
onCreate(Bundle state)50   public void onCreate(Bundle state) {
51     super.onCreate(state);
52 
53     LogUtil.enterBlock("NewCallLogFragment.onCreate");
54 
55     CallLogFramework callLogFramework = CallLogComponent.get(getContext()).callLogFramework();
56     callLogFramework.attachUi(this);
57   }
58 
59   @Override
onResume()60   public void onResume() {
61     super.onResume();
62 
63     LogUtil.enterBlock("NewCallLogFragment.onResume");
64 
65     CallLogFramework callLogFramework = CallLogComponent.get(getContext()).callLogFramework();
66     callLogFramework.attachUi(this);
67   }
68 
69   @Override
onPause()70   public void onPause() {
71     super.onPause();
72 
73     LogUtil.enterBlock("NewCallLogFragment.onPause");
74 
75     CallLogFramework callLogFramework = CallLogComponent.get(getContext()).callLogFramework();
76     callLogFramework.detachUi();
77   }
78 
79   @Override
onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)80   public View onCreateView(
81       LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
82     LogUtil.enterBlock("NewCallLogFragment.onCreateView");
83 
84     View view = inflater.inflate(R.layout.new_call_log_fragment, container, false);
85     ListView listView = (ListView) view.findViewById(R.id.list);
86 
87     this.cursorAdapter =
88         new MyCursorAdapter(
89             getContext(),
90             R.layout.new_call_log_entry,
91             null /* cursor */,
92             new String[] {Columns.TIMESTAMP, Columns.CONTACT_NAME},
93             new int[] {R.id.timestamp, R.id.contact_name},
94             0);
95     listView.setAdapter(cursorAdapter);
96 
97     getLoaderManager().initLoader(0, null, this);
98 
99     return view;
100   }
101 
102   @Override
invalidateUi()103   public void invalidateUi() {
104     LogUtil.enterBlock("NewCallLogFragment.invalidateUi");
105     // TODO: Implementation.
106   }
107 
108   @Override
onCreateLoader(int id, Bundle args)109   public Loader<Cursor> onCreateLoader(int id, Bundle args) {
110     // TODO: This is sort of weird, do we need to implement a content provider?
111     return new AnnotatedCallLogCursorLoader(getContext());
112   }
113 
114   @Override
onLoadFinished(Loader<Cursor> loader, Cursor newCursor)115   public void onLoadFinished(Loader<Cursor> loader, Cursor newCursor) {
116     cursorAdapter.swapCursor(newCursor);
117   }
118 
119   @Override
onLoaderReset(Loader<Cursor> loader)120   public void onLoaderReset(Loader<Cursor> loader) {
121     cursorAdapter.swapCursor(null);
122   }
123 
124   private static class MyCursorAdapter extends SimpleCursorAdapter {
125 
MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)126     MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
127       super(context, layout, c, from, to, flags);
128     }
129 
130     @Override
setViewText(TextView view, String text)131     public void setViewText(TextView view, String text) {
132       if (view.getId() == R.id.timestamp) {
133         text = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US).format(Long.valueOf(text));
134       }
135       view.setText(text);
136     }
137   }
138 }
139