1 /* 2 * Copyright (C) 2017 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 package com.android.documentsui.inspector; 17 18 import static androidx.core.util.Preconditions.checkArgument; 19 20 import android.content.Context; 21 import android.content.Intent; 22 import android.graphics.Color; 23 import android.net.Uri; 24 import android.os.Build; 25 import android.os.Bundle; 26 import android.view.MenuItem; 27 import android.view.View; 28 29 import androidx.appcompat.app.AppCompatActivity; 30 import androidx.appcompat.widget.Toolbar; 31 import androidx.loader.app.LoaderManager; 32 33 import com.android.documentsui.R; 34 import com.android.documentsui.base.Shared; 35 import com.android.documentsui.base.UserId; 36 import com.android.documentsui.inspector.InspectorController.DataSupplier; 37 38 public class InspectorActivity extends AppCompatActivity { 39 40 private static final String EXTRA_USER_ID = "user_id"; 41 42 private InspectorController mController; 43 private View mView; 44 private Toolbar mToolbar; 45 46 /** 47 * Returns an intent for inspector activity with a uri and user of the uri. 48 */ createIntent(Context context, Uri uri, UserId userId)49 public static Intent createIntent(Context context, Uri uri, UserId userId) { 50 Intent intent = new Intent(context, InspectorActivity.class); 51 intent.setData(uri); 52 intent.putExtra(EXTRA_USER_ID, userId.getIdentifier()); 53 return intent; 54 } 55 56 @Override onCreate(Bundle savedInstanceState)57 public void onCreate(Bundle savedInstanceState) { 58 super.onCreate(savedInstanceState); 59 60 // ToDo Create tool to check resource version before applyStyle for the theme 61 // If version code is not match, we should reset overlay package to default, 62 // in case Activity continueusly encounter resource not found exception 63 getTheme().applyStyle(R.style.DocumentsDefaultTheme, false); 64 65 setContentView(R.layout.inspector_activity); 66 67 setContainer(); 68 69 mToolbar = findViewById(R.id.toolbar); 70 setSupportActionBar(mToolbar); 71 getSupportActionBar().setDisplayHomeAsUpEnabled(true); 72 73 final DataSupplier loader = new RuntimeDataSupplier(this, LoaderManager.getInstance(this)); 74 75 mController = new InspectorController(this, loader, mView, 76 getIntent().getStringExtra(Intent.EXTRA_TITLE), 77 getIntent().getBooleanExtra(Shared.EXTRA_SHOW_DEBUG, false)); 78 } 79 80 @Override onStart()81 protected void onStart() { 82 super.onStart(); 83 Uri uri = getIntent().getData(); 84 checkArgument(getIntent().hasExtra(EXTRA_USER_ID)); 85 checkArgument(uri.getScheme().equals("content")); 86 UserId userId = UserId.of( 87 getIntent().getIntExtra(EXTRA_USER_ID, UserId.UNSPECIFIED_USER.getIdentifier())); 88 mController.loadInfo(uri, userId); 89 } 90 91 @Override onStop()92 protected void onStop() { 93 super.onStop(); 94 mController.reset(); 95 } 96 97 @Override onOptionsItemSelected(MenuItem item)98 public boolean onOptionsItemSelected(MenuItem item) { 99 switch (item.getItemId()) { 100 case android.R.id.home: 101 finish(); 102 return true; 103 } 104 return super.onOptionsItemSelected(item); 105 } 106 setContainer()107 private void setContainer() { 108 mView = findViewById(R.id.inspector_root); 109 mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 110 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 111 mView.setOnApplyWindowInsetsListener((v, insets) -> { 112 mView.setPadding(insets.getSystemWindowInsetLeft(), 113 insets.getSystemWindowInsetTop(), 114 insets.getSystemWindowInsetRight(), 0); 115 116 View container = findViewById(R.id.inspector_container); 117 container.setPadding(0, 0, 0, insets.getSystemWindowInsetBottom()); 118 return insets; 119 }); 120 121 getWindow().setNavigationBarDividerColor(Color.TRANSPARENT); 122 if (Build.VERSION.SDK_INT >= 29) { 123 getWindow().setNavigationBarColor(Color.TRANSPARENT); 124 getWindow().setNavigationBarContrastEnforced(true); 125 } else { 126 getWindow().setNavigationBarColor(getColor(R.color.nav_bar_translucent)); 127 } 128 } 129 }