Example usage for android.content Context MODE_WORLD_READABLE

List of usage examples for android.content Context MODE_WORLD_READABLE

Introduction

In this page you can find the example usage for android.content Context MODE_WORLD_READABLE.

Prototype

int MODE_WORLD_READABLE

To view the source code for android.content Context MODE_WORLD_READABLE.

Click Source Link

Document

File creation mode: allow all other applications to have read access to the created file.

Usage

From source file:Main.java

/**
 * Show a level//from  w w w .  j a  v  a2s . c  o m
 * 
 * @param context The context
 * @param level The level
 */
public static void showLevel(Context context, int level) {
    String filename;
    switch (level) {
    case 1: {
        filename = "ground_floor.png";
        break;
    }
    case 2: {
        filename = "talks_floor.png";
        break;
    }

    default: {
        return;
    }
    }
    File f = new File(context.getFilesDir() + "/" + filename);
    try {
        if (f.exists() == false) {
            InputStream is = context.getAssets().open(filename);
            FileOutputStream fos = context.openFileOutput(filename, Context.MODE_WORLD_READABLE);
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
            // write the stream to file
            fos.write(buffer, 0, buffer.length);
            fos.close();
            is.close();
        }

        // Prepare the intent
        //TODO - create an activity for this instead. Internal viewers might be quite heavy
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(f), "image/png");
        context.startActivity(intent);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.klinker.android.twitter.ui.compose.NotificationCompose.java

@Override
public void setUpReplyText() {
    // mark the messages as read here
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancel(1);//w  w w  .jav a 2s . c o  m
    mNotificationManager.cancel(9);

    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    Context context = getApplicationContext();
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    // we can just mark everything as read because it isnt taxing at all and won't do anything in the mentions if there isn't one
    // and the shared prefs are easy.
    // this is only called from the notification and there will only ever be one thing that is unread when this button is available

    MentionsDataSource.getInstance(context).markAllRead(currentAccount);

    // set up the reply box
    sharedPrefs.edit().putInt("dm_unread_" + currentAccount, 0).commit();
    reply.setText(sharedPrefs.getString("from_notification", ""));
    reply.setSelection(reply.getText().toString().length());
    notiId = sharedPrefs.getLong("from_notification_long", 0);
    replyText = sharedPrefs.getString("from_notification_text", "");

    sharedPrefs.edit().putLong("from_notification_id", 0).commit();
    sharedPrefs.edit().putString("from_notification_text", "").commit();
    sharedPrefs.edit().putString("from_notification", "").commit();
    sharedPrefs.edit().putBoolean("from_notification_bool", false).commit();

    String t = reply.getText().toString();
    if (!android.text.TextUtils.isEmpty(t) && !t.endsWith(" ")) {
        reply.append(" ");
        reply.setSelection(reply.getText().length());
    }

    // try from android wear device
    CharSequence voiceReply = getVoiceReply(getIntent());
    if (voiceReply != null) {
        if (!voiceReply.equals("")) {
            // set the text
            reply.append(voiceReply);

            // send the message
            doneClick();

            finish();
        }
    }
}

From source file:com.klinker.android.twitter.ui.compose.NotificationComposeSecondAcc.java

@Override
public void setUpReplyText() {
    // mark the messages as read here
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancel(1);/* w w w.  j  a  v  a  2s  .  c o  m*/
    mNotificationManager.cancel(9);

    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    Context context = getApplicationContext();
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    if (currentAccount == 1) {
        currentAccount = 2;
    } else {
        currentAccount = 1;
    }

    useAccOne = false;
    useAccTwo = true;

    NetworkedCacheableImageView pic = (NetworkedCacheableImageView) findViewById(R.id.profile_pic);
    HoloTextView currentName = (HoloTextView) findViewById(R.id.current_name);

    if (settings.roundContactImages) {
        pic.loadImage(settings.secondProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
    } else {
        pic.loadImage(settings.secondProfilePicUrl, false, null);
    }

    currentName.setText("@" + settings.secondScreenName);

    MentionsDataSource.getInstance(context).markAllRead(currentAccount);
    sharedPrefs.edit().putInt("dm_unread_" + currentAccount, 0).commit();

    // set up the reply box
    reply.setText(sharedPrefs.getString("from_notification_second", ""));
    reply.setSelection(reply.getText().toString().length());
    notiId = sharedPrefs.getLong("from_notification_long_second", 0);
    replyText = sharedPrefs.getString("from_notification_text_second", "");

    sharedPrefs.edit().putLong("from_notification_id_second", 0).commit();
    sharedPrefs.edit().putString("from_notification_text_second", "").commit();
    sharedPrefs.edit().putString("from_notification_second", "").commit();
    sharedPrefs.edit().putBoolean("from_notification_bool_second", false).commit();

    // try from android wear device
    CharSequence voiceReply = getVoiceReply(getIntent());
    if (voiceReply != null) {
        if (!voiceReply.equals("")) {
            // set the text
            reply.append(voiceReply);

            // send the message
            doneClick();

            finish();
        }
    }
}

From source file:com.klinker.android.twitter.ui.drawer_activities.discover.DiscoverPager.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    context = this;
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    settings = AppSettings.getInstance(this);

    requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

    setUpTheme();//from   w  ww.j  av a2  s  .c o  m
    setContentView(R.layout.trends_activity);
    setUpDrawer(3, getResources().getString(R.string.trends));

    actionBar = getActionBar();
    actionBar.setTitle(getResources().getString(R.string.trends));

    if (!settings.isTwitterLoggedIn) {
        Intent login = new Intent(context, LoginActivity.class);
        startActivity(login);
        finish();
    }

    mSectionsPagerAdapter = new TrendsPagerAdapter(getFragmentManager(), context);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOverScrollMode(ViewPager.OVER_SCROLL_NEVER);

    mViewPager.setOffscreenPageLimit(3);

    if (settings.addonTheme) {
        PagerTitleStrip strip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);
        strip.setBackgroundColor(settings.pagerTitleInt);
    }
}

From source file:reco.frame.tv.http.entityhandler.FileEntityHandler.java

public Object handleEntity(Context appContext, HttpEntity entity, EntityCallBack callback, String target,
        boolean isResume) throws IOException {
    if (TextUtils.isEmpty(target) || target.trim().length() == 0)
        return null;

    File targetFile = new File(target);

    if (!targetFile.exists()) {
        targetFile.createNewFile();/* w  w  w .j  a v  a 2s .  co  m*/
    }

    if (mStop) {
        return targetFile;
    }

    long current = 0;
    FileOutputStream os = null;
    if (isResume) {
        current = targetFile.length();
        os = appContext.openFileOutput(target.substring(target.lastIndexOf("/") + 1),
                Context.MODE_APPEND | Context.MODE_WORLD_READABLE);
        //os = new FileOutputStream(target, true);
    } else {
        os = appContext.openFileOutput(target.substring(target.lastIndexOf("/") + 1),
                Context.MODE_WORLD_READABLE);
    }

    if (mStop) {
        return targetFile;
    }

    InputStream input = entity.getContent();
    long count = entity.getContentLength() + current;

    if (current >= count || mStop) {
        return targetFile;
    }

    int readLen = 0;
    byte[] buffer = new byte[1024];
    while (!mStop && !(current >= count) && ((readLen = input.read(buffer, 0, 1024)) > 0)) {//
        os.write(buffer, 0, readLen);
        current += readLen;
        callback.callBack(count, current, false);
    }
    callback.callBack(count, current, true);

    if (mStop && current < count) { //
        throw new IOException("user stop download thread");
    }

    return targetFile;
}

From source file:piramide.multimodal.downloader.client.ApplicationDownloader.java

void download() throws DownloaderException {
    final HttpClient client = new DefaultHttpClient();
    try {//from   ww w  .  ja  v  a 2  s.co  m
        final FileOutputStream fos = this.context.openFileOutput(APK_FILENAME, Context.MODE_WORLD_READABLE);
        final HttpResponse response = client.execute(new HttpGet(this.url));
        if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() >= 400) {
            throw new DownloaderException("Invalid status code downloading application: "
                    + response.getStatusLine().getReasonPhrase());
        }
        downloadFile(response, fos);
        fos.close();
    } catch (ClientProtocolException e) {
        throw new DownloaderException(e);
    } catch (IOException e) {
        throw new DownloaderException(e);
    }
}

From source file:de.Maxr1998.xposed.maxlock.ui.MasterSwitchShortcutActivity.java

@SuppressLint("WorldReadableFiles")
@Override//from ww w.  j  ava 2 s  . c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getIntent().getBooleanExtra("LaunchOnly", false)) {
        // Launch
        Log.d("MaxLock", "Launching shortcut");
        //noinspection deprecation
        prefsPackages = getSharedPreferences(Common.PREFS_PACKAGES, Context.MODE_WORLD_READABLE);
        if (prefsPackages.getBoolean(Common.MASTER_SWITCH_ON, true)) {
            setContentView(R.layout.activity_lock);
            Fragment frag = new LockFragment();
            Bundle b = new Bundle(1);
            b.putString(Common.INTENT_EXTRAS_PKG_NAME, getString(R.string.unlock_master_switch));
            frag.setArguments(b);
            getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, frag).commit();
        } else {
            prefsPackages.edit().putBoolean(Common.MASTER_SWITCH_ON, true).commit();
            Toast.makeText(this, getString(R.string.toast_master_switch_on), Toast.LENGTH_LONG).show();
            fireIntentAndFinish();
        }
    } else {
        // Create shortcut
        Log.d("MaxLock", "Creating shortcut");
        Intent shortcut = new Intent(this, MasterSwitchShortcutActivity.class);
        shortcut.putExtra("LaunchOnly", true);
        Intent install = new Intent();
        install.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.toggle_master_switch));
        install.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher));
        install.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
        setResult(RESULT_OK, install);
        fireIntentAndFinish();
    }
}

From source file:piramide.multimodal.client.tester.ApplicationDownloader.java

void download() throws DownloaderException {
    final HttpClient client = new DefaultHttpClient();
    try {//  w w w.  ja  v a 2s .  c  om
        final FileOutputStream fos = this.activity.openFileOutput(APK_FILENAME, Context.MODE_WORLD_READABLE);
        final HttpResponse response = client.execute(new HttpGet(URL));
        downloadFile(response, fos);
        fos.close();
    } catch (ClientProtocolException e) {
        throw new DownloaderException(e);
    } catch (IOException e) {
        throw new DownloaderException(e);
    }
}

From source file:com.klinker.android.twitter.settings.configure_pages.ConfigurePagerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    context = this;
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    settings = AppSettings.getInstance(this);

    try {/*from w w  w  .  j  a va  2s. com*/
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    } catch (Throwable e) {
        // don't have a clue why
    }

    Utils.setUpTheme(context, settings);
    setContentView(R.layout.configuration_activity);

    setUpDoneDiscard();

    actionBar = getActionBar();

    if (!settings.isTwitterLoggedIn) {
        Intent login = new Intent(context, LoginActivity.class);
        startActivity(login);
        finish();
    }

    mSectionsPagerAdapter = new ConfigurationPagerAdapter(getFragmentManager(), context);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOverScrollMode(ViewPager.OVER_SCROLL_NEVER);

    mViewPager.setOffscreenPageLimit(3);
}

From source file:com.rong.xposed.headsoff.adapter.PackageListAdapter.java

@SuppressLint("WorldReadableFiles")
@SuppressWarnings("deprecation")
public PackageListAdapter(Context context, List<Map<String, Object>> list) {
    mContext = context;/*from  w  w w. j av  a 2  s  . c om*/
    mItemList = list;
    prefs = context.getSharedPreferences(SettingValues.PREF_FILE, Context.MODE_WORLD_READABLE);
    initColors();
}