Back to project page android_device.
The source code is released under:
[Apache License](http://www.apache.org/licenses/): Version 2.0, January 2004 =============== ## TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION ## ### 1. Definitions. ### "License" sha...
If you think the Android project android_device listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * ================================================================================================= * Copyright (C) 2013 - 2014 Martin Albedinsky [Wolf-ITechnologies] * ================================================================================================= * Licensed under the Apache License, Version 2.0 or later (further "License" only). * ------------------------------------------------------------------------------------------------- * You may use this file only in compliance with the License. More details and copy of this License * you may obtain at/*from w w w.j a va 2 s .com*/ * * http://www.apache.org/licenses/LICENSE-2.0 * * You can redistribute, modify or publish any part of the code written within this file but as it * is described in the License, the software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES or CONDITIONS OF ANY KIND. * * See the License for the specific language governing permissions and limitations under the License. * ================================================================================================= */ package com.wit.android.device.examples.fragment; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.CheckBox; import android.widget.EditText; import android.widget.SeekBar; import android.widget.Spinner; import com.wit.android.device.examples.R; import com.wit.android.device.examples.adapter.OrientationsAdapter; import com.wit.android.device.Screen; import com.wit.android.device.util.ScreenUtils; import com.wit.android.examples.libs.fragment.annotation.ExActionBarOptions; import com.wit.android.examples.libs.fragment.annotation.ExClickableViews; import com.wit.android.examples.libs.fragment.annotation.ExContentView; import com.wit.android.examples.libs.fragment.annotation.ExInjectView; import com.wit.android.examples.libs.fragment.annotation.ExInjectViews; /** * <p> * Description. * </p> * * @author Martin Albedinsky */ @ExInjectViews @ExClickableViews({ R.id.fragment_screen_interface_button_hide_keyboard, R.id.fragment_screen_interface_button_show_keyboard }) @ExContentView(R.layout.fragment_screen_interface) @ExActionBarOptions(title = R.string.Navigation_Label_ScreenInterface) public class ScreenInterfaceFragment extends BaseDeviceFragment implements Spinner.OnItemSelectedListener { /** * Log TAG. */ // private static final String TAG = ScreenInterfaceFragment.class.getSimpleName(); /** * */ private static final String BUNDLE_SELECTED_ORIENTATION = "com.wit.android.device.examples.fragment.ScreenInterfaceFragment.BUNDLE.SelectedOrientation"; @ExInjectView(value = R.id.fragment_screen_interface_check_box_lock_orientation, clickable = true) private CheckBox mCheckLockOrientation; @ExInjectView(R.id.fragment_screen_interface_edit_text) private EditText mEdit; /** * Android device's screen wrapper. */ private Screen mScreen; /** * */ private OrientationsAdapter mOrientationsAdapter; /** */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Obtain screen wrapper. this.mScreen = getAndroidDevice().getScreen(); } /** */ @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // Set up orientation adapter. this.mOrientationsAdapter = new OrientationsAdapter(getActivity()); if (savedInstanceState != null) { mOrientationsAdapter.dispatchItemSelected(savedInstanceState.getInt(BUNDLE_SELECTED_ORIENTATION)); } // Set up orientation spinner. final Spinner spinner = (Spinner) view.findViewById(R.id.fragment_screen_interface_spinner_change_orientation); spinner.setAdapter(mOrientationsAdapter); spinner.setOnItemSelectedListener(this); // Set up brightness seek bar. final SeekBar brightnessSeekBar = (SeekBar) view.findViewById(R.id.fragment_screen_interface_seek_bar_brightness); brightnessSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { /** */ @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } /** */ @Override public void onStartTrackingTouch(SeekBar seekBar) { } /** */ @Override public void onStopTrackingTouch(SeekBar seekBar) { mScreen.setBrightness(seekBar.getProgress(), getActivity()); } }); brightnessSeekBar.setProgress(mScreen.getSystemBrightness()); } /** */ @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (mOrientationsAdapter.dispatchItemSelected(position)) { // Check selected orientation. final Screen.ScreenOrientation orientation = mOrientationsAdapter.getItem(position); switch (orientation) { case USER: mCheckLockOrientation.setChecked(false); break; } mScreen.requestOrientation(orientation, getActivity()); } } /** */ @Override protected boolean onViewClick(View view, int id) { switch (id) { case R.id.fragment_screen_interface_check_box_lock_orientation: if (((CheckBox) view).isChecked()) { mScreen.lockOrientation(getActivity()); } else { mScreen.requestOrientation(Screen.ScreenOrientation.FULL_SENSOR, getActivity()); } return true; case R.id.fragment_screen_interface_button_hide_keyboard: ScreenUtils.hideSoftKeyboard(getActivity()); return true; case R.id.fragment_screen_interface_button_show_keyboard: ScreenUtils.showSoftKeyboard(mEdit); return true; } return super.onViewClick(view, id); } /** */ @Override public void onNothingSelected(AdapterView<?> parent) { } /** */ @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(BUNDLE_SELECTED_ORIENTATION, mOrientationsAdapter.getSelectedPosition()); } }