Example usage for android.os Message Message

List of usage examples for android.os Message Message

Introduction

In this page you can find the example usage for android.os Message Message.

Prototype

public Message() 

Source Link

Document

Constructor (but the preferred way to get a Message is to call #obtain() Message.obtain() ).

Usage

From source file:eu.liveandgov.ar.core.ARViewFragment.java

/** Create MetaioSDK, handler for startCamera, ScreenshotCapture for IBS*  */
@Override//from  ww  w. j ava  2s. com
public void onCreate(Bundle savedInstanceState) {
    deb("ARViewFragment", "onCreate ARViewFragment");

    super.onCreate(savedInstanceState);

    metaioSDK = null;
    mGLSurfaceView = null;
    mRendererInitialized = false;

    ctxL = getTheContext();

    // ----------- Asynchronous start stop camera -----------------------
    handlerCamera = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.arg1 == 1)
                startCamera();
            super.handleMessage(msg);
        }
    };

    try {
        mSensors = new SensorsComponentAndroid(ctxL);

        metaioSDK = MetaioSDK.CreateMetaioSDKAndroid(ctxL,
                getResources().getString(R.string.metaioSDKSignature));
        metaioSDK.registerSensorsComponent(mSensors);
        mSensors.start(SensorsComponentAndroid.SENSOR_ALL);

        metaioSDK.registerCallback(new IMetaioSDKCallback() {

            /* (non-Javadoc)
             * @see com.metaio.sdk.jni.IMetaioSDKCallback#onTrackingEvent(com.metaio.sdk.jni.TrackingValuesVector)
             */
            @Override
            public void onTrackingEvent(TrackingValuesVector trackingValues) {
                //for (int i=0; i<trackingValues.size(); i++){
                if (trackingValues.get(0).getState() == com.metaio.sdk.jni.ETRACKING_STATE.ETS_LOST) {
                    ctxL.sendBroadcast(
                            new Intent("android.intent.action.MAIN").putExtra("ImageLost", "confirm"));
                } else if (trackingValues.get(0).getState() == com.metaio.sdk.jni.ETRACKING_STATE.ETS_FOUND) {
                    ctxL.sendBroadcast(new Intent("android.intent.action.MAIN").putExtra("ImageFound",
                            trackingValues.get(0).getCosName()));
                }
                //}

                super.onTrackingEvent(trackingValues);
            }

            @Override
            public void onSDKReady() {
                super.onSDKReady();
                // ----------- Asynchronous start camera -----------------------
                Message msg = new Message();
                msg.arg1 = 1;
                handlerCamera.sendMessage(msg);
            }

            /* (non-Javadoc)
             * @see com.metaio.sdk.jni.IMetaioSDKCallback#onCameraImageSaved(java.lang.String)
             */
            @Override
            public void onScreenshotSaved(String filepath) {

                try {
                    // convert to 4:3 ratio or 3:4. Otherwise service not working at all!
                    FileInputStream streamIn;
                    streamIn = new FileInputStream(filepath);
                    Bitmap bitmap = BitmapFactory.decodeStream(streamIn);

                    int w, h;
                    if (bitmap.getHeight() > bitmap.getWidth()) {
                        h = 640;
                        w = 480;
                    } else {
                        w = 640;
                        h = 480;
                    }
                    bitmap = Bitmap.createScaledBitmap(bitmap, w, h, false);

                    FileOutputStream out = new FileOutputStream(filepath);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 95, out);
                    out.close();
                    // Recognize now
                    new AsyncTask_ImRec(filepath, "5", ctxL).execute();
                } catch (Exception e) {

                }

            };
        });
    } catch (Exception e) {
        Log.e("CARF", "ARViewActivity.onCreate: failed to create or intialize metaio SDK: " + e.getMessage());
    }
}

From source file:com.insthub.O2OMobile.Activity.B0_SigninActivity.java

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (url.endsWith(ApiInterface.USER_SIGNIN)) {
        usersigninResponse usersigninResponse = new usersigninResponse();
        usersigninResponse.fromJson(jo);
        if (usersigninResponse.succeed == 1) {
            Message msg = new Message();
            msg.what = MessageConstant.SIGN_IN_SUCCESS;
            EventBus.getDefault().post(msg);
            Intent intent = new Intent(B0_SigninActivity.this, SlidingActivity.class);
            startActivity(intent);//from   w  w  w  . j a va 2 s  .c  o  m
            finish();
        } else {
            ToastView toast = new ToastView(this, getString(R.string.mobile_phone_or_password_error));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mPassword.requestFocus();
        }

    }

}

From source file:com.nextgis.uikobserver.HttpSendData.java

@Override
protected Void doInBackground(String... urls) {
    if (IsNetworkAvailible(mContext)) {
        String sPostBody = urls[0];

        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new HttpPost("http://gis-lab.info:8090/");

        HttpParams params = httppost.getParams();
        params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE);

        HttpContext localContext = new BasicHttpContext();

        try {/*from   w  w w.j  ava  2 s.co m*/
            StringEntity se = new StringEntity(sPostBody, "UTF8");
            se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
            httppost.setEntity(se);
            httppost.setHeader("Content-type", "application/json");

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost, localContext);

            Bundle bundle = new Bundle();
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                bundle.putBoolean("error", false);
            } else {
                bundle.putBoolean("error", true);
            }

            bundle.putInt("src", mnType);
            Message msg = new Message();
            msg.setData(bundle);
            if (mEventReceiver != null) {
                mEventReceiver.sendMessage(msg);
            }

        } catch (ClientProtocolException e) {
            mError = e.getMessage();
            cancel(true);
        } catch (IOException e) {
            mError = e.getMessage();
            cancel(true);
        }
    } else {
        Bundle bundle = new Bundle();
        bundle.putBoolean("error", true);
        bundle.putString("err_msq", mContext.getString(R.string.sNetworkUnreach));
        bundle.putInt("src", mnType);

        Message msg = new Message();
        msg.setData(bundle);
        if (mEventReceiver != null) {
            mEventReceiver.sendMessage(msg);
        }
    }
    return null;
}

From source file:com.example.sample.provider.SampleProvider.java

public void logMessage(final String text) {
    runOnUiThread(new Runnable() {
        public void run() {
            final Message msg = new Message();
            msg.obj = text;/*from ww w.ja  va 2s  . c om*/
            mLogTextView.append("\n");
            mLogTextView.append(text);
        }
    });
    Log.i(TAG, text);
}

From source file:com.apkits.android.widget.WebImageView.java

/**
 * </br><b>description :</b>???
 * </br><b>time :</b>      2012-8-4 ?4:03:19
 * @param url/*from ww w  . j a v  a 2  s .  co  m*/
 */
public void fetchFromUrl(final String url) {
    if (!CommonRegex.matcherRegex("[\\w\\p{P}]*\\.[jpngifJPNGIF]{3,4}", url)) {
        if (mDefaultImageRes != 0)
            setImageResource(mDefaultImageRes);
        WebImageView.this.invalidate();
        return;
    }
    final String tempFile = HashEncrypt.encode(CryptType.SHA1, url);
    //?
    if (mContext.getFileStreamPath(tempFile).exists()) {
        Message msg = new Message();
        msg.what = State.Success;
        msg.obj = tempFile;
        mDownloadCallback.sendMessage(msg);
    } else {
        //
        new Thread(new Runnable() {
            @Override
            public void run() {
                Message msg = new Message();
                msg.what = State.Success;
                try {
                    HttpGet httpRequest = new HttpGet(url);
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
                    HttpEntity entity = response.getEntity();
                    BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity);
                    InputStream is = bufferedHttpEntity.getContent();
                    FileOutputStream os = mContext.openFileOutput(tempFile, Context.MODE_PRIVATE);
                    byte[] cache = new byte[1 * 1024];
                    for (int len = 0; (len = is.read(cache)) != -1;) {
                        os.write(cache, 0, len);
                    }
                    os.close();
                    is.close();
                    msg.obj = tempFile;
                } catch (IOException e) {
                    msg.obj = e.getMessage();
                    msg.what = State.Error;
                    e.printStackTrace();
                } finally {
                    mDownloadCallback.sendMessage(msg);
                }
            }
        }).start();
    }
}

From source file:com.app.jdy.ui.MyRecordActivity.java

public void getData() {
    params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("memberId", ID));
    Thread thread = new Thread(new Runnable() {

        @Override/*w w  w. j av  a  2  s . c  om*/
        public void run() {
            Message msg = new Message();
            dataJson = HttpUtils.request(params, URLs.MY_RECORD);
            if (dataJson.length() != 0 && !dataJson.equals("0x110")) {
                msg.what = 1;
            } else {
                msg.what = 0;
            }
            handler.sendMessage(msg);
        }
    });
    thread.start();
}

From source file:com.neu.fragment.BancheTimeFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.banche_info, null);
    screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth();
    screenHeight = getActivity().getWindowManager().getDefaultDisplay().getHeight();

    toast = new Toast(getActivity());

    // System.out.println(screenHeight+"px");
    // System.out.println("width:" + screenWidth);
    tableInfo = (TableLayout) view.findViewById(R.id.tableInfo);
    fromHunnan = (RelativeLayout) view.findViewById(R.id.hunnan_bt);
    fromNanhu = (RelativeLayout) view.findViewById(R.id.nanhu_bt);
    from_tx = (TextView) view.findViewById(R.id.from_tx);
    // spinner = (Spinner) view.findViewById(R.id.spinner_type);
    // ???/*from   w w w  . j a v a2 s.com*/
    selected_image = (ImageView) view.findViewById(R.id.selected_image);
    selected_name = (TextView) view.findViewById(R.id.selected_name);
    searchName = selected_name.getText().toString();
    searchName_fore = searchName;

    stu_show = (LinearLayout) view.findViewById(R.id.stu_show);
    dialog = MyDialog.createLoadingDialog(getActivity(), "...");

    freshInfo = (TextView) view.findViewById(R.id.fresh_info);
    //??
    freshInfo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            new Thread(new Runnable() {
                String result = "";

                @Override
                public void run() {
                    try {
                        // TODO Auto-generated method stub
                        //xml???
                        StoreBancheInfoUtils.storeInfoFromNet(getActivity());

                    } catch (UnkownNetWorkException e) {
                        System.out.println(e.getMessage());

                        Message msg = new Message();
                        msg.what = MSG_NETERROR;
                        handler.sendMessage(msg);

                    } catch (IOException e) {
                        // TODO: handle exception
                    }
                }
            }).start();
        }
    });
    // popMenu
    final PopMenu popMenu = new PopMenu(getActivity(), screenWidth);

    // ??
    RelativeLayout showType = (RelativeLayout) view.findViewById(R.id.select_type);
    showType.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            // TODO Auto-generated method stub
            popMenu.showAsDropDown(view);

        }
    });
    // ? 
    popMenu.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            searchName = ((Person) parent.getItemAtPosition(position)).getItem_name().toString();
            int drawable = ((Person) parent.getItemAtPosition(position)).getItem_image();
            selected_image.setBackgroundResource(drawable);
            selected_name.setText(searchName);
            if (searchName.equals("")) {
                if (!searchName_fore.equals(searchName)) {
                    stu_show.setVisibility(View.VISIBLE);
                    from_tx.setText("");
                    tableInfo.removeAllViews();
                }
            } else if (searchName.equals("?")) {
                if (!searchName_fore.equals(searchName)) {
                    stu_show.setVisibility(View.GONE);
                    from_tx.setText("");
                    tableInfo.removeAllViews();
                }
            }
            searchName_fore = searchName;

            popMenu.dismiss();
        }
    });

    fromHunnan.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            from = "?";
            task = new SearchAsyncTask();
            task.dialog = dialog;
            task.from = from;
            task.stu_show = stu_show;
            task.from_tx = from_tx;
            task.toast = toast;
            task.searchName = searchName;
            task.tableInfo = tableInfo;
            task.execute();
        }
    });
    fromNanhu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            if (searchName.equals(""))
                from = "??";
            else
                from = "?";
            task = new SearchAsyncTask();
            task.dialog = dialog;
            task.from = from;
            task.toast = toast;
            task.stu_show = stu_show;
            task.from_tx = from_tx;
            task.searchName = searchName;
            task.tableInfo = tableInfo;
            task.execute();
        }
    });

    return view;
}

From source file:com.example.parking.HistoryRecordFragment.java

public void setHistoryRecord(String date, int type, List<Map<String, Object>> list) {
    mDBAdapter.open();//from   w  w w . j  av  a  2  s  .c om
    String paymentState = new String();
    if (mType == TYPE_UNFINISHED_PAYMENT_STATE) {
        paymentState = "";
    } else if (mType == TYPE_FINISHED_PAYMENT_STATE_MOBILE) {
        paymentState = "";
    } else if (mType == TYPE_FINISHED_PAYMENT_STATE_CASH) {
        paymentState = "";
    } else if (mType == TYPE_UNFINISHED_PAYMENT_STATE_LEAVE) {
        paymentState = "";
    }
    Log.e("yifan", "date : " + date);
    Log.e("yifan", "paymentState : " + paymentState);
    Cursor cursor = mDBAdapter.getParkingByStartTime(date + "%");
    Log.e("yifan", "count : " + cursor.getCount());
    Map<String, Object> titleMap = new HashMap<String, Object>();
    titleMap.put("licensePlateNumber", "");
    titleMap.put("startTime", "");
    titleMap.put("leaveTime", "");
    titleMap.put("parkingLocation", "?");
    titleMap.put("expense", "");
    list.add(titleMap);
    int count = 0;
    try {
        do {
            Log.e("yifan", "paymentpattern : " + cursor.getString(cursor.getColumnIndex("paymentpattern")));
            if ((cursor.getString(cursor.getColumnIndex("paymentpattern"))).equals(paymentState)) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("licensePlateNumber", cursor.getString(cursor.getColumnIndex("licenseplate")));
                map.put("parkingLocation", cursor.getInt(cursor.getColumnIndex("locationnumber")) + "");
                map.put("startTime", ": " + cursor.getString(cursor.getColumnIndex("starttime")));
                if (cursor.getString(cursor.getColumnIndex("leavetime")) == null) {
                    map.put("leaveTime", null);
                } else {
                    map.put("leaveTime", ": " + cursor.getString(cursor.getColumnIndex("leavetime")));
                }
                map.put("paymentState", cursor.getString(cursor.getColumnIndex("paymentpattern")));
                if (cursor.getString(cursor.getColumnIndex("expense")) == null) {
                    map.put("expense", null);
                } else {
                    map.put("expense", cursor.getString(cursor.getColumnIndex("expense")));
                }
                list.add(map);
                count++;
            }
        } while (cursor.moveToNext());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (count == 0) {
            list.remove(titleMap);
            Message msg = new Message();
            msg.what = NO_TODAY_PARKING_RECORD;
            mHandler.sendMessage(msg);
            mEmptyNotifyTV.setVisibility(View.VISIBLE);
        }
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.app.jdy.ui.MyOrderActivity.java

public void getData() {
    params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("memberId", ID));
    Thread thread = new Thread(new Runnable() {

        @Override/*from   w  w  w  .j a va 2  s .  c  om*/
        public void run() {
            Message msg = new Message();
            dataJson = HttpUtils.request(params, URLs.MY_ORDER);
            if (dataJson.length() != 0 && !dataJson.equals("0x110")) {
                msg.what = 1;
            } else {
                msg.what = 0;
            }
            handler.sendMessage(msg);
        }
    });
    thread.start();
}