List of usage examples for android.widget CompoundButton.OnCheckedChangeListener CompoundButton.OnCheckedChangeListener
CompoundButton.OnCheckedChangeListener
From source file:net.networksaremadeofstring.rhybudd.PushSettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_push_config, container, false); progressbar = (ProgressBar) rootView.findViewById(R.id.progressBar); pushKey = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString(ZenossAPI.PREFERENCE_PUSHKEY, ""); pushEnabled = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getBoolean(ZenossAPI.PREFERENCE_PUSH_ENABLED, false); senderID = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString(ZenossAPI.PREFERENCE_PUSH_SENDERID, ""); FilterKey = (EditText) rootView.findViewById(R.id.pushFilterEditText); enabledSwitch = (Switch) rootView.findViewById(R.id.PushEnabledSwitch); registerWithZenPack = (Button) rootView.findViewById(R.id.RegisterButton); checkZenPack = (Button) rootView.findViewById(R.id.CheckButton); exitButton = (Button) rootView.findViewById(R.id.ExitButton); ZPInstalledImg = (ImageView) rootView.findViewById(R.id.ZPInstalledStatusImg); ZPDeviceRegistered = (ImageView) rootView.findViewById(R.id.ZPDevRegStatusImg); ZPVersion = (TextView) rootView.findViewById(R.id.ZenPackVersion); //Log.e("pushKey",pushKey); //Set the filter try {//from w w w. ja v a 2s.c om if (!pushKey.equals("")) { FilterKey.setText(pushKey); } } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "onCreateView", e); } try { if (checkZPImmediately) { checkZenPack.setVisibility(View.GONE); exitButton.setVisibility(View.GONE); registerWithZenPack.setVisibility(View.VISIBLE); } else { checkZenPack.setVisibility(View.VISIBLE); exitButton.setVisibility(View.VISIBLE); registerWithZenPack.setVisibility(View.GONE); } } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "onCreateView", e); } //Set the enabled setting try { enabledSwitch.setChecked(pushEnabled); enabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getActivity()) .edit(); editor.putBoolean(ZenossAPI.PREFERENCE_PUSH_ENABLED, b); editor.commit(); if (b) { RegisterWithZenPack(); } else { checkZPHandler.sendEmptyMessage(RhybuddHandlers.msg_zp_not_registered); GCMRegistrar.unregister(getActivity()); } } }); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "onCreateView", e); } try { exitButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString(ZenossAPI.PREFERENCE_URL, "").equals("")) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage( "Rhybudd needs details such as the URL and credentials in order to interact with Zenoss") .setTitle("Zenoss Credentials Needed").setCancelable(false) .setPositiveButton("Configure Zenoss Core", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { ((FirstRunSettings) getActivity()).setPushTab(0); alertDialog.cancel(); } }).setNeutralButton("Configure ZaaS", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { ((FirstRunSettings) getActivity()).setPushTab(1); alertDialog.cancel(); } }).setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent in = new Intent(); getActivity().setResult(2, in); getActivity().finish(); } }); alertDialog = builder.create(); alertDialog.show(); } else { /*progressbar.setVisibility(View.VISIBLE); //if(PushKey.getText().length() == 32) // { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit(); editor.putString(ZenossAPI.PREFERENCE_PUSHKEY, PushKey.getText().toString()); editor.commit(); progressbar.setVisibility(View.GONE);*/ Intent in = new Intent(); in.putExtra("forceRefresh", true); //in.putExtra(ZenossAPI.PREFERENCE_PUSHKEY,PushKey.getText().toString()); getActivity().setResult(1, in); getActivity().finish(); } } }); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "onCreateView", e); } try { checkZenPack.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { checkZP(); } }); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "onCreateView", e); } try { registerWithZenPack.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (hasZenPack) { RegisterWithZenPack(); } else { Toast.makeText(getActivity(), getString(R.string.PushZPErrorNoZP), Toast.LENGTH_LONG) .show(); } } }); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "onCreateView", e); } /*Button getID = (Button) rootView.findViewById(R.id.GenerateNewIDButton); getID.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //SaveKey.setVisibility(View.GONE); PushKey.setText(""); progressbar.startAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in)); progressbar.setVisibility(View.VISIBLE); ((Thread) new Thread(){ public void run() { try { String PushKey = ZenossAPI.getPushKey(); if(null != PushKey) { Message msg = new Message(); Bundle bundle = new Bundle(); msg.what = RhybuddHandlers.msg_generic_success; bundle.putString(ZenossAPIv2.PREFERENCE_PUSHKEY, PushKey); msg.setData(bundle); Message.obtain(); getIDhandler.sendMessage(msg); } else { getIDhandler.sendEmptyMessage(RhybuddHandlers.msg_generic_failure); } } catch (IOException e) { e.printStackTrace(); BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "GetKey", e); getIDhandler.sendEmptyMessage(RhybuddHandlers.msg_generic_http_transport_error); } catch (JSONException e) { e.printStackTrace(); BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "GetKey", e); getIDhandler.sendEmptyMessage(RhybuddHandlers.msg_json_error); } } }).start(); } });*/ return rootView; }
From source file:fm.krui.kruifm.StreamFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Instantiate class members prefManager = new PreferenceManager(getActivity()); favTrackManager = new FavoriteTrackManager(getActivity()); // FIXME: Move these to PreferenceManager after expanding its scope for cleaner code trackPrefs = getActivity().getSharedPreferences(StreamService.PREFS_NAME, 0); // Instantiate broadcast receiver broadcastReceiver = new BroadcastReceiver() { @Override/* ww w . ja v a2 s .c o m*/ public void onReceive(Context context, Intent intent) { processBroadcastCommand(intent); } }; // Determine the URL we need to use to stream based on the station tag and quality preferences streamUrl = getStreamUrl(stationTag); Log.v(TAG, "streamUrl is now set to: " + streamUrl); // Perform initial configuration of audio server changeUrl(stationTag); // Begin buffering the audio startAudio((ImageView) getActivity().findViewById(R.id.play_audio_imageview)); // Build play button listener final ImageView playButton = (ImageView) getActivity().findViewById(R.id.play_audio_imageview); playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handleAudio(playButton); } }); // Build volume seek bar listener // ** DISABLED FOR NOW -- This might be completely thrown out. ** /*final SeekBar volumeSeekBar = (SeekBar)getActivity().findViewById(R.id.volume_seekbar); volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { // When seek bar progress is changed, change the audio of the media player appropriately. @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // Send new volume via intent? Will this be slow? } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); */ // Build settings button listener and apply it to settings icon and submit button View.OnClickListener flipListener = new View.OnClickListener() { @Override public void onClick(View v) { // Card flip animation which toggles between stream controls and settings views flipCard(); } }; final ImageView settingsButton = (ImageView) getActivity().findViewById(R.id.stream_settings_imageview); final Button saveSettingsButton = (Button) getActivity().findViewById(R.id.set_stream_settings_button); settingsButton.setOnClickListener(flipListener); saveSettingsButton.setOnClickListener(flipListener); // Build favorite button listener final ImageView favoriteButton = (ImageView) getActivity().findViewById(R.id.stream_favorite_imageview); favoriteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (trackIsFavorite) { favoriteButton.setImageResource(R.drawable.star_unfilled_white); trackIsFavorite = false; removeTrackFromFavorites(); } else { favoriteButton.setImageResource(R.drawable.star_filled_white); trackIsFavorite = true; addTrackToFavorites(); } } }); // Build settings switches final Switch streamQualitySwitch = (Switch) getActivity().findViewById(R.id.stream_quality_switch); final Switch albumArtSwitch = (Switch) getActivity().findViewById(R.id.stream_album_art_switch); // Set initial state of switches albumArtSwitch.setChecked(prefManager.getAlbumArtDownloadPreference()); if (prefManager.getStreamQuality() == prefManager.HIGH_QUALITY) { streamQualitySwitch.setChecked(true); } else { streamQualitySwitch.setChecked(false); } // Assign listeners to switches streamQualitySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { prefManager.setStreamQuality(prefManager.HIGH_QUALITY); Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality()); } else { prefManager.setStreamQuality(prefManager.LOW_QUALITY); Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality()); } changeUrl(stationSpinnerPosition); } }); albumArtSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { prefManager.setAlbumArtDownloadPreference(true); Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference()); } else { prefManager.setAlbumArtDownloadPreference(false); Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference()); } } }); }
From source file:fm.krui.kruifm.StreamActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.stream_layout); // Instantiate class members prefManager = new PreferenceManager(this); favTrackManager = new FavoriteTrackManager(this); stationTag = getIntent().getIntExtra(KEY_STATION_TAG, -1); // Set ActionBar Title ActionBar actionBar = getActionBar(); actionBar.setTitle(getString(R.string.listen_sidebar)); actionBar.setSubtitle(getActivitySubtitle(getIntent())); // FIXME: Move these to PreferenceManager after expanding its scope for cleaner code trackPrefs = this.getSharedPreferences(StreamService.PREFS_NAME, 0); // Instantiate broadcast receiver broadcastReceiver = new BroadcastReceiver() { @Override// w ww . j a v a 2s. c o m public void onReceive(Context context, Intent intent) { processBroadcastCommand(intent); } }; // Retrieve player state to determine how to build this activity boolean playerState = prefManager.getPlayerState(); // If audio is playing in StreamService, we don't want to rebuffer, and we want to restore the UI state from the cache. if (playerState) { restoreUIState(); } // If audio is NOT playing, buffer and treat this launch like a clean startup. else { // Determine the URL we need to use to stream based on the station tag and quality preferences streamUrl = getStreamUrl(stationTag); Log.v(TAG, "streamUrl is now set to: " + streamUrl); // Perform initial configuration of audio server changeUrl(stationTag); // Begin buffering the audio startAudio((ImageView) this.findViewById(R.id.play_audio_imageview)); } // Build play button listener final ImageView playButton = (ImageView) this.findViewById(R.id.play_audio_imageview); playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handleAudio(playButton); } }); // Build volume seek bar listener // ** DISABLED FOR NOW -- This might be completely thrown out. ** /*final SeekBar volumeSeekBar = (SeekBar)this.findViewById(R.id.volume_seekbar); volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { // When seek bar progress is changed, change the audio of the media player appropriately. @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // Send new volume via intent? Will this be slow? } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); */ // Build settings button listener and apply it to settings icon and submit button View.OnClickListener flipListener = new View.OnClickListener() { @Override public void onClick(View v) { // Card flip animation which toggles between stream controls and settings views flipCard(); } }; final ImageView settingsButton = (ImageView) this.findViewById(R.id.stream_settings_imageview); final Button saveSettingsButton = (Button) this.findViewById(R.id.set_stream_settings_button); settingsButton.setOnClickListener(flipListener); saveSettingsButton.setOnClickListener(flipListener); // Build favorite button listener final ImageView favoriteButton = (ImageView) this.findViewById(R.id.stream_favorite_imageview); favoriteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (trackIsFavorite) { favoriteButton.setImageResource(R.drawable.star_unfilled_white); trackIsFavorite = false; removeTrackFromFavorites(); } else { favoriteButton.setImageResource(R.drawable.star_filled_white); trackIsFavorite = true; addTrackToFavorites(); } } }); // Build settings switches final Switch streamQualitySwitch = (Switch) this.findViewById(R.id.stream_quality_switch); final Switch albumArtSwitch = (Switch) this.findViewById(R.id.stream_album_art_switch); // Set initial state of switches albumArtSwitch.setChecked(prefManager.getAlbumArtDownloadPreference()); if (prefManager.getStreamQuality() == prefManager.HIGH_QUALITY) { streamQualitySwitch.setChecked(true); } else { streamQualitySwitch.setChecked(false); } // Assign listeners to switches streamQualitySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { prefManager.setStreamQuality(prefManager.HIGH_QUALITY); Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality()); } else { prefManager.setStreamQuality(prefManager.LOW_QUALITY); Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality()); } changeUrl(stationSpinnerPosition); } }); albumArtSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { prefManager.setAlbumArtDownloadPreference(true); Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference()); } else { prefManager.setAlbumArtDownloadPreference(false); Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference()); } } }); // ***** Old onCreate function starts here! // Initialize screen lock/wake receiver IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); BroadcastReceiver screenReceiver = new ScreenReceiver(); // Attach it to this activity this.getApplicationContext().registerReceiver(screenReceiver, filter); }
From source file:mx.klozz.xperience.tweaker.fragments.CPUSettings.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.cpu_settings, root, false); mIsTegra3 = new File(TEGRA_MAX_FREQ_PATH).exists(); mIsDynFreq = new File(DYN_MAX_FREQ_PATH).exists() && new File(DYN_MIN_FREQ_PATH).exists(); lCurrentCPU = (LinearLayout) view.findViewById(R.id.lCurCPU); mCurFreq = (TextView) view.findViewById(R.id.current_speed); mCurFreq.setOnClickListener(new View.OnClickListener() { @Override//www . ja v a2 s . c o m public void onClick(View view) { if (nCpus == 1) return; if (++MainActivity.CurrentCPU > (nCpus - 1)) MainActivity.CurrentCPU = 0; setCPUval(MainActivity.CurrentCPU); } }); mCurFreq.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { if (new File(CPU_ON_PATH.replace("cpu0", "cpu" + MainActivity.CurrentCPU)).exists() && MainActivity.CurrentCPU > 0) { final StringBuilder sb = new StringBuilder(); if (MainActivity.mCPUOn.get(MainActivity.CurrentCPU).equals("1")) { sb.append("set_val \"").append(CPU_ON_PATH.replace("cpu0", "cpu" + MainActivity.CurrentCPU)) .append("\" \"0\";\n"); MainActivity.mCPUOn.set(MainActivity.CurrentCPU, "0"); } else { sb.append("set_val \"").append(CPU_ON_PATH.replace("cpu0", "cpu" + MainActivity.CurrentCPU)) .append("\" \"1\";\n"); MainActivity.mCPUOn.set(MainActivity.CurrentCPU, "1"); } Helpers.shExec(sb, context, true); setCPUval(MainActivity.CurrentCPU); } return true; } }); final int mFrequenciesNum = MainActivity.mAvailableFrequencies.length - 1; mMaxSlider = (SeekBar) view.findViewById(R.id.max_slider); mMaxSlider.setMax(mFrequenciesNum); mMaxSlider.setOnSeekBarChangeListener(this); mMaxSpeedText = (TextView) view.findViewById(R.id.max_speed_text); mMinSlider = (SeekBar) view.findViewById(R.id.min_slider); mMinSlider.setMax(mFrequenciesNum); mMinSlider.setOnSeekBarChangeListener(this); mMinSpeedText = (TextView) view.findViewById(R.id.min_speed_text); mGovernor = (Spinner) view.findViewById(R.id.pref_governor); String[] mAvailableGovernors = Helpers.LeerUnaLinea(GOVERNORS_LIST_PATH).split(" "); ArrayAdapter<CharSequence> governorAdapter = new ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_item); governorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String mAvailableGovernor : mAvailableGovernors) { governorAdapter.add(mAvailableGovernor.trim()); } mGovernor.setAdapter(governorAdapter); mGovernor.setSelection(Arrays.asList(mAvailableGovernors) .indexOf(MainActivity.mCurrentGovernor.get(MainActivity.CurrentCPU))); mGovernor.post(new Runnable() { public void run() { mGovernor.setOnItemSelectedListener(new GovListener()); } }); mIo = (Spinner) view.findViewById(R.id.pref_io); String[] mAvailableIo = Helpers.getAvailableIOSchedulers(IO_SCHEDULER_PATH); ArrayAdapter<CharSequence> ioAdapter = new ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_item); ioAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String aMAvailableIo : mAvailableIo) { ioAdapter.add(aMAvailableIo); } mIo.setAdapter(ioAdapter); mIo.setSelection( Arrays.asList(mAvailableIo).indexOf(MainActivity.mCurrentIOSched.get(MainActivity.CurrentCPU))); mIo.post(new Runnable() { public void run() { mIo.setOnItemSelectedListener(new IOListener()); } }); Switch mSetOnBoot = (Switch) view.findViewById(R.id.cpu_sob); mSetOnBoot.setChecked(mPreferences.getBoolean(CPU_SOB, false)); mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putBoolean(CPU_SOB, checked); if (checked) { for (int i = 0; i < nCpus; i++) { editor.putString(PREF_MIN_CPU + i, MainActivity.mMinimunFreqSetting.get(i)); editor.putString(PREF_MAX_CPU + i, MainActivity.mMaximunFreqSetting.get(i)); editor.putString(PREF_GOV, MainActivity.mCurrentGovernor.get(i)); editor.putString(PREF_IO, MainActivity.mCurrentIOSched.get(i)); editor.putString("cpuon" + i, MainActivity.mCPUOn.get(i)); } } editor.apply(); } }); //if(nCpus>1){ LinearLayout vcpus[] = new LinearLayout[nCpus]; for (int i = 0; i < nCpus; i++) { vcpus[i] = (LinearLayout) inflater.inflate(R.layout.cpu_view, root, false); vcpus[i].setId(i); TextView nc = (TextView) vcpus[i].findViewById(R.id.ncpu); nc.setText(Integer.toString(i + 1)); if (i != MainActivity.CurrentCPU) nc.setText(" "); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, (float) 0.1); lCurrentCPU.addView(vcpus[i], params); } //} setCPUval(MainActivity.CurrentCPU); return view; }
From source file:com.brewcrewfoo.performance.fragments.BatteryInfo.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.battery_info, root, false); mbattery_percent = (TextView) view.findViewById(R.id.batt_percent); mbattery_volt = (TextView) view.findViewById(R.id.batt_volt); mbattery_status = (TextView) view.findViewById(R.id.batt_status); mBattIcon = (ImageView) view.findViewById(R.id.batt_icon); if (new File(BAT_VOLT_PATH).exists()) { int volt = Integer.parseInt(Helpers.readOneLine(BAT_VOLT_PATH)); if (volt > 5000) volt = (int) Math.round(volt / 1000.0);// in microvolts mbattery_volt.setText(volt + " mV"); mBattIcon.setVisibility(ImageView.GONE); mbattery_volt.setVisibility(TextView.VISIBLE); mbattery_volt.setOnClickListener(new View.OnClickListener() { @Override/*from ww w.ja v a2 s. c o m*/ public void onClick(View view) { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null) startActivity(powerUsageIntent); } }); mbattery_volt.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { mBattIcon.setVisibility(ImageView.VISIBLE); mbattery_volt.setVisibility(TextView.GONE); return true; } }); } else { mBattIcon.setVisibility(ImageView.VISIBLE); mbattery_volt.setVisibility(TextView.GONE); mBattIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); startActivity(powerUsageIntent); } catch (Exception e) { } } }); } SeekBar mBlxSlider = (SeekBar) view.findViewById(R.id.blx_slider); if (new File(BLX_PATH).exists()) { no_settings = false; mBlxSlider.setMax(100); mBlxVal = (TextView) view.findViewById(R.id.blx_val); mBlxVal.setText(getString(R.string.blx_title) + " " + Helpers.readOneLine(BLX_PATH) + "%"); mBlxSlider.setProgress(Integer.parseInt(Helpers.readOneLine(BLX_PATH))); mBlxSlider.setOnSeekBarChangeListener(this); Switch mSetOnBoot = (Switch) view.findViewById(R.id.blx_sob); mSetOnBoot.setChecked(mPreferences.getBoolean(BLX_SOB, false)); mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putBoolean(BLX_SOB, checked); if (checked) { editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH))); } editor.commit(); } }); } else { LinearLayout mpart = (LinearLayout) view.findViewById(R.id.blx_layout); mpart.setVisibility(LinearLayout.GONE); } mFastChargePath = Helpers.fastcharge_path(); if (mFastChargePath != null) { no_settings = false; mFastchargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob); mFastchargeOnBoot.setChecked( mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.readOneLine(mFastChargePath).equals("1"))); mFastchargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply(); final NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (checked) { new CMDProcessor().su.runWaitFor("busybox echo 1 > " + mFastChargePath); Notification n = new Notification.Builder(context) .setContentTitle(context.getText(R.string.app_name)) .setContentText(context.getText(R.string.fast_charge_notification_title)) .setTicker(context.getText(R.string.fast_charge_notification_title)) .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis()) .getNotification(); //n.flags = Notification.FLAG_NO_CLEAR; nm.notify(1337, n); } else { new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath); nm.cancel(1337); } } }); } else { LinearLayout mpart = (LinearLayout) view.findViewById(R.id.fastcharge_layout); mpart.setVisibility(LinearLayout.GONE); } if (no_settings) { LinearLayout ns = (LinearLayout) view.findViewById(R.id.no_settings); ns.setVisibility(LinearLayout.VISIBLE); } return view; }
From source file:mx.klozz.xperience.tweaker.fragments.BatteryInfo.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.battery_info, root, false); mBattery_Percent = (TextView) view.findViewById(R.id.battery_percent); mBattery_volt = (TextView) view.findViewById(R.id.battery_volt); mBattery_Status = (TextView) view.findViewById(R.id.battery_status); mBatteryIcon = (ImageView) view.findViewById(R.id.battery_icon); //Checamos si existe algo relacionado con la direccion de voltajes if (new File(BAT_VOLT_PATH).exists()) { int volt = Integer.parseInt(Helpers.LeerUnaLinea(BAT_VOLT_PATH));//vemos si existe el directorio if (volt > 5000) volt = (int) Math.round(volt / 1000.0);//Convertimos a microvolts mBattery_volt.setText(volt + " mV");//Hacemos visible los datos mBatteryIcon.setVisibility(ImageView.GONE); mBattery_volt.setVisibility(TextView.VISIBLE); mBattery_volt.setOnClickListener(new View.OnClickListener() { @Override/*from w w w . jav a 2 s. co m*/ public void onClick(View view) { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null) startActivity(powerUsageIntent); } }); mBattery_volt.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { mBatteryIcon.setVisibility(ImageView.VISIBLE); mBattery_volt.setVisibility(TextView.GONE); return true; } }); } else { mBatteryIcon.setVisibility(ImageView.VISIBLE); mBattery_volt.setVisibility(TextView.GONE); mBatteryIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); startActivity(powerUsageIntent); } catch (Exception e) { } } }); } mFastChargePath = Helpers.fastcharge_path(); if (mFastChargePath != null) { no_settings = false; mFastChargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob); mFastChargeOnBoot.setChecked( mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.LeerUnaLinea(mFastChargePath).equals("1"))); mFastChargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply(); final NotificationManager NM = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (checked) { new CMDProcessor().su.runWaitFor("busybox exho 1 > " + mFastChargePath); Notification N = new Notification.Builder(context) .setContentTitle(context.getText(R.string.app_name)) .setContentText(context.getText(R.string.fast_charge_notification_title)) .setTicker(context.getText(R.string.fast_charge_notification_title)) .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis()) .getNotification(); NM.notify(1337, N); } else { new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath); NM.cancel(1337); } } }); } else { LinearLayout mPart = (LinearLayout) view.findViewById(R.id.fastcharge_layout); mPart.setVisibility(LinearLayout.GONE); } if (no_settings) { LinearLayout NS = (LinearLayout) view.findViewById(R.id.no_settings); NS.setVisibility(LinearLayout.VISIBLE); } return view; }
From source file:com.ibuildapp.romanblack.FanWallPlugin.FanWallPlugin.java
private void initializeUI() { setContentView(R.layout.romanblack_fanwall_main); mainlLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_main); mainlLayout.setBackgroundColor(Statics.color1); // less then android L if (android.os.Build.VERSION.SDK_INT <= 20) { InputMethodManager im = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE); SoftKeyboard softKeyboard;/*from w ww .ja v a2 s .co m*/ softKeyboard = new SoftKeyboard(mainlLayout, im); softKeyboard.setSoftKeyboardCallback(new SoftKeyboard.SoftKeyboardChanged() { @Override public void onSoftKeyboardHide() { Message msg = handler.obtainMessage(HANDLE_TAP_BAR, 1, 0); handler.sendMessage(msg); } @Override public void onSoftKeyboardShow() { Message msg = handler.obtainMessage(HANDLE_TAP_BAR, 0, 0); handler.sendMessage(msg); } }); } bottomBarHodler = (LinearLayout) findViewById(R.id.romanblack_fanwall_main_bottom_bar); TextView noMsgText = (TextView) findViewById(R.id.romanblack_fanwall_nomessages_text); // top bar setTopBarLeftButtonText(getResources().getString(R.string.common_home_upper), true, new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); // set title if (TextUtils.isEmpty(widget.getTitle())) setTopBarTitle(getString(R.string.fanwall_talks)); else setTopBarTitle(widget.getTitle()); imageHolder = (LinearLayout) findViewById(R.id.fanwall_image_holder); userImage = (ImageView) findViewById(R.id.fanwall_user_image); closeBtn = (ImageView) findViewById(R.id.fanwall_close_image); closeBtn.setOnClickListener(this); chooserHolder = (LinearLayout) findViewById(R.id.fanwall_chooser_holder); openBottom = (LinearLayout) findViewById(R.id.romanblack_fanwall_open_bottom); openBottom.setOnClickListener(this); enableGpsCheckbox = (CheckBox) findViewById(R.id.romanblack_fanwall_enable_gps_checkbox); enableGpsCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b) { if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { final AlertDialog.Builder builder = new AlertDialog.Builder(FanWallPlugin.this); builder.setMessage(getString(R.string.enable_gps_msg)).setCancelable(false) .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) { startActivityForResult( new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), GPS_SETTINGS_ACTIVITY); } }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) { enableGpsCheckbox.setChecked(false); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.show(); } else { Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, true); } } else Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, false); } }); enableGpsCheckbox.setChecked(Prefs.with(FanWallPlugin.this).getBoolean(Prefs.KEY_GPS, false)); galleryChooser = (LinearLayout) findViewById(R.id.romanblack_fanwall_gallery); galleryChooser.setOnClickListener(this); photoChooser = (LinearLayout) findViewById(R.id.romanblack_fanwall_make_photo); photoChooser.setOnClickListener(this); postMsg = (LinearLayout) findViewById(R.id.romanblack_fanwall_send_post); postMsg.setOnClickListener(this); editMsg = (EditText) findViewById(R.id.romanblack_fanwall_edit_msg); editMsg.addTextChangedListener(FanWallPlugin.this); tabHolder = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder); tabHolder.setBackgroundColor(res.getColor(R.color.black_50_trans)); LinearLayout separator = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder_separator); separator.setBackgroundColor(res.getColor(R.color.white_30_trans)); LinearLayout separatorUp = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder_up); LinearLayout separatorDown = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder_down); tabMapLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_map_layout); tabMapLayout.setOnClickListener(this); tabPhotosLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_photos_layout); tabPhotosLayout.setOnClickListener(this); if (Statics.isSchemaDark) { separatorUp.setBackgroundColor(res.getColor(R.color.white_20_trans)); separatorDown.setBackgroundColor(res.getColor(R.color.white_20_trans)); int temp = Color.WHITE & 0x00ffffff; int result = temp | 0x80000000; noMsgText.setTextColor(result); } else { separatorUp.setBackgroundColor(res.getColor(R.color.black_20_trans)); separatorDown.setBackgroundColor(res.getColor(R.color.black_20_trans)); int temp = Color.BLACK & 0x00ffffff; int result = temp | 0x80000000; noMsgText.setTextColor(result); } noMessagesLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_main_nomessages_layout); messageListLayoutRoot = (FrameLayout) findViewById(R.id.romanblack_fanwall_messagelist_list_layout); messageList = (PullToRefreshListView) findViewById(R.id.romanblack_fanwall_messagelist_pulltorefresh); messageList.setDivider(null); messageList.setBackgroundColor(Color.TRANSPARENT); messageList.setDrawingCacheBackgroundColor(Color.TRANSPARENT); ILoadingLayout loadingLayout = messageList.getLoadingLayoutProxy(); if (Statics.isSchemaDark) { loadingLayout.setHeaderColor(Color.WHITE); } else { loadingLayout.setHeaderColor(Color.BLACK); } //messageList.set adapter = new MainLayoutMessagesAdapter(FanWallPlugin.this, messageList, messages, widget); adapter.setInnerInterface(new MainLayoutMessagesAdapter.onEndReached() { @Override public void endReached() { if (!refreshingBottom) refreshBottom(); } }); messageList.setAdapter(adapter); messageList.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() { @Override public void onRefresh(PullToRefreshBase<ListView> refreshView) { refreshTop(); } }); if (Statics.canEdit.compareToIgnoreCase("all") == 0) { bottomBarHodler.setVisibility(View.VISIBLE); } else { bottomBarHodler.setVisibility(View.GONE); } // start downloading messages // exactly in create() method!!! handler.sendEmptyMessage(SHOW_PROGRESS_DIALOG); refreshMessages(); }
From source file:nf.frex.android.FrexActivity.java
private void prepareColorsDialog(final Dialog dialog) { //Log.d(TAG, "prepareColorsDialog() entered"); getColorSchemes();//from w ww . j a va 2 s . c om //Log.d(TAG, "prepareColorsDialog: new bitmaps are being created"); Bitmap[] colorSchemeIcons = new Bitmap[colorSchemes.getSize()]; for (int i = 0; i < colorSchemeIcons.length; i++) { ColorScheme colorScheme = colorSchemes.getValue(i); colorSchemeIcons[i] = colorScheme.getGradientIcon(); } int checkedIndex = Registries.colorSchemes.getIndex(view.getColorSchemeId()); //Log.d(TAG, "prepareColorsDialog: checkedIndex = " + checkedIndex); final Spinner colorTableSpinner = (Spinner) dialog.findViewById(R.id.color_table_spinner); colorTableSpinner.setAdapter(new ImageArrayAdapter(this, 0, colorSchemeIcons)); colorTableSpinner.setSelection(checkedIndex, false); colorTableSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) { view.setColorSchemeId(Registries.colorSchemes.getId(position)); view.setColorScheme(Registries.colorSchemes.getValue(position)); view.recomputeColors(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); final SeekBar colorFactorSeekBar = (SeekBar) dialog.findViewById(R.id.color_gain_seek_bar); final double colorFactorMin = -3.0; final double colorFactorMax = 2.0; final SeekBarConfigurer colorFactorSeekBarConfigurer = SeekBarConfigurer.create(colorFactorSeekBar, colorFactorMin, colorFactorMax, true, view.getColorGain()); colorFactorSeekBar.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) { view.setColorGain((float) colorFactorSeekBarConfigurer.getValue()); view.recomputeColors(); } }); final SeekBar colorBiasSeekBar = (SeekBar) dialog.findViewById(R.id.color_offset_seek_bar); final double colorBiasMin = 0; final double colorBiasMax = 1024; final SeekBarConfigurer colorBiasSeekBarConfigurer = SeekBarConfigurer.create(colorBiasSeekBar, colorBiasMin, colorBiasMax, false, view.getColorOffset()); colorBiasSeekBar.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) { view.setColorOffset((float) colorBiasSeekBarConfigurer.getValue()); view.recomputeColors(); } }); final CheckBox colorRepeatCheckBox = (CheckBox) dialog.findViewById(R.id.color_repeat); colorRepeatCheckBox.setChecked(view.isColorRepeat()); colorRepeatCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { view.setColorRepeat(isChecked); view.recomputeColors(); } }); Button randomButton = (Button) dialog.findViewById(R.id.random_button); randomButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { colorTableSpinner.setSelection((int) (Math.random() * colorSchemes.getSize())); colorFactorSeekBarConfigurer.setRandomValue(); colorBiasSeekBarConfigurer.setRandomValue(); view.recomputeColors(); } }); Button getPalFromImgButton = (Button) dialog.findViewById(R.id.get_pal_from_img_button); getPalFromImgButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); dialog.dismiss(); startActivityForResult(photoPickerIntent, SELECT_PICTURE_REQUEST_CODE); } }); //Log.d(TAG, "prepareColorsDialog() exited"); }
From source file:com.juick.android.MainActivity.java
public void updateNavigation() { navigationItems = new ArrayList<NavigationItem>(); List<MicroBlog> blogs = new ArrayList<MicroBlog>(microBlogs.values()); Collections.<MicroBlog>sort(blogs, new Comparator<MicroBlog>() { @Override//from w w w .j a v a 2 s. c om public int compare(MicroBlog microBlog, MicroBlog microBlog2) { return microBlog.getPiority() - microBlog2.getPiority(); } }); for (MicroBlog blog : blogs) { blog.addNavigationSources(navigationItems, this); } navigationItems.add(new NavigationItem(NAVITEM_UNREAD, R.string.navigationUnread, R.drawable.navicon_juickadvanced, "msrcUnread") { @Override public void action() { final NavigationItem thisNi = this; final ProgressDialog pd = new ProgressDialog(MainActivity.this); pd.setIndeterminate(true); pd.setTitle(R.string.navigationUnread); pd.setCancelable(true); pd.show(); UnreadSegmentsView.loadPeriods(MainActivity.this, new Utils.Function<Void, ArrayList<DatabaseService.Period>>() { @Override public Void apply(ArrayList<DatabaseService.Period> periods) { if (pd.isShowing()) { pd.cancel(); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final AlertDialog alerDialog; if (periods.size() == 0) { alerDialog = builder.setTitle(getString(R.string.UnreadSegments)) .setMessage(getString(R.string.YouHaveNotEnabledForUnreadSegments)) .setCancelable(true) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }).create(); } else { UnreadSegmentsView unreadSegmentsView = new UnreadSegmentsView( MainActivity.this, periods); final int myIndex = navigationItems.indexOf(thisNi); alerDialog = builder.setTitle(getString(R.string.ChooseUnreadSegment)) .setView(unreadSegmentsView).setCancelable(true) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }) .create(); unreadSegmentsView.setListener(new UnreadSegmentsView.PeriodListener() { @Override public void onPeriodClicked(DatabaseService.Period period) { alerDialog.dismiss(); int beforeMid = period.beforeMid; Bundle args = new Bundle(); args.putSerializable("messagesSource", new UnreadSegmentMessagesSource( getString(R.string.navigationUnread), MainActivity.this, period)); if (getSelectedNavigationIndex() != myIndex) { setSelectedNavigationItem(myIndex); } runDefaultFragmentWithBundle(args, thisNi); } }); } alerDialog.show(); restyleChildrenOrWidget(alerDialog.getWindow().getDecorView()); } return null; } }); return; } }); navigationItems.add(new NavigationItem(NAVITEM_SAVED, R.string.navigationSaved, R.drawable.navicon_juickadvanced, "msrcSaved") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new SavedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_READ, R.string.navigationRecentlyOpened, R.drawable.navicon_juickadvanced, "msrcRecentOpen") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyOpenedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_WRITE, R.string.navigationRecentlyCommented, R.drawable.navicon_juickadvanced, "msrcRecentComment") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyCommentedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_ALL_COMBINED, R.string.navigationAllCombined, R.drawable.navicon_juickadvanced, "msrcAllCombined") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedAllMessagesSource(MainActivity.this, "combined_all")); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllCombined(); break; } } }); navigationItems.add(new NavigationItem(NAVITEM_SUBS_COMBINED, R.string.navigationSubsCombined, R.drawable.navicon_juickadvanced, "msrcSubsCombined") { @Override public void action() { final NavigationItem thiz = this; new Thread("MessageSource Initializer") { @Override public void run() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedSubscriptionMessagesSource(MainActivity.this)); runOnUiThread(new Runnable() { @Override public void run() { runDefaultFragmentWithBundle(args, thiz); } }); } }.start(); final Bundle args = new Bundle(); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllSubs(); break; } } }); int index = 10000; final SharedPreferences sp_order = getSharedPreferences("messages_source_ordering", MODE_PRIVATE); for (NavigationItem navigationItem : navigationItems) { navigationItem.itemOrder = sp_order.getInt("order_" + navigationItem.id, -1); if (navigationItem.itemOrder == -1) { navigationItem.itemOrder = index; sp_order.edit().putInt("order_" + navigationItem.id, navigationItem.itemOrder).commit(); } index++; } Collections.sort(navigationItems, new Comparator<NavigationItem>() { @Override public int compare(NavigationItem lhs, NavigationItem rhs) { return lhs.itemOrder - rhs.itemOrder; // increasing } }); allNavigationItems = new ArrayList<NavigationItem>(navigationItems); final Iterator<NavigationItem> iterator = navigationItems.iterator(); while (iterator.hasNext()) { NavigationItem next = iterator.next(); if (next.sharedPrefsKey != null) { if (!sp.getBoolean(next.sharedPrefsKey, defaultValues(next.sharedPrefsKey))) { iterator.remove(); } } } sp_order.edit().commit(); // save final boolean compressedMenu = sp.getBoolean("compressedMenu", false); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final float finalMenuFontScale = menuFontScale; navigationList = (DragSortListView) findViewById(R.id.navigation_list); // adapter for old-style navigation final BaseAdapter navigationAdapter = new BaseAdapter() { @Override public int getCount() { return navigationItems.size(); } @Override public Object getItem(int position) { return navigationItems.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } final int screenHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight(); final int layoutId = R.layout.simple_list_item_1_mine; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); if (parent instanceof Spinner) { tv.setTextSize(18 * finalMenuFontScale); tv.setEllipsize(TextUtils.TruncateAt.MARQUEE); } else { tv.setTextSize(22 * finalMenuFontScale); } tv.setText(getString(navigationItems.get(position).labelId)); if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } retval.setPressedListener(new PressableLinearLayout.PressedListener() { @Override public void onPressStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } @Override public void onSelectStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } }); MainActivity.restyleChildrenOrWidget(retval, false); return retval; } }; // adapter for new-style navigation final BaseAdapter navigationListAdapter = new BaseAdapter() { @Override public int getCount() { return getItems().size(); } private ArrayList<NavigationItem> getItems() { if (navigationList.isDragEnabled()) { return allNavigationItems; } else { return navigationItems; } } @Override public Object getItem(int position) { return getItems().get(position); } @Override public long getItemId(int position) { return position; } float textSize = -1; @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } if (textSize < 0) { View inflate = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView text = (TextView) inflate.findViewById(android.R.id.text1); textSize = text.getTextSize(); } final int layoutId = R.layout.navigation_list_item; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); final ArrayList<NavigationItem> items = getItems(); final NavigationItem theItem = items.get(position); tv.setText(getString(theItem.labelId)); ImageButton menuButton = (ImageButton) retval.findViewById(R.id.menu_button); menuButton.setFocusable(false); ArrayList<String> menuItems = theItem.getMenuItems(); menuButton.setVisibility(menuItems != null && menuItems.size() > 0 ? View.VISIBLE : View.GONE); menuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { doNavigationItemMenu(theItem); } }); ImageView iv = (ImageView) retval.findViewById(android.R.id.icon); iv.setImageResource(theItem.imageId); retval.findViewById(R.id.draggable) .setVisibility(items != allNavigationItems ? View.GONE : View.VISIBLE); retval.findViewById(R.id.checkbox).setVisibility( items != allNavigationItems || theItem.sharedPrefsKey == null ? View.GONE : View.VISIBLE); CheckBox cb = (CheckBox) retval.findViewById(R.id.checkbox); cb.setOnCheckedChangeListener(null); if (theItem.sharedPrefsKey != null) { cb.setChecked(sp.getBoolean(theItem.sharedPrefsKey, defaultValues(theItem.sharedPrefsKey))); } cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { sp.edit().putBoolean(theItem.sharedPrefsKey, isChecked).commit(); } }); int spacing = sp.getInt("navigation_spacing", 0); tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize + spacing); retval.setPadding(0, spacing, 0, spacing); return retval; } }; ActionBar bar = getSupportActionBar(); updateActionBarMode(); navigationList.setDragEnabled(false); ((DragSortController) navigationList.getFloatViewManager()).setDragHandleId(R.id.draggable); navigationList.setAdapter(navigationListAdapter); navigationList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { setSelectedNavigationItem(position); closeNavigationMenu(true, false); } }); navigationList.setDropListener(new DragSortListView.DropListener() { @Override public void drop(int from, int to) { final NavigationItem item = allNavigationItems.remove(from); allNavigationItems.add(to, item); int index = 0; for (NavigationItem allNavigationItem : allNavigationItems) { if (allNavigationItem.itemOrder != index) { allNavigationItem.itemOrder = index; sp_order.edit().putInt("order_" + allNavigationItem.id, allNavigationItem.itemOrder) .commit(); } index++; } sp_order.edit().commit(); // save navigationListAdapter.notifyDataSetChanged(); //To change body of implemented methods use File | Settings | File Templates. } }); bar.setListNavigationCallbacks(navigationAdapter, this); final View navigationMenuButton = (View) findViewById(R.id.navigation_menu_button); navigationMenuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(MainActivity.this) .setItems(navigationList.isDragEnabled() ? R.array.navigation_menu_end : R.array.navigation_menu_start, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int spacing = sp.getInt("navigation_spacing", 0); switch (which) { case 0: if (navigationList.isDragEnabled()) { navigationList.setDragEnabled(false); updateNavigation(); } else { navigationList.setDragEnabled(true); } break; case 1: final Map<String, ?> all = sp_order.getAll(); for (String s : all.keySet()) { sp_order.edit().remove(s).commit(); } sp_order.edit().commit(); updateNavigation(); break; case 2: // wider sp.edit().putInt("navigation_spacing", spacing + 1).commit(); ((BaseAdapter) navigationList.getAdapter()).notifyDataSetInvalidated(); break; case 3: // narrower if (spacing > 0) { sp.edit().putInt("navigation_spacing", spacing - 1).commit(); ((BaseAdapter) navigationList.getAdapter()) .notifyDataSetInvalidated(); } break; case 4: // logout from.. logoutFromSomeServices(); break; } navigationListAdapter.notifyDataSetChanged(); } }) .setCancelable(true).create().show(); } }); final SharedPreferences spn = getSharedPreferences("saved_last_navigation_type", MODE_PRIVATE); int restoredLastNavItem = spn.getInt("last_navigation", 0); if (restoredLastNavItem != 0) { NavigationItem allSources = null; for (int i = 0; i < navigationItems.size(); i++) { NavigationItem navigationItem = navigationItems.get(i); if (navigationItem.labelId == restoredLastNavItem) { lastNavigationItem = navigationItem; } if (navigationItem.labelId == R.string.navigationAll) { allSources = navigationItem; } } if (lastNavigationItem == null) { lastNavigationItem = allSources; // could be null if not configured } if (lastNavigationItem == null && navigationItems.size() > 0) { lastNavigationItem = navigationItems.get(0); // last default } if (lastNavigationItem != null) { restoreLastNavigationPosition(); lastNavigationItem.action(); } } }