Home | History | Annotate | Download | only in com.example.android.advancedimmersivemode
      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.advancedimmersivemode;
     21 
     22 import android.os.Bundle;
     23 import android.support.v4.app.FragmentTransaction;
     24 import android.view.Menu;
     25 
     26 import com.example.android.common.activities.SampleActivityBase;
     27 import com.example.android.common.logger.Log;
     28 import com.example.android.common.logger.LogFragment;
     29 import com.example.android.common.logger.LogWrapper;
     30 import com.example.android.common.logger.MessageOnlyLogFilter;
     31 
     32 /**
     33  * A simple launcher activity containing a summary sample description
     34  * and a few action bar buttons.
     35  */
     36 public class MainActivity extends SampleActivityBase {
     37 
     38     public static final String TAG = "MainActivity";
     39 
     40     public static final String FRAGTAG = "AdvancedImmersiveModeFragment";
     41 
     42     @Override
     43     protected void onCreate(Bundle savedInstanceState) {
     44         super.onCreate(savedInstanceState);
     45         setContentView(R.layout.activity_main);
     46 
     47         if (getSupportFragmentManager().findFragmentByTag(FRAGTAG) == null ) {
     48             FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
     49             AdvancedImmersiveModeFragment fragment = new AdvancedImmersiveModeFragment();
     50             transaction.add(fragment, FRAGTAG);
     51             transaction.commit();
     52         }
     53     }
     54 
     55     @Override
     56     public boolean onCreateOptionsMenu(Menu menu) {
     57         getMenuInflater().inflate(R.menu.main, menu);
     58         return true;
     59     }
     60 
     61     /** Create a chain of targets that will receive log data */
     62     @Override
     63     public void initializeLogging() {
     64         // Wraps Android's native log framework.
     65         LogWrapper logWrapper = new LogWrapper();
     66         // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
     67         Log.setLogNode(logWrapper);
     68 
     69         // Filter strips out everything except the message text.
     70         MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
     71         logWrapper.setNext(msgFilter);
     72 
     73         // On screen logging via a fragment with a TextView.
     74         LogFragment logFragment = (LogFragment) getSupportFragmentManager()
     75                 .findFragmentById(R.id.log_fragment);
     76         msgFilter.setNext(logFragment.getLogView());
     77 
     78         Log.i(TAG, "Ready");
     79     }
     80 }
     81