1 /* 2 * Copyright (C) 2014 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.documentcentricapps; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.view.View; 23 import android.widget.TextView; 24 25 /** 26 * Represents a "document" in the new overview notion. This is just a placeholder. 27 * Real world examples of this could be: 28 * 29 * <ul> 30 * <li>Document Editing</li> 31 * <li>Browser tabs</li> 32 * <li>Message composition</li> 33 * <li>Sharing</li> 34 * <li>Shopping item details</li> 35 * </ul> 36 */ 37 public class NewDocumentActivity extends Activity { 38 39 private TextView mDocumentCounterTextView; 40 private int mDocumentCount; 41 42 @Override onCreate(Bundle savedInstanceState)43 protected void onCreate(Bundle savedInstanceState) { 44 super.onCreate(savedInstanceState); 45 setContentView(R.layout.activity_new_document); 46 mDocumentCount = getIntent() 47 .getIntExtra(DocumentCentricActivity.KEY_EXTRA_NEW_DOCUMENT_COUNTER, 0); 48 mDocumentCounterTextView = (TextView) findViewById( 49 R.id.hello_new_document_text_view); 50 setDocumentCounterText(R.string.hello_new_document_counter); 51 } 52 53 @Override onNewIntent(Intent intent)54 protected void onNewIntent(Intent intent) { 55 super.onNewIntent(intent); 56 /* If {@link Intent#FLAG_ACTIVITY_MULTIPLE_TASK} has not been used this Activity 57 will be reused. 58 */ 59 setDocumentCounterText(R.string.reusing_document_counter); 60 } 61 onRemoveFromOverview(View view)62 public void onRemoveFromOverview(View view) { 63 // It is good pratice to remove a document from the overview stack if not needed anymore. 64 finishAndRemoveTask(); 65 } 66 setDocumentCounterText(int resId)67 public void setDocumentCounterText(int resId) { 68 mDocumentCounterTextView 69 .setText(String.format(getString(resId), String.valueOf(mDocumentCount))); 70 } 71 72 } 73