protected ShowcaseView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Get the attributes for the ShowcaseView final TypedArray styled = context .getTheme() .obtainStyledAttributes( attrs, R.styleable.ShowcaseView, R.attr.showcaseViewStyle, R.style.ShowcaseView); mBackgroundColor = styled.getInt(R.styleable.ShowcaseView_sv_backgroundColor, Color.argb(128, 80, 80, 80)); int showcaseColor = styled.getColor(R.styleable.ShowcaseView_sv_showcaseColor, Color.parseColor("#33B5E5")); int titleTextAppearance = styled.getResourceId( R.styleable.ShowcaseView_sv_titleTextAppearance, R.style.TextAppearance_ShowcaseView_Title); int detailTextAppearance = styled.getResourceId( R.styleable.ShowcaseView_sv_detailTextAppearance, R.style.TextAppearance_ShowcaseView_Detail); mButtonText = styled.getString(R.styleable.ShowcaseView_sv_buttonText); styled.recycle(); mMetricScale = getContext().getResources().getDisplayMetrics().density; mEndButton = (Button) LayoutInflater.from(context).inflate(R.layout.showcase_button, null); mShowcaseDrawer = new ClingDrawerImpl(getResources(), showcaseColor); // TODO: This isn't ideal, ClingDrawer and Calculator interfaces should be separate mTextDrawer = new TextDrawerImpl(mMetricScale, mShowcaseDrawer); mTextDrawer.setTitleStyling(context, titleTextAppearance); mTextDrawer.setDetailStyling(context, detailTextAppearance); ConfigOptions options = new ConfigOptions(); options.showcaseId = getId(); setConfigOptions(options); init(); }
public ShowcaseView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Get the attributes for the ShowcaseView final TypedArray styled = context .getTheme() .obtainStyledAttributes( attrs, R.styleable.ShowcaseView, R.attr.showcaseViewStyle, R.style.ShowcaseView); backColor = styled.getInt(R.styleable.ShowcaseView_sv_backgroundColor, Color.argb(128, 80, 80, 80)); detailTextColor = styled.getColor(R.styleable.ShowcaseView_sv_detailTextColor, Color.WHITE); titleTextColor = styled.getColor(R.styleable.ShowcaseView_sv_titleTextColor, Color.parseColor("#49C0EC")); buttonText = styled.getString(R.styleable.ShowcaseView_sv_buttonText); styled.recycle(); metricScale = getContext().getResources().getDisplayMetrics().density; mEndButton = (Button) LayoutInflater.from(context).inflate(R.layout.showcase_button, null); ConfigOptions options = new ConfigOptions(); options.showcaseId = getId(); setConfigOptions(options); }
/** * Creates a dialog where the user can specify the location of the database,including the type of * network connection (if this is a networked client)and IP address and port number; or search and * select the database on a local drive if this is a standalone client. * * @param parent Defines the Component that is to be the parent of this dialog box. For * information on how this is used, see <code>JOptionPane</code> * @param connectionMode Specifies the type of connection (standalone or networked) * @see JOptionPane */ public DatabaseLocationDialog(Frame parent, ApplicationMode connectionMode) { configOptions = (new ConfigOptions(connectionMode)); configOptions.getObservable().addObserver(this); // load saved configuration SavedConfiguration config = SavedConfiguration.getSavedConfiguration(); // the port and connection type are irrelevant in standalone mode if (connectionMode == ApplicationMode.STANDALONE_CLIENT) { validPort = true; validCnx = true; networkType = ConnectionType.DIRECT; location = config.getParameter(SavedConfiguration.DATABASE_LOCATION); } else { // there may not be a network connectivity type defined and, if // not, we do not set a default - force the user to make a choice // the at least for the first time they run this. String tmp = config.getParameter(SavedConfiguration.NETWORK_TYPE); if (tmp != null) { try { networkType = ConnectionType.valueOf(tmp); configOptions.setNetworkConnection(networkType); validCnx = true; } catch (IllegalArgumentException e) { log.warning("Unknown connection type: " + networkType); } } // there is always at least a default port number, so we don't have // to validate this. port = config.getParameter(SavedConfiguration.SERVER_PORT); configOptions.setPortNumberText(port); validPort = true; location = config.getParameter(SavedConfiguration.SERVER_ADDRESS); } // there may not be a default database location, so we had better // validate before using the returned value. if (location != null) { configOptions.setLocationFieldText(location); validDb = true; } options = new JOptionPane(configOptions, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); connectButton.setActionCommand(CONNECT); connectButton.addActionListener(this); boolean allValid = validDb && validPort && validCnx; connectButton.setEnabled(allValid); exitButton.setActionCommand(EXIT); exitButton.addActionListener(this); options.setOptions(new Object[] {connectButton, exitButton}); dialog = options.createDialog(parent, TITLE); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(this); dialog.setVisible(true); }
/** * Callback method to process modifications in the common ConfigOptions panel. ConfigOptions was * developed to be common to many applications (even though we only have three modes), so it does * not have any knowledge of how we are using it within this dialog box. So ConfigOptions just * sends updates to registered Observers whenever anything changes. We can receive those * notifications here, and decide whether we have enough information to enable the "Connect" * button of the dialog box. */ public void update(Observable o, Object arg) { // we are going to ignore the Observable object, since we are only // observing one object. All we are interested in is the argument. if (!(arg instanceof OptionUpdate)) { log.log( Level.WARNING, "DatabaseLocationDialog received update type: " + arg, new IllegalArgumentException()); return; } OptionUpdate optionUpdate = (OptionUpdate) arg; // load saved configuration SavedConfiguration config = SavedConfiguration.getSavedConfiguration(); switch (optionUpdate.getUpdateType()) { case DB_LOCATION_CHANGED: location = (String) optionUpdate.getPayload(); if (configOptions.getApplicationMode() == ApplicationMode.STANDALONE_CLIENT) { File f = new File(location); if (f.exists() && f.canRead() && f.canWrite()) { validDb = true; log.info("File chosen " + location); config.setParameter(SavedConfiguration.DATABASE_LOCATION, location); } else { log.warning("Invalid file " + location); } } else { try { if (location.matches("\\d+\\.\\d+\\.\\d+\\.\\d+")) { // location given matches 4 '.' separated numbers // regex could be improved by limiting each quad to // no more than 3 digits. String[] quads = location.split("\\."); byte[] address = new byte[quads.length]; for (int i = 0; i < quads.length; i++) { address[i] = new Integer(quads[i]).byteValue(); } InetAddress.getByAddress(address); } else { InetAddress.getAllByName(location); } log.info("Server specified " + location); validDb = true; config.setParameter(SavedConfiguration.SERVER_ADDRESS, location); } catch (UnknownHostException uhe) { log.warning("Unknown host: " + location); validDb = false; } } break; case PORT_CHANGED: port = (String) optionUpdate.getPayload(); int p = Integer.parseInt(port); if (p >= LOWEST_PORT && p < HIGHEST_PORT) { if (p < SYSTEM_PORT_BOUNDARY) { log.info("User chose System port " + port); } else if (p < IANA_PORT_BOUNDARY) { log.info("User chose IANA port " + port); } else { log.info("User chose dynamic port " + port); } validPort = true; config.setParameter(SavedConfiguration.SERVER_PORT, port); } else { validPort = false; } break; case NETWORK_CHOICE_MADE: networkType = (ConnectionType) optionUpdate.getPayload(); switch (networkType) { case SOCKET: log.info("Server connection via Sockets"); break; case RMI: log.info("Server connection via RMI"); break; default: log.info("Unknown connection type: " + networkType); break; } config.setParameter(SavedConfiguration.NETWORK_TYPE, "" + networkType); validCnx = true; break; default: log.warning("Unknown update: " + optionUpdate); break; } boolean allValid = validDb && validPort && validCnx; connectButton.setEnabled(allValid); }
/** * Decide whether touches outside the showcased circle should be ignored or not * * @param block true to block touches, false otherwise. By default, this is true. * @deprecated Use the option in {@link ConfigOptions} instead. */ @Deprecated public void blockNonShowcasedTouches(boolean block) { mOptions.block = block; }
/** * Set the shot method of the showcase - only once or no limit * * @param shotType either TYPE_ONE_SHOT or TYPE_NO_LIMIT * @deprecated Use the option in {@link ConfigOptions} instead. */ @Deprecated public void setShotType(int shotType) { if (shotType == TYPE_NO_LIMIT || shotType == TYPE_ONE_SHOT) { mOptions.shotType = shotType; } }