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.basicandroidkeystore; 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 = "BasicAndroidKeyStoreFragment"; 42 43 @Override 44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 setContentView(R.layout.activity_main); 47 48 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 49 BasicAndroidKeyStoreFragment fragment = new BasicAndroidKeyStoreFragment(); 50 transaction.add(fragment, FRAGTAG); 51 transaction.commit(); 52 } 53 54 @Override 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 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 Log.i(TAG, "Ready"); 80 } 81 }