List of usage examples for java.lang NullPointerException printStackTrace
public void printStackTrace()
From source file:com.github.developerpaul123.filepickerlibrary.FilePickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; //get the theme type for this activity themeType = (ThemeType) getIntent().getSerializableExtra(THEME_TYPE); if (themeType == null) { themeType = ThemeType.ACTIVITY;/* www . j av a2 s . c om*/ } setThemeType(themeType); areButtonsShowing = false; try { getActionBar().setDisplayHomeAsUpEnabled(true); } catch (NullPointerException e) { e.printStackTrace(); } //set up the mime type for the file. Object rawMimeTypeParameter = getIntent().getExtras().get(MIME_TYPE); if (rawMimeTypeParameter instanceof String) { mimeType = (String) rawMimeTypeParameter; } else if (rawMimeTypeParameter instanceof MimeType) { mimeType = ((MimeType) rawMimeTypeParameter).getMimeType(); } else { mimeType = null; } //set up the animations setUpAnimations(); Intent givenIntent = getIntent(); //get the scope type and request code. Defaults are all files and request of a directory //path. scopeType = (Scope) givenIntent.getSerializableExtra(SCOPE); if (scopeType == null) { //set default if it is null scopeType = Scope.ALL; } requestCode = (Request) givenIntent.getSerializableExtra(REQUEST); colorId = givenIntent.getIntExtra(INTENT_EXTRA_COLOR_ID, android.R.color.holo_blue_light); drawableId = givenIntent.getIntExtra(INTENT_EXTRA_DRAWABLE_ID, -1); fabColorId = givenIntent.getIntExtra(INTENT_EXTRA_FAB_COLOR_ID, -1); setContentView(R.layout.file_picker_activity_layout); listView = (ListView) findViewById(android.R.id.list); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (areButtonsShowing) { if (Math.abs(firstVisibleItem - mLastFirstVisibleItem) >= 3) { hideButtons(); adapter.setSelectedPosition(-1); mLastFirstVisibleItem = firstVisibleItem; } else if (firstVisibleItem > adapter.getSelectedPosition()) { hideButtons(); adapter.setSelectedPosition(-1); } } else { mLastFirstVisibleItem = firstVisibleItem; } } }); listHeaderView = getLayoutInflater().inflate(R.layout.file_list_header_view, null); listHeaderView.setFocusable(false); listHeaderView.setClickable(false); listHeaderView.setOnClickListener(null); listHeaderView.setActivated(false); initializeViews(); //drawable has not been set so set the color. setHeaderBackground(colorId, drawableId); //check for proper permissions. if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { //Show permission rationale. new MaterialDialog.Builder(this).title(R.string.file_picker_permission_rationale_dialog_title) .content(R.string.file_picker_permission_rationale_dialog_content) .positiveText(R.string.file_picker_ok).negativeText(R.string.file_picker_cancel) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { ActivityCompat.requestPermissions(FilePickerActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_FOR_READ_EXTERNAL_STORAGE); } }).onNegative(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { setResult(RESULT_CANCELED); finish(); } }).show(); } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_FOR_READ_EXTERNAL_STORAGE); } } else { init(); } } else { init(); } }
From source file:com.ti.sensortag.gui.services.ServicesActivity.java
/** * This class listens to changes in the model of sensor values. * *///from www . j a v a 2s . c om @Override public void propertyChange(final PropertyChangeEvent event) { final String property = event.getPropertyName(); runOnUiThread(new Runnable() { public void run() { try { /*if (property.equals(PROPERTY_ACCELEROMETER)) { // A change in accelerometer data has occured. Point3D newValue = (Point3D) event.getNewValue(); String xaxis = decimal.format(newValue.x); String yaxis = decimal.format(newValue.y); String zaxis = decimal.format(newValue.z); String acl = "X: " + decimal.format(newValue.x) + "g" + "\nY: " + decimal.format(newValue.y) + "g" + "\nZ: " + decimal.format(newValue.z) + "g"; ((TextView) findViewById(R.id.accelerometerTxt)).setText(acl); } } else */if (property.equals(PROPERTY_AMBIENT_TEMPERATURE)) { double newAmbientValue = (Double) event.getNewValue(); final int img; TextView textView = (TextView) findViewById(R.id.ambientTemperatureTxt); String formattedText = "Touch Not Detected"; if (newAmbientValue == 11.00) { formattedText = "Touch Detected"; //img = touch; } else { //img = notouch; } //((ImageView) findViewById(R.id.touch)).setImageResource(img); textView.setText(formattedText); } /*ARVelse*/ else if (property.equals(PROPERTY_IR_TEMPERATURE)) { double newIRValue = (Double) event.getNewValue(); // float newIRValue_1 = (Float) event.getNewValue(); TextView textView = (TextView) findViewById(R.id.ir_temperature); String value = decimal.format(newIRValue); String formattedText = value + DEGREE_SYM; wakelockk.acquire(); textView.setText(formattedText); tempwriteintoafile(value); analyze(Float.valueOf(value), patient); // Added by Nihesh for analysis of incoming readings. //ARV /*try { java.util.Date date = new java.util.Date(); Timestamp chk = new Timestamp(date.getTime()); long timemilli = System.currentTimeMillis(); String abc = String.valueOf(timemilli);//chk.toString(); String separator = System.getProperty("line.separator"); File ext = Environment.getExternalStorageDirectory(); File myFile = new File(ext, "mysdfile_7.txt"); if(myFile.exists()){ try { FileOutputStream fOut = new FileOutputStream(myFile,true); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(abc); myOutWriter.append(" "); myOutWriter.append(formattedText_1); myOutWriter.append(separator); myOutWriter.flush(); myOutWriter.close(); fOut.close(); } catch (Exception e) { // TODO: handle exception } } else{ myFile.createNewFile(); } // File myFile = new File("/sdcard/mysdfile.txt"); // myFile.createNewFile(); // FileOutputStream fOut = new FileOutputStream(myFile); //ARV OutputStreamWriter myOutWriter = //ARV new OutputStreamWriter(openFileOutput(FILENAME, Context.MODE_APPEND));//fOut // myOutWriter.append(txtData.getText()); //ARV myOutWriter.write(abc); //ARV myOutWriter.append(separator); //ARV myOutWriter.flush(); //ARV myOutWriter.close(); // fOut.close(); Toast.makeText(getBaseContext(), "Done writing SD 'mysdfile.txt'", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } //ARV */ } //endif /* else if (property.equals(PROPERTY_HUMIDITY)) { double newHumidity = (Double) event.getNewValue(); // ARV TextView textView = (TextView) findViewById(R.id.humidityTxt); String formattedText = decimal.format(newHumidity) + "%rH"; //ARV textView.setText(formattedText); } else if (property.equals(PROPERTY_MAGNETOMETER)) { Point3D newValue = (Point3D) event.getNewValue(); String msg = "X: " + decimal.format(newValue.x) + "uT" + "\nY: " + decimal.format(newValue.y) + "uT" + "\nZ: " + decimal.format(newValue.z) + "uT"; //ARV ((TextView) findViewById(R.id.magnetometerTxt)).setText(msg); } else if (property.equals(PROPERTY_GYROSCOPE)) { Point3D newValue = (Point3D) event.getNewValue(); String msg = "X: " + decimal.format(newValue.x) + "deg/s" + "\nY: " + decimal.format(newValue.y) + "deg/s" + "\nZ: " + decimal.format(newValue.z) + "deg/s"; //ARV ((TextView) findViewById(R.id.gyroscopeTxt)).setText(msg); } else if (property.equals(Measurements.PROPERTY_BAROMETER)) { Double newValue = (Double) event.getNewValue(); String msg = new DecimalFormat("+0.0;-0.0").format(newValue / 100) + " hPa"; //ARV ((TextView) findViewById(R.id.barometerTxt)).setText(msg); } else if (property.equals(PROPERTY_SIMPLE_KEYS)) { SimpleKeysStatus newValue = (SimpleKeysStatus) event.getNewValue(); final int img; switch (newValue) { case OFF_OFF: img = buttonsoffoff; break; case OFF_ON: img = buttonsoffon; break; case ON_OFF: img = buttonsonoff; break; case ON_ON: img = buttonsonon; break; default: throw new UnsupportedOperationException(); } ((ImageView) findViewById(R.id.buttons)).setImageResource(img); }*/ else if (property.equals(LOST_DEVICE_ + CONNECTED)) { // A device has been disconnected // We notify the user with a toast int duration = Toast.LENGTH_SHORT; String text = "Lost connection"; Toast.makeText(ServicesActivity.this, text, duration).show(); finish(); } else if (property.equals(NEW_DEVICE_ + CONNECTED)) { // A device has been disconnected // We notify the user with a toast int duration = Toast.LENGTH_SHORT; String text = "Established connection"; Toast.makeText(ServicesActivity.this, text, duration).show(); } } catch (NullPointerException e) { e.printStackTrace(); // Could be that the ServicesFragment is no longer visible // But we still receive property change events. // referring to the views with findViewById will then return a null. } } }); }
From source file:org.mewx.wenku8.fragment.NavigationDrawerFragment.java
/** * This function will highlight the button selected, and switch to the fragment in MainActivity. * * @param f the target fragment, type MainActivity.FRAGMENT_LIST. *//*from www . j a v a2s.c om*/ private void setHighLightButton(MainActivity.FRAGMENT_LIST f) { // sdk ver is too low if (Build.VERSION.SDK_INT < 16) { try { switch (f) { case RKLIST: ((TextView) mainActivity.findViewById(R.id.main_menu_text_rklist)) .setTextColor(getResources().getColor(R.color.menu_item_blue)); ((ImageButton) mainActivity.findViewById(R.id.main_menu_ic_rklist)) .setColorFilter(getResources().getColor(R.color.menu_item_blue)); break; case LATEST: ((TextView) mainActivity.findViewById(R.id.main_menu_text_latest)) .setTextColor(getResources().getColor(R.color.menu_item_blue)); ((ImageButton) mainActivity.findViewById(R.id.main_menu_ic_latest)) .setColorFilter(getResources().getColor(R.color.menu_item_blue)); break; case FAV: ((TextView) mainActivity.findViewById(R.id.main_menu_text_fav)) .setTextColor(getResources().getColor(R.color.menu_item_blue)); ((ImageButton) mainActivity.findViewById(R.id.main_menu_ic_fav)) .setColorFilter(getResources().getColor(R.color.menu_item_blue)); break; case CONFIG: ((TextView) mainActivity.findViewById(R.id.main_menu_text_config)) .setTextColor(getResources().getColor(R.color.menu_item_blue)); ((ImageButton) mainActivity.findViewById(R.id.main_menu_ic_config)) .setColorFilter(getResources().getColor(R.color.menu_item_blue)); break; } } catch (NullPointerException e) { Toast.makeText(mainActivity, "NullPointerException in setHighLightButton(); sdk16-", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } } else { try { switch (f) { case RKLIST: mainActivity.findViewById(R.id.main_menu_rklist) .setBackground(getResources().getDrawable(R.drawable.btn_menu_item_selected)); ((TextView) mainActivity.findViewById(R.id.main_menu_text_rklist)) .setTextColor(getResources().getColor(R.color.menu_text_color_selected)); ((ImageButton) mainActivity.findViewById(R.id.main_menu_ic_rklist)) .setColorFilter(getResources().getColor(R.color.menu_item_white)); break; case LATEST: mainActivity.findViewById(R.id.main_menu_latest) .setBackground(getResources().getDrawable(R.drawable.btn_menu_item_selected)); ((TextView) mainActivity.findViewById(R.id.main_menu_text_latest)) .setTextColor(getResources().getColor(R.color.menu_text_color_selected)); ((ImageButton) mainActivity.findViewById(R.id.main_menu_ic_latest)) .setColorFilter(getResources().getColor(R.color.menu_item_white)); break; case FAV: mainActivity.findViewById(R.id.main_menu_fav) .setBackground(getResources().getDrawable(R.drawable.btn_menu_item_selected)); ((TextView) mainActivity.findViewById(R.id.main_menu_text_fav)) .setTextColor(getResources().getColor(R.color.menu_text_color_selected)); ((ImageButton) mainActivity.findViewById(R.id.main_menu_ic_fav)) .setColorFilter(getResources().getColor(R.color.menu_item_white)); break; case CONFIG: mainActivity.findViewById(R.id.main_menu_config) .setBackground(getResources().getDrawable(R.drawable.btn_menu_item_selected)); ((TextView) mainActivity.findViewById(R.id.main_menu_text_config)) .setTextColor(getResources().getColor(R.color.menu_text_color_selected)); ((ImageButton) mainActivity.findViewById(R.id.main_menu_ic_config)) .setColorFilter(getResources().getColor(R.color.menu_item_white)); break; } } catch (NullPointerException e) { Toast.makeText(mainActivity, "NullPointerException in setHighLightButton();", Toast.LENGTH_SHORT) .show(); e.printStackTrace(); } } }
From source file:com.ibuildapp.romanblack.NewsPlugin.NewsPlugin.java
/** * Called when module colors was parsed. */// ww w. ja v a 2s . co m private void colorsReceived() { setTopBarBackgroundColor(Statics.color1); try { mainLayout.setBackgroundColor(Statics.color1); } catch (NullPointerException nPEx) { nPEx.printStackTrace(); } }
From source file:fm.krui.kruifm.StreamFragment.java
private void addTrackToFavorites() { String trackName = ""; String artistAlbumName = ""; TextView trackNameTextView = (TextView) getActivity().findViewById(R.id.song_name_textview); TextView artistAlbumNameTextView = (TextView) getActivity().findViewById(R.id.artist_album_name_textview); // Extract text from their views try {//from w w w . j a v a2 s . c o m trackName = trackNameTextView.getText().toString(); artistAlbumName = artistAlbumNameTextView.getText().toString(); } catch (NullPointerException e) { Log.e(TAG, "Caught NullPointerException when extracting values from StreamFragment textviews!"); e.printStackTrace(); } // Build a Track from currently playing track. Track track = new Track(); track.setTitle(trackName); // Separate Artist/Album Name String[] arr = artistAlbumName.split("-"); track.setAlbum(arr[1]); track.setArtist(arr[0]); // Add this track to favorites favTrackManager.addTrackToFavorites(track); String message = getString(R.string.add_favorite); showStreamStatusBar(message, false); }
From source file:cz.zcu.kiv.eegdatabase.webservices.client.ClientServiceImpl.java
@Override public int addExperiment(ExperimentInfo info) { Experiment experiment = new Experiment(); try {//from w w w . ja v a2s.c o m log.debug("Client Service - adding new measuration"); log.debug("Creating new Measuration object"); log.debug("Setting the owner to the logged user."); Person owner = personDao.read(info.getOwnerPersonId()); experiment.setPersonByOwnerId(owner); log.debug("Setting the group, which is the new experiment being added into."); ResearchGroup researchGroup = researchGroupDao.read(info.getResearchGroupId()); researchGroup.setResearchGroupId(info.getResearchGroupId()); experiment.setResearchGroup(researchGroup); Weather weather = weatherDao.read(info.getWeatherId()); weather.setWeatherId(info.getWeatherId()); experiment.setWeather(weather); log.debug("Setting Scenario object - ID " + info.getScenarioId()); Scenario scenario = scenarioDao.read(info.getScenarioId()); scenario.setScenarioId(info.getScenarioId()); experiment.setScenario(scenario); log.debug("Setting Person object (measured person) - ID " + info.getSubjectPersonId()); Person subjectPerson = personDao.read(info.getSubjectPersonId()); subjectPerson.setPersonId(info.getSubjectPersonId()); experiment.setPersonBySubjectPersonId(subjectPerson); experiment.setStartTime(new Timestamp(info.getStartTimeInMillis())); log.debug("Setting start date - " + info.getStartTimeInMillis()); experiment.setEndTime(new Timestamp(info.getEndTimeInMillis())); log.debug("Setting end date - " + info.getEndTimeInMillis()); log.debug("Setting the temperature - " + info.getTemperature()); experiment.setTemperature(info.getTemperature()); log.debug("Setting the weather note - " + info.getWeatherNote()); experiment.setEnvironmentNote(info.getWeatherNote()); log.debug("Started setting the Hardware objects"); List<Integer> hwList = info.getHwIds(); Set<Hardware> hardwareSet = new HashSet<Hardware>(); for (int hardwareId : hwList) { Hardware tempHardware = hardwareDao.read(hardwareId); hardwareSet.add(tempHardware); tempHardware.getExperiments().add(experiment); log.debug("Added Hardware object - ID " + hardwareId); } log.debug("Setting Hardware list to Measuration object"); experiment.setHardwares(hardwareSet); Digitization digitization = new Digitization(); digitization.setFilter("Unknown"); digitization.setGain(1); digitization.setSamplingRate(1); digitizationDao.create(digitization); // TODO digitization setters experiment.setDigitization(digitization); SubjectGroup subjectGroup = new SubjectGroup(); subjectGroup.setTitle("Unknown"); subjectGroup.setDescription("Unknown"); // TODO subject group setters subjectGroupDao.create(subjectGroup); experiment.setSubjectGroup(subjectGroup); Artifact artifact = new Artifact(); artifact.setCompensation("Unknown"); artifact.setRejectCondition("Unknown"); artifactDao.create(artifact); // TODO artifact setters experiment.setArtifact(artifact); ElectrodeSystem system = new ElectrodeSystem(); system.setDescription("Unknown"); system.setTitle("Unknown"); // TODO electrode system setters electrodeSystemDao.create(system); ElectrodeConf conf = new ElectrodeConf(); conf.setImpedance(1); conf.setElectrodeSystem(system); electrodeConfDao.create(conf); // TODO conf setters experiment.setElectrodeConf(conf); log.debug("Setting private/public access"); experiment.setPrivateExperiment(info.isPrivateExperiment()); log.debug("Saving the Measuration object to database using DAO - create()"); return experimentDao.create(experiment); } catch (NullPointerException n) { n.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return -1; }
From source file:com.devpaul.filepickerlibrary.FilePickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; //get the theme type for this activity themeType = (ThemeType) getIntent().getSerializableExtra(THEME_TYPE); if (themeType == null) { themeType = ThemeType.ACTIVITY;/*from w w w .j ava 2s . com*/ } setThemeType(themeType); areButtonsShowing = false; try { getActionBar().setDisplayHomeAsUpEnabled(true); } catch (NullPointerException e) { e.printStackTrace(); } //set up the mime type for the file. Object rawMimeTypeParameter = getIntent().getExtras().get(MIME_TYPE); if (rawMimeTypeParameter instanceof String) { mimeType = (String) rawMimeTypeParameter; } else if (rawMimeTypeParameter instanceof FileType) { mimeType = ((FileType) rawMimeTypeParameter).getMimeType(); } else { mimeType = null; } //set up the animations setUpAnimations(); Intent givenIntent = getIntent(); //get the scope type and request code. Defaults are all files and request of a directory //path. scopeType = (FileScopeType) givenIntent.getSerializableExtra(SCOPE_TYPE); if (scopeType == null) { //set default if it is null scopeType = FileScopeType.ALL; } requestCode = givenIntent.getIntExtra(REQUEST_CODE, REQUEST_DIRECTORY); colorId = givenIntent.getIntExtra(INTENT_EXTRA_COLOR_ID, android.R.color.holo_blue_light); drawableId = givenIntent.getIntExtra(INTENT_EXTRA_DRAWABLE_ID, -1); fabColorId = givenIntent.getIntExtra(INTENT_EXTRA_FAB_COLOR_ID, -1); setContentView(R.layout.file_picker_activity_layout); listView = (ListView) findViewById(android.R.id.list); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (areButtonsShowing) { if (Math.abs(firstVisibleItem - mLastFirstVisibleItem) >= 3) { hideButtons(); adapter.setSelectedPosition(-1); mLastFirstVisibleItem = firstVisibleItem; } else if (firstVisibleItem > adapter.getSelectedPosition()) { hideButtons(); adapter.setSelectedPosition(-1); } } else { mLastFirstVisibleItem = firstVisibleItem; } } }); listHeaderView = getLayoutInflater().inflate(R.layout.file_list_header_view, null); listHeaderView.setFocusable(false); listHeaderView.setClickable(false); listHeaderView.setOnClickListener(null); listHeaderView.setActivated(false); initializeViews(); //drawable has not been set so set the color. setHeaderBackground(colorId, drawableId); //check for proper permissions. if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { //Show permission rationale. new MaterialDialog.Builder(FilePickerActivity.this) .title(R.string.file_picker_permission_rationale_dialog_title) .content(R.string.file_picker_permission_rationale_dialog_content) .positiveText(R.string.file_picker_ok).negativeText(R.string.file_picker_cancel) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { ActivityCompat.requestPermissions(FilePickerActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_FOR_READ_EXTERNAL_STORAGE); } @Override public void onNegative(MaterialDialog dialog) { setResult(RESULT_CANCELED); finish(); } }).show(); } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_FOR_READ_EXTERNAL_STORAGE); } } else { init(); } } else { init(); } }
From source file:com.softminds.matrixcalculator.MainActivity.java
@Override protected void onActivityResult(int requestcode, int resultCode, Intent data) { super.onActivityResult(requestcode, resultCode, data); if (resultCode == RESULT) { if (data != null) { Bundle AllData = new Bundle(); AllData.putAll(data.getExtras()); try { MatrixV2 m = MatrixV2.constructFromBundle(AllData); ((GlobalValues) getApplication()).AddToGlobal(m); //Sending the things to Global Reference if (actionBar.getSubtitle() == null) actionBar.setSubtitle(R.string.MainSubtitle); t.setText(null);/* www . j ava 2 s.c o m*/ Toast.makeText(getApplicationContext(), R.string.Created, Toast.LENGTH_SHORT).show(); } catch (NullPointerException e2) { e2.printStackTrace(); Log.d("NullException:", "The Adapter was Null Forcing user to Refresh"); EnforceRefresh(); } catch (Exception ignored) { //catch Exception apart fro above two and ignore it } } } if (resultCode == 100) this.recreate(); // Recreate this Activity if a Change in Theme has been marked }
From source file:net.networksaremadeofstring.rhybudd.PushSettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Log.e("onCreate","onCreate"); setHasOptionsMenu(true);/*w w w . j av a 2 s .c o m*/ if (null != getArguments() && getArguments().containsKey("checkZPImmediately")) checkZPImmediately = getArguments().getBoolean("checkZPImmediately"); // Check for available NFC Adapter mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity()); if (null != mNfcAdapter) { // Register callback mNfcAdapter.setNdefPushMessageCallback(this, getActivity()); } checkZPHandler = new Handler() { public void handleMessage(Message msg) { try { if (null != progressbar) { progressbar.startAnimation( AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out)); progressbar.setVisibility(View.GONE); } } catch (NullPointerException npe) { npe.printStackTrace(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "checkZPHandler", e); } switch (msg.what) { /*case RhybuddHandlers.msg_push_show_undo: { FilterKey.setText(msg.getData().getString("newfilterkey")); try { if(null == undoMenuItem) { menu.add(Menu.NONE,MENU_UNDO,Menu.NONE,"Undo"); undoMenuItem = menu.findItem(MENU_UNDO); undoMenuItem.setIcon(R.drawable.ic_action_content_undo); undoMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); } getActivity().invalidateOptionsMenu(); } catch(Exception e) { e.printStackTrace(); BugSenseHandler.sendExceptionMessage("PushSettingsFragment","processIntent",e); } } break;*/ case RhybuddHandlers.msg_generic_http_transport_error: { try { Toast.makeText(getActivity(), getActivity().getString(R.string.PushZPNoHost), Toast.LENGTH_LONG).show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "checkZPHandler msg_generic_http_transport_error", e); } } break; case RhybuddHandlers.msg_zp_is_installed: { try { hasZenPack = true; ZPInstalledImg.setImageResource(R.drawable.ic_acknowledged); ZPDeviceRegistered.setImageResource(R.drawable.ic_unacknowledged); ZPVersion.setText("1.0.1"); enabledSwitch.setEnabled(hasZenPack); registerWithZenPack.setEnabled(hasZenPack); if (checkZPImmediately) { RegisterWithZenPack(); } else { checkZenPack.setVisibility(View.VISIBLE); registerWithZenPack.setVisibility(View.GONE); } } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "checkZPHandler msg_zp_is_installed", e); } } break; case RhybuddHandlers.msg_zp_not_installed: { try { hasZenPack = false; ZPInstalledImg.setImageResource(R.drawable.ic_unacknowledged); ZPDeviceRegistered.setImageResource(R.drawable.ic_unacknowledged); ZPVersion.setText("----"); enabledSwitch.setEnabled(hasZenPack); registerWithZenPack.setEnabled(hasZenPack); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "checkZPHandler msg_zp_not_installed", e); } } break; case RhybuddHandlers.msg_zp_registered: { try { ZPDeviceRegistered.setImageResource(R.drawable.ic_acknowledged); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "checkZPHandler msg_zp_registered", e); } } break; case RhybuddHandlers.msg_zp_not_registered: { try { ZPDeviceRegistered.setImageResource(R.drawable.ic_unacknowledged); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "checkZPHandler msg_zp_not_registered", e); } } break; } } }; getIDhandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case RhybuddHandlers.msg_generic_success: { try { String pushKey = msg.getData().getString(ZenossAPI.PREFERENCE_PUSHKEY); progressbar.setVisibility(View.GONE); //PushKey.startAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in)); //PushKey.setVisibility(View.VISIBLE); PushKeyDesc.startAnimation( AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in)); PushKeyDesc.setVisibility(View.VISIBLE); //PushKey.setText(pushKey); SharedPreferences.Editor editor = PreferenceManager .getDefaultSharedPreferences(getActivity()).edit(); editor.putString(ZenossAPI.PREFERENCE_PUSHKEY, pushKey); editor.commit(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "getIDhandler msg_generic_success", e); } } break; case RhybuddHandlers.msg_json_error: { try { progressbar.setVisibility(View.GONE); Toast.makeText(getActivity(), getString(R.string.JSONExceptionMessage), Toast.LENGTH_LONG) .show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "getIDhandler msg_json_error", e); } } break; case RhybuddHandlers.msg_generic_http_transport_error: { try { progressbar.setVisibility(View.GONE); Toast.makeText(getActivity(), getString(R.string.HttpTransportExceptionMessage), Toast.LENGTH_LONG).show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "getIDhandler msg_json_error", e); } } break; case RhybuddHandlers.msg_generic_failure: { try { progressbar.setVisibility(View.GONE); Toast.makeText(getActivity(), getString(R.string.GenericExceptionMessage), Toast.LENGTH_LONG).show(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "getIDhandler msg_generic_failure", e); } } break; } } }; }
From source file:org.mewx.wenku8.fragment.NavigationDrawerFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // set button clicked listener, mainly working on change fragment in MainActivity. try {/* w ww. j a v a 2 s. c o m*/ mainActivity.findViewById(R.id.main_menu_rklist).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mainActivity.getCurrentFragment() == MainActivity.FRAGMENT_LIST.RKLIST) return; // selected button, so just ignore. clearAllButtonColor(); setHighLightButton(MainActivity.FRAGMENT_LIST.RKLIST); mainActivity.setCurrentFragment(MainActivity.FRAGMENT_LIST.RKLIST); mainActivity.changeFragment(new RKListFragment()); closeDrawer(); } }); mainActivity.findViewById(R.id.main_menu_latest).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mainActivity.getCurrentFragment() == MainActivity.FRAGMENT_LIST.LATEST) return; // selected button, so just ignore. clearAllButtonColor(); setHighLightButton(MainActivity.FRAGMENT_LIST.LATEST); mainActivity.setCurrentFragment(MainActivity.FRAGMENT_LIST.LATEST); mainActivity.changeFragment(new LatestFragment()); closeDrawer(); } }); mainActivity.findViewById(R.id.main_menu_fav).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mainActivity.getCurrentFragment() == MainActivity.FRAGMENT_LIST.FAV) return; // selected button, so just ignore. clearAllButtonColor(); setHighLightButton(MainActivity.FRAGMENT_LIST.FAV); mainActivity.setCurrentFragment(MainActivity.FRAGMENT_LIST.FAV); mainActivity.changeFragment(new FavFragment()); closeDrawer(); } }); mainActivity.findViewById(R.id.main_menu_config).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mainActivity.getCurrentFragment() == MainActivity.FRAGMENT_LIST.CONFIG) return; // selected button, so just ignore. clearAllButtonColor(); setHighLightButton(MainActivity.FRAGMENT_LIST.CONFIG); mainActivity.setCurrentFragment(MainActivity.FRAGMENT_LIST.CONFIG); mainActivity.changeFragment(new ConfigFragment()); closeDrawer(); } }); mainActivity.findViewById(R.id.main_menu_open_source).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new MaterialDialog.Builder(getActivity()).theme(Theme.LIGHT).title(R.string.main_menu_statement) .content(GlobalConfig.getOpensourceLicense()).forceStacking(true) .positiveColorRes(R.color.dlgPositiveButtonColor) .positiveText(R.string.dialog_positive_known).show(); } }); mainActivity.findViewById(R.id.main_menu_dark_mode_switcher) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openOrCloseDarkMode(); } }); } catch (NullPointerException e) { Toast.makeText(mainActivity, "NullPointerException in onActivityCreated();", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } // User Account // RelativeLayout rlBackground = (RelativeLayout)getActivity().findViewById(R.id.top_background); rivUserAvatar = (RoundedImageView) getActivity().findViewById(R.id.user_avatar); tvUserName = (TextView) getActivity().findViewById(R.id.user_name); View.OnClickListener ocl = new View.OnClickListener() { @Override public void onClick(View v) { if (!LightUserSession.getLogStatus() && GlobalConfig.isNetworkAvailable(getActivity())) { if (!LightUserSession.isUserInfoSet()) { Intent intent = new Intent(getActivity(), UserLoginActivity.class); startActivity(intent); } else { // show dialog to login, error to jump to login activity if (LightUserSession.aiui.getStatus() == AsyncTask.Status.FINISHED) { Toast.makeText(getActivity(), "Relogged.", Toast.LENGTH_SHORT).show(); LightUserSession.aiui = new LightUserSession.AsyncInitUserInfo(); LightUserSession.aiui.execute(); } } } else if (!GlobalConfig.isNetworkAvailable(getActivity())) { // no network, no log in Toast.makeText(getActivity(), getResources().getString(R.string.system_network_error), Toast.LENGTH_SHORT).show(); } else { // Logged, click to info page Intent intent = new Intent(getActivity(), UserInfoActivity.class); startActivity(intent); } } }; rivUserAvatar.setOnClickListener(ocl); tvUserName.setOnClickListener(ocl); // Initial: set color states here ... // get net work status, no net -> FAV if (!GlobalConfig.isNetworkAvailable(getActivity())) { clearAllButtonColor(); setHighLightButton(MainActivity.FRAGMENT_LIST.FAV); mainActivity.setCurrentFragment(MainActivity.FRAGMENT_LIST.FAV); mainActivity.changeFragment(new FavFragment()); } else { clearAllButtonColor(); setHighLightButton(mainActivity.getCurrentFragment()); mainActivity.changeFragment(new LatestFragment()); } // set menu background bgImage = (ImageView) getActivity().findViewById(R.id.bg_img); if (GlobalConfig.getFromAllSetting(GlobalConfig.SettingItems.menu_bg_id) != null) { switch (GlobalConfig.getFromAllSetting(GlobalConfig.SettingItems.menu_bg_id)) { case "0": try { bmMenuBackground = BitmapFactory .decodeFile(GlobalConfig.getFromAllSetting(GlobalConfig.SettingItems.menu_bg_path)); } catch (OutOfMemoryError oome) { try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; bmMenuBackground = BitmapFactory.decodeFile( GlobalConfig.getFromAllSetting(GlobalConfig.SettingItems.menu_bg_path), options); if (bmMenuBackground == null) throw new Exception("PictureLoadFailureException"); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getActivity(), "Exception: " + e.toString() + "\n??SD?????", Toast.LENGTH_SHORT).show(); bgImage.setImageDrawable(getResources().getDrawable(R.drawable.bg_avatar_04)); return; } } bgImage.setImageBitmap(bmMenuBackground); break; case "1": bgImage.setImageDrawable(getResources().getDrawable(R.drawable.bg_avatar_01)); break; case "2": bgImage.setImageDrawable(getResources().getDrawable(R.drawable.bg_avatar_02)); break; case "3": bgImage.setImageDrawable(getResources().getDrawable(R.drawable.bg_avatar_03)); break; case "4": bgImage.setImageDrawable(getResources().getDrawable(R.drawable.bg_avatar_04)); break; case "5": bgImage.setImageDrawable(getResources().getDrawable(R.drawable.bg_avatar_05)); break; } } }