1 /* 2 * Copyright (C) 2015 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.android.packageinstaller.permission.ui.wear; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.graphics.drawable.Drawable; 22 import android.graphics.drawable.Icon; 23 import android.os.Bundle; 24 25 import com.android.packageinstaller.R; 26 27 public final class WarningConfirmationActivity extends Activity { 28 public final static String EXTRA_WARNING_MESSAGE = "EXTRA_WARNING_MESSAGE"; 29 // Saved index that will be returned in the onActivityResult() callback 30 public final static String EXTRA_INDEX = "EXTRA_INDEX"; 31 32 private ConfirmationViewHandler mViewHandler; 33 private String mMessage; 34 35 @Override 36 protected void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 39 mMessage = getIntent().getStringExtra(EXTRA_WARNING_MESSAGE); 40 41 mViewHandler = new ConfirmationViewHandler(this) { 42 @Override // ConfirmationViewHandler 43 public int getButtonBarMode() { 44 return MODE_VERTICAL_BUTTONS; 45 } 46 47 @Override 48 public void onButton1() { 49 setResultAndFinish(Activity.RESULT_CANCELED); 50 } 51 52 @Override 53 public void onButton2() { 54 setResultAndFinish(Activity.RESULT_OK); 55 } 56 57 @Override 58 public void onButton3() { 59 // no-op 60 } 61 62 @Override 63 public CharSequence getVerticalButton1Text() { 64 return getString(R.string.cancel); 65 } 66 67 @Override 68 public CharSequence getVerticalButton2Text() { 69 return getString(R.string.grant_dialog_button_deny_anyway); 70 } 71 72 @Override 73 public CharSequence getVerticalButton3Text() { 74 return null; 75 } 76 77 @Override 78 public Drawable getVerticalButton1Icon() { 79 return getDrawable(R.drawable.cancel_button); 80 } 81 82 @Override 83 public Drawable getVerticalButton2Icon() { 84 return getDrawable(R.drawable.confirm_button); 85 } 86 87 @Override 88 public Drawable getVerticalButton3Icon() { 89 return null; 90 } 91 92 @Override 93 public CharSequence getCurrentPageText() { 94 return null; 95 } 96 97 @Override 98 public Icon getPermissionIcon() { 99 return null; 100 } 101 102 @Override 103 public CharSequence getMessage() { 104 return mMessage; 105 } 106 }; 107 108 setContentView(mViewHandler.createView()); 109 mViewHandler.invalidate(); 110 } 111 112 private void setResultAndFinish(int result) { 113 Intent intent = new Intent(); 114 intent.putExtra(EXTRA_INDEX, getIntent().getIntExtra(EXTRA_INDEX, -1)); 115 setResult(result, intent); 116 finish(); 117 } 118 } 119