Tuesday, 26 April 2016

API parsing MyClientPost For sending Image to server Part 3

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import util.Utils;

/** * This is used for post data from API. * * @author Mayank * @since 1.4 */public class MyClientPost extends AsyncTask<Map<String, Object>, String, String> {

    public ProgressDialog dialog;
    private String message;
    private Context context;
    private OnPostCallComplete onpostcallcomplete;
    private JSONObject jsonResult;

    public MyClientPost(Context context, String progressMessage, OnPostCallComplete onPostCallComplete2) {
        message = progressMessage;
        this.context = context;
        this.onpostcallcomplete = onPostCallComplete2;

        if (!(message.equals(""))) {
            dialog = new ProgressDialog(context);
            dialog.setMessage(progressMessage);
        }
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub        super.onPreExecute();
        if (!(message.equals(""))) {
            dialog.setCancelable(false);
            dialog.show();
        }
    }

    @Override
    protected String doInBackground(Map<String, Object>... params) {
        String result = null;

        if (!isCancelled()) {

            Map<String, Object> passed_params = params[0];
            // API call URL            String serverUrl = (String) passed_params.get("url");
            Log.v(Utils.TAG, "API url: " + serverUrl);
            // parameter data to send            @SuppressWarnings("unchecked")
            Map<String, String> methodParameter = (Map<String, String>) passed_params.get("method_parameters");
            try {
                HttpClient client = new DefaultHttpClient();
                HttpPost post = new HttpPost(serverUrl);

                Iterator<Entry<String, String>> iterator = methodParameter.entrySet().iterator();
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(methodParameter.size());
                while (iterator.hasNext()) {
                    Entry<String, String> param = iterator.next();
                    nameValuePairs.add(new BasicNameValuePair(param.getKey(), param.getValue()));
                }
                Log.v(Utils.TAG, "post latlng " + nameValuePairs.toString());
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nameValuePairs);
                post.setEntity(entity);
                HttpResponse response = client.execute(post);
                HttpEntity resp_entity = response.getEntity();
                result = EntityUtils.toString(resp_entity);
                // System.out.println("result in post 80: "+result);                if (response.getStatusLine().getStatusCode() != 200) {
                    Log.v(Utils.TAG, "post  status code " + response.getStatusLine().getStatusCode());
                    jsonResult = new JSONObject();
                    jsonResult.put("response_code", "9999");
                    jsonResult.put("response_message", "85 Server error occurred while processing request. Please try again.");
                    result = jsonResult.toString();
                    return result;
                }
            } catch (Exception e) {
                Log.v(Utils.TAG, "post exception " + e.getMessage());
                try {
                    jsonResult = new JSONObject();
                    jsonResult.put("response_code", "9999");
                    jsonResult.put("response_message", "94 Server error occurred while processing request. Please try again.");
                    result = jsonResult.toString();
                    return result;
                } catch (JSONException jsone) {
                    jsone.printStackTrace();
                }
            }
        }
        //System.out.println("result in post: "+result);        return result;
    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub        super.onPostExecute(result);
        if (!(message.equals(""))) {
            if (dialog != null) {
                dialog.hide();
                dialog.dismiss();
            }
        }
        System.out.println("result in onPostExecute: " + result);
        try {
            onpostcallcomplete.response(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public interface OnPostCallComplete {
        public void response(String result) throws JSONException;
    }
}

Download Jar files from here.

https://drive.google.com/file/d/0B53Ze24TLSktWjQyeE9tbF9JVkk/view?usp=sharing

https://drive.google.com/file/d/0B53Ze24TLSktZGtFVzRQdFBvbFE/view?usp=sharing

https://drive.google.com/file/d/0B53Ze24TLSktck9JZDd5YkhoOW8/view?usp=sharing

Picasso: https://drive.google.com/file/d/0B53Ze24TLSktb1lzWmRFeUxEaXM/view?usp=sharing


Call from activity

        Map<String, String> get_params = new HashMap<String, String>();
        get_params .put("type", type);
        Map<String, Object> api_params = new HashMap<String, Object>();
        api_params.put("url", getResources().getString(URL, Utils.getAPIAccessKey(context), Utils.getUserAccessKey(context)));
        api_params.put("method_parameters", get_params );
        System.out.println(api_params.values().toString());
        MyClientPost posting = new MyClientPost(context, "Please wait", onGetCallComplete);
        posting.execute(api_params);
MyClientPost.OnPostCallComplete onGetCallComplete = new MyClientPost.OnPostCallComplete() { @Override public void response(String result) { try {  JSONObject jobj = new JSONObject(result);
String response_code = jobj.getString("response_code"); if (response_code.equals(getResources().getString(R.string.success_code))) { JSONArray userContacts = jobj.getJSONArray("arrayname");
for (int i = 0; i < arrayname.length(); i++) {
} } } } catch (JSONException e) { e.printStackTrace(); } } };

API parsing MyClientGet For sending Image to server Part 2

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

import util.Utils;


/** * This is used for get data from API. * * @author Mayank * @since 1.4 */public class MyClientGet extends AsyncTask<String, String, String> {

    private ProgressDialog dialog;
    private String message;
    private Context context;
    private OnGetCallComplete ongetcallcomplete;

    public MyClientGet(Context ctx, String progressMessage, OnGetCallComplete onGetCallComplete) {
        message = progressMessage;
        this.context = ctx;
        this.ongetcallcomplete = onGetCallComplete;
        if (!(message.equals(""))) {
            dialog = new ProgressDialog(ctx);
            dialog.setMessage(progressMessage);
        }
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub        super.onPreExecute();
        if (!(message.equals(""))) {
            dialog.setCancelable(false);
            dialog.show();
        }
    }

    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub        String result = null;
        if (!isCancelled()) {
            String serverurl = params[0];
            result = Utils.NetworkOperation(serverurl);
        }
        return result;
    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub        super.onPostExecute(result);
        if (!(message.equals(""))) {
            if (dialog != null) {
                dialog.hide();
                dialog.dismiss();
            }
        }
        ongetcallcomplete.response(result);
    }

    protected void onProgressUpdate(String... progress) {
    }

    public interface OnGetCallComplete {
        public void response(String result);
    }
}

 MyClientGet myclientget = new MyClientGet(context, "", onAccessKeyCallComplete);
        myclientget.execute(getResources().getString(URL, "param"));


/**
     * Get AccessKey call Done.
     */
    MyClientGet.OnGetCallComplete onAccessKeyCallComplete = new MyClientGet.OnGetCallComplete() {
        @Override
        public void response(String result) {
            try {
               
                jobj = new JSONObject(result);
                String response_code = jobj.getString("response_code");
                if (response_code.equals(getResources().getString(R.string.success_code))) {
                    
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    };

API parsing MyClientMultipartPost For sending Image to server Part 1

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/** * This is used for post data from API. * * @author Mayank * @since 1.4 */public class MyClientMultipartPost extends AsyncTask<Void, Void, Void> {

    private final String ApiLink;
    private final MultipartEntity multipartentity;
    public ProgressDialog dialog;
    private String message;
    private Context context;
    private OnPostCallComplete onpostcallcomplete;
    private JSONObject jsonResult;
    private String json;

    public MyClientMultipartPost(Context context, String progressMessage,
                                 OnPostCallComplete onPostCallComplete2, String ApiLink,
                                 MultipartEntity multipartentity) {
        message = progressMessage;
        this.context = context;
        this.ApiLink = ApiLink;
        this.multipartentity = multipartentity;
        this.onpostcallcomplete = onPostCallComplete2;

        if (!(message.equals(""))) {
            dialog = new ProgressDialog(context);
            dialog.setMessage(progressMessage);
        }
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub        super.onPreExecute();
        if (!(message.equals(""))) {
            dialog.setCancelable(false);
            dialog.show();
        }
    }

    @Override
    protected Void doInBackground(Void... params) {
        String result = null;

        if (!isCancelled()) {

            InputStream is = null;
            JSONObject jObj = null;

//            Utils.Log(getClass().getSimpleName(), "Url : " + ApiLink + " Params : " + multipartentity.toString());            System.out.println("create poll data " + ApiLink);
            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpContext localContext = new BasicHttpContext();
                HttpPost httppost = new HttpPost(ApiLink);
                httppost.setEntity(multipartentity);

                HttpResponse response = httpclient.execute(httppost, localContext);
                if (response == null) {

                } else {
                    HttpEntity entity = response.getEntity();
                    is = entity.getContent();

                    // Log.e("log_tag", ""+is.toString());                }
            } catch (Exception e) {
                e.printStackTrace();
                // Log.e("log_tag", "Error in http connection " + e.toString());            }

            // convert response to string            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();
                json = sb.toString();
                Log.i("res", json);
            } catch (Exception e) {
                // Log.e("log_tag", "Error converting result " + e.toString());                e.printStackTrace();
            }
        }
        //System.out.println("result in post: "+result);        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub        super.onPostExecute(result);
        if (!(message.equals(""))) {
            if (dialog != null) {
                dialog.hide();
                dialog.dismiss();
            }
        }
        System.out.println("result in onPostExecute: " + result);
        try {
            onpostcallcomplete.response(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public interface OnPostCallComplete {
        public void response(String result) throws JSONException;
    }
}

Tuesday, 16 September 2014

Material Design Animation

This document is a preview.


Authentic Motion



Perceiving an object's tangible form helps us understand how to manipulate it. Observing an object's motion tells us whether it is light or heavy, flexible or rigid, small or large. Motion in the world of material design is not only beautiful, it builds meaning about the spatial relationships, functionality, and intention of the system.


Mass and Weight

Physical objects have mass and move only when forces are applied to them. Consequently, objects can’t start or stop instantaneously. Animation with abrupt starts and stops or rapid changes in direction appears unnatural and can be an unexpected and unpleasant disruption for the user.

Best Practices

A critical aspect of motion for material design is to retain the feeling of physicality without sacrificing elegance, simplicity, beauty, and the magic of a seamless user experience. Here are some guidelines to help translate these concepts into animations.

Motion with swift acceleration and gentle deceleration feels natural and delightful.


Linear motion feels mechanical. An abrupt change in velocity at both the beginning and end of the animation curve means the object instantaneously starts and stops, which is unrealistic.

Special Cases: Entering and Exiting Frame

When an object enters the frame, ensure it's moving at its peak velocity. This behavior emulates natural movement: a person entering the frame of vision does not begin walking at the edge of the frame but well before it. Similarly, when an object exits the frame, have it maintain its velocity, rather than slowing down as it exits the frame. Easing in when entering and slowing down when exiting draw the user's attention to that motion, which, in most cases, isn't the effect you want.

Enter and exit frame at peak velocity. The ball enters and exits frame at peak velocity, creating a confident transit
Speed up when entering or slow down when exiting. Don’t distract the user with unnecessary changes in velocity.

Making adjustments

Not all objects move the same way. Lighter/smaller objects may accelerate or decelerate faster, because they have less mass and require less force to do so. Larger/heavier objects may need more time to reach peak speed and come to rest. Think about how this applies to the various UI elements in your app and consider how their motion should be represented.

Material Design

This document is a preview.



Introduction













We challenged ourselves to create a visual language for our users that synthesizes the classic principles of good design with the innovation and possibility of technology and science. This is material design. This spec is a living document that will be updated as we continue to develop the tenets and specifics of material design.


Goals


Create a visual language that synthesizes classic principles of good design with the innovation and possibility of technology and science.


Develop a single underlying system that allows for a unified experience across platforms and device sizes. Mobile precepts are fundamental, but touch, voice, mouse, and keyboard are all first-class input methods.

Principles



Material is the metaphor

A material metaphor is the unifying theory of a rationalized space and a system of motion. The material is grounded in tactile reality, inspired by the study of paper and ink, yet technologically advanced and open to imagination and magic.

Surfaces and edges of the material provide visual cues that are grounded in reality. The use of familiar tactile attributes helps users quickly understand affordances. Yet the flexibility of the material creates new affordances that supercede those in the physical world, without breaking the rules of physics.

The fundamentals of light, surface, and movement are key to conveying how objects move, interact, and exist in space in relation to each other. Realistic lighting shows seams, divides space, and indicates moving parts.
Bold, graphic, intentional

The foundational elements of print-based design—typography, grids, space, scale, color, and use of imagery—guide visual treatments. These elements do far more than please the eye; they create hierarchy, meaning, and focus. Deliberate color choices, edge-to-edge imagery, large-scale typography, and intentional white space create a bold and graphic interface that immerses the user in the experience.

An emphasis on user actions makes core functionality immediately apparent and provides waypoints for the user.
Motion provides meaning

Motion respects and reinforces the user as the prime mover. Primary user actions are inflection points that initiate motion, transforming the whole design.

All action takes place in a single environment. Objects are presented to the user without breaking the continuity of experience even as they transform and reorganize.

Motion is meaningful and appropriate, serving to focus attention and maintain continuity. Feedback is subtle yet clear. Transitions are efficient yet coherent.