private void fillData() { newName.setText(intent.getStringExtra(NutrientsDBAdapter.KEY_NAME)); newProteins.setText(String.valueOf(intent.getFloatExtra(NutrientsDBAdapter.KEY_PROTEINS, 0))); newFats.setText(String.valueOf(intent.getFloatExtra(NutrientsDBAdapter.KEY_FATS, 0))); newCarbs.setText(String.valueOf(intent.getFloatExtra(NutrientsDBAdapter.KEY_CARBOHYDRATES, 0))); newCalories.setText(String.valueOf(intent.getFloatExtra(NutrientsDBAdapter.KEY_CALORIES, 0))); }
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); switch (action) { case AttributeEvent.AUTOPILOT_ERROR: String errorName = intent.getStringExtra(AttributeEventExtra.EXTRA_AUTOPILOT_ERROR_ID); final ErrorType errorType = ErrorType.getErrorById(errorName); onAutopilotError(errorType); break; case AttributeEvent.STATE_ARMING: case AttributeEvent.STATE_CONNECTED: case AttributeEvent.STATE_DISCONNECTED: case AttributeEvent.STATE_UPDATED: enableSlidingUpPanel(dpApp.getDrone()); break; case AttributeEvent.FOLLOW_START: // Extend the sliding drawer if collapsed. if (!mSlidingPanelCollapsing.get() && mSlidingPanel.isSlidingEnabled() && !mSlidingPanel.isPanelExpanded()) { mSlidingPanel.expandPanel(); } break; case AttributeEvent.MISSION_DRONIE_CREATED: float dronieBearing = intent.getFloatExtra(AttributeEventExtra.EXTRA_MISSION_DRONIE_BEARING, -1); if (dronieBearing != -1) updateMapBearing(dronieBearing); break; } }
@Test public void testFloatExtra() throws Exception { Intent intent = new Intent(); assertSame(intent, intent.putExtra("foo", 2f)); assertEquals(2f, intent.getExtras().get("foo")); assertEquals(2f, intent.getFloatExtra("foo", -1)); }
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (SensorTagService.ACTION_GATT_CONNECTED.equals(action)) { setConnected(true); } else if (SensorTagService.ACTION_GATT_DISCONNECTED.equals(action)) { setConnected(false); } else if (SensorTagService.ACTION_GYROSCOPE_DATA_AVAILABLE.equals(action)) { setConnected(true); float x = intent.getFloatExtra(SensorTagService.DATA_GYROSCOPE_X, 0); float y = intent.getFloatExtra(SensorTagService.DATA_GYROSCOPE_Y, 0); float z = intent.getFloatExtra(SensorTagService.DATA_GYROSCOPE_Z, 0); mXValueTextView.setText(Float.toString(x)); mYValueTextView.setText(Float.toString(y)); mZValueTextView.setText(Float.toString(z)); } }
/** 初始化 */ public void setupViews() { intent = getIntent(); mAppId = intent.getIntExtra("app_id", 0); // 获取对应app 的ID mAmount = intent.getIntExtra("amount", 0); // 评论人数 mUserID = intent.getStringExtra("user_id"); // 用户id mHaveBeenEvaluated = intent.getBooleanExtra("isScore", false); // 获取是否评分 mScoreValue = intent.getFloatExtra("ScoreValue", 0); // 获取已评分数 if ("-1".equals(mUserID)) { // 祥情里没获取userid,则默认此时已评价(不提交评分信息) mHaveBeenEvaluated = true; } mRatingBar = (RatingBar) findViewById(R.id.ratingBar); bar = (LinearLayout) findViewById(R.id.bar); mRatingBarText = (TextView) findViewById(R.id.text); animationDrawable = (AnimationDrawable) bar.getBackground(); mCloseButton = (ImageButton) findViewById(R.id.close); mTextView1 = (TextView) findViewById(R.id.text_1); // 已有多少人评价 mTextView2 = (TextView) findViewById(R.id.text_2); // 使用说明 mRatingBar.setRating(mScoreValue); mRatingBar.setOnRatingBarChangeListener(new RatingBarListener()); // if(mHaveBeenEvaluated){ //已评价 // evaluated(); // //mRatingBar.setFocusable(false);//让星星失去焦点 // AppLog.d(TAG,"-------------------------id--"+mAppId +"--已评价----------------"); // }else{ // mRatingBar.setRating(mScoreValue); // mRatingBar.setOnRatingBarChangeListener(new RatingBarListener()); // AppLog.d(TAG,"-------------------------id--"+mAppId +"--未评价----------------"); // } // 每次都让评价 // mRatingBar.setOnRatingBarChangeListener(new RatingBarListener()); mCloseButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (v.getId() == R.id.close) { finish(); } } }); setCloseFocuseChange(mCloseButton); mRatingBar.requestFocus(); animationDrawable.start(); mRatingBar.setOnClickListener( new OnClickListener() { public void onClick(View v) { mIsSuer = true; mTextView1.setText( AppAppraisalActivity.this.getString(R.string.app_appraisal_text1, mAmount + 1)); handler.sendEmptyMessageDelayed(CLOSE, 700); } }); setBarFocuseChange(mRatingBar); }
/** * (non-Javadoc) * * @see android.app.Service#onStart(android.content.Intent, int) * <p>在Service启动时获取用户设置, 得到最合适的位置提供器 */ @Override public void onStart(Intent intent, int startId) { // TODO Auto-generated method stub super.onStart(intent, startId); this.isRunning = true; long minTime = 3000L; float minDistance = 50F; if (intent != null) { minTime = intent.getLongExtra("minTime", 3000L); minDistance = intent.getFloatExtra("minDistance", 50F); } this.lbsManager.requestLocationUpdates(this.iProvider, minTime, minDistance, new LBSListener()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.counter_activity); tvCounter = (TextView) findViewById(R.id.tvCounter); cflCounter = (CounterFrameLayout) findViewById(R.id.cflCounter); tvCounter.setText("" + mRepCounter); mHub = Hub.getInstance(); if (!mHub.init(this, getPackageName())) { // We can't do anything with the Myo device if the Hub can't be initialized, so exit. Toast.makeText(this, "Couldn't initialize Hub", Toast.LENGTH_SHORT).show(); finish(); return; } mTextToSpeech = new TextToSpeech( getApplicationContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int status) {} }); mTextToSpeech.setLanguage(Locale.US); Intent intent = getIntent(); mWorkout = intent.getParcelableExtra(Workout.TAG); mHub.setLockingPolicy(Hub.LockingPolicy.NONE); mHub.addListener(mWorkout); float peak = intent.getFloatExtra(CalibrationActivity.KEY_PEAK, 0); float dip = intent.getFloatExtra(CalibrationActivity.KEY_DIP, 0); mWorkout.setRange(dip, peak); mWorkout.setCallback(this); Log.e(TAG, "PEAK: " + dip); Log.e(TAG, "DIP: " + peak); }
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(INTENT_ACTION_CMDS)) { String command = intent.getStringExtra(SwoopBroadcastReceiver.TYPE_CMD); if (CMD_SET_TAB_GRAVITY.equals(command)) { SwipeTabViewController.this.setTabGravity( intent.getIntExtra(SwoopBroadcastReceiver.TYPE_DATA, 0)); } else if (CMD_SET_TAB_VERTICAL.equals(command)) { SwipeTabViewController.this.setTabVerticalOffset( (int) intent.getFloatExtra(SwoopBroadcastReceiver.TYPE_DATA, 0.0f)); } } }
// Get data back from child activity. protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != RESULT_OK) { return; } String id = data.getStringExtra(Constants.KEY_ID); String subject = data.getStringExtra(Constants.KEY_SUBJECT); String body = data.getStringExtra(Constants.KEY_BODY); String url = data.getStringExtra(Constants.KEY_URL); float rating = data.getFloatExtra(Constants.KEY_RATING, 0); boolean isWatched = data.getBooleanExtra(Constants.KEY_IS_WATCHED, false); // When returning from Editor Screen, add/update a movie in the list. if (requestCode == REQUEST_EDITOR) { if (id.equals(Constants.VALUE_NEW_MOVIE)) { // New Movie in list. Movie movie = new Movie(subject, body, url, rating, isWatched); mMovies.add(movie); // Add to file. FileManager.addToFile(this, FILE_NAME, movie); } else { int position = data.getIntExtra(Constants.KEY_POSITION, -1); // Update the movie in list at id position. Movie movie = mMovies.get(position); movie.setSubject(subject); movie.setBody(body); movie.setUrl(url); movie.setRating(rating); movie.setIsWatched(isWatched); // Rewrite the file. FileManager.saveFile(this, FILE_NAME, mMovies); } } // On returning from Search screen, add new movie in the list. else if (requestCode == REQUEST_SEARCH) { // New Movie in list. Movie movie = new Movie(id, subject, body, url); movie.setRating(rating); mMovies.add(movie); // Add to file. FileManager.addToFile(this, FILE_NAME, movie); } mMainListAdapter.notifyDataSetChanged(); }
@Override protected void onHandleIntent(Intent intent) { try { initialized = false; isRecording = true; noise = intent.getFloatExtra(NOISE, 1.0f); } catch (Exception e1) { e1.printStackTrace(); } try { sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // verifica presenza accelerometro if (accelerometer != null) { sensorManager.registerListener( mySensorEventListener, accelerometer, intent.getIntExtra(SENSOR_DELAY, SensorManager.SENSOR_DELAY_NORMAL)); /* imposto che il servizio di registrazione si autochiuda allo scadere del tempo prefissato * nelle preferenze * */ long endTime = System.currentTimeMillis() + RecordActivity.remaining_time; while (isRecording && System.currentTimeMillis() < endTime) { synchronized (this) { try { wait(endTime - System.currentTimeMillis()); } catch (InterruptedException e) { e.printStackTrace(); } } } try { sensorManager.unregisterListener(mySensorEventListener); } catch (NullPointerException ex) { ex.printStackTrace(); } initialized = true; } else initialized = false; } catch (Exception e) { Toast.makeText(this, getString(R.string.error_no_accelerometer), Toast.LENGTH_SHORT).show(); e.printStackTrace(); initialized = false; } }
@Override protected Fragment createFragment() { Intent intent = getIntent(); // put what StartExerciseFragment is sending into Bundle for fragment Bundle bundle = new Bundle(); bundle.putParcelable( LocationExercise.LOCATION_EXERCISE_TABLE, intent.getParcelableExtra(LocationExercise.LOCATION_EXERCISE_TABLE)); bundle.putString(Exercise.EXERCISE, intent.getStringExtra(Exercise.EXERCISE)); bundle.putString(ExrcsLocation.LOCATION, intent.getStringExtra(ExrcsLocation.LOCATION)); bundle.putFloat( Exercise.MIN_DISTANCE_TO_LOG, intent.getFloatExtra(Exercise.MIN_DISTANCE_TO_LOG, 10)); bundle.putInt( Exercise.ELEVATION_IN_DIST_CALCS, intent.getIntExtra(Exercise.ELEVATION_IN_DIST_CALCS, 0)); bundle.putString( LocationExercise.DESCRIPTION, intent.getStringExtra(LocationExercise.DESCRIPTION)); return ActivityLoggerFragment.newInstance(bundle); }
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); switch (action) { case AttributeEvent.AUTOPILOT_ERROR: String errorName = intent.getStringExtra(AttributeEventExtra.EXTRA_AUTOPILOT_ERROR_ID); final ErrorType errorType = ErrorType.getErrorById(errorName); onAutopilotError(errorType); break; case AttributeEvent.AUTOPILOT_MESSAGE: final int logLevel = intent.getIntExtra( AttributeEventExtra.EXTRA_AUTOPILOT_MESSAGE_LEVEL, Log.VERBOSE); final String message = intent.getStringExtra(AttributeEventExtra.EXTRA_AUTOPILOT_MESSAGE); onAutopilotError(logLevel, message); break; case AttributeEvent.STATE_ARMING: case AttributeEvent.STATE_CONNECTED: case AttributeEvent.STATE_DISCONNECTED: case AttributeEvent.STATE_UPDATED: case AttributeEvent.TYPE_UPDATED: enableSlidingUpPanel(getDrone()); break; case AttributeEvent.FOLLOW_START: // Extend the sliding drawer if collapsed. if (!mSlidingPanelCollapsing.get() && mSlidingPanel.isEnabled() && mSlidingPanel.getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED) { mSlidingPanel.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED); } break; case AttributeEvent.MISSION_DRONIE_CREATED: float dronieBearing = intent.getFloatExtra(AttributeEventExtra.EXTRA_MISSION_DRONIE_BEARING, -1); if (dronieBearing != -1) updateMapBearing(dronieBearing); break; } }
protected void initializeView(View view) { mPhotoView = (PhotoView) view.findViewById(R.id.photo_view); mPhotoView.setMaxInitialScale(mIntent.getFloatExtra(Intents.EXTRA_MAX_INITIAL_SCALE, 1)); mPhotoView.setOnClickListener(this); mPhotoView.setFullScreen(mFullScreen, false); mPhotoView.enableImageTransforms(false); mPhotoPreviewAndProgress = view.findViewById(R.id.photo_preview); mPhotoPreviewImage = (ImageView) view.findViewById(R.id.photo_preview_image); mThumbnailShown = false; final ProgressBar indeterminate = (ProgressBar) view.findViewById(R.id.indeterminate_progress); final ProgressBar determinate = (ProgressBar) view.findViewById(R.id.determinate_progress); mPhotoProgressBar = new ProgressBarWrapper(determinate, indeterminate, true); mEmptyText = (TextView) view.findViewById(R.id.empty_text); mRetryButton = (ImageView) view.findViewById(R.id.retry_button); // Don't call until we've setup the entire view setViewVisibility(); }
private void parseIntent(Intent i) { Uri dat = getIntentUri(i); if (dat == null) resultFinish(RESULT_FAILED); String datString = dat.toString(); if (!datString.equals(dat.toString())) dat = Uri.parse(datString); mUri = dat; mNeedLock = i.getBooleanExtra("lockScreen", false); mDisplayName = i.getStringExtra("displayName"); mFromStart = i.getBooleanExtra("fromStart", false); mSaveUri = i.getBooleanExtra("saveUri", true); mStartPos = i.getFloatExtra("startPosition", -1.0f); mLoopCount = i.getIntExtra("loopCount", 1); mParentId = i.getIntExtra("parentId", 0); mSubPath = i.getStringExtra("subPath"); mSubShown = i.getBooleanExtra("subShown", true); mIsHWCodec = i.getBooleanExtra("hwCodec", false); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_lunch_info); Intent intent = this.getIntent(); TextView title = (TextView) findViewById(R.id.lunch_info_title); String str = intent.getStringExtra(Consts.LUNCH_INFO_TITLE); str = Utils.getFormatText(str, MAX_CHARS_IN_LINE, false); title.setText(str); TextView description = (TextView) findViewById(R.id.lunch_info_description); str = intent.getStringExtra(Consts.LUNCH_INFO_DESCRIPTION); description.setText(str); description.setMovementMethod(ScrollingMovementMethod.getInstance()); float cost = intent.getFloatExtra(Consts.LUNCH_INFO_PRICE, -1f); str = String.format(Locale.US, "%.2f ", cost); TextView price = (TextView) findViewById(R.id.lunch_info_price); price.setText(str); ImageStorage imageStorage = new ImageStorage(this); str = intent.getStringExtra(Consts.LUNCH_INFO_IMAGE); imageStorage.getImage(str, this); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { mNeedsAlive = true; if (intent != null && intent.getBooleanExtra(SAVING, false)) { // we save using an intent to keep the service around after the // activity has been destroyed. String presetJson = intent.getStringExtra(PRESET); String source = intent.getStringExtra(SOURCE_URI); String selected = intent.getStringExtra(SELECTED_URI); String destination = intent.getStringExtra(DESTINATION_FILE); int quality = intent.getIntExtra(QUALITY, 100); float sizeFactor = intent.getFloatExtra(SIZE_FACTOR, 1); boolean flatten = intent.getBooleanExtra(FLATTEN, false); boolean exit = intent.getBooleanExtra(EXIT, false); Uri sourceUri = Uri.parse(source); Uri selectedUri = null; if (selected != null) { selectedUri = Uri.parse(selected); } File destinationFile = null; if (destination != null) { destinationFile = new File(destination); } ImagePreset preset = new ImagePreset(); preset.readJsonFromString(presetJson); mNeedsAlive = false; mSaving = true; handleSaveRequest( sourceUri, selectedUri, destinationFile, preset, MasterImage.getImage().getHighresImage(), flatten, quality, sizeFactor, exit); } return START_REDELIVER_INTENT; }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) { return; } if (GaitAnalysisService.GAIT_UPDATE.equals(action)) { cadence = intent.getFloatExtra(GaitAnalysisService.CADENCE, 0); gait = intent.getStringExtra(GaitAnalysisService.GAIT); text_cadence.setText(String.format("%.1f", cadence)); text_gait.setText(gait); if (gait != null && cadence > 0) { gaits.add(0, gait); gaitListAdapter.notifyDataSetChanged(); } } else if (GaitAnalysisService.GAITLIB_STATUS_UPDATE.equals(action)) { String message = intent.getStringExtra(GaitAnalysisService.GAITLIB_STATUS_MESSAGE); text_status.setText(message); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setitngButton = (Button) findViewById(R.id.settingbutton); transmitDataText = (EditText) findViewById(R.id.tran_data_text); transmitDataButton = (Button) findViewById(R.id.tran_data_button); transmitCarrierButton = (Button) findViewById(R.id.tran_carrier_button); textTitle = (TextView) findViewById(R.id.textView_title); Intent getParameterData = getIntent(); carrier_frequency = getParameterData.getIntExtra("carrier_frequency", 2000); samples_per_symbol = getParameterData.getIntExtra("sample_per_symbol", 110); // double excess_width = getParameterData.getDoubleExtra("excess_width", 0.5); pulse_half_width = getParameterData.getIntExtra("pulse_half_width", 5); // int cf = Integer.parseInt(carrier_frequency); excess_width = getParameterData.getFloatExtra("excess_width", 0.5f); constellation = getParameterData.getStringExtra("const"); if (constellation == null) { constellation = "bpsk"; } pilot_sequence = getParameterData.getStringExtra("pilot"); if (pilot_sequence == null) { pilot_sequence = "barker13"; } if (constellation == "bpsk") { M = 2; } else { M = 4; } // text send back data // textTitle.append(" " + pilot_sequence); }
@Override public void onReceive(Context context, Intent intent) { if (StatusBarTintApi.INTENT_CHANGE_COLOR_NAME.equals(intent.getAction())) { boolean link = intent.getBooleanExtra("link_panels", false); if (intent.hasExtra("time")) { long time = intent.getLongExtra("time", -1); if (time != -1) { if (mLastReceivedTime == -1) { mLastReceivedTime = time; } else { if (time < mLastReceivedTime) { log("Ignoring change request because of earlier request"); log("mLastReceivedTime: " + mLastReceivedTime + " time: " + time); return; } else { mLastReceivedTime = time; } } } } if (intent.hasExtra(Common.INTENT_SAVE_ACTIONBAR_COLOR_NAME)) mActionBarColor = mLastTint; if (intent.hasExtra(StatusBarTintApi.KEY_STATUS_BAR_TINT)) { mLastTint = intent.getIntExtra(StatusBarTintApi.KEY_STATUS_BAR_TINT, -1); setStatusBarTint(mLastTint); } if (intent.hasExtra(StatusBarTintApi.KEY_STATUS_BAR_ICON_TINT)) { mLastIconTint = intent.getIntExtra(StatusBarTintApi.KEY_STATUS_BAR_ICON_TINT, -1); setStatusBarIconsTint(mLastIconTint); } if (intent.hasExtra(StatusBarTintApi.KEY_NAVIGATION_BAR_TINT) && !link) { mNavigationBarTint = intent.getIntExtra(StatusBarTintApi.KEY_NAVIGATION_BAR_TINT, -1); setNavigationBarTint(mNavigationBarTint, true); } else if (link) { mNavigationBarTint = intent.getIntExtra(StatusBarTintApi.KEY_STATUS_BAR_TINT, -1); setNavigationBarTint(mNavigationBarTint); } if (intent.hasExtra(StatusBarTintApi.KEY_NAVIGATION_BAR_ICON_TINT) && !link) { mNavigationBarIconTint = intent.getIntExtra(StatusBarTintApi.KEY_NAVIGATION_BAR_ICON_TINT, -1); setNavigationBarIconTint(mNavigationBarIconTint, true); } else if (link) { mNavigationBarIconTint = intent.getIntExtra(StatusBarTintApi.KEY_STATUS_BAR_ICON_TINT, -1); setNavigationBarIconTint(mNavigationBarIconTint); } } else if (Common.INTENT_RESET_ACTIONBAR_COLOR_NAME.equals(intent.getAction())) { mLastTint = mActionBarColor; setStatusBarTint(mActionBarColor); } else if (Common.INTENT_SETTINGS_UPDATED.equals(intent.getAction())) { Log.d("Xposed", "TintedStatusBar settings updated, reloading..."); mSettingsHelper.reload(); mSettingsHelper.reloadOverlayMode(); } else if (Common.INTENT_KEYBOARD_VISIBLITY_CHANGED.equals(intent.getAction())) { if (intent.hasExtra(Common.EXTRA_KEY_KEYBOARD_UP)) onKeyboardVisible(intent.getBooleanExtra(Common.EXTRA_KEY_KEYBOARD_UP, false)); } else if (WindowManagerServiceHooks.INTENT_DIM_CHANGED.equals(intent.getAction())) { if (intent.hasExtra(WindowManagerServiceHooks.KEY_TARGET_ALPHA)) onDimLayerChanged( intent.getFloatExtra(WindowManagerServiceHooks.KEY_TARGET_ALPHA, -1)); } }
/** * Update map with the new coordinates for the driver * * @param intent containing driver coordinates */ private void updateMap(final Intent intent) { // not logging entry as it will flood the logs // getting driver LatLng values from the intent final LatLng driverLatLng = new LatLng( intent.getFloatExtra(Constants.LATITUDE, 0), intent.getFloatExtra(Constants.LONGITUDE, 0)); // create driver marker if it doesn't exist and move the camera accordingly if (driverMarker == null) { mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(driverLatLng, 10)); driverMarker = mMap.addMarker( new MarkerOptions() .position(driverLatLng) .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_driver))); return; } // update driver location with LatLng driverLocation.setLatitude(driverLatLng.latitude); driverLocation.setLongitude(driverLatLng.longitude); // calculate current distance to the passenger float distance = passengerLocation.distanceTo(driverLocation) / 1000; // set the distance text distanceDetails.setText( String.format(getResources().getString(R.string.distance_with_value), distance)); // calculating ETA - we are assuming here that the car travels at 20mph to simplify the // calculations calendar = Calendar.getInstance(); calendar.add(Calendar.MINUTE, Math.round(distance / 20 * 60)); // set AM/PM to a relevant value AM_PM = getString(R.string.am); if (calendar.get(Calendar.AM_PM) == 1) { AM_PM = getString(R.string.pm); } // format ETA string to HH:MM String eta = String.format( getResources().getString(R.string.eta_with_value), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), AM_PM); // set the ETA text etaDetails.setText(eta); // as we are throttling updates to the coordinates, we might need to smooth out the moving // of the driver's marker. To do so we are going to draw temporary markers between the // previous and the current coordinates. We are going to use interpolation for this and // use handler/looper to set the marker's position // get hold of the handler final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); // get map projection and the driver's starting point Projection proj = mMap.getProjection(); Point startPoint = proj.toScreenLocation(driverMarker.getPosition()); final LatLng startLatLng = proj.fromScreenLocation(startPoint); final long duration = 150; // create new Interpolator final Interpolator interpolator = new LinearInterpolator(); // post a Runnable to the handler handler.post( new Runnable() { @Override public void run() { // calculate how soon we need to redraw the marker long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * intent.getFloatExtra(Constants.LONGITUDE, 0) + (1 - t) * startLatLng.longitude; double lat = t * intent.getFloatExtra(Constants.LATITUDE, 0) + (1 - t) * startLatLng.latitude; // set the driver's marker position driverMarker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { handler.postDelayed(this, 10); } } }); }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION_WIDGET_UPDATE.equals(action)) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.vlcwidget); String title = intent.getStringExtra("title"); String artist = intent.getStringExtra("artist"); boolean isplaying = intent.getBooleanExtra("isplaying", false); Bitmap cover = intent.getParcelableExtra("cover"); views.setTextViewText(R.id.songName, title); views.setTextViewText(R.id.artist, artist); views.setImageViewResource( R.id.play_pause, isplaying ? R.drawable.ic_pause : R.drawable.ic_play); if (cover != null) views.setImageViewBitmap(R.id.cover, cover); else views.setImageViewResource(R.id.cover, R.drawable.cone); views.setViewVisibility( R.id.timeline_parent, artist != null && artist.length() > 0 ? View.VISIBLE : View.INVISIBLE); /* commands */ Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD); Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE); Intent iStop = new Intent(ACTION_REMOTE_STOP); Intent iForward = new Intent(ACTION_REMOTE_FORWARD); Intent iVlc = new Intent(); iVlc.setClassName(VLC_PACKAGE, isplaying ? VLC_PLAYER : VLC_MAIN); iVlc.putExtra(START_FROM_NOTIFICATION, true); PendingIntent piBackward = PendingIntent.getBroadcast(context, 0, iBackward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piPlay = PendingIntent.getBroadcast(context, 0, iPlay, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piStop = PendingIntent.getBroadcast(context, 0, iStop, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piForward = PendingIntent.getBroadcast(context, 0, iForward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piVlc = PendingIntent.getActivity(context, 0, iVlc, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.backward, piBackward); views.setOnClickPendingIntent(R.id.play_pause, piPlay); views.setOnClickPendingIntent(R.id.stop, piStop); views.setOnClickPendingIntent(R.id.forward, piForward); views.setOnClickPendingIntent(R.id.cover, piVlc); ComponentName widget = new ComponentName(context, VLCAppWidgetProvider.class); AppWidgetManager manager = AppWidgetManager.getInstance(context); manager.updateAppWidget(widget, views); } else if (ACTION_WIDGET_UPDATE_POSITION.equals(action)) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.vlcwidget); float pos = intent.getFloatExtra("position", 0f); views.setProgressBar(R.id.timeline, 100, (int) (100 * pos), false); ComponentName widget = new ComponentName(context, VLCAppWidgetProvider.class); AppWidgetManager manager = AppWidgetManager.getInstance(context); manager.updateAppWidget(widget, views); } else super.onReceive(context, intent); }