use of com.jaku.model.Channel in project RoMote by wseemann.
the class ChannelAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup container) {
// Now handle the main ImageView thumbnails
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
// if it's not recycled, instantiate and initialize
convertView = mInflater.inflate(R.layout.list_item_grid, null);
holder = new ViewHolder();
holder.mImageView = (ImageView) convertView.findViewById(android.R.id.icon);
holder.mText1 = (TextView) convertView.findViewById(android.R.id.text1);
// imageView = new RecyclingImageView(mContext);
holder.mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
holder.mImageView.setLayoutParams(mImageViewLayoutParams);
holder.mImageButton = (ImageView) convertView.findViewById(R.id.overflow_button);
convertView.setTag(holder);
} else {
// Otherwise re-use the converted view
holder = (ViewHolder) convertView.getTag();
}
// Check the height matches our calculated column width
if (holder.mImageView.getLayoutParams().height != mItemHeight) {
holder.mImageView.setLayoutParams(mImageViewLayoutParams);
}
final Channel channel = getItem(position);
holder.mText1.setText(channel.getTitle());
holder.mImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message message = mHandler.obtainMessage();
v.setTag(channel);
message.obj = v;
mHandler.sendMessage(message);
}
});
// Finally load the image asynchronously into the ImageView, this also takes care of
// setting a placeholder image while the background thread runs
mImageFetcher.loadImage(CommandHelper.getIconURL(mContext, channel.getId()), holder.mImageView);
return convertView;
}
use of com.jaku.model.Channel in project RoMote by wseemann.
the class ChannelFragment method showMenu.
private void showMenu(final View v) {
PopupMenu popup = new PopupMenu(getActivity(), v);
// This activity implements OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_share:
Channel channel = (Channel) v.getTag();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Install this Roku channel (" + channel.getTitle() + "):\n\n" + "http://romote/" + channel.getId() + "\n\n" + "Sent using RoMote.");
intent.setType("text/plain");
startActivity(intent);
return true;
default:
return false;
}
}
});
popup.inflate(R.menu.channel_menu);
popup.show();
}
use of com.jaku.model.Channel in project RoMote by wseemann.
the class ChannelFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_channels, container, false);
final GridView mGridView = (GridView) v.findViewById(android.R.id.list);
mSwiperefresh = (SwipeRefreshLayout) v.findViewById(R.id.swiperefresh);
mSwiperefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// This method performs the actual data-refresh operation.
// The method calls setRefreshing(false) when it's finished.
getLoaderManager().restartLoader(0, new Bundle(), ChannelFragment.this);
}
});
// View emptyView = v.findViewById(android.R.id.empty);
// mGridView.setEmptyView(emptyView);
mGridView.setAdapter(mAdapter);
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Channel channel = (Channel) parent.getItemAtPosition(position);
performLaunch(channel.getId());
}
});
mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
// Pause fetcher to ensure smoother scrolling when flinging
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
// Before Honeycomb pause image loading on scroll to help with performance
if (!Utils.hasHoneycomb()) {
mImageFetcher.setPauseWork(true);
}
} else {
mImageFetcher.setPauseWork(false);
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
// This listener is used to get the final width of the GridView and then calculate the
// number of columns and the width of each column. The width of each column is variable
// as the GridView has stretchMode=columnWidth. The column width is used to set the height
// of each view so we get nice square thumbnails.
mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
if (mAdapter.getNumColumns() == 0) {
final int numColumns = (int) Math.floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
if (numColumns > 0) {
final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
mAdapter.setNumColumns(numColumns);
mAdapter.setItemHeight(columnWidth);
if (BuildConfig.DEBUG) {
Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
}
if (Utils.hasJellyBean()) {
mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
}
}
});
return v;
}
use of com.jaku.model.Channel in project RoMote by wseemann.
the class NotificationService method sendStatusCommand.
private void sendStatusCommand() {
String url = CommandHelper.getDeviceURL(this);
QueryActiveAppRequest queryActiveAppRequest = new QueryActiveAppRequest(url);
JakuRequest request = new JakuRequest(queryActiveAppRequest, new AppsParser());
new RequestTask(request, new RequestCallback() {
@Override
public void requestResult(RokuRequestTypes rokuRequestType, RequestTask.Result result) {
List<Channel> channels = (List<Channel>) result.mResultValue;
if (channels.size() > 0) {
mChannel = channels.get(0);
getAppIcon(mChannel.getId());
}
}
@Override
public void onErrorResponse(RequestTask.Result result) {
Log.d(TAG, "That didn't work!");
}
}).execute(RokuRequestTypes.query_active_app);
}
use of com.jaku.model.Channel in project RoMote by wseemann.
the class RequestTask method doInBackground.
@Override
protected RequestTask.Result doInBackground(RokuRequestTypes... requestTypes) {
Result result = null;
if (!isCancelled() && requestTypes != null && requestTypes.length > 0) {
RokuRequestTypes requestType = requestTypes[0];
try {
if (requestType.equals(RokuRequestTypes.query_active_app)) {
JakuResponse response = request.send();
List<Channel> channels = (List<Channel>) response.getResponseData();
result = new Result(channels);
} else if (requestType.equals(RokuRequestTypes.query_device_info)) {
JakuResponse response = request.send();
Device device = (Device) response.getResponseData();
result = new Result(device);
} else if (requestType.equals(RokuRequestTypes.query_icon)) {
JakuResponse response = request.send();
byte[] data = ((ByteArrayOutputStream) response.getResponseData()).toByteArray();
result = new Result(data);
} else {
request.send();
}
} catch (Exception e) {
e.printStackTrace();
result = new Result(e);
}
}
return result;
}
Aggregations