Sample Page
This is an example page. It’s different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:
Hi there! I’m a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin’ caught in the rain.)
…or something like this:
Some example shortcakes:
[java]your code here[/java] [code lang=»php»]your code here[/code] [java autolinks=»false» classname=»myclass» collapse=»true» firstline=»1″ gutter=»true» highlight=»1-3,6,9″ htmlscript=»true» light=»false» padlinenumbers=»false» smarttabs=»true» tabsize=»4″ toolbar=»true» title=»Fragment Java»] package fragments;import android.app.Activity;
import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wmtech.tipocambio.R;
import java.text.DecimalFormat;
import java.util.ArrayList;
import config.Constant;
import config.Fecha;
import modelo.entTipoCambio;
import util.AlertDialogManager;
import util.DetectorConexion;
import util.JsonUtils;
public class FragmentHome extends Fragment {
public static final String ARG_ARTICLES_NUMBER = "articles_number";
public FragmentHome() {
//constructor vacio obligatorio
}
Activity act;
public DetectorConexion cn;
ArrayList<entTipoCambio> hoyarray;
TextView txtcompra, txtventa, txtestado;
AlertDialogManager alert = new AlertDialogManager();
String strfecha="";
//1.- iniciamos sharedpref para SET y GET
public SharedPreferences prefs;
DecimalFormat df;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
act = getActivity();
df=new DecimalFormat("#0.00");
//para mostrar un subtitulo con la fecha de la ultima actualizacion.
strfecha = Fecha.mostrarFechayHora();
((AppCompatActivity) act).getSupportActionBar().setSubtitle(Html.fromHtml("<small><font color=’#FFFFFF’>"
+ "Actualizado: " + strfecha+"</font></small>"));//"Actualizado: "+strfecha+" "+hora);
cn = new DetectorConexion(act);
//2.- se agrega para guardar las datos en una session
prefs = act.getSharedPreferences("tipocambio", 0);
hoyarray = new ArrayList<entTipoCambio>();
txtcompra = (TextView) rootView.findViewById(R.id.txtCompra);
txtventa = (TextView) rootView.findViewById(R.id.txtVenta);
txtestado = (TextView) rootView.findViewById(R.id.txtEstadoDolar);
//mostrar el tipo de cambio de ayer y si subio o bajo
if(!prefs.getString("acompra","").equals("")){
double resultado=0.0;
double compraayer = Double.parseDouble(prefs.getString("acompra", ""));
double comprahoy = Double.parseDouble(prefs.getString("compra", ""));
if(comprahoy>compraayer){
double resta = comprahoy-compraayer ;
resultado = resta*100/comprahoy;
txtestado.setText("Dólar subio "+df.format(resta)+" ("+String.valueOf(df.format(resultado))+"%), Ayer Compra: "+compraayer);
}else if(comprahoy<compraayer){
double resta = compraayer-comprahoy ;
resultado = resta*100/compraayer;
txtestado.setText("Dólar bajo "+df.format(resta)+" ("+String.valueOf(df.format(resultado))+"%), Ayer Compra: "+compraayer);
}else{
txtestado.setText("Dólar Sigue igual ("+String.valueOf(df.format(resultado))+"%), Ayer Compra: "+compraayer);
}
}
//llenar tipo cambio compra y venta
if(!prefs.getString("dia","").equals("")){
//4.- esto sirve para saber si por alguna razon el mes actual no tenga ningun tipo cambio
//entonces muestra el ultimo dia que se visualizo en la app.
txtcompra.setText(prefs.getString("compra","").toString());
txtventa.setText(prefs.getString("venta", "").toString());
}
if(cn.estaConectadoInternet()){
new loadHoyTask().execute(Constant.JSON_HOY);
}else{
showToast(getString(R.string.conne_msg1));
alert.showAlertDialog(act, getString(R.string.conne_msg2), getString(R.string.conne_msg3), false);
}
return rootView;
}
private class loadHoyTask extends AsyncTask<String, Void, String> {
ProgressDialog pDialog;
@Override
protected String doInBackground(String… params) {
return JsonUtils.getJSONString(params[0]);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(act);
pDialog.setMessage(getString(R.string.loading));
pDialog.setCancelable(false);
//pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDialog.show();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (null != pDialog && pDialog.isShowing()) {
pDialog.dismiss();
}
if (null == result || result.length() == 0) {
showToast(getString(R.string.conne_msg4));
alert.showAlertDialog(act, getString(R.string.conne_msg4), getString(R.string.conne_msg5), false);
} else {
try {
JSONObject mainJson = new JSONObject(result);
if(mainJson.has("Error")){
String error = mainJson.getString("Error");
Toast.makeText(act,error.toString(),Toast.LENGTH_LONG).show();
}
JSONArray jsonArray = mainJson.getJSONArray("hoy");
if(jsonArray!=null) {
JSONObject objJson = null;
for (int i = 0; i < jsonArray.length(); i++) {
objJson = jsonArray.getJSONObject(i);
//esto solo es dable cuando biene un solo objeto en la lista -_-
String dia = String.valueOf(objJson.getInt("id"));
txtcompra.setText(String.valueOf(objJson.getDouble("compra")));
txtventa.setText(String.valueOf(objJson.getDouble("venta")));
//3.- agregamos dia, compra, venta a session
prefs.edit().putString("dia", dia).commit();
prefs.edit().putString("compra", txtcompra.getText().toString()).commit();
prefs.edit().putString("venta", txtventa.getText().toString()).commit();
//fin
}
}
//metodo para sacar el tipo de cambio de ayer
JSONArray arrayAyer = mainJson.getJSONArray("ayer");
if(arrayAyer!=null){
JSONObject objson = null;
for (int i = 0; i < arrayAyer.length(); i++) {
objson = arrayAyer.getJSONObject(i);
prefs.edit().putString("acompra", String.valueOf(objson.getDouble("compra"))).commit();
//Por ahora solo se esta usando el ayer venta en el Widget
prefs.edit().putString("aventa", String.valueOf(objson.getDouble("venta"))).commit();
}
}
//esto es para llenar el textview si dolar subio o bajo
if(!prefs.getString("acompra","").equals("")&&!prefs.getString("aventa","").equals("")){
double resultado=0.0;
double compraayer = Double.parseDouble(prefs.getString("acompra", ""));
double comprahoy = Double.parseDouble(prefs.getString("compra", ""));
if(comprahoy>compraayer){
double resta = comprahoy-compraayer ;
resultado = resta*100/comprahoy;
txtestado.setText("Dólar subio "+df.format(resta)+" ("+String.valueOf(df.format(resultado))+"%), Ayer Compra: "+compraayer);
}else if(comprahoy<compraayer){
double resta = compraayer-comprahoy ;
resultado = resta*100/compraayer;
txtestado.setText("Dólar bajo "+df.format(resta)+" ("+String.valueOf(df.format(resultado))+"%), Ayer Compra: "+compraayer);
}else{
txtestado.setText("Dólar Sigue igual ("+String.valueOf(df.format(resultado))+"%), Ayer Compra: "+compraayer);
}
}
} catch (JSONException e) {
Toast.makeText(act,e.toString(),Toast.LENGTH_LONG).show();// e.printStackTrace();
}catch (Exception ej){
Toast.makeText(act,ej.toString(),Toast.LENGTH_LONG).show();// ej.printStackTrace();
}
}
}
}
public void showToast(String msg) {
Toast.makeText(act, msg, Toast.LENGTH_LONG).show();
}
//———————SE AGREGA UN MENU PARA ESTE FRAGMENTO ———–
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_main, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.About){
if(cn.estaConectadoInternet()){
new loadHoyTask().execute(Constant.JSON_HOY);
((AppCompatActivity) act).getSupportActionBar().setSubtitle(Html.fromHtml("<small><font color=’#FFFFFF’>" + "Actualizado: " + strfecha + "</font></small>"));
}else{
showToast(getString(R.string.conne_msg1));
alert.showAlertDialog(act, getString(R.string.conne_msg2), getString(R.string.conne_msg3), false);
}
Toast.makeText(act,"Menu About",Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
//———————FIN MENU PARA ESTE FRAGMENTO ———–
}
[/java]
The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.
[java firstline=»19″] List<String> list = new ArrayList<String>();
String hola ="sudo apt-get";
list.add("hola"); [/java]
As a new WordPress user, you should go to your dashboard to delete this page and create new pages for your content. Have fun!
[java highlight=»2-5,9″]List<String> list = new ArrayList<String>();
String hola ="sudo apt-get";
<pre>list.add("hola");
<pre>list.add("hola");
<pre>list.add("hola");
<pre>list.add("hola");
<pre>list.add("hola");
<pre>list.add("hola");
<pre>list.add("hola");
<pre>list.add("hola");
<pre>list.add("hola");
<pre>list.add("hola");
[/java]