List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:org.computeforcancer.android.PrefsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (Logging.VERBOSE) Log.d(Logging.TAG, "ProjectsFragment onCreateView"); // Inflate the layout for this fragment View layout = inflater.inflate(R.layout.prefs_layout, container, false); lv = (ListView) layout.findViewById(R.id.listview); listAdapter = new PrefsListAdapter(getActivity(), this, R.id.listview, data); lv.setAdapter(listAdapter);/*from ww w .j ava2 s. c om*/ final SharedPreferences mSharedPreferences = getContext().getSharedPreferences( "org.computeforcancer.android", Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS); mAutoStart = (SwitchCompat) layout.findViewById(R.id.switchRun); mAutoStart.setChecked(mSharedPreferences.getBoolean(SharedPrefs.AUTO_START, true)); mAutoStart.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mSharedPreferences.edit().putBoolean(SharedPrefs.AUTO_START, b).commit(); try { BOINCActivity.monitor.setAutostart(b); BOINCActivity.monitor.setRunMode(b ? BOINCDefs.RUN_MODE_AUTO : BOINCDefs.RUN_MODE_NEVER); } catch (RemoteException e) { e.printStackTrace(); } } }); mDailyButton = (AppCompatRadioButton) layout.findViewById(R.id.checkBtnDaily); mDailyButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { mDailyButton.setChecked(true); mWeeklyButton.setChecked(false); mMonthlyButton.setChecked(false); mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, DAY).commit(); } }); mWeeklyButton = (AppCompatRadioButton) layout.findViewById(R.id.checkBtnWeekly); mWeeklyButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { mDailyButton.setChecked(false); mWeeklyButton.setChecked(true); mMonthlyButton.setChecked(false); mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, WEEK).commit(); } }); mMonthlyButton = (AppCompatRadioButton) layout.findViewById(R.id.checkBtnMonthly); mMonthlyButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { mDailyButton.setChecked(false); mWeeklyButton.setChecked(false); mMonthlyButton.setChecked(true); mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, MONTH).commit(); } }); final SwitchCompat notificationSwitch = (SwitchCompat) layout.findViewById(R.id.switchNotifications); notificationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b) { mDailyButton.setChecked(true); mWeeklyButton.setChecked(false); mMonthlyButton.setChecked(false); mDailyButton.setEnabled(true); mWeeklyButton.setEnabled(true); mMonthlyButton.setEnabled(true); if (mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE) == Long.MAX_VALUE) { mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, DAY).commit(); } } else { mDailyButton.setChecked(true); mWeeklyButton.setChecked(false); mMonthlyButton.setChecked(false); mDailyButton.setEnabled(false); mWeeklyButton.setEnabled(false); mMonthlyButton.setEnabled(false); mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE).commit(); } } }); if (mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE) == DAY) { notificationSwitch.setChecked(true); mDailyButton.setChecked(true); mWeeklyButton.setChecked(false); mMonthlyButton.setChecked(false); mDailyButton.setEnabled(true); mWeeklyButton.setEnabled(true); mMonthlyButton.setEnabled(true); } else if (mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE) == WEEK) { notificationSwitch.setChecked(true); mDailyButton.setChecked(false); mWeeklyButton.setChecked(true); mMonthlyButton.setChecked(false); mDailyButton.setEnabled(true); mWeeklyButton.setEnabled(true); mMonthlyButton.setEnabled(true); } else if (mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE) == MONTH) { notificationSwitch.setChecked(true); mDailyButton.setChecked(false); mWeeklyButton.setChecked(false); mMonthlyButton.setChecked(true); mDailyButton.setEnabled(true); mWeeklyButton.setEnabled(true); mMonthlyButton.setEnabled(true); } else { notificationSwitch.setChecked(false); mDailyButton.setChecked(true); mWeeklyButton.setChecked(false); mMonthlyButton.setChecked(false); mDailyButton.setEnabled(false); mWeeklyButton.setEnabled(false); mMonthlyButton.setEnabled(false); } return layout; }
From source file:com.farmerbb.taskbar.service.TaskbarService.java
@SuppressLint("RtlHardcoded") private void drawTaskbar() { IconCache.getInstance(this).clearCache(); // Initialize layout params windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); U.setCachedRotation(windowManager.getDefaultDisplay().getRotation()); final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT);/* w ww .j av a 2s . c om*/ // Determine where to show the taskbar on screen switch (U.getTaskbarPosition(this)) { case "bottom_left": layoutId = R.layout.taskbar_left; params.gravity = Gravity.BOTTOM | Gravity.LEFT; positionIsVertical = false; break; case "bottom_vertical_left": layoutId = R.layout.taskbar_vertical; params.gravity = Gravity.BOTTOM | Gravity.LEFT; positionIsVertical = true; break; case "bottom_right": layoutId = R.layout.taskbar_right; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; positionIsVertical = false; break; case "bottom_vertical_right": layoutId = R.layout.taskbar_vertical; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; positionIsVertical = true; break; case "top_left": layoutId = R.layout.taskbar_left; params.gravity = Gravity.TOP | Gravity.LEFT; positionIsVertical = false; break; case "top_vertical_left": layoutId = R.layout.taskbar_top_vertical; params.gravity = Gravity.TOP | Gravity.LEFT; positionIsVertical = true; break; case "top_right": layoutId = R.layout.taskbar_right; params.gravity = Gravity.TOP | Gravity.RIGHT; positionIsVertical = false; break; case "top_vertical_right": layoutId = R.layout.taskbar_top_vertical; params.gravity = Gravity.TOP | Gravity.RIGHT; positionIsVertical = true; break; } // Initialize views int theme = 0; SharedPreferences pref = U.getSharedPreferences(this); switch (pref.getString("theme", "light")) { case "light": theme = R.style.AppTheme; break; case "dark": theme = R.style.AppTheme_Dark; break; } boolean altButtonConfig = pref.getBoolean("alt_button_config", false); ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme); layout = (LinearLayout) LayoutInflater.from(wrapper).inflate(layoutId, null); taskbar = (LinearLayout) layout.findViewById(R.id.taskbar); scrollView = (FrameLayout) layout.findViewById(R.id.taskbar_scrollview); if (altButtonConfig) { space = (Space) layout.findViewById(R.id.space_alt); layout.findViewById(R.id.space).setVisibility(View.GONE); } else { space = (Space) layout.findViewById(R.id.space); layout.findViewById(R.id.space_alt).setVisibility(View.GONE); } space.setOnClickListener(v -> toggleTaskbar()); startButton = (ImageView) layout.findViewById(R.id.start_button); int padding; if (pref.getBoolean("app_drawer_icon", false)) { startButton.setImageDrawable(ContextCompat.getDrawable(this, R.mipmap.ic_launcher)); padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding_alt); } else { startButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.all_apps_button_icon)); padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding); } startButton.setPadding(padding, padding, padding, padding); startButton.setOnClickListener(ocl); startButton.setOnLongClickListener(view -> { openContextMenu(); return true; }); startButton.setOnGenericMotionListener((view, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) openContextMenu(); return false; }); refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "2")) * 1000); if (refreshInterval == 0) refreshInterval = 100; sortOrder = pref.getString("sort_order", "false"); runningAppsOnly = pref.getString("recents_amount", "past_day").equals("running_apps_only"); switch (pref.getString("recents_amount", "past_day")) { case "past_day": searchInterval = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY; break; case "app_start": long oneDayAgo = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY; long appStartTime = pref.getLong("time_of_service_start", System.currentTimeMillis()); long deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime(); long startTime = deviceStartTime > appStartTime ? deviceStartTime : appStartTime; searchInterval = startTime > oneDayAgo ? startTime : oneDayAgo; break; } Intent intent = new Intent("com.farmerbb.taskbar.HIDE_START_MENU"); LocalBroadcastManager.getInstance(TaskbarService.this).sendBroadcast(intent); if (altButtonConfig) { button = (Button) layout.findViewById(R.id.hide_taskbar_button_alt); layout.findViewById(R.id.hide_taskbar_button).setVisibility(View.GONE); } else { button = (Button) layout.findViewById(R.id.hide_taskbar_button); layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE); } try { button.setTypeface(Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf")); } catch (RuntimeException e) { /* Gracefully fail */ } updateButton(false); button.setOnClickListener(v -> toggleTaskbar()); LinearLayout buttonLayout = (LinearLayout) layout.findViewById( altButtonConfig ? R.id.hide_taskbar_button_layout_alt : R.id.hide_taskbar_button_layout); if (buttonLayout != null) buttonLayout.setOnClickListener(v -> toggleTaskbar()); LinearLayout buttonLayoutToHide = (LinearLayout) layout.findViewById( altButtonConfig ? R.id.hide_taskbar_button_layout : R.id.hide_taskbar_button_layout_alt); if (buttonLayoutToHide != null) buttonLayoutToHide.setVisibility(View.GONE); int backgroundTint = U.getBackgroundTint(this); int accentColor = U.getAccentColor(this); dashboardButton = (FrameLayout) layout.findViewById(R.id.dashboard_button); navbarButtons = (LinearLayout) layout.findViewById(R.id.navbar_buttons); dashboardEnabled = pref.getBoolean("dashboard", false); if (dashboardEnabled) { layout.findViewById(R.id.square1).setBackgroundColor(accentColor); layout.findViewById(R.id.square2).setBackgroundColor(accentColor); layout.findViewById(R.id.square3).setBackgroundColor(accentColor); layout.findViewById(R.id.square4).setBackgroundColor(accentColor); layout.findViewById(R.id.square5).setBackgroundColor(accentColor); layout.findViewById(R.id.square6).setBackgroundColor(accentColor); dashboardButton.setOnClickListener(v -> LocalBroadcastManager.getInstance(TaskbarService.this) .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD"))); } else dashboardButton.setVisibility(View.GONE); if (pref.getBoolean("button_back", false)) { navbarButtonsEnabled = true; ImageView backButton = (ImageView) layout.findViewById(R.id.button_back); backButton.setVisibility(View.VISIBLE); backButton.setOnClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_BACK); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); }); } if (pref.getBoolean("button_home", false)) { navbarButtonsEnabled = true; ImageView homeButton = (ImageView) layout.findViewById(R.id.button_home); homeButton.setVisibility(View.VISIBLE); homeButton.setOnClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_HOME); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); }); homeButton.setOnLongClickListener(v -> { Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(voiceSearchIntent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); return true; }); homeButton.setOnGenericMotionListener((view13, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) { Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(voiceSearchIntent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); } return true; }); } if (pref.getBoolean("button_recents", false)) { navbarButtonsEnabled = true; ImageView recentsButton = (ImageView) layout.findViewById(R.id.button_recents); recentsButton.setVisibility(View.VISIBLE); recentsButton.setOnClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_RECENTS); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { recentsButton.setOnLongClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); return true; }); recentsButton.setOnGenericMotionListener((view13, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); } return true; }); } } if (!navbarButtonsEnabled) navbarButtons.setVisibility(View.GONE); layout.setBackgroundColor(backgroundTint); layout.findViewById(R.id.divider).setBackgroundColor(accentColor); button.setTextColor(accentColor); if (isFirstStart && FreeformHackHelper.getInstance().isInFreeformWorkspace()) showTaskbar(false); else if (!pref.getBoolean("collapsed", false) && pref.getBoolean("taskbar_active", false)) toggleTaskbar(); LocalBroadcastManager.getInstance(this).unregisterReceiver(showReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(tempShowReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(tempHideReceiver); LocalBroadcastManager.getInstance(this).registerReceiver(showReceiver, new IntentFilter("com.farmerbb.taskbar.SHOW_TASKBAR")); LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_TASKBAR")); LocalBroadcastManager.getInstance(this).registerReceiver(tempShowReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_SHOW_TASKBAR")); LocalBroadcastManager.getInstance(this).registerReceiver(tempHideReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_HIDE_TASKBAR")); startRefreshingRecents(); windowManager.addView(layout, params); isFirstStart = false; }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragment.java
/** * Get data retrieved with the intent, or restore state * @param savedInstanceState the previously saved state *//*from www . ja v a 2 s .c o m*/ @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // initialize the producten & vaste producten values String[] productParams = getResources().getStringArray(R.array.array_product_param); for (String product : productParams) { mProducten.put(product, -1); mProductenVast.put(product, -1); } // get settings from the shared preferences SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); mMarktId = settings.getInt(getString(R.string.sharedpreferences_key_markt_id), 0); mActiveAccountId = settings.getInt(getString(R.string.sharedpreferences_key_account_id), 0); mActiveAccountNaam = settings.getString(getString(R.string.sharedpreferences_key_account_naam), null); // get the date of today for the dag param SimpleDateFormat sdf = new SimpleDateFormat(getString(R.string.date_format_dag)); mDagToday = sdf.format(new Date()); // only on fragment creation, not on rotation/re-creation if (savedInstanceState == null) { // check if we are editing an existing dagvergunning or making a new one Intent intent = getActivity().getIntent(); if ((intent != null) && (intent.hasExtra( MakkelijkeMarktProvider.mTableDagvergunning + MakkelijkeMarktProvider.Dagvergunning.COL_ID))) { int dagvergunningId = intent.getIntExtra( MakkelijkeMarktProvider.mTableDagvergunning + MakkelijkeMarktProvider.Dagvergunning.COL_ID, 0); if (dagvergunningId != 0) { mId = dagvergunningId; } } // init loader if an existing dagvergunning was selected if (mId > 0) { // create an argument bundle with the dagvergunning id and initialize the loader Bundle args = new Bundle(); args.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_ID, mId); getLoaderManager().initLoader(DAGVERGUNNING_LOADER, args, this); // show the progressbar (because we are fetching the koopman from the api later in the onloadfinished) mProgressbar.setVisibility(View.VISIBLE); } else { // check time in hours since last fetched the sollicitaties for selected markt long diffInHours = getResources() .getInteger(R.integer.makkelijkemarkt_api_sollicitaties_fetch_interval_hours); if (settings .contains(getContext().getString(R.string.sharedpreferences_key_sollicitaties_last_fetched) + mMarktId)) { long lastFetchTimestamp = settings.getLong( getContext().getString(R.string.sharedpreferences_key_sollicitaties_last_fetched) + mMarktId, 0); long differenceMs = new Date().getTime() - lastFetchTimestamp; diffInHours = TimeUnit.MILLISECONDS.toHours(differenceMs); } // if last sollicitaties fetched more than 12 hours ago, fetch them again if (diffInHours >= getResources() .getInteger(R.integer.makkelijkemarkt_api_sollicitaties_fetch_interval_hours)) { // show progress dialog mGetSollicitatiesProcessDialog.show(); ApiGetSollicitaties getSollicitaties = new ApiGetSollicitaties(getContext()); getSollicitaties.setMarktId(mMarktId); getSollicitaties.enqueue(); } } } else { // restore dagvergunning data from saved state mMarktId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_MARKT_ID); mDag = savedInstanceState.getString(MakkelijkeMarktProvider.Dagvergunning.COL_DAG); mId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_ID); mErkenningsnummer = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_WAARDE); mErkenningsnummerInvoerMethode = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_METHODE); mRegistratieDatumtijd = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_DATUMTIJD); mRegistratieGeolocatieLatitude = savedInstanceState .getDouble(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LAT); mRegistratieGeolocatieLongitude = savedInstanceState .getDouble(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LONG); mTotaleLengte = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_TOTALE_LENGTE); mSollicitatieStatus = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_STATUS_SOLLICITATIE); mKoopmanAanwezig = savedInstanceState.getString(MakkelijkeMarktProvider.Dagvergunning.COL_AANWEZIG); mKoopmanId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_KOOPMAN_ID); mKoopmanVoorletters = savedInstanceState.getString(MakkelijkeMarktProvider.Koopman.COL_VOORLETTERS); mKoopmanAchternaam = savedInstanceState.getString(MakkelijkeMarktProvider.Koopman.COL_ACHTERNAAM); mKoopmanFoto = savedInstanceState.getString(MakkelijkeMarktProvider.Koopman.COL_FOTO_URL); mRegistratieAccountId = savedInstanceState .getInt(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_ACCOUNT_ID); mRegistratieAccountNaam = savedInstanceState.getString(MakkelijkeMarktProvider.Account.COL_NAAM); mSollicitatieId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_SOLLICITATIE_ID); mSollicitatieNummer = savedInstanceState .getInt(MakkelijkeMarktProvider.Sollicitatie.COL_SOLLICITATIE_NUMMER); mNotitie = savedInstanceState.getString(MakkelijkeMarktProvider.Dagvergunning.COL_NOTITIE); mProducten = (HashMap<String, Integer>) savedInstanceState.getSerializable(STATE_BUNDLE_KEY_PRODUCTS); mProductenVast = (HashMap<String, Integer>) savedInstanceState .getSerializable(STATE_BUNDLE_KEY_PRODUCTS_VAST); mVervangerId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ID); mVervangerErkenningsnummer = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ERKENNINGSNUMMER); // select tab of viewpager from saved fragment state (if it's different) if (mViewPager.getCurrentItem() != mCurrentTab) { mViewPager.setCurrentItem(mCurrentTab); } } // set the right wizard menu depending on the current tab position setWizardMenu(mCurrentTab); // prevent the keyboard from popping up on first pager fragment load Utility.hideKeyboard(getActivity()); // // TODO: get credentials and payleven api-key from mm api // // decrypt loaded credentials // String paylevenMerchantEmail = "marco@langebeeke.com"; // String paylevenMerchantPassword = "unknown"; // String paylevenApiKey = "unknown"; // // // register with payleven api // PaylevenFactory.registerAsync( // getContext(), // paylevenMerchantEmail, // paylevenMerchantPassword, // paylevenApiKey, // new PaylevenRegistrationListener() { // @Override // public void onRegistered(Payleven payleven) { // mPaylevenApi = payleven; // Utility.log(getContext(), LOG_TAG, "Payleven Registered!"); // } // @Override // public void onError(PaylevenError error) { // Utility.log(getContext(), LOG_TAG, "Payleven registration Error: " + error.getMessage()); // } // }); // TODO: in the overzicht step change 'Opslaan' into 'Afrekenen' and show a payment dialog when clicked // TODO: if the bluetooth payleven cardreader has not been paired yet inform the toezichthouder, show instructions and open the bluetooth settings // TODO: give the toezichthouder the option in the payment dialog to save without payleven and make the payment with an old pin device? // TODO: the payment dialog shows: // - logo's of the accepted debit card standards // - total amount to pay // (this can be the difference between a changed dagvergunning and an already paid amount, // or the total amount if it is a new dagvergunning. we don't pay refunds using the app? // refunds can be done by the beheerder using the dashboard? // or do we allow refunds in the app? In that case we need to inform the toezichthouder // that a refund will be made, and keep him informed about the status of the trasnaction) // - 'start payment/refund' button? // - instructions for making the payment using the payleven cardreader // - optionally a selection list to select the bluetooth cardreader if it was not yet selected before // (if it was already selected before, show the selected reader with a 'wiebertje' in front. when // clicked it will show the list of cardreaders that can be selected) // - status of the transaction // TODO: when the payment is done succesfully we safe the dagvergunning and close the dialog and the dagvergunning activity }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showNews() { if (!selectingChannels) { final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this); if (pref.getBoolean(getString(R.string.PREF_NEWS_SHOW), getResources().getBoolean(R.bool.pref_news_show_default))) { long lastShown = pref.getLong(getString(R.string.NEWS_DATE_LAST_SHOWN), 0); long lastKnown = pref.getLong(getString(R.string.NEWS_DATE_LAST_KNOWN), 0); final String news = pref.getString(getString(R.string.NEWS_TEXT), ""); if (lastShown < lastKnown && news.trim().length() > 0) { handler.post(new Runnable() { @Override//from w w w . ja v a 2 s .c om public void run() { final AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); builder.setTitle(R.string.title_news); builder.setCancelable(false); builder.setMessage(Html.fromHtml(news, null, new NewsTagHandler())); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Editor edit = pref.edit(); edit.putLong(getString(R.string.NEWS_DATE_LAST_SHOWN), System.currentTimeMillis()); edit.commit(); showPluginInfo(); } }); AlertDialog d = builder.create(); d.show(); ((TextView) d.findViewById(android.R.id.message)) .setMovementMethod(LinkMovementMethod.getInstance()); } }); } else { showPluginInfo(); } } else { showPluginInfo(); } } }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showEpgDonateInfo() { if (!SHOWING_DONATION_INFO && hasEpgDonateChannelsSubscribed()) { final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this); final String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); int month = Calendar.getInstance().get(Calendar.MONTH); final long now = System.currentTimeMillis(); long firstDownload = pref.getLong(getString(R.string.EPG_DONATE_FIRST_DATA_DOWNLOAD), now); long lastDownload = pref.getLong(getString(R.string.EPG_DONATE_LAST_DATA_DOWNLOAD), now); long lastShown = pref.getLong(getString(R.string.EPG_DONATE_LAST_DONATION_INFO_SHOWN), (now - (60 * 24 * 60 * 60000L))); Calendar monthTest = Calendar.getInstance(); monthTest.setTimeInMillis(lastShown); int shownMonth = monthTest.get(Calendar.MONTH); boolean firstTimeoutReached = (firstDownload + (14 * 24 * 60 * 60000L)) < now; boolean lastTimoutReached = lastDownload > (now - ((42 * 24 * 60 * 60000L))); boolean alreadyShowTimeoutReached = (lastShown + (14 * 24 * 60 * 60000L) < now); boolean alreadyShownThisMonth = shownMonth == month; boolean dontShowAgainThisYear = year .equals(pref.getString(getString(R.string.EPG_DONATE_DONT_SHOW_AGAIN_YEAR), "0")); boolean radomShow = Math.random() > 0.33; boolean show = firstTimeoutReached && lastTimoutReached && alreadyShowTimeoutReached && !alreadyShownThisMonth && !dontShowAgainThisYear && radomShow; //Log.d("info21", "firstTimeoutReached (" + ((now - firstDownload)/(24 * 60 * 60000L)) + "): " + firstTimeoutReached + " lastTimoutReached: " + lastTimoutReached + " alreadyShowTimeoutReached: " + alreadyShowTimeoutReached + " alreadyShownThisMonth: " + alreadyShownThisMonth + " dontShowAgainThisYear: " + dontShowAgainThisYear + " randomShow: " + radomShow + " SHOW: " + show); if (show) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); String info = getString(R.string.epg_donate_info); String amount = getString(R.string.epg_donate_amount); String percentInfo = getString(R.string.epg_donate_percent_info); String amountValue = pref.getString( getString(R.string.EPG_DONATE_CURRENT_DONATION_AMOUNT_PREFIX) + "_" + year, getString(R.string.epg_donate_current_donation_amount_default)); int percentValue = Integer .parseInt(pref.getString(getString(R.string.EPG_DONATE_CURRENT_DONATION_PERCENT), "-1")); amount = amount.replace("{0}", year).replace("{1}", amountValue); info = info.replace("{0}", "<h2>" + amount + "</h2>"); builder.setTitle(R.string.epg_donate_name); builder.setCancelable(false); View view = getLayoutInflater().inflate(R.layout.dialog_epg_donate_info, getParentViewGroup(), false);/*w w w . j a v a2 s . c o m*/ TextView message = (TextView) view.findViewById(R.id.dialog_epg_donate_message); message.setText(Html.fromHtml(info)); message.setMovementMethod(LinkMovementMethod.getInstance()); TextView percentInfoView = (TextView) view.findViewById(R.id.dialog_epg_donate_percent_info); percentInfoView.setText(Html.fromHtml(percentInfo, null, new NewsTagHandler())); SeekBar percent = (SeekBar) view.findViewById(R.id.dialog_epg_donate_percent); percent.setEnabled(false); if (percentValue >= 0) { percent.setProgress(percentValue); } else { percentInfoView.setVisibility(View.GONE); percent.setVisibility(View.GONE); } final Spinner reason = (Spinner) view.findViewById(R.id.dialog_epg_donate_reason_selection); reason.setEnabled(false); final CheckBox dontShowAgain = (CheckBox) view.findViewById(R.id.dialog_epg_donate_dont_show_again); dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { reason.setEnabled(isChecked); } }); builder.setView(view); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SHOWING_DONATION_INFO = false; Editor edit = pref.edit(); edit.putLong(getString(R.string.EPG_DONATE_LAST_DONATION_INFO_SHOWN), now); if (dontShowAgain.isChecked()) { edit.putString(getString(R.string.EPG_DONATE_DONT_SHOW_AGAIN_YEAR), year); } edit.commit(); } }); builder.show(); SHOWING_DONATION_INFO = true; } } }
From source file:de.ub0r.android.websms.WebSMS.java
/** * {@inheritDoc}//from www . ja va2 s .co m */ @SuppressWarnings({ "unchecked", "deprecation" }) @Override public final void onCreate(final Bundle savedInstanceState) { this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); this.setTheme(PreferencesActivity.getTheme(this)); super.onCreate(savedInstanceState); Log.d(TAG, "onCreate(" + savedInstanceState + ")"); this.threadHandler = new Handler(); // Restore preferences de.ub0r.android.lib.Utils.setLocale(this); this.cbmgr = (ClipboardManager) this.getSystemService(CLIPBOARD_SERVICE); // save ref to me. me = this; final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this); // inflate XML this.setContentView(R.layout.main); this.getSupportActionBar().setHomeButtonEnabled(true); // indeterminate progress bar is spinning by default so stop it, // updateProgressBar will start it again if necessary this.setSupportProgressBarIndeterminateVisibility(false); this.etTo = (MultiAutoCompleteTextView) this.findViewById(R.id.to); this.etText = (EditText) this.findViewById(R.id.text); this.etTextLabel = (TextView) this.findViewById(R.id.text_); this.tvPaste = (TextView) this.findViewById(R.id.text_paste); this.tvClear = (TextView) this.findViewById(R.id.text_clear); this.vCustomSender = (ToggleButton) this.findViewById(R.id.custom_sender); this.vFlashSMS = (ToggleButton) this.findViewById(R.id.flashsms); this.vSendLater = (ToggleButton) this.findViewById(R.id.send_later); if (isNewVersion()) { Log.i(TAG, "detected version update"); SharedPreferences.Editor editor = p.edit(); editor.remove(PREFS_CONNECTORS); // remove cache editor.apply(); rules.upgrade(); } // get cached Connectors String s = p.getString(PREFS_CONNECTORS, null); if (TextUtils.isEmpty(s)) { this.updateConnectors(); } else if (CONNECTORS.size() == 0) { // skip static remaining connectors try { ArrayList<ConnectorSpec> cache; cache = (ArrayList<ConnectorSpec>) (new ObjectInputStream(new BufferedInputStream( new ByteArrayInputStream(Base64.decode(s, Base64.DEFAULT)), BUFSIZE))).readObject(); CONNECTORS.addAll(cache); if (p.getBoolean(PREFS_AUTOUPDATE, true)) { updateFreecount(); } } catch (Exception e) { Log.d(TAG, "error loading connectors", e); } } Log.d(TAG, "loaded connectors: " + CONNECTORS.size()); if (PSEUDO_CONNECTORS.size() == 0) { PSEUDO_CONNECTORS.add(rules.getSpec(this)); } if (savedInstanceState == null) { this.revertPrefsToStdConnector(); // note: do not revert to std connector on orientation change } this.reloadPrefs(); if (savedInstanceState != null) { this.lastTo = savedInstanceState.getString(EXTRA_TO); this.lastMsg = savedInstanceState.getString(EXTRA_TEXT); } // register Listener this.vCustomSender.setOnClickListener(this); this.vSendLater.setOnClickListener(this); this.findViewById(R.id.select).setOnClickListener(this); View v = this.findViewById(R.id.clear); v.setOnClickListener(this); v.setOnLongClickListener(this); this.findViewById(R.id.emo).setOnClickListener(this); this.tvPaste.setOnClickListener(this); this.tvClear.setOnClickListener(this); this.etText.addTextChangedListener(this.twCount); this.etText.addTextChangedListener(this.twButtons); this.etTo.addTextChangedListener(this.twButtons); this.etTo.setAdapter(new MobilePhoneAdapter(this)); this.etTo.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); this.etTo.requestFocus(); this.parseIntent(this.getIntent()); boolean checkPrefix = true; boolean showIntro = false; if (TextUtils.isEmpty(p.getString(PREFS_SENDER, null)) && TextUtils.isEmpty(p.getString(PREFS_DEFPREFIX, null)) && CONNECTORS.size() == 0) { checkPrefix = false; showIntro = true; } requestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_READ_CONTACTS, R.string.permissions_read_contacts, null); if (TextUtils.isEmpty(p.getString(PREFS_SENDER, null)) || TextUtils.isEmpty(p.getString(PREFS_DEFPREFIX, null))) { fetchSenderAndPrefixFromPhoneNumber(); } // check default prefix if (checkPrefix && !p.getString(PREFS_DEFPREFIX, "").startsWith("+")) { this.log(R.string.log_wrong_defprefix); } if (showIntro) { // skip help intro for at least 2min if (System.currentTimeMillis() > p.getLong(PREFS_LASTHELP, 0L) + de.ub0r.android.lib.Utils.MINUTES_IN_MILLIS * 2) { p.edit().putLong(PREFS_LASTHELP, System.currentTimeMillis()).apply(); this.startActivity(new Intent(this, HelpIntroActivity.class)); } } }
From source file:com.scooter1556.sms.android.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Retrieve preferences if they exist SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); sharedPreferences.registerOnSharedPreferenceChangeListener(onPreferencesChanged); // Set volume control to media setVolumeControlStream(AudioManager.STREAM_MUSIC); // Initialise database db = new ConnectionDatabase(this); // Load default settings PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Action Bar assert getSupportActionBar() != null; getSupportActionBar().setDisplayShowHomeEnabled(false); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Navigation Drawer drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerList = (ListView) findViewById(R.id.navigation_drawer_list); NavigationDrawerListItem[] drawerListItems = new NavigationDrawerListItem[3]; drawerListItems[MENU_MEDIA_BROWSER] = new NavigationDrawerListItem(R.drawable.ic_media_browser, getResources().getStringArray(R.array.navigation_drawer_list_items)[MENU_MEDIA_BROWSER]); drawerListItems[MENU_SETTINGS] = new NavigationDrawerListItem(R.drawable.ic_settings, getResources().getStringArray(R.array.navigation_drawer_list_items)[MENU_SETTINGS]); drawerListItems[MENU_EXIT] = new NavigationDrawerListItem(R.drawable.ic_close, getResources().getStringArray(R.array.navigation_drawer_list_items)[MENU_EXIT]); NavigationDrawerListItemAdapter drawerAdapter = new NavigationDrawerListItemAdapter(this, R.layout.drawer_list_item, drawerListItems); drawerList.setAdapter(drawerAdapter); drawerList.setOnItemClickListener(new DrawerItemClickListener()); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); getSupportActionBar().setTitle(title); }/*from ww w . ja va 2 s . c o m*/ /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); title = getSupportActionBar().getTitle().toString(); getSupportActionBar().setTitle(getString(R.string.navigation_drawer_title)); } }; // Set the drawer toggle as the DrawerListener drawerLayout.setDrawerListener(drawerToggle); // Sliding Panel slidingPanel = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout); slidingPanel.setPanelHeight((int) getResources().getDimension(R.dimen.audio_player_small_fragment_height)); PanelSlideListener slidingPanelListener = new SlidingUpPanelLayout.PanelSlideListener() { @Override public void onPanelAnchored(final View panel) { } @Override public void onPanelCollapsed(final View panel) { View audioPlayerSmallContainer = findViewById(R.id.sliding_panel_small_container); View audioPlayerContainer = findViewById(R.id.sliding_panel_container); audioPlayerSmallContainer.setVisibility(View.VISIBLE); audioPlayerSmallContainer.setAlpha(1.0f); audioPlayerContainer.setVisibility(View.GONE); audioPlayerContainer.setAlpha(1.0f); // Update menu items audioPlayerFragment.setMenuVisibility(false); audioPlaylistFragment.setMenuVisibility(false); mediaBrowserFragment.setMenuVisibility(true); //Update action bar title getSupportActionBar().setTitle(title); } @Override public void onPanelExpanded(final View panel) { View audioPlayerSmallContainer = findViewById(R.id.sliding_panel_small_container); View audioPlayerContainer = findViewById(R.id.sliding_panel_container); audioPlayerSmallContainer.setVisibility(View.GONE); audioPlayerSmallContainer.setAlpha(1.0f); audioPlayerContainer.setVisibility(View.VISIBLE); audioPlayerContainer.setAlpha(1.0f); // Update menu items audioPlayerFragment.setMenuVisibility(slidingPanelFragment == SLIDING_PANEL_PLAYER); audioPlaylistFragment.setMenuVisibility(slidingPanelFragment == SLIDING_PANEL_PLAYLIST); mediaBrowserFragment.setMenuVisibility(false); //Update action bar title getSupportActionBar().setTitle(slidingPanelTitle); } @Override public void onPanelHidden(final View view) { } @Override public void onPanelSlide(final View panel, final float slideOffset) { View audioPlayerSmallContainer = findViewById(R.id.sliding_panel_small_container); View audioPlayerContainer = findViewById(R.id.sliding_panel_container); if (slideOffset < 1.0f) { audioPlayerSmallContainer.setVisibility(View.VISIBLE); audioPlayerContainer.setVisibility(View.VISIBLE); } else { audioPlayerSmallContainer.setVisibility(View.GONE); audioPlayerContainer.setVisibility(View.VISIBLE); } audioPlayerSmallContainer.setAlpha(1.0f - slideOffset); audioPlayerContainer.setAlpha(slideOffset); } }; slidingPanel.setPanelSlideListener(slidingPanelListener); if (savedInstanceState == null) { // Initialise main view mediaBrowserFragment = new MediaFolderFragment(); mediaBrowserTitle = title = getString(R.string.media_title); getSupportFragmentManager().beginTransaction() .add(R.id.main_container, mediaBrowserFragment, Integer.toString(MENU_MEDIA_BROWSER)).commit(); assert getSupportActionBar() != null; getSupportActionBar().setTitle(getString(R.string.media_title)); updateDrawer(MENU_MEDIA_BROWSER); // Initialise small audio player sliding panel fragment audioPlayerSmallFragment = new AudioPlayerSmallFragment(); getSupportFragmentManager().beginTransaction().add(R.id.sliding_panel_small_container, audioPlayerSmallFragment, Integer.toString(SLIDING_PANEL_SMALL_PLAYER)).commit(); // Initialise audio player fragment audioPlayerFragment = new AudioPlayerFragment(); audioPlayerFragment.setMenuVisibility(false); getSupportFragmentManager().beginTransaction() .add(R.id.sliding_panel_container, audioPlayerFragment, Integer.toString(SLIDING_PANEL_PLAYER)) .commit(); slidingPanelTitle = getString(R.string.audio_player_title); slidingPanelFragment = SLIDING_PANEL_PLAYER; // Initialise audio playlist fragment audioPlaylistFragment = new AudioPlaylistFragment(); audioPlaylistFragment.setMenuVisibility(false); getSupportFragmentManager().beginTransaction().add(R.id.sliding_panel_container, audioPlaylistFragment, Integer.toString(SLIDING_PANEL_PLAYLIST)).hide(audioPlaylistFragment).commit(); // Check connection long id = sharedPreferences.getLong("Connection", -1); if (id < 0) { Intent connectionsIntent = new Intent(this, ConnectionActivity.class); startActivityForResult(connectionsIntent, RESULT_CODE_CONNECTIONS); } else { Connection connection = db.getConnection(id); RESTService.getInstance().setConnection(connection); } } else { // Reload fragments mediaBrowserFragment = getSupportFragmentManager() .findFragmentByTag(Integer.toString(MENU_MEDIA_BROWSER)); audioPlayerSmallFragment = (AudioPlayerSmallFragment) getSupportFragmentManager() .findFragmentByTag(Integer.toString(SLIDING_PANEL_SMALL_PLAYER)); audioPlayerFragment = (AudioPlayerFragment) getSupportFragmentManager() .findFragmentByTag(Integer.toString(SLIDING_PANEL_PLAYER)); audioPlaylistFragment = (AudioPlaylistFragment) getSupportFragmentManager() .findFragmentByTag(Integer.toString(SLIDING_PANEL_PLAYLIST)); // Restore activity state variables slidingPanelFragment = savedInstanceState.getInt(STATE_SLIDING_PANEL_FRAGMENT); slidingPanelTitle = savedInstanceState.getString(STATE_SLIDING_PANEL_TITLE); title = savedInstanceState.getString(STATE_MAIN_TITLE); if (savedInstanceState.getSerializable(STATE_SLIDING_PANEL) == PanelState.EXPANDED) { slidingPanel.setPanelState(PanelState.EXPANDED); slidingPanelListener.onPanelSlide(slidingPanel, 1.0f); slidingPanelListener.onPanelExpanded(slidingPanel); } else { slidingPanel.setPanelState(PanelState.COLLAPSED); slidingPanelListener.onPanelSlide(slidingPanel, 0.0f); slidingPanelListener.onPanelCollapsed(slidingPanel); } } // Add fragment back stack listener getSupportFragmentManager().addOnBackStackChangedListener(this); }