Advertisement
Guest User

Java1

a guest
Jul 28th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.30 KB | None | 0 0
  1. package com.hwready.app;
  2.  
  3. import android.app.*;
  4. import android.os.*;
  5. import android.view.*;
  6. import android.view.View.*;
  7. import android.widget.*;
  8. import android.content.*;
  9. import android.content.ClipboardManager;
  10. import android.graphics.*;
  11. import android.media.*;
  12. import android.net.*;
  13. import android.text.*;
  14. import android.util.*;
  15. import android.webkit.*;
  16. import java.util.*;
  17. import java.text.*;
  18.  
  19.  
  20.  
  21. public class MainActivity extends Activity {
  22.  
  23.  
  24.  
  25.  
  26.     private Intent webviewActivity = new Intent();
  27.  
  28.  
  29.     @Override
  30.     protected void onCreate(Bundle savedInstanceState) {
  31.         super.onCreate(savedInstanceState);
  32.         setContentView(R.layout.main);
  33.         initialize();
  34.         initializeLogic();
  35.     }
  36.  
  37.     private void  initialize() {
  38.  
  39.  
  40.  
  41.  
  42.     }
  43.  
  44.     private void  initializeLogic() {
  45.         webviewActivity.setClass(getApplicationContext(), WebviewActivity.class);
  46.         startActivity(webviewActivity);
  47.     }
  48.  
  49.  
  50.  
  51.  
  52.     // created automatically
  53.     private void showMessage(String _s) {
  54.         Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
  55.     }
  56.  
  57.     private int getRandom(int _minValue ,int _maxValue){
  58.         Random random = new Random();
  59.         return random.nextInt(_maxValue - _minValue + 1) + _minValue;
  60.     }
  61.  
  62.     public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
  63.         ArrayList<Double> _result = new ArrayList<Double>();
  64.         SparseBooleanArray _arr = _list.getCheckedItemPositions();
  65.         for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
  66.             if (_arr.valueAt(_iIdx))
  67.                 _result.add((double)_arr.keyAt(_iIdx));
  68.         }
  69.         return _result;
  70.     }
  71.  
  72. }
  73. package com.hwready.app;
  74.  
  75. import android.app.*;
  76. import android.os.*;
  77. import android.view.*;
  78. import android.view.View.*;
  79. import android.widget.*;
  80. import android.content.*;
  81. import android.content.ClipboardManager;
  82. import android.graphics.*;
  83. import android.media.*;
  84. import android.net.*;
  85. import android.text.*;
  86. import android.util.*;
  87. import android.webkit.*;
  88. import java.util.*;
  89. import java.text.*;
  90.  
  91.  
  92.  
  93. public class WebviewActivity extends Activity {
  94.  
  95.     private Switch switch1;
  96.     private WebView webview2;
  97.  
  98.  
  99.     private ArrayList<String> sites = new ArrayList<String>();
  100.  
  101.     private Intent calculator = new Intent();
  102.  
  103.  
  104.     @Override
  105.     protected void onCreate(Bundle savedInstanceState) {
  106.         super.onCreate(savedInstanceState);
  107.         setContentView(R.layout.webview);
  108.         initialize();
  109.         initializeLogic();
  110.     }
  111.  
  112.     private void  initialize() {
  113.         switch1 = (Switch) findViewById(R.id.switch1);
  114.         webview2 = (WebView) findViewById(R.id.webview2);
  115.         webview2.getSettings().setJavaScriptEnabled(true);
  116.         webview2.getSettings().setSupportZoom(true);
  117.         webview2.setWebViewClient(new WebViewClient() {
  118.             @Override
  119.             public void onPageStarted(WebView _view,final String _url, Bitmap _favicon) {
  120.  
  121.                 super.onPageStarted(_view, _url, _favicon);
  122.             }
  123.             @Override
  124.             public void onPageFinished(WebView _view,final String _url) {
  125.  
  126.                 super.onPageFinished(_view, _url);
  127.             }
  128.         });
  129.  
  130.  
  131.  
  132.         switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  133.             @Override
  134.             public void onCheckedChanged(CompoundButton _buttonView, final boolean _isChecked)  {
  135.                 calculator.setClass(getApplicationContext(), CalculatorActivity.class);
  136.                 startActivity(calculator);
  137.             }
  138.         });
  139.  
  140.     }
  141.  
  142.     private void  initializeLogic() {
  143.         webview2.setVisibility(View.VISIBLE);
  144.         sites.add("http://www.hwready.it");
  145.         sites.add("https://www.amazon.it//ref=as_li_ss_tl?ie=UTF8&linkCode=ll2&tag=hwrandroid-21&linkId=9c2c07cbcd42df74096ca3a354d247e5");
  146.         sites.add("https://www.facebook.com/hwready/");
  147.         sites.add("https://m.youtube.com/channel/UCat_HI_nl3rQ8NQolhqnZiQ");
  148.         switch1.setChecked(false);
  149.     }
  150.  
  151.     @Override
  152.     protected void onPostCreate(Bundle _savedInstanceState) {
  153.         super.onPostCreate(_savedInstanceState);
  154.                 webview2.loadUrl("http://www.hwready.it");
  155.                 webview2.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
  156.     }
  157.  
  158.  
  159.  
  160.     // created automatically
  161.     private void showMessage(String _s) {
  162.         Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
  163.     }
  164.  
  165.     private int getRandom(int _minValue ,int _maxValue){
  166.         Random random = new Random();
  167.         return random.nextInt(_maxValue - _minValue + 1) + _minValue;
  168.     }
  169.  
  170.     public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
  171.         ArrayList<Double> _result = new ArrayList<Double>();
  172.         SparseBooleanArray _arr = _list.getCheckedItemPositions();
  173.         for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
  174.             if (_arr.valueAt(_iIdx))
  175.                 _result.add((double)_arr.keyAt(_iIdx));
  176.         }
  177.         return _result;
  178.     }
  179.  
  180. }
  181. package com.hwready.app;
  182.  
  183. import android.app.*;
  184. import android.os.*;
  185. import android.view.*;
  186. import android.view.View.*;
  187. import android.widget.*;
  188. import android.content.*;
  189. import android.content.ClipboardManager;
  190. import android.graphics.*;
  191. import android.media.*;
  192. import android.net.*;
  193. import android.text.*;
  194. import android.util.*;
  195. import android.webkit.*;
  196. import java.util.*;
  197. import java.text.*;
  198.  
  199.  
  200.  
  201. public class CalculatorActivity extends Activity {
  202.  
  203.     private TextView textview2;
  204.     private EditText edittext1;
  205.     private TextView textview3;
  206.     private CheckBox checkbox1;
  207.     private CheckBox checkbox2;
  208.     private CheckBox checkbox3;
  209.     private CheckBox checkbox4;
  210.     private Button button1;
  211.     private TextView textview4;
  212.     private TextView textview5;
  213.  
  214.     private String type = "";
  215.     private double finaltext = 0;
  216.  
  217.  
  218.     private Intent calculator = new Intent();
  219.  
  220.  
  221.     @Override
  222.     protected void onCreate(Bundle savedInstanceState) {
  223.         super.onCreate(savedInstanceState);
  224.         setContentView(R.layout.calculator);
  225.         initialize();
  226.         initializeLogic();
  227.     }
  228.  
  229.     private void  initialize() {
  230.         textview2 = (TextView) findViewById(R.id.textview2);
  231.         edittext1 = (EditText) findViewById(R.id.edittext1);
  232.         textview3 = (TextView) findViewById(R.id.textview3);
  233.         checkbox1 = (CheckBox) findViewById(R.id.checkbox1);
  234.         checkbox2 = (CheckBox) findViewById(R.id.checkbox2);
  235.         checkbox3 = (CheckBox) findViewById(R.id.checkbox3);
  236.         checkbox4 = (CheckBox) findViewById(R.id.checkbox4);
  237.         button1 = (Button) findViewById(R.id.button1);
  238.         textview4 = (TextView) findViewById(R.id.textview4);
  239.         textview5 = (TextView) findViewById(R.id.textview5);
  240.  
  241.  
  242.  
  243.         checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  244.             @Override
  245.             public void onCheckedChanged(CompoundButton _buttonView, final boolean _isChecked)  {
  246.                 checkbox1.setChecked(true);
  247.             }
  248.         });
  249.         checkbox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  250.             @Override
  251.             public void onCheckedChanged(CompoundButton _buttonView, final boolean _isChecked)  {
  252.                 checkbox2.setChecked(true);
  253.             }
  254.         });
  255.         checkbox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  256.             @Override
  257.             public void onCheckedChanged(CompoundButton _buttonView, final boolean _isChecked)  {
  258.                 checkbox3.setChecked(true);
  259.             }
  260.         });
  261.         checkbox4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  262.             @Override
  263.             public void onCheckedChanged(CompoundButton _buttonView, final boolean _isChecked)  {
  264.                 checkbox4.setChecked(true);
  265.             }
  266.         });
  267.         edittext1.addTextChangedListener(new TextWatcher() {
  268.             @Override
  269.             public void beforeTextChanged(CharSequence _text, int _start, int _count, int _after) {
  270.             }
  271.             @Override
  272.             public void onTextChanged(final CharSequence _charSeq, int _start, int _before, int _count) {
  273.                 type = edittext1.getText().toString();
  274.             }
  275.             @Override
  276.             public void afterTextChanged(Editable _text) {
  277.             }
  278.         });
  279.         button1.setOnClickListener(new View.OnClickListener() {
  280.             @Override
  281.             public void onClick(View _v) {
  282.                 if (checkbox1.isChecked()) {
  283.                     finaltext = Double.parseDouble(type) % 70;
  284.                     textview5.setText(String.valueOf(finaltext));
  285.                     if (checkbox2.isChecked()) {
  286.                         finaltext = Double.parseDouble(type) * 1.33d;
  287.                         textview5.setText(String.valueOf(finaltext));
  288.                         if (checkbox3.isChecked()) {
  289.                             finaltext = Double.parseDouble(type) * 1.20d;
  290.                             textview5.setText(String.valueOf(finaltext));
  291.                             if (checkbox4.isChecked()) {
  292.                                 finaltext = Double.parseDouble(type) * 1.13d;
  293.                                 textview5.setText(String.valueOf(finaltext));
  294.                             }
  295.                         }
  296.                     }
  297.                 }
  298.                 else {
  299.                     showMessage("Seleziona almeno una casella!");
  300.                 }
  301.             }
  302.         });
  303.  
  304.     }
  305.  
  306.     private void  initializeLogic() {
  307.         checkbox1.setChecked(false);
  308.         checkbox2.setChecked(false);
  309.         checkbox3.setChecked(false);
  310.         checkbox4.setChecked(false);
  311.     }
  312.  
  313.     @Override
  314.     public void onBackPressed() {
  315.                 finish();
  316.     }
  317.  
  318.  
  319.  
  320.     // created automatically
  321.     private void showMessage(String _s) {
  322.         Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
  323.     }
  324.  
  325.     private int getRandom(int _minValue ,int _maxValue){
  326.         Random random = new Random();
  327.         return random.nextInt(_maxValue - _minValue + 1) + _minValue;
  328.     }
  329.  
  330.     public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
  331.         ArrayList<Double> _result = new ArrayList<Double>();
  332.         SparseBooleanArray _arr = _list.getCheckedItemPositions();
  333.         for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
  334.             if (_arr.valueAt(_iIdx))
  335.                 _result.add((double)_arr.keyAt(_iIdx));
  336.         }
  337.         return _result;
  338.     }
  339.  
  340. }
  341. <LinearLayout
  342.     xmlns:android="http://schemas.android.com/apk/res/android"
  343.     android:layout_width="match_parent"
  344.     android:layout_height="match_parent"
  345.     android:orientation="vertical"
  346.     >
  347. </LinearLayout>
  348. <LinearLayout
  349.     xmlns:android="http://schemas.android.com/apk/res/android"
  350.     android:layout_width="match_parent"
  351.     android:layout_height="match_parent"
  352.     android:orientation="vertical"
  353.     >
  354.     <Switch
  355.         android:id="@+id/switch1"
  356.         android:layout_width="wrap_content"
  357.         android:layout_height="wrap_content"
  358.         android:padding="8dp"
  359.         android:text="Switch to calc"
  360.         android:textSize="12sp"
  361.         android:textColor="#000000"
  362.         />
  363.     <WebView
  364.         android:id="@+id/webview2"
  365.         android:layout_width="match_parent"
  366.         android:layout_height="match_parent"
  367.         />
  368. </LinearLayout>
  369. <LinearLayout
  370.     xmlns:android="http://schemas.android.com/apk/res/android"
  371.     android:layout_width="match_parent"
  372.     android:layout_height="match_parent"
  373.     android:orientation="vertical"
  374.     >
  375.     <TextView
  376.         android:id="@+id/textview2"
  377.         android:layout_width="wrap_content"
  378.         android:layout_height="wrap_content"
  379.         android:layout_marginTop="50dp"
  380.         android:padding="8dp"
  381.         android:gravity="left|right|top|bottom"
  382.         android:text="Calcolatrice per oggetti usati"
  383.         android:textSize="20sp"
  384.         android:textColor="#000000"
  385.         android:layout_gravity="center_horizontal"
  386.         />
  387.     <EditText
  388.         android:id="@+id/edittext1"
  389.         android:layout_width="wrap_content"
  390.         android:layout_height="wrap_content"
  391.         android:padding="8dp"
  392.         android:textSize="16sp"
  393.         android:textColor="#000000"
  394.         android:hint="Prezzo nuovo piú basso"
  395.         android:textColorHint="#607D8B"
  396.         android:lines="1"
  397.         android:inputType="numberDecimal"
  398.         android:layout_gravity="center_horizontal"
  399.         />
  400.     <TextView
  401.         android:id="@+id/textview3"
  402.         android:layout_width="wrap_content"
  403.         android:layout_height="wrap_content"
  404.         android:layout_marginTop="10dp"
  405.         android:padding="8dp"
  406.         android:text="Seleziona le caselle in base alla richiesta."
  407.         android:textSize="14sp"
  408.         android:textColor="#000000"
  409.         android:layout_gravity="center_horizontal"
  410.         />
  411.     <CheckBox
  412.         android:id="@+id/checkbox1"
  413.         android:layout_width="wrap_content"
  414.         android:layout_height="wrap_content"
  415.         android:padding="8dp"
  416.         android:text="È rotto\?"
  417.         android:textSize="12sp"
  418.         android:textColor="#000000"
  419.         android:layout_gravity="center_horizontal"
  420.         />
  421.     <CheckBox
  422.         android:id="@+id/checkbox2"
  423.         android:layout_width="wrap_content"
  424.         android:layout_height="wrap_content"
  425.         android:padding="8dp"
  426.         android:text="Ha la garanzia\?"
  427.         android:textSize="12sp"
  428.         android:textColor="#000000"
  429.         android:layout_gravity="center_horizontal"
  430.         />
  431.     <CheckBox
  432.         android:id="@+id/checkbox3"
  433.         android:layout_width="wrap_content"
  434.         android:layout_height="wrap_content"
  435.         android:padding="8dp"
  436.         android:text="Comprende il bundle\?"
  437.         android:textSize="12sp"
  438.         android:textColor="#000000"
  439.         android:layout_gravity="center_horizontal"
  440.         />
  441.     <CheckBox
  442.         android:id="@+id/checkbox4"
  443.         android:layout_width="wrap_content"
  444.         android:layout_height="wrap_content"
  445.         android:padding="8dp"
  446.         android:text="Ha segni d'usura\?"
  447.         android:textSize="12sp"
  448.         android:textColor="#000000"
  449.         android:layout_gravity="center_horizontal"
  450.         />
  451.     <Button
  452.         android:id="@+id/button1"
  453.         android:layout_width="wrap_content"
  454.         android:layout_height="wrap_content"
  455.         android:padding="8dp"
  456.         android:text="CALCOLA"
  457.         android:textSize="12sp"
  458.         android:textColor="#000000"
  459.         android:layout_gravity="center_horizontal"
  460.         />
  461.     <TextView
  462.         android:id="@+id/textview4"
  463.         android:layout_width="wrap_content"
  464.         android:layout_height="wrap_content"
  465.         android:layout_marginTop="20dp"
  466.         android:padding="8dp"
  467.         android:text="Prezzo calcolato:"
  468.         android:textSize="16sp"
  469.         android:textColor="#000000"
  470.         android:layout_gravity="center_horizontal"
  471.         />
  472.     <TextView
  473.         android:id="@+id/textview5"
  474.         android:layout_width="wrap_content"
  475.         android:layout_height="wrap_content"
  476.         android:padding="8dp"
  477.         android:textSize="16sp"
  478.         android:textColor="#000000"
  479.         android:layout_gravity="center_horizontal"
  480.         />
  481. </LinearLayout>
  482. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  483.         package="com.hwready.app">
  484.  
  485.     <uses-permission android:name="android.permission.INTERNET"/>
  486.  
  487.     <application android:allowBackup="true"
  488.         android:label="HWReady App"
  489.         android:icon="@drawable/app_icon"
  490.         android:name=".SketchApplication"
  491.         android:theme="@style/AppTheme">
  492.  
  493.             <activity
  494.                 android:name=".MainActivity"
  495.                 android:configChanges="orientation|screenSize"
  496.                 android:screenOrientation="portrait"
  497.                 >
  498.                 <intent-filter>
  499.                     <action android:name="android.intent.action.MAIN"/>
  500.                     <category android:name="android.intent.category.LAUNCHER"/>
  501.                 </intent-filter>
  502.             </activity>
  503.             <activity
  504.                 android:name=".WebviewActivity" android:configChanges="orientation|screenSize"
  505.                 android:screenOrientation="portrait" />
  506.             <activity
  507.                 android:name=".CalculatorActivity" android:configChanges="orientation|screenSize"
  508.                 android:screenOrientation="portrait" />
  509.             <activity android:name=".DebugActivity" android:screenOrientation="portrait"/>
  510.     </application>
  511.  
  512. </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement