List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.yamin.kk.vlc.Util.java
public static void updateLibVlcSettings(SharedPreferences pref) { LibVLC instance = LibVLC.getExistingInstance(); if (instance == null) return;/*from w w w . j a v a 2s .co m*/ instance.setIomx(pref.getBoolean("enable_iomx", false)); instance.setSubtitlesEncoding(pref.getString("subtitles_text_encoding", "")); instance.setTimeStretching(pref.getBoolean("enable_time_stretching_audio", false)); instance.setFrameSkip(pref.getBoolean("enable_frame_skip", false)); instance.setChroma(pref.getString("chroma_format", "")); instance.setVerboseMode(pref.getBoolean("enable_verbose_mode", true)); if (pref.getBoolean("equalizer_enabled", false)) instance.setEqualizer(getFloatArray(pref, "equalizer_values")); int aout; try { aout = Integer.parseInt(pref.getString("aout", "-1")); } catch (NumberFormatException nfe) { aout = -1; } int vout; try { vout = Integer.parseInt(pref.getString("vout", "-1")); } catch (NumberFormatException nfe) { vout = -1; } int deblocking; try { deblocking = Integer.parseInt(pref.getString("deblocking", "-1")); } catch (NumberFormatException nfe) { deblocking = -1; } int hardwareAcceleration; try { hardwareAcceleration = Integer.parseInt(pref.getString("hardware_acceleration", "-1")); } catch (NumberFormatException nfe) { hardwareAcceleration = -1; } int networkCaching = pref.getInt("network_caching_value", 0); if (networkCaching > 60000) networkCaching = 60000; else if (networkCaching < 0) networkCaching = 0; instance.setAout(aout); instance.setVout(vout); instance.setDeblocking(deblocking); instance.setNetworkCaching(networkCaching); instance.setHardwareAcceleration(hardwareAcceleration); }
From source file:com.nextgis.maplibui.activity.ModifyAttributesActivity.java
private String formatCoordinates(double value, int caption) { String appendix;/* w w w. j a va 2 s.c o m*/ if (value != Double.NaN) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); int nFormat = Integer.parseInt( prefs.getString(SettingsConstantsUI.KEY_PREF_COORD_FORMAT, Location.FORMAT_DEGREES + "")); int nFraction = prefs.getInt(SettingsConstantsUI.KEY_PREF_COORD_FRACTION, 6); appendix = LocationUtil.formatLatitude(value, nFormat, nFraction, getResources()); } else appendix = getString(R.string.n_a); return getString(caption) + ": " + appendix; }
From source file:aarddict.android.ArticleViewActivity.java
@TargetApi(android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void applyTextZoomPref() { SharedPreferences prefs = getPreferences(MODE_PRIVATE); int textZoom = prefs.getInt("articleView.textZoom", 100); articleView.getSettings().setTextZoom(textZoom); }
From source file:com.tt.jobtracker.MainActivity.java
private String getRegistrationId(Context context) { final SharedPreferences prefs = getGcmPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (registrationId.isEmpty()) { return ""; }/*from w ww . ja v a 2 s . com*/ int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); int currentVersion = getAppVersion(context); if (registeredVersion != currentVersion) { return ""; } // sendRegistrationIdToBackend(registrationId, Shared.LoggedInUser.ID); return registrationId; }
From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java
@Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.repeater_list); overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale); lv = (ListView) findViewById(R.id.repeaterListView); tvAddress = (TextView) findViewById(R.id.tvAddress); xlocation = new Repeater("", LAT_DEFAULT, LNG_DEFAULT); rl = RepeaterListActivity.loadData(R.raw.repeaterdata5, this); xlocation.calcDistanceAll(rl);//from www .j av a 2 s . c om rl.sort(); adapter = new RepeaterAdapter(this, rl, xlocation, local_distance, excludeLink, excludeDirection); lv.setFastScrollEnabled(true); lv.setVerticalFadingEdgeEnabled(false); lv.setVerticalScrollBarEnabled(true); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(this); // SharedPreferences prefs = getSharedPreferences("Location", // MODE_PRIVATE); SharedPreferences prefshare = PreferenceManager.getDefaultSharedPreferences(this); int walkcount = prefshare.getInt("walkthrough", WALK_VERSION_CODE); if (walkcount < (WALK_VERSION_CODE + 1)) { Intent intent = new Intent(); intent.setClassName(getApplicationContext(), "net.mypapit.mobile.myrepeater.SettingsActivity"); startActivity(intent); intent.setClassName(getApplicationContext(), "net.mypapit.mobile.myrepeater.WalkthroughActivity"); SharedPreferences.Editor prefEditor = prefshare.edit(); walkcount++; SharedPreferences repeater_prefs = PreferenceManager.getDefaultSharedPreferences(this); m_deviceid = repeater_prefs.getString("deviceid", this.generateCallsign()); prefEditor.putInt("walkthrough", walkcount); // prefEditor.putString("callsign", new // StringBuilder("9W2-").append(this.generateCallsign()).toString()); prefEditor.putString("deviceid", m_deviceid); prefEditor.commit(); startActivity(intent); } // need to put token to avoid app from popping up annoying select manual // dialog will be triggered if location/gps is not enabled AND if the // date in dd/MM is not equal to 'token' saved in StaticLocationActivity // location dialog SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM", Locale.US); Date date = new Date(); SharedPreferences preftoken = getSharedPreferences("Location", MODE_PRIVATE); if (!this.isLocationEnabled(this) && !dateFormat.format(date).equalsIgnoreCase(preftoken.getString("token", "28/10"))) { // show dialog if Location Services is not enabled AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.gps_not_found_title); // GPS not found builder.setMessage(R.string.gps_not_found_message); // Want to // enable? // if yes - bring user to enable Location Service settings builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplicationContext().startActivity(intent); } }); // if no - bring user to selecting Static Location Activity builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(); intent.setClassName(getApplicationContext(), "net.mypapit.mobile.myrepeater.StaticLocationActivity"); startActivity(intent); } }); builder.create().show(); } new GPSThread(this).start(); lv.setAdapter(adapter); }
From source file:com.urs.triptracks.TripUploader.java
private JSONObject getUserJSON() throws JSONException { JSONObject user = new JSONObject(); Map<String, Integer> fieldMap = new HashMap<String, Integer>(); //HS-fieldMap.put(USER_AGE, new Integer(UserInfoActivity.PREF_AGE));//Use Integer.valueOf(UserInfoActivity.PREF_AGE) instead //fieldMap.put(USER_EMAIL, new Integer(UserInfoActivity.PREF_EMAIL)); //Use Integer.valueOf(UserInfoActivity.PREF_AGE) instead fieldMap.put(USER_GENDER, Integer.valueOf(UserInfoActivity.PREF_GENDER)); fieldMap.put(USER_AGE, Integer.valueOf(UserInfoActivity.PREF_AGE)); /*fieldMap.put(USER_EMPLOYMENTSTATUS1, Integer.valueOf(UserInfoActivity.PREF_EMPLOYMENTSTATUS1)); fieldMap.put(USER_EMPLOYMENTSTATUS2, Integer.valueOf(UserInfoActivity.PREF_EMPLOYMENTSTATUS2)); fieldMap.put(USER_EMPLOYMENTSTATUS3, Integer.valueOf(UserInfoActivity.PREF_EMPLOYMENTSTATUS3)); fieldMap.put(USER_EMPLOYMENTSTATUS4, Integer.valueOf(UserInfoActivity.PREF_EMPLOYMENTSTATUS4)); fieldMap.put(USER_EMPLOYMENTSTATUS5, Integer.valueOf(UserInfoActivity.PREF_EMPLOYMENTSTATUS5)); fieldMap.put(USER_EMPLOYMENTSTATUS6, Integer.valueOf(UserInfoActivity.PREF_EMPLOYMENTSTATUS6)); fieldMap.put(USER_EMPLOYMENTSTATUS7, Integer.valueOf(UserInfoActivity.PREF_EMPLOYMENTSTATUS7)); fieldMap.put(USER_EMPLOYMENTSTATUS8, Integer.valueOf(UserInfoActivity.PREF_EMPLOYMENTSTATUS8)); fieldMap.put(USER_DAYSWORKTRIP, Integer.valueOf(UserInfoActivity.PREF_DAYSWORKTRIP)); fieldMap.put(USER_STUDENT, Integer.valueOf(UserInfoActivity.PREF_STUDENT));*/ fieldMap.put(USER_STUDENTLEVEL, Integer.valueOf(UserInfoActivity.PREF_STUDENTLEVEL)); //fieldMap.put(USER_VALIDDRIVERLIC, Integer.valueOf(UserInfoActivity.PREF_VALIDDRIVERLIC)); // fieldMap.put(USER_TRANSITPASS, Integer.valueOf(UserInfoActivity.PREF_TRANSITPASS)); //fieldMap.put(USER_DISABLEDPARKPASS, Integer.valueOf(UserInfoActivity.PREF_DISABLEDPARKPASS)); /* fieldMap.put(USER_ZIP_HOME, new Integer(UserInfoActivity.PREF_ZIPHOME)); fieldMap.put(USER_ZIP_WORK, new Integer(UserInfoActivity.PREF_ZIPWORK)); fieldMap.put(USER_ZIP_SCHOOL, new Integer(UserInfoActivity.PREF_ZIPSCHOOL));*/ SharedPreferences settings = this.mCtx.getSharedPreferences("PREFS", 0); for (Entry<String, Integer> entry : fieldMap.entrySet()) { user.put(entry.getKey(), settings.getString(entry.getValue().toString(), null)); }//from www . j a v a2 s.co m user.put(USER_EMPLOYMENTSTATUS1, settings.getInt("" + UserInfoActivity.PREF_EMPLOYMENTSTATUS1, 0)); user.put(USER_EMPLOYMENTSTATUS2, settings.getInt("" + UserInfoActivity.PREF_EMPLOYMENTSTATUS2, 0)); user.put(USER_EMPLOYMENTSTATUS3, settings.getInt("" + UserInfoActivity.PREF_EMPLOYMENTSTATUS3, 0)); user.put(USER_EMPLOYMENTSTATUS4, settings.getInt("" + UserInfoActivity.PREF_EMPLOYMENTSTATUS4, 0)); user.put(USER_EMPLOYMENTSTATUS5, settings.getInt("" + UserInfoActivity.PREF_EMPLOYMENTSTATUS5, 0)); user.put(USER_EMPLOYMENTSTATUS6, settings.getInt("" + UserInfoActivity.PREF_EMPLOYMENTSTATUS6, 0)); user.put(USER_EMPLOYMENTSTATUS7, settings.getInt("" + UserInfoActivity.PREF_EMPLOYMENTSTATUS7, 0)); user.put(USER_EMPLOYMENTSTATUS8, settings.getInt("" + UserInfoActivity.PREF_EMPLOYMENTSTATUS8, 0)); user.put(USER_DAYSWORKTRIP, settings.getInt("" + UserInfoActivity.PREF_DAYSWORKTRIP, 0)); user.put(USER_STUDENT, settings.getInt("" + UserInfoActivity.PREF_STUDENT, 0)); // user.put(USER_STUDENTLEVEL, settings.getInt(""+UserInfoActivity.PREF_STUDENTLEVEL, 0)); user.put(USER_VALIDDRIVERLIC, settings.getInt("" + UserInfoActivity.PREF_VALIDDRIVERLIC, 0)); user.put(USER_TRANSITPASS, settings.getInt("" + UserInfoActivity.PREF_TRANSITPASS, 0)); user.put(USER_DISABLEDPARKPASS, settings.getInt("" + UserInfoActivity.PREF_DISABLEDPARKPASS, 0)); user.put("device", getDeviceId()); //user.put(USER_CYCLING_FREQUENCY, Integer.parseInt(settings.getString(""+UserInfoActivity.PREF_CYCLEFREQ, "0"))/100); return user; }
From source file:org.xingjitong.ChatFragment.java
@SuppressLint("Recycle") @SuppressWarnings("static-access") @Override/* w ww. ja va 2 s . c om*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { SharedPreferences share = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (share.getInt(getString(R.string.setting_reg_uid), 0) == 0) { Toast.makeText(getActivity(), "!?,?!", Toast.LENGTH_LONG).show(); getActivity().getSupportFragmentManager().popBackStack(); } String displayName = getArguments().getString("DisplayName"); String pictureUri = getArguments().getString("PictureUri"); sipUri = getArguments().getString("SipUri"); sipUri = sipUri.substring(sipUri.indexOf(":") + 1, sipUri.indexOf("@")); try { LinphoneAddress address = LinphoneManager.getInstance().getLc().interpretUrl(sipUri); sipUri = address.asString(); sipUri = sipUri.replace("<", "").replace(">", ""); } catch (LinphoneCoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } view = inflater.inflate(R.layout.chat, container, false); contactName = (TextView) view.findViewById(R.id.contactName); contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture); sendMessage = (TextView) view.findViewById(R.id.sendMessage); sendMessage.setOnClickListener(this); message = (EditText) view.findViewById(R.id.message); if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) { message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE); message.setMaxLines(1); } uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout); textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout); messagesLayout = (RelativeLayout) view.findViewById(R.id.messages); messagesScrollView = (ScrollView) view.findViewById(R.id.chatScrollView); progressBar = (ProgressBar) view.findViewById(R.id.progressbar); sendImage = (TextView) view.findViewById(R.id.sendPicture); registerForContextMenu(sendImage); sendImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pickImage(); } }); cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload); cancelUpload.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { uploadThread.interrupt(); uploadLayout.setVisibility(View.GONE); textLayout.setVisibility(View.VISIBLE); progressBar.setProgress(0); } }); displayChat(displayName, pictureUri); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { chatRoom = lc.createChatRoom(sipUri); } // SharedPreferences prefs = // PreferenceManager.getDefaultSharedPreferences(LinphoneActivity.instance()); // uploadServerUri = // prefs.getString(getString(R.string.pref_image_sharing_server_key), // getString(R.string.pref_image_sharing_server_default)); uploadServerUri = getString(R.string.pref_image_sharing_server_default); textWatcher = new TextWatcher() { public void afterTextChanged(Editable arg0) { } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { if (message.getText().toString().equals("")) { sendMessage.setEnabled(false); } else { sendMessage.setEnabled(true); } } }; // Force hide keyboard if (LinphoneActivity.isInstanciated()) { InputMethodManager imm = (InputMethodManager) LinphoneActivity.instance() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } // Workaround for SGS3 issue if (savedInstanceState != null) { fileToUploadPath = savedInstanceState.getString("fileToUploadPath"); imageToUpload = savedInstanceState.getParcelable("imageToUpload"); } if (fileToUploadPath != null || imageToUpload != null) { sendImage.post(new Runnable() { @Override public void run() { sendImage.showContextMenu(); } }); } return view; }
From source file:com.ijsbrandslob.appirater.Appirater.java
private void loadSettings() { SharedPreferences settings = mContext.getSharedPreferences(mContext.getPackageName(), Context.MODE_PRIVATE); // Did we save settings before? if (settings.contains(APPIRATER_FIRST_USE_DATE)) { long firstUseDate = settings.getLong(APPIRATER_FIRST_USE_DATE, -1); if (-1 != firstUseDate) { mFirstUseDate = new Date(firstUseDate); } else {/*from w ww . j a v a 2 s .c o m*/ mFirstUseDate = new Date(); } long reminderRequestDate = settings.getLong(APPIRATER_REMINDER_REQUEST_DATE, -1); if (-1 != reminderRequestDate) mReminderRequestDate = new Date(reminderRequestDate); mUseCount = settings.getInt(APPIRATER_USE_COUNT, 0); mSignificantEventCount = settings.getInt(APPIRATER_SIG_EVENT_COUNT, 0); mCurrentVersion = settings.getString(APPIRATER_CURRENT_VERSION_NAME, NO_VERSION); if (mCurrentVersion == null || mCurrentVersion.equals("")) { mCurrentVersion = NO_VERSION; } mRatedCurrentVersion = settings.getBoolean(APPIRATER_RATED_CURRENT_VERSION, false); mDeclinedToRate = settings.getBoolean(APPIRATER_DECLINED_TO_RATE, false); } else { mCurrentVersion = appVersion(); mFirstUseDate = new Date(); if (mConfig.debug) System.out.println(String.format("APPIRATER Tracking version: %d", mCurrentVersion)); } if (newAppVersion()) resetTrackingForNewVersion(); saveSettings(); }
From source file:tw.com.sti.store.api.android.AndroidApiService.java
private AndroidApiService(Context context, Configuration config) { this.config = config; this.apiUrl = new ApiUrl(config); if (Logger.DEBUG) L.d("new ApiService()"); sdkVer = Build.VERSION.SDK;/*from w w w . j a va2 s .c o m*/ sdkRel = Build.VERSION.RELEASE; try { PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES); storeId = pi.packageName; clientVer = "" + pi.versionCode; } catch (NameNotFoundException e) { } TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); deviceId = tm.getDeviceId() == null ? "0" : tm.getDeviceId(); macAddress = NetworkUtils.getDeviceMacAddress(context); subscriberId = tm.getSubscriberId() == null ? "0" : tm.getSubscriberId(); simSerialNumber = tm.getSimSerialNumber() == null ? "0" : tm.getSimSerialNumber(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); try { Class<Display> cls = Display.class; Method method = cls.getMethod("getRotation"); Object retobj = method.invoke(display); int rotation = Integer.parseInt(retobj.toString()); if (Surface.ROTATION_0 == rotation || Surface.ROTATION_180 == rotation) { wpx = "" + display.getWidth(); hpx = "" + display.getHeight(); } else { wpx = "" + display.getHeight(); hpx = "" + display.getWidth(); } } catch (Exception e) { if (display.getOrientation() == 1) { wpx = "" + display.getHeight(); hpx = "" + display.getWidth(); } else { wpx = "" + display.getWidth(); hpx = "" + display.getHeight(); } } SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); // token = pref.getString(PREF_KEY_TOKEN, ""); // uid = pref.getString(PREF_KEY_UID, ""); // userId = pref.getString(PREF_KEY_USER_ID, ""); appFilter = pref.getInt(PREF_KEY_APP_FILTER, 0); // ipLoginEnable = pref.getBoolean(PREF_KEY_IP_LOGIN_ENABLE, true); // ??SIM? String pref_subscriberId = pref.getString(PREF_KEY_SUBSCRIBER_ID, "0"); String pref_simSerialNumber = pref.getString(PREF_KEY_SIM_SERIAL_NUMBER, "0"); if (!subscriberId.equals(pref_subscriberId) || !simSerialNumber.equals(pref_simSerialNumber)) { if (Logger.DEBUG) L.d("Change SIM card."); cleanCredential(context); } this.getCredential(context); }
From source file:com.android.kalite27.ScriptActivity.java
@SuppressLint("NewApi") @Override/*from w w w . jav a2 s .c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // mounted sdcard ? //if (!Environment.getExternalStorageState().equals("mounted")) { // Log.e(GlobalConstants.LOG_TAG, "External storage is not mounted"); // // Toast toast = Toast.makeText( getApplicationContext(), "External storage not mounted", Toast.LENGTH_LONG); // toast.show(); // return; //} mUtilities = new KaliteUtilities(); GlobalValues.initialize(this); gv = GlobalValues.getInstance(); // set the lauching ui setContentView(R.layout.activity_launching); startView = (RelativeLayout) findViewById(R.id.startView); retryButton = (Button) findViewById(R.id.buttonStart); spinner = (ProgressBar) findViewById(R.id.progressBar); webProgressBar = (ProgressBar) findViewById(R.id.webProgressBar); ServerStatusTextView = (TextView) findViewById(R.id.ServerStatus); FileTextView = (TextView) findViewById(R.id.FileDirectory); // check internet new InternetCheckAsyncTask().execute(); retryButton.setVisibility(View.INVISIBLE); // install needed ? boolean installNeeded = isInstallNeeded(); // first time running if (installNeeded) { // this will also call generate_local_settings after unzip library spinner.setVisibility(View.INVISIBLE); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setVisibility(View.VISIBLE); isGuideClosed = false; mViewPager.setAdapter(new GuidePagerAdapter()); mViewPager.setOnPageChangeListener(new GuidePageChangeListener()); new InstallAsyncTask().execute(); } else { contentPath = mUtilities.readContentPath(this); contentPath = contentPath.replaceAll("\n", ""); File contentFiles = new File(contentPath); if (contentFiles.exists()) { FileTextView.setText("Content Location: " + contentPath); FileTextView.setBackgroundColor(Color.parseColor("#A3CC7A")); runScriptService("start"); } else { // spinner.setVisibility(View.INVISIBLE); ServerStatusTextView.setText("Please set the content folder path first."); ServerStatusTextView.setTextColor(Color.parseColor("#FF9966")); // runScriptService("start"); } } wv = (XWalkView) findViewById(R.id.webview); wv.setVisibility(View.INVISIBLE); wv.setLayerType(View.LAYER_TYPE_HARDWARE, null); mCookieManager = new XWalkCookieManager(); mCookieManager.setAcceptCookie(true); mCookieManager.setAcceptFileSchemeCookies(true); wv.setResourceClient(new XWalkResourceClient(wv) { @Override public void onLoadStarted(XWalkView view, String url) { super.onLoadStarted(view, url); if (!isHeartViewClosed) { wv.getNavigationHistory().clear(); } } @Override public void onLoadFinished(XWalkView view, String url) { super.onLoadFinished(view, url); webProgressBar.setVisibility(View.INVISIBLE); if (url.equals("http://0.0.0.0:8008/") && isHomePageFirstTime) { isHomePageFirstTime = false; startView.setVisibility(View.GONE); view.setVisibility(View.VISIBLE); view.getNavigationHistory().clear(); } } @Override public void onProgressChanged(XWalkView view, int progress) { webProgressBar.setProgress(progress); if (progress > 99) { webProgressBar.setProgress(0); } } @Override public boolean shouldOverrideUrlLoading(XWalkView view, String url) { if (!isHomePageFirstTime) { webProgressBar.setVisibility(View.VISIBLE); } if (!isHeartViewClosed) { webProgressBar.setVisibility(View.VISIBLE); wv.getNavigationHistory().clear(); } if (url.startsWith("http://0.0.0.0:8008/api/control_panel/") && url.contains("format=csv")) { // dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); // String cookies = mCookieManager.getCookie(url); // Request request = new Request( // Uri.parse(url)); // request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) // .setTitle(csv_name) // .addRequestHeader("Cookie", cookies) // .setMimeType("text/csv") // .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, csv_name); // dm.enqueue(request); new DownloadFile().execute(url); return true; } return false; } }); XWalkPreferences.setValue("enable-javascript", true); XWalkPreferences.setValue(XWalkPreferences.JAVASCRIPT_CAN_OPEN_WINDOW, true); XWalkPreferences.setValue(XWalkPreferences.SUPPORT_MULTIPLE_WINDOWS, false); /* * !!! remember to disable REMOTE_DEBUGGING in production, it causes error message overflow */ if (GlobalConstants.IS_REMOTE_DEBUGGING) { XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true); } // new PreCacheAsyncTask().execute(); prefs = getSharedPreferences("MyPrefs", MODE_MULTI_PROCESS); editor = prefs.edit(); //clean kalite_command from before, we are not using SharedPreferences in conventional way. editor.clear(); editor.commit(); prefs_listener = new SharedPreferences.OnSharedPreferenceChangeListener() { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (prefs.getBoolean("from_process", false)) { editor.putBoolean("from_process", false); int server_status = prefs.getInt("python_exit_code", -7); String kalite_command = prefs.getString("kalite_command", "no command yet"); if (server_status == 0) { // 0 means the server is running isServerRunning = true; openWebViewIfAllConditionsMeet(); } else if (server_status != 0 && kalite_command.equals("start") || kalite_command.equals("restart")) { runScriptService("status"); } else if (kalite_command.equals("status")) { ServerStatusTextView.setText(mUtilities.exitCodeTranslate(server_status)); ServerStatusTextView.setTextColor(Color.parseColor("#FF9966")); spinner.setVisibility(View.INVISIBLE); retryButton.setVisibility(View.VISIBLE); } } } }; prefs.registerOnSharedPreferenceChangeListener(prefs_listener); }