mardi 4 août 2015

Cache Images with Volley

I'm trying to implement Image Caching into my app. The code i currently have regarding the images is below:

Network call to get images:

public void getImage(String url, final ImageView imageView) {

    System.out.println("Image Url is: " + url);
    ImageRequest requestImage = new ImageRequest(url, new Response.Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            imageView.setImageBitmap(response);
        }
    }, 0, 0, null, null);

    queue.add(requestImage);
}

How could I implement the caching? I have read a few articles on SO, but am not sure on how to implement it into my app?

Thanks for your help



via Chebli Mohamed

What is the best way to fetch data from site in android?

I want to develop an android app for a site. I have following options:

  1. A Native Android Application
  2. A HTML 5 rendered on the Web view built into a Native app
  3. Throw in some Responsive Design into the front-end of your Web-app with HTML 5 and JavaScript.

I don't have access to the database. The site is given, what I need to do is to fetch data from site and displays it with listview, textView and imageview. Here I think I have a few options too: 1. Use a parser 2. Use rss feed.

I am confused about these two options. Please suggest me any better idea.

P.S. : I know the question is too broad, and can be downvoted.



via Chebli Mohamed

Auto-moving image on drag listener

I set a drag listener to an ImageView in my app, but when I click it, I don't want it to center the image based on where I pressed. It does this:

http://ift.tt/1IjkGXw

Basically, if I press on bottom right of the image, it takes where I press as central point and moves image's center point on that exact location. But I don't want it to do that. If I press on bottom right , it shouldn't auto move itself and I can drag the image from that point. I don't think any code is necessary but just in case:

@Override
public boolean onDrag(View v, DragEvent event) {
    switch (event.getAction()) {
        // Signal for the start of drag and drop operation
        case DragEvent.ACTION_DRAG_STARTED: {
            // do nothing
            break;
        }
        // The drag point has entered the bounding box of the View
        case DragEvent.ACTION_DRAG_ENTERED: {
            // do nothing
            break;
        }
        // The user has moved the drag shadow outside the bounding box of the view
        case DragEvent.ACTION_DRAG_EXITED: {
            // do nothing
            break;
        }
        // Drag shadow has been released, the drag point is within the bounding box of the view
        case DragEvent.ACTION_DROP: {
            // Get the image and its position
            ImageView view = (ImageView) event.getLocalState();
            int position = (int) view.getTag(R.id.piece_position);

            /**
             * If it is dropped on the left pane, remove it from its parent and also
             * remove the bitmap at the position and notify the adapter.
             * Add it to the left pane and set the position.
             */
            if (v == puzzlePane) {
                ViewGroup viewgroup = (ViewGroup) view.getParent();
                viewgroup.removeView(view);

                if (position != -1) {
                    pieces.remove(position);
                    mAdapter.notifyDataSetChanged();
                }

                FrameLayout containView = (FrameLayout) v;
                containView.addView(view);
                view.setVisibility(View.VISIBLE);
                view.setTag(R.id.piece_state, "left");
                view.setTag(R.id.piece_position, -1);
                view.setOnLongClickListener(null);
                view.setOnTouchListener(mAdapter);
            } else {
                view.setVisibility(View.VISIBLE);
                view.setTag(R.id.piece_state, "right");
                view.setOnTouchListener(null);
                view.setOnLongClickListener(mAdapter);
            }

            Log.d(MyDragListener.class.getSimpleName(), view.getTag(R.id.piece_state) + "");

            view.setX(event.getX() - (view.getWidth() / 2));
            view.setY(event.getY() - (view.getHeight() / 2));

            break;
        }
        // The drag and drop operation has concluded
        case DragEvent.ACTION_DRAG_ENDED: {
            // do nothing
            break;
        }
    }
    return true;
}



via Chebli Mohamed

RecyclerView.Adapter get item position of my list

I have created a RecyclerView.Adapter and I want to fill a list.. so my problem now is I don't know how to implement the get position of my list.

below you can see my code:

public class RecyclerViewAdapter extends RecyclerView.Adapter {

List<Result> _contents;

public RecyclerViewAdapter(List<Result> contents) {
    this._contents = contents;
}


@Override
public int getItemCount() {
    return _contents.size();
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int position) {
    View view = null;
    view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.list_item_card_small, parent, false);

    Result tempResult = _contents.get(position);

    TextView temp = (TextView) view.findViewById(R.id.text_city_name);
    temp.setText(tempResult.getInfo().getCity().getName());

    return new RecyclerView.ViewHolder(view) {
    };
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

   }
}

so the function onCreateViewHolder doesn't get properly the id is always the same id.. how can I fix this or implement to get the right position of mi list?¿ What it´s happening now is the list has the right number of items but is always the same item, the fist one. I guess it´s something simple but I cant figure out how to implement it.

Thanks!!



via Chebli Mohamed

Android: Hmac SHA512 in java

I have the following code in php:

$binKey = pack("H*", $keyTest);
$hmac = strtoupper(hash_hmac($pbx_hash, $msg, $binKey));

How can i achieve the same in android (java).

I have tried few methods available for hmac sha512 but the result of php snippet is different from that of mine.

Thanks in advance



via Chebli Mohamed

notifyDataSetChanged method is not refreshing listview using updated data?

I am using an ArrayAdapter with filterable interface to implement search functionality in a listview.My code for adapter is following:

public class FlightsAdapter extends ArrayAdapter<Flight> implements Filterable {

    List<Flight> flightLists = new ArrayList<Flight>();
    private List<Flight> origFlightList;
    private Context context;
    Flight flight = null;

    public FlightsAdapter(Context context, int textViewResourceId,
            List<Flight> fLists) {
        super(context, textViewResourceId, fLists);
        this.context = context;
        this.flightLists = fLists;
    }

    public void updateFlightList(List<Flight> newData){
        this.flightLists.clear();
        this.flightLists = newData;

    }
public Filter getFilter() {
        return new Filter() {

            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
                final FilterResults oReturn = new FilterResults();
                final List<Flight> results = new ArrayList<Flight>();
                if (origFlightList == null)
                    origFlightList = flightLists;
                if (constraint != null) {
                    if (origFlightList != null && origFlightList.size() > 0) {
                        for (final Flight f : origFlightList) {
                            if (f.getPlace().toLowerCase()
                                    .contains(constraint.toString()))
                                results.add(f);
                        }
                    }
                    oReturn.values = results;
                    oReturn.count = results.size();
                }
                return oReturn;
            }

            @SuppressWarnings("unchecked")
            @Override
            protected void publishResults(CharSequence constraint,
                                          FilterResults results) {
                flightLists = (ArrayList<Flight>) results.values;
                notifyDataSetChanged();
            }
        };
    }

}

getFilter() and publishResults() methods get triggered properly on searching and flightLists get populated with new data but the listview remain same with no items change, I don't know what I am doing wrong in above code, Please help me figure out this problem



via Chebli Mohamed

Android TV Emulater is Blank. How can I see apps like Google Play Store and others?

I have started new Android TV Emulator. But it shows nothing except settings and search icon. I am unable to open even Google Play to add more apps.

enter image description here

enter image description here



via Chebli Mohamed