Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Commit

Permalink
Open option in context menu is working, also wavelist shows unreaded …
Browse files Browse the repository at this point in the history
…messages.
  • Loading branch information
Santiago Martinez committed Jul 30, 2010
1 parent 205f97d commit 6d868ac
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 94 deletions.
2 changes: 1 addition & 1 deletion android-gui/AndroidManifest.xml
Expand Up @@ -3,7 +3,7 @@
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="3" />
<application android:label="@string/app_name"
android:name="OneWave" android:icon="@drawable/wave_icon">
android:name="OneWave" android:icon="@drawable/wave_icon" android:debuggable="true">
<activity android:label="@string/app_name"
android:launchMode="singleInstance" android:name="OAuthRedirect">
<intent-filter>
Expand Down
11 changes: 9 additions & 2 deletions android-gui/res/layout/wavelist.xml
Expand Up @@ -24,17 +24,24 @@
android:gravity="center_vertical"
android:ellipsize="marquee"
android:singleLine="true"
android:textStyle="bold"
android:id="@+id/titleWave" />
<TextView android:id="@+id/participants"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textSize="10px"
android:layout_height="0dip"
android:gravity="center_vertical"
android:ellipsize="marquee"
android:singleLine="true"/>


</LinearLayout>
<TextView android:text="@+id/unread"
android:id="@+id/unread"
android:textStyle="bold"
android:paddingRight="2px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</LinearLayout>
<ImageView android:id="@+id/throbber"
android:layout_width="wrap_content"
Expand Down
186 changes: 95 additions & 91 deletions android-gui/src/net/processone/awc/WaveList.java
Expand Up @@ -12,7 +12,6 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
Expand All @@ -33,15 +32,15 @@
import com.google.wave.api.SearchResult.Digest;

public class WaveList extends ListActivity {

private static final String TAG = WaveList.class.getSimpleName();

private static final int PROGRESS_DIALOG = 0;

/**
* Number of waves to retrieve in each batch. Value 20.
*/
private static final int BATCH_SIZE = 20;
private static final int BATCH_SIZE = 20;

private OneWave ow;

Expand All @@ -54,64 +53,67 @@ public class WaveList extends ListActivity {
* UI.
*/
private Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ow = (OneWave) getApplication();

showDialog(PROGRESS_DIALOG);

this.registerForContextMenu(getListView()); // context menu, activated by long pressing

this.registerForContextMenu(getListView()); // context menu, activated
// by long pressing
handler = new Handler() {
public void handleMessage(Message msg) {
dismissDialog(PROGRESS_DIALOG);
ArrayList<Digest> waveList = (ArrayList<Digest>) msg.obj;
ArrayList<Digest> waveList = (ArrayList<Digest>) msg.obj;
if (waveList.size() < BATCH_SIZE) {
// It must be an ArrayList.
setListAdapter(new WaveAdapter(WaveList.this, waveList));
} else {
// It must be an ArrayList.
setListAdapter(new WaveAsyncAdapter(waveList));
setListAdapter(new WaveAsyncAdapter(waveList));
}
}
};
}

/**
* This is for creating context menu of the items in the wave list.
* remove form inbox, show, reply? etc.
* This is for creating context menu of the items in the wave list. remove
* form inbox, show, reply? etc.
*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.wave_context_menu, menu);
Log.i(TAG, menuInfo.getClass().toString());
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.wave_context_menu, menu);
Log.i(TAG, menuInfo.getClass().toString());
}

/**
* User selects one option of the conext menu
*/
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.itemFollowWave:
return true;
case R.id.itemRemoveFromInbox:
return true;
case R.id.itemMarkAsRead:
return true;
case R.id.itemView:
return true;
default:
return super.onContextItemSelected(item);
}
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
switch (item.getItemId()) {
case R.id.itemFollowWave:
return true;
case R.id.itemRemoveFromInbox:
return true;
case R.id.itemMarkAsRead:
return true;
case R.id.itemView:
onListItemClick(getListView(), info.targetView, info.position,
info.id);
return true;
default:
return super.onContextItemSelected(item);
}

}

@Override
protected void onResume() {
super.onResume();
Expand All @@ -136,13 +138,13 @@ protected void onListItemClick(ListView listView, View view, int position,
long id) {
Digest wave = (Digest) listView.getItemAtPosition(position);
String waveId = wave.getWaveId();

Intent i = new Intent(this, WaveletList.class);
i.putExtra("waveId", waveId);

startActivity(i);
}

/**
* Background task to retrieve all Waves.
*/
Expand All @@ -152,12 +154,12 @@ public void run() {
SearchResult r = ow.search("in:inbox", 0, BATCH_SIZE);
// It must be an ArrayList, to be able to use it in the ArrayAdapter
ArrayList<Digest> waveList = new ArrayList<Digest>(r.getDigests());

Message msg = handler.obtainMessage();
msg.obj = waveList;
msg.obj = waveList;
Log.i(TAG, "Reported num of results:" + r.getNumResults());
Log.i(TAG, "Retrieved results:" + r.getDigests().size());

handler.sendMessage(msg);
}
}
Expand All @@ -170,68 +172,67 @@ public static class WaveAdapter extends ArrayAdapter<Digest> {

public WaveAdapter(Context c, ArrayList<Digest> list) {
// Second parameter won't be used, we redefine getView.
super(c,0, list);
super(c, 0, list);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;

if (convertView == null) {
// Make up a new view
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.wavelist, null);
} else {
// Use convertView if it is available.
view = convertView;
convertView = inflater.inflate(R.layout.wavelist, null);
}

Digest wave = getItem(position);

// wave.getLastModified();
// wave.getSnippet();
// <- may be a good idea is to put that info, that we already had
// available to the user in some way, altough no idea how, we
// don't have much space.

TextView title = (TextView) view.findViewById(R.id.titleWave);

if (wave.getUnreadCount() > 0) {
//Has new content,
title.setText((Html.fromHtml("<strong>" + wave.getTitle() + "</strong>")));
} else {
title.setText(wave.getTitle());
}
TextView participants = (TextView) view.findViewById(R.id.participants);
StringBuilder b = new StringBuilder("<small>");
// wave.getSnippet();
// <- may be a good idea is to put that info, that we already had
// available to the user in some way, altough no idea how, we
// don't have much space.

TextView title = (TextView) convertView
.findViewById(R.id.titleWave);
title.setText(wave.getTitle());

TextView unread = (TextView) convertView.findViewById(R.id.unread);

int unreadCount = wave.getUnreadCount();

unread.setVisibility(unreadCount == 0 ? View.INVISIBLE
: View.VISIBLE);

unread.setText(String.valueOf(unreadCount));

TextView participants = (TextView) convertView
.findViewById(R.id.participants);
StringBuilder b = new StringBuilder();
Iterator<String> it = wave.getParticipants().iterator();
while(it.hasNext()) { //keep only the username
while (it.hasNext()) { // keep only the username
String contact = it.next();
int i = contact.indexOf("@");
if (i >= 0) {
contact = contact.substring(0, i);
}
b.append(contact);
String[] splited = contact.split("@");
b.append(splited[0]);
if (it.hasNext())
b.append(",");
b.append(", ");
}

participants.setText(Html.fromHtml(b.append("</small>").toString()) );

return view;
participants.setText(b.toString());

return convertView;
}
}

class WaveAsyncAdapter extends EndlessAdapter {
private RotateAnimation rotate=null;
private RotateAnimation rotate = null;

private List<Digest> waveCache;

public WaveAsyncAdapter(ArrayList<Digest> list) {
super(new WaveAdapter(WaveList.this, list));
rotate = new RotateAnimation(0f, 360f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(600);
rotate.setRepeatMode(Animation.RESTART);
rotate.setRepeatCount(Animation.INFINITE);
Expand All @@ -248,41 +249,44 @@ protected void appendCachedData() {
}

@Override
/**
* Note that this is executed in a separate thread, we don't need to spawn it ourselves
/*
* Note that this is executed in a separate thread, we don't need to
* spawn it ourselves
*/
protected boolean cacheInBackground() {
int newIndex = this.getWrappedAdapter().getCount();
Log.i(TAG, "New Index to query for: " + newIndex);

SearchResult r = ow.search("in:inbox", newIndex, BATCH_SIZE);
waveCache = r.getDigests();
Log.i(TAG, "Reported num of results:" + r.getNumResults());
Log.i(TAG, "Retrieved results:" + r.getDigests().size());
// If there were less returned, then no more messages exists.
return(r.getNumResults() == BATCH_SIZE);
return (r.getNumResults() == BATCH_SIZE);
}

@Override
protected View getPendingView(ViewGroup parent) {
View row=getLayoutInflater().inflate(R.layout.wavelist, null);
//View child=row.findViewById(R.id.titleWave);
View child=row.findViewById(R.id.waveItemRow);
View row = getLayoutInflater().inflate(R.layout.wavelist, null);
// View child=row.findViewById(R.id.titleWave);
View child = row.findViewById(R.id.waveItemRow);
child.setVisibility(View.GONE);
child=row.findViewById(R.id.throbber);
child = row.findViewById(R.id.throbber);
child.setVisibility(View.VISIBLE);
child.startAnimation(rotate);
return(row);
return (row);
}

@Override
protected void rebindPendingView(int position, View row) {
View child=row.findViewById(R.id.titleWave);
View child = row.findViewById(R.id.titleWave);
child.setVisibility(View.VISIBLE);
//MMM... this is probably wrong.. but didn't manage to test it. Probably it must be
// MMM... this is probably wrong.. but didn't manage to test it.
// Probably it must be
// analog to what WaveAdapter do with his view
((TextView)child).setText(getWrappedAdapter().getItem(position).toString());
child=row.findViewById(R.id.throbber);
((TextView) child).setText(getWrappedAdapter().getItem(position)
.toString());
child = row.findViewById(R.id.throbber);
child.setVisibility(View.GONE);
child.clearAnimation();
}
Expand Down

0 comments on commit 6d868ac

Please sign in to comment.