Example usage for android.content.res Configuration Configuration

List of usage examples for android.content.res Configuration Configuration

Introduction

In this page you can find the example usage for android.content.res Configuration Configuration.

Prototype

public Configuration() 

Source Link

Document

Construct an invalid Configuration.

Usage

From source file:com.nxp.nfc_demo.activities.MainActivity.java

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

    // Application package name to be used by the AAR record
    PACKAGE_NAME = getApplicationContext().getPackageName();
    String languageToLoad = "en";
    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);/*from w  ww .  j av  a2 s  .  c o m*/
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    setContentView(R.layout.activity_main);
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);
    mTabsAdapter.addTab(mTabHost.newTabSpec("leds").setIndicator(getString(R.string.leds)), LedFragment.class,
            null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("ndef").setIndicator(getString(R.string.ndefs)), NdefFragment.class,
            null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("ntag_rf").setIndicator(getString(R.string.ntag_rf_text)),
            SpeedTestFragment.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("config").setIndicator(getString(R.string.settings)),
            ConfigFragment.class, null);

    // set current Tag to the Speedtest, so it loads the values
    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }
    // Get App version
    appVersion = "";
    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        appVersion = pInfo.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    // Board firmware version
    boardFirmwareVersion = "Unknown";

    // Notifier to be used for the demo changing
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (demo.isReady()) {
                demo.finishAllTasks();
                if (tabId.equalsIgnoreCase("leds") && demo.isConnected()) {
                    launchDemo(tabId);
                }
            }
            mTabsAdapter.onTabChanged(tabId);
        }
    });
    // When we open the application by default we set the status to disabled (we don't know the product yet)
    mAuthStatus = AuthStatus.Disabled.getValue();

    // Initialize the demo in order to handle tab change events
    demo = new Ntag_I2C_Demo(null, this, null, 0);
    mAdapter = NfcAdapter.getDefaultAdapter(this);
    setNfcForeground();
    checkNFC();
}

From source file:eu.focusnet.app.util.ApplicationHelper.java

/**
 * Reset language to the default language
 *///from   w ww.  ja va 2s  . co m
public static void resetLanguage() {
    Locale defaultLocale = ApplicationHelper.getDefaultLocale();
    Locale.setDefault(defaultLocale);
    Configuration config = new Configuration();
    config.locale = defaultLocale;
    getApplicationContext().getResources().updateConfiguration(config,
            getApplicationContext().getResources().getDisplayMetrics());
}

From source file:com.jtechme.apphub.FDroidApp.java

private void applyLanguage() {
    Context ctx = getBaseContext();
    Configuration cfg = new Configuration();
    cfg.locale = locale == null ? Locale.getDefault() : locale;
    ctx.getResources().updateConfiguration(cfg, null);
}

From source file:com.morphoss.jumble.frontend.SettingsActivity.java

/**
 * This method set a particular language as the current language
 * /*w  w w. j a  va  2  s.c  o m*/
 * @param v
 */
public void setLanguage(String language) {
    languageToLoad = language;
    Log.d(TAG, "the language chosen is: " + language);
    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getResources().updateConfiguration(config, getResources().getDisplayMetrics());
    initControls();
}

From source file:de.pezeshki.bahaicalendar.MainActivity.java

private void setParameters() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    dateFormat = sharedPref.getString(SettingsActivity.KEY_PREF_DATE_FORMAT, "");
    String languageToLoad = sharedPref.getString(SettingsActivity.KEY_PREF_LANGUAGE, "");
    locale = new Locale(languageToLoad);
    Locale.setDefault(locale);/*from  w w  w  . j a v a 2  s  .c  o m*/
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
}

From source file:com.grarak.kerneladiutor.utils.Utils.java

public static void setLocale(String lang, Context context) {
    Locale locale = new Locale(lang);
    Locale.setDefault(locale);//from w w w  . j  ava2s  . c om
    Configuration config = new Configuration();
    config.locale = locale;
    context.getApplicationContext().getResources().updateConfiguration(config, null);
}

From source file:eu.faircode.netguard.ServiceJob.java

private static void submit(Rule rule, PersistableBundle bundle, Context context) {
    PackageManager pm = context.getPackageManager();
    JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

    // Get english application label
    String label = null;/* w w  w.j a  v  a 2  s .co  m*/
    try {
        Configuration config = new Configuration();
        config.setLocale(new Locale("en"));
        Resources res = pm.getResourcesForApplication(rule.info.packageName);
        res.updateConfiguration(config, res.getDisplayMetrics());
        label = res.getString(rule.info.applicationInfo.labelRes);
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        CharSequence cs = rule.info.applicationInfo.loadLabel(pm);
        if (cs != null)
            label = cs.toString();
    }

    // Add application data
    bundle.putInt("uid", rule.info.applicationInfo.uid);
    bundle.putString("package", rule.info.packageName);
    bundle.putInt("version_code", rule.info.versionCode);
    bundle.putString("version_name", rule.info.versionName);
    bundle.putString("label", label);
    bundle.putInt("system", rule.system ? 1 : 0);
    try {
        bundle.putString("installer", pm.getInstallerPackageName(rule.info.packageName));
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        bundle.putString("installer", null);
    }

    // Cancel overlapping jobs
    for (JobInfo pending : scheduler.getAllPendingJobs()) {
        String type = pending.getExtras().getString("type");
        if (type != null && type.equals(bundle.getString("type"))) {
            if (type.equals("rule")) {
                int uid = pending.getExtras().getInt("uid");
                if (uid == bundle.getInt("uid")) {
                    Log.i(TAG, "Canceling id=" + pending.getId());
                    scheduler.cancel(pending.getId());
                }
            } else if (type.equals("host")) {
                int uid = pending.getExtras().getInt("uid");
                int version = pending.getExtras().getInt("version");
                int protocol = pending.getExtras().getInt("protocol");
                String daddr = pending.getExtras().getString("daddr");
                int dport = pending.getExtras().getInt("dport");
                if (uid == bundle.getInt("uid") && version == bundle.getInt("version")
                        && protocol == bundle.getInt("protocol") && daddr != null
                        && daddr.equals(bundle.getString("daddr")) && dport == bundle.getInt("dport")) {
                    Log.i(TAG, "Canceling id=" + pending.getId());
                    scheduler.cancel(pending.getId());
                }
            }
        }
    }

    // Schedule job
    ComponentName serviceName = new ComponentName(context, ServiceJob.class);
    JobInfo job = new JobInfo.Builder(++id, serviceName).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
            .setMinimumLatency(Util.isDebuggable(context) ? 10 * 1000 : 60 * 1000).setExtras(bundle)
            .setPersisted(true).build();
    if (scheduler.schedule(job) == JobScheduler.RESULT_SUCCESS)
        Log.i(TAG, "Scheduled job=" + job.getId() + " success");
    else
        Log.e(TAG, "Scheduled job=" + job.getId() + " failed");
}

From source file:com.anykey.balala.activity.BaseActivity.java

@Override
public Resources getResources() {
    Resources res = super.getResources();
    Configuration config = new Configuration();
    config.setToDefaults();//from  ww w  .  j  ava  2 s  .  co  m
    res.updateConfiguration(config, res.getDisplayMetrics());
    return res;
}

From source file:mp.paschalis.App.java

public static void updateLanguage(Context ctx) {

    // Change locale
    Locale locale = new Locale(App.lang);
    Locale.setDefault(locale);//  ww  w.j  av a2  s.  c  om
    Configuration config = new Configuration();
    config.locale = locale;
    ctx.getResources().updateConfiguration(config, ctx.getResources().getDisplayMetrics());

}

From source file:com.google.ytd.SubmitActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.submit);

    this.authorizer = new GlsAuthorizer.GlsAuthorizerFactory().getAuthorizer(this,
            GlsAuthorizer.YOUTUBE_AUTH_TOKEN_TYPE);

    dbHelper = new DbHelper(this);
    dbHelper = dbHelper.open();//from   w  ww .j a v a  2s . c  om

    Intent intent = this.getIntent();
    this.videoUri = intent.getData();
    this.ytdDomain = intent.getExtras().getString(DbHelper.YTD_DOMAIN);
    this.assignmentId = intent.getExtras().getString(DbHelper.ASSIGNMENT_ID);
    this.title = intent.getExtras().getString(DbHelper.DESCRIPTION);
    this.instructions = intent.getExtras().getString(DbHelper.INSTRUCTIONS);

    this.domainHeader = (TextView) this.findViewById(R.id.domainHeader);
    domainHeader.setText(SettingActivity.getYtdDomains(this).get(this.ytdDomain));

    this.preferences = this.getSharedPreferences(MainActivity.SHARED_PREF_NAME, Activity.MODE_PRIVATE);
    this.youTubeName = preferences.getString(DbHelper.YT_ACCOUNT, null);

    final Button submitButton = (Button) findViewById(R.id.submitButton);
    submitButton.setEnabled(false);

    submitButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_LEGAL);
        }
    });

    Button cancelButton = (Button) findViewById(R.id.cancelButton);
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(RESULT_CANCELED);
            finish();
        }
    });

    EditText titleEdit = (EditText) findViewById(R.id.submitTitle);
    titleEdit.setText(title);
    titleEdit.setEnabled(false);
    enableSubmitIfReady();

    EditText descriptionEdit = (EditText) findViewById(R.id.submitDescription);
    descriptionEdit.setText(instructions);
    descriptionEdit.setEnabled(false);

    Cursor cursor = this.managedQuery(this.videoUri, null, null, null, null);

    if (cursor.getCount() == 0) {
        Log.d(LOG_TAG, "not a valid video uri");
        Toast.makeText(SubmitActivity.this, "not a valid video uri", Toast.LENGTH_LONG).show();
    } else {
        getVideoLocation();

        if (cursor.moveToFirst()) {

            long id = cursor.getLong(cursor.getColumnIndex(Video.VideoColumns._ID));
            this.dateTaken = new Date(cursor.getLong(cursor.getColumnIndex(Video.VideoColumns.DATE_TAKEN)));

            SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm aaa");
            Configuration userConfig = new Configuration();
            Settings.System.getConfiguration(getContentResolver(), userConfig);
            Calendar cal = Calendar.getInstance(userConfig.locale);
            TimeZone tz = cal.getTimeZone();

            dateFormat.setTimeZone(tz);

            TextView dateTakenView = (TextView) findViewById(R.id.dateCaptured);
            dateTakenView.setText("Date captured: " + dateFormat.format(dateTaken));

            ImageView thumbnail = (ImageView) findViewById(R.id.thumbnail);
            ContentResolver crThumb = getContentResolver();
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 1;
            Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id,
                    MediaStore.Video.Thumbnails.MICRO_KIND, options);
            thumbnail.setImageBitmap(curThumb);
        }
    }
}