If you think the Android project matrix-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.matrix.matrixandroidsdk.activity;
/*www.java2s.com*/import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import org.matrix.androidsdk.data.RoomState;
import org.matrix.androidsdk.rest.callback.SimpleApiCallback;
import org.matrix.androidsdk.rest.model.PublicRoom;
import org.matrix.matrixandroidsdk.ErrorListener;
import org.matrix.matrixandroidsdk.Matrix;
import org.matrix.matrixandroidsdk.R;
import org.matrix.matrixandroidsdk.adapters.RoomsAdapter;
import java.util.List;
/**
* Displays a list of available public rooms.
*/publicclass PublicRoomsActivity extends ActionBarActivity {
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_public_rooms);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final GridView publicRoomsGridView = (GridView) findViewById(R.id.gridView_publicRoomList);
final RoomsAdapter adapter = new RoomsAdapter(this, R.layout.adapter_item_public_rooms);
adapter.setAlternatingColours(0xFFFFFFFF, 0xFFEEEEEE);
publicRoomsGridView.setAdapter(adapter);
Matrix.getInstance(getApplicationContext()).getDefaultSession().getEventsApiClient().loadPublicRooms(new SimpleApiCallback<List<PublicRoom>>() {
@Override
publicvoid onSuccess(List<PublicRoom> publicRooms) {
for (PublicRoom publicRoom : publicRooms) {
adapter.add(publicRoom);
}
adapter.sortRooms();
}
});
publicRoomsGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
publicvoid onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
RoomState room = adapter.getItem(i);
String roomId = room.roomId;
goToRoom(roomId);
}
});
// The error listener needs the current activity
Matrix.getInstance(getApplicationContext()).getDefaultSession().setFailureCallback(new ErrorListener(this));
}
@Override
publicboolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.public_rooms, menu);
return true;
}
@Override
publicboolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (CommonActivityUtils.handleMenuItemSelected(this, id)) {
return true;
}
if (id == R.id.action_my_rooms) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
privatevoid goToRoom(String roomId) {
Intent intent = new Intent(this, RoomActivity.class);
intent.putExtra(RoomActivity.EXTRA_ROOM_ID, roomId);
startActivity(intent);
}
}