• 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.wearable.synchronizednotifications;
18 
19 import android.graphics.Color;
20 import android.os.Bundle;
21 import android.support.v4.app.FragmentTransaction;
22 import android.text.Html;
23 import android.widget.TextView;
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 = "SynchronizedNotificationsFragment";
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         setContentView(R.layout.activity_main);
46         TextView sampleOutput = (TextView) findViewById(R.id.sample_output);
47         sampleOutput.setText(Html.fromHtml(getString(R.string.intro_message)));
48 
49         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
50         SynchronizedNotificationsFragment fragment = new SynchronizedNotificationsFragment();
51         transaction.add(fragment, FRAGTAG);
52         transaction.commit();
53     }
54 
55     @Override
onCreateOptionsMenu(Menu menu)56     public boolean onCreateOptionsMenu(Menu menu) {
57         getMenuInflater().inflate(R.menu.main, menu);
58         return true;
59     }
60 
61     /** Create a chain of targets that will receive log data */
62     @Override
initializeLogging()63     public void initializeLogging() {
64         // Wraps Android's native log framework.
65         LogWrapper logWrapper = new LogWrapper();
66         // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
67         Log.setLogNode(logWrapper);
68 
69         // Filter strips out everything except the message text.
70         MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
71         logWrapper.setNext(msgFilter);
72 
73         // On screen logging via a fragment with a TextView.
74         LogFragment logFragment = (LogFragment) getSupportFragmentManager()
75                 .findFragmentById(R.id.log_fragment);
76         msgFilter.setNext(logFragment.getLogView());
77         logFragment.getLogView().setTextAppearance(this, R.style.Log);
78         logFragment.getLogView().setBackgroundColor(Color.WHITE);
79 
80         Log.i(TAG, "Ready");
81     }
82 }
83