• 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.basicandroidkeystore;
19 
20 import android.graphics.Color;
21 import android.os.Bundle;
22 import android.support.v4.app.FragmentTransaction;
23 import android.text.Html;
24 import android.widget.TextView;
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
onCreate(Bundle savedInstanceState)44     protected void onCreate(Bundle savedInstanceState) {
45         super.onCreate(savedInstanceState);
46         setContentView(R.layout.activity_main);
47         TextView sampleOutput = (TextView) findViewById(R.id.sample_output);
48         sampleOutput.setText(Html.fromHtml(getString(R.string.intro_message)));
49 
50         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
51         BasicAndroidKeyStoreFragment fragment = new BasicAndroidKeyStoreFragment();
52         transaction.add(fragment, FRAGTAG);
53         transaction.commit();
54     }
55 
56     @Override
onCreateOptionsMenu(Menu menu)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
initializeLogging()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         Log.i(TAG, "Ready");
82     }
83 }
84