1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/*
* Copyright (C) 2013 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.android.dialer.calllog;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.ViewGroup;
import com.android.contacts.common.interactions.TouchPointManager;
import com.android.contacts.common.list.ViewPagerTabs;
import com.android.contacts.common.util.PermissionsUtil;
import com.android.contacts.commonbind.analytics.AnalyticsUtil;
import com.android.dialer.DialtactsActivity;
import com.android.dialer.R;
import com.android.dialer.voicemail.VoicemailStatusHelper;
import com.android.dialer.voicemail.VoicemailStatusHelperImpl;
public class CallLogActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
private ViewPager mViewPager;
private ViewPagerTabs mViewPagerTabs;
private ViewPagerAdapter mViewPagerAdapter;
private CallLogFragment mAllCallsFragment;
private CallLogFragment mMissedCallsFragment;
private String[] mTabTitles;
private static final int TAB_INDEX_ALL = 0;
private static final int TAB_INDEX_MISSED = 1;
private static final int TAB_INDEX_COUNT = 2;
private boolean mIsResumed;
public class ViewPagerAdapter extends FragmentPagerAdapter {
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case TAB_INDEX_ALL:
return new CallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL);
case TAB_INDEX_MISSED:
return new CallLogFragment(Calls.MISSED_TYPE);
}
throw new IllegalStateException("No fragment at position " + position);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
final CallLogFragment fragment =
(CallLogFragment) super.instantiateItem(container, position);
switch (position) {
case TAB_INDEX_ALL:
mAllCallsFragment = fragment;
break;
case TAB_INDEX_MISSED:
mMissedCallsFragment = fragment;
break;
}
return fragment;
}
@Override
public CharSequence getPageTitle(int position) {
return mTabTitles[position];
}
@Override
public int getCount() {
return TAB_INDEX_COUNT;
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
}
return super.dispatchTouchEvent(ev);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.call_log_activity);
getWindow().setBackgroundDrawable(null);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setElevation(0);
int startingTab = TAB_INDEX_ALL;
final Intent intent = getIntent();
if (intent != null) {
final int callType = intent.getIntExtra(CallLog.Calls.EXTRA_CALL_TYPE_FILTER, -1);
if (callType == CallLog.Calls.MISSED_TYPE) {
startingTab = TAB_INDEX_MISSED;
}
}
mTabTitles = new String[TAB_INDEX_COUNT];
mTabTitles[0] = getString(R.string.call_log_all_title);
mTabTitles[1] = getString(R.string.call_log_missed_title);
mViewPager = (ViewPager) findViewById(R.id.call_log_pager);
mViewPagerAdapter = new ViewPagerAdapter(getFragmentManager());
mViewPager.setAdapter(mViewPagerAdapter);
mViewPager.setOffscreenPageLimit(1);
mViewPager.setOnPageChangeListener(this);
mViewPagerTabs = (ViewPagerTabs) findViewById(R.id.viewpager_header);
mViewPagerTabs.setViewPager(mViewPager);
mViewPager.setCurrentItem(startingTab);
}
@Override
protected void onResume() {
mIsResumed = true;
super.onResume();
sendScreenViewForChildFragment(mViewPager.getCurrentItem());
}
@Override
protected void onPause() {
mIsResumed = false;
super.onPause();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
final MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.call_log_options, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
final MenuItem itemDeleteAll = menu.findItem(R.id.delete_all);
if (mAllCallsFragment != null && itemDeleteAll != null) {
// If onPrepareOptionsMenu is called before fragments are loaded, don't do anything.
final CallLogAdapter adapter = mAllCallsFragment.getAdapter();
itemDeleteAll.setVisible(adapter != null && !adapter.isEmpty());
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
final Intent intent = new Intent(this, DialtactsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
case R.id.delete_all:
ClearCallLogDialog.show(getFragmentManager());
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
mViewPagerTabs.onPageScrolled(position, positionOffset, positionOffsetPixels);
}
@Override
public void onPageSelected(int position) {
if (mIsResumed) {
sendScreenViewForChildFragment(position);
}
mViewPagerTabs.onPageSelected(position);
}
@Override
public void onPageScrollStateChanged(int state) {
mViewPagerTabs.onPageScrollStateChanged(state);
}
private void sendScreenViewForChildFragment(int position) {
AnalyticsUtil.sendScreenView(CallLogFragment.class.getSimpleName(), this,
getFragmentTagForPosition(position));
}
/**
* Returns the fragment located at the given position in the {@link ViewPagerAdapter}. May
* be null if the position is invalid.
*/
private String getFragmentTagForPosition(int position) {
switch (position) {
case TAB_INDEX_ALL:
return "All";
case TAB_INDEX_MISSED:
return "Missed";
}
return null;
}
}
|