@Override protected void onResume() { super.onResume(); SharedPreferences settings = getSharedPreferences("Settings", Context.MODE_PRIVATE); // Put the saved URL in the EditText String url = settings.getString("url", "http://uinelj.eu/misc/rpgm/"); ((EditText) findViewById(R.id.editTextURL)).setText(url); // Put the saved nickname in the EditText String nickname = settings.getString("nickname", "foo"); ((EditText) findViewById(R.id.editTextNick)).setText(nickname); // Put the saved language as default on spinner String lang = settings.getString("locale", "en_US"); String language; switch (lang) { case "fr_FR": language = "Français"; break; case "en_US": default: language = "English"; break; } String[] array = {"English", "Français"}; ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.activity_options, array); langSelect.setSelection(adapter.getPosition(language)); // Checks or not the notification option according to the saved preference SharedPreferences notifSettings = getSharedPreferences("notifications", Context.MODE_PRIVATE); allowNotif.setChecked(notifSettings.getBoolean("allow", true)); }
@Override protected void onDestroy() { if (mAdView != null) { mAdView.destroy(); } super.onDestroy(); }
@Override protected void onResume() { super.onResume(); EpiTime.getInstance().setCurrentActivity(this); EpiTime.getInstance().sendScreen("com.epitime.groupList"); EpiTime.getInstance().sendEvent("GroupList", this.school, ""); }
@Override protected void onResume() { super.onResume(); IntentFilter filter = new IntentFilter(SendServiceHelper.ACTION_REQUEST_RESULT); requestReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int resultRequestId = intent.getIntExtra(SendServiceHelper.EXTRA_REQUEST_ID, 0); Log.d( LOG_TAG, "Received intent " + intent.getAction() + ", request ID " + resultRequestId); int resultCode = intent.getIntExtra(SendServiceHelper.EXTRA_RESULT_CODE, 0); Log.d(LOG_TAG, String.valueOf(resultCode)); RequestType requestType = requestsIdMap.remove(resultRequestId); switch (requestType) { case COMMENT_VOTE: if (resultCode != 200) { switch (resultCode) { case 406: Toast.makeText( getApplicationContext(), R.string.you_already_vote_for_this_comment, Toast.LENGTH_SHORT) .show(); break; default: handleResponseErrors(resultCode); break; } } break; case COMMENT_NEW: if (resultCode != 200) { handleResponseErrors(resultCode); } else { mMessageTextInput.setText(""); mCommentsRecyclerView.smoothScrollToPosition(0); } break; case COMMENT_LIST: if (resultCode != 200) { handleResponseErrors(resultCode); } break; } } }; if (mAdView != null) { mAdView.resume(); } registerReceiver(requestReceiver, filter); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(LOG_TAG, "onCreate"); Intent intent = getIntent(); imageId = intent.getIntExtra(IMAGE_ID_EXTRA, -1); Log.d(LOG_TAG, "Image ID: " + String.valueOf(imageId)); getSupportLoaderManager().restartLoader(0, null, this); setContentView(R.layout.activity_comments); mCommentsRecyclerView = (RecyclerView) findViewById(R.id.comments_recycler_view); mCommentsAdapter = new CommentsAdapter(); mCommentsAdapter.setOnItemClickListener(this); mCommentsRecyclerView.setAdapter(mCommentsAdapter); mCommentsRecyclerView.setItemAnimator(new DefaultItemAnimator()); mCommentsRecyclerView.setLayoutManager( new LinearLayoutManager(getApplication().getApplicationContext())); mSendButton = (ImageView) findViewById(R.id.send_button); mSendButton.setOnClickListener(this); mMessageTextInput = (EditText) findViewById(R.id.message_text_input); mMessageTextInput.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { mSendButton.setImageDrawable( getResources() .getDrawable( s.length() >= MIN_INPUT_TEXT_LENGTH ? R.drawable.ic_arrow_forward_white_48dp : R.drawable.ic_arrow_forward_black_48dp)); } }); if (isNeedToShowAd) { mAdView = (AdView) findViewById(R.id.advertising_block); mAdView.loadAd(adRequest); } requestsIdMap.put( SendServiceHelper.getInstance(this).requestCommentList(imageId), RequestType.COMMENT_LIST); }
@Override protected void onPause() { super.onPause(); if (mAdView != null) { mAdView.pause(); } if (requestReceiver != null) { try { this.unregisterReceiver(requestReceiver); } catch (IllegalArgumentException e) { Log.e(LOG_TAG, e.getLocalizedMessage(), e); } } }
@Override public void onCreate(Bundle savedInstanceState) { this.hasNoGroup = this.getIntent().getExtras().getBoolean("NoGroup"); this.school = this.getIntent().getExtras().getString("School"); this.layout = R.layout.activity_group_select; super.onCreate(savedInstanceState); EpiTime.getInstance().setCurrentActivity(this); if (hasNoGroup) { this.drawerToggle.isDrawerOpened = true; this.drawerLayout.openDrawer(Gravity.LEFT); } this.groupList = (ListView) this.findViewById(R.id.group_list); this.groupList.setOnItemClickListener(new OnGroupListItemClick()); this.addHeaders(); this.reloadListView(); }
@Override // Used when clicking a menu item protected void onItemSelection(AdapterView<?> parent, View view, int position, long id) { Intent intent; switch (position) { case 0: intent = new Intent(this, CharacterSheetActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent); break; case 1: intent = new Intent(this, DiceActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent); break; case 2: super.updateLocale(); mDrawerLayout.closeDrawers(); break; default: break; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // inflate your activity layout here! View contentView = inflater.inflate(R.layout.folder_list_activity_main, null, false); mDrawerLayout.addView(contentView, 0); androidOpenDbHelperObj = new NoteshareDatabaseHelper(context); sqliteDatabase = androidOpenDbHelperObj.getWritableDatabase(); DataManager.sharedDataManager().setSelectedIndex(-1); initlizeUIElement(contentView); // getDeafultNote(); getallNotes(); // getAllFolder(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_options); // Initializes the button to test the connection to the server testCon = (Button) findViewById(R.id.buttonCon); testCon.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // Gets the URL String urlString = ((EditText) findViewById(R.id.editTextURL)).getText().toString(); if (!(urlString.startsWith("http://") || urlString.startsWith("https://"))) { urlString = "http://" + urlString; } // Tries to connect try { URL url = new URL(urlString); HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); urlc.setRequestMethod("HEAD"); urlc.setConnectTimeout(5 * 1000); urlc.setReadTimeout(5 * 1000); urlc.connect(); if (urlc.getResponseCode() == HttpURLConnection.HTTP_OK) { Log.d(TAG, "Reachable destination"); Toast.makeText(OptionsActivity.this, R.string.toast_r_dest, Toast.LENGTH_SHORT) .show(); if (!urlString.endsWith("/")) { urlString += "/"; } Log.d(TAG, "Saving URL " + urlString); SharedPreferences settings = getSharedPreferences("Settings", Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putString("url", urlString); editor.apply(); } } catch (IOException e) { Log.d(TAG, "Unreachable destination"); Toast.makeText(OptionsActivity.this, R.string.toast_unr_dest, Toast.LENGTH_SHORT) .show(); } } }); // Button to change the user's nickname acceptNick = (Button) findViewById(R.id.ok_button); acceptNick.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // Changes the user's nickname in the preferences String nickname = ((EditText) findViewById(R.id.editTextNick)).getText().toString(); SharedPreferences settings = getSharedPreferences("Settings", Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putString("nickname", nickname); editor.apply(); Toast.makeText( OptionsActivity.this, getResources().getString(R.string.toast_new_nick) + " : " + nickname, Toast.LENGTH_SHORT) .show(); } }); // Button to change the language loadLocale = (Button) findViewById(R.id.buttonLocale); loadLocale.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // Restart the activity Intent intent = OptionsActivity.this.getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); OptionsActivity.this.finish(); startActivity(intent); } }); // Spinner of languages langSelect = (Spinner) findViewById(R.id.spinnerLanguages); langSelect.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String selected = parent.getSelectedItem().toString(); String lang; switch (selected) { case "Français": lang = "fr_FR"; break; case "English": default: lang = "en_US"; break; } Log.d(TAG, "SELECTED lang=" + lang); // Updates the preferences SharedPreferences settings = getSharedPreferences("Settings", Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putString("locale", lang); editor.apply(); OptionsActivity.super.updateLocale(); } @Override public void onNothingSelected(AdapterView<?> parent) {} }); allowNotif = (CheckBox) findViewById(R.id.allowNotifCheck); allowNotif.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { SharedPreferences notifSettings = getSharedPreferences("notifications", Context.MODE_PRIVATE); SharedPreferences.Editor editor = notifSettings.edit(); editor.putBoolean("allow", isChecked); editor.apply(); if (isChecked) { Intent notifIntent = new Intent(getApplicationContext(), NotificationService.class); notifIntent.addCategory(NotificationService.TAG); stopService(notifIntent); startService(notifIntent); } } }); }