use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project Applozic-Android-SDK by AppLozic.
the class PushNotificationDispatcher method scheduleJob.
public static void scheduleJob(Context context, Message message) {
try {
Bundle bundle = new Bundle();
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
bundle.putString(MobiComKitConstants.AL_MESSAGE_KEY, message.getKeyString());
Class pushNotificationJobServiceClass = Class.forName("com.applozic.mobicomkit.uiwidgets.notification.PushNotificationJobService");
Job myJob = dispatcher.newJobBuilder().setService(// the JobService that will be called
pushNotificationJobServiceClass).setTag(// uniquely identifies the job
MobiComKitConstants.PUSH_NOTIFICATION_DISPATCHER).setRecurring(false).setTrigger(Trigger.executionWindow(0, 0)).setReplaceCurrent(true).setRetryStrategy(RetryStrategy.DEFAULT_LINEAR).setConstraints(Constraint.ON_ANY_NETWORK).setExtras(bundle).build();
dispatcher.mustSchedule(myJob);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project MPW by shineangelic.
the class SettingsFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences);
// Crashlytics.getInstance().crash();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
mFirebaseAnalytics = FirebaseAnalytics.getInstance(getActivity());
PoolEnum mPool = PoolEnum.valueOf(prefs.getString("poolEnum", ""));
CurrencyEnum mCur = CurrencyEnum.valueOf(prefs.getString("curEnum", ""));
final android.support.v7.preference.SwitchPreferenceCompat globalNotifications = (SwitchPreferenceCompat) findPreference("pref_notify");
final android.support.v7.preference.EditTextPreference walletAddr = (EditTextPreference) findPreference("wallet_addr");
final android.support.v7.preference.SwitchPreferenceCompat service = (SwitchPreferenceCompat) findPreference("pref_sync");
final android.support.v7.preference.ListPreference listFreqPreference = (ListPreference) findPreference("pref_sync_freq");
final android.support.v7.preference.SwitchPreferenceCompat offlineNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_offline");
final android.support.v7.preference.SwitchPreferenceCompat blockNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_block");
final android.support.v7.preference.SwitchPreferenceCompat paymentNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_payment");
// Service Enabled listener
Preference.OnPreferenceChangeListener listenerServ = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// newValue is the value you choose
listFreqPreference.setEnabled((Boolean) newValue);
Boolean nv = (Boolean) newValue;
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
dispatcher.cancelAll();
if (nv) {
Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
int res = dispatcher.schedule(myJob);
if (res != dispatcher.SCHEDULE_RESULT_SUCCESS) {
Toast.makeText(getActivity(), "Cannot enable service. Is Play Services up to date? Notifications won't work", Toast.LENGTH_SHORT).show();
return false;
}
Log.w(Constants.TAG, "SERVICE ACTIVE, schedule res: " + res);
}
// firebase log event
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, nv.toString());
mFirebaseAnalytics.logEvent("service_active", bundle);
return true;
}
};
service.setOnPreferenceChangeListener(listenerServ);
// Service FREQ listener
Preference.OnPreferenceChangeListener listenerServF = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Integer nv = Integer.valueOf((String) newValue);
// newValue is the value you choose
Log.w(Constants.TAG, "Changed FREQ setting to: " + nv);
// pezza perche il val ancora non c'e
prefs.edit().putString("pref_sync_freq", "" + nv).apply();
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
dispatcher.schedule(myJob);
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
mFirebaseAnalytics.logEvent("service_freq", bundle);
return true;
}
};
listFreqPreference.setOnPreferenceChangeListener(listenerServF);
// Notification global
Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Log.w(Constants.TAG, "Changed NOTIF setting to: " + newValue);
Boolean nv = (Boolean) newValue;
// newValue is the value you choose
blockNotifications.setEnabled(nv);
offlineNotifications.setEnabled(nv);
paymentNotifications.setEnabled(nv);
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
mFirebaseAnalytics.logEvent("service_notifications", bundle);
return true;
}
};
globalNotifications.setOnPreferenceChangeListener(listener);
// Listener x controllo correttezza
walletAddr.setOnPreferenceChangeListener(new WalletPrefChangeListener(getActivity(), mPool, mCur));
walletAddr.setSummary(getString(R.string.wallet_info, mPool.toString(), mCur.toString()));
walletAddr.setDialogTitle(mPool.toString() + " Network Login");
}
use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project MPW by shineangelic.
the class ChoosePoolActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ChoosePoolActivity.this);
AppCompatDelegate.setDefaultNightMode(Integer.valueOf(prefs.getString("pref_theme", "0")));
setContentView(R.layout.activity_choose_pool);
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
// Set up the login form.
mWalletView = findViewById(R.id.wallet);
poolSpinner = findViewById(R.id.spinnerPoolChooser);
skipIntro = findViewById(R.id.skipIntro);
skipIntro.setChecked(prefs.getBoolean("skipIntro", false));
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, new Boolean(prefs.getBoolean("skipIntro", false)).toString());
mFirebaseAnalytics.logEvent("skip_intro", bundle);
// SERVICE Schedule
Boolean synchActive = prefs.getBoolean("pref_sync", true);
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
if (synchActive) {
Job myJob = MPWService.getJobUpdate(prefs, dispatcher, false);
dispatcher.schedule(myJob);
} else {
dispatcher.cancelAll();
}
if (skipIntro.isChecked()) {
Intent miner = new Intent(ChoosePoolActivity.this, MainActivity.class);
startActivity(miner);
finish();
}
// admob
MobileAds.initialize(this, "ca-app-pub-2379213694485575~9889984422");
ArrayAdapter poolSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, PoolEnum.values());
poolSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
poolSpinner.setAdapter(poolSpinnerAdapter);
currencySpinner = findViewById(R.id.spinnerCurrencyChooser);
ArrayAdapter curAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, CurrencyEnum.values());
curAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
currencySpinner.setAdapter(curAdapter);
poolSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
ArrayAdapter arra = new ArrayAdapter<>(ChoosePoolActivity.this, android.R.layout.simple_spinner_item, ((PoolEnum) poolSpinner.getAdapter().getItem(position)).getSupportedCurrencies());
arra.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
currencySpinner.setAdapter(arra);
String prevWallet = prefs.getString("wallet_addr_" + ((PoolEnum) poolSpinner.getAdapter().getItem(position)).name() + "_" + ((CurrencyEnum) currencySpinner.getAdapter().getItem(currencySpinner.getSelectedItemPosition())).name(), "");
mWalletView.setText(prevWallet);
Log.d(Constants.TAG, "poolSpinner list: " + ((PoolEnum) poolSpinner.getAdapter().getItem(position)).name());
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
currencySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// read saved wallet from pref
String xCode = "wallet_addr_" + ((PoolEnum) poolSpinner.getItemAtPosition(poolSpinner.getSelectedItemPosition())).name() + "_" + ((CurrencyEnum) currencySpinner.getAdapter().getItem(position)).name();
String prevWallet = prefs.getString(xCode, "");
mWalletView.setText(prevWallet.length() == 0 ? getString(R.string.no_wallet_set) : Utils.formatEthAddress(prevWallet));
Log.d(Constants.TAG, "currencySpinner list: " + currencySpinner.getItemAtPosition(currencySpinner.getSelectedItemPosition()));
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
Button mEmailSignInButton = findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
attemptLogin();
}
});
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
}
use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project MPW by shineangelic.
the class MainActivity method onCreate.
/* private static long getAverageBlockSecondsSincePoolsBirth(HomeStats lastHit) {
final Date firstBlockDate = new Date();//2017/07/15
firstBlockDate.setTime(1500099900000L);
long datediffFirst = (new Date().getTime() - firstBlockDate.getTime()) / 1000;
//meno uno perche` il conto parte dal secondo blocco. Il primo boh
return datediffFirst / (lastHit.getMaturedTotal() - 1);
}*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Locale current = getResources().getConfiguration().locale;
mDbHelper = new PoolDbHelper(this, mPool, mCur);
builder = new GsonBuilder();
// gestione UNIX time lungo e non
builder.registerTypeAdapter(Date.class, new MyDateTypeAdapter());
builder.registerTypeAdapter(Calendar.class, new MyTimeStampTypeAdapter());
noobText = findViewById(R.id.textViewWalletTitle);
hashText = findViewById(R.id.hashrateText);
textViewNetDiffTitle = findViewById(R.id.textViewWalHashrateTitle);
poolLastBeat = findViewById(R.id.textViewWalLastShareValue);
textViewNetDiffValue = findViewById(R.id.textViewNetDiffValue);
lastFoundTextLabel = findViewById(R.id.textViewLastBlock);
lastFoundText = findViewById(R.id.textViewWalPaymentsValue);
onlineMinersText = findViewById(R.id.textViewWalCurHashrateValue);
textViewBlockChainHeightValue = findViewById(R.id.textViewBlockChainHeightValue);
poolHashrateText = findViewById(R.id.textViewPoolHashrateValue);
roundSharesText = findViewById(R.id.textViewRoundSharesValue);
textViewVarianceValue = findViewById(R.id.textViewVarianceValue);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Async Refresh Sent", Snackbar.LENGTH_SHORT).setAction("Action", null).show();
issueRefresh(mDbHelper, builder);
}
});
// i grafici hanno controlli globali
RadioGroup radioGroupChartGranularity = findViewById(R.id.radioDifficultyGranularity);
radioGroupBackTo = findViewById(R.id.radioBackto);
final RadioButton radioDay = findViewById(R.id.radioButtonDay);
final RadioButton radioMin = findViewById(R.id.radioButtonMinutes);
final RadioGroup.OnCheckedChangeListener mescola = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
radioGroupBackTo.post(new Runnable() {
@Override
public void run() {
GranularityEnum granoEnum = GranularityEnum.HOUR;
if (radioDay.isChecked())
granoEnum = GranularityEnum.DAY;
else if (radioMin.isChecked())
granoEnum = GranularityEnum.MINUTE;
int radioButtonID = radioGroupBackTo.getCheckedRadioButtonId();
View radioButton = findViewById(radioButtonID);
LinkedMap<Date, HomeStats> storia = mDbHelper.getHistoryData(BackToEnum.valueOf((String) radioButton.getTag()));
ChartUtils.drawDifficultyHistory(textViewNetDiffTitle, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_difficulty), granoEnum);
ChartUtils.drawHashrateHistory(hashText, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_hashrate), granoEnum);
}
});
}
};
radioGroupBackTo.setOnCheckedChangeListener(mescola);
radioGroupChartGranularity.setOnCheckedChangeListener(mescola);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = MPWCoinmarketcapService.getJobUpdate(dispatcher);
dispatcher.schedule(myJob);
// ADS
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
use of com.firebase.jobdispatcher.FirebaseJobDispatcher in project Habba18 by chiragsastry1996.
the class MyFirebaseMessagingService method scheduleJob.
// [END receive_message]
/**
* Schedule a job using FirebaseJobDispatcher.
*/
private void scheduleJob() {
// [START dispatch_job]
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = dispatcher.newJobBuilder().setService(MyJobService.class).setTag("my-job-tag").build();
dispatcher.schedule(myJob);
// [END dispatch_job]
}
Aggregations