1 /*
2  * Copyright (C) 2023 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.sdksandboxclient;
18 
19 import android.content.SharedPreferences;
20 
21 public class BannerOptions {
22 
23     public enum ViewType {
24         RANDOM_COLOUR,
25         INFLATED,
26         VIDEO,
27         WEBVIEW,
28         AD_REFRESH,
29         EDITTEXT
30     }
31 
32     public enum OnClick {
33         OPEN_CHROME,
34         OPEN_PACKAGE,
35     }
36 
37     public enum Placement {
38         BOTTOM,
39         SCROLL_VIEW
40     }
41 
42     public enum AdSize {
43         SMALL,
44         MEDIUM,
45         LARGE,
46     };
47 
48     private final ViewType mViewType;
49     private final String mVideoUrl;
50     private final OnClick mOnClick;
51     private final Placement mPlacement;
52     private final AdSize mAdSize;
53 
54     private final String mPackageToOpen;
55 
getViewType()56     public ViewType getViewType() {
57         return mViewType;
58     }
59 
getOnClick()60     public OnClick getOnClick() {
61         return mOnClick;
62     }
63 
getPlacement()64     public Placement getPlacement() {
65         return mPlacement;
66     }
67 
getVideoUrl()68     public String getVideoUrl() {
69         return mVideoUrl;
70     }
71 
getmPackageToOpen()72     public String getmPackageToOpen() {
73         return mPackageToOpen;
74     }
75 
getAdSize()76     public AdSize getAdSize() {
77         return mAdSize;
78     }
79 
80     @Override
toString()81     public String toString() {
82         return String.format(
83                 "BannerOptions { ViewType=%s, VideoUrl=%s, OnClick=%s, Placement=%s AdSize=%s }",
84                 mViewType, mVideoUrl, mOnClick, mPlacement, mAdSize);
85     }
86 
BannerOptions( ViewType viewType, String videoUrl, OnClick onClick, String packageToOpen, Placement placement, AdSize adSize)87     private BannerOptions(
88             ViewType viewType,
89             String videoUrl,
90             OnClick onClick,
91             String packageToOpen,
92             Placement placement,
93             AdSize adSize) {
94         mViewType = viewType;
95         mVideoUrl = videoUrl;
96         mOnClick = onClick;
97         mPlacement = placement;
98         mPackageToOpen = packageToOpen;
99         mAdSize = adSize;
100     }
101 
fromSharedPreferences(SharedPreferences sharedPreferences)102     public static BannerOptions fromSharedPreferences(SharedPreferences sharedPreferences) {
103         return new BannerOptions(
104                 ViewType.valueOf(sharedPreferences.getString("banner_view_type", "")),
105                 sharedPreferences.getString("banner_video_url", ""),
106                 OnClick.valueOf(sharedPreferences.getString("banner_on_click", "")),
107                 sharedPreferences.getString("package_to_open", ""),
108                 Placement.valueOf(sharedPreferences.getString("banner_placement", "")),
109                 AdSize.valueOf(sharedPreferences.getString("banner_ad_size", "")));
110     }
111 }
112