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