Skip to content

Commit fe17b52

Browse files
committed
Upstream 3.0.3 source
2 parents 3f80a58 + 51e2ef2 commit fe17b52

File tree

53 files changed

+2527
-2499
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2527
-2499
lines changed

app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ext {
77
// exactly 1 digit
88
versionMinor = 0
99
// exactly 2 digits
10-
versionBuild = 2
10+
versionBuild = 3
1111
}
1212

1313
android {
@@ -90,7 +90,8 @@ android {
9090
}
9191

9292
dependencies {
93-
compile "com.android.support:support-v4:22.0.0"
94-
compile "com.android.support:support-v13:22.0.0"
93+
compile 'com.android.support:appcompat-v7:24.+'
94+
compile 'com.android.support:recyclerview-v7:24.+'
95+
compile "com.android.support:support-v13:24.+"
9596
compile(name:'setup-wizard-lib-platform-release', ext:'aar')
9697
}

app/src/main/java/com/afwsamples/testdpc/SetupManagementFragment.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
import android.app.Fragment;
2222
import android.content.ClipData;
2323
import android.content.ContentResolver;
24+
import android.content.Context;
2425
import android.content.Intent;
2526
import android.content.res.ColorStateList;
2627
import android.net.Uri;
2728
import android.os.Build;
2829
import android.os.Bundle;
2930
import android.os.PersistableBundle;
31+
import android.view.ContextThemeWrapper;
3032
import android.view.LayoutInflater;
3133
import android.view.View;
3234
import android.view.ViewGroup;
@@ -93,7 +95,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
9395
mCurrentColor = getResources().getColor(R.color.teal);
9496
}
9597

96-
View view = inflater.inflate(R.layout.setup_management_fragment, container, false);
98+
// Use setupwizard theme
99+
final Context contextThemeWrapper =
100+
new ContextThemeWrapper(getActivity(), R.style.SetupTheme);
101+
LayoutInflater themeInflater = inflater.cloneInContext(contextThemeWrapper);
102+
View view = themeInflater.inflate(R.layout.setup_management_fragment, container, false);
97103
SetupWizardLayout layout = (SetupWizardLayout) view.findViewById(R.id.setup_wizard_layout);
98104
NavigationBar navigationBar = layout.getNavigationBar();
99105
navigationBar.setNavigationBarListener(this);
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (C) 2016 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.afwsamples.testdpc.common;
18+
19+
import android.app.Fragment;
20+
import android.content.pm.PackageManager;
21+
import android.os.Bundle;
22+
import android.view.LayoutInflater;
23+
import android.view.View;
24+
import android.view.ViewGroup;
25+
import android.widget.AdapterView;
26+
import android.widget.BaseAdapter;
27+
import android.widget.ListView;
28+
import android.widget.Spinner;
29+
import android.widget.SpinnerAdapter;
30+
import android.widget.TextView;
31+
32+
import com.afwsamples.testdpc.R;
33+
34+
/**
35+
* This fragment shows a spinner of all allowed component and a list of associated properties.
36+
*/
37+
public abstract class BaseManageComponentFragment<T> extends Fragment
38+
implements View.OnClickListener {
39+
40+
protected PackageManager mPackageManager;
41+
protected Spinner mManagedAppsSpinner;
42+
protected TextView mHeaderView;
43+
protected ListView mAppListView;
44+
protected BaseAdapter mAdapter;
45+
46+
@Override
47+
public void onResume() {
48+
super.onResume();
49+
getActivity().getActionBar().setTitle(R.string.manage_apps);
50+
}
51+
52+
@Override
53+
public void onCreate(Bundle savedInstanceState) {
54+
super.onCreate(savedInstanceState);
55+
mPackageManager = getActivity().getPackageManager();
56+
}
57+
58+
@Override
59+
public View onCreateView(LayoutInflater layoutInflater, ViewGroup container,
60+
Bundle savedInstanceState) {
61+
View view = layoutInflater.inflate(R.layout.manage_apps, null);
62+
63+
mHeaderView = (TextView) view.findViewById(R.id.header_text);
64+
mManagedAppsSpinner = (Spinner) view.findViewById(R.id.managed_apps_list);
65+
mManagedAppsSpinner.setAdapter(createSpinnerAdapter());
66+
mManagedAppsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
67+
@Override
68+
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
69+
onSpinnerItemSelected((T) mManagedAppsSpinner.getSelectedItem());
70+
}
71+
72+
@Override
73+
public void onNothingSelected(AdapterView<?> parent) {
74+
// Do nothing.
75+
}
76+
});
77+
mAppListView = (ListView) view.findViewById(R.id.app_list_view);
78+
mAdapter = createListAdapter();
79+
mAppListView.setAdapter(mAdapter);
80+
view.findViewById(R.id.save_app).setOnClickListener(this);
81+
view.findViewById(R.id.reset_app).setOnClickListener(this);
82+
view.findViewById(R.id.add_new_row).setOnClickListener(this);
83+
view.findViewById(R.id.load_default_button).setOnClickListener(this);
84+
onSpinnerItemSelected((T) mManagedAppsSpinner.getSelectedItem());
85+
return view;
86+
}
87+
88+
protected abstract SpinnerAdapter createSpinnerAdapter();
89+
90+
protected abstract BaseAdapter createListAdapter();
91+
92+
/**
93+
* Populates the adapter for app_list_view with data for this application.
94+
* @param item the selected spinner item.
95+
*/
96+
protected abstract void onSpinnerItemSelected(T item);
97+
98+
@Override
99+
public void onClick(View view) {
100+
switch (view.getId()) {
101+
case R.id.reset_app:
102+
resetConfig();
103+
break;
104+
case R.id.save_app:
105+
saveConfig();
106+
break;
107+
case R.id.add_new_row:
108+
addNewRow();
109+
break;
110+
case R.id.load_default_button:
111+
loadDefault();
112+
}
113+
}
114+
115+
protected abstract void resetConfig();
116+
protected abstract void saveConfig();
117+
protected abstract void addNewRow();
118+
protected abstract void loadDefault();
119+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2016 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.afwsamples.testdpc.common;
18+
19+
import android.annotation.TargetApi;
20+
import android.os.Build;
21+
import android.os.Bundle;
22+
import android.os.PersistableBundle;
23+
24+
import java.util.Set;
25+
26+
public class BundleUtil {
27+
28+
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
29+
public static PersistableBundle bundleToPersistableBundle(Bundle bundle) {
30+
Set<String> keySet = bundle.keySet();
31+
PersistableBundle persistableBundle = new PersistableBundle();
32+
for (String key : keySet) {
33+
Object value = bundle.get(key);
34+
if (value instanceof Boolean) {
35+
persistableBundle.putBoolean(key, (boolean) value);
36+
} else if (value instanceof Integer) {
37+
persistableBundle.putInt(key, (int) value);
38+
} else if (value instanceof String) {
39+
persistableBundle.putString(key, (String) value);
40+
} else if (value instanceof String[]) {
41+
persistableBundle.putStringArray(key, (String[]) value);
42+
} else if (value instanceof Bundle) {
43+
PersistableBundle innerBundle = bundleToPersistableBundle((Bundle) value);
44+
persistableBundle.putPersistableBundle(key, innerBundle);
45+
}
46+
}
47+
return persistableBundle;
48+
}
49+
50+
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
51+
public static Bundle persistableBundleToBundle(PersistableBundle persistableBundle) {
52+
Set<String> keySet = persistableBundle.keySet();
53+
Bundle bundle = new Bundle();
54+
for (String key : keySet) {
55+
Object value = persistableBundle.get(key);
56+
if (value instanceof Boolean) {
57+
bundle.putBoolean(key, (boolean) value);
58+
} else if (value instanceof Integer) {
59+
bundle.putInt(key, (int) value);
60+
} else if (value instanceof String) {
61+
bundle.putString(key, (String) value);
62+
} else if (value instanceof String[]) {
63+
bundle.putStringArray(key, (String[]) value);
64+
} else if (value instanceof PersistableBundle) {
65+
Bundle innerBundle = persistableBundleToBundle((PersistableBundle) value);
66+
bundle.putBundle(key, innerBundle);
67+
}
68+
}
69+
return bundle;
70+
}
71+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (C) 2016 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.afwsamples.testdpc.common;
18+
19+
import android.content.Context;
20+
import android.view.LayoutInflater;
21+
import android.view.View;
22+
import android.view.ViewGroup;
23+
import android.view.ViewParent;
24+
import android.widget.ArrayAdapter;
25+
import android.widget.TextView;
26+
27+
import com.afwsamples.testdpc.R;
28+
29+
import java.util.Collections;
30+
import java.util.Comparator;
31+
import java.util.List;
32+
33+
/**
34+
* List of rows with edit and delete button.
35+
*/
36+
public abstract class EditDeleteArrayAdapter<T> extends ArrayAdapter<T>
37+
implements View.OnClickListener {
38+
39+
private List<T> mEntries;
40+
private OnEditButtonClickListener mOnEditButtonClickListener;
41+
private OnDeleteButtonClickListener mOnDeleteButtonClickListener;
42+
43+
public EditDeleteArrayAdapter(Context context, List<T> entries,
44+
OnEditButtonClickListener onEditButtonClickListener,
45+
OnDeleteButtonClickListener onDeleteButtonClickListener) {
46+
super(context, 0, entries);
47+
mEntries = entries;
48+
mOnEditButtonClickListener = onEditButtonClickListener;
49+
mOnDeleteButtonClickListener = onDeleteButtonClickListener;
50+
}
51+
52+
@Override
53+
public View getView(final int position, View convertView, ViewGroup parent) {
54+
RowViewHolder<T> viewHolder;
55+
if (convertView == null) {
56+
convertView = LayoutInflater.from(getContext()).inflate(
57+
R.layout.edit_delete_row, parent, false);
58+
convertView.findViewById(R.id.edit_row).setOnClickListener(this);
59+
convertView.findViewById(R.id.delete_row).setOnClickListener(this);
60+
61+
viewHolder = new RowViewHolder<>();
62+
convertView.setTag(viewHolder);
63+
viewHolder.restrictionKeyText = (TextView) convertView.findViewById(
64+
R.id.restriction_key);
65+
} else {
66+
viewHolder = (RowViewHolder) convertView.getTag();
67+
}
68+
viewHolder.entry = getItem(position);
69+
viewHolder.restrictionKeyText.setText(getDisplayName(viewHolder.entry));
70+
viewHolder.entryPosition = position;
71+
return convertView;
72+
}
73+
74+
@Override
75+
public void onClick(View view) {
76+
ViewParent parentView = view.getParent();
77+
if (!(parentView instanceof View) || ((View) parentView).getTag() == null) {
78+
return;
79+
}
80+
final RowViewHolder<T> viewHolder =
81+
(RowViewHolder<T>) ((View) parentView).getTag();
82+
final T entry = viewHolder.entry;
83+
if (view.getId() == R.id.edit_row) {
84+
mOnEditButtonClickListener.onEditButtonClick(entry);
85+
} else if (view.getId() == R.id.delete_row) {
86+
remove(entry);
87+
if (mOnDeleteButtonClickListener != null) {
88+
mOnDeleteButtonClickListener.onDeleteButtonClick(entry);
89+
}
90+
}
91+
}
92+
93+
@Override
94+
public void notifyDataSetChanged() {
95+
if (mEntries != null) {
96+
Collections.sort(mEntries, new Comparator<T>() {
97+
@Override
98+
public int compare(T entry1, T entry2) {
99+
return getDisplayName(entry1).compareTo(getDisplayName(entry2));
100+
}
101+
});
102+
}
103+
super.notifyDataSetChanged();
104+
}
105+
106+
public void set(int index, T item) {
107+
mEntries.set(index, item);
108+
notifyDataSetChanged();
109+
}
110+
111+
protected abstract String getDisplayName(T entry);
112+
113+
private static class RowViewHolder<T> {
114+
T entry;
115+
TextView restrictionKeyText;
116+
int entryPosition;
117+
}
118+
119+
public interface OnEditButtonClickListener<T> {
120+
void onEditButtonClick(T entry);
121+
}
122+
123+
public interface OnDeleteButtonClickListener<T> {
124+
void onDeleteButtonClick(T entry);
125+
}
126+
}

0 commit comments

Comments
 (0)