Search in sources :

Example 6 with DeskClock

use of org.omnirom.deskclock.DeskClock in project android_packages_apps_OmniClock by omnirom.

the class TimerFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    final DeskClock activity = (DeskClock) getActivity();
    activity.registerPageChangedListener(this);
    if (mAdapter == null) {
        mAdapter = new TimerFragmentAdapter(getChildFragmentManager(), mPrefs);
    }
    mAdapter.populateTimersFromPref();
    // xxx
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOnPageChangeListener(mOnPageChangeListener);
    mPrefs.registerOnSharedPreferenceChangeListener(this);
    // Clear the flag set in the notification and alert because the adapter was just
    // created and is thus in sync with the database
    final SharedPreferences.Editor editor = mPrefs.edit();
    if (mPrefs.getBoolean(Timers.FROM_NOTIFICATION, false)) {
        editor.putBoolean(Timers.FROM_NOTIFICATION, false);
    }
    if (mPrefs.getBoolean(Timers.FROM_ALERT, false)) {
        editor.putBoolean(Timers.FROM_ALERT, false);
    }
    editor.apply();
    boolean goToSetUpView;
    // Process extras that were sent to the app and were intended for the timer fragment
    final Intent newIntent = getActivity().getIntent();
    if (newIntent != null && newIntent.getBooleanExtra(TimerFullScreenFragment.GOTO_SETUP_VIEW, false)) {
        goToSetUpView = true;
    } else if (newIntent != null && newIntent.getBooleanExtra(Timers.FIRST_LAUNCH_FROM_API_CALL, false)) {
        // We use this extra to identify if a. this activity is launched from api call,
        // and b. this fragment is resumed for the first time. If both are true,
        // we should show the timer view instead of setup view.
        goToSetUpView = false;
        // Show the first timer because that's the newly created one
        highlightPageIndicator(0);
        mViewPager.setCurrentItem(0);
        // Reset the extra to false to ensure when next time the fragment resume,
        // we no longer care if it's from api call or not.
        newIntent.putExtra(Timers.FIRST_LAUNCH_FROM_API_CALL, false);
    } else {
        if (mViewState != null) {
            final int currPage = mViewState.getInt(CURR_PAGE);
            mViewPager.setCurrentItem(currPage);
            highlightPageIndicator(currPage);
            final boolean hasPreviousInput = mViewState.getBoolean(KEY_SETUP_SELECTED, false);
            goToSetUpView = hasPreviousInput || mAdapter.getCount() == 0;
            if (goToSetUpView && activity.isTimerTab()) {
                mSetupView.restoreEntryState(mViewState, KEY_ENTRY_STATE);
            }
        } else {
            highlightPageIndicator(0);
            // If user was not previously using the setup, determine which view to go by count
            goToSetUpView = mAdapter.getCount() == 0;
        }
    }
    if (goToSetUpView) {
        goToSetUpView();
    } else {
        goToPagerView();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) DeskClock(org.omnirom.deskclock.DeskClock)

Example 7 with DeskClock

use of org.omnirom.deskclock.DeskClock in project android_packages_apps_OmniClock by omnirom.

the class TimerFragment method setLeftRightButtonAppearance.

@Override
public void setLeftRightButtonAppearance() {
    final DeskClock activity = (DeskClock) getActivity();
    if (mLeftButton == null || mRightButton == null || !activity.isTimerTab()) {
        return;
    }
    mLeftButton.setEnabled(true);
    mRightButton.setEnabled(true);
    boolean leftVisible = false;
    if (mLeftButtonSticky) {
        leftVisible = true;
    } else if (mLastView == mSetupView) {
        leftVisible = mAdapter.getCount() != 0;
    } else {
        leftVisible = true;
    }
    boolean rightVisible = mLastView == mTimerView;
    if (leftVisible) {
        mLeftButton.setImageResource(org.omnirom.deskclock.R.drawable.ic_cancel);
        mLeftButton.setContentDescription(getString(org.omnirom.deskclock.R.string.timer_delete));
    }
    if (rightVisible) {
        mRightButton.setImageResource(org.omnirom.deskclock.R.drawable.ic_fab_plus);
        mRightButton.setContentDescription(getString(org.omnirom.deskclock.R.string.timer_add_timer));
    }
    final AnimatorSet animatorSet = getButtonTransition(leftVisible, rightVisible);
    if (animatorSet != null) {
        animatorSet.start();
    }
}
Also used : AnimatorSet(android.animation.AnimatorSet) DeskClock(org.omnirom.deskclock.DeskClock)

Example 8 with DeskClock

use of org.omnirom.deskclock.DeskClock in project android_packages_apps_OmniClock by omnirom.

the class TimerFullScreenFragment method onPause.

@Override
public void onPause() {
    if (getActivity() instanceof DeskClock) {
        ((DeskClock) getActivity()).unregisterPageChangedListener(this);
    }
    super.onPause();
    stopClockTicks();
    if (mAdapter != null) {
        mAdapter.saveGlobalState();
    }
    mPrefs.unregisterOnSharedPreferenceChangeListener(this);
    // This is called because the lock screen was activated, the window stay
    // active under it and when we unlock the screen, we see the old time for
    // a fraction of a second.
    View v = getView();
    if (v != null) {
        v.setVisibility(View.INVISIBLE);
    }
}
Also used : StaggeredGridView(org.omnirom.deskclock.widget.sgv.StaggeredGridView) TimerSetupView(org.omnirom.deskclock.TimerSetupView) View(android.view.View) TextView(android.widget.TextView) DeskClock(org.omnirom.deskclock.DeskClock)

Example 9 with DeskClock

use of org.omnirom.deskclock.DeskClock in project android_packages_apps_OmniClock by omnirom.

the class TimerItemFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final View v = mTimerObj.mView;
    if (v == null) {
        return;
    }
    final FrameLayout labelLayout = (FrameLayout) v.findViewById(org.omnirom.deskclock.R.id.timer_label);
    final TextView labelPlaceholder = (TextView) v.findViewById(org.omnirom.deskclock.R.id.timer_label_placeholder);
    final TextView labelText = (TextView) v.findViewById(org.omnirom.deskclock.R.id.timer_label_text);
    if (TextUtils.isEmpty(mTimerObj.mLabel)) {
        labelText.setVisibility(View.GONE);
        labelPlaceholder.setVisibility(View.VISIBLE);
    } else {
        labelText.setText(mTimerObj.mLabel);
        labelText.setVisibility(View.VISIBLE);
        labelPlaceholder.setVisibility(View.GONE);
    }
    final Activity activity = getActivity();
    if (activity instanceof DeskClock) {
        labelLayout.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                onLabelPressed(mTimerObj);
            }
        });
    } else {
        labelPlaceholder.setVisibility(View.INVISIBLE);
    }
}
Also used : FrameLayout(android.widget.FrameLayout) Activity(android.app.Activity) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) DeskClock(org.omnirom.deskclock.DeskClock)

Example 10 with DeskClock

use of org.omnirom.deskclock.DeskClock in project android_packages_apps_OmniClock by omnirom.

the class StopwatchFragment method onPause.

@Override
public void onPause() {
    if (mState == Stopwatches.STOPWATCH_RUNNING) {
        stopUpdateThread();
        // This is called because the lock screen was activated, the window stay
        // active under it and when we unlock the screen, we see the old time for
        // a fraction of a second.
        View v = getView();
        if (v != null) {
            v.setVisibility(View.INVISIBLE);
        }
    }
    // The stopwatch must keep running even if the user closes the app so save stopwatch state
    // in shared prefs
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    prefs.unregisterOnSharedPreferenceChangeListener(this);
    writeToSharedPref(prefs);
    mTime.writeToSharedPref(prefs, "sw");
    mTimeText.blinkTimeStr(false);
    ((DeskClock) getActivity()).unregisterPageChangedListener(this);
    releaseWakeLock();
    super.onPause();
}
Also used : SharedPreferences(android.content.SharedPreferences) CountingTimerView(org.omnirom.deskclock.timer.CountingTimerView) View(android.view.View) CircleTimerView(org.omnirom.deskclock.CircleTimerView) TextView(android.widget.TextView) ListView(android.widget.ListView) DeskClock(org.omnirom.deskclock.DeskClock)

Aggregations

DeskClock (org.omnirom.deskclock.DeskClock)10 View (android.view.View)5 TextView (android.widget.TextView)5 SharedPreferences (android.content.SharedPreferences)4 AnimatorSet (android.animation.AnimatorSet)3 Intent (android.content.Intent)2 OnClickListener (android.view.View.OnClickListener)2 ListView (android.widget.ListView)2 CircleTimerView (org.omnirom.deskclock.CircleTimerView)2 TimerSetupView (org.omnirom.deskclock.TimerSetupView)2 CountingTimerView (org.omnirom.deskclock.timer.CountingTimerView)2 StaggeredGridView (org.omnirom.deskclock.widget.sgv.StaggeredGridView)2 Activity (android.app.Activity)1 Handler (android.os.Handler)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 FrameLayout (android.widget.FrameLayout)1