2 Copyright (c) 2014, The Linux Foundation. All Rights Reserved.
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions are
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above
9 copyright notice, this list of conditions and the following
10 disclaimer in the documentation and/or other materials provided
11 with the distribution.
12 * Neither the name of The Linux Foundation nor the names of its
13 contributors may be used to endorse or promote products derived
14 from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 package com.android.settings;
31 import java.io.FileNotFoundException;
32 import java.io.InputStream;
34 import android.app.ActionBar;
35 import android.app.Activity;
36 import android.content.ComponentName;
37 import android.content.Context;
38 import android.content.Intent;
39 import android.content.ServiceConnection;
40 import android.content.SharedPreferences;
41 import android.content.SharedPreferences.Editor;
42 import android.graphics.Bitmap;
43 import android.graphics.BitmapFactory;
44 import android.graphics.drawable.BitmapDrawable;
45 import android.net.Uri;
46 import android.os.Bundle;
47 import android.os.IBinder;
48 import android.os.RemoteException;
49 import android.util.Log;
50 import android.view.Gravity;
51 import android.view.LayoutInflater;
52 import android.view.Menu;
53 import android.view.MenuItem;
54 import android.view.View;
55 import android.view.View.OnClickListener;
56 import android.view.ViewGroup;
57 import android.view.Window;
58 import android.widget.AdapterView;
59 import android.widget.AdapterView.OnItemClickListener;
60 import android.widget.ArrayAdapter;
61 import android.widget.ListView;
62 import android.widget.Button;
63 import android.widget.ImageView;
64 import android.widget.LinearLayout;
65 import android.widget.PopupMenu;
66 import android.widget.RadioButton;
67 import android.widget.PopupMenu.OnMenuItemClickListener;
68 import android.widget.RadioGroup;
69 import android.widget.RelativeLayout;
70 import android.widget.SeekBar;
71 import android.widget.TextView;
72 import android.widget.PopupWindow;
74 import com.android.display.IPPService;
76 public class ScreenColorSettings extends Activity {
77 private final static String TAG = "ScreenColorSettings";
78 private final static boolean DEBUG = false;
80 private final static int MODE_STANDARD = 0;
81 private final static int MODE_VIVID = 1;
82 private final static int MODE_CUSTOM = 2;
84 private static final String COLOR_MODE = "mode";
85 private static final String COLOR_HUE = "hue";
86 private static final String COLOR_SATURATION = "saturation";
87 private static final String COLOR_INTENSITY = "intensity";
88 private static final String COLOR_CONTRAST = "contrast";
90 private static final String PREVIEW_STRING_NAME = "screencolor_preview_name";
92 private int mMode = 0;
93 private IPPService mPPService = null;
94 private PPServiceConnection mPPServiceConn = null;
95 private SharedPreferences mSharedPreference;
98 protected void onCreate(Bundle savedInstanceState) {
99 super.onCreate(savedInstanceState);
101 getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
102 setContentView(R.layout.screencolor_settings);
104 ListView listView = (ListView)findViewById(R.id.mode_list);
105 listView.setBackgroundColor(R.color.screencolor_background);
106 mSharedPreference = getSharedPreferences(PREVIEW_STRING_NAME, Context.MODE_PRIVATE);
107 mMode = mSharedPreference.getInt(COLOR_MODE, 0);
108 setScreenColorMode(mMode);
109 String[] list = getResources().getStringArray(R.array.screen_color_setting);
110 ColorModeAdaper adapter = new ColorModeAdaper(this,
111 R.layout.screen_color_item, list);
112 listView.setAdapter(adapter);
115 private class ColorModeAdaper extends ArrayAdapter<String> {
116 private int mResource;
117 private RelativeLayout mItemView;
119 public ColorModeAdaper(Context context, int resource, String[] list) {
120 super(context, resource, list);
121 this.mResource = resource;
125 public View getView(int position, View convertView, ViewGroup parent) {
126 String name = getItem(position);
127 if(convertView == null) {
128 mItemView = new RelativeLayout(getContext());
129 LayoutInflater vi = (LayoutInflater)getContext()
130 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
131 vi.inflate(mResource, mItemView, true);
133 mItemView = (RelativeLayout) convertView;
135 ((TextView) mItemView.findViewById(android.R.id.title)).setText(name);
137 RadioButton radioButton = (RadioButton) mItemView.findViewById(android.R.id.button1);
138 ImageView setting = (ImageView) mItemView.findViewById(android.R.id.button2);
139 if (mMode == position) {
140 radioButton.setChecked(true);
141 setting.setEnabled(true);
143 radioButton.setChecked(false);
144 setting.setEnabled(false);
147 if (position != getCount()-1) {
148 ((ImageView) mItemView.findViewById(R.id.divider)).setVisibility(View.INVISIBLE);
149 setting.setVisibility(View.INVISIBLE);
151 setting.setOnClickListener(new OnClickListener () {
153 public void onClick(View v) {
154 Intent intent = new Intent();
155 intent.setClass(ScreenColorSettings.this, CustomScreenColor.class);
156 startActivity(intent);
160 View v = mItemView.findViewById(R.id.widget_frame);
162 v.setOnClickListener(new OnClickListener () {
164 public void onClick(View v) {
165 int mode = (Integer)(v.getTag());
166 setScreenColorMode(mode);
167 notifyDataSetChanged();
173 private void initPPService() {
174 mPPServiceConn = new PPServiceConnection();
175 String packetname = "com.qualcomm.display";
176 String service = "com.qualcomm.display.PPService";
177 Intent i = new Intent(IPPService.class.getName());
179 ComponentName component = new ComponentName(packetname, service);
180 i.setComponent(component);
182 bindService(i, mPPServiceConn, Context.BIND_AUTO_CREATE);
185 private class PPServiceConnection implements ServiceConnection {
188 public void onServiceConnected(ComponentName name, IBinder service) {
189 mPPService = IPPService.Stub.asInterface((IBinder) service);
190 if (DEBUG) Log.d(TAG, "onServiceConnected, service=" + mPPService);
192 if (null != mPPService) {
193 mPPService.startPP();
194 setScreenColorMode(mMode);
196 } catch (RemoteException e) {
197 Log.e(TAG, "startPP exception");
202 public void onServiceDisconnected(ComponentName name) {
203 if (null != mPPService) {
206 } catch (RemoteException e) {
207 Log.e(TAG, "stopPP exception");
215 private void setScreenColorMode(int mode) {
216 if (DEBUG) Log.i(TAG, "setScreenColorMode mode = " + mode);
235 hue = mSharedPreference.getInt(COLOR_HUE, 180);
236 saturation = mSharedPreference.getInt(COLOR_SATURATION, 180);
237 intensity = mSharedPreference.getInt(COLOR_INTENSITY, 255);
238 contrast = mSharedPreference.getInt(COLOR_CONTRAST, 180);
244 updateHSCIValue(hue, saturation, intensity, contrast);
247 private void updateHSCIValue(int hue, int saturation, int intensity, int contrast) {
249 if (null != mPPService && mPPService.getPPStatus()) {
250 mPPService.updateHSIC(hue, saturation, intensity, contrast);
252 } catch (RemoteException e) {
253 Log.e(TAG, "updateHSIC exception");
258 protected void onDestroy() {
260 unbindService(mPPServiceConn);
263 private void saveModeValue(int mode) {
265 Editor editor = mSharedPreference.edit();
266 editor.putInt(COLOR_MODE, mode);