List of usage examples for android.content Context MODE_WORLD_READABLE
int MODE_WORLD_READABLE
To view the source code for android.content Context MODE_WORLD_READABLE.
Click Source Link
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static String[] getTitle(int[] unreadCount, Context context, int currentAccount) { String text = ""; String name = null;/*from www. ja v a 2 s .c o m*/ String names = ""; int homeTweets = unreadCount[0]; int mentionsTweets = unreadCount[1]; int dmTweets = unreadCount[2]; // they only have a new mention if (mentionsTweets == 1 && homeTweets == 0 && dmTweets == 0) { MentionsDataSource mentions = MentionsDataSource.getInstance(context); name = mentions.getNewestName(currentAccount); String n = mentions.getNewestNames(currentAccount); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); for (String s : n.split(" ")) { if (!s.equals("") && !sharedPrefs.getString("twitter_screen_name_" + currentAccount, "").equals(s) && !s.equals(name)) { names += "@" + s + " "; } } text = context.getResources().getString(R.string.mentioned_by) + " @" + name; // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return null; } } else if (homeTweets == 0 && mentionsTweets == 0 && dmTweets == 1) { // they have 1 new direct message DMDataSource dm = DMDataSource.getInstance(context); name = dm.getNewestName(currentAccount); text = context.getResources().getString(R.string.message_from) + " @" + name; } else { // other cases we will just put talon text = context.getResources().getString(R.string.app_name); } return new String[] { text, name, names }; }
From source file:com.klinker.android.twitter.ui.MainActivity.java
@Override public void onStart() { super.onStart(); MainActivity.isPopup = false;// w w w. j a v a2 s . co m Log.v("talon_starting", "main activity starting"); sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); // check for night mode switching int theme = AppSettings.getCurrentTheme(sharedPrefs); if (!getWindow().hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY) || sharedPrefs.getBoolean("launcher_frag_switch", false) || (theme != settings.theme && !settings.addonTheme)) { sharedPrefs.edit().putBoolean("launcher_frag_switch", false).putBoolean("dont_refresh", true).commit(); AppSettings.invalidate(); Log.v("talon_theme", "no action bar overlay found, recreating"); finish(); overridePendingTransition(0, 0); startActivity(getRestartIntent()); overridePendingTransition(0, 0); MainActivity.caughtstarting = true; // return so that it doesn't start the background refresh, that is what caused the dups. sharedPrefs.edit().putBoolean("dont_refresh_on_start", true).commit(); return; } else { sharedPrefs.edit().putBoolean("dont_refresh", false).putBoolean("should_refresh", true).commit(); } if (DrawerActivity.settings.pushNotifications) { if (!TalonPullNotificationService.isRunning) { context.startService(new Intent(context, TalonPullNotificationService.class)); } } else { context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE")); } // cancel the alarm to start the catchup service AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getService(context, 236, new Intent(context, CatchupPull.class), 0); am.cancel(pendingIntent); // cancel the old one, then start the new one in 1 min // clear the pull unread sharedPrefs.edit().putInt("pull_unread", 0).commit(); UpdateUtils.checkUpdate(this); /*new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(1000); } catch (Exception e) { } NotificationUtils.refreshNotification(context); } }).start();*/ }
From source file:joshuamgoodwin.gmail.com.ohiolegalaidassistant.MainActivity.java
private void CopyAssets(String fileName) { AssetManager am = getAssets();/*from w ww. j a v a 2s . com*/ InputStream in = null; OutputStream out = null; File file = new File(getFilesDir(), fileName); try { in = am.open(fileName); out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); copyFile(in, out); in.close(); in = null; out.close(); out = null; } catch (Exception e) { Log.e("tag", e.getMessage()); } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + getFilesDir() + "/" + fileName), "application/pdf"); startActivity(intent); }
From source file:com.klinker.android.twitter.ui.tweet_viewer.TweetPager.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed();//from www . j a v a 2 s . c o m return true; case R.id.menu_delete_tweet: new DeleteTweet().execute(); getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE).edit() .putBoolean("just_muted", true).commit(); return true; case R.id.menu_share: String text1 = tweet; text1 = "@" + screenName + ": " + text1 + "\n\n" + "https://twitter.com/" + screenName + "/status/" + tweetId; Log.v("my_text_on_share", text1); Intent share = new Intent(Intent.ACTION_SEND); share.setType("text/plain"); share.putExtra(Intent.EXTRA_TEXT, text1); startActivity(share); return true; case R.id.menu_copy_text: ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("tweet_text", tweet); clipboard.setPrimaryClip(clip); return true; /*case R.id.menu_open_web: Uri weburi; try { weburi = Uri.parse(otherLinks[0]); } catch (Exception e) { weburi = Uri.parse(webpage); } Intent launchBrowser = new Intent(Intent.ACTION_VIEW, weburi); startActivity(launchBrowser); return true;*/ case R.id.menu_save_image: new Thread(new Runnable() { @Override public void run() { Looper.prepare(); try { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.downloading) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.saving_picture) + "...") .setProgress(100, 100, true).setLargeIcon(BitmapFactory .decodeResource(context.getResources(), R.drawable.ic_action_save)); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); String url = webpage; if (webpage.contains("insta")) { url = url.substring(0, url.length() - 1) + "l"; } URL mUrl = new URL(url); Bitmap bitmap = BitmapFactory.decodeStream(mUrl.openConnection().getInputStream()); Random generator = new Random(); int n = 1000000; n = generator.nextInt(n); String fname = "Image-" + n; Uri uri = IOUtils.saveImage(bitmap, fname, context); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/*"); PendingIntent pending = PendingIntent.getActivity(context, 91, intent, 0); mBuilder = new NotificationCompat.Builder(context).setContentIntent(pending) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.saved_picture) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.saved_picture) + "!") .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_save)); mNotificationManager.notify(6, mBuilder.build()); } catch (Exception e) { e.printStackTrace(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.error) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.error) + "...") .setProgress(100, 100, true).setLargeIcon(BitmapFactory .decodeResource(context.getResources(), R.drawable.ic_action_save)); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); } } }).start(); return true; case R.id.menu_quote: String text = tweet; if (!settings.preferRT) { text = "\"@" + screenName + ": " + text + "\" "; } else { text = " RT @" + screenName + ": " + text; } Intent quote = new Intent(context, ComposeActivity.class); quote.putExtra("user", text); quote.putExtra("id", tweetId); startActivity(quote); return true; case R.id.menu_spam: new MarkSpam().execute(); getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE).edit() .putBoolean("just_muted", true).commit(); return super.onOptionsItemSelected(item); /*case R.id.menu_mute_hashtags: if (!hashtags[0].equals("")) { ArrayList<String> tags = new ArrayList<String>(); if (hashtags != null) { for (String s : hashtags) { if (!s.equals("")) { tags.add("#" + s); } } } final CharSequence[] fItems = new CharSequence[tags.size()]; for (int i = 0; i < tags.size(); i++) { fItems[i] = tags.get(i); } final SharedPreferences sharedPreferences = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); if (fItems.length > 1) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setItems(fItems, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { String touched = fItems[item] + ""; Toast.makeText(context, getResources().getString(R.string.muted) + " " + touched, Toast.LENGTH_SHORT).show(); touched = touched.replace("#", "") + " "; String current = sharedPreferences.getString("muted_hashtags", ""); sharedPreferences.edit().putString("muted_hashtags", current + touched).commit(); sharedPreferences.edit().putBoolean("refresh_me", true).commit(); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } else { String touched = fItems[0] + ""; Toast.makeText(context, getResources().getString(R.string.muted) + " " + touched, Toast.LENGTH_SHORT).show(); touched = touched.replace("#", "") + " "; String current = sharedPreferences.getString("muted_hashtags", ""); sharedPreferences.edit().putString("muted_hashtags", current + touched).commit(); sharedPreferences.edit().putBoolean("refresh_me", true).commit(); } } else { Toast.makeText(context, getResources().getString(R.string.no_hashtags), Toast.LENGTH_SHORT).show(); } PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("just_muted", true).commit(); return super.onOptionsItemSelected(item); case R.id.menu_share_links: if (!otherLinks[0].equals("")) { ArrayList<String> urls = new ArrayList<String>(); if (otherLinks != null) { for (String s : otherLinks) { if (!s.equals("")) { urls.add(s); } } } final CharSequence[] fItems = new CharSequence[urls.size()]; for (int i = 0; i < urls.size(); i++) { fItems[i] = urls.get(i); } if (fItems.length > 1) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setItems(fItems, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { String touched = fItems[item] + ""; Intent intent=new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, touched); context.startActivity(Intent.createChooser(intent, context.getResources().getString(R.string.menu_share))); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } else { String touched = fItems[0] + ""; Intent intent=new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, touched); context.startActivity(Intent.createChooser(intent, context.getResources().getString(R.string.menu_share))); } } else { Toast.makeText(context, getResources().getString(R.string.no_links), Toast.LENGTH_SHORT).show(); } return super.onOptionsItemSelected(item);*/ case R.id.menu_translate: try { String query = tweet.replaceAll(" ", "+"); String url = "http://translate.google.com/#auto|en|" + tweet; Uri uri = Uri.parse(url); Intent browser = new Intent(Intent.ACTION_VIEW, uri); browser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(browser); } catch (Exception e) { } return true; default: return super.onOptionsItemSelected(item); } }
From source file:de.schildbach.wallet.worldcoin.service.BlockchainServiceImpl.java
@Override public void onCreate() { Log.d(TAG, ".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); final int versionCode = application.applicationVersionCode(); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, versionCode).commit(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);//from w w w . j a v a 2 s . c o m final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { Log.d(TAG, "blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); copyBlockchainSnapshot(blockChainFile); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); if (!blockChainFileExists) { // Starting from scratch try { final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); final InputStream checkpointsFileIn = getAssets().open("checkpoints"); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsFileIn, blockStore, earliestKeyCreationTime); } catch (IOException e) { Log.d("worldcoin", "Couldn't find checkpoints file; starting from genesis"); } } blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } catch (final NullPointerException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:de.schildbach.wallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { Log.d(TAG, ".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); final int versionCode = application.applicationVersionCode(); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, versionCode).commit(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);/*from w w w. ja v a2 s .c o m*/ final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { Log.d(TAG, "blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); } catch (final IOException x) { // continue without checkpoints x.printStackTrace(); } } } catch (final BlockStoreException x) { try { blockStore = new BoundedOverheadBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x2) { blockChainFile.delete(); x2.printStackTrace(); throw new Error("blockstore cannot be created", x2); } } Log.i(TAG, "using " + blockStore.getClass().getName()); try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:de.schildbach.wallet.digitalcoin.service.BlockchainServiceImpl.java
@Override public void onCreate() { Log.d(TAG, ".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); final int versionCode = application.applicationVersionCode(); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, versionCode).commit(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);/*from w ww .ja va2s.c o m*/ final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { Log.d(TAG, "blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); copyBlockchainSnapshot(blockChainFile); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); if (!blockChainFileExists) { // Starting from scratch try { final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); final InputStream checkpointsFileIn = getAssets().open("checkpoints"); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsFileIn, blockStore, earliestKeyCreationTime); } catch (IOException e) { Log.d("digitalcoin", "Couldn't find checkpoints file; starting from genesis"); } } blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } catch (final NullPointerException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:com.feathercoin.wallet.feathercoin.service.BlockchainServiceImpl.java
@Override public void onCreate() { Log.d(TAG, ".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); final int versionCode = application.applicationVersionCode(); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, versionCode).commit(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);// www . j av a 2 s .c o m final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { Log.d(TAG, "blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); copyBlockchainSnapshot(blockChainFile); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); if (!blockChainFileExists) { // Starting from scratch try { final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); final InputStream checkpointsFileIn = getAssets().open("checkpoints"); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsFileIn, blockStore, earliestKeyCreationTime); } catch (IOException e) { Log.d("Feathercoin", "Couldn't find checkpoints file; starting from genesis"); } } blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } catch (final NullPointerException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:de.schildbach.wallet.goldcoin.service.BlockchainServiceImpl.java
@Override public void onCreate() { Log.d(TAG, ".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); final int versionCode = application.applicationVersionCode(); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, versionCode).commit(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);//from www . jav a2 s . co m final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { Log.d(TAG, "blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); copyBlockchainSnapshot(blockChainFile); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); if (!blockChainFileExists) { // Starting from scratch try { final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); final InputStream checkpointsFileIn = getAssets().open("checkpoints"); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsFileIn, blockStore, earliestKeyCreationTime); } catch (IOException e) { Log.d("Litecoin", "Couldn't find checkpoints file; starting from genesis"); } } blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } catch (final NullPointerException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:de.schildbach.wallet.marscoin.service.BlockchainServiceImpl.java
@Override public void onCreate() { Log.d(TAG, ".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); final int versionCode = application.applicationVersionCode(); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, versionCode).commit(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);// w w w .j a v a 2s . co m final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { Log.d(TAG, "blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); copyBlockchainSnapshot(blockChainFile); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); if (!blockChainFileExists) { // Starting from scratch try { final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); final InputStream checkpointsFileIn = getAssets().open("checkpoints"); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsFileIn, blockStore, earliestKeyCreationTime); } catch (IOException e) { Log.d("marscoin", "Couldn't find checkpoints file; starting from genesis"); } } blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } catch (final NullPointerException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }