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:divya.myvision.TessActivity.java

public void setLang(String lang) {
    Locale locale;//from w w  w  . j a  v  a2 s.  c om
    if (lang.equals("Spanish")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                Locale locSpanish = new Locale("spa", "MEX");
                tts.setLanguage(locSpanish);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("spa", "MEX");
    }

    else if (lang.equals("French")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.FRENCH);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("fr");
    } else if (lang.equals("Japanese")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.JAPANESE);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("ja");
    } else if (lang.equals("Chinese")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.CHINESE);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("zh");
    } else if (lang.equals("German")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.GERMAN);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("de");
    } else if (lang.equals("Italian")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.ITALIAN);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("it");
    } else if (lang.equals("Korean")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.KOREAN);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("ko");
    } else if (lang.equals("Hindi")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                Locale locHindhi = new Locale("hi");
                tts.setLanguage(locHindhi);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("hi");
    } else if (lang.equals("Russian")) {
        // Set up the Text To Speech engine.
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                Locale locHindhi = new Locale("ru");
                tts.setLanguage(locHindhi);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("ru");
    } else {
        TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(final int status) {
                tts.setLanguage(Locale.US);
            }
        };
        tts = new TextToSpeech(this.getApplicationContext(), listener);
        locale = new Locale("en");
    }
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.setLocale(locale);
    this.getApplicationContext().getResources().updateConfiguration(config, null);

}

From source file:org.dbhatt.d_deleted_contact.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_restore_all:
        if (Build.VERSION.SDK_INT > 22) {
            if (ContextCompat.checkSelfPermission(this,
                    Manifest.permission.WRITE_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
                restore_all_contacts();/*from  w w  w  .  java 2s .  c  o  m*/
            } else {
                final MainActivity mainActivity = this;
                if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                        Manifest.permission.WRITE_CONTACTS)) {
                    new AlertDialog.Builder(this).setTitle(R.string.permission)
                            .setMessage(R.string.permission_message_write_external_storage)
                            .setPositiveButton(R.string.permission_grant,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            finish_activity = false;
                                            ActivityCompat.requestPermissions(mainActivity,
                                                    new String[] { Manifest.permission.WRITE_CONTACTS },
                                                    REQUEST_WRITE_CONTACTS_CONTACT);
                                        }
                                    })
                            .create().show();
                } else {
                    finish_activity = false;
                    ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_CONTACTS },
                            REQUEST_WRITE_CONTACTS_CONTACT);
                }
            }
        } else {
            restore_all_contacts();
        }
        break;
    case R.id.action_app_invite:
        finish_activity = false;
        GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(AppInvite.API)
                .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
                    @Override
                    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

                    }
                }).build();
        Intent app_invite_intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invite_title))
                .setMessage(getString(R.string.invite_message))
                .setEmailSubject(getString(R.string.invite_email_subject))
                .setEmailHtmlContent("<html><h2 class='h2'><a href='%%APPINVITE_LINK_PLACEHOLDER%%'>"
                        + getString(R.string.app_name) + "</a></h2></html>")
                .build();
        startActivityForResult(app_invite_intent, APP_INVITE);
        break;

    case R.id.action_share:
        finish_activity = false;
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("application/zip");
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(getApplicationInfo().sourceDir)));
        startActivityForResult(Intent.createChooser(intent, getString(R.string.share)), APP_INVITE);
        break;

    case R.id.action_contact_us:
        finish_activity = false;
        startActivityForResult(new Intent(getApplicationContext(), Contact_us.class),
                DO_NOT_FINISH_REQUEST_CODE);
        break;
    case R.id.action_refresh:
        if (refreshing)
            Toast.makeText(this, R.string.try_after_some_time, Toast.LENGTH_SHORT).show();
        else
            load_contacts();
        break;
    case R.id.action_language:
        try {
            new AlertDialog.Builder(this).setTitle(R.string.action_language)
                    .setNegativeButton(R.string.dismiss, null)
                    .setItems(R.array.languages, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Locale locale = new Locale(getApplicationContext().getResources()
                                    .getStringArray(R.array.language_code)[which]);
                            Locale.setDefault(locale);
                            Configuration config = new Configuration();
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
                                config.setLocale(locale);
                            else
                                config.locale = locale;
                            getApplicationContext().getResources().updateConfiguration(config, null);
                            startActivity(new Intent(getApplicationContext(), Splash.class));
                            finish();
                        }
                    }).create().show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:github.daneren2005.dsub.util.Util.java

public static void applyTheme(Context context, String theme) {
    if ("dark".equals(theme)) {
        context.setTheme(R.style.Theme_DSub_Dark);
    } else if ("black".equals(theme)) {
        context.setTheme(R.style.Theme_DSub_Black);
    } else if ("holo".equals(theme)) {
        context.setTheme(R.style.Theme_DSub_Holo);
    } else {/*from w  w  w  .jav  a  2s  .c o  m*/
        context.setTheme(R.style.Theme_DSub_Light);
    }

    SharedPreferences prefs = Util.getPreferences(context);
    if (prefs.getBoolean(Constants.PREFERENCES_KEY_OVERRIDE_SYSTEM_LANGUAGE, false)) {
        Configuration config = new Configuration();
        config.locale = Locale.ENGLISH;
        context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
    }
}

From source file:com.BeatYourRecord.SubmitActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }//w  w  w. j a v  a  2 s .c  o m
    if (haveConnectedWifi == false) {
        showDialog(11);
    }
    super.onCreate(savedInstanceState);

    // SharedPreferences pref = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
    //Editor editor = pref.edit();
    //auth = pref.getString("BYR_session", null);
    /*SharedPreferences pref6 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
      Editor editor7 = pref6.edit();
      //this.setContentView(R.layout.submit);
        String logoutme = pref6.getString("log", null);
        //log.v("log",logoutme);
     */
    SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
    Editor editor1 = pref1.edit();
    tourid = pref1.getString("id", null);
    logout = pref1.getString("log", null);
    filepath = pref1.getString("filepath", null);
    //log.v("id",tourid);
    //log.v("log",logout);

    Log.v("reached here first", "reached here first");
    File f = new File("/data/data/com.BeatYourRecord/shared_prefs/Tester15.xml");
    if (f.exists() && logout.equals("yes") == false) {

        //log.v("yyy","yyy");
        SharedPreferences pref = SubmitActivity.this.getSharedPreferences("Tester15", 0); // 0 - for private mode
        Editor editor = pref.edit();
        this.setContentView(R.layout.submit);
        auth = pref.getString("BYR_session", null);

    } else {
        //log.v("yyy","yyy1");
        this.setContentView(R.layout.submit1);
        showDialog(10);
    }

    //   String checksession = pref.getString("BYR_session", null);
    //   //log.v("checksession", checksession);

    ////log.v("Authhere",auth);
    this.authorizer = new ClientLoginAuthorizer.ClientLoginAuthorizerFactory().getAuthorizer(this,
            ClientLoginAuthorizer.YOUTUBE_AUTH_TOKEN_TYPE);

    dbHelper = new DbHelper(this);
    dbHelper = dbHelper.open();

    Intent intent = this.getIntent();
    this.videoUri = intent.getData();
    SharedPreferences pref1223 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
    Editor editor1223 = pref1223.edit();
    filepath = pref1223.getString("filepath", null);
    // this.videoUri =

    //   Uri path = Uri.parse(filepath);
    //File f1 = new File(filepath);  
    //Uri imageUri = Uri.fromFile(f1);
    //this.videoUri = imageUri;
    //this.videoUri = path;

    Log.v("Reached here second", "Reached here secord");
    //this.videoUri= Uri.fromFile(new File("/sdcard/Movies/com.BeatYourRecord/BYR_tournName_dateTim_20130724181901222.mp4"));
    //log.v("haha","haha");

    MediaScannerConnectionClient mediaScannerClient = new MediaScannerConnectionClient() {
        private MediaScannerConnection msc = null;
        {
            msc = new MediaScannerConnection(getApplicationContext(), this);
            msc.connect();
        }

        public void onMediaScannerConnected() {
            msc.scanFile(filepath, null);
        }

        public void onScanCompleted(String path, Uri uri) {
            //This is where you get your content uri
            Log.d("test3", uri.toString());
            needed = uri;
            // videoUri=needed;

            msc.disconnect();
        }
    };

    String videoPath = "";

    try {
        videoPath = getFilePathFromUri(this.videoUri);
        filepath1 = videoPath;
        Log.v("videoPath", videoPath);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    File videoFile = new File(videoPath);

    this.ytdDomain = intent.getExtras().getString(DbHelper.YTD_DOMAIN);
    this.assignmentId = intent.getExtras().getString(DbHelper.ASSIGNMENT_ID);

    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);
        }
    });
    addusertotournament();
    Button cancelButton = (Button) findViewById(R.id.cancelButton);
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
            //Editor editor = pref1.edit();
            //editor.putString("filepath", permfilepath); 
            //editor.commit();
            Intent intent = new Intent(SubmitActivity.this, DetailsActivity.class);
            //    intent.putExtra(DbHelper.YTD_DOMAIN, "TODO-appname.appspot.com");

            //intent.setData(Uri.fromFile(file));   
            startActivity(intent);
            finish();
            // setResult(RESULT_CANCELED);
            //finish();
        }
    });

    Button forgotButton = (Button) findViewById(R.id.forgotButton);

    forgotButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
            //Editor editor = pref1.edit();
            //editor.putString("filepath", permfilepath); 
            //editor.commit();

            SharedPreferences pref155 = getApplicationContext().getSharedPreferences("TourPref", 0); // 0 - for private mode
            Editor editor155 = pref155.edit();

            editor155.putString("filepath", filepath1);
            editor155.commit();
            Log.v("fielpathss", filepath1);
            Intent intent = new Intent(SubmitActivity.this, DetailsActivity.class);
            //    intent.putExtra(DbHelper.YTD_DOMAIN, "TODO-appname.appspot.com");

            //intent.setData(Uri.fromFile(file));   
            startActivity(intent);
            //   finish();
            // setResult(RESULT_CANCELED);
            //finish();
        }
    });

    EditText titleEdit = (EditText) findViewById(R.id.submitTitle);
    titleEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
            enableSubmitIfReady();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    EditText descriptionEdit = (EditText) findViewById(R.id.submitDescription);
    descriptionEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
            enableSubmitIfReady();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    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)));
            Log.v("here", "here12");
            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();*/
            Log.v("here", "here13");

            // 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);
        }
    }
}

From source file:com.awt.supark.MainActivity.java

public void setLanguage(String lang) {
    sharedprefs.edit().putString("lang", lang).commit();
    if (!lang.equals("auto")) {
        Locale locale = new Locale(lang);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;/*from   ww  w .j  a va2 s  . co m*/
        getBaseContext().getResources().updateConfiguration(config,
                getBaseContext().getResources().getDisplayMetrics());
    }
}

From source file:dev.datvt.cloudtracks.MainActivity.java

public void loadLocale() {
    String langPref = "Language";
    SharedPreferences prefs = getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
    String language = prefs.getString(langPref, "en");
    myLocale = new Locale(language);
    Locale.setDefault(myLocale);/*from  w  ww .  jav a  2  s .c om*/
    Configuration config = new Configuration();
    config.locale = myLocale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());

}

From source file:com.linkbubble.util.Util.java

static public void setLocale(Context context, String code) {
    Locale locale = new Locale(code);
    Locale.setDefault(locale);//from w  w w. ja v  a  2s.c  o  m
    Configuration config = new Configuration();
    config.locale = locale;
    context.getApplicationContext().getResources().updateConfiguration(config, null);
}

From source file:org.osm.keypadmapper2.KeypadMapper2Activity.java

private void updateLocale() {
    String languageToLoad = KeypadMapperApplication.getInstance().getSettings().getCurrentLanguageCode();
    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);//  w  w w  .j a  va  2 s  . c  om
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    lang = languageToLoad;
}

From source file:info.guardianproject.pixelknot.PixelKnotActivity.java

private void setNewLocale(String locale_code) {
    Configuration configuration = new Configuration();
    switch (Integer.parseInt(locale_code)) {
    case Settings.Locales.DEFAULT:
        configuration.locale = new Locale(Locale.getDefault().getLanguage());
        break;// w  w  w.j  a v a2s.c  om
    case Settings.Locales.EN:
        configuration.locale = new Locale("en");
        break;
    case Settings.Locales.FA:
        configuration.locale = new Locale("fa");
        break;
    }
    getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
    restart();
}

From source file:com.android.server.MountService.java

private void copyLocaleFromMountService() {
    String systemLocale;//from   w w w . j a  v  a  2  s . c o m
    try {
        systemLocale = getField(StorageManager.SYSTEM_LOCALE_KEY);
    } catch (RemoteException e) {
        return;
    }
    if (TextUtils.isEmpty(systemLocale)) {
        return;
    }

    Slog.d(TAG, "Got locale " + systemLocale + " from mount service");
    Locale locale = Locale.forLanguageTag(systemLocale);
    Configuration config = new Configuration();
    config.setLocale(locale);
    try {
        ActivityManagerNative.getDefault().updateConfiguration(config);
    } catch (RemoteException e) {
        Slog.e(TAG, "Error setting system locale from mount service", e);
    }

    // Temporary workaround for http://b/17945169.
    Slog.d(TAG, "Setting system properties to " + systemLocale + " from mount service");
    SystemProperties.set("persist.sys.language", locale.getLanguage());
    SystemProperties.set("persist.sys.country", locale.getCountry());
}