Example usage for android.os Message getData

List of usage examples for android.os Message getData

Introduction

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

Prototype

public Bundle getData() 

Source Link

Document

Obtains a Bundle of arbitrary data associated with this event, lazily creating it if necessary.

Usage

From source file:com.example.manan.enhancedurdureader.EpubReader.BookView.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override//ww w .j a  v  a  2  s.c  om
public void onActivityCreated(Bundle saved) {
    super.onActivityCreated(saved);
    view = (WebView) getView().findViewById(R.id.Viewport);
    view.getSettings().setTextZoom(textSize);

    mScaleDetector = new ScaleGestureDetector(getActivity().getBaseContext(),
            new ScaleGestureDetector.OnScaleGestureListener() {
                @Override
                public void onScaleEnd(ScaleGestureDetector detector) {
                }

                @Override
                public boolean onScaleBegin(ScaleGestureDetector detector) {
                    return true;
                }

                @Override
                public boolean onScale(ScaleGestureDetector detector) {
                    //Log.w(LOG_KEY, "zoom ongoing, scale: " + detector.getScaleFactor());
                    return false;
                }

            });

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

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

            /*   if (state == ViewStateEnum.books)
                  swipePage(v, event, 0);
               //int fontSize, newFont;*/
            WebView view = (WebView) v;

            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                x1 = event.getX();
                break;
            case MotionEvent.ACTION_UP:
                if (mode != ZOOM && swipeFlag) {
                    //if (state == ViewStateEnum.books)
                    //swipePage(v, event, 0);

                }
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                oldDist = spacing(event);
                if (oldDist > 10f) {
                    mode = ZOOM;
                }
                break;
            case MotionEvent.ACTION_POINTER_UP:
                mode = NONE;
                break;

            case MotionEvent.ACTION_MOVE:

                if (mode == ZOOM) {
                    float newDist = spacing(event);
                    if (newDist > 10f) {
                        float scale = newDist / oldDist;
                        if (scale > 1) {
                            int currentTextSize = view.getSettings().getTextZoom();
                            textSize = currentTextSize + 15;
                            view.getSettings().setTextZoom(textSize);

                            mode = NONE;
                            swipeFlag = false;
                        } else {
                            int currentTextSize = view.getSettings().getTextZoom();
                            textSize = currentTextSize - 15;
                            view.getSettings().setTextZoom(textSize);
                            mode = NONE;
                            swipeFlag = false;
                        }
                    }
                }
                break;

            }
            return view.onTouchEvent(event);
        }

    });

    // ----- NOTE & LINK
    view.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)
                        navigator.setNote(url, index);
                }
            });
            view.requestFocusNodeHref(msg);

            return false;
        }
    });

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

    loadPage(viewedPage);
}

From source file:org.sufficientlysecure.keychain.ui.CreateKeyYubiKeyImportFragment.java

public void importKey() {

    // Message is received after decrypting is done in KeychainService
    ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity(),
            getString(R.string.progress_importing), ProgressDialog.STYLE_HORIZONTAL) {
        @Override// w  w w .  j  a  va  2s .  co m
        public void handleMessage(Message message) {
            // handle messages by standard KeychainIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == MessageStatus.OKAY.ordinal()) {
                // get returned data bundle
                Bundle returnData = message.getData();

                ImportKeyResult result = returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);

                long[] masterKeyIds = result.getImportedMasterKeyIds();

                // TODO handle masterKeyIds.length != 1...? sorta outlandish scenario

                if (!result.success() || masterKeyIds.length == 0) {
                    result.createNotify(getActivity()).show();
                    return;
                }

                Intent intent = new Intent(getActivity(), ViewKeyActivity.class);
                // use the imported masterKeyId, not the one from the yubikey, because
                // that one might* just have been a subkey of the imported key
                intent.setData(KeyRings.buildGenericKeyRingUri(masterKeyIds[0]));
                intent.putExtra(ViewKeyActivity.EXTRA_DISPLAY_RESULT, result);
                intent.putExtra(ViewKeyActivity.EXTRA_NFC_AID, mNfcAid);
                intent.putExtra(ViewKeyActivity.EXTRA_NFC_USER_ID, mNfcUserId);
                intent.putExtra(ViewKeyActivity.EXTRA_NFC_FINGERPRINTS, mNfcFingerprints);
                startActivity(intent);
                getActivity().finish();

            }

        }
    };

    // Send all information needed to service to decrypt in other thread
    Intent intent = new Intent(getActivity(), KeychainService.class);

    // fill values for this action
    Bundle data = new Bundle();

    intent.setAction(KeychainService.ACTION_IMPORT_KEYRING);

    ArrayList<ParcelableKeyRing> keyList = new ArrayList<>();
    keyList.add(new ParcelableKeyRing(mNfcFingerprint, null, null));
    data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, keyList);

    {
        Preferences prefs = Preferences.getPreferences(getActivity());
        Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true,
                prefs.getPreferredKeyserver());
        data.putString(KeychainService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);
    }

    intent.putExtra(KeychainService.EXTRA_DATA, data);

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(saveHandler);
    intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);

    saveHandler.showProgressDialog(getActivity());

    // start service with intent
    getActivity().startService(intent);

}

From source file:org.peercast.core.PeerCastServiceController.java

/**
 * PeerCastService???//from ww w  . j a  va2s .co m
 * 
 *<ul>
 * <li>
 *    MSG_GET_APPLICATION_PROPERTIES = 0x00;<br>
 *   ????<br>
 *   :  getInt("port") ??=0<br><br>
 * <li>    
 *  MSG_GET_CHANNELS = 0x01;<br>
 *  ??????<br>
 *   :  nativeGetChannel()?<br>
 *   : Channel.java <br><br>
 * <li>    
 *  MSG_GET_STATS = 0x02;<br>
 *  ?????<br>
  *   :   nativeGetStats()?<br>
  *   : Stats.java <br><br>
 *
 * @param what MSG_ ??
 * @param listener ??Bundle????
 */
public void sendCommand(int what, final OnServiceResultListener listener) {
    if (serverMessenger == null)
        new IllegalStateException("service not connected.");
    Message msg = Message.obtain(null, what);
    msg.replyTo = new Messenger(new Handler(new Handler.Callback() {
        //Handler???
        @Override
        public boolean handleMessage(Message msg) {
            listener.onServiceResult(msg.getData());
            return true;
        }
    }));
    try {
        serverMessenger.send(msg);
    } catch (RemoteException e) {
        Log.e(TAG, "what=" + what, e);
    }
}

From source file:com.nextgis.mobile.map.MapBase.java

/**
 * Create handler for messages/*w ww.java  2  s .  c  om*/
 */
protected void createHandler() {
    mHandler = new Handler() {
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            Bundle resultData = msg.getData();
            boolean bHasErr = resultData.getBoolean(BUNDLE_HASERROR_KEY);
            if (bHasErr) {
                reportError(resultData.getString(BUNDLE_MSG_KEY));
            } else {
                processMessage(resultData);
            }
        }
    };
}

From source file:com.zia.freshdocs.widget.CMISAdapter.java

/**
 * Saves the content node to the favorites area of the sdcard
 * @param position/*from   ww  w . j av  a 2 s.c  o m*/
 */
public void toggleFavorite(int position) {
    final Context context = getContext();
    final CMISPreferencesManager prefsMgr = CMISPreferencesManager.getInstance();
    final NodeRef ref = getItem(position);
    final Set<NodeRef> favorites = prefsMgr.getFavorites(context);

    if (favorites.contains(ref)) {
        favorites.remove(ref);
        prefsMgr.storeFavorites(context, favorites);

        if (_favoritesView) {
            remove(ref);
            notifyDataSetChanged();
        }
    } else {
        downloadContent(ref, new Handler() {
            public void handleMessage(Message msg) {
                boolean done = msg.getData().getBoolean("done");
                if (done) {
                    dismissProgressDlg();

                    File file = (File) _dlThread.getResult();

                    if (file != null) {
                        favorites.add(ref);
                        prefsMgr.storeFavorites(context, favorites);
                    }
                } else {
                    int value = msg.getData().getInt("progress");
                    if (value > 0) {
                        _progressDlg.setProgress(value);
                    }
                }
            }
        });
    }
}

From source file:com.zia.freshdocs.widget.CMISAdapter.java

/**
 * Retrieve the children from the specified node.  
 * @param position n-th child position/*from w w w . j  av  a  2  s  .c om*/
 */
public void getChildren(int position) {
    final NodeRef ref = getItem(position);

    // For folders display the contents for the specified URI
    if (ref.isFolder()) {
        _stack.push(_currentState);
        String uuid = ref.getContent();
        _currentState = new Pair<String, NodeRef[]>(uuid, null);
        getChildren(uuid);
    }
    // For non-folders try a download (if there is an external storage card)
    else {
        String storageState = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(storageState)) {
            downloadContent(ref, new Handler() {
                public void handleMessage(Message msg) {
                    boolean done = msg.getData().getBoolean("done");
                    if (done) {
                        dismissProgressDlg();

                        File file = (File) _dlThread.getResult();
                        if (file != null) {
                            viewContent(file, ref);
                        }
                    } else {
                        int value = msg.getData().getInt("progress");
                        if (value > 0) {
                            _progressDlg.setProgress(value);
                        }
                    }
                }
            });
        }
    }
}

From source file:com.example.pyrkesa.shwc.LoginActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_log);//from  w ww  . ja v a2s .c  o m

    final ModelFactory model = (ModelFactory) ModelFactory.getContext();
    UserAuthenticate = model.UserAuthenticate;
    //For settings option-- put it in the first acticity on the onCreate function
    if (getIntent().getBooleanExtra("Exit me", false)) {

        finish();
    }

    if (LoginActivity.UserAuthenticate) {
        Intent homepage = new Intent(getApplicationContext(), MainActivity.class);
        homepage.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(homepage);
        finish();
    }

    final Handler searchipHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            String shwcipadress = msg.getData().getString("ip");
            if (shwcipadress != null) {
                if (LoginActivity.UserAuthenticate == false) {
                    LoginActivity.shwcserverFound = true;
                    LoginActivity.url_all_box = "http://" + shwcipadress
                            + "/SHWCDataManagement/Box/get_all_box.php";
                    LoginActivity.url_authenticate = "http://" + shwcipadress
                            + "/SHWCDataManagement/Users/authenticate.php";
                    LoginActivity.url_authenticateByDevice = "http://" + shwcipadress
                            + "/SHWCDataManagement/Users/authenticateByDevice.php";

                    Log.d("SHWCServer", "IP=" + shwcipadress);

                    String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

                    Log.d("Android id :", android_id);

                    ArrayList<String> Logs1 = new ArrayList<String>();
                    Logs1.add(url_authenticateByDevice);
                    Logs1.add(android_id);
                    Logs1.add(url_all_box);
                    new AuthenticateUserByDevice().execute(Logs1);
                }
            }

        }
    };

    // Run the ServiceNSD to find the shwcserver
    //final FindServicesNSD zeroconf=new FindServicesNSD((NsdManager)getSystemService(NSD_SERVICE), "_http._tcp",searchipHandler);
    //zeroconf.run();
    // LoginActivity.x=zeroconf;

    // simulation dcouverte serveur shwc
    LoginActivity.shwcserverFound = true;
    model.api_url = "http://" + "10.0.1.5" + "/SHWCDataManagement/";
    LoginActivity.url_all_box = model.api_url + "Box/get_all_box.php";
    LoginActivity.url_authenticate = model.api_url + "Users/authenticate.php";
    LoginActivity.url_authenticateByDevice = model.api_url + "Users/authenticateByDevice.php";

    String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    Log.d("Android id :", android_id);

    ArrayList<String> Logs1 = new ArrayList<String>();
    Logs1.add(url_authenticateByDevice);
    Logs1.add(android_id);
    Logs1.add(url_all_box);

    if (getIntent().hasExtra("logout")) {
        new LoadAllBoxes().execute(url_all_box);
    } else {
        new AuthenticateUserByDevice().execute(Logs1);
    }

    /// end simulation

    LogInButton = ((ImageButton) this.findViewById(R.id.LogInButton));
    // Get login and password from EditText
    final EditText login = ((EditText) this.findViewById(R.id.login));
    final EditText password = ((EditText) this.findViewById(R.id.password));
    final Spinner box_choice = ((Spinner) this.findViewById(R.id.box_choice));

    LogInButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (LoginActivity.shwcserverFound) {
                String pass = password.getText().toString();
                String log = login.getText().toString();
                String box = box_choice.getSelectedItem().toString();

                String android_id1 = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
                ArrayList<String> Logs = new ArrayList<String>();
                Logs.add(log);
                Logs.add(pass);
                Logs.add(url_authenticate);
                Logs.add(android_id1);
                Logs.add(box);
                new AuthenticateUser().execute(Logs);
            } else {
                Toast.makeText(LoginActivity.this, "Systme SHWC indisponible !", Toast.LENGTH_LONG).show();
            }

        }
    });
    // on seleting single product
    // launching Edit Product Screen

}

From source file:edu.asu.cse535.assignment3.MainActivity.java

public void setHandlerForService() {
    handler = new Handler() {
        @Override/*from   www  . ja  va  2s .  co  m*/
        public void handleMessage(Message msg) {
            //ideally do it in service. Because extra filling of array may be avoided.But
            // check if the built message will be sent to the queue if stopself is called
            // before sendig the message.
            Log.w(this.getClass().getSimpleName(), "Message received and stopping service");

            Bundle b = msg.getData();
            ActivityData activityData = (ActivityData) b.getSerializable("ActivityData");
            Log.w(this.getClass().getSimpleName(),
                    "The data for " + activityData.getActivity() + " will be added to database");
            activityDatabaseHandler.addActivityToDatabase(activityData);
            stopAccService();

            notifyCompletion();
            Toast.makeText(MainActivity.this, "Activity added to Database", Toast.LENGTH_SHORT).show();
            new ActivityPublishHelper(activityData, getApplicationContext());
        }
    };
}

From source file:org.sufficientlysecure.keychain.ui.SafeSlingerActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_SAFE_SLINGER) {
        if (resultCode == ExchangeActivity.RESULT_EXCHANGE_CANCELED) {
            return;
        }/*from w  ww.  ja  va 2 s.c o  m*/

        final FragmentActivity activity = SafeSlingerActivity.this;

        // Message is received after importing is done in KeychainIntentService
        KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(activity,
                getString(R.string.progress_importing), ProgressDialog.STYLE_HORIZONTAL, true) {
            public void handleMessage(Message message) {
                // handle messages by standard KeychainIntentServiceHandler first
                super.handleMessage(message);

                if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                    // get returned data bundle
                    Bundle returnData = message.getData();
                    if (returnData == null) {
                        return;
                    }
                    final ImportKeyResult result = returnData.getParcelable(OperationResult.EXTRA_RESULT);
                    if (result == null) {
                        Log.e(Constants.TAG, "result == null");
                        return;
                    }

                    if (!result.success()) {
                        //                            result.createNotify(activity).show();
                        // only return if no success...
                        Intent data = new Intent();
                        data.putExtras(returnData);
                        setResult(RESULT_OK, data);
                        finish();
                        return;
                    }

                    //                        if (mExchangeMasterKeyId == null) {
                    //                            return;
                    //                        }

                    Intent certifyIntent = new Intent(activity, CertifyKeyActivity.class);
                    certifyIntent.putExtra(CertifyKeyActivity.EXTRA_RESULT, result);
                    certifyIntent.putExtra(CertifyKeyActivity.EXTRA_KEY_IDS, result.getImportedMasterKeyIds());
                    certifyIntent.putExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, mMasterKeyId);
                    startActivityForResult(certifyIntent, KeyListActivity.REQUEST_CODE_RESULT_TO_LIST);

                    //                        mExchangeMasterKeyId = null;
                }
            }
        };

        Log.d(Constants.TAG, "importKeys started");

        // Send all information needed to service to import key in other thread
        Intent intent = new Intent(activity, KeychainIntentService.class);

        intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);

        // instead of giving the entries by Intent extra, cache them into a
        // file to prevent Java Binder problems on heavy imports
        // read FileImportCache for more info.
        try {
            // import exchanged keys
            ArrayList<ParcelableKeyRing> it = getSlingedKeys(data.getExtras());

            // We parcel this iteratively into a file - anything we can
            // display here, we should be able to import.
            ParcelableFileCache<ParcelableKeyRing> cache = new ParcelableFileCache<ParcelableKeyRing>(activity,
                    "key_import.pcl");
            cache.writeCache(it.size(), it.iterator());

            // fill values for this action
            Bundle bundle = new Bundle();
            intent.putExtra(KeychainIntentService.EXTRA_DATA, bundle);

            // Create a new Messenger for the communication back
            Messenger messenger = new Messenger(saveHandler);
            intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

            // show progress dialog
            saveHandler.showProgressDialog(activity);

            // start service with intent
            activity.startService(intent);
        } catch (IOException e) {
            Log.e(Constants.TAG, "Problem writing cache file", e);
            Notify.showNotify(activity, "Problem writing cache file!", Notify.Style.ERROR);
        }
    } else {
        // give everything else down to KeyListActivity!
        setResult(resultCode, data);
        finish();
    }
}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

/**
 * Implementation of SearchMessageHandler.OnMessageHandledListener
 *//*  w  w  w.j  a  v  a 2  s .  c  om*/
@Override
public void OnMessageHandled(Message msg) {
    final Bundle b = msg.getData();

    mView.findViewById(R.id.details_progress_address).setVisibility(View.GONE);

    if (b.getInt(Const.KEY_BUNDLE_REVERSE_GEOCODER) == Const.BUNDLE_SEARCH_ADDRESS_SUCCESS) {
        TextView addressUi = (TextView) mView.findViewById(R.id.details_address);
        final String desc = b.getString(Const.KEY_BUNDLE_ADDRESS_DESC);
        addressUi.setText(desc);
        addressUi.setVisibility(View.VISIBLE);

        final int indexOfSeparator = desc.indexOf(Const.LINE_SEPARATOR);
        if (indexOfSeparator > 0) {
            mFavoriteLabel = desc.substring(0, indexOfSeparator);
        } else {
            mFavoriteLabel = desc;
        }

    } else {
        /**
         * Address not found! Display error message.
         */
        try {
            ((ParkingApp) getActivity().getApplicationContext()).showToastText(R.string.toast_address_error,
                    Toast.LENGTH_SHORT);
        } catch (NullPointerException e) {
            e.printStackTrace();
        }

    }

}