Commit a178d272 authored by Alexandre Lision's avatar Alexandre Lision
Browse files

cleanup: remove unused resources

Tuleap: #1313
Change-Id: I0a852dd98ff678a72bd1ce0040bbe85a3805bf4c
parent c8741e1b
......@@ -151,11 +151,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:label="@string/app_name"
android:screenOrientation="fullUser"
android:theme="@style/AppThemeBase" />
<activity
android:name=".client.NewConversationActivity"
android:label="@string/app_name"
android:screenOrientation="fullUser"
android:theme="@style/AppThemeBase" />
<receiver android:name=".service.OutgoingCallHandler">
<intent-filter>
......
/*
* Copyright (C) 2004-2016 Savoir-faire Linux Inc.
*
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package cx.ring.adapters;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SectionIndexer;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import cx.ring.R;
import cx.ring.fragments.ContactListFragment;
import cx.ring.model.CallContact;
import cx.ring.utils.BitmapUtils;
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
public class ContactsAdapter extends BaseAdapter implements StickyListHeadersAdapter, SectionIndexer {
private final ExecutorService infosFetcher;
private final Context mContext;
private ArrayList<CallContact> mContacts;
private int[] mSectionIndices;
private Character[] mSectionLetters;
WeakReference<ContactListFragment.Callbacks> parent;
private LayoutInflater mInflater;
final private LruCache<Long, Bitmap> mMemoryCache;
private static final String TAG = ContactsAdapter.class.getSimpleName();
public ContactsAdapter(Context c, ContactListFragment.Callbacks cb, LruCache<Long, Bitmap> cache, ExecutorService pool) {
super();
mContext = c;
mInflater = LayoutInflater.from(mContext);
parent = new WeakReference<>(cb);
mContacts = new ArrayList<>();
mSectionIndices = getSectionIndices();
mSectionLetters = getSectionLetters();
mMemoryCache = cache;
infosFetcher = pool;
}
private int[] getSectionIndices() {
ArrayList<Integer> sectionIndices = new ArrayList<>(32);
if (mContacts.isEmpty()) {
return new int[0];
}
char lastFirstChar = Character.toUpperCase(mContacts.get(0).getDisplayName().charAt(0));
sectionIndices.add(0);
for (int i = 1; i < mContacts.size(); i++) {
char c = Character.toUpperCase(mContacts.get(i).getDisplayName().charAt(0));
if (c != lastFirstChar) {
lastFirstChar = c;
sectionIndices.add(i);
}
}
int[] sections = new int[sectionIndices.size()];
for (int i = 0; i < sectionIndices.size(); i++) {
sections[i] = sectionIndices.get(i);
}
return sections;
}
private Character[] getSectionLetters() {
Character[] letters = new Character[mSectionIndices.length];
for (int i = 0; i < mSectionIndices.length; i++) {
letters[i] = Character.toUpperCase(mContacts.get(mSectionIndices[i]).getDisplayName().charAt(0));
}
return letters;
}
@Override
public View getView(final int position, View convertView, ViewGroup root) {
ContactView entryView;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_contact, root, false);
entryView = new ContactView();
entryView.photo = (ImageView) convertView.findViewById(R.id.photo);
entryView.display_name = (TextView) convertView.findViewById(R.id.display_name);
entryView.quick_call = (ImageButton) convertView.findViewById(R.id.quick_call);
entryView.position = -1;
convertView.setTag(entryView);
} else {
entryView = (ContactView) convertView.getTag();
}
final CallContact item = mContacts.get(position);
if (entryView.contact != null && entryView.contact.get() != null && item.getId() == entryView.contact.get().getId()) {
return convertView;
}
entryView.display_name.setText(item.getDisplayName());
entryView.contact = new WeakReference<>(item);
entryView.position = position;
entryView.quick_call.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
parent.get().onCallContact(item);
}
});
final Long cid = item.getId();
final Long pid = item.getPhotoId();
Bitmap bmp = BitmapUtils.bytesToBitmap(item.getPhoto());
if (bmp == null) {
bmp = mMemoryCache.get(pid);
if (bmp != null) {
item.setPhoto(BitmapUtils.bitmapToBytes(bmp));
}
}
if (bmp != null) {
entryView.photo.setImageBitmap(bmp);
} else {
entryView.photo.setImageBitmap(null);
final WeakReference<ContactView> wh = new WeakReference<>(entryView);
infosFetcher.execute(new ContactDetailsTask(mContext, entryView.photo, null, item, new ContactDetailsTask.DetailsLoadedCallback() {
@Override
public void onDetailsLoaded(final Bitmap bmp, final String name) {
mMemoryCache.put(pid, bmp);
final ContactView fh = wh.get();
if (fh == null || fh.photo.getParent() == null) {
return;
}
if (fh.position == position)
fh.photo.post(new Runnable() {
@Override
public void run() {
final CallContact c = fh.contact.get();
if (c.getId() == cid) {
c.setPhoto(BitmapUtils.bitmapToBytes(bmp));
fh.photo.setImageBitmap(bmp);
fh.photo.startAnimation(AnimationUtils.loadAnimation(fh.photo.getContext(), R.anim.contact_fadein));
}
}
});
}
}));
}
return convertView;
}
/*********************
* ViewHolder Pattern
*********************/
public class ContactView {
ImageButton quick_call;
ImageView photo;
TextView display_name;
WeakReference<CallContact> contact = new WeakReference<>(null);
int position;
}
@Override
public int getCount() {
return mContacts.size();
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
HeaderViewHolder holder;
if (convertView == null) {
holder = new HeaderViewHolder();
convertView = mInflater.inflate(R.layout.header, parent, false);
holder.text = (TextView) convertView.findViewById(R.id.header_letter);
convertView.setTag(holder);
} else {
holder = (HeaderViewHolder) convertView.getTag();
}
// set header text as first char in name
holder.text.setText(String.valueOf(Character.toUpperCase(mContacts.get(position).getDisplayName().charAt(0))));
return convertView;
}
class HeaderViewHolder {
TextView text;
}
@Override
public long getHeaderId(int position) {
// return the first character of the name as ID because this is what
// headers are based upon
return Character.toUpperCase(mContacts.get(position).getDisplayName().charAt(0));
}
@Override
public int getPositionForSection(int section) {
if (section >= mSectionIndices.length) {
section = mSectionIndices.length - 1;
} else if (section < 0) {
section = 0;
}
return mSectionIndices[section];
}
@Override
public int getSectionForPosition(int position) {
for (int i = 0; i < mSectionIndices.length; i++) {
if (position < mSectionIndices[i]) {
return i - 1;
}
}
return mSectionIndices.length - 1;
}
@Override
public Object[] getSections() {
return mSectionLetters;
}
@Override
public CallContact getItem(int position) {
return mContacts.get(position);
}
public void clear() {
mContacts = new ArrayList<>();
mSectionIndices = new int[0];
mSectionLetters = new Character[0];
}
public void setData(ArrayList<CallContact> contacts) {
mContacts = contacts;
mSectionIndices = getSectionIndices();
mSectionLetters = getSectionLetters();
notifyDataSetChanged();
}
}
/*
* Copyright (C) 2004-2016 Savoir-faire Linux Inc.
*
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package cx.ring.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import cx.ring.R;
import cx.ring.model.CallContact;
import cx.ring.utils.BitmapUtils;
public class StarredContactsAdapter extends BaseAdapter {
private ExecutorService infos_fetcher = Executors.newCachedThreadPool();
private ArrayList<CallContact> dataset;
Context mContext;
// private static final String TAG = ContactsAdapter.class.getSimpleName();
public StarredContactsAdapter(Context context) {
super();
mContext = context;
dataset = new ArrayList<>();
}
public void setData(ArrayList<CallContact> contacts) {
dataset = contacts;
notifyDataSetChanged();
}
@Override
public int getCount() {
return dataset.size();
}
@Override
public CallContact getItem(int index) {
return dataset.get(index);
}
@Override
public long getItemId(int index) {
return dataset.get(index).getId();
}
@Override
public View getView(int pos, View convView, ViewGroup parent) {
View v = convView;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (v == null) {
v = inflater.inflate(R.layout.item_contact_starred, parent, false);
}
CallContact item = dataset.get(pos);
((TextView) v.findViewById(R.id.display_name)).setText(item.getDisplayName());
ImageView photo_view = (ImageView) v.findViewById(R.id.photo);
if (item.hasPhoto()) {
photo_view.setImageBitmap(BitmapUtils.bytesToBitmap(item.getPhoto()));
} else {
infos_fetcher.execute(new ContactDetailsTask(mContext, photo_view, item));
}
return v;
}
}
\ No newline at end of file
......@@ -66,7 +66,6 @@ import cx.ring.R;
import cx.ring.about.AboutFragment;
import cx.ring.application.RingApplication;
import cx.ring.fragments.AccountsManagementFragment;
import cx.ring.fragments.ContactListFragment;
import cx.ring.fragments.SmartListFragment;
import cx.ring.model.Account;
import cx.ring.model.CallContact;
......@@ -82,8 +81,7 @@ import cx.ring.utils.FileUtils;
public class HomeActivity extends AppCompatActivity implements LocalService.Callbacks,
RingNavigationFragment.OnNavigationSectionSelected,
ActivityCompat.OnRequestPermissionsResultCallback,
ContactListFragment.Callbacks {
ActivityCompat.OnRequestPermissionsResultCallback {
static final String TAG = HomeActivity.class.getSimpleName();
......@@ -649,7 +647,6 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
.addToBackStack(SETTINGS_TAG).commit();
}
@Override
public void onCallContact(final CallContact c) {
Log.d(TAG, "onCallContact " + c.toString() + " " + c.getId() + " " + c.getKey());
if (c.getPhones().size() > 1) {
......@@ -680,7 +677,6 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
}
}
@Override
public void onTextContact(final CallContact c) {
if (c.getPhones().size() > 1) {
final CharSequence numbers[] = new CharSequence[c.getPhones().size()];
......
package cx.ring.client;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.view.MenuItem;
import cx.ring.R;
import cx.ring.fragments.ContactListFragment;
import cx.ring.model.CallContact;
import cx.ring.model.Phone;
import cx.ring.service.IDRingService;
import cx.ring.service.LocalService;
import cx.ring.utils.ContentUriHandler;
public class NewConversationActivity extends Activity implements ContactListFragment.Callbacks {
private LocalService service = null;
//private SearchView searchView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent = new Intent(this, LocalService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
@Override
protected void onDestroy() {
super.onDestroy();
unbindService(mConnection);
}
private final ServiceConnection mConnection = new ServiceConnection() {
@SuppressWarnings("unchecked")
@Override
public void onServiceConnected(ComponentName className, IBinder binder) {
service = ((LocalService.LocalBinder) binder).getService();
setContentView(R.layout.activity_new_conversation);
}
@Override
public void onServiceDisconnected(ComponentName name) {
service = null;
}
};
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onCallContact(final CallContact c) {
if (c.getPhones().size() > 1) {
final CharSequence numbers[] = new CharSequence[c.getPhones().size()];
int i = 0;
for (Phone p : c.getPhones())
numbers[i++] = p.getNumber().getRawUriString();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.choose_number);
builder.setItems(numbers, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
CharSequence selected = numbers[which];
Intent intent = new Intent(CallActivity.ACTION_CALL)
.setClass(NewConversationActivity.this, CallActivity.class)
.setData(Uri.parse(selected.toString()));
startActivityForResult(intent, HomeActivity.REQUEST_CODE_CALL);
}
});
builder.show();
} else {
Intent intent = new Intent(CallActivity.ACTION_CALL)
.setClass(this, CallActivity.class)
.setData(Uri.parse(c.getPhones().get(0).getNumber().getRawUriString()));
startActivityForResult(intent, HomeActivity.REQUEST_CODE_CALL);
}
}
@Override
public void onTextContact(final CallContact c) {
if (c.getPhones().size() > 1) {
final CharSequence numbers[] = new CharSequence[c.getPhones().size()];
int i = 0;
for (Phone p : c.getPhones())
numbers[i++] = p.getNumber().getRawUriString();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.choose_number);
builder.setItems(numbers, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
CharSequence selected = numbers[which];
Intent intent = new Intent(Intent.ACTION_VIEW)
.setClass(NewConversationActivity.this, ConversationActivity.class)
.setData(Uri.withAppendedPath(ContentUriHandler.CONVERSATION_CONTENT_URI, c.getIds().get(0)))
.putExtra("number", selected);
startActivityForResult(intent, HomeActivity.REQUEST_CODE_CONVERSATION);
}
});
builder.show();
} else {
Intent intent = new Intent(Intent.ACTION_VIEW)
.setClass(this, ConversationActivity.class)
.setData(Uri.withAppendedPath(ContentUriHandler.CONVERSATION_CONTENT_URI, c.getIds().get(0)));
startActivityForResult(intent, HomeActivity.REQUEST_CODE_CONVERSATION);
}
}
@Override
public IDRingService getRemoteService() {
return service.getRemoteService();
}
@Override
public LocalService getService() {
return service;
}
}
/*
* Copyright (C) 2004-2016 Savoir-faire Linux Inc.
*
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
* Alexandre Lision <alexandre.lision@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License