Wednesday, May 29, 2024

Audio/ Sound Project

 ..Mainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


..MainActivity.java 

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
private EditText edittext1, edittext2;
private Button buttonSum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
//getSupportActionBar().hide(); // hide the title bar
// this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
setContentView(R.layout.activity_main);
try {
Uri uri = Uri.parse("https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_100KB_OGG.ogg");
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(this,uri);
player.prepare();
player.start();
} catch(Exception e) {
System.out.println(e.toString());
}

}
}

..activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heloow"
></TextView>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="109dp"
android:text="ADD"
tools:layout_editor_absoluteX="148dp"
tools:layout_editor_absoluteY="266dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent">

</TextView>

</LinearLayout>

Friday, July 22, 2022

C-Programming-Android-App















MainActivity.java


import androidx.appcompat.app.AppCompatActivity;

import android.content.res.AssetManager;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.ScrollingMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;

public class MainActivity extends AppCompatActivity {
TextView tv;
Typeface face;
Spannable raw;
TextView tvOutput;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tvDisplay);
face = Typeface.createFromAsset(getAssets(), "Fonts/Consolas.ttf");
tv.setMovementMethod(new ScrollingMovementMethod());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.textsize3));
tv.setTypeface(face);
openFile();
syntaxHighlight();

tvOutput = (TextView) findViewById(R.id.tvOutputDisplay);
tvOutput.setMovementMethod(new ScrollingMovementMethod());
openOutput();
tvOutput.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.textsize3));
}


private void openFile() {
// Using AssetManager and InputStream to open file selected by the user.
Bundle extras = getIntent().getExtras();
// temp = extras.getString("KEY");
//loc = extras.getString("LOC");
final AssetManager am = getAssets();
try {
InputStream is = am.open("Programs/" + "Hello World.c");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String text = new String(buffer);
tv.setText(text);
} catch (IOException e) {
e.printStackTrace();
}
}

private void openOutput() {
Bundle extras = getIntent().getExtras();
final AssetManager am = getAssets();
try {
InputStream is = am.open("Outputs/" + "Hello World output.txt");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String text = new String(buffer);
tvOutput.setText(text);
} catch (IOException e) {
e.printStackTrace();
}
}


private void syntaxHighlight() {

String [] green = {"#define", "#include<stdio.h>", "#include<conio.h>", "#include<stdlib.h>", "#include<math.h>",
"#include<graphics.h>", "#include<string.h>", "#include<malloc.h>", "#include<time.h>", "#include<ctype.h>"};
for(String key: green){
fontcolor(key, 0xFF458b00);
}

doColor();

String[] purple = {"int", "float", "char", "signed", "long", "double", "NULL", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
for(String key: purple){
fontcolor(key, 0xFFc133a4);
}

String [] red = {"printf", "scanf", "if", "else", "for", "while", "switch", "case", "break", "default", "goto", "typedef", "struct", "return", "FILE", "exit", "fopen", "fprintf", "fscanf", "fclose", "(", ")"};
for(String key: red){
fontcolor(key, 0xFFDD2626);
}

String [] orange = {"main()", "getch()", "void"};
for(String key: orange){
fontcolor(key, 0xFFee7621);
}

printColor();
commentColor();
}



private void fontcolor(String key, int color) {
raw = new SpannableString(tv.getText());
int index = TextUtils.indexOf(raw, key);
while (index >= 0)
{
raw.setSpan(new ForegroundColorSpan(color), index, index + key.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
index=TextUtils.indexOf(raw, key, index + key.length());
}
tv.setText(raw);
}

private void doColor() {
raw = new SpannableString(tv.getText());
int index = TextUtils.indexOf(raw, "do");
while(index >= 0){
raw.setSpan(new ForegroundColorSpan(Color.parseColor("#DD2626")), index, index + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
index=TextUtils.indexOf(raw, "do", index + 2);
}
tv.setText(raw);
}

private void printColor() {
raw = new SpannableString(tv.getText());
int index1 =TextUtils.indexOf(raw, '"');
int index2 = TextUtils.indexOf(raw, '"', index1+1);
while(index1 >= 0){
raw.setSpan(new ForegroundColorSpan(Color.BLUE), index1, index2+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
index1 = TextUtils.indexOf(raw, '"', index2+1);
index2 = TextUtils.indexOf(raw, '"', index1+1);
}
tv.setText(raw);
}

private void commentColor() {
raw = new SpannableString(tv.getText());
int index=TextUtils.indexOf(raw, "*/");
raw.setSpan(new ForegroundColorSpan(Color.parseColor("#198CFF")), 0, index+2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(raw);
}

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<TextView
android:id="@+id/tvDisplay"
android:background="#324065"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop = "true"
android:layout_centerHorizontal = "true"
/>
<TextView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "Output:"
android:id = "@+id/textView"
android:layout_below = "@+id/tvDisplay"
android:layout_centerHorizontal = "true"
android:textColor = "#ff7aff24"
android:textSize = "30dp" />
<TextView
android:id="@+id/tvOutputDisplay"
android:background="#4CAF50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop = "46dp"
android:layout_below = "@+id/tvDisplay"
android:layout_centerHorizontal = "true"
/>

</RelativeLayout>

res/values/dimens.xml
<resources>

<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="textsize3">8sp</dimen>

</resources>


assets/Programs/Hello World.c
/* Simple C Program to print "Hello World!" */
#include<stdio.h>
#include<conio.h>
main()
{
printf("Hello world!");
getch();
}


assets/Outputs/Hello World output.txt
Hello World!


Reference

Download

Reference

Saturday, June 25, 2022

Project

 

Content

Audio/ Sound Project

 ..Mainfest.xml <? xml version ="1.0" encoding ="utf-8" ?> < manifest xmlns: android ="http://schemas.andr...