Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08bb3cf6 authored by Justin Klaassen's avatar Justin Klaassen
Browse files

resolve merge conflicts of 1cf96ee5 to ub-deskclock-escargatoire.

Change-Id: I38a50e55e85aff0a23476da5cd7bdee2dbf7b084
parents a9489547 1cf96ee5
Loading
Loading
Loading
Loading
+23 −19
Original line number Diff line number Diff line
@@ -17,26 +17,30 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">
    <group android:id="@+id/menu_items">
        <item android:id="@+id/menu_item_search"
            android:title="@android:string/search_go"
        <item
            android:id="@+id/menu_item_search"
            android:icon="@android:drawable/ic_menu_search"
            android:imeOptions="actionSearch"
            android:orderInCategory="1"
            app:showAsAction="ifRoom"
            app:actionViewClass="android.support.v7.widget.SearchView" />
        <item android:id="@+id/menu_item_sort"
            android:title="@android:string/search_go"
            android:visible="false"
            app:actionViewClass="android.support.v7.widget.SearchView"
            app:showAsAction="ifRoom"/>
        <item
            android:id="@+id/menu_item_sort"
            android:title="@string/menu_item_sort_by_gmt_offset"
            app:showAsAction="never"/>
        <item android:id="@+id/menu_item_night_mode"
            android:title="@string/menu_item_night_mode"
            android:icon="@android:drawable/ic_menu_preferences"/>
        <item android:id="@+id/menu_item_settings"
            android:title="@string/menu_item_settings"
            android:icon="@android:drawable/ic_menu_preferences"/>
        <item android:id="@+id/menu_item_help"
            android:title="@string/menu_item_help"
            android:icon="@android:drawable/ic_menu_preferences"/>
        <item
            android:id="@+id/menu_item_night_mode"
            android:icon="@android:drawable/ic_menu_preferences"
            android:title="@string/menu_item_night_mode"/>
        <item
            android:id="@+id/menu_item_settings"
            android:icon="@android:drawable/ic_menu_preferences"
            android:title="@string/menu_item_settings"/>
        <item
            android:id="@+id/menu_item_help"
            android:icon="@android:drawable/ic_menu_preferences"
            android:title="@string/menu_item_help"/>
    </group>
</menu>
 No newline at end of file

+53 −49
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ public class DeskClock extends BaseActivity
        // not the most recent launch was via a dock event
        setIntent(newIntent);

        // Timer receiver may ask to go to the timers fragment if a timer expired.
        // Honor the tab requested by the intent, if any.
        int tab = newIntent.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1);
        if (tab != -1 && mTabLayout != null) {
            mTabLayout.getTabAt(tab).select();
@@ -108,45 +108,6 @@ public class DeskClock extends BaseActivity
        }
    }

    private void initViews() {
        setContentView(R.layout.desk_clock);
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
        mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
        mFab = (ImageView) findViewById(R.id.fab);
        mLeftButton = (ImageButton) findViewById(R.id.left_button);
        mRightButton = (ImageButton) findViewById(R.id.right_button);
        if (mTabsAdapter == null) {
            mViewPager = (RtlViewPager) findViewById(R.id.desk_clock_pager);
            // Keep all four tabs to minimize jank.
            mViewPager.setOffscreenPageLimit(3);
            // Set Accessibility Delegate to null so ViewPager doesn't intercept movements and
            // prevent the fab from being selected.
            mViewPager.setAccessibilityDelegate(null);
            mTabsAdapter = new TabsAdapter(this, mViewPager);
            createTabs();
            mTabLayout.setOnTabSelectedListener(new ViewPagerOnTabSelectedListener(mViewPager));
        }

        mFab.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                getSelectedFragment().onFabClick(view);
            }
        });
        mLeftButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                getSelectedFragment().onLeftButtonClick(view);
            }
        });
        mRightButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                getSelectedFragment().onRightButtonClick(view);
            }
        });
    }

    @VisibleForTesting
    DeskClockFragment getSelectedFragment() {
        return (DeskClockFragment) mTabsAdapter.getItem(mSelectedTab);
@@ -178,10 +139,6 @@ public class DeskClock extends BaseActivity
    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        mActionBarMenuManager.addMenuItemController(new SettingMenuItemController(this))
                .addMenuItemController(MenuItemControllerFactory.getInstance()
                        .buildMenuItemControllers(this))
                .addMenuItemController(nightModeMenuItemController);
        setVolumeControlStream(AudioManager.STREAM_ALARM);

        if (icicle != null) {
@@ -195,15 +152,62 @@ public class DeskClock extends BaseActivity
                    false /* animate */);
        }

        // Timer receiver may ask the app to go to the timer fragment if a timer expired
        Intent i = getIntent();
        if (i != null) {
            int tab = i.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1);
        // Honor the tab requested by the intent, if any.
        final Intent intent = getIntent();
        if (intent != null) {
            int tab = intent.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1);
            if (tab != -1) {
                mSelectedTab = tab;
            }
        }
        initViews();

        setContentView(R.layout.desk_clock);
        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
        mFab = (ImageView) findViewById(R.id.fab);
        mLeftButton = (ImageButton) findViewById(R.id.left_button);
        mRightButton = (ImageButton) findViewById(R.id.right_button);
        if (mTabsAdapter == null) {
            mViewPager = (RtlViewPager) findViewById(R.id.desk_clock_pager);
            // Keep all four tabs to minimize jank.
            mViewPager.setOffscreenPageLimit(3);
            // Set Accessibility Delegate to null so ViewPager doesn't intercept movements and
            // prevent the fab from being selected.
            mViewPager.setAccessibilityDelegate(null);
            mTabsAdapter = new TabsAdapter(this, mViewPager);
            createTabs();
            mTabLayout.setOnTabSelectedListener(new ViewPagerOnTabSelectedListener(mViewPager));
        }

        mFab.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                getSelectedFragment().onFabClick(view);
            }
        });
        mLeftButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                getSelectedFragment().onLeftButtonClick(view);
            }
        });
        mRightButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                getSelectedFragment().onRightButtonClick(view);
            }
        });

        // Configure the menu item controllers.
        mActionBarMenuManager.addMenuItemController(new SettingMenuItemController(this))
                .addMenuItemController(MenuItemControllerFactory.getInstance()
                        .buildMenuItemControllers(this))
                .addMenuItemController(nightModeMenuItemController);

        // Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu
        // inflation occurs *after* the initial draw and a second layout pass adds in the menu.
        onCreateOptionsMenu(toolbar.getMenu());

        // We need to update the system next alarm time on app startup because the
        // user might have clear our data.
+34 −32
Original line number Diff line number Diff line
@@ -133,20 +133,25 @@ public final class SettingsActivity extends BaseActivity
    public static class PrefsFragment extends PreferenceFragment
            implements Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener {

        private static CharSequence[][] mTimezones;
        private long mTime;

        @Override
        public void onCreatePreferences(Bundle bundle, String s) {
        public void onCreatePreferences(Bundle bundle, String rootKey) {
            addPreferencesFromResource(R.xml.settings);
            loadTimeZoneList();
        }

        @Override
        public void onResume() {
            super.onResume();
            loadTimeZoneList();
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);

            // By default, do not recreate the DeskClock activity
            getActivity().setResult(RESULT_CANCELED);

        }

        @Override
        public void onResume() {
            super.onResume();

            refresh();
        }

@@ -216,7 +221,7 @@ public final class SettingsActivity extends BaseActivity

            switch (pref.getKey()) {
                case KEY_DATE_TIME:
                    Intent dialogIntent = new Intent(Settings.ACTION_DATE_SETTINGS);
                    final Intent dialogIntent = new Intent(Settings.ACTION_DATE_SETTINGS);
                    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(dialogIntent);
                    return true;
@@ -240,20 +245,13 @@ public final class SettingsActivity extends BaseActivity
        }

        /**
         * Reconstruct the timezone list. We don't want to do this unnecessary, so proceed only if
         * this is the initial load or the locale has changed since the last load.
         * Reconstruct the timezone list.
         */
        private void loadTimeZoneList() {
            final Locale currentLocale = getResources().getConfiguration().locale;
            final Context context = getActivity();
            if (mTimezones == null || Utils.getTimezoneLocale(context) != currentLocale) {
                mTime = System.currentTimeMillis();
                mTimezones = getAllTimezones();
                Utils.setTimezoneLocale(context, currentLocale);
            }
            final CharSequence[][] timezones = getAllTimezones();
            final ListPreference homeTimezonePref = (ListPreference) findPreference(KEY_HOME_TZ);
            homeTimezonePref.setEntryValues(mTimezones[0]);
            homeTimezonePref.setEntries(mTimezones[1]);
            homeTimezonePref.setEntryValues(timezones[0]);
            homeTimezonePref.setEntries(timezones[1]);
            homeTimezonePref.setSummary(homeTimezonePref.getEntry());
            homeTimezonePref.setOnPreferenceChangeListener(this);
        }
@@ -267,21 +265,24 @@ public final class SettingsActivity extends BaseActivity
         * @return double array of tz ids and tz names
         */
        public CharSequence[][] getAllTimezones() {
            Resources resources = this.getResources();
            String[] ids = resources.getStringArray(R.array.timezone_values);
            String[] labels = resources.getStringArray(R.array.timezone_labels);
            final Resources res = getResources();
            final String[] ids = res.getStringArray(R.array.timezone_values);
            final String[] labels = res.getStringArray(R.array.timezone_labels);

            int minLength = ids.length;
            if (ids.length != labels.length) {
                minLength = Math.min(minLength, labels.length);
                LogUtils.e("Timezone ids and labels have different length!");
            }
            List<TimeZoneRow> timezones = new ArrayList<>();

            final long currentTimeMillis = System.currentTimeMillis();
            final List<TimeZoneRow> timezones = new ArrayList<>(minLength);
            for (int i = 0; i < minLength; i++) {
                timezones.add(new TimeZoneRow(ids[i], labels[i]));
                timezones.add(new TimeZoneRow(ids[i], labels[i], currentTimeMillis));
            }
            Collections.sort(timezones);

            CharSequence[][] timeZones = new CharSequence[2][timezones.size()];
            final CharSequence[][] timeZones = new CharSequence[2][timezones.size()];
            int i = 0;
            for (TimeZoneRow row : timezones) {
                timeZones[0][i] = row.mId;
@@ -354,18 +355,19 @@ public final class SettingsActivity extends BaseActivity
            fragment.show(getFragmentManager(), PREFERENCE_DIALOG_FRAGMENT_TAG);
        }

        private class TimeZoneRow implements Comparable<TimeZoneRow> {
        private static class TimeZoneRow implements Comparable<TimeZoneRow> {

            private static final boolean SHOW_DAYLIGHT_SAVINGS_INDICATOR = false;

            public final String mId;
            public final String mDisplayName;
            public final int mOffset;

            public TimeZoneRow(String id, String name) {
            public TimeZoneRow(String id, String name, long currentTimeMillis) {
                final TimeZone tz = TimeZone.getTimeZone(id);
                final boolean useDaylightTime = tz.useDaylightTime();
                mId = id;
                TimeZone tz = TimeZone.getTimeZone(id);
                boolean useDaylightTime = tz.useDaylightTime();
                mOffset = tz.getOffset(mTime);
                mOffset = tz.getOffset(currentTimeMillis);
                mDisplayName = buildGmtDisplayName(name, useDaylightTime);
            }

@@ -375,8 +377,8 @@ public final class SettingsActivity extends BaseActivity
            }

            public String buildGmtDisplayName(String displayName, boolean useDaylightTime) {
                int p = Math.abs(mOffset);
                StringBuilder name = new StringBuilder("(GMT");
                final int p = Math.abs(mOffset);
                final StringBuilder name = new StringBuilder("(GMT");
                name.append(mOffset < 0 ? '-' : '+');

                name.append(p / DateUtils.HOUR_IN_MILLIS);