Example usage for android.view Gravity START

List of usage examples for android.view Gravity START

Introduction

In this page you can find the example usage for android.view Gravity START.

Prototype

int START

To view the source code for android.view Gravity START.

Click Source Link

Document

Push object to x-axis position at the start of its container, not changing its size.

Usage

From source file:com.android.mail.ui.AbstractActivityController.java

/**
 * The application can be started from the following entry points:
 * <ul>//from  w  ww .  j  av  a2  s  . co m
 *     <li>Launcher: you tap on the Gmail icon in the launcher. This is what most users think of
 *         as Starting the app?.</li>
 *     <li>Shortcut: Users can make a shortcut to take them directly to a label.</li>
 *     <li>Widget: Shows the contents of a synced label, and allows:
 *     <ul>
 *         <li>Viewing the list (tapping on the title)</li>
 *         <li>Composing a new message (tapping on the new message icon in the title. This
 *         launches the {@link ComposeActivity}.
 *         </li>
 *         <li>Viewing a single message (tapping on a list element)</li>
 *     </ul>
 *
 *     </li>
 *     <li>Tapping on a notification:
 *     <ul>
 *         <li>Shows message list if more than one message</li>
 *         <li>Shows the conversation if the notification is for a single message</li>
 *     </ul>
 *     </li>
 *     <li>...and most importantly, the activity life cycle can tear down the application and
 *     restart it:
 *     <ul>
 *         <li>Rotate the application: it is destroyed and recreated.</li>
 *         <li>Navigate away, and return from recent applications.</li>
 *     </ul>
 *     </li>
 *     <li>Add a new account: fires off an intent to add an account,
 *     and returns in {@link #onActivityResult(int, int, android.content.Intent)} .</li>
 *     <li>Re-authenticate your account: again returns in onActivityResult().</li>
 *     <li>Composing can happen from many entry points: third party applications fire off an
 *     intent to compose email, and launch directly into the {@link ComposeActivity}
 *     .</li>
 * </ul>
 * {@inheritDoc}
 */
@Override
public void onCreate(Bundle savedState) {
    initializeActionBar();
    initializeDevLoggingService();
    // Allow shortcut keys to function for the ActionBar and menus.
    mActivity.setDefaultKeyMode(Activity.DEFAULT_KEYS_SHORTCUT);
    mResolver = mActivity.getContentResolver();
    mNewEmailReceiver = new SuppressNotificationReceiver();
    mRecentFolderList.initialize(mActivity);
    mVeiledMatcher.initialize(this);

    mFloatingComposeButton = mActivity.findViewById(R.id.compose_button);
    mFloatingComposeButton.setOnClickListener(this);

    if (isDrawerEnabled()) {
        mDrawerToggle = new ActionBarDrawerToggle(mActivity, mDrawerContainer, R.string.drawer_open,
                R.string.drawer_close);
        mDrawerContainer.setDrawerListener(mDrawerListener);
        mDrawerContainer.setDrawerShadow(mContext.getResources().getDrawable(R.drawable.drawer_shadow),
                Gravity.START);

        // Disable default drawer indicator as we are setting the drawer indicator icons.
        // TODO(shahrk): Once we can disable/enable drawer animation, go back to using
        // drawer indicators.
        mDrawerToggle.setDrawerIndicatorEnabled(false);
        mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_menu_wht_24dp);
    } else {
        final ActionBar ab = mActivity.getSupportActionBar();
        ab.setHomeAsUpIndicator(R.drawable.ic_menu_wht_24dp);
        ab.setHomeActionContentDescription(R.string.drawer_open);
        ab.setDisplayHomeAsUpEnabled(true);
    }

    // All the individual UI components listen for ViewMode changes. This
    // simplifies the amount of logic in the AbstractActivityController, but increases the
    // possibility of timing-related bugs.
    mViewMode.addListener(this);
    mPagerController = new ConversationPagerController(mActivity, this);
    mToastBar = findActionableToastBar(mActivity);
    attachActionBar();

    mDrawIdler.setRootView(mActivity.getWindow().getDecorView());

    final Intent intent = mActivity.getIntent();

    mSearchViewController = new MaterialSearchViewController(mActivity, this, intent, savedState);
    addConversationListLayoutListener(mSearchViewController);

    // Immediately handle a clean launch with intent, and any state restoration
    // that does not rely on restored fragments or loader data
    // any state restoration that relies on those can be done later in
    // onRestoreInstanceState, once fragments are up and loader data is re-delivered
    if (savedState != null) {
        if (savedState.containsKey(SAVED_ACCOUNT)) {
            setAccount((Account) savedState.getParcelable(SAVED_ACCOUNT));
        }
        if (savedState.containsKey(SAVED_FOLDER)) {
            final Folder folder = savedState.getParcelable(SAVED_FOLDER);
            final String query = savedState.getString(SAVED_QUERY, null);
            setListContext(folder, query);
        }
        if (savedState.containsKey(SAVED_ACTION)) {
            mDialogAction = savedState.getInt(SAVED_ACTION);
        }
        mDialogFromSelectedSet = savedState.getBoolean(SAVED_ACTION_FROM_SELECTED, false);
        mViewMode.handleRestore(savedState);
    } else if (intent != null) {
        handleIntent(intent);
    }
    // Create the accounts loader; this loads the account switch spinner.
    mActivity.getLoaderManager().initLoader(LOADER_ACCOUNT_CURSOR, Bundle.EMPTY, mAccountCallbacks);
}

From source file:org.anurag.file.quest.FileQuestHD.java

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {

    case R.id.open_drawer_menu:
        if (!Constants.LONG_CLICK[pager.getCurrentItem()])
            drawer.openDrawer(Gravity.START);
        break;//ww  w.  jav  a  2 s.c o m
    }
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();

    Account realAccount = null;/*from  w w  w  . j  a v  a2 s .  c  o  m*/

    FolderInfoHolder folder = null;

    if (mListView.getItemAtPosition(menuInfo.position) != null) {

        if (menuInfo.position - 1 > mAdapter_Accounts.getCount() - 5) {

            if (0 < menuInfo.position - (mAdapter_Accounts.getCount() + 4)) {

                folder = (FolderInfoHolder) mAdapter
                        .getItem(menuInfo.position - (mAdapter_Accounts.getCount() + 6));

            } else {
                folder = (FolderInfoHolder) mAdapter.getItem(menuInfo.position);

            }

        } else {

            folder = (FolderInfoHolder) mAdapter.getItem(menuInfo.position);

            if (menuInfo != null && mListView.getItemAtPosition(menuInfo.position) != null) {

                mSelectedContextAccount = (BaseAccount) getListView().getItemAtPosition(menuInfo.position);
            }

            if (mSelectedContextAccount instanceof Account) {
                realAccount = (Account) mSelectedContextAccount;

            }

        }

    }

    switch (item.getItemId()) {
    case R.id.clear_local_folder:
        onClearFolder(mAccount, folder.name);
        break;
    case R.id.refresh_folder:
        checkMail(folder);
        break;
    case R.id.folder_settings:
        mDrawerLayout.closeDrawer(Gravity.START);
        FolderSettings.actionSettings(this, mAccount, folder.name);

        break;
    case R.id.delete_account:
        onDeleteAccount(realAccount);

        break;
    case R.id.account_settings:
        mDrawerLayout.closeDrawer(Gravity.START);
        onEditAccount(realAccount);

        break;
    case R.id.activate:
        onActivateAccount(realAccount);

        break;
    case R.id.clear_pending:
        onClearCommands(realAccount);

        break;
    case R.id.empty_trash:
        onEmptyTrash(realAccount);

        break;
    case R.id.clear:
        onClear(realAccount);

        break;
    case R.id.recreate:
        onRecreate(realAccount);

        break;
    case R.id.export:
        onExport(false, realAccount);

        break;
    case R.id.move_up:
        onMove(realAccount, true);

        break;
    case R.id.move_down:
        onMove(realAccount, false);

        break;
    }

    return super.onContextItemSelected(item);

}

From source file:org.de.jmg.learn._MainActivity.java

public void SetViewsToVokMode() {
    if (_mBackgroundBack != null)
        _MeaningBG = _mBackgroundBack;// w w  w.j ava  2  s.c o m
    // _txtWord.setMaxLines(3);
    // _txtWord.setLines(1);
    _txtWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (60 * scale));
    _txtWord.setHorizontallyScrolling(false);

    // _txtKom.setMaxLines(3);
    // _txtKom.setLines(2);
    _txtKom.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (35 * scale));
    _txtKom.setHorizontallyScrolling(false);

    _txtMeaning1.setLines(1);
    _txtMeaning1.setSingleLine();
    _txtMeaning1.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (40 * scale));
    _txtMeaning1.setMaxLines(3);
    _txtMeaning1.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    _txtMeaning1.setHorizontallyScrolling(false);
    //_txtMeaning1.setAutoLinkMask(0);
    if (_originalMovementmethod != null
            && _txtMeaning1.getMovementMethod() == LinkMovementMethod.getInstance()) {
        _txtMeaning1.setMovementMethod(_originalMovementmethod);
    }
    //_txtMeaning1.setVerticalScrollBarEnabled(false);

    //_txtMeaning1.requestFocus();
    //InputMethodManager Imn = (InputMethodManager) _main.getSystemService(Context.INPUT_METHOD_SERVICE);
    //Imn.showSoftInputFromInputMethod(_txtMeaning1.getWindowToken(), 0);

    //_txtMeaning1.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);

    _txtMeaning2.setVisibility(View.VISIBLE);
    _txtMeaning2.setLines(1);
    _txtMeaning2.setSingleLine();
    _txtMeaning2.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (40 * scale));
    _txtMeaning2.setMaxLines(3);
    _txtMeaning2.setHorizontallyScrolling(false);

    _txtMeaning3.setVisibility(View.VISIBLE);
    _txtMeaning3.setLines(1);
    _txtMeaning3.setSingleLine();
    _txtMeaning3.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (40 * scale));
    _txtMeaning3.setMaxLines(3);
    _txtMeaning3.setHorizontallyScrolling(false);

}

From source file:org.de.jmg.learn._MainActivity.java

public void SetViewsToCardmode() {
    // _txtWord.setMaxLines(3);
    // _txtWord.setLines(2);
    // _txtKom.setMaxLines(3);
    // _txtKom.setLines(2);

    _txtWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (40 * scale));
    _txtKom.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (30 * scale));

    _txtMeaning1.setSingleLine(false);//from www . j  a  v a 2 s.co  m
    _txtMeaning1.setMaxLines(1000);
    _txtMeaning1.setLines(16);
    //_txtMeaning1.setMinLines(2);
    _txtMeaning1.setGravity(Gravity.TOP | Gravity.START);
    _txtMeaning1.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (25 * scale));
    //_txtMeaning1.requestFocus();
    //InputMethodManager Imn = (InputMethodManager) _main.getSystemService(Context.INPUT_METHOD_SERVICE);
    //Imn.hideSoftInputFromInputMethod(_txtMeaning1.getWindowToken(), 0);
    if (_originalMovementmethod == null)
        _originalMovementmethod = _txtMeaning1.getMovementMethod();
    //_txtMeaning1.setAutoLinkMask(Linkify.ALL);
    if (_txtMeaning1.getMovementMethod() != LinkMovementMethod.getInstance())
        _txtMeaning1.setMovementMethod(LinkMovementMethod.getInstance());
    //_txtMeaning1.setVerticalScrollBarEnabled(true);
    //_txtMeaning1.setInputType(InputType.TYPE_NULL);
    // _txtMeaning1.setImeOptions(EditorInfo.IME_NULL);
    // _txtMeaning1.setImeActionLabel(null, KeyEvent.KEYCODE_ENTER);
    // _txtMeaning1.setImeActionLabel("Custom text",
    // KeyEvent.KEYCODE_ENTER);
    _txtMeaning2.setVisibility(View.GONE);
    _txtMeaning3.setVisibility(View.GONE);

    if (_MeaningBG != null)
        _mBackgroundBack = _MeaningBG;
    _MeaningBG = null;
    //if (_mBackgroundBack!=null) _MeaningBG = _mBackgroundBack;

}

From source file:xyz.klinker.blur.launcher3.Launcher.java

@Override
public void onRestoreInstanceState(Bundle state) {
    super.onRestoreInstanceState(state);
    for (int page : mSynchronouslyBoundPages) {
        mWorkspace.restoreInstanceStateForChild(page);
    }//from   w w w . j a v  a  2s.  c om

    if (mLauncherDrawer.isDrawerOpen(Gravity.START)) {
        if (Utilities.ATLEAST_MARSHMALLOW) {
            mLauncherDrawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        if (Utilities.ATLEAST_LOLLIPOP) {
            ValueAnimator animator = ValueAnimator.ofArgb(Color.TRANSPARENT, Color.parseColor("#22000000"));
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    int color = (Integer) valueAnimator.getAnimatedValue();
                    getWindow().setNavigationBarColor(color);
                    getWindow().setStatusBarColor(color);
                }
            });
            animator.setDuration(300);
            animator.start();
        }
    }
}

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

@Override
public void onBackPressed() {
    if (MainConfiguration.ALLOW_DRAWER && this.drawerLayout.isDrawerOpen(Gravity.START)) {
        this.drawerLayout.closeDrawer(Gravity.START);
        return;/*  ww w. j  a  v a 2  s . c  o m*/
    }

    if (isAllAppsVisible()) {
        showWorkspace(true);
    } else if (mWorkspace.getOpenFolder() != null) {
        Folder openFolder = mWorkspace.getOpenFolder();
        if (openFolder.isEditingName()) {
            openFolder.dismissEditingName();
        } else {
            closeFolder();
        }
    } else {
        mWorkspace.exitWidgetResizeMode();

        // Back button is a no-op here, but give at least some feedback for the button press
        mWorkspace.showOutlinesTemporarily();
    }
}

From source file:com.tct.mail.ui.AbstractActivityController.java

/**
 * The application can be started from the following entry points:
 * <ul>/*from www  .  j  av  a 2  s .  co  m*/
 *     <li>Launcher: you tap on the Gmail icon in the launcher. This is what most users think of
 *         as Starting the app?.</li>
 *     <li>Shortcut: Users can make a shortcut to take them directly to a label.</li>
 *     <li>Widget: Shows the contents of a synced label, and allows:
 *     <ul>
 *         <li>Viewing the list (tapping on the title)</li>
 *         <li>Composing a new message (tapping on the new message icon in the title. This
 *         launches the {@link ComposeActivity}.
 *         </li>
 *         <li>Viewing a single message (tapping on a list element)</li>
 *     </ul>
 *
 *     </li>
 *     <li>Tapping on a notification:
 *     <ul>
 *         <li>Shows message list if more than one message</li>
 *         <li>Shows the conversation if the notification is for a single message</li>
 *     </ul>
 *     </li>
 *     <li>...and most importantly, the activity life cycle can tear down the application and
 *     restart it:
 *     <ul>
 *         <li>Rotate the application: it is destroyed and recreated.</li>
 *         <li>Navigate away, and return from recent applications.</li>
 *     </ul>
 *     </li>
 *     <li>Add a new account: fires off an intent to add an account,
 *     and returns in {@link #onActivityResult(int, int, android.content.Intent)} .</li>
 *     <li>Re-authenticate your account: again returns in onActivityResult().</li>
 *     <li>Composing can happen from many entry points: third party applications fire off an
 *     intent to compose email, and launch directly into the {@link ComposeActivity}
 *     .</li>
 * </ul>
 * {@inheritDoc}
 */
@SuppressLint("NewApi")
@Override
public boolean onCreate(Bundle savedState) {
    initializeActionBar();
    initializeDevLoggingService();
    // Allow shortcut keys to function for the ActionBar and menus.
    mActivity.setDefaultKeyMode(Activity.DEFAULT_KEYS_SHORTCUT);
    mResolver = mActivity.getContentResolver();
    mNewEmailReceiver = new SuppressNotificationReceiver();
    mRecentFolderList.initialize(mActivity);
    mVeiledMatcher.initialize(this);

    mFloatingComposeButton = mActivity.findViewById(R.id.compose_button);

    //TS: ke.ma 2015-03-12 EMAIL BUGFIX-947440 ADD_S
    mFloatingComposeButton.setElevation(8);
    mFloatingComposeButton.setOutlineProvider(new ViewOutlineProvider() {

        @Override
        public void getOutline(View view, Outline outline) {
            // TODO Auto-generated method stub
            outline.setOval(0, 0, view.getWidth(), view.getWidth());
        }
    });
    //TS: ke.ma 2015-03-12 EMAIL BUGFIX-947440 ADD_E
    mFloatingComposeButton.setOnClickListener(this);

    if (isDrawerEnabled()) {
        mDrawerToggle = new ActionBarDrawerToggle(mActivity, mDrawerContainer,
                //                    false,
                //                    R.drawable.ic_drawer,
                R.string.drawer_open, R.string.drawer_close);
        mDrawerContainer.setDrawerListener(mDrawerListener);
        mDrawerContainer.setDrawerShadow(mContext.getResources().getDrawable(R.drawable.drawer_shadow),
                Gravity.START);

        mDrawerToggle.setDrawerIndicatorEnabled(isDrawerEnabled());
    } else {
        final ActionBar ab = mActivity.getSupportActionBar();
        ab.setHomeAsUpIndicator(R.drawable.ic_drawer);
        ab.setHomeActionContentDescription(R.string.drawer_open);
        ab.setDisplayHomeAsUpEnabled(true);
    }

    // All the individual UI components listen for ViewMode changes. This
    // simplifies the amount of logic in the AbstractActivityController, but increases the
    // possibility of timing-related bugs.
    mViewMode.addListener(this);
    mPagerController = new ConversationPagerController(mActivity, this);
    mToastBar = findActionableToastBar(mActivity);
    attachActionBar();

    mDrawIdler.setRootView(mActivity.getWindow().getDecorView());

    final Intent intent = mActivity.getIntent();

    // Immediately handle a clean launch with intent, and any state restoration
    // that does not rely on restored fragments or loader data
    // any state restoration that relies on those can be done later in
    // onRestoreInstanceState, once fragments are up and loader data is re-delivered
    if (savedState != null) {
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-S
        // restore check status for star toggle
        mCheckStatus = savedState.getBoolean(BUNDLE_CHECK_STATUS_KEY, false);
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-E
        /// TCT: restore global search tag.
        if (savedState.containsKey(SAVED_GLOBAL_SEARCH)) {
            mGlobalSearch = savedState.getBoolean(SAVED_GLOBAL_SEARCH);
            LogUtils.logFeature(LogTag.SEARCH_TAG, "onCreate restore mGlobalSearch [%s] ", mGlobalSearch);
        }
        if (savedState.containsKey(SAVED_ACCOUNT)) {
            setAccount((Account) savedState.getParcelable(SAVED_ACCOUNT));
        }
        if (savedState.containsKey(SAVED_FOLDER)) {
            final Folder folder = savedState.getParcelable(SAVED_FOLDER);
            /**
             * TCT: Restore the local search or global search instance:
             * 1. Restore the ConversationListContext from Bundle.
             * 2. Restore query if in global search mode.
             * 3. Update Local Search UI (ActionBarView)
             * @{
             */
            final Bundle bundle = savedState.getParcelable(SAVED_LOCAL_SEARCH);
            if (bundle != null) {
                final ConversationListContext convListContext = ConversationListContext.forBundle(bundle);
                mConvListContext = convListContext;
                LogUtils.logFeature(LogTag.SEARCH_TAG,
                        "onCreate restore ConverationListContext from saved instance [%s] ", mConvListContext);
            }
            String query = mConvListContext != null ? mConvListContext.getSearchQuery() : null;
            if (TextUtils.isEmpty(query) && mGlobalSearch) {
                query = intent.getStringExtra(SearchManager.QUERY);
                mConvListContext.setLocalSearch(true);
                mConvListContext.setSearchQueryText(query);
                LogUtils.logFeature(LogTag.SEARCH_TAG, "onCreate restore global search query [%s]",
                        mConvListContext);
            }
            setListContext(folder, query);
            if (mConvListContext.isLocalSearch()) {
                LogUtils.logFeature(LogTag.SEARCH_TAG, "[Local Search] Enter and execute local search [%s]",
                        query);
                mActionBarController.expandSearch(query, mConvListContext.getSearchField());
            }
            /** @} */
        }
        if (savedState.containsKey(SAVED_ACTION)) {
            mDialogAction = savedState.getInt(SAVED_ACTION);
        }
        mDialogFromSelectedSet = savedState.getBoolean(SAVED_ACTION_FROM_SELECTED, false);
        mViewMode.handleRestore(savedState);
    } else if (intent != null) {
        handleIntent(intent);
    }
    // Create the accounts loader; this loads the account switch spinner.
    mActivity.getLoaderManager().initLoader(LOADER_ACCOUNT_CURSOR, Bundle.EMPTY, mAccountCallbacks);
    return true;
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

@Override
public void onBackPressed() {
    if (mDisplayMode == DisplayMode.MESSAGE_VIEW && mMessageListWasDisplayed) {
        showMessageList();/*from   w w  w. j  a  v a  2 s. c o  m*/

    } else {
        super.onBackPressed();
    }
    mDrawerToggle.setDrawerIndicatorEnabled(true);

    mDrawerLayout.closeDrawer(Gravity.START);

    SharedPreferences.Editor localEditor1 = getSharedPreferences("return_to_main", Context.MODE_PRIVATE).edit();

    localEditor1.putString("fragment_to_start", "0");

    localEditor1.commit();

}

From source file:com.android.tv.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    /*//from   w w  w .j av a 2 s . c  om
     * The following keyboard keys map to these remote keys or "debug actions"
     *  - --------
     *  A KEYCODE_MEDIA_AUDIO_TRACK
     *  D debug: show debug options
     *  E updateChannelBannerAndShowIfNeeded
     *  I KEYCODE_TV_INPUT
     *  O debug: show display mode option
     *  P debug: togglePipView
     *  S KEYCODE_CAPTIONS: select subtitle
     *  W debug: toggle screen size
     *  V KEYCODE_MEDIA_RECORD debug: record the current channel for 30 sec
     *  X KEYCODE_BUTTON_X KEYCODE_PROG_BLUE debug: record current channel for a few minutes
     *  Y KEYCODE_BUTTON_Y KEYCODE_PROG_GREEN debug: Play a recording
     */
    if (SystemProperties.LOG_KEYEVENT.getValue()) {
        Log.d(TAG, "onKeyUp(" + keyCode + ", " + event + ")");
    }
    // If we are in the middle of channel change, finish it before showing overlays.
    finishChannelChangeIfNeeded();

    if (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
        showSearchActivity();
        return true;
    }
    switch (mOverlayManager.onKeyUp(keyCode, event)) {
    case KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY:
        return super.onKeyUp(keyCode, event);
    case KEY_EVENT_HANDLER_RESULT_HANDLED:
        return true;
    case KEY_EVENT_HANDLER_RESULT_NOT_HANDLED:
        return false;
    case KEY_EVENT_HANDLER_RESULT_PASSTHROUGH:
    default:
        // pass through
    }
    if (mSearchFragment.isVisible()) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            getFragmentManager().popBackStack();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // When the event is from onUnhandledInputEvent, onBackPressed is not automatically
        // called. Therefore, we need to explicitly call onBackPressed().
        onBackPressed();
        return true;
    }

    if (!mChannelTuner.areAllChannelsLoaded()) {
        // Now channel map is under loading.
    } else if (mChannelTuner.getBrowsableChannelCount() == 0) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_CHANNEL_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_CHANNEL_DOWN:
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_NUMPAD_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_E:
        case KeyEvent.KEYCODE_MENU:
            showSettingsFragment();
            return true;
        }
    } else {
        if (KeypadChannelSwitchView.isChannelNumberKey(keyCode)) {
            showKeypadChannelSwitchView(keyCode);
            return true;
        }
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (!PermissionUtils.hasModifyParentalControls(this)) {
                // TODO: support this feature for non-system LC app. b/23939816
                return true;
            }
            PinDialogFragment dialog = null;
            if (mTvView.isScreenBlocked()) {
                dialog = new PinDialogFragment(PinDialogFragment.PIN_DIALOG_TYPE_UNLOCK_CHANNEL,
                        new PinDialogFragment.ResultListener() {
                            @Override
                            public void done(boolean success) {
                                if (success) {
                                    unblockScreen(mTvView);
                                    mIsCurrentChannelUnblockedByUser = true;
                                }
                            }
                        });
            } else if (mTvView.getBlockedContentRating() != null) {
                final TvContentRating rating = mTvView.getBlockedContentRating();
                dialog = new PinDialogFragment(PinDialogFragment.PIN_DIALOG_TYPE_UNLOCK_PROGRAM,
                        new PinDialogFragment.ResultListener() {
                            @Override
                            public void done(boolean success) {
                                if (success) {
                                    mLastAllowedRatingForCurrentChannel = rating;
                                    mTvView.unblockContent(rating);
                                }
                            }
                        });
            }
            if (dialog != null) {
                mOverlayManager.showDialogFragment(PinDialogFragment.DIALOG_TAG, dialog, false);
            }
            return true;

        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_NUMPAD_ENTER:
        case KeyEvent.KEYCODE_E:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_MENU:
            if (event.isCanceled()) {
                // Ignore canceled key.
                // Note that if there's a TIS granted RECEIVE_INPUT_EVENT,
                // fallback keys not blacklisted will have FLAG_CANCELED.
                // See dispatchKeyEvent() for detail.
                return true;
            }
            if (keyCode != KeyEvent.KEYCODE_MENU) {
                updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_FORCE_SHOW);
            }
            if (keyCode != KeyEvent.KEYCODE_E) {
                mOverlayManager.showMenu(
                        mTvView.isRecordingPlayback() ? Menu.REASON_RECORDING_PLAYBACK : Menu.REASON_NONE);
            }
            return true;
        case KeyEvent.KEYCODE_CHANNEL_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_CHANNEL_DOWN:
        case KeyEvent.KEYCODE_DPAD_DOWN:
            // Channel change is already done in the head of this method.
            return true;
        case KeyEvent.KEYCODE_S:
            if (!SystemProperties.USE_DEBUG_KEYS.getValue()) {
                break;
            }
        case KeyEvent.KEYCODE_CAPTIONS: {
            mOverlayManager.getSideFragmentManager().show(new ClosedCaptionFragment());
            return true;
        }
        case KeyEvent.KEYCODE_A:
            if (!SystemProperties.USE_DEBUG_KEYS.getValue()) {
                break;
            }
        case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
            mOverlayManager.getSideFragmentManager().show(new MultiAudioFragment());
            return true;
        }
        case KeyEvent.KEYCODE_GUIDE: {
            mOverlayManager.showProgramGuide();
            return true;
        }
        case KeyEvent.KEYCODE_INFO: {
            mOverlayManager.showBanner();
            return true;
        }
        }
    }
    if (SystemProperties.USE_DEBUG_KEYS.getValue()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_W: {
            mDebugNonFullSizeScreen = !mDebugNonFullSizeScreen;
            if (mDebugNonFullSizeScreen) {
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTvView.getLayoutParams();
                params.width = 960;
                params.height = 540;
                params.gravity = Gravity.START;
                mTvView.setLayoutParams(params);
            } else {
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTvView.getLayoutParams();
                params.width = ViewGroup.LayoutParams.MATCH_PARENT;
                params.height = ViewGroup.LayoutParams.MATCH_PARENT;
                params.gravity = Gravity.CENTER;
                mTvView.setLayoutParams(params);
            }
            return true;
        }
        case KeyEvent.KEYCODE_P: {
            togglePipView();
            return true;
        }
        case KeyEvent.KEYCODE_CTRL_LEFT:
        case KeyEvent.KEYCODE_CTRL_RIGHT: {
            mUseKeycodeBlacklist = !mUseKeycodeBlacklist;
            return true;
        }
        case KeyEvent.KEYCODE_O: {
            mOverlayManager.getSideFragmentManager().show(new DisplayModeFragment());
            return true;
        }

        case KeyEvent.KEYCODE_D:
            mOverlayManager.getSideFragmentManager().show(new DebugOptionFragment());
            return true;

        case KeyEvent.KEYCODE_MEDIA_RECORD: // TODO(DVR) handle with debug_keys set
        case KeyEvent.KEYCODE_V: {
            DvrManager dvrManager = TvApplication.getSingletons(this).getDvrManager();
            long startTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(5);
            long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(35);
            dvrManager.addSchedule(getCurrentChannel(), startTime, endTime);
            return true;
        }
        case KeyEvent.KEYCODE_PROG_BLUE:
        case KeyEvent.KEYCODE_BUTTON_X:
        case KeyEvent.KEYCODE_X: {
            if (CommonFeatures.DVR.isEnabled(this)) {
                Channel channel = mTvView.getCurrentChannel();
                long channelId = channel.getId();
                Program p = mProgramDataManager.getCurrentProgram(channelId);
                if (p == null) {
                    long now = System.currentTimeMillis();
                    mDvrManager.addSchedule(channel, now, now + TimeUnit.MINUTES.toMillis(1));
                } else {
                    mDvrManager.addSchedule(p, mDvrManager.getScheduledRecordingsThatConflict(p));
                }
                return true;
            }
        }
        case KeyEvent.KEYCODE_PROG_YELLOW:
        case KeyEvent.KEYCODE_BUTTON_Y:
        case KeyEvent.KEYCODE_Y: {
            if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) {
                // TODO(DVR) only get finished recordings.
                List<RecordedProgram> recordedPrograms = mDvrDataManager.getRecordedPrograms();
                Log.d(TAG, "Found " + recordedPrograms.size() + "  recordings");
                if (recordedPrograms.isEmpty()) {
                    Toast.makeText(this, "No finished recording to play", Toast.LENGTH_LONG).show();
                } else {
                    RecordedProgram r = recordedPrograms.get(0);
                    Intent intent = new Intent(this, DvrPlayActivity.class);
                    intent.putExtra(ScheduledRecording.RECORDING_ID_EXTRA, r.getId());
                    startActivity(intent);
                }
                return true;
            }
        }
        }
    }
    return super.onKeyUp(keyCode, event);
}