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:com.narkii.security.info.LicenseInfoFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);

    fileButton = (Button) view.findViewById(R.id.button_add_local);
    captureButton = (Button) view.findViewById(R.id.button_add_capture);
    uploadButton = (Button) view.findViewById(R.id.button_upload);
    previewImage = (ImageView) view.findViewById(R.id.image_preview);
    gridView = (GridView) view.findViewById(R.id.image_uploaded);
    fileName = (EditText) view.findViewById(R.id.text_file_name);

    gridViewAdapter = new GridViewAdapter(getActivity(), null, false);
    gridView.setAdapter(gridViewAdapter);

    captureButton.setOnClickListener(new OnClickListener() {

        @Override/*  w w  w.  j  a  va2 s.co  m*/
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            fileUri = MediaFileStorage.getOutputMediaFileUri(MediaFileStorage.MEDIA_TYPE_IMAGE);
            Log.d(TAG, fileUri.toString());
            Log.d(TAG, fileUri.getPath());
            i.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
            getParentFragment().startActivityForResult(i, Constants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
        }
    });

    fileButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent();
            intent.setType("*/*"); //("image/*")
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            //FragmentFragmentFragmentFragmentResultFragment
            getParentFragment().startActivityForResult(intent, Constants.CONTENT_GET_ACTIVITY_REQUEST_CODE);
        }
    });
    uploadButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (preBitmap != null && !fileName.getText().toString().equals("")) {
                //
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        DbOperations operations = DbOperations.getInstance(getActivity());
                        ContentValues values = new ContentValues();
                        values.put(Permission.COLUMN_FK_ENTERPRISE_ID,
                                getArguments().getLong("enterpriseId", 0));
                        Log.d(TAG, "storage file:" + fileUri.toString());
                        Log.d(TAG, "storage file:" + fileUri.getPath());
                        values.put(Permission.COLUMN_URL, fileUri.toString());
                        values.put(Permission.COLUMN_CERTIFICATE_NAME, fileName.getText().toString());
                        if (isImage)
                            values.put(Permission.COLUMN_TYPE, 1);
                        else
                            values.put(Permission.COLUMN_TYPE, 2);
                        long result = operations.insert(Permission.TABLE_NAME, values);
                        if (result > 0) {
                            Message msg = new Message();
                            msg.what = Constants.INSERT_UPLOADED_OK_MSG;
                            handler.sendMessage(msg);
                        }
                    }
                }).start();
            } else {
                Toast.makeText(getActivity(), "please select file and input name", Toast.LENGTH_LONG).show();
            }
        }
    });

    long id = getArguments().getLong("enterpriseId", 0);
    Bundle bundle = new Bundle();
    bundle.putLong("id", id);
    getLoaderManager().initLoader(Constants.PERMISSION_IMAGE_ID, bundle, this);
}

From source file:cm.aptoide.pt.Aptoide.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    keepScreenOn = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
            "Full Power");
    DownloadQueueServiceIntent = new Intent(getApplicationContext(), DownloadQueueService.class);
    startService(DownloadQueueServiceIntent);

    //@dsilveira  #534 +10lines Check if Aptoide is already running to avoid wasting time and showing the splash
    ActivityManager activityManager = (ActivityManager) getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> running = activityManager.getRunningTasks(Integer.MAX_VALUE);
    for (RunningTaskInfo runningTask : running) {
        if (runningTask.baseActivity.getClassName().equals("cm.aptoide.pt.RemoteInTab")) { //RemoteInTab is the real Aptoide Activity
            Message msg = new Message();
            msg.what = LOAD_TABS;//from w  w  w . ja  v  a 2 s  . c  om
            startHandler.sendMessage(msg);
            return;
        }
    }

    Log.d("Aptoide", "******* \n Downloads will be made to: "
            + Environment.getExternalStorageDirectory().getPath() + "\n ********");

    sPref = getSharedPreferences("aptoide_prefs", MODE_PRIVATE);
    prefEdit = sPref.edit();

    db = new DbHandler(this);

    PackageManager mPm = getPackageManager();
    try {
        pkginfo = mPm.getPackageInfo("cm.aptoide.pt", 0);
    } catch (NameNotFoundException e) {
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    try {
        if (pkginfo.versionCode < Integer.parseInt(getXmlElement("versionCode"))) {
            Log.d("Aptoide-VersionCode", "Using version " + pkginfo.versionCode + ", suggest update!");
            requestUpdateSelf();
        } else {
            proceed();
        }
    } catch (Exception e) {
        e.printStackTrace();
        proceed();
    }

}

From source file:it.angrydroids.epub3reader.EpubReaderMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_epub_reader_main);

    // ----- get activity elements
    view1 = (WebView) findViewById(R.id.firstViewport);
    view2 = (WebView) findViewById(R.id.secondViewport);
    layout = (LinearLayout) findViewById(R.id.mainLayout);

    iconCloseView1 = (Button) findViewById(R.id.topRightFirstView);
    iconCloseView2 = (Button) findViewById(R.id.topRightSecondView);

    layoutView1 = (RelativeLayout) findViewById(R.id.firstViewportLayout);
    layoutView2 = (RelativeLayout) findViewById(R.id.secondViewportLayout);
    // -----/*  w ww  .  ja v  a 2  s . com*/

    // ----- get activity screen size
    DisplayMetrics metrics = this.getResources().getDisplayMetrics();
    screenWidth = metrics.widthPixels;
    screenHeight = metrics.heightPixels;
    // -----

    navigator = new EpubNavigator(getBaseContext());

    // enable JavaScript for cool things to happen!
    view1.getSettings().setJavaScriptEnabled(true);
    view2.getSettings().setJavaScriptEnabled(true);

    // when the app starts, only one view is shown
    updateView1(ViewStateEnum.books);
    updateView2(ViewStateEnum.invisible);

    // ----- SWIPE PAGE
    view1.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (stateView1 == ViewStateEnum.books) {
                swipePage(v, event, BookEnum.first);
            }

            if (syncScrollActivated == true && stateView2 != ViewStateEnum.invisible) {
                // syncScroll(v, view2, event); work in progress
            }

            WebView view = (WebView) v;
            return view.onTouchEvent(event);
        }
    });

    view2.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (stateView2 == ViewStateEnum.books) {
                swipePage(v, event, BookEnum.second);
            }
            WebView view = (WebView) v;
            return view.onTouchEvent(event);
        }
    });
    // -----

    // ----- VIEW CLOSING
    iconCloseView1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ViewStateEnum newState = navigator.closeView1();
            ViewStateEnum oldState = stateView1;
            updateView1(newState);
            if (oldState == ViewStateEnum.books) {
                updateView2(ViewStateEnum.invisible);
            }
        }
    });

    iconCloseView2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            updateView2(navigator.closeView2());
        }
    });
    // -----

    // ----- NOTE & LINK
    view1.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (stateView1 == ViewStateEnum.books || stateView1 == ViewStateEnum.notes) {
                Message msg = new Message();
                msg.setTarget(new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        String url = msg.getData().getString(getString(R.string.url));
                        if (url != null)
                            if (stateView1 == ViewStateEnum.books || stateView1 == ViewStateEnum.notes) {
                                updateView2(ViewStateEnum.notes);
                                navigator.setView2(url);
                            } else {
                                navigator.setView1(url);
                            }
                    }
                });
                view1.requestFocusNodeHref(msg);
            }
            return false;
        }
    });

    view1.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try {
                updateView1(navigator.setView1(url));
            } catch (Exception e) {
                errorMessage(getString(R.string.error_LoadPage));
            }
            return true;
        }
    });

    view2.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Message msg = new Message();
            msg.setTarget(new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    String url = msg.getData().getString(getString(R.string.url));
                    if (url != null) {
                        try {
                            if (stateView2 == ViewStateEnum.books || stateView2 == ViewStateEnum.notes) {
                                updateView1(ViewStateEnum.notes);
                                navigator.setView1(url);
                            } else {
                                navigator.setView2(url);
                            }
                        } catch (Exception e) {
                            errorMessage(getString(R.string.error_LoadPage));
                        }
                    }

                }
            });
            view2.requestFocusNodeHref(msg);
            return false;
        }
    });

    view2.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try {
                updateView2(navigator.setView2(url));
            } catch (Exception e) {
                errorMessage(getString(R.string.error_LoadPage));
            }
            return true;
        }
    });
    // -----

    // ----- LOAD STATE
    SharedPreferences preferences = getPreferences(MODE_PRIVATE);
    if (preferences.getBoolean(getString(R.string.bookOpen), false)) {
        loadState(preferences);
    } else {
        bookSelector = BookEnum.first;
        Intent goToChooser = new Intent(this, FileChooser.class);
        startActivityForResult(goToChooser, 0);
    }
    // -----
}

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

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (url.endsWith(ApiInterface.MYSERVICE_MODIFY)) {
        ToastView toast = new ToastView(this, getString(R.string.price_edit_success));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();/*ww  w  .java 2 s .co m*/
        CloseKeyBoard();
        Message msg = new Message();
        msg.what = MessageConstant.Change_Seivice;
        EventBus.getDefault().post(msg);
        Intent intent = new Intent();
        intent.putExtra("ok", "ok");
        setResult(RESULT_OK, intent);
        finish();
    }
}

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

@Override
protected void onPostExecute(Void unused) {
    super.onPostExecute(unused);
    if (mbShowProgress) {
        mDownloadDialog.dismiss();/* w ww.  j a  v a2 s  . com*/
    }
    if (mError != null) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("error", true);
        bundle.putString("err_msq", mError);
        bundle.putInt("src", mnType);

        Message msg = new Message();
        msg.setData(bundle);
        if (mEventReceiver != null) {
            mEventReceiver.sendMessage(msg);
        }
    } else {
        //Toast.makeText(FireReporter.this, "Source: " + Content, Toast.LENGTH_LONG).show();
    }
}

From source file:net.evecom.androidecssp.activity.event.EventAddActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case 1: // 
        String filePath = data.getStringExtra("filePath");
        // manageFileDataAndListView(filePath);
        break;/*from   www .  j  a v a 2s .c  o  m*/
    case R.layout.afnail_picture_activity: //   

        break;
    case 3: // 

        break;
    case R.layout.picture_select_at: // 
        new Thread(new Runnable() {
            @Override
            public void run() {
                filebeans.removeAll(filebeans);
                filebeans = getDb().findAll(FileManageBean.class);
                Message message = new Message();
                message.what = R.layout.picture_select_at;
                pubHandler.sendMessage(message);
            }
        }).start();
        break;
    case R.layout.event_name_add_activity: // 
        BaseModel eventinfo = (BaseModel) getData("eventinfo", data);
        if (null != eventinfo) {
            nameTV.setText(eventinfo.getStr("eventname"));
            addrTV.setText(eventinfo.getStr("happenaddress"));
            bgrTV.setText(eventinfo.getStr("reporterperson") + "-" + eventinfo.getStr("reportertel"));
            contentTV.setText(eventinfo.getStr("eventcontent"));
        }
        break;
    case R.layout.tree_list_at: // 
        /* eventTypeid = data.getStringExtra("eventTypeid");
        eventTypeName = data.getStringExtra("eventTypeName");
        clztTV.setText(eventTypeName);*/
        eventTypeid = data.getStringExtra("nodeid");
        eventTypeName = data.getStringExtra("nodeName");
        clztTV.setText(eventTypeName);
        break;
    default:
        break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.qddagu.app.meetreader.ui.MainActivity.java

/**
 * ?/*from   ww w  .j ava 2  s . c o  m*/
 * @param handler
 */
public void loadMeeting(final String url) {
    final ProgressDialog mLoadingDialog = new ProgressDialog(this);
    mLoadingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mLoadingDialog.setTitle("??");
    mLoadingDialog.setMessage("??...");
    mLoadingDialog.setCancelable(false);
    mLoadingDialog.show();
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            mLoadingDialog.dismiss();
            if (msg.what == 1) { //?
                Meeting meeting = ((Meeting) msg.obj);
                User user = meeting.getUser();
                if (user != null) {
                    //??
                    appContext.saveUserInfo(user);
                }
                appContext.setMeeting(meeting);//?
                appContext.saveHistory(meeting);//??

                UIHelper.showMeeting(MainActivity.this);
            } else if (msg.what == 0) { //
                UIHelper.ToastMessage(MainActivity.this, "");
            } else if (msg.what == -1 && msg.obj != null) {
                ((AppException) msg.obj).makeToast(MainActivity.this);
            }
        }
    };
    new Thread() {
        public void run() {
            Message msg = new Message();
            try {
                Meeting meeting = appContext.getMeeting(url);
                msg.what = (meeting != null && meeting.getId() > 0) ? 1 : 0;
                msg.obj = meeting;
            } catch (AppException e) {
                e.printStackTrace();
                msg.what = -1;
                msg.obj = e;
            }
            handler.sendMessage(msg);
        }
    }.start();
}

From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java

private void Refresh() {
    CritCount = 0;/*from   w w  w .ja  va2  s  .c o  m*/
    ErrCount = 0;
    WarnCount = 0;

    ((Thread) new Thread() {
        public void run() {
            try {
                //tempZenossEvents = rhybuddCache.GetRhybuddEvents();
                RhybuddDataSource datasource = new RhybuddDataSource(wContext);
                datasource.open();
                tempZenossEvents = datasource.GetRhybuddEvents();
                datasource.close();
            } catch (Exception e) {
                e.printStackTrace();
                //tempZenossEvents.clear();
                tempZenossEvents = null;
            }

            if (null != tempZenossEvents) {
                //Log.i("CountWidget","Found DB Data!");
                handler.sendEmptyMessage(1);
            }
            /*else
            {
               //Log.i("CountWidget","No DB data found, querying API directly");
               //handler.sendEmptyMessage(2);
               try
               {
                  if(API == null)
                  {
             if(settings.getBoolean("httpBasicAuth", false))
             {
                API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""),settings.getString("BAUser", ""), settings.getString("BAPassword", ""));
             }
             else
             {
                API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""));
             }
                  }
                          
                  try 
                  {
             if(API != null)
             {
                tempZenossEvents = API.GetRhybuddEvents(true,
                      true,
                      true,
                      false,
                      false,
                      true,
                      null,
                      null);
             }
             else
             {
                tempZenossEvents = null;
                handler.sendEmptyMessage(999);
             }
                  }
                  catch(Exception e)
                  {
             handler.sendEmptyMessage(999);
                  }
               }
               catch(Exception e)
               {
                  e.printStackTrace();
               }
            }*/

            if (tempZenossEvents != null) {
                EventCount = tempZenossEvents.size();

                for (int i = 0; i < EventCount; i++) {
                    if (tempZenossEvents.get(i).getSeverity().equals("5"))
                        CritCount++;

                    if (tempZenossEvents.get(i).getSeverity().equals("4"))
                        ErrCount++;

                    if (tempZenossEvents.get(i).getSeverity().equals("3"))
                        WarnCount++;
                }
                tempZenossEvents = null;
                API = null;
            }

            //No matter what send an update
            //handler.sendEmptyMessage(0);
            Message Msg = new Message();
            Bundle data = new Bundle();
            data.putInt("CritCount", CritCount);
            data.putInt("ErrCount", ErrCount);
            data.putInt("WarnCount", WarnCount);
            Msg.setData(data);
            Msg.what = 1;
            handler.sendMessage(Msg);
        }
    }).start();
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void login(final String phone, final String password) {
    new Thread() {
        Message msg = new Message();

        public void run() {
            String data = "&phone=" + phone + "&password=" + password;
            Log.e("data is ", data);
            String result_data = NetUtil.getResponse(WebAddress.LOGIN, data);
            Log.e("successful", result_data);
            try {
                JSONObject obj = new JSONObject(result_data);
                msg.what = CommunalInterfaces.LOGIN;
                msg.obj = obj;/*w  w  w.j av  a2  s.co  m*/
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}