Advertisement
Guest User

Untitled

a guest
Nov 8th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.15 KB | None | 0 0
  1. //app fo setting an alarm
  2.  
  3. activity.main.xml
  4. <?xml version="1.0" encoding="utf-8"?>
  5. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. android:orientation="vertical">
  9.  
  10. <TimePicker
  11. android:id="@+id/timePicker"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:layout_gravity="center" />
  15.  
  16. <ToggleButton
  17. android:id="@+id/toggleButton"
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:layout_gravity="center"
  21. android:layout_margin="20dp"
  22. android:checked="false"
  23. android:onClick="OnToggleClicked" />
  24.  
  25. </LinearLayout>
  26.  
  27. Mainactivity.java
  28.  
  29. package com.example.akshay.alarm;
  30.  
  31. import android.app.AlarmManager;
  32. import android.app.PendingIntent;
  33. import android.content.Intent;
  34. import android.os.Bundle;
  35. import android.support.v7.app.AppCompatActivity;
  36. import android.view.View;
  37. import android.widget.TimePicker;
  38. import android.widget.Toast;
  39. import android.widget.ToggleButton;
  40.  
  41. import java.util.Calendar;
  42.  
  43. public class MainActivity extends AppCompatActivity
  44. {
  45. TimePicker alarmTimePicker;
  46. PendingIntent pendingIntent;
  47. AlarmManager alarmManager;
  48.  
  49. @Override
  50. protected void onCreate(Bundle savedInstanceState)
  51. {
  52. super.onCreate(savedInstanceState);
  53. setContentView(R.layout.activity_main);
  54. alarmTimePicker = (TimePicker) findViewById(R.id.timePicker);
  55. alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
  56. }
  57. public void OnToggleClicked(View view)
  58. {
  59. long time;
  60. if (((ToggleButton) view).isChecked())
  61. {
  62. Toast.makeText(MainActivity.this, "ALARM ON", Toast.LENGTH_SHORT).show();
  63. Calendar calendar = Calendar.getInstance();
  64. calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());
  65. calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());
  66. Intent intent = new Intent(this, AlarmReceiver.class);
  67. pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
  68.  
  69. time=(calendar.getTimeInMillis()-(calendar.getTimeInMillis()%60000));
  70. if(System.currentTimeMillis()>time)
  71. {
  72. if (calendar.AM_PM == 0)
  73. time = time + (1000*60*60*12);
  74. else
  75. time = time + (1000*60*60*24);
  76. }
  77. alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 10000, pendingIntent);
  78. }
  79. else
  80. {
  81. alarmManager.cancel(pendingIntent);
  82. Toast.makeText(MainActivity.this, "ALARM OFF", Toast.LENGTH_SHORT).show();
  83. }
  84. }
  85. }
  86.  
  87. AlarmReciver.java
  88. package com.example.akshay.alarm;
  89.  
  90. import android.content.BroadcastReceiver;
  91. import android.content.Context;
  92. import android.content.Intent;
  93. import android.media.Ringtone;
  94. import android.media.RingtoneManager;
  95. import android.net.Uri;
  96. import android.widget.Toast;
  97.  
  98. public class AlarmReceiver extends BroadcastReceiver
  99. {
  100. @Override
  101. public void onReceive(Context context, Intent intent)
  102. {
  103. Toast.makeText(context, "Alarm! Wake up! Wake up!", Toast.LENGTH_LONG).show();
  104. Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
  105. if (alarmUri == null)
  106. {
  107. alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  108. }
  109. Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);
  110. ringtone.play();
  111. }
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. ////alert on recive a message
  121. activity.main.xml
  122. <?xml version="1.0" encoding="utf-8"?>
  123. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  124. android:layout_width="match_parent"
  125. android:layout_height="match_parent"
  126. android:layout_margin="10dp"
  127. android:orientation="vertical">
  128.  
  129. <TextView
  130. android:layout_width="wrap_content"
  131. android:layout_height="wrap_content"
  132. android:text="Message"
  133. android:textSize="30sp" />
  134.  
  135. <EditText
  136. android:id="@+id/editText"
  137. android:layout_width="match_parent"
  138. android:layout_height="wrap_content"
  139. android:singleLine="true"
  140. android:textSize="30sp" />
  141.  
  142. <Button
  143. android:id="@+id/button"
  144. android:layout_width="wrap_content"
  145. android:layout_height="wrap_content"
  146. android:layout_margin="30dp"
  147. android:layout_gravity="center"
  148. android:text="Notify"
  149. android:textSize="30sp"/>
  150.  
  151. </LinearLayout>
  152.  
  153.  
  154. Mainactivity.java
  155. package com.example.akshay.alarm;
  156.  
  157. import android.app.Notification;
  158. import android.app.NotificationManager;
  159. import android.app.PendingIntent;
  160. import android.content.Intent;
  161. import android.os.Bundle;
  162. import android.support.v7.app.AppCompatActivity;
  163. import android.view.View;
  164. import android.widget.Button;
  165. import android.widget.EditText;
  166.  
  167. public class MainActivity extends AppCompatActivity
  168. {
  169. Button notify;
  170. EditText e;
  171. @Override
  172. protected void onCreate(Bundle savedInstanceState)
  173. {
  174. super.onCreate(savedInstanceState);
  175. setContentView(R.layout.activity_main);
  176.  
  177. notify= (Button) findViewById(R.id.button);
  178. e= (EditText) findViewById(R.id.editText);
  179.  
  180. notify.setOnClickListener(new View.OnClickListener()
  181. {
  182. @Override
  183. public void onClick(View v)
  184. {
  185. Intent intent = new Intent(MainActivity.this, SecondActivity.class);
  186. PendingIntent pending = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
  187. Notification noti = new Notification.Builder(MainActivity.this).setContentTitle("New Message").setContentText(e.getText().toString()).setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pending).build();
  188. NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  189. noti.flags |= Notification.FLAG_AUTO_CANCEL;
  190. manager.notify(0, noti);
  191. }
  192. });
  193. }
  194. }
  195.  
  196. Then Go to file
  197. new>activity>emptyactivity
  198. name it as second activity
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208. //read and write data to sdcard
  209. Add the below line to android_mainfest.xml above the application tag
  210. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
  211.  
  212. activity_main.xml
  213. <?xml version="1.0" encoding="utf-8"?>
  214. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  215. android:layout_width="match_parent"
  216. android:layout_height="match_parent"
  217. android:layout_margin="20dp"
  218. android:orientation="vertical">
  219.  
  220. <EditText
  221. android:id="@+id/editText"
  222. android:layout_width="match_parent"
  223. android:layout_height="wrap_content"
  224. android:singleLine="true"
  225. android:textSize="30dp" />
  226.  
  227. <Button
  228. android:id="@+id/button"
  229. android:layout_width="match_parent"
  230. android:layout_height="wrap_content"
  231. android:layout_margin="10dp"
  232. android:text="Write Data"
  233. android:textSize="30dp" />
  234.  
  235. <Button
  236. android:id="@+id/button2"
  237. android:layout_width="match_parent"
  238. android:layout_height="wrap_content"
  239. android:layout_margin="10dp"
  240. android:text="Read data"
  241. android:textSize="30dp" />
  242.  
  243. <Button
  244. android:id="@+id/button3"
  245. android:layout_width="match_parent"
  246. android:layout_height="wrap_content"
  247. android:layout_margin="10dp"
  248. android:text="Clear"
  249. android:textSize="30dp" />
  250.  
  251. </LinearLayout>
  252.  
  253. Mainactivity.java
  254. package com.example.akshay.alarm;
  255. import android.os.Bundle;
  256. import android.support.v7.app.AppCompatActivity;
  257. import android.view.View;
  258. import android.widget.Button;
  259. import android.widget.EditText;
  260. import android.widget.Toast;
  261.  
  262. import java.io.BufferedReader;
  263. import java.io.File;
  264. import java.io.FileInputStream;
  265. import java.io.FileOutputStream;
  266. import java.io.InputStreamReader;
  267.  
  268. public class MainActivity extends AppCompatActivity
  269. {
  270. EditText e1;
  271. Button write,read,clear;
  272. @Override
  273. protected void onCreate(Bundle savedInstanceState)
  274. {
  275. super.onCreate(savedInstanceState);
  276. setContentView(R.layout.activity_main);
  277.  
  278. e1= (EditText) findViewById(R.id.editText);
  279. write= (Button) findViewById(R.id.button);
  280. read= (Button) findViewById(R.id.button2);
  281. clear= (Button) findViewById(R.id.button3);
  282.  
  283. write.setOnClickListener(new View.OnClickListener()
  284. {
  285. @Override
  286. public void onClick(View v)
  287. {
  288. String message=e1.getText().toString();
  289. try
  290. {
  291. File f=new File("/sdcard/myfile.txt");
  292. f.createNewFile();
  293. FileOutputStream fout=new FileOutputStream(f);
  294. fout.write(message.getBytes());
  295. fout.close();
  296. Toast.makeText(getBaseContext(),"Data Written in SDCARD",Toast.LENGTH_LONG).show();
  297. }
  298. catch (Exception e)
  299. {
  300. Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();
  301. }
  302. }
  303. });
  304.  
  305. read.setOnClickListener(new View.OnClickListener()
  306. {
  307. @Override
  308. public void onClick(View v)
  309. {
  310. String message;
  311. String buf = "";
  312. try
  313. {
  314. File f = new File("/sdcard/myfile.txt");
  315. FileInputStream fin = new FileInputStream(f);
  316. BufferedReader br = new BufferedReader(new InputStreamReader(fin));
  317. while ((message = br.readLine()) != null)
  318. {
  319. buf += message;
  320. }
  321. e1.setText(buf);
  322. br.close();
  323. fin.close();
  324. Toast.makeText(getBaseContext(),"Data Recived from SDCARD",Toast.LENGTH_LONG).show();
  325. }
  326. catch (Exception e)
  327. {
  328. Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
  329. }
  330. }
  331. });
  332.  
  333. clear.setOnClickListener(new View.OnClickListener()
  334. {
  335. @Override
  336. public void onClick(View v)
  337. {
  338. e1.setText("");
  339. }
  340. });
  341. }
  342. }
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352. ////tic-toc-toe game
  353. activity_main.xml
  354.  
  355. <?xml version="1.0" encoding="utf-8"?>
  356. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  357. xmlns:app="http://schemas.android.com/apk/res-auto"
  358. xmlns:tools="http://schemas.android.com/tools"
  359. android:layout_width="match_parent"
  360. android:layout_height="match_parent"
  361. android:orientation="vertical"
  362. tools:context="com.codinginflow.tictactoe.MainActivity">
  363.  
  364. <RelativeLayout
  365. android:layout_width="match_parent"
  366. android:layout_height="wrap_content">
  367.  
  368. <TextView
  369. android:id="@+id/text_view_p1"
  370. android:layout_width="wrap_content"
  371. android:layout_height="wrap_content"
  372. android:freezesText="true"
  373. android:text="Player 1: 0"
  374. android:textSize="30sp" />
  375.  
  376. <TextView
  377. android:id="@+id/text_view_p2"
  378. android:layout_width="wrap_content"
  379. android:layout_height="wrap_content"
  380. android:layout_below="@+id/text_view_p1"
  381. android:freezesText="true"
  382. android:text="Player 2: 0"
  383. android:textSize="30sp" />
  384.  
  385. <Button
  386. android:id="@+id/button_reset"
  387. android:layout_width="wrap_content"
  388. android:layout_height="wrap_content"
  389. android:layout_alignParentEnd="true"
  390. android:layout_centerVertical="true"
  391. android:layout_marginEnd="33dp"
  392. android:text="reset" />
  393.  
  394. </RelativeLayout>
  395.  
  396. <LinearLayout
  397. android:layout_width="match_parent"
  398. android:layout_height="0dp"
  399. android:layout_weight="1">
  400.  
  401. <Button
  402. android:id="@+id/button_00"
  403. android:layout_width="0dp"
  404. android:layout_height="match_parent"
  405. android:layout_weight="1"
  406. android:freezesText="true"
  407. android:textSize="60sp" />
  408.  
  409. <Button
  410. android:id="@+id/button_01"
  411. android:layout_width="0dp"
  412. android:layout_height="match_parent"
  413. android:layout_weight="1"
  414. android:freezesText="true"
  415. android:textSize="60sp" />
  416.  
  417. <Button
  418. android:id="@+id/button_02"
  419. android:layout_width="0dp"
  420. android:layout_height="match_parent"
  421. android:layout_weight="1"
  422. android:freezesText="true"
  423. android:textSize="60sp" />
  424.  
  425. </LinearLayout>
  426.  
  427. <LinearLayout
  428. android:layout_width="match_parent"
  429. android:layout_height="0dp"
  430. android:layout_weight="1">
  431.  
  432. <Button
  433. android:id="@+id/button_10"
  434. android:layout_width="0dp"
  435. android:layout_height="match_parent"
  436. android:layout_weight="1"
  437. android:freezesText="true"
  438. android:textSize="60sp" />
  439.  
  440. <Button
  441. android:id="@+id/button_11"
  442. android:layout_width="0dp"
  443. android:layout_height="match_parent"
  444. android:layout_weight="1"
  445. android:freezesText="true"
  446. android:textSize="60sp" />
  447.  
  448. <Button
  449. android:id="@+id/button_12"
  450. android:layout_width="0dp"
  451. android:layout_height="match_parent"
  452. android:layout_weight="1"
  453. android:freezesText="true"
  454. android:textSize="60sp" />
  455.  
  456. </LinearLayout>
  457.  
  458. <LinearLayout
  459. android:layout_width="match_parent"
  460. android:layout_height="0dp"
  461. android:layout_weight="1">
  462.  
  463. <Button
  464. android:id="@+id/button_20"
  465. android:layout_width="0dp"
  466. android:layout_height="match_parent"
  467. android:layout_weight="1"
  468. android:freezesText="true"
  469. android:textSize="60sp" />
  470.  
  471. <Button
  472. android:id="@+id/button_21"
  473. android:layout_width="0dp"
  474. android:layout_height="match_parent"
  475. android:layout_weight="1"
  476. android:freezesText="true"
  477. android:textSize="60sp" />
  478.  
  479. <Button
  480. android:id="@+id/button_22"
  481. android:layout_width="0dp"
  482. android:layout_height="match_parent"
  483. android:layout_weight="1"
  484. android:freezesText="true"
  485. android:textSize="60sp" />
  486.  
  487. </LinearLayout>
  488.  
  489. </LinearLayout>
  490.  
  491.  
  492. mainActivity.java
  493. package com.example.akshay.alarm;
  494.  
  495. import android.support.v7.app.AppCompatActivity;
  496. import android.os.Bundle;
  497. import android.view.View;
  498. import android.widget.Button;
  499. import android.widget.TextView;
  500. import android.widget.Toast;
  501.  
  502. public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  503.  
  504. private Button[][] buttons = new Button[3][3];
  505.  
  506. private boolean player1Turn = true;
  507.  
  508. private int roundCount;
  509.  
  510. private int player1Points;
  511. private int player2Points;
  512.  
  513. private TextView textViewPlayer1;
  514. private TextView textViewPlayer2;
  515.  
  516. @Override
  517. protected void onCreate(Bundle savedInstanceState) {
  518. super.onCreate(savedInstanceState);
  519. setContentView(R.layout.activity_main);
  520.  
  521. textViewPlayer1 = findViewById(R.id.text_view_p1);
  522. textViewPlayer2 = findViewById(R.id.text_view_p2);
  523.  
  524. for (int i = 0; i < 3; i++) {
  525. for (int j = 0; j < 3; j++) {
  526. String buttonID = "button_" + i + j;
  527. int resID = getResources().getIdentifier(buttonID, "id", getPackageName());
  528. buttons[i][j] = findViewById(resID);
  529. buttons[i][j].setOnClickListener(this);
  530. }
  531. }
  532.  
  533. Button buttonReset = findViewById(R.id.button_reset);
  534. buttonReset.setOnClickListener(new View.OnClickListener() {
  535. @Override
  536. public void onClick(View v) {
  537. resetGame();
  538. }
  539. });
  540. }
  541.  
  542. @Override
  543. public void onClick(View v) {
  544. if (!((Button) v).getText().toString().equals("")) {
  545. return;
  546. }
  547.  
  548. if (player1Turn) {
  549. ((Button) v).setText("X");
  550. } else {
  551. ((Button) v).setText("O");
  552. }
  553.  
  554. roundCount++;
  555.  
  556. if (checkForWin()) {
  557. if (player1Turn) {
  558. player1Wins();
  559. } else {
  560. player2Wins();
  561. }
  562. } else if (roundCount == 9) {
  563. draw();
  564. } else {
  565. player1Turn = !player1Turn;
  566. }
  567.  
  568. }
  569.  
  570. private boolean checkForWin() {
  571. String[][] field = new String[3][3];
  572.  
  573. for (int i = 0; i < 3; i++) {
  574. for (int j = 0; j < 3; j++) {
  575. field[i][j] = buttons[i][j].getText().toString();
  576. }
  577. }
  578.  
  579. for (int i = 0; i < 3; i++) {
  580. if (field[i][0].equals(field[i][1])
  581. && field[i][0].equals(field[i][2])
  582. && !field[i][0].equals("")) {
  583. return true;
  584. }
  585. }
  586.  
  587. for (int i = 0; i < 3; i++) {
  588. if (field[0][i].equals(field[1][i])
  589. && field[0][i].equals(field[2][i])
  590. && !field[0][i].equals("")) {
  591. return true;
  592. }
  593. }
  594.  
  595. if (field[0][0].equals(field[1][1])
  596. && field[0][0].equals(field[2][2])
  597. && !field[0][0].equals("")) {
  598. return true;
  599. }
  600.  
  601. if (field[0][2].equals(field[1][1])
  602. && field[0][2].equals(field[2][0])
  603. && !field[0][2].equals("")) {
  604. return true;
  605. }
  606.  
  607. return false;
  608. }
  609.  
  610. private void player1Wins() {
  611. player1Points++;
  612. Toast.makeText(this, "Player 1 wins!", Toast.LENGTH_SHORT).show();
  613. updatePointsText();
  614. resetBoard();
  615. }
  616.  
  617. private void player2Wins() {
  618. player2Points++;
  619. Toast.makeText(this, "Player 2 wins!", Toast.LENGTH_SHORT).show();
  620. updatePointsText();
  621. resetBoard();
  622. }
  623.  
  624. private void draw() {
  625. Toast.makeText(this, "Draw!", Toast.LENGTH_SHORT).show();
  626. resetBoard();
  627. }
  628.  
  629. private void updatePointsText() {
  630. textViewPlayer1.setText("Player 1: " + player1Points);
  631. textViewPlayer2.setText("Player 2: " + player2Points);
  632. }
  633.  
  634. private void resetBoard() {
  635. for (int i = 0; i < 3; i++) {
  636. for (int j = 0; j < 3; j++) {
  637. buttons[i][j].setText("");
  638. }
  639. }
  640.  
  641. roundCount = 0;
  642. player1Turn = true;
  643. }
  644.  
  645. private void resetGame() {
  646. player1Points = 0;
  647. player2Points = 0;
  648. updatePointsText();
  649. resetBoard();
  650. }
  651.  
  652. @Override
  653. protected void onSaveInstanceState(Bundle outState) {
  654. super.onSaveInstanceState(outState);
  655.  
  656. outState.putInt("roundCount", roundCount);
  657. outState.putInt("player1Points", player1Points);
  658. outState.putInt("player2Points", player2Points);
  659. outState.putBoolean("player1Turn", player1Turn);
  660. }
  661.  
  662. @Override
  663. protected void onRestoreInstanceState(Bundle savedInstanceState) {
  664. super.onRestoreInstanceState(savedInstanceState);
  665.  
  666. roundCount = savedInstanceState.getInt("roundCount");
  667. player1Points = savedInstanceState.getInt("player1Points");
  668. player2Points = savedInstanceState.getInt("player2Points");
  669. player1Turn = savedInstanceState.getBoolean("player1Turn");
  670. }
  671. }
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680. Cdma
  681. import java.util.*;
  682. public class Main{
  683. private int[][] walshTable;
  684. private int[][] copy;
  685. private int[] channelSeq;
  686.  
  687. public void setUp(int data[],int numStations){
  688. walshTable=new int[numStations][numStations];
  689. copy=new int[numStations][numStations];
  690.  
  691. buildWalshTable(numStations, 0, numStations-1, 0, numStations-1, false);
  692. showWalshTable(numStations);
  693.  
  694. for(int i=0;i<numStations;i++)
  695. for(int j=0;j<numStations;j++){
  696. copy[i][j]=walshTable[i][j];
  697. walshTable[i][j]*=data[i];
  698. }
  699. channelSeq=new int [numStations];
  700. for (int i=0;i<numStations;i++)
  701. for(int j=0;j<numStations;j++){
  702. channelSeq[i]+=walshTable[j][i];
  703. }
  704.  
  705. }
  706.  
  707. public void buildWalshTable(int len,int i1,int i2,int j1,int j2,boolean val){
  708. if(len==2){
  709. if(!val){
  710. walshTable[i1][j1]=1;
  711. walshTable[i1][j2]=1;
  712. walshTable[i2][j1]=1;
  713. walshTable[i2][j2]=-1;
  714. }
  715. else{
  716. walshTable[i1][j1]=-1;
  717. walshTable[i1][j2]=-1;
  718. walshTable[i2][j1]=-1;
  719. walshTable[i2][j2]=1;
  720. }
  721.  
  722. }
  723. else{
  724. int midi=(i1+i2)/2;
  725. int midj=(j1+j2)/2;
  726.  
  727. buildWalshTable(len/2,i1,midi,j1,midj,val);
  728. buildWalshTable(len/2,midi+1,i2,j1,midj,val);
  729. buildWalshTable(len/2,i1,midi,midj+1,j2,val);
  730. buildWalshTable(len/2,midi+1,i2,midj+1,j2,!val);
  731. }
  732.  
  733. }
  734. public void showWalshTable(int numStations){
  735. System.out.println("Walsh Table");
  736. for(int i=0;i<numStations;i++)
  737. {
  738. for(int j=0;j<numStations;j++){
  739. System.out.print(walshTable[i][j]+"\t");
  740. }
  741. System.out.println();
  742. }
  743.  
  744. }
  745. public void listenTo(int numStations,int sourceStation){
  746. int innerProduct=0;
  747. for (int i=0;i< numStations;i++)
  748. innerProduct+=copy[sourceStation][i]*channelSeq[i];
  749. System.out.println("Data received is : "+innerProduct/numStations);
  750.  
  751. }
  752.  
  753. public static void main(String args[]){
  754. Main channel= new Main();
  755. int numStations=4;
  756.  
  757. int[] data=new int[numStations];
  758. data[0]=-1;
  759. data[1]=-1;
  760. data[2]=0;
  761. data[3]=1;
  762. channel.setUp(data,numStations);
  763. int sourceStation=3;
  764. channel.listenTo(numStations,sourceStation);
  765.  
  766. }
  767. }
  768.  
  769.  
  770.  
  771.  
  772.  
  773. cdma python
  774. def mult(c,d):
  775. return list(map(lambda x : x * d, c))
  776.  
  777. c1=[1,1,1,1]
  778. c2=[1,-1,1,-1]
  779. c3=[1,1,-1,-1]
  780. c4=[1,-1,-1,1]
  781. C=[c1,c2,c3,c4]
  782.  
  783. d=[int(x) for x in input("Enter data bits for 4 channels:").split()]
  784. result=[]
  785. for i in range(4):
  786. result.append(mult(C[i],d[i]))
  787.  
  788. print(result)
  789. channel=[]
  790. for i in range(4):
  791. res=0
  792. for j in range(4):
  793. res+=result[j][i]
  794. channel.append(res)
  795.  
  796. station=int(input("Enter station you want to listen:"))
  797.  
  798. res2=0
  799. for i in range(4):
  800. res2+=channel[i]*C[station-1][i]
  801.  
  802. print("Data bit transmitted:",res2//4)
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814. Phonebook
  815. ANDROID : PHONEBOOK ActivityMain.xml:
  816. <? ​ xml version=​"1.0" ​encoding=​"utf-8"​?>
  817. <​LinearLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
  818. ​xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
  819. ​xmlns:​tools​=​"http://schemas.android.com/tools"
  820. ​android​:layout_width=​"match_parent"
  821. ​android​:layout_height=​"match_parent"
  822. ​android​:orientation=​"vertical"
  823. ​tools​:context=​".MainActivity" ​>
  824.  
  825. <​EditText
  826. ​android​:id=​"@+id/etName"
  827. ​android​:layout_width=​"match_parent"
  828. ​android​:layout_height=​"wrap_content"
  829. ​android​:ems=​"10"
  830. ​android​:inputType=​"textPersonName"
  831. ​android​:hint=​"Name" ​/>
  832.  
  833. <​EditText
  834. ​android​:id=​"@+id/etPhone"
  835. ​android​:layout_width=​"match_parent"
  836. ​android​:layout_height=​"wrap_content"
  837. ​android​:ems=​"10"
  838. ​android​:inputType=​"phone"
  839. ​android​:hint=​"Phone Number"​/>
  840.  
  841. <​EditText
  842. ​android​:id=​"@+id/etEmail"
  843. ​android​:layout_width=​"match_parent"
  844. ​android​:layout_height=​"wrap_content"
  845. ​android​:ems=​"10"
  846. ​android​:inputType=​"textEmailAddress"
  847. ​android​:hint=​"Email"​/>
  848.  
  849. <​EditText
  850. ​android​:id=​"@+id/etAddress"
  851. ​android​:layout_width=​"match_parent"
  852. ​android​:layout_height=​"wrap_content"
  853. ​android​:ems=​"10"
  854. ​android​:inputType=​"textPostalAddress"
  855. ​android​:hint=​"Address"​/>
  856.  
  857. <​Button
  858. ​android​:id=​"@+id/btnAdd"
  859. ​android​:layout_width=​"match_parent"
  860. ​android​:layout_height=​"wrap_content"
  861. ​android​:text=​"Add" ​/>
  862. <​Button
  863. ​android​:id=​"@+id/btnView"
  864. ​android​:layout_width=​"match_parent"
  865. ​android​:layout_height=​"wrap_content"
  866. ​android​:text=​"View Contacts" ​/>
  867. </​LinearLayout​>
  868.  
  869.  
  870.  
  871. ActivityView.xml:
  872. <? ​ xml version=​"1.0" ​encoding=​"utf-8"​?>
  873. <​LinearLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
  874. ​xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
  875. ​xmlns:​tools​=​"http://schemas.android.com/tools"
  876. ​android​:layout_width=​"match_parent"
  877. ​android​:layout_height=​"match_parent"
  878. ​tools​:context=​".ViewActivity"
  879. ​android​:orientation=​"vertical"​>
  880.  
  881. <​TextView
  882. ​android​:id=​"@+id/tvData"
  883. ​android​:layout_width=​"match_parent"
  884. ​android​:layout_height=​"wrap_content"
  885. ​android​:text=​""
  886. ​android​:scrollbars=​"vertical"​/>
  887.  
  888. </​LinearLayout​>
  889.  
  890. MainActivity.java:
  891. package ​com.example.phonebookmcc;
  892. import ​android.content.Intent;
  893. import ​android.support.v7.app.AppCompatActivity;
  894. import ​android.os.Bundle;
  895. import ​android.view.View;
  896. import ​android.widget.Button;
  897. import ​android.widget.EditText;
  898. import ​android.widget.Toast;
  899. import static ​android.widget.Toast.​makeText ​ ;
  900. public class ​MainActivity ​extends ​AppCompatActivity {
  901. ​static ​DatabaseHandler ​dbH ​ ;
  902. EditText ​etName​,​etPhone​,​etAddress​,​etEmail​;
  903. Button ​btnAdd​,​btnView​;
  904. ​@Override
  905. ​protected void ​onCreate(Bundle savedInstanceState) {
  906. ​super​.onCreate(savedInstanceState);
  907. setContentView(R.layout.​activity_main ​ );
  908. ​etAddress​=(EditText)findViewById(R.id.​etAddress ​ );
  909. ​etEmail​=(EditText)findViewById(R.id.​etEmail ​ );
  910. ​etName​=(EditText)findViewById(R.id.​etName ​ );
  911. ​etPhone​=(EditText)findViewById(R.id.​etPhone ​ );
  912. ​btnAdd​=(Button)findViewById(R.id.​btnAdd ​ );
  913. ​btnView​=(Button)findViewById(R.id.​btnView ​ );
  914. ​dbH ​ =​new ​DatabaseHandler(​this​);
  915. ​btnAdd​.setOnClickListener(​new ​View.OnClickListener() {
  916. ​@Override ​public void ​onClick(View v) {
  917. ​String name=​etName​.getText().toString();
  918. String phone=​etPhone​.getText().toString();
  919. String email=​etEmail​.getText().toString();
  920. String address=​etAddress​.getText().toString();
  921. ​int ​check=​dbH ​ .addContact(name,phone,email,address);
  922. ​if ​(check==​1​){
  923. Toast.​makeText ​ (MainActivity.​this​,​"CONTACT ADDED"​,Toast.​LENGTH_SHORT ​ ).show(); ​etAddress​.setText(​""​);
  924. ​etPhone​.setText(​""​);
  925. ​etEmail​.setText(​""​);
  926. ​etName​.setText(​""​);
  927. ​etName​.requestFocus();
  928. }
  929. ​else ​{
  930.  
  931. Toast.​makeText ​ (MainActivity.​this​,​"Issues"​,Toast.​LENGTH_SHORT ​ ).show();
  932. }
  933. }
  934. });
  935.  
  936. ​btnView​.setOnClickListener(​new ​View.OnClickListener() {
  937. ​@Override
  938. ​public void ​onClick(View v) {
  939. Intent i=​new ​Intent(MainActivity.​this​,ViewActivity.​class​);
  940. startActivity(i);
  941.  
  942. }
  943. });
  944. } }
  945.  
  946.  
  947.  
  948.  
  949.  
  950. ViewActivity.java:
  951.  
  952. package ​com.example.phonebookmcc;
  953.  
  954. import ​android.support.v7.app.AppCompatActivity;
  955. import ​android.os.Bundle;
  956. import ​android.text.method.ScrollingMovementMethod;
  957. import ​android.widget.TextView;
  958.  
  959. public class ​ViewActivity ​extends ​AppCompatActivity {
  960. TextView ​tvData​;
  961. ​@Override
  962. ​protected void ​onCreate(Bundle savedInstanceState) {
  963. ​super​.onCreate(savedInstanceState);
  964. setContentView(R.layout.​activity_view ​ );
  965. ​tvData​=(TextView)findViewById(R.id.​tvData ​ );
  966. ​String data=MainActivity.​dbH ​ .viewContact();
  967. ​tvData​.setMovementMethod(​new ​ScrollingMovementMethod());
  968. ​if​(data.length()==​0​)
  969. ​tvData​.setText(​"No records to show"​);
  970. ​else
  971. ​tvData​.setText(data);
  972. } }
  973.  
  974.  
  975.  
  976. DatabaseHandler.java:
  977. package ​com.example.phonebookmcc;
  978. import ​android.content.ContentValues;
  979. import ​android.content.Context;
  980. import ​android.database.Cursor;
  981. import ​android.database.sqlite.SQLiteDatabase;
  982. import ​android.database.sqlite.SQLiteOpenHelper;
  983. public class ​DatabaseHandler ​extends ​SQLiteOpenHelper {
  984. ​SQLiteDatabase ​db​;
  985. Context ​context​;
  986. ​public ​DatabaseHandler(Context context) {
  987. ​super​(context,​"contacts"​,​null​,​1​);
  988. ​this​.​context​=context;
  989. ​db​=​this​.getWritableDatabase();
  990. }
  991. ​@Override
  992. ​public void ​onCreate(SQLiteDatabase db) {
  993. ​db.execSQL(​"create table phone(name TEXT,phoneNo text,email text,address text)"​); }
  994. ​@Override
  995. ​public void ​onUpgrade(SQLiteDatabase db, ​int ​oldVersion, ​int ​newVersion) {
  996. }
  997. ​ ​public int ​addContact(String name,String phone,String email,String address){
  998. ContentValues values=​new ​ContentValues();
  999. values.put(​"name"​,name);
  1000. values.put(​"phoneNo"​,phone);
  1001. values.put(​"email"​,email);
  1002. values.put(​"address"​,address);
  1003. ​long ​rid=​db​.insert(​"phone"​,​null​,values);
  1004. ​if​(rid<​0​)
  1005. ​return ​0​;
  1006. ​else
  1007. return ​1​;
  1008. }
  1009. ​public ​String viewContact(){
  1010. ​Cursor cursor=​db​.query(​"phone"​,​new String[]{​"name"​,​"phoneNo"​,​"email"​,​"address"​},​null​,​null​,​null​,​null​,​null​);
  1011. StringBuffer sb=​new ​StringBuffer();
  1012. cursor.moveToFirst();
  1013. ​if​(cursor.getCount()>​0​)
  1014. ​do
  1015. ​{
  1016. sb.append(​"Name: "​+cursor.getString(​0​)+​"​\n​Phone No: "​+cursor.getString(​1​)+​"​\n​Email: "​+cursor.getString(​2​)+​"​\n​Address: "​+cursor.getString(​3​)+
  1017. ​"​\n​--------------------------------------------​\n​"​);
  1018. }​while ​(cursor.moveToNext());
  1019. ​return ​sb.toString();
  1020. } }
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030. //Timer
  1031. ANDROID: TIMER activity_main.xml
  1032. <?xml​ version​=​"1.0"​ encoding​=​"utf-8"​?>
  1033. <​LinearLayout xmlns:android​=​"http://schemas.android.com/apk/res/android"
  1034. ​android:layout_width​=​"match_parent"
  1035. ​android:layout_height​=​"match_parent"
  1036. ​android:orientation​=​"vertical"
  1037. ​android:padding​=​"10dp"​>
  1038. ​<TextView
  1039. ​android:id​=​"@+id/tvCounter"
  1040. ​android:layout_marginTop​=​"150dp"
  1041. ​android:layout_marginBottom​=​"150dp"
  1042. ​android:layout_width​=​"wrap_content"
  1043. ​android:layout_height​=​"wrap_content"
  1044. ​android:gravity​=​"center"
  1045. ​android:layout_gravity​=​"center_horizontal"
  1046. ​android:textSize​=​"60sp"
  1047. ​android:text​=​"00:00:00"
  1048. ​android:textStyle​=​"bold"
  1049. ​android:textColor​=​"#4CAF50"​/>
  1050. ​<EditText
  1051. ​android:id​=​"@+id/etMinutes"
  1052. ​android:layout_width​=​"wrap_content"
  1053. ​android:layout_gravity​=​"center"
  1054. ​android:layout_height​=​"wrap_content"
  1055. ​android:layout_marginLeft​=​"10dp"
  1056. ​android:layout_marginRight​=​"10dp"
  1057. ​android:hint​=​"Enter Minutes!"
  1058. ​android:padding​=​"10dp"
  1059. ​android:maxLength​=​"4"
  1060. ​android:inputType​=​"number"
  1061. ​android:textSize​=​"26sp"
  1062. ​android:gravity​=​"center"
  1063. ​android:textColor​=​"#000000"
  1064. ​android:textColorHint​=​"#9E9E9E"​ ​/>
  1065.  
  1066. ​<LinearLayout
  1067. ​android:layout_marginTop​=​"30dp"
  1068. ​android:orientation​=​"horizontal"
  1069. ​android:layout_width​=​"fill_parent"
  1070. ​android:gravity​=​"center"
  1071. ​android:padding​=​"10dp"
  1072. ​android:layout_gravity​=​"center"
  1073. ​android:layout_height​=​"wrap_content"​>
  1074.  
  1075. ​<Button
  1076. ​android:id​=​"@+id/btnStartStopTimer"
  1077. ​android:layout_width​=​"wrap_content"
  1078. ​android:layout_height​=​"wrap_content"
  1079. ​android:layout_marginRight​=​"10dp"
  1080. ​android:padding​=​"10dp"
  1081. ​android:background​=​"#009688"
  1082. ​android:textColor​=​"#ffffff"
  1083. ​android:textSize​=​"16sp"
  1084. ​android:text​=​"Start Timer"​ ​/>
  1085. ​<Button
  1086. ​android:id​=​"@+id/btnResetTimer"
  1087. ​android:layout_width​=​"wrap_content"
  1088. ​android:layout_height​=​"wrap_content"
  1089. ​android:background​=​"#009688"
  1090. ​android:textColor​=​"#ffffff"
  1091. ​android:textSize​=​"16sp"
  1092. ​android:padding​=​"10dp"
  1093. ​android:layout_marginLeft​=​"10dp"
  1094. ​android:text​=​"Reset Timer"​ ​/>
  1095. ​</LinearLayout>
  1096. </​LinearLayout​>
  1097.  
  1098.  
  1099.  
  1100. MainActivity.java:
  1101. package​ com.karanmadhu.mytimer;
  1102. import​ androidx.appcompat.app.AppCompatActivity;
  1103. import​ android.os.Bundle;
  1104. import​ android.os.CountDownTimer;
  1105. import​ android.view.View;
  1106. import​ android.view.WindowManager;
  1107. import​ android.widget.Button;
  1108. import​ android.widget.EditText;
  1109. import​ android.widget.TextView;
  1110. import​ android.widget.Toast;
  1111. import​ java.util.concurrent.TimeUnit;
  1112. public​ ​class​ ​MainActivity​ ​extends​ ​AppCompatActivity​ {
  1113. ​TextView​ ​tvCounter​;
  1114. ​EditText​ ​etMinutes​;
  1115. ​Button​ ​btnStartStopTimer​, ​btnResetTimer​;
  1116. ​private​ ​static​ ​CountDownTimer​ ​countDownTimer​;
  1117. @​Override
  1118. ​protected​ ​void​ ​onCreate​(​Bundle​ ​savedInstanceState​) {
  1119. ​super​.​onCreate​(savedInstanceState);
  1120. ​setContentView​(​R​.​layout​.​activity_main​); ​// Hide status bar
  1121. getWindow​().​addFlags​(​WindowManager​.​LayoutParams​.​FLAG_FULLSCREEN​) ; ​// Hide action bar ​getSupportActionBar​().​hide​();
  1122. tvCounter = ​findViewById​(​R​.​id​.​tvCounter​);
  1123. etMinutes = ​findViewById​(​R​.​id​.​etMinutes​);
  1124. btnStartStopTimer = findViewById​(​R​.​id​.​btnStartStopTimer​);
  1125. btnResetTimer = ​findViewById​(​R​.​id​.​btnResetTimer​);
  1126. ​btnStartStopTimer​.​setOnClickListener​(​new View.​OnClickListener​() {
  1127. @​Override
  1128. ​public​ ​void​ ​onClick​(​View​ ​view​) {
  1129. ​if​ (countDownTimer == ​null​) {
  1130. ​String​ ​getMinutes​ = etMinutes​.​getText​().​toString​(); ​//Get minutes from editText ​//Check validation over editText
  1131. ​if​ (!​getMinutes​.​equals​(​""​) && getMinutes​.​length​() > ​0​) {
  1132. ​int​ ​noOfMinutes​ = Integer​.​parseInt​(getMinutes);
  1133. ​int​ ​milliseconds​ = noOfMinutes * ​60​ * 1000​; ​//Convert minutes into milliseconds
  1134. countDownTimer = ​new CountDownTimer​(milliseconds, ​1000​) {
  1135. ​public​ ​void​ ​onTick​(​long millisUntilFinished​) {
  1136. ​long​ ​millis​ = millisUntilFinished;
  1137. ​//Convert milliseconds into hour, minute and seconds
  1138. ​long​ ​hours​ = TimeUnit​.​MILLISECONDS​.​toHours​(millis);
  1139. ​long​ ​minutes​ = TimeUnit​.​MILLISECONDS​.​toMinutes​(millis) - TimeUnit​.​HOURS​.​toMinutes​(hours);
  1140. ​long​ ​seconds​ = TimeUnit​.​MILLISECONDS​.​toSeconds​(millis) - TimeUnit​.​MINUTES​.​toSeconds​(minutes);
  1141. ​String​ ​hms​ = String​.​format​(​"%02d:%02d:%02d"​, hours, minutes, seconds);
  1142. ​tvCounter​.​setText​(hms);
  1143. }
  1144. ​public​ ​void​ ​onFinish​() {
  1145. ​tvCounter​.​setText​(​"TIME'S UP!!"​);
  1146. countDownTimer = ​null​;
  1147. ​btnStartStopTimer​.​setText​(​"Start Timer"​);
  1148.  
  1149. }
  1150. }.​start​();
  1151. ​btnStartStopTimer​.​setText​(​"Stop Timer"​);​//Change Text
  1152. } ​else
  1153. ​Toast​.​makeText​(​getApplicationContext​(),
  1154. ​"Please enter no. of Minutes."​,
  1155. ​Toast​.​LENGTH_SHORT​).​show​();
  1156. }
  1157. ​else​ {
  1158. ​countDownTimer​.​cancel​();
  1159. countDownTimer = ​null​;
  1160. ​btnStartStopTimer​.​setText​(​"Start Timer"​);
  1161. }
  1162. }
  1163. });
  1164. ​btnResetTimer​.​setOnClickListener​(​new View.​OnClickListener​() {
  1165. @​Override
  1166. ​public​ ​void​ ​onClick​(​View​ ​view​) {
  1167. ​if​ (countDownTimer != ​null​) {
  1168. ​countDownTimer​.​cancel​();
  1169. countDownTimer = ​null​;
  1170. }
  1171. ​btnStartStopTimer​.​setText​(​"Start Timer"​);
  1172. ​tvCounter​.​setText​(​"00:00:00"​);
  1173. }
  1174. });
  1175. }
  1176. }
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185. ///frequency reuse
  1186. mport java.util.Scanner;
  1187. class Cofrequency{
  1188. public static void main(String[] args) {
  1189. int[][] arr = new int[11][11];
  1190.  
  1191. int i,j,k;
  1192. Scanner sc=new Scanner(System.in);
  1193. System.out.print("Enter i: ");
  1194. i=sc.nextInt();
  1195. System.out.print("Enter j: ");
  1196. j=sc.nextInt();
  1197.  
  1198. int x,y;
  1199. System.out.println("\nBefore");
  1200. for(x=0;x<11;x++){
  1201. for(y=0;y<11;y++){
  1202. System.out.print(arr[x][y] + " ");
  1203. }
  1204. System.out.println();
  1205. }
  1206. arr[5][5]=2;
  1207. arr[5+j][5+j+i]=1;
  1208. arr[5-j][5+j+i]=1;
  1209. arr[5+j][5-j-i]=1;
  1210. arr[5-j][5-j-i]=1;
  1211. arr[5-i-j-1][5]=1;
  1212. arr[5+i+j+1][5]=1;
  1213.  
  1214. System.out.println("\nAfter");
  1215. for(x=0;x<11;x++){
  1216. for(y=0;y<11;y++){
  1217. System.out.print(arr[x][y] + " ");
  1218. }
  1219. System.out.println();
  1220. }
  1221. for(i=2;i<=8;i++)
  1222. for(j=3;j<8;j++)
  1223. if (arr[i][j]==0)
  1224. arr[i][j]=1;
  1225. System.out.println("\nCluster Formation");
  1226. for(x=0;x<11;x++){
  1227. for(y=0;y<11;y++){
  1228. System.out.print(arr[x][y] + " ");
  1229. }
  1230. System.out.println();
  1231. }
  1232.  
  1233. }
  1234. }
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244. //fontandroid
  1245.  
  1246. XML FILE:
  1247. <?xml version="1.0" encoding="utf-8"?>
  1248. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  1249. xmlns:app="http://schemas.android.com/apk/res-auto"
  1250. xmlns:tools="http://schemas.android.com/tools"
  1251. android:layout_width="match_parent"
  1252. android:layout_height="match_parent"
  1253. tools:context=".MainActivity">
  1254.  
  1255. <TextView
  1256. android:id="@+id/textView"
  1257. android:layout_width="match_parent"
  1258. android:layout_height="wrap_content"
  1259. android:layout_margin="30dp"
  1260. android:layout_marginBottom="8dp"
  1261. android:layout_marginTop="160dp"
  1262. android:gravity="center"
  1263. android:text="Hello World!"
  1264. android:textSize="25sp"
  1265. android:textStyle="bold"
  1266. app:layout_constraintBottom_toBottomOf="parent"
  1267. app:layout_constraintEnd_toEndOf="parent"
  1268. app:layout_constraintStart_toStartOf="parent"
  1269. app:layout_constraintTop_toTopOf="parent"
  1270. app:layout_constraintVertical_bias="0.214" />
  1271.  
  1272. <Button
  1273. android:id="@+id/button1"
  1274. android:layout_width="match_parent"
  1275. android:layout_height="wrap_content"
  1276. android:layout_margin="20dp"
  1277. android:layout_marginStart="16dp"
  1278. android:gravity="center"
  1279. android:text="Change font size"
  1280. android:textSize="25sp"
  1281. app:layout_constraintBottom_toBottomOf="parent"
  1282. app:layout_constraintStart_toStartOf="parent"
  1283. app:layout_constraintTop_toTopOf="parent" />
  1284.  
  1285. <Button
  1286. android:id="@+id/button2"
  1287. android:layout_width="match_parent"
  1288. android:layout_height="wrap_content"
  1289. android:layout_margin="20dp"
  1290. android:layout_marginBottom="8dp"
  1291. android:layout_marginTop="8dp"
  1292. android:gravity="center"
  1293. android:text="Change color"
  1294. android:textSize="25sp"
  1295. app:layout_constraintBottom_toBottomOf="parent"
  1296. app:layout_constraintEnd_toEndOf="parent"
  1297. app:layout_constraintStart_toStartOf="parent"
  1298. app:layout_constraintTop_toBottomOf="@+id/button1" />
  1299.  
  1300. </android.support.constraint.ConstraintLayout>
  1301.  
  1302. JAVA FILE:
  1303. package com.example.sharad.font;
  1304.  
  1305. import android.graphics.Color;
  1306. import android.support.v7.app.AppCompatActivity;
  1307. import android.os.Bundle;
  1308. import android.view.View;
  1309. import android.widget.Button;
  1310. import android.widget.TextView;
  1311.  
  1312. public class MainActivity extends AppCompatActivity {
  1313. int ch=1;
  1314. float font=30;
  1315.  
  1316. @Override
  1317. protected void onCreate(Bundle savedInstanceState) {
  1318. super.onCreate(savedInstanceState);
  1319. setContentView(R.layout.activity_main);
  1320. final TextView t= (TextView) findViewById(R.id.textView);
  1321. Button b1= (Button) findViewById(R.id.button1);
  1322. b1.setOnClickListener(new View.OnClickListener() {
  1323. @Override
  1324. public void onClick(View v) {
  1325. t.setTextSize(font);
  1326. font = font + 5;
  1327. if (font == 50)
  1328. font = 30;
  1329. }
  1330. });
  1331.  
  1332. Button b2= (Button) findViewById(R.id.button2);
  1333.  
  1334. b2.setOnClickListener(new View.OnClickListener() {
  1335. @Override
  1336. public void onClick(View v) {
  1337. switch (ch) {
  1338. case 1:
  1339. t.setTextColor(Color.RED);
  1340. break;
  1341. case 2:
  1342. t.setTextColor(Color.GREEN);
  1343. break;
  1344. case 3:
  1345. t.setTextColor(Color.BLUE);
  1346. break;
  1347. case 4:
  1348. t.setTextColor(Color.CYAN);
  1349. break;
  1350. case 5:
  1351. t.setTextColor(Color.YELLOW);
  1352. break;
  1353. case 6:
  1354. t.setTextColor(Color.MAGENTA);
  1355. break;
  1356. }
  1357. ch++;
  1358. if (ch == 7)
  1359. ch = 1;
  1360.  
  1361.  
  1362. }
  1363. });
  1364. }
  1365. }
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373. //graphical premitives
  1374. Activity_main.xml:
  1375. <?xml version="1.0" encoding="utf-8"?>
  1376. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  1377. xmlns:app="http://schemas.android.com/apk/res-auto"
  1378. xmlns:tools="http://schemas.android.com/tools"
  1379. android:layout_width="match_parent"
  1380. android:layout_height="match_parent"
  1381. tools:context=".MainActivity">
  1382.  
  1383.  
  1384. <ImageView
  1385. android:id="@+id/image"
  1386. android:layout_width="match_parent"
  1387. android:layout_height="match_parent"
  1388. />
  1389. </RelativeLayout>
  1390.  
  1391. MainActivity.java:
  1392. package com.example.basicprimitivesmcc;
  1393.  
  1394. import android.graphics.Bitmap;
  1395. import android.graphics.Canvas;
  1396. import android.graphics.Color;
  1397. import android.graphics.Paint;
  1398. import android.graphics.drawable.BitmapDrawable;
  1399. import android.support.v7.app.AppCompatActivity;
  1400. import android.os.Bundle;
  1401. import android.widget.ImageView;
  1402.  
  1403. public class MainActivity extends AppCompatActivity {
  1404.  
  1405. @Override
  1406. protected void onCreate(Bundle savedInstanceState) {
  1407. super.onCreate(savedInstanceState);
  1408. setContentView(R.layout.activity_main);
  1409.  
  1410. Bitmap bm = Bitmap.createBitmap(720,1280,Bitmap.Config.ARGB_8888);
  1411. ImageView i = (ImageView)findViewById(R.id.image);
  1412. i.setBackgroundDrawable(new BitmapDrawable(bm));
  1413. Canvas canvas=new Canvas(bm);
  1414. Paint paint=new Paint();
  1415. paint.setColor(Color.RED);
  1416. paint.setTextSize(50);
  1417. canvas.drawRect(400,200,600,700,paint);//left top right bottom
  1418. canvas.drawCircle(200,200,100,paint);//cx,cy,radius
  1419. canvas.drawRect(50,800,300,1100,paint);
  1420. canvas.drawLine(500,800,500,1100,paint);//startx,starty,stopx,stopy
  1421.  
  1422. }
  1423. }
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431. ///gps
  1432. ANDROID : GPS Give permissions after installing apk in your phone
  1433. MainActivity.xml:
  1434. <? ​ xml version=​"1.0" ​encoding=​"utf-8"​?>
  1435. <​LinearLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
  1436. ​xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
  1437. ​xmlns:​tools​=​"http://schemas.android.com/tools"
  1438. ​android​:layout_width=​"match_parent"
  1439. ​android​:layout_height=​"match_parent"
  1440. ​tools​:context=​".MainActivity"
  1441. ​android​:orientation=​"vertical" ​>
  1442.  
  1443. <​TextView
  1444. ​android​:id=​"@+id/tvInfo"
  1445. ​android​:layout_width=​"match_parent"
  1446. ​android​:layout_height=​"wrap_content"
  1447.  
  1448. ​android​:text=​"" ​/>
  1449. <​Button
  1450. ​android​:id=​"@+id/btnShare"
  1451. ​android​:layout_width=​"match_parent"
  1452. ​android​:layout_height=​"wrap_content"
  1453. ​android​:text=​"Share" ​/>
  1454. </​LinearLayout​>
  1455.  
  1456. MainActivity.java:
  1457. package ​com.example.locationmcc;
  1458.  
  1459. import ​android.Manifest;
  1460. import ​android.content.Intent;
  1461. import ​android.content.pm.PackageManager;
  1462. import ​android.location.Address;
  1463. import ​android.location.Geocoder;
  1464. import ​android.location.Location;
  1465. import ​android.support.annotation.​NonNull​;
  1466. import ​android.support.annotation.​Nullable​;
  1467. import ​android.support.v4.app.ActivityCompat;
  1468. import ​android.support.v7.app.AppCompatActivity;
  1469. import ​android.os.Bundle;
  1470. import ​android.view.View;
  1471. import ​android.widget.Button;
  1472. import ​android.widget.TextView;
  1473. import ​android.widget.Toast;
  1474. import ​com.google.android.gms.common.ConnectionResult;
  1475. import ​com.google.android.gms.common.api.GoogleApiClient;
  1476. import ​com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
  1477. import ​com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
  1478. import ​com.google.android.gms.location.LocationServices;
  1479. import ​java.io.IOException;
  1480. import ​java.util.List;
  1481. import ​java.util.Locale;
  1482.  
  1483. public class ​MainActivity ​extends ​AppCompatActivity ​implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener​ {
  1484. ​TextView ​tvInfo​;
  1485. Button ​btnShare​;
  1486. GoogleApiClient ​gac​;
  1487. Location ​loc​;
  1488.  
  1489. ​@Override
  1490. ​protected void ​onCreate(Bundle savedInstanceState) {
  1491. ​ super​.onCreate(savedInstanceState);
  1492. setContentView(R.layout.​activity_main ​ );
  1493. ​tvInfo ​= findViewById(R.id.​tvInfo ​ );
  1494. ​btnShare ​= findViewById(R.id.​btnShare ​ );
  1495. GoogleApiClient.Builder builder = ​new ​GoogleApiClient.Builder(​this​);
  1496. builder.addApi(LocationServices.​API ​ );
  1497. builder.addConnectionCallbacks(​this​);
  1498. builder.addOnConnectionFailedListener(​this​);
  1499. ​gac ​= builder.build();
  1500. ​btnShare​.setOnClickListener(​new ​View.OnClickListener() {
  1501. ​@Override
  1502. ​public void ​onClick(View view) {
  1503. ​Intent i = ​new ​Intent(Intent.​ACTION_SEND ​ );
  1504. i.setType(​"text/plain"​);
  1505. i.putExtra(Intent.​EXTRA_TEXT ​ , ​"My address is: " ​+ tvInfo​.getText().toString());
  1506. startActivity(i);
  1507. }
  1508. });
  1509. }
  1510.  
  1511. ​@Override
  1512. ​protected void ​onStart() {
  1513. ​super​.onStart();
  1514. ​if ​(​gac ​!= ​null​)
  1515. ​gac​.connect();
  1516. }
  1517. ​@Override
  1518. ​protected void ​onStop() {
  1519. ​super​.onStop();
  1520. ​if ​(​gac ​!= ​null​) {
  1521. ​gac​.disconnect();
  1522. ​//btnShare.setEnabled(false);
  1523. ​ }
  1524. }
  1525. ​@Override
  1526. ​public void ​onPointerCaptureChanged(​boolean ​hasCapture) {
  1527. }
  1528. ​@Override
  1529. ​public void ​onConnectionFailed(​@NonNull ​ConnectionResult connectionResult) {
  1530. Toast.​makeText ​ (​this​, ​"Connection Failed"​, Toast.​LENGTH_SHORT ​ ).show();
  1531. }
  1532. ​@Override
  1533. ​public void ​onConnected(​@Nullable ​Bundle bundle) {
  1534. ​ ​if ​(ActivityCompat.​checkSelfPermission
  1535. ​ (​this​, android.Manifest.permission.​ACCESS_FINE_LOCATION​ ) != PackageManager.​PERMISSION_GRANTED && ActivityCompat.​checkSelfPermission
  1536. ​ (​this​, android.Manifest.permission.​ACCESS_COARSE_LOCATION ​ ) != PackageManager.​PERMISSION_GRANTED
  1537. ​ )
  1538. {
  1539. ​return​;
  1540. }
  1541. ​loc ​= LocationServices.​FusedLocationApi.getLastLocation(​gac​);
  1542. ​if​(​loc ​!= ​null​){
  1543. ​double ​lat = ​loc​.getLatitude();
  1544. ​double ​lon = ​loc​.getLongitude();
  1545. ​tvInfo​.setText(​"Latitude: "​+ lat+ ​" Longitude: "​+ lon);
  1546. Geocoder g = ​new ​Geocoder(​this​, Locale.​ENGLISH ​ );
  1547. ​try ​{
  1548. ​List<android.location.Address> la = g.getFromLocation(lat, lon, ​1​); //number of results = 1
  1549. ​ android.location.Address add = la.get(​0​);
  1550. String msg = add.getCountryName() + ​" " ​+ add.getAdminArea() + ​" " ​+ add.getSubAdminArea() + ​" " ​+ add.getLocality() + ​" " ​+ add.getSubLocality() + ​" " ​+ add.getThoroughfare() + ​" " ​+
  1551. add.getSubThoroughfare() + ​" " ​+ add.getPostalCode(); ​tvInfo​.setText(msg);
  1552. }
  1553. ​catch ​(IOException e) {
  1554. e.printStackTrace();
  1555. }
  1556. }
  1557. ​else​{
  1558. ​tvInfo​.setText(​"Please enable GPS"​);
  1559. }
  1560. }
  1561. ​@Override
  1562. ​public void ​onConnectionSuspended(​int ​i) {
  1563. Toast.​makeText ​ (​this​, ​"Connection Suspended "​+​CAUSE_NETWORK_LOST ​ , Toast.​LENGTH_SHORT ​ ).show();
  1564. }
  1565. }
  1566.  
  1567.  
  1568.  
  1569. AndroidManifest.xml:
  1570. <?xml version="1.0" encoding="utf-8"?>
  1571. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  1572. package="com.example.locationmcc"> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  1573. <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  1574. <uses-permission android:name="android.permission.INTERNET"/>
  1575. <application
  1576. android:allowBackup="true"
  1577. android:icon="@mipmap/ic_launcher"
  1578. android:label="@string/app_name"
  1579. android:roundIcon="@mipmap/ic_launcher_round"
  1580. android:supportsRtl="true"
  1581. android:theme="@style/AppTheme">
  1582. <activity android:name=".MainActivity">
  1583. <intent-filter>
  1584. <action android:name="android.intent.action.MAIN" />
  1585.  
  1586. <category android:name="android.intent.category.LAUNCHER" />
  1587. </intent-filter>
  1588. </activity>
  1589. ​<meta-data
  1590. android:name="com.google.android.geo.API_KEY"
  1591. android:value="​YOUR KEY HERE ​ "/>
  1592. </application> </manifest>
  1593.  
  1594. Gradle: (Add this line) implementation ​'com.google.android.gms:play-services:12.0.1'
  1595.  
  1596.  
  1597.  
  1598.  
  1599.  
  1600. /login form react native
  1601. import React, { Component } from 'react';
  1602. import { Alert, Button, TextInput, View, StyleSheet } from 'react-native';
  1603.  
  1604. export default class App extends Component {
  1605. constructor(props) {
  1606. super(props);
  1607.  
  1608. this.state = {
  1609. username: '',
  1610. password: '',
  1611. };
  1612. }
  1613.  
  1614. onLogin() {
  1615. const { username, password } = this.state;
  1616.  
  1617. Alert.alert('Credentials', `${username} + ${password}`);
  1618. }
  1619.  
  1620. render() {
  1621. return (
  1622. <View style={styles.container}>
  1623. <TextInput
  1624. value={this.state.username}
  1625. onChangeText={(username) => this.setState({ username })}
  1626. placeholder={'Username'}
  1627. style={styles.input}
  1628. />
  1629. <TextInput
  1630. value={this.state.password}
  1631. onChangeText={(password) => this.setState({ password })}
  1632. placeholder={'Password'}
  1633. secureTextEntry={true}
  1634. style={styles.input}
  1635. />
  1636.  
  1637. <Button
  1638. title={'Login'}
  1639. style={styles.input}
  1640. onPress={this.onLogin.bind(this)}
  1641. />
  1642. </View>
  1643. );
  1644. }
  1645. }
  1646.  
  1647. const styles = StyleSheet.create({
  1648. container: {
  1649. flex: 1,
  1650. alignItems: 'center',
  1651. justifyContent: 'center',
  1652. backgroundColor: '#ecf0f1',
  1653. },
  1654. input: {
  1655. width: 200,
  1656. height: 44,
  1657. padding: 10,
  1658. borderWidth: 1,
  1659. borderColor: 'black',
  1660. marginBottom: 10,
  1661. },
  1662. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement