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.android.tv.settings.accounts; 18 19 import android.accounts.Account; 20 import android.accounts.AccountManager; 21 import android.graphics.Bitmap; 22 import android.graphics.drawable.BitmapDrawable; 23 import android.graphics.drawable.Drawable; 24 import android.net.Uri; 25 import android.os.Bundle; 26 27 import com.android.tv.settings.BrowseInfoFactory; 28 import com.android.tv.settings.MenuActivity; 29 import com.android.tv.settings.util.UriUtils; 30 import com.android.tv.settings.widget.BitmapDownloader; 31 import com.android.tv.settings.widget.BitmapDownloader.BitmapCallback; 32 import com.android.tv.settings.widget.BitmapWorkerOptions; 33 34 public class AccountSettingsActivity extends MenuActivity { 35 36 public static final String EXTRA_ACCOUNT = "account_name"; 37 38 private Drawable mAccountDrawable; 39 40 @Override 41 protected String getBrowseTitle() { 42 return getIntent().getStringExtra(EXTRA_ACCOUNT); 43 } 44 45 @Override 46 protected Drawable getBadgeImage() { 47 return mAccountDrawable; 48 } 49 50 @Override 51 protected BrowseInfoFactory getBrowseInfoFactory() { 52 return new AccountsBrowseInfo(this, getIntent().getStringExtra(EXTRA_ACCOUNT)); 53 } 54 55 @Override 56 protected void onCreate(Bundle savedInstanceState) { 57 super.onCreate(savedInstanceState); 58 Uri imageUri = UriUtils.getAccountImageUri(getIntent().getStringExtra(EXTRA_ACCOUNT), null); 59 BitmapCallback bitmapCallBack = new BitmapCallback() { 60 @Override 61 public void onBitmapRetrieved(Bitmap bitmap) { 62 if (bitmap != null) { 63 mAccountDrawable = new BitmapDrawable(getResources(), bitmap); 64 updateBrowseParams(); 65 } 66 } 67 }; 68 69 BitmapWorkerOptions bitmapWorkerOptions = new BitmapWorkerOptions.Builder(this) 70 .resource(imageUri).build(); 71 BitmapDownloader.getInstance(this).getBitmap(bitmapWorkerOptions, bitmapCallBack); 72 } 73 74 @Override 75 protected void onResume() { 76 super.onResume(); 77 String accountName = getIntent().getStringExtra(EXTRA_ACCOUNT); 78 for (Account account : AccountManager.get(this).getAccounts()) { 79 if (account.name.equals(accountName)) { 80 return; 81 } 82 } 83 setResult(RESULT_CANCELED); 84 finish(); 85 } 86 87 } 88