Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
ImmersiveMode / src / com.example.android.immersivemode /

MainActivity.java

       
        1
       
       
        /*
       
       
        2
       
       
        * Copyright 2013 The Android Open Source Project
       
       
        3
       
       
        *
       
       
        4
       
       
        * Licensed under the Apache License, Version 2.0 (the "License");
       
       
        5
       
       
        * you may not use this file except in compliance with the License.
       
       
        6
       
       
        * You may obtain a copy of the License at
       
       
        7
       
       
        *
       
       
        8
       
       
        *     http://www.apache.org/licenses/LICENSE-2.0
       
       
        9
       
       
        *
       
       
        10
       
       
        * Unless required by applicable law or agreed to in writing, software
       
       
        11
       
       
        * distributed under the License is distributed on an "AS IS" BASIS,
       
       
        12
       
       
        * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
       
        13
       
       
        * See the License for the specific language governing permissions and
       
       
        14
       
       
        * limitations under the License.
       
       
        15
       
       
        */
       
       
        16
       
       
       
       
        17
       
       
       
       
        18
       
       
       
       
        19
       
       
       
       
        20
       
       
        package com.example.android.immersivemode;
       
       
        21
       
       
       
       
        22
       
       
        import android.graphics.Color;
       
       
        23
       
       
        import android.os.Bundle;
       
       
        24
       
       
        import android.support.v4.app.FragmentTransaction;
       
       
        25
       
       
        import android.view.Menu;
       
       
        26
       
       
       
       
        27
       
       
        import com.example.android.common.activities.SampleActivityBase;
       
       
        28
       
       
        import com.example.android.common.logger.Log;
       
       
        29
       
       
        import com.example.android.common.logger.LogFragment;
       
       
        30
       
       
        import com.example.android.common.logger.LogWrapper;
       
       
        31
       
       
        import com.example.android.common.logger.MessageOnlyLogFilter;
       
       
        32
       
       
       
       
        33
       
       
        /**
       
       
        34
       
       
        * A simple launcher activity containing a summary sample description
       
       
        35
       
       
        * and a few action bar buttons.
       
       
        36
       
       
        */
       
       
        37
       
       
        public class MainActivity extends SampleActivityBase {
       
       
        38
       
       
       
       
        39
       
       
        public static final String TAG = "MainActivity";
       
       
        40
       
       
       
       
        41
       
       
        public static final String FRAGTAG = "ImmersiveModeFragment";
       
       
        42
       
       
       
       
        43
       
       
        @Override
       
       
        44
       
       
        protected void onCreate(Bundle savedInstanceState) {
       
       
        45
       
       
        super.onCreate(savedInstanceState);
       
       
        46
       
       
        setContentView(R.layout.activity_main);
       
       
        47
       
       
       
       
        48
       
       
        if (getSupportFragmentManager().findFragmentByTag(FRAGTAG) == null ) {
       
       
        49
       
       
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
       
       
        50
       
       
        ImmersiveModeFragment fragment = new ImmersiveModeFragment();
       
       
        51
       
       
        transaction.add(fragment, FRAGTAG);
       
       
        52
       
       
        transaction.commit();
       
       
        53
       
       
        }
       
       
        54
       
       
        }
       
       
        55
       
       
       
       
        56
       
       
        @Override
       
       
        57
       
       
        public boolean onCreateOptionsMenu(Menu menu) {
       
       
        58
       
       
        getMenuInflater().inflate(R.menu.main, menu);
       
       
        59
       
       
        return true;
       
       
        60
       
       
        }
       
       
        61
       
       
       
       
        62
       
       
        /** Create a chain of targets that will receive log data */
       
       
        63
       
       
        @Override
       
       
        64
       
       
        public void initializeLogging() {
       
       
        65
       
       
        // Wraps Android's native log framework.
       
       
        66
       
       
        LogWrapper logWrapper = new LogWrapper();
       
       
        67
       
       
        // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
       
       
        68
       
       
        Log.setLogNode(logWrapper);
       
       
        69
       
       
       
       
        70
       
       
        // Filter strips out everything except the message text.
       
       
        71
       
       
        MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
       
       
        72
       
       
        logWrapper.setNext(msgFilter);
       
       
        73
       
       
       
       
        74
       
       
        // On screen logging via a fragment with a TextView.
       
       
        75
       
       
        LogFragment logFragment = (LogFragment) getSupportFragmentManager()
       
       
        76
       
       
        .findFragmentById(R.id.log_fragment);
       
       
        77
       
       
        msgFilter.setNext(logFragment.getLogView());
       
       
        78
       
       
        logFragment.getLogView().setTextAppearance(this, R.style.Log);
       
       
        79
       
       
        logFragment.getLogView().setBackgroundColor(Color.WHITE);
       
       
        80
       
       
       
       
        81
       
       
       
       
        82
       
       
        Log.i(TAG, "Ready");
       
       
        83
       
       
        }
       
       
        84
       
       
        }