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.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 = "BasicAndroidKeyStoreFragment"; 41 42 @Override onCreate(Bundle savedInstanceState)43 protected void onCreate(Bundle savedInstanceState) { 44 super.onCreate(savedInstanceState); 45 setContentView(R.layout.activity_main); 46 47 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 48 BasicAndroidKeyStoreFragment fragment = new BasicAndroidKeyStoreFragment(); 49 transaction.add(fragment, FRAGTAG); 50 transaction.commit(); 51 } 52 53 @Override onCreateOptionsMenu(Menu menu)54 public boolean onCreateOptionsMenu(Menu menu) { 55 getMenuInflater().inflate(R.menu.main, menu); 56 return true; 57 } 58 59 /** Create a chain of targets that will receive log data */ 60 @Override initializeLogging()61 public void initializeLogging() { 62 // Wraps Android's native log framework. 63 LogWrapper logWrapper = new LogWrapper(); 64 // Using Log, front-end to the logging chain, emulates android.util.log method signatures. 65 Log.setLogNode(logWrapper); 66 67 // Filter strips out everything except the message text. 68 MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter(); 69 logWrapper.setNext(msgFilter); 70 71 // On screen logging via a fragment with a TextView. 72 LogFragment logFragment = (LogFragment) getSupportFragmentManager() 73 .findFragmentById(R.id.log_fragment); 74 msgFilter.setNext(logFragment.getLogView()); 75 76 Log.i(TAG, "Ready"); 77 } 78 }