Java Code Examples for android.widget.Chronometer#setBase()

The following examples show how to use android.widget.Chronometer#setBase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChronoActivity2.java    From android-lifecycles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // The ViewModelStore provides a new ViewModel or one previously created.
    ChronometerViewModel chronometerViewModel
            = new ViewModelProvider(this).get(ChronometerViewModel.class);

    // Get the chronometer reference
    Chronometer chronometer = findViewById(R.id.chronometer);

    if (chronometerViewModel.getStartTime() == null) {
        // If the start date is not defined, it's a new ViewModel so set it.
        long startTime = SystemClock.elapsedRealtime();
        chronometerViewModel.setStartTime(startTime);
        chronometer.setBase(startTime);
    } else {
        // Otherwise the ViewModel has been retained, set the chronometer's base to the original
        // starting time.
        chronometer.setBase(chronometerViewModel.getStartTime());
    }

    chronometer.start();
}
 
Example 2
Source File: MiscViewsDemoFragment.java    From elasticity with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View fragmentView = inflater.inflate(R.layout.misc_overscroll_demo, null, false);

    View textView = fragmentView.findViewById(R.id.demo_text);
    ElasticityHelper.setUpStaticOverScroll(textView, ORIENTATION.HORIZONTAL);

    View imageView = fragmentView.findViewById(R.id.demo_image);
    ElasticityHelper.setUpStaticOverScroll(imageView, ORIENTATION.VERTICAL);

    mChrono = (Chronometer) fragmentView.findViewById(R.id.demo_chronometer);
    if (savedInstanceState != null) {
        mChrono.setBase(savedInstanceState.getLong(CHRONO_TIME_SAVE_ID));
    }
    ElasticityHelper.setUpStaticOverScroll(mChrono, ORIENTATION.HORIZONTAL);
    mChrono.start();

    return fragmentView;
}
 
Example 3
Source File: MiscViewsDemoFragment.java    From overscroll-decor with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View fragmentView = inflater.inflate(R.layout.misc_overscroll_demo, null, false);

    View textView = fragmentView.findViewById(R.id.demo_text);
    OverScrollDecoratorHelper.setUpStaticOverScroll(textView, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);

    View imageView = fragmentView.findViewById(R.id.demo_image);
    OverScrollDecoratorHelper.setUpStaticOverScroll(imageView, OverScrollDecoratorHelper.ORIENTATION_VERTICAL);

    mChrono = (Chronometer) fragmentView.findViewById(R.id.demo_chronometer);
    if (savedInstanceState != null) {
        mChrono.setBase(savedInstanceState.getLong(CHRONO_TIME_SAVE_ID));
    }
    OverScrollDecoratorHelper.setUpStaticOverScroll(mChrono, OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);
    mChrono.start();

    return fragmentView;
}
 
Example 4
Source File: CallActivity.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
private void displayConferenceCall(final Call call) {
    LinearLayout conferenceCallView =
            (LinearLayout)
                    LayoutInflater.from(this)
                            .inflate(R.layout.call_conference_cell, null, false);

    TextView contactNameView = conferenceCallView.findViewById(R.id.contact_name);
    LinphoneContact contact =
            ContactsManager.getInstance().findContactFromAddress(call.getRemoteAddress());
    if (contact != null) {
        ContactAvatar.displayAvatar(
                contact, conferenceCallView.findViewById(R.id.avatar_layout), true);
        contactNameView.setText(contact.getFullName());
    } else {
        String displayName = LinphoneUtils.getAddressDisplayName(call.getRemoteAddress());
        ContactAvatar.displayAvatar(
                displayName, conferenceCallView.findViewById(R.id.avatar_layout), true);
        contactNameView.setText(displayName);
    }

    Chronometer timer = conferenceCallView.findViewById(R.id.call_timer);
    timer.setBase(SystemClock.elapsedRealtime() - 1000 * call.getDuration());
    timer.start();

    ImageView removeFromConference =
            conferenceCallView.findViewById(R.id.remove_from_conference);
    removeFromConference.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    LinphoneManager.getCallManager().removeCallFromConference(call);
                }
            });

    mConferenceList.addView(conferenceCallView);
}
 
Example 5
Source File: CallActivity.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
private void displayPausedCall(final Call call) {
    LinearLayout callView =
            (LinearLayout)
                    LayoutInflater.from(this).inflate(R.layout.call_inactive_row, null, false);

    TextView contactName = callView.findViewById(R.id.contact_name);
    Address address = call.getRemoteAddress();
    LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(address);
    if (contact == null) {
        String displayName = LinphoneUtils.getAddressDisplayName(address);
        contactName.setText(displayName);
        ContactAvatar.displayAvatar(displayName, callView.findViewById(R.id.avatar_layout));
    } else {
        contactName.setText(contact.getFullName());
        ContactAvatar.displayAvatar(contact, callView.findViewById(R.id.avatar_layout));
    }

    Chronometer timer = callView.findViewById(R.id.call_timer);
    timer.setBase(SystemClock.elapsedRealtime() - 1000 * call.getDuration());
    timer.start();

    ImageView resumeCall = callView.findViewById(R.id.call_pause);
    resumeCall.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    togglePause(call);
                }
            });

    mCallsList.addView(callView);
}
 
Example 6
Source File: MeasurementActivity.java    From NoiseCapture with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
    try {
        if(activity.measurementService.isRecording()) {
            int seconds = activity.measurementService.getLeqAdded();
            if(seconds >= MeasurementActivity.DEFAULT_MINIMAL_LEQ && !activity.buttonrecord.isEnabled()) {
                activity.buttonrecord.setEnabled(true);
            }
            Chronometer chronometer = (Chronometer) activity
                    .findViewById(R.id.chronometer_recording_time);
            if (activity.chronometerWaitingToStart.getAndSet(false)) {
                chronometer.setBase(SystemClock.elapsedRealtime() - seconds * 1000);
                TextView overlayMessage = (TextView) activity.findViewById(R.id.textView_message_overlay);
                if(activity.measurementService.isPaused()) {
                    chronometer.stop();
                    chronometer.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.pause_anim));
                    overlayMessage.setText(R.string.measurement_pause);
                } else {
                    chronometer.clearAnimation();
                    chronometer.start();
                    overlayMessage.setText("");
                }
            }

            //Update accuracy hint
            final TextView accuracyText = (TextView) activity.findViewById(R.id.textView_value_gps_precision);
            final ImageView accuracyImageHint = (ImageView) activity.findViewById(R.id.imageView_value_gps_precision);
            Location location = activity.measurementService.getLastLocation();
            if(location != null) {
                float lastPrecision = location.getAccuracy();
                if (lastPrecision < APROXIMATE_LOCATION_ACCURACY) {
                    accuracyImageHint.setImageResource(R.drawable.gps_fixed);
                    accuracyText.setText(activity.getString(R.string.gps_hint_precision,
                            (int)lastPrecision));
                } else {
                    accuracyImageHint.setImageResource(R.drawable.gps_not_fixed);
                    accuracyText.setText(activity.getString(R.string.gps_hint_precision,
                            (int)lastPrecision));
                }
                if (accuracyImageHint.getVisibility() == View.INVISIBLE) {
                    accuracyImageHint.setVisibility(View.VISIBLE);
                }
                long now = System.currentTimeMillis();
                if(now - activity.lastMapLocationRefresh >= REFRESH_MAP_LOCATION_RATE) {
                    activity.getMapControler().updateLocationMarker(new MapFragment.LatLng(location.getLatitude(), location.getLongitude()), location.getAccuracy());
                    activity.lastMapLocationRefresh = now;
                }
            } else {
                accuracyImageHint.setImageResource(R.drawable.gps_off);
                accuracyText.setText(R.string.no_gps_hint);
            }
            // Update current location of user
            final double leq = activity.measurementService.getAudioProcess().getLeq(false);
            activity.setData(activity.measurementService.getAudioProcess().getLeq(false));
            // Change the text and the textcolor in the corresponding textview
            // for the Leqi value
            LeqStats leqStats =
                    activity.measurementService.getFastLeqStats();
            final TextView mTextView = (TextView) activity.findViewById(R.id.textView_value_SL_i);
            formatdBA(leq, mTextView);
            if(activity.measurementService.getLeqAdded() != 0) {
                // Stats are only available if the recording of previous leq are activated
                final TextView valueMin = (TextView) activity.findViewById(R.id
                        .textView_value_Min_i);
                formatdBA(leqStats.getLeqMin(), valueMin);
                final TextView valueMax = (TextView) activity.findViewById(R.id
                        .textView_value_Max_i);
                formatdBA(leqStats.getLeqMax(), valueMax);
                final TextView valueMean = (TextView) activity.findViewById(R.id
                        .textView_value_Mean_i);
                formatdBA(leqStats.getLeqMean(), valueMean);
            }


            int nc = MeasurementActivity.getNEcatColors(leq);    // Choose the color category in
            // function of the sound level
            mTextView.setTextColor(activity.NE_COLORS[nc]);

            // Spectrum data
            activity.updateSpectrumGUI();
        } else {
            activity.initGuiState();
        }

        // Debug processing time
    } finally {
        activity.isComputingMovingLeq.set(false);
    }
}