public SpectrumPlot(double[] periods) { Application app = Application.getInstance(); if (app.isUseFrequencies()) { xValues = new double[periods.length]; for (int i = 0; i < periods.length; ++i) { xValues[xValues.length - i - 1] = 1 / periods[i]; } } else { xValues = periods; } this.reference1 = readReference(Application.PropertySpecRef1); this.reference2 = readReference(Application.PropertySpecRef2); this.logScale = Application.getInstance().getProperty(Application.PropertySpecLogScale, false); // this.setBackground(BackgroundColor); }
/** Clear list of status presets. */ public void clearSavedStatuses() { savedStatuses.clear(); Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { StatusTable.getInstance().clear(); } }); }
/** * Remove status from presets. * * @param statusMode * @param statusText */ public void removeSavedStatus(final SavedStatus savedStatus) { if (!savedStatuses.remove(savedStatus)) return; Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { StatusTable.getInstance() .remove(savedStatus.getStatusMode(), savedStatus.getStatusText()); } }); }
private void logoutUser() { JSONObject jsonObject = new JSONObject(); jsonObject.put("cmd", "logoutUser"); try { Application.getInstance().getConnection().sendData(jsonObject); } catch (Exception ex) { } if (this.user != null) { this.user.dispose(); this.user = null; } }
public void onAccountsChanged(final Collection<String> accounts) { Application.getInstance() .runOnUiThread( new Runnable() { @Override public void run() { for (OnAccountChangedListener accountListener : Application.getInstance().getUIListeners(OnAccountChangedListener.class)) accountListener.onAccountsChanged(accounts); } }); }
/** * Save status in presets. * * @param statusMode * @param statusText */ private void addSavedStatus(final StatusMode statusMode, final String statusText) { SavedStatus savedStatus = new SavedStatus(statusMode, statusText); if (savedStatuses.contains(savedStatus)) return; savedStatuses.add(savedStatus); Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { StatusTable.getInstance().write(statusMode, statusText); } }); }
private AccountManager() { this.application = Application.getInstance(); accountItems = new HashMap<String, AccountItem>(); enabledAccounts = new HashSet<String>(); savedStatuses = new ArrayList<SavedStatus>(); authorizationErrorProvider = new BaseAccountNotificationProvider<AccountAuthorizationError>( R.drawable.ic_stat_auth_failed); passwordRequestProvider = new BaseAccountNotificationProvider<PasswordRequest>(R.drawable.ic_stat_request); TypedArray accountAvatars = application.getResources().obtainTypedArray(R.array.account_avatars); colors = accountAvatars.length(); accountAvatars.recycle(); TypedArray types = application.getResources().obtainTypedArray(R.array.account_types); accountTypes = new ArrayList<AccountType>(); for (int index = 0; index < types.length(); index++) { int id = types.getResourceId(index, 0); TypedArray values = application.getResources().obtainTypedArray(id); AccountProtocol protocol = AccountProtocol.valueOf(values.getString(0)); if (Application.SDK_INT < 8 && protocol == AccountProtocol.wlm) { values.recycle(); continue; } ArrayList<String> servers = new ArrayList<String>(); servers.add(values.getString(9)); for (int i = 10; i < values.length(); i++) servers.add(values.getString(i)); accountTypes.add( new AccountType( id, protocol, values.getString(1), values.getString(2), values.getString(3), values.getDrawable(4), values.getBoolean(5, false), values.getString(6), values.getInt(7, 5222), values.getBoolean(8, false), servers)); values.recycle(); } types.recycle(); away = false; xa = false; }
private List<Double> readReference(String key) { List<Double> refs = new ArrayList(); String[] values = Application.getInstance().getProperty(key, "").split(","); for (String v : values) { if (refs.size() >= xValues.length) { LOG.warn("more reference values than periods specified in parameter: " + key); break; } refs.add(Double.parseDouble(v)); } if (!refs.isEmpty() && refs.size() < xValues.length) { LOG.warn("fewer reference values than periods specified in parameter: " + key); } return refs; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Application.getInstance().setAppContext(getApplicationContext()); uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.movie); handler = new Handler(); actionbarSize = (int) (getResources().getDimension(R.dimen.action_bar_size) * Resources.getSystem().getDisplayMetrics().density); ButterKnife.bind(this); setupToolbar(); setupVideoList(); if (savedInstanceState == null) { pendingIntroAnimation = true; } else { adapter.updateItems(false); } }
public void OpenFileToolbar() { JFileChooser fileChooser = new JFileChooser(); int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { opentFile(file.getPath()); Workspaces workspaces = Application.getInstance().getWorkspaces(); Map<String, Workspaces.ViewFrame> frames = workspaces.getOpenFrames(); Object[] objFrames = frames.values().toArray(); ViewFrame[] viewFrames = new ViewFrame[objFrames.length]; for (int i = 0; i < objFrames.length; i++) { viewFrames[i] = (ViewFrame) objFrames[i]; if (viewFrames[i].isSelected()) viewFrames[i].setTitle(file.getPath()); } } catch (Exception ex) { ex.printStackTrace(); } } }
@Override public void run() { View currentFocusedLayout = videoList.getLayoutManager().findViewByPosition(positionView); ImageView downloadView; CircularProgressBar progressView; try { downloadView = (ImageView) currentFocusedLayout.findViewById(R.id.ivFeedCenter); progressView = (CircularProgressBar) currentFocusedLayout.findViewById(R.id.video_progress_view); } catch (NullPointerException e) { Log.e(TAG, "NPE in PlayerUpdater"); return; } if (player != null) { player.stop(); player.release(); oldFocusedLayout.findViewById(R.id.ivFeedCenter).setVisibility(View.VISIBLE); oldFocusedLayout.findViewById(R.id.video_progress_view).setVisibility(View.GONE); } TextureView playerTextureView = (TextureView) currentFocusedLayout.findViewById(R.id.iv_feed_center_video); player = new MediaPlayer(); SurfaceTexture texture = playerTextureView.getSurfaceTexture(); Surface playerSurface = new Surface(texture); player.setSurface(playerSurface); try { player.setDataSource(Application.getInstance().getAppContext(), uri); player.prepare(); player.setLooping(true); } catch (IOException e) { Log.e(TAG, "IOException in PlayerUpdater"); } player.start(); downloadView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); currentVideoPos = positionView; oldFocusedLayout = currentFocusedLayout; }
@Override protected void paintComponent(Graphics g) { java.util.List<Network> networks = getNetworkParts(); positions = new int[networks.size()]; Graphics2D g2 = (Graphics2D) g; g2.setFont(SMALL_BOLD_FONT); g2.setPaint(addressGradientPaint); g2.fill(g2.getClipBounds()); // g2.drawImage(addressGradient, 0, 0, getWidth(), 26, null); int x = 14; for (int i = 0; i < networks.size(); i++) { Network part = networks.get(i); if (i == armed) { g2.setColor(TEXT_ARMED_COLOR); } else { g2.setColor(TEXT_NORMAL_COLOR); } String displayName = part.getDisplayName(); SwingUtils.drawShadowText(g2, displayName, x, 16); int width = (int) g2.getFontMetrics().stringWidth(displayName); x += width + 5; positions[i] = x + 10; g2.drawImage(addressArrow, x, 0, null); x += 15; } String version = Application.getInstance().getVersion(); int versionX = getWidth() - g2.getFontMetrics().stringWidth(version) - 10; SwingUtils.drawShadowText(g2, version, versionX, 16); if (renderException != null) { g2.drawImage(addressExclamation, versionX - 30, 0, null); } }
/** * Remove user`s account. Don't call any callbacks. * * @param account */ private void removeAccountWithoutCallback(final String account) { final AccountItem accountItem = getAccount(account); boolean wasEnabled = accountItem.isEnabled(); accountItem.setEnabled(false); accountItem.updateConnection(true); if (wasEnabled) { if (accountItem.getRawStatusMode().isOnline()) onAccountOffline(accountItem); onAccountDisabled(accountItem); } Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { AccountTable.getInstance().remove(account, accountItem.getId()); } }); accountItems.remove(account); enabledAccounts.remove(account); for (OnAccountRemovedListener listener : application.getManagers(OnAccountRemovedListener.class)) listener.onAccountRemoved(accountItem); removeAuthorizationError(account); }
private void loginUser(String userName, String password) throws Exception { JSONObject jsonObject = new JSONObject(); JSONObject paramsObject = new JSONObject(); jsonObject.put("cmd", "loginUser"); jsonObject.put("params", paramsObject); paramsObject.put("userName", userName); paramsObject.put("password", password); JSONObject responseObject = Application.getInstance().getConnection().sendDataAndWaitForResponse(jsonObject); if (responseObject != null) { JSONObject params = (JSONObject) responseObject.get("params"); if (params.get("status").equals("success")) { JSONObject userObject = (JSONObject) params.get("user"); User user = new User(); if (userObject.get("id") != null) user.setId(((Long) userObject.get("id")).intValue()); if (userObject.get("firstName") != null) user.setFirstName(String.valueOf(userObject.get("firstName"))); if (userObject.get("lastName") != null) user.setLastName(String.valueOf(userObject.get("lastName"))); if (userObject.get("userName") != null) user.setUserName(String.valueOf(userObject.get("userName"))); if (userObject.get("nickName") != null) user.setNickName(String.valueOf(userObject.get("nickName"))); if (userObject.get("password") != null) user.setPassword(String.valueOf(userObject.get("password"))); if (userObject.get("imageUrl") != null) user.setImageUrl(String.valueOf(userObject.get("imageUrl"))); if (userObject.get("elo") != null) user.setElo(((Long) userObject.get("elo")).intValue()); this.user = user; } else { throw new IOException(String.valueOf(params.get("errorMessage"))); } } else { throw new IOException("Error de conexión con el servidor"); } }
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Application application = Application.getInstance(); application.run(); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int width = getWidth() - Border.left - Border.right; int height = getHeight() - Border.top - Border.bottom; g2.translate(Border.left, Border.top); // create x and y axes g2.setColor(Color.black); g2.drawLine(0, height, width, height); g2.drawLine(0, 0, 0, height); g2.setFont(g2.getFont().deriveFont(10.0f)); FontMetrics fm = g2.getFontMetrics(); if (xValues.length == 0 || target == null || xValues[xValues.length - 1] <= 0) { return; } double factor; String yText; Application app = Application.getInstance(); Shaking.Type t = app.getSpectrumParameter(); if (t == Shaking.Type.PSA) { factor = Application.EarthAcceleration1; yText = t.toString().toUpperCase() + ", g"; } else if (t == Shaking.Type.DRS) { factor = 100; yText = t.toString().toUpperCase() + ", cm"; } else { LOG.warn("unsupported spectrum parameter: " + t.toString()); return; } synchronized (target) { // determine min/max of x and y axis double xMin; double xMax; double dx = 0; if (logScale) { xMin = Math.log10(xValues[0]); xMax = Math.log10(xValues[xValues.length - 1]); } else { xMin = 0.0; xMax = xValues[xValues.length - 1]; } if (xMax > xMin) { dx = (double) width / (xMax - xMin); } double yMin = 0; double yMax = 0; double dy = 0; boolean first = true; for (double v : reference1) { if (first) { first = false; /*yMin =*/ yMax = v; } /*yMin = Math.min(yMin, v);*/ yMax = Math.max(yMax, v); } for (double v : reference2) { if (first) { first = false; /*yMin =*/ yMax = v; } /*yMin = Math.min(yMin, v);*/ yMax = Math.max(yMax, v); } for (Shaking s : target.spectralValues) { if (first) { first = false; /*yMin =*/ yMax = s.expectedSI * factor; } else { /*yMin = Math.min(yMin, s.expectedSI * factor);*/ yMax = Math.max(yMax, s.expectedSI * factor); } /* yMin = Math.min(yMin, s.expectedSI * factor); yMin = Math.min(yMin, s.percentile84 * factor); yMin = Math.min(yMin, s.percentile16 * factor); */ yMax = Math.max(yMax, s.expectedSI * factor); yMax = Math.max(yMax, s.percentile84 * factor); yMax = Math.max(yMax, s.percentile16 * factor); } if (yMax > yMin) { dy = (double) height / (yMax - yMin); } List<Point> expectedPoints = new ArrayList(); List<Point> percentile84Points = new ArrayList(); List<Point> percentile16Points = new ArrayList(); List<Point> ref1Points = new ArrayList(); List<Point> ref2Points = new ArrayList(); int x, y, iV; boolean isFreq = app.isUseFrequencies(); for (int i = 0; i < xValues.length; i++) { if (logScale) { x = (int) ((Math.log10(xValues[i]) - xMin) / (xMax - xMin) * width); } else { x = (int) ((xValues[i] - xMin) / (xMax - xMin) * width); } iV = isFreq ? xValues.length - i - 1 : i; if (iV < target.spectralValues.size()) { Shaking s = target.spectralValues.get(iV); y = (int) ((yMax - s.expectedSI * factor) * dy); expectedPoints.add(new Point(x, y)); y = (int) ((yMax - s.percentile84 * factor) * dy); percentile84Points.add(new Point(x, y)); y = (int) ((yMax - s.percentile16 * factor) * dy); percentile16Points.add(new Point(x, y)); } if (iV < reference1.size()) { y = (int) ((yMax - reference1.get(iV)) * dy); ref1Points.add(new Point(x, y)); } if (iV < reference2.size()) { y = (int) ((yMax - reference2.get(iV)) * dy); ref2Points.add(new Point(x, y)); } } // Y-axis String text; int halfAscent = fm.getAscent() / 2 - 1; double q = Math.log10(2 * (yMax - yMin) * 2 * fm.getHeight() / height); double rx = q - Math.floor(q); int d = rx < 0.3 ? 1 : rx > 0.7 ? 5 : 2; double tickStep = d * Math.pow(10, Math.floor(q - rx)); for (double v = 0; v < yMax; v += tickStep) { y = height - (int) (v * dy) - 1; g2.drawLine(0, y, -TickLength, y); text = Double.toString(((int) (v * 1000.0 + 0.5)) / 1000.0); int w = (int) fm.getStringBounds(text, null).getWidth(); g2.drawString(text, -TickLength - 3 - w, y + halfAscent); } // X-axis q = Math.log10(2 * (xMax - xMin) * 50 / width); rx = q - Math.floor(q); d = rx < 0.3 ? 1 : rx > 0.7 ? 5 : 2; tickStep = d * Math.pow(10, Math.floor(q - rx)); for (double v = xMin; v < xMax; v += tickStep) { x = (int) ((v - xMin) * dx); g2.drawLine(x, height, x, height + TickLength); text = String.format("%.2f", logScale ? Math.pow(10, v) : v); // String text = Double.toString(logScale ? Math.pow(10, v) : v);//((int) (v * 1000.0 + // 0.5)) / 1000.0); int w = (int) fm.getStringBounds(text, null).getWidth(); g2.drawString(text, x - w / 2, height + TickLength + 3 + fm.getAscent()); } // axis label g2.setFont(g2.getFont().deriveFont(14.0f)); AffineTransform orig = g2.getTransform(); int w = (int) ((height + fm.getStringBounds(yText, null).getWidth()) / 2); g2.translate(-Border.left + fm.getAscent() + 7, w); g2.rotate(-Math.PI / 2); g2.drawString(yText, 0, 0); g2.setTransform(orig); text = "vibration " + (isFreq ? "frequency, Hz" : "period, s"); g2.drawString( text, (int) ((width - fm.getStringBounds(text, null).getWidth()) / 2), height + TickLength + 3 + 2 * fm.getHeight()); g2.setClip(0, 0, width, height); g2.setStroke(DefaultStroke); g2.setColor(Ref1Color); drawGraph(g2, ref1Points); g2.setColor(Ref2Color); drawGraph(g2, ref2Points); g2.setStroke(PercentileStroke); g2.setColor(ShakingColor); drawGraph(g2, percentile16Points); drawGraph(g2, percentile84Points); g2.setStroke(DefaultStroke); drawGraph(g2, expectedPoints); } }
@Override protected void onResume() { super.onResume(); Application.getInstance().trackScreenName("LoginActivity"); }
static { instance = new AccountManager(); Application.getInstance().addManager(instance); }
/** * Save account item to database. * * @param accountItem */ void requestToWriteAccount(final AccountItem accountItem) { final AccountProtocol protocol = accountItem.getConnectionSettings().getProtocol(); final boolean custom = accountItem.getConnectionSettings().isCustom(); final String host = accountItem.getConnectionSettings().getHost(); final int port = accountItem.getConnectionSettings().getPort(); final String serverName = accountItem.getConnectionSettings().getServerName(); final String userName = accountItem.getConnectionSettings().getUserName(); final String resource = accountItem.getConnectionSettings().getResource(); final boolean storePassword = accountItem.isStorePassword(); final String password = accountItem.getConnectionSettings().getPassword(); final int colorIndex = accountItem.getColorIndex(); final int priority = accountItem.getPriority(); final StatusMode statusMode = accountItem.getRawStatusMode(); final String statusText = accountItem.getStatusText(); final boolean enabled = accountItem.isEnabled(); final boolean saslEnabled = accountItem.getConnectionSettings().isSaslEnabled(); final TLSMode tlsMode = accountItem.getConnectionSettings().getTlsMode(); final boolean compression = accountItem.getConnectionSettings().useCompression(); final ProxyType proxyType = accountItem.getConnectionSettings().getProxyType(); final String proxyHost = accountItem.getConnectionSettings().getProxyHost(); final int proxyPort = accountItem.getConnectionSettings().getProxyPort(); final String proxyUser = accountItem.getConnectionSettings().getProxyUser(); final String proxyPassword = accountItem.getConnectionSettings().getProxyPassword(); final boolean syncable = accountItem.isSyncable(); final KeyPair keyPair = accountItem.getKeyPair(); final Date lastSync = accountItem.getLastSync(); final ArchiveMode archiveMode = accountItem.getArchiveMode(); Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { accountItem.setId( AccountTable.getInstance() .write( accountItem.getId(), protocol, custom, host, port, serverName, userName, resource, storePassword, password, colorIndex, priority, statusMode, statusText, enabled, saslEnabled, tlsMode, compression, proxyType, proxyHost, proxyPort, proxyUser, proxyPassword, syncable, keyPair, lastSync, archiveMode)); } }); }
@Override public void onLoad() { final Collection<SavedStatus> savedStatuses = new ArrayList<SavedStatus>(); final Collection<AccountItem> accountItems = new ArrayList<AccountItem>(); Cursor cursor = StatusTable.getInstance().list(); try { if (cursor.moveToFirst()) { do { savedStatuses.add( new SavedStatus( StatusTable.getStatusMode(cursor), StatusTable.getStatusText(cursor))); } while (cursor.moveToNext()); } } finally { cursor.close(); } cursor = AccountTable.getInstance().list(); try { if (cursor.moveToFirst()) { do { AccountItem accountItem = new AccountItem( AccountTable.getProtocol(cursor), AccountTable.isCustom(cursor), AccountTable.getHost(cursor), AccountTable.getPort(cursor), AccountTable.getServerName(cursor), AccountTable.getUserName(cursor), AccountTable.getResource(cursor), AccountTable.isStorePassword(cursor), AccountTable.getPassword(cursor), AccountTable.getColorIndex(cursor), AccountTable.getPriority(cursor), AccountTable.getStatusMode(cursor), AccountTable.getStatusText(cursor), AccountTable.isEnabled(cursor), AccountTable.isSaslEnabled(cursor), AccountTable.getTLSMode(cursor), AccountTable.isCompression(cursor), AccountTable.getProxyType(cursor), AccountTable.getProxyHost(cursor), AccountTable.getProxyPort(cursor), AccountTable.getProxyUser(cursor), AccountTable.getProxyPassword(cursor), AccountTable.isSyncable(cursor), AccountTable.getKeyPair(cursor), AccountTable.getLastSync(cursor), AccountTable.getArchiveMode(cursor)); accountItem.setId(AccountTable.getId(cursor)); accountItems.add(accountItem); } while (cursor.moveToNext()); } } finally { cursor.close(); } Application.getInstance() .runOnUiThread( new Runnable() { @Override public void run() { onLoaded(savedStatuses, accountItems); } }); }