• 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 package com.example.android.basicgesturedetect;
18 
19 import android.graphics.Color;
20 import android.os.Bundle;
21 import android.support.v4.app.FragmentTransaction;
22 import android.view.Menu;
23 
24 import com.example.android.common.activities.SampleActivityBase;
25 import com.example.android.common.logger.Log;
26 import com.example.android.common.logger.LogFragment;
27 import com.example.android.common.logger.LogWrapper;
28 import com.example.android.common.logger.MessageOnlyLogFilter;
29 
30 /**
31  * A simple launcher activity containing a summary sample description
32  * and a few action bar buttons.
33  */
34 public class MainActivity extends SampleActivityBase {
35 
36     public static final String TAG = "MainActivity";
37 
38     public static final String FRAGTAG = "BasicGestureDetectFragment";
39 
40     @Override
onCreate(Bundle savedInstanceState)41     protected void onCreate(Bundle savedInstanceState) {
42         super.onCreate(savedInstanceState);
43         setContentView(R.layout.activity_main);
44 
45         if (getSupportFragmentManager().findFragmentByTag(FRAGTAG) == null ) {
46             FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
47             BasicGestureDetectFragment fragment = new BasicGestureDetectFragment();
48             transaction.add(fragment, FRAGTAG);
49             transaction.commit();
50         }
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         logFragment.getLogView().setTextAppearance(this, R.style.Log);
76         logFragment.getLogView().setBackgroundColor(Color.WHITE);
77 
78 
79         Log.i(TAG, "Ready");
80     }
81 }
82