Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java

Issue 2016343002: Revert of Add drawer with state information (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 package org.skia.viewer;
2
3 import android.view.LayoutInflater;
4 import android.view.View;
5 import android.view.ViewGroup;
6 import android.widget.AdapterView;
7 import android.widget.ArrayAdapter;
8 import android.widget.BaseAdapter;
9 import android.widget.Spinner;
10 import android.widget.TextView;
11
12 import org.json.JSONArray;
13 import org.json.JSONException;
14 import org.json.JSONObject;
15
16 import java.util.ArrayList;
17
18 public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec tedListener {
19 static final String NAME = "name";
20 static final String VALUE = "value";
21 static final String OPTIONS = "options";
22
23 ViewerActivity mViewerActivity;
24 JSONArray mStateJson;
25
26 public StateAdapter(ViewerActivity viewerActivity) {
27 mViewerActivity = viewerActivity;
28 try {
29 mStateJson = new JSONArray("[{\"name\": \"Please\", " +
30 "\"value\": \"Initialize\", \"options\": []}]");
31 } catch (JSONException e) {
32 e.printStackTrace();
33 }
34 }
35
36 public void setState(String stateJson) {
37 try {
38 mStateJson = new JSONArray(stateJson);
39 notifyDataSetChanged();
40 } catch (JSONException e) {
41 e.printStackTrace();
42 }
43 }
44
45 @Override
46 public int getCount() {
47 return mStateJson.length();
48 }
49
50 @Override
51 public Object getItem(int position) {
52 try {
53 return mStateJson.getJSONObject(position);
54 } catch (JSONException e) {
55 e.printStackTrace();
56 return null;
57 }
58 }
59
60 @Override
61 public long getItemId(int position) {
62 return 0;
63 }
64
65 @Override
66 public View getView(int position, View convertView, ViewGroup parent) {
67 if (convertView == null) {
68 convertView = LayoutInflater.from(mViewerActivity).inflate(R.layout. state_item, null);
69 }
70 TextView nameText = (TextView) convertView.findViewById(R.id.nameText);
71 TextView valueText = (TextView) convertView.findViewById(R.id.valueText) ;
72 Spinner optionSpinner = (Spinner) convertView.findViewById(R.id.optionSp inner);
73 JSONObject stateObject = (JSONObject) getItem(position);
74 try {
75 nameText.setText(stateObject.getString(NAME));
76 String value = stateObject.getString(VALUE);
77 JSONArray options = stateObject.getJSONArray(OPTIONS);
78 if (options.length() == 0) {
79 valueText.setText(value);
80 valueText.setVisibility(View.VISIBLE);
81 optionSpinner.setVisibility(View.GONE);
82
83 } else {
84 ArrayList<String> optionList = new ArrayList<>();
85 String[] optionStrings = new String[options.length()];
86 for(int i=0; i<options.length(); i++) {
87 optionList.add(options.getString(i));
88 }
89 optionSpinner.setAdapter(new ArrayAdapter<String>(mViewerActivit y,
90 android.R.layout.simple_spinner_dropdown_item, optionLis t));
91 optionSpinner.setSelection(optionList.indexOf(value));
92 optionSpinner.setOnItemSelectedListener(this);
93 optionSpinner.setVisibility(View.VISIBLE);
94 valueText.setVisibility(View.GONE);
95 }
96 } catch (JSONException e) {
97 e.printStackTrace();
98 }
99 return convertView;
100 }
101
102 @Override
103 public void onItemSelected(AdapterView<?> parent, View view, int position, l ong id) {
104 View stateItem = (View) parent.getParent();
105 String stateName = ((TextView) stateItem.findViewById(R.id.nameText)).ge tText().toString();
106 String stateValue = ((TextView) view).getText().toString();
107 mViewerActivity.onStateChanged(stateName, stateValue);
108 }
109
110 @Override
111 public void onNothingSelected(AdapterView<?> parent) {
112 // do nothing
113 }
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698