/** * Name: begin Description: Instantiates the several components of the display and sets a listener * for the layout. */ @Override public void begin() { activity.setContentView(R.layout.activity_main); scoreView = (TextView) activity.findViewById(R.id.score); activity .findViewById(R.id.layout) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { activity.setInput(v); } }); grid = (GridView) activity.findViewById(R.id.gridView); grid.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { activity.setInput(view); } }); bird = BitmapFactory.decodeResource(activity.getResources(), R.drawable.bird); block = BitmapFactory.decodeResource(activity.getResources(), R.drawable.block); blank = BitmapFactory.decodeResource(activity.getResources(), R.drawable.blank); }
private VacancyModel parseVacancyInfo(String jsonResponceString) { VacancyModel model = new VacancyModel(); ArrayList<VacancyItemModel> data = new ArrayList<VacancyItemModel>(); try { JSONObject jObj = new JSONObject(jsonResponceString); JSONArray jItems = jObj.getJSONArray(JSON_PARAMETER_ITEMS); model.setPage(jObj.getInt(JSON_PARAMETER_PAGE)); model.setPages(jObj.getInt(JSON_PARAMETER_PAGES)); for (int i = 0; i < jItems.length(); i++) { JSONObject item = jItems.getJSONObject(i); VacancyItemModel modelItem = new VacancyItemModel(); modelItem.setId(item.getInt(JSON_PARAMETER_ID)); modelItem.setName(item.getString(JSON_PARAMETER_NAME)); modelItem.setUrl((item.getString(JSON_PARAMETER_URL))); PublisherItemModel publisher = new PublisherItemModel(); JSONObject jPublisher = item.getJSONObject(JSON_PARAMETER_EMPLOYER); publisher.setId(jPublisher.getInt(JSON_PARAMETER_ID)); publisher.setName(jPublisher.getString(JSON_PARAMETER_NAME)); SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT, activity.getResources().getConfiguration().locale); modelItem.setDate(formatter.parse(item.getString(JSON_PARAMETER_CREATED_AT))); JSONObject jIcons = jPublisher.optJSONObject(JSON_PARAMETER_LOGO); if (jIcons != null) { String iconUrl = jIcons.getString(JSON_PARAMETER_90); publisher.setIconUrl(iconUrl); } modelItem.setPublisher(publisher); data.add(modelItem); } } catch (Exception e) { e.printStackTrace(); } model.setItems(data); return model; }
@Override public void onFinishJsonDataDownload(JSONArray jArray) { if (jArray == null) { dispTwitterTrendInformation(m_activity.getResources().getString(R.string.getError)); return; } JSONObject json; try { StringBuilder builder = new StringBuilder(); json = jArray.getJSONObject(0); JSONArray trends = json.getJSONArray("trends"); for (int i = 0; i < trends.length(); i++) { JSONObject e = trends.getJSONObject(i); builder.append(e.getString("name")); builder.append("\n"); } dispTwitterTrendInformation(builder.toString()); } catch (JSONException e) { e.printStackTrace(); dispTwitterTrendInformation(m_activity.getResources().getString(R.string.getError)); } }
private VacancyModel getDataFormService(String searchText, String page) { try { HttpClient httpclient = new DefaultHttpClient(); ArrayList<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>(); parameters.add(new BasicNameValuePair(SERVICE_PARAMETER_TEXT, searchText)); if (page == "") { page = "0"; } Locale currentLocale = activity.getResources().getConfiguration().locale; parameters.add(new BasicNameValuePair(SERVICE_PARAMETER_PAGE, page)); parameters.add( new BasicNameValuePair( SERVICE_PARAMETER_LOCALE, currentLocale.getLanguage().toUpperCase(currentLocale))); String requestUrl = createRequestString(SERVICE_VACANCIES, parameters); HttpGet httpget = new HttpGet(requestUrl); HttpResponse response = httpclient.execute(httpget); String xmlString = EntityUtils.toString(response.getEntity()); return parseVacancyInfo(xmlString); } catch (Exception e) { e.printStackTrace(); } return new VacancyModel(); }
@Override public void onItemClick(AdapterView<?> list, View view, int position, long id) { final int index = position; AlertDialog.Builder builder = new AlertDialog.Builder(mParent); builder .setMessage( mParent.getResources().getString(mStore.get().getDescriptionId(index)) + "\n\nAmount Owned: " + mStore.get().getItemAmount(index)) .setTitle((mStore.get().getName(index))); builder.setNegativeButton( "Buy", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int num) { // buy the item at index mStore.get().BuyItem(index); ((TextView) mParent.findViewById(R.id.moneyAmount)) .setText(String.format("$ %.2f", mStore.get().getMoney())); } }); builder.setPositiveButton( "Sell", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int num) { // sell the item at index mStore.get().SellItem(index); ((TextView) mParent.findViewById(R.id.moneyAmount)) .setText(String.format("$ %.2f", mStore.get().getMoney())); } }); AlertDialog dialog = builder.create(); dialog.show(); }
/** * Creates the actual minesweeper board as well as all Boxes. Sets up certain boxes as mines. * * @param frame2 tablerow to hold board * @param x number of rows * @param y number of columns * @param mines number of mines * @param context context of activity */ public void createBoard(ViewGroup frame2, int x, int y, int mines, MainActivity context) { TableLayout frame = (TableLayout) frame2; this.context = context; this.context.minesRemaining.setText(Integer.toString(mines)); this.x = x; this.y = y; this.mines = mines; this.boxesFilled = 0; this.isGoing = false; this.isPaused = false; int minesCreated = 0; this.board = new Box[x][y]; for (int i = 0; i < this.x; ++i) { TableRow row = new TableRow(context); int height = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, (float) 48.0, context.getResources().getDisplayMetrics()); TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, height); params.gravity = Gravity.CENTER; params.setMargins(0, 0, 0, 0); row.setLayoutParams(params); row.setOrientation(0); int padding = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, (float) -2, context.getResources().getDisplayMetrics()); row.setPadding(padding, padding, padding, padding); for (int j = 0; j < this.y; ++j) { this.board[i][j] = new Box(this, context); final int localI = i; final int localJ = j; final MainActivity newcontext = context; this.board[i][j].setOnClickListener( new OnClickListener() { public void onClick(View v) { final int result; if (newcontext.flagMode == 1) { result = flagIt(localI, localJ); } else { result = hitIt(localI, localJ); } getResult(result); } }); row.addView(this.board[i][j]); } frame.addView(row); } // use a while loop for more randomness while (minesCreated < this.mines) { Random r = new Random(); int i = r.nextInt(this.x); int j = r.nextInt(this.y); double rando = (((this.mines - minesCreated) / ((this.x * this.y) - ((i * this.y) + j) * 1.0)) * 10); int surroundingMines = this.getSurrounding(i, j); int temp = r.nextInt(10 - (surroundingMines / 2)); if (rando >= temp && this.board[i][j].isMine() == 0) { this.board[i][j].makeMine(); this.addSurrounding(i, j); minesCreated++; } } /*for (int i = 0; i < this.x; ++i) { for (int j = 0; j < this.y; ++j) { Random r = new Random(); double rando = (((this.mines-minesCreated) / ((this.x*this.y)-((i * this.y) + j)*1.0)) * 10); int surroundingMines = this.getSurrounding(i, j); int temp = r.nextInt(10-surroundingMines); if (rando >= temp && minesCreated < this.mines) { this.board[i][j].makeMine(); this.addSurrounding(i, j); minesCreated++; } } }*/ // zoom in and out code final Minesweeper ms2 = this; ImageView zoomOutButton = (ImageView) context.findViewById(R.id.zoomout); zoomOutButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { ms2.resizeMe(1); } }); ImageView zoomInButton = (ImageView) context.findViewById(R.id.zoomin); zoomInButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { ms2.resizeMe(0); } }); context.flagButton.setImageDrawable(context.getResources().getDrawable(R.drawable.mine)); context.flagMode = 0; }
private void getJsonData() { m_activity.getTextView().setText(""); JsonDataDownloadAsyncTask task = new JsonDataDownloadAsyncTask(); task.setOnJsonDataDownloadListener(this); task.execute(m_activity.getResources().getString(R.string.url)); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate base layout ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_transactions, container, false); mMainView = view; mListView = (ListView) view.findViewById(android.R.id.list); // Inflate header (which contains account balance) mListHeader = (ViewGroup) inflater.inflate(R.layout.fragment_transactions_header, null, false); mListHeaderContainer = new FrameLayout(mParent); setHeaderPinned(true); mListView.addHeaderView(mListHeaderContainer); mListView.setOnScrollListener(new TransactionsInfiniteScrollListener()); mBalanceText = (TextView) mListHeader.findViewById(R.id.wallet_balance); mBalanceCurrency = (TextView) mListHeader.findViewById(R.id.wallet_balance_currency); mBalanceHome = (TextView) mListHeader.findViewById(R.id.wallet_balance_home); mAccount = (TextView) mListHeader.findViewById(R.id.wallet_account); mSyncErrorView = (TextView) mListHeader.findViewById(R.id.wallet_error); mAccount.setText(LoginManager.getInstance().getSelectedAccountName(mParent)); // Load old balance SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mParent); int activeAccount = prefs.getInt(Constants.KEY_ACTIVE_ACCOUNT, -1); String oldBalance = prefs.getString(String.format(Constants.KEY_ACCOUNT_BALANCE, activeAccount), null); String oldCurrency = prefs.getString(String.format(Constants.KEY_ACCOUNT_BALANCE_CURRENCY, activeAccount), null); String oldHomeBalance = prefs.getString(String.format(Constants.KEY_ACCOUNT_BALANCE_HOME, activeAccount), null); String oldHomeCurrency = prefs.getString( String.format(Constants.KEY_ACCOUNT_BALANCE_HOME_CURRENCY, activeAccount), null); if (oldBalance != null) { mBalanceText.setText(oldBalance); mBalanceCurrency.setText(oldCurrency); mBalanceText.setTextColor(mParent.getResources().getColor(R.color.wallet_balance_color)); mBalanceHome.setText( String.format( mParent.getString(R.string.wallet_balance_home), oldHomeBalance, oldHomeCurrency)); } if (mBalanceLoading) { mBalanceText.setTextColor( mParent.getResources().getColor(R.color.wallet_balance_color_invalid)); } view.findViewById(R.id.wallet_send) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mParent.openTransferMenu(false); } }); view.findViewById(R.id.wallet_request) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mParent.openTransferMenu(true); } }); // Load transaction list loadTransactionsList(); return view; }