Search in sources :

Example 1 with Channel

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;
}
Also used : Message(android.os.Message) LayoutInflater(android.view.LayoutInflater) Channel(com.jaku.model.Channel) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 2 with Channel

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();
}
Also used : Channel(com.jaku.model.Channel) MenuItem(android.view.MenuItem) Intent(android.content.Intent) PopupMenu(android.support.v7.widget.PopupMenu)

Example 3 with Channel

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;
}
Also used : Bundle(android.os.Bundle) Channel(com.jaku.model.Channel) AbsListView(android.widget.AbsListView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SuppressLint(android.annotation.SuppressLint) AdapterView(android.widget.AdapterView) GridView(android.widget.GridView) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi)

Example 4 with Channel

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);
}
Also used : RequestTask(wseemann.media.romote.tasks.RequestTask) RokuRequestTypes(wseemann.media.romote.utils.RokuRequestTypes) JakuRequest(com.jaku.core.JakuRequest) RequestCallback(wseemann.media.romote.tasks.RequestCallback) AppsParser(com.jaku.parser.AppsParser) Channel(com.jaku.model.Channel) QueryActiveAppRequest(com.jaku.request.QueryActiveAppRequest) List(java.util.List)

Example 5 with Channel

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;
}
Also used : RokuRequestTypes(wseemann.media.romote.utils.RokuRequestTypes) Device(com.jaku.model.Device) Channel(com.jaku.model.Channel) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JakuResponse(com.jaku.core.JakuResponse)

Aggregations

Channel (com.jaku.model.Channel)5 View (android.view.View)2 List (java.util.List)2 RokuRequestTypes (wseemann.media.romote.utils.RokuRequestTypes)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Message (android.os.Message)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 PopupMenu (android.support.v7.widget.PopupMenu)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 ViewTreeObserver (android.view.ViewTreeObserver)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 JakuRequest (com.jaku.core.JakuRequest)1